1 | <?php |
||
2 | /** |
||
3 | * This file is part of the O2System Framework package. |
||
4 | * |
||
5 | * For the full copyright and license information, please view the LICENSE |
||
6 | * file that was distributed with this source code. |
||
7 | * |
||
8 | * @author Steeve Andrian Salim |
||
9 | * @copyright Copyright (c) Steeve Andrian Salim |
||
10 | */ |
||
11 | // ------------------------------------------------------------------------ |
||
12 | |||
13 | if ( ! function_exists('base_url')) { |
||
14 | /** |
||
15 | * base_url |
||
16 | * |
||
17 | * @param null $segments |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
18 | * @param null $query |
||
0 ignored issues
–
show
|
|||
19 | * |
||
20 | * @return string |
||
21 | */ |
||
22 | function base_url($segments = null, $query = null) |
||
23 | { |
||
24 | $uri = (new \O2System\Kernel\Http\Message\Uri()) |
||
25 | ->withSegments(new \O2System\Kernel\Http\Message\Uri\Segments('')) |
||
26 | ->withQuery(''); |
||
27 | |||
28 | if ($uriConfig = config()->offsetGet('uri')) { |
||
29 | if ( ! empty($uriConfig[ 'base' ])) { |
||
30 | $base = (is_https() ? 'https' : 'http') . '://' . str_replace(['http://', 'https://'], '', |
||
31 | $uriConfig[ 'base' ]); |
||
32 | $uri = new \O2System\Kernel\Http\Message\Uri($base); |
||
33 | } |
||
34 | } |
||
35 | |||
36 | if (isset($segments)) { |
||
37 | $uri = $uri->addSegments($segments); |
||
38 | } |
||
39 | |||
40 | if (isset($query)) { |
||
41 | $uri = $uri->addQuery($query); |
||
42 | } |
||
43 | |||
44 | return $uri->__toString(); |
||
45 | } |
||
46 | } |
||
47 | |||
48 | // ------------------------------------------------------------------------ |
||
49 | |||
50 | if ( ! function_exists('domain_url')) { |
||
51 | /** |
||
52 | * domain_url |
||
53 | * |
||
54 | * @param null $segments |
||
0 ignored issues
–
show
|
|||
55 | * @param null $query |
||
0 ignored issues
–
show
|
|||
56 | * @param null $subdomain |
||
0 ignored issues
–
show
|
|||
57 | * |
||
58 | * @return string |
||
59 | */ |
||
60 | function domain_url($segments = null, $query = null, $subdomain = null) |
||
61 | { |
||
62 | $uri = (new \O2System\Kernel\Http\Message\Uri()) |
||
63 | ->withSubDomain($subdomain) |
||
64 | ->withSegments(new \O2System\Kernel\Http\Message\Uri\Segments('')) |
||
65 | ->withQuery(''); |
||
66 | |||
67 | if ($uriConfig = config()->offsetGet('uri')) { |
||
68 | if ( ! empty($uriConfig[ 'base' ])) { |
||
69 | $base = (is_https() ? 'https' : 'http') . '://' . str_replace(['http://', 'https://'], '', |
||
70 | $uriConfig[ 'base' ]); |
||
71 | $uri = new \O2System\Kernel\Http\Message\Uri($base); |
||
72 | } |
||
73 | } |
||
74 | |||
75 | if (isset($subdomain)) { |
||
76 | $uri = $uri->withSubDomain($subdomain); |
||
77 | } |
||
78 | |||
79 | if (isset($segments)) { |
||
80 | $uri = $uri->addSegments($segments); |
||
81 | } |
||
82 | |||
83 | if (isset($query)) { |
||
84 | $uri = $uri->addQuery($query); |
||
85 | } |
||
86 | |||
87 | return $uri->__toString(); |
||
88 | } |
||
89 | } |
||
90 | |||
91 | // ------------------------------------------------------------------------ |
||
92 | |||
93 | if ( ! function_exists('current_url')) { |
||
94 | /** |
||
95 | * current_url |
||
96 | * |
||
97 | * @param null $segments |
||
0 ignored issues
–
show
|
|||
98 | * @param null $query |
||
0 ignored issues
–
show
|
|||
99 | * |
||
100 | * @return string |
||
101 | */ |
||
102 | function current_url($segments = null, $query = null) |
||
103 | { |
||
104 | $uri = new \O2System\Kernel\Http\Message\Uri(); |
||
105 | |||
106 | if (isset($segments)) { |
||
107 | $uri = $uri->addSegments($segments); |
||
108 | } |
||
109 | |||
110 | if (isset($query)) { |
||
111 | $uri = $uri->addQuery($query); |
||
112 | } |
||
113 | |||
114 | return $uri->__toString(); |
||
115 | } |
||
116 | } |
||
117 | |||
118 | if ( ! function_exists('public_url')) { |
||
119 | /** |
||
120 | * public_url |
||
121 | * |
||
122 | * @param string $path Uri path. |
||
123 | * |
||
124 | * @return string |
||
125 | */ |
||
126 | function public_url($path) |
||
127 | { |
||
128 | return path_to_url($path); |
||
129 | } |
||
130 | } |
||
131 | |||
132 | // ------------------------------------------------------------------------ |
||
133 | |||
134 | if ( ! function_exists('assets_url')) { |
||
135 | /** |
||
136 | * assets_url |
||
137 | * |
||
138 | * @param string $path Uri path. |
||
139 | * |
||
140 | * @return string |
||
141 | */ |
||
142 | function assets_url($path) |
||
143 | { |
||
144 | return presenter()->assets->file($path); |
||
145 | } |
||
146 | } |
||
147 | |||
148 | // ------------------------------------------------------------------------ |
||
149 | |||
150 | if ( ! function_exists('storage_url')) { |
||
151 | /** |
||
152 | * storage_url |
||
153 | * |
||
154 | * @param string $path Uri path. |
||
155 | * |
||
156 | * @return string |
||
157 | */ |
||
158 | function storage_url($path) |
||
159 | { |
||
160 | $urlPath = str_replace(PATH_STORAGE, '', $path); |
||
161 | |||
162 | return base_url('storage/' . $urlPath); |
||
163 | } |
||
164 | } |
||
165 | |||
166 | // ------------------------------------------------------------------------ |
||
167 | |||
168 | if ( ! function_exists('images_url')) { |
||
169 | /** |
||
170 | * images_url |
||
171 | * |
||
172 | * @param string $path Uri path. |
||
173 | * |
||
174 | * @return string |
||
175 | */ |
||
176 | function images_url($path) |
||
177 | { |
||
178 | $urlPath = str_replace(PATH_STORAGE, '', $path); |
||
179 | |||
180 | return base_url('images/' . $urlPath); |
||
181 | } |
||
182 | } |
||
183 | |||
184 | // ------------------------------------------------------------------------ |
||
185 | |||
186 | if ( ! function_exists('prepare_url')) { |
||
187 | /** |
||
188 | * prepare_url |
||
189 | * |
||
190 | * Simply adds the http:// part if no scheme is included |
||
191 | * |
||
192 | * @param string the URL |
||
0 ignored issues
–
show
The type
the was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
193 | * |
||
194 | * @return string |
||
195 | */ |
||
196 | function prepare_url($uri = '') |
||
197 | { |
||
198 | if ($uri === 'http://' or $uri === 'https://' or $uri === '') { |
||
199 | return ''; |
||
200 | } |
||
201 | |||
202 | /** |
||
203 | * Converts double slashes in a string to a single slash, |
||
204 | * except those found in http:// |
||
205 | * |
||
206 | * http://www.some-site.com//index.php |
||
207 | * |
||
208 | * becomes: |
||
209 | * |
||
210 | * http://www.some-site.com/index.php |
||
211 | */ |
||
212 | $uri = preg_replace('#(^|[^:])//+#', '\\1/', $uri); |
||
213 | |||
214 | $url = parse_url($uri); |
||
215 | |||
216 | if ( ! $url or ! isset($url[ 'scheme' ])) { |
||
217 | return (is_https() ? 'https://' : 'http://') . $uri; |
||
218 | } |
||
219 | |||
220 | return $uri; |
||
221 | } |
||
222 | } |
||
223 | |||
224 | // ------------------------------------------------------------------------ |
||
225 | |||
226 | if ( ! function_exists('redirect_url')) { |
||
227 | /** |
||
228 | * redirect_url |
||
229 | * |
||
230 | * Header redirect in two flavors |
||
231 | * For very fine grained control over headers, you could use the Browser |
||
232 | * Library's set_header() function. |
||
233 | * |
||
234 | * @param string $uri URL |
||
235 | * @param string $method Redirect method |
||
236 | * 'auto', 'location' or 'refresh' |
||
237 | * @param int $code HTTP Response status code |
||
238 | * |
||
239 | * @return void |
||
240 | */ |
||
241 | function redirect_url($uri = '', $method = 'auto', $code = null) |
||
242 | { |
||
243 | if (is_array($uri)) { |
||
0 ignored issues
–
show
|
|||
244 | $uri = implode('/', $uri); |
||
245 | } |
||
246 | |||
247 | if (strpos($uri, 'http') === false) { |
||
248 | $uri = base_url($uri); |
||
249 | } |
||
250 | |||
251 | // IIS environment likely? Use 'refresh' for better compatibility |
||
252 | if ($method === 'auto' && isset($_SERVER[ 'SERVER_SOFTWARE' ]) && strpos( |
||
253 | $_SERVER[ 'SERVER_SOFTWARE' ], |
||
254 | 'Microsoft-IIS' |
||
255 | ) !== false |
||
256 | ) { |
||
257 | $method = 'refresh'; |
||
258 | } elseif ($method !== 'refresh' && (empty($code) OR ! is_numeric($code))) { |
||
259 | if (isset($_SERVER[ 'SERVER_PROTOCOL' ], $_SERVER[ 'REQUEST_METHOD' ]) && $_SERVER[ 'SERVER_PROTOCOL' ] === 'HTTP/1.1') { |
||
260 | $code = ($_SERVER[ 'REQUEST_METHOD' ] !== 'GET') |
||
261 | ? 303 // reference: http://en.wikipedia.org/wiki/Post/Redirect/Get |
||
262 | : 307; |
||
263 | } else { |
||
264 | $code = 302; |
||
265 | } |
||
266 | } |
||
267 | |||
268 | switch ($method) { |
||
269 | case 'refresh': |
||
270 | header('Refresh:0;url=' . $uri); |
||
271 | break; |
||
272 | default: |
||
273 | header('Location: ' . $uri, true, $code); |
||
274 | break; |
||
275 | } |
||
276 | |||
277 | exit; |
||
0 ignored issues
–
show
|
|||
278 | } |
||
279 | } |