@@ -101,8 +101,8 @@ |
||
101 | 101 | } |
102 | 102 | // Convert paths like ../foo or ../../bar |
103 | 103 | if(substr($path, 0, 3) == '../') { |
104 | - $removeTwoPointSlash = new RemovePathWithPointPointSlash($this, $path); |
|
105 | - return $removeTwoPointSlash->compute(); |
|
104 | + $removeTwoPointSlash = new RemovePathWithPointPointSlash($this, $path); |
|
105 | + return $removeTwoPointSlash->compute(); |
|
106 | 106 | } |
107 | 107 | if (empty($path)) { |
108 | 108 | return $this->getPagePath(); |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | /** @var string|null */ |
38 | 38 | private $baseTag = null; |
39 | 39 | /** @var string|null */ |
40 | - private $starterPath=null; |
|
40 | + private $starterPath = null; |
|
41 | 41 | /** |
42 | 42 | * @var array|false|int|string|null |
43 | 43 | */ |
@@ -56,9 +56,9 @@ discard block |
||
56 | 56 | * ConvertToAbsolutePath constructor. |
57 | 57 | * @param $pagePath |
58 | 58 | */ |
59 | - public function __construct($pagePath=NULL) |
|
59 | + public function __construct($pagePath = NULL) |
|
60 | 60 | { |
61 | - if(isset($pagePath)) { |
|
61 | + if (isset($pagePath)) { |
|
62 | 62 | $this->setPagePath($pagePath); |
63 | 63 | } |
64 | 64 | } |
@@ -70,11 +70,11 @@ discard block |
||
70 | 70 | { |
71 | 71 | // Skip converting if the relative url like http://... or android-app://... etc. |
72 | 72 | if (preg_match('/[a-z0-9-]{1,}(:\/\/)/i', $path)) { |
73 | - if(preg_match('/services:\/\//i', $path)) |
|
73 | + if (preg_match('/services:\/\//i', $path)) |
|
74 | 74 | return ''; |
75 | - if(preg_match('/whatsapp:\/\//i', $path)) |
|
75 | + if (preg_match('/whatsapp:\/\//i', $path)) |
|
76 | 76 | return ''; |
77 | - if(preg_match('/tel:/i', $path)) |
|
77 | + if (preg_match('/tel:/i', $path)) |
|
78 | 78 | return ''; |
79 | 79 | return $path; |
80 | 80 | } |
@@ -83,24 +83,24 @@ discard block |
||
83 | 83 | return ''; |
84 | 84 | } |
85 | 85 | // Convert //www.google.com to http://www.google.com |
86 | - if(substr($path, 0, 2) == '//') { |
|
86 | + if (substr($path, 0, 2) == '//') { |
|
87 | 87 | return 'http:' . $path; |
88 | 88 | } |
89 | 89 | // If the path is a fragment or query string, |
90 | 90 | // it will be appended to the base url |
91 | - if($this->isHaveQueryOrFragment($path)) { |
|
91 | + if ($this->isHaveQueryOrFragment($path)) { |
|
92 | 92 | return $this->getStarterPath() . $path; |
93 | 93 | } |
94 | 94 | // Treat paths with doc root, i.e, /about |
95 | - if(substr($path, 0, 1) == '/') { |
|
95 | + if (substr($path, 0, 1) == '/') { |
|
96 | 96 | return $this->onlySitePath($this->getStarterPath()) . $path; |
97 | 97 | } |
98 | 98 | // For paths like ./foo, it will be appended to the furthest directory |
99 | - if(substr($path, 0, 2) == './') { |
|
99 | + if (substr($path, 0, 2) == './') { |
|
100 | 100 | return $this->uptoLastDir($this->getStarterPath()) . substr($path, 2); |
101 | 101 | } |
102 | 102 | // Convert paths like ../foo or ../../bar |
103 | - if(substr($path, 0, 3) == '../') { |
|
103 | + if (substr($path, 0, 3) == '../') { |
|
104 | 104 | $removeTwoPointSlash = new RemovePathWithPointPointSlash($this, $path); |
105 | 105 | return $removeTwoPointSlash->compute(); |
106 | 106 | } |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | $parseUrl = parse_url($url); |
118 | 118 | if ($this->isCorrectUrl($parseUrl)) { |
119 | 119 | return ''; |
120 | - }elseif(isset($parseUrl['scheme'])){ |
|
120 | + }elseif (isset($parseUrl['scheme'])) { |
|
121 | 121 | return $parseUrl['scheme'] . '://' . $parseUrl['host']; |
122 | - } else { |
|
122 | + }else { |
|
123 | 123 | return $parseUrl['host']; |
124 | 124 | } |
125 | 125 | } |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | public function upToLastDir($url) { |
130 | 130 | $parseUrl = parse_url($url); |
131 | 131 | $path = ''; |
132 | - if(isset($parseUrl['path'])) |
|
132 | + if (isset($parseUrl['path'])) |
|
133 | 133 | $path = preg_replace('/\/([^\/]+)$/i', '', $parseUrl['path']); |
134 | 134 | return rtrim($parseUrl['scheme'] . '://' . $parseUrl['host'] . $path, '/') . '/'; |
135 | 135 | } |
@@ -167,12 +167,12 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public function getStarterPath(): string |
169 | 169 | { |
170 | - if($this->starterPath===null){ |
|
171 | - if($this->getBaseTag() === null) { |
|
172 | - $this->starterPath =$this->getPagePath(); |
|
173 | - }elseif(array_key_exists('scheme', $this->getBaseTagParsing())){ |
|
174 | - $this->starterPath = $this->getBaseTag() ; |
|
175 | - }else{ |
|
170 | + if ($this->starterPath === null) { |
|
171 | + if ($this->getBaseTag() === null) { |
|
172 | + $this->starterPath = $this->getPagePath(); |
|
173 | + }elseif (array_key_exists('scheme', $this->getBaseTagParsing())) { |
|
174 | + $this->starterPath = $this->getBaseTag(); |
|
175 | + }else { |
|
176 | 176 | $this->starterPath = $this->getPagePathParsing()['scheme'] . '://' . $this->getPagePathParsing()['host'] . $this->getBaseTag(); |
177 | 177 | } |
178 | 178 | } |
@@ -182,11 +182,11 @@ discard block |
||
182 | 182 | public function getDomain() |
183 | 183 | { |
184 | 184 | if ($this->domain === null) { |
185 | - if($this->getBaseTag() === null) { |
|
185 | + if ($this->getBaseTag() === null) { |
|
186 | 186 | $this->domain = $this->getPagePathParsing()['host'] . '/'; |
187 | - }elseif(array_key_exists('scheme', $this->getBaseTagParsing())){ |
|
187 | + }elseif (array_key_exists('scheme', $this->getBaseTagParsing())) { |
|
188 | 188 | $this->domain = $this->getBaseTagParsing()['host'] . '/'; |
189 | - }else{ |
|
189 | + }else { |
|
190 | 190 | $this->domain = $this->getPagePathParsing()['host'] . '/'; |
191 | 191 | } |
192 | 192 | } |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | public function getScheme() |
197 | 197 | { |
198 | 198 | if ($this->scheme === null) { |
199 | - if($this->getBaseTag() === null) { |
|
199 | + if ($this->getBaseTag() === null) { |
|
200 | 200 | $this->scheme = $this->getPagePathParsing()['scheme']; |
201 | - }elseif(array_key_exists('scheme', $this->getBaseTagParsing())){ |
|
201 | + }elseif (array_key_exists('scheme', $this->getBaseTagParsing())) { |
|
202 | 202 | $this->scheme = $this->getBaseTagParsing()['scheme']; |
203 | - }else{ |
|
203 | + }else { |
|
204 | 204 | $this->scheme = $this->getPagePathParsing()['scheme']; |
205 | 205 | } |
206 | 206 | } |
@@ -209,14 +209,14 @@ discard block |
||
209 | 209 | |
210 | 210 | public function getBaseTagParsing() |
211 | 211 | { |
212 | - if($this->baseTagParsing == null) |
|
212 | + if ($this->baseTagParsing == null) |
|
213 | 213 | $this->baseTagParsing = parse_url($this->getBaseTag()); |
214 | 214 | return $this->baseTagParsing; |
215 | 215 | } |
216 | 216 | |
217 | 217 | public function getPagePathParsing() |
218 | 218 | { |
219 | - if($this->pagePathParsing == null) |
|
219 | + if ($this->pagePathParsing == null) |
|
220 | 220 | $this->pagePathParsing = parse_url($this->getPagePath()); |
221 | 221 | return $this->pagePathParsing; |
222 | 222 | } |
@@ -70,12 +70,15 @@ discard block |
||
70 | 70 | { |
71 | 71 | // Skip converting if the relative url like http://... or android-app://... etc. |
72 | 72 | if (preg_match('/[a-z0-9-]{1,}(:\/\/)/i', $path)) { |
73 | - if(preg_match('/services:\/\//i', $path)) |
|
74 | - return ''; |
|
75 | - if(preg_match('/whatsapp:\/\//i', $path)) |
|
76 | - return ''; |
|
77 | - if(preg_match('/tel:/i', $path)) |
|
78 | - return ''; |
|
73 | + if(preg_match('/services:\/\//i', $path)) { |
|
74 | + return ''; |
|
75 | + } |
|
76 | + if(preg_match('/whatsapp:\/\//i', $path)) { |
|
77 | + return ''; |
|
78 | + } |
|
79 | + if(preg_match('/tel:/i', $path)) { |
|
80 | + return ''; |
|
81 | + } |
|
79 | 82 | return $path; |
80 | 83 | } |
81 | 84 | // Treat path as invalid if it is like javascript:... etc. |
@@ -117,7 +120,7 @@ discard block |
||
117 | 120 | $parseUrl = parse_url($url); |
118 | 121 | if ($this->isCorrectUrl($parseUrl)) { |
119 | 122 | return ''; |
120 | - }elseif(isset($parseUrl['scheme'])){ |
|
123 | + } elseif(isset($parseUrl['scheme'])){ |
|
121 | 124 | return $parseUrl['scheme'] . '://' . $parseUrl['host']; |
122 | 125 | } else { |
123 | 126 | return $parseUrl['host']; |
@@ -129,8 +132,9 @@ discard block |
||
129 | 132 | public function upToLastDir($url) { |
130 | 133 | $parseUrl = parse_url($url); |
131 | 134 | $path = ''; |
132 | - if(isset($parseUrl['path'])) |
|
133 | - $path = preg_replace('/\/([^\/]+)$/i', '', $parseUrl['path']); |
|
135 | + if(isset($parseUrl['path'])) { |
|
136 | + $path = preg_replace('/\/([^\/]+)$/i', '', $parseUrl['path']); |
|
137 | + } |
|
134 | 138 | return rtrim($parseUrl['scheme'] . '://' . $parseUrl['host'] . $path, '/') . '/'; |
135 | 139 | } |
136 | 140 | |
@@ -170,9 +174,9 @@ discard block |
||
170 | 174 | if($this->starterPath===null){ |
171 | 175 | if($this->getBaseTag() === null) { |
172 | 176 | $this->starterPath =$this->getPagePath(); |
173 | - }elseif(array_key_exists('scheme', $this->getBaseTagParsing())){ |
|
177 | + } elseif(array_key_exists('scheme', $this->getBaseTagParsing())){ |
|
174 | 178 | $this->starterPath = $this->getBaseTag() ; |
175 | - }else{ |
|
179 | + } else{ |
|
176 | 180 | $this->starterPath = $this->getPagePathParsing()['scheme'] . '://' . $this->getPagePathParsing()['host'] . $this->getBaseTag(); |
177 | 181 | } |
178 | 182 | } |
@@ -184,9 +188,9 @@ discard block |
||
184 | 188 | if ($this->domain === null) { |
185 | 189 | if($this->getBaseTag() === null) { |
186 | 190 | $this->domain = $this->getPagePathParsing()['host'] . '/'; |
187 | - }elseif(array_key_exists('scheme', $this->getBaseTagParsing())){ |
|
191 | + } elseif(array_key_exists('scheme', $this->getBaseTagParsing())){ |
|
188 | 192 | $this->domain = $this->getBaseTagParsing()['host'] . '/'; |
189 | - }else{ |
|
193 | + } else{ |
|
190 | 194 | $this->domain = $this->getPagePathParsing()['host'] . '/'; |
191 | 195 | } |
192 | 196 | } |
@@ -198,9 +202,9 @@ discard block |
||
198 | 202 | if ($this->scheme === null) { |
199 | 203 | if($this->getBaseTag() === null) { |
200 | 204 | $this->scheme = $this->getPagePathParsing()['scheme']; |
201 | - }elseif(array_key_exists('scheme', $this->getBaseTagParsing())){ |
|
205 | + } elseif(array_key_exists('scheme', $this->getBaseTagParsing())){ |
|
202 | 206 | $this->scheme = $this->getBaseTagParsing()['scheme']; |
203 | - }else{ |
|
207 | + } else{ |
|
204 | 208 | $this->scheme = $this->getPagePathParsing()['scheme']; |
205 | 209 | } |
206 | 210 | } |
@@ -209,15 +213,17 @@ discard block |
||
209 | 213 | |
210 | 214 | public function getBaseTagParsing() |
211 | 215 | { |
212 | - if($this->baseTagParsing == null) |
|
213 | - $this->baseTagParsing = parse_url($this->getBaseTag()); |
|
216 | + if($this->baseTagParsing == null) { |
|
217 | + $this->baseTagParsing = parse_url($this->getBaseTag()); |
|
218 | + } |
|
214 | 219 | return $this->baseTagParsing; |
215 | 220 | } |
216 | 221 | |
217 | 222 | public function getPagePathParsing() |
218 | 223 | { |
219 | - if($this->pagePathParsing == null) |
|
220 | - $this->pagePathParsing = parse_url($this->getPagePath()); |
|
224 | + if($this->pagePathParsing == null) { |
|
225 | + $this->pagePathParsing = parse_url($this->getPagePath()); |
|
226 | + } |
|
221 | 227 | return $this->pagePathParsing; |
222 | 228 | } |
223 | 229 |
@@ -24,13 +24,13 @@ |
||
24 | 24 | |
25 | 25 | public function compute() |
26 | 26 | { |
27 | - while(substr($this->getPath(), 0, 3) == '../') { |
|
27 | + while (substr($this->getPath(), 0, 3) == '../') { |
|
28 | 28 | $this->setStarterPath(preg_replace('/\/([^\/]+\/)$/i', '/', $this->getStarterPath())); |
29 | 29 | $this->setPath(substr($this->getPath(), 3)); |
30 | 30 | } |
31 | 31 | if ($this->getStarterPath() === ($this->getScheme() . '://')) { |
32 | 32 | $this->setStarterPath($this->getStarterPath() . $this->getDomain()); |
33 | - } elseif ($this->getStarterPath() ===($this->getScheme(). ':/')) { |
|
33 | + } elseif ($this->getStarterPath() === ($this->getScheme() . ':/')) { |
|
34 | 34 | $this->setStarterPath($this->getStarterPath() . '/' . $this->getDomain()); |
35 | 35 | } |
36 | 36 | return $this->getStarterPath() . $this->getPath(); |