@@ -15,24 +15,24 @@ |
||
15 | 15 | * Author URI: http://github.com/wladston |
16 | 16 | */ |
17 | 17 | |
18 | -$imgix_options = get_option( 'imgix_settings' ); |
|
18 | +$imgix_options = get_option('imgix_settings'); |
|
19 | 19 | |
20 | -include( 'includes/compability.php' ); |
|
21 | -include( 'includes/do-functions.php' ); |
|
22 | -include( 'includes/options-page.php' ); |
|
20 | +include('includes/compability.php'); |
|
21 | +include('includes/do-functions.php'); |
|
22 | +include('includes/options-page.php'); |
|
23 | 23 | |
24 | -function imgix_plugin_admin_action_links( $links, $file ) { |
|
24 | +function imgix_plugin_admin_action_links($links, $file) { |
|
25 | 25 | static $my_plugin; |
26 | 26 | |
27 | - if ( ! $my_plugin ) { |
|
28 | - $my_plugin = plugin_basename( __FILE__ ); |
|
27 | + if ( ! $my_plugin) { |
|
28 | + $my_plugin = plugin_basename(__FILE__); |
|
29 | 29 | } |
30 | 30 | |
31 | - if ( $file === $my_plugin ) { |
|
31 | + if ($file === $my_plugin) { |
|
32 | 32 | $settings_link = '<a href="options-general.php?page=imgix-options">Settings</a>'; |
33 | - array_unshift( $links, $settings_link ); |
|
33 | + array_unshift($links, $settings_link); |
|
34 | 34 | } |
35 | 35 | return $links; |
36 | 36 | } |
37 | 37 | |
38 | -add_filter( 'plugin_action_links', 'imgix_plugin_admin_action_links', 10, 2 ); |
|
38 | +add_filter('plugin_action_links', 'imgix_plugin_admin_action_links', 10, 2); |
@@ -12,13 +12,13 @@ discard block |
||
12 | 12 | * @param $content |
13 | 13 | * @return string Content with retina-enriched image tags. |
14 | 14 | */ |
15 | -function add_retina( $content ) { |
|
15 | +function add_retina($content) { |
|
16 | 16 | $pattern = '/<img((?![^>]+srcset )([^>]*)'; |
17 | 17 | $pattern .= 'src=[\'"]([^\'"]*imgix.net[^\'"]*\?[^\'"]*w=[^\'"]*)[\'"]([^>]*)*?)>/i'; |
18 | 18 | $repl = '<img$2src="$3" srcset="${3}, ${3}&dpr=2 2x, ${3}&dpr=3 3x,"$4>'; |
19 | - $content = preg_replace( $pattern, $repl, $content ); |
|
19 | + $content = preg_replace($pattern, $repl, $content); |
|
20 | 20 | |
21 | - return preg_replace( $pattern, $repl, $content ); |
|
21 | + return preg_replace($pattern, $repl, $content); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
@@ -26,13 +26,13 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @return array An array of matching arrays with two keys: 'url' and 'params' |
28 | 28 | */ |
29 | -function imgix_extract_imgs( $content ) { |
|
30 | - preg_match_all( '/src=["\']http.+\/([^\s]+?)["\']/', $content, $matches ); |
|
29 | +function imgix_extract_imgs($content) { |
|
30 | + preg_match_all('/src=["\']http.+\/([^\s]+?)["\']/', $content, $matches); |
|
31 | 31 | $results = array(); |
32 | 32 | |
33 | - if ( $matches ) { |
|
34 | - foreach ( $matches[1] as $url ) { |
|
35 | - array_push( $results, $url ); |
|
33 | + if ($matches) { |
|
34 | + foreach ($matches[1] as $url) { |
|
35 | + array_push($results, $url); |
|
36 | 36 | } |
37 | 37 | } |
38 | 38 | |
@@ -46,17 +46,17 @@ discard block |
||
46 | 46 | * |
47 | 47 | * @return string Content with matching URLs having the new querystrings. |
48 | 48 | */ |
49 | -function apply_parameters_to_url( $url, $params, $content ) { |
|
50 | - $parts = explode( '?', $url . '?' ); |
|
49 | +function apply_parameters_to_url($url, $params, $content) { |
|
50 | + $parts = explode('?', $url . '?'); |
|
51 | 51 | |
52 | - list( $base_url, $base_params ) = array( $parts[0], $parts[1] ); |
|
52 | + list($base_url, $base_params) = array($parts[0], $parts[1]); |
|
53 | 53 | |
54 | 54 | $new_url = $old_url = $base_url; |
55 | 55 | $new_url .= '?' . $params; |
56 | 56 | $new_url .= $base_params ? '&' . $base_params : ''; |
57 | 57 | $old_url .= $base_params ? '?' . $base_params : ''; |
58 | 58 | |
59 | - return str_replace( $old_url, $new_url, $content ); |
|
59 | + return str_replace($old_url, $new_url, $content); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -71,19 +71,19 @@ discard block |
||
71 | 71 | // For now, only "auto" is supported. |
72 | 72 | $auto = array(); |
73 | 73 | |
74 | - if ( isset( $imgix_options['auto_format'] ) && $imgix_options['auto_format'] ) { |
|
75 | - array_push( $auto, 'format' ); |
|
74 | + if (isset($imgix_options['auto_format']) && $imgix_options['auto_format']) { |
|
75 | + array_push($auto, 'format'); |
|
76 | 76 | } |
77 | 77 | |
78 | - if ( isset( $imgix_options['auto_enhance'] ) && $imgix_options['auto_enhance'] ) { |
|
79 | - array_push( $auto, 'enhance' ); |
|
78 | + if (isset($imgix_options['auto_enhance']) && $imgix_options['auto_enhance']) { |
|
79 | + array_push($auto, 'enhance'); |
|
80 | 80 | } |
81 | 81 | |
82 | - if ( ! empty( $auto ) ) { |
|
83 | - array_push( $params, 'auto=' . implode( '%2C', $auto ) ); |
|
82 | + if ( ! empty($auto)) { |
|
83 | + array_push($params, 'auto=' . implode('%2C', $auto)); |
|
84 | 84 | } |
85 | 85 | |
86 | - return implode( '&', $params ); |
|
86 | + return implode('&', $params); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -92,24 +92,24 @@ discard block |
||
92 | 92 | * |
93 | 93 | * @return string A sanitized URL. |
94 | 94 | */ |
95 | -function ensure_valid_url( $url ) { |
|
96 | - $slash = strpos( $url, '//' ) == 0 ? '//' : ''; |
|
95 | +function ensure_valid_url($url) { |
|
96 | + $slash = strpos($url, '//') == 0 ? '//' : ''; |
|
97 | 97 | |
98 | - if ( $slash ) { |
|
99 | - $url = substr( $url, 2 ); |
|
98 | + if ($slash) { |
|
99 | + $url = substr($url, 2); |
|
100 | 100 | } |
101 | 101 | |
102 | - $urlp = wp_parse_url( $url ); |
|
103 | - $pref = array_key_exists( 'scheme', $urlp ) ? $urlp['scheme'] . '://' : $slash; |
|
102 | + $urlp = wp_parse_url($url); |
|
103 | + $pref = array_key_exists('scheme', $urlp) ? $urlp['scheme'] . '://' : $slash; |
|
104 | 104 | |
105 | - if ( ! $slash && strpos( $pref, 'http' ) !== 0 ) { |
|
105 | + if ( ! $slash && strpos($pref, 'http') !== 0) { |
|
106 | 106 | $pref = 'http://'; |
107 | 107 | } |
108 | 108 | |
109 | - $result = ! empty( $urlp['host'] ) ? $pref . $urlp['host'] : false; |
|
109 | + $result = ! empty($urlp['host']) ? $pref . $urlp['host'] : false; |
|
110 | 110 | |
111 | - if ( $result ) { |
|
112 | - return trailingslashit( $result ); |
|
111 | + if ($result) { |
|
112 | + return trailingslashit($result); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | return null; |
@@ -120,32 +120,32 @@ discard block |
||
120 | 120 | * |
121 | 121 | * @return array Size's width, height and crop values. |
122 | 122 | */ |
123 | -function get_size_info( $size ) { |
|
123 | +function get_size_info($size) { |
|
124 | 124 | global $_wp_additional_image_sizes; |
125 | 125 | |
126 | - if ( $size === 'original' ) { |
|
126 | + if ($size === 'original') { |
|
127 | 127 | return array( |
128 | 128 | 'width' => '', |
129 | 129 | 'height' => '', |
130 | 130 | 'crop' => false, |
131 | 131 | ); |
132 | - } elseif ( is_array( $size ) ) { |
|
132 | + } elseif (is_array($size)) { |
|
133 | 133 | return array( |
134 | 134 | 'width' => $size[1], |
135 | 135 | 'height' => $size[0], |
136 | 136 | 'crop' => false, |
137 | 137 | ); |
138 | - } elseif ( in_array( $size, array( 'thumbnail', 'medium', 'large' ), true ) ) { |
|
138 | + } elseif (in_array($size, array('thumbnail', 'medium', 'large'), true)) { |
|
139 | 139 | return array( |
140 | - 'width' => get_option( $size . '_size_w' ), |
|
141 | - 'height' => get_option( $size . '_size_h' ), |
|
142 | - 'crop' => (boolean) get_option( $size . '_crop' ), |
|
140 | + 'width' => get_option($size . '_size_w'), |
|
141 | + 'height' => get_option($size . '_size_h'), |
|
142 | + 'crop' => (boolean) get_option($size . '_crop'), |
|
143 | 143 | ); |
144 | - } elseif ( isset( $_wp_additional_image_sizes[ $size ] ) ) { |
|
144 | + } elseif (isset($_wp_additional_image_sizes[$size])) { |
|
145 | 145 | return array( |
146 | - 'width' => $_wp_additional_image_sizes[ $size ]['width'], |
|
147 | - 'height' => $_wp_additional_image_sizes[ $size ]['height'], |
|
148 | - 'crop' => $_wp_additional_image_sizes[ $size ]['crop'], |
|
146 | + 'width' => $_wp_additional_image_sizes[$size]['width'], |
|
147 | + 'height' => $_wp_additional_image_sizes[$size]['height'], |
|
148 | + 'crop' => $_wp_additional_image_sizes[$size]['crop'], |
|
149 | 149 | ); |
150 | 150 | } |
151 | 151 | |
@@ -170,33 +170,33 @@ discard block |
||
170 | 170 | * @return array An array of arrays that has extracted the URL's inferred w', |
171 | 171 | * 'h', and 'type' |
172 | 172 | */ |
173 | -function imgix_extract_img_details( $content ) { |
|
174 | - preg_match_all( '/-([0-9]+)x([0-9]+)\.([^"\']+)/', $content, $matches ); |
|
173 | +function imgix_extract_img_details($content) { |
|
174 | + preg_match_all('/-([0-9]+)x([0-9]+)\.([^"\']+)/', $content, $matches); |
|
175 | 175 | |
176 | - $lookup = array( 'raw', 'w', 'h', 'type' ); |
|
176 | + $lookup = array('raw', 'w', 'h', 'type'); |
|
177 | 177 | $data = array(); |
178 | 178 | |
179 | - foreach ( $matches as $k => $v ) { |
|
179 | + foreach ($matches as $k => $v) { |
|
180 | 180 | |
181 | - foreach ( $v as $index => $value ) { |
|
181 | + foreach ($v as $index => $value) { |
|
182 | 182 | |
183 | - if ( ! array_key_exists( $index, $data ) ) { |
|
184 | - $data[ $index ] = array(); |
|
183 | + if ( ! array_key_exists($index, $data)) { |
|
184 | + $data[$index] = array(); |
|
185 | 185 | } |
186 | 186 | |
187 | - $key = $lookup[ $k ]; |
|
187 | + $key = $lookup[$k]; |
|
188 | 188 | |
189 | - if ( $key === 'type' ) { |
|
190 | - if ( strpos( $value, '?' ) !== false ) { |
|
191 | - $parts = explode( '?', $value ); |
|
192 | - $data[ $index ]['type'] = $parts[0]; |
|
193 | - $data[ $index ]['extra'] = $parts[1]; |
|
189 | + if ($key === 'type') { |
|
190 | + if (strpos($value, '?') !== false) { |
|
191 | + $parts = explode('?', $value); |
|
192 | + $data[$index]['type'] = $parts[0]; |
|
193 | + $data[$index]['extra'] = $parts[1]; |
|
194 | 194 | } else { |
195 | - $data[ $index ]['type'] = $value; |
|
196 | - $data[ $index ]['extra'] = ''; |
|
195 | + $data[$index]['type'] = $value; |
|
196 | + $data[$index]['extra'] = ''; |
|
197 | 197 | } |
198 | 198 | } else { |
199 | - $data[ $index ][ $key ] = $value; |
|
199 | + $data[$index][$key] = $value; |
|
200 | 200 | } |
201 | 201 | } |
202 | 202 | } |
@@ -211,26 +211,26 @@ discard block |
||
211 | 211 | * @return array An array countaining the final string, and a boolean value |
212 | 212 | * indicating if it's different from the given input string. |
213 | 213 | */ |
214 | -function replace_host( $str, $require_prefix = false ) { |
|
214 | +function replace_host($str, $require_prefix = false) { |
|
215 | 215 | global $imgix_options; |
216 | 216 | |
217 | - if ( ! isset( $imgix_options['cdn_link'] ) || ! $imgix_options['cdn_link'] ) { |
|
218 | - return array( $str, false ); |
|
217 | + if ( ! isset($imgix_options['cdn_link']) || ! $imgix_options['cdn_link']) { |
|
218 | + return array($str, false); |
|
219 | 219 | } |
220 | 220 | |
221 | - $new_host = ensure_valid_url( $imgix_options['cdn_link'] ); |
|
222 | - if ( ! $new_host ) { |
|
223 | - return array( $str, false ); |
|
221 | + $new_host = ensure_valid_url($imgix_options['cdn_link']); |
|
222 | + if ( ! $new_host) { |
|
223 | + return array($str, false); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | // As soon as srcset is supported… |
227 | 227 | // $prefix = $require_prefix? 'srcs?e?t?=[\'"]|,[\S+\n\r\s]*': ''; |
228 | - $prefix = $require_prefix? 'src=[\'"]': ''; |
|
229 | - $src = '(' . preg_quote( home_url( '/' ), '/' ) . '|\/\/)'; |
|
228 | + $prefix = $require_prefix ? 'src=[\'"]' : ''; |
|
229 | + $src = '(' . preg_quote(home_url('/'), '/') . '|\/\/)'; |
|
230 | 230 | $patt = '/(' . $prefix . ' )' . $src . '/i'; |
231 | - $str = preg_replace( $patt, '$1' . $new_host, $str, -1, $count ); |
|
231 | + $str = preg_replace($patt, '$1' . $new_host, $str, -1, $count); |
|
232 | 232 | |
233 | - return array( $str, (boolean) $count ); |
|
233 | + return array($str, (boolean) $count); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
@@ -239,56 +239,56 @@ discard block |
||
239 | 239 | * |
240 | 240 | * @return string equivalent imgix source with correct parameters. |
241 | 241 | */ |
242 | -function replace_src( $src, $size ) { |
|
243 | - $size_info = get_size_info( $size ); |
|
242 | +function replace_src($src, $size) { |
|
243 | + $size_info = get_size_info($size); |
|
244 | 244 | |
245 | - if ( $size_info ) { |
|
245 | + if ($size_info) { |
|
246 | 246 | |
247 | - list( $src, $match_src ) = replace_host( $src, false ); |
|
247 | + list($src, $match_src) = replace_host($src, false); |
|
248 | 248 | |
249 | - if ( $match_src ) { |
|
249 | + if ($match_src) { |
|
250 | 250 | $g_params = get_global_params_string(); |
251 | 251 | $params = array(); |
252 | 252 | |
253 | - if ( isset( $size_info['crop'] ) && $size_info['crop'] ) { |
|
254 | - array_push( $params, 'fit=crop' ); |
|
253 | + if (isset($size_info['crop']) && $size_info['crop']) { |
|
254 | + array_push($params, 'fit=crop'); |
|
255 | 255 | } |
256 | 256 | |
257 | - if ( isset( $size_info['width'] ) && $size_info['width'] ) { |
|
258 | - array_push( $params, 'w=' . $size_info['width'] ); |
|
257 | + if (isset($size_info['width']) && $size_info['width']) { |
|
258 | + array_push($params, 'w=' . $size_info['width']); |
|
259 | 259 | } |
260 | 260 | |
261 | - if ( isset( $size_info['height'] ) && $size_info['height'] ) { |
|
262 | - array_push( $params, 'h=' . $size_info['height'] ); |
|
261 | + if (isset($size_info['height']) && $size_info['height']) { |
|
262 | + array_push($params, 'h=' . $size_info['height']); |
|
263 | 263 | } |
264 | 264 | |
265 | - $p = implode( '&', $params ); |
|
266 | - $p = ( $p && $g_params ) ? $p . '&' . $g_params : $p . $g_params; |
|
267 | - $src = apply_parameters_to_url( $src, $p, $src ); |
|
265 | + $p = implode('&', $params); |
|
266 | + $p = ($p && $g_params) ? $p . '&' . $g_params : $p . $g_params; |
|
267 | + $src = apply_parameters_to_url($src, $p, $src); |
|
268 | 268 | } |
269 | 269 | } |
270 | 270 | |
271 | 271 | return $src; |
272 | 272 | } |
273 | 273 | |
274 | -function imgix_file_url( $url ) { |
|
274 | +function imgix_file_url($url) { |
|
275 | 275 | |
276 | 276 | global $imgix_options; |
277 | 277 | |
278 | - if ( empty ( $imgix_options['cdn_link'] ) ) { |
|
278 | + if (empty ($imgix_options['cdn_link'])) { |
|
279 | 279 | return $url; |
280 | 280 | } |
281 | 281 | |
282 | - $file = pathinfo( $url ); |
|
282 | + $file = pathinfo($url); |
|
283 | 283 | |
284 | - if ( in_array( $file['extension'], array( 'jpg', 'gif', 'png', 'jpeg' ) ) ) { |
|
285 | - return str_replace( get_bloginfo( 'wpurl' ), $imgix_options['cdn_link'], $url ); |
|
284 | + if (in_array($file['extension'], array('jpg', 'gif', 'png', 'jpeg'))) { |
|
285 | + return str_replace(get_bloginfo('wpurl'), $imgix_options['cdn_link'], $url); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | return $url; |
289 | 289 | } |
290 | -add_filter( 'wp_get_attachment_url', 'imgix_file_url' ); |
|
291 | -add_filter( 'imgix/add-image-url', 'imgix_file_url' ); |
|
290 | +add_filter('wp_get_attachment_url', 'imgix_file_url'); |
|
291 | +add_filter('imgix/add-image-url', 'imgix_file_url'); |
|
292 | 292 | |
293 | 293 | /** |
294 | 294 | * |
@@ -300,58 +300,58 @@ discard block |
||
300 | 300 | * |
301 | 301 | * @return array $sources |
302 | 302 | */ |
303 | -function imgix_cdn_srcset( $sources, $size_array, $image_src, $image_meta, $attachment_id ) { |
|
304 | - foreach ( $sources as $source ) { |
|
303 | +function imgix_cdn_srcset($sources, $size_array, $image_src, $image_meta, $attachment_id) { |
|
304 | + foreach ($sources as $source) { |
|
305 | 305 | |
306 | - $sources[ $source['value'] ]['url'] = apply_filters( 'imgix/add-image-url', $sources[ $source['value'] ]['url'] ); |
|
306 | + $sources[$source['value']]['url'] = apply_filters('imgix/add-image-url', $sources[$source['value']]['url']); |
|
307 | 307 | |
308 | 308 | } |
309 | 309 | |
310 | 310 | return $sources; |
311 | 311 | } |
312 | -add_filter( 'wp_calculate_image_srcset', 'imgix_cdn_srcset', 10, 5 ); |
|
312 | +add_filter('wp_calculate_image_srcset', 'imgix_cdn_srcset', 10, 5); |
|
313 | 313 | |
314 | -function imgix_replace_non_wp_images( $content ) { |
|
315 | - list( $content, $match ) = replace_host( $content, true ); |
|
314 | +function imgix_replace_non_wp_images($content) { |
|
315 | + list($content, $match) = replace_host($content, true); |
|
316 | 316 | |
317 | - if ( $match ) { |
|
317 | + if ($match) { |
|
318 | 318 | // Apply image-tag-encoded params for every image in $content. |
319 | - foreach ( imgix_extract_img_details( $content ) as $img ) { |
|
319 | + foreach (imgix_extract_img_details($content) as $img) { |
|
320 | 320 | $to_replace = $img['raw']; |
321 | 321 | $extra_params = $img['extra'] ? '&' . $img['extra'] : ''; |
322 | 322 | $new_url = '.' . $img['type'] . '?h=' . $img['h'] . '&w=' . $img['w'] . $extra_params; |
323 | - $content = str_replace( $to_replace, $new_url, $content ); |
|
323 | + $content = str_replace($to_replace, $new_url, $content); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | // Apply global parameters. |
327 | 327 | $g_params = get_global_params_string(); |
328 | - foreach ( imgix_extract_imgs( $content ) as $img_url ) { |
|
329 | - $content = apply_parameters_to_url( $img_url, $g_params, $content ); |
|
328 | + foreach (imgix_extract_imgs($content) as $img_url) { |
|
329 | + $content = apply_parameters_to_url($img_url, $g_params, $content); |
|
330 | 330 | } |
331 | 331 | } |
332 | 332 | return $content; |
333 | 333 | } |
334 | 334 | |
335 | -add_filter( 'the_content', 'imgix_replace_non_wp_images' ); |
|
335 | +add_filter('the_content', 'imgix_replace_non_wp_images'); |
|
336 | 336 | |
337 | 337 | function imgix_wp_head() { |
338 | 338 | global $imgix_options; |
339 | 339 | |
340 | - if ( isset( $imgix_options['cdn_link'] ) && $imgix_options['cdn_link'] ) { |
|
341 | - printf( "<link rel='dns-prefetch' href='%s'/>", |
|
342 | - esc_url( preg_replace( '/^https?:/', '', untrailingslashit( $imgix_options['cdn_link'] ) ) ) |
|
340 | + if (isset($imgix_options['cdn_link']) && $imgix_options['cdn_link']) { |
|
341 | + printf("<link rel='dns-prefetch' href='%s'/>", |
|
342 | + esc_url(preg_replace('/^https?:/', '', untrailingslashit($imgix_options['cdn_link']))) |
|
343 | 343 | ); |
344 | 344 | } |
345 | 345 | } |
346 | 346 | |
347 | -add_action( 'wp_head', 'imgix_wp_head', 1 ); |
|
347 | +add_action('wp_head', 'imgix_wp_head', 1); |
|
348 | 348 | |
349 | -if ( isset( $imgix_options['add_dpi2_srcset'] ) && $imgix_options['add_dpi2_srcset'] ) { |
|
349 | +if (isset($imgix_options['add_dpi2_srcset']) && $imgix_options['add_dpi2_srcset']) { |
|
350 | 350 | function buffer_start() { |
351 | - ob_start( 'add_retina' ); } |
|
351 | + ob_start('add_retina'); } |
|
352 | 352 | function buffer_end() { |
353 | 353 | ob_end_flush(); } |
354 | - add_action( 'after_setup_theme', 'buffer_start' ); |
|
355 | - add_action( 'shutdown', 'buffer_end' ); |
|
356 | - add_filter( 'the_content', 'add_retina' ); |
|
354 | + add_action('after_setup_theme', 'buffer_start'); |
|
355 | + add_action('shutdown', 'buffer_end'); |
|
356 | + add_filter('the_content', 'add_retina'); |
|
357 | 357 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * @package imgix |
6 | 6 | */ |
7 | 7 | |
8 | -if ( ! function_exists( 'wp_parse_url' ) ) { |
|
8 | +if ( ! function_exists('wp_parse_url')) { |
|
9 | 9 | /** |
10 | 10 | * A wrapper for PHP's parse_url() function that handles edgecases in < PHP 5.4.7 |
11 | 11 | * |
@@ -23,30 +23,30 @@ discard block |
||
23 | 23 | * @return bool|array False on failure; Array of URL components on success; |
24 | 24 | * See parse_url()'s return values. |
25 | 25 | */ |
26 | - function wp_parse_url( $url ) { |
|
27 | - $parts = @parse_url( $url ); |
|
28 | - if ( ! $parts ) { |
|
26 | + function wp_parse_url($url) { |
|
27 | + $parts = @parse_url($url); |
|
28 | + if ( ! $parts) { |
|
29 | 29 | // < PHP 5.4.7 compat, trouble with relative paths including a scheme break in the path |
30 | - if ( '/' == $url[0] && false !== strpos( $url, '://' ) ) { |
|
30 | + if ('/' == $url[0] && false !== strpos($url, '://')) { |
|
31 | 31 | // Since we know it's a relative path, prefix with a scheme/host placeholder and try again |
32 | - if ( ! $parts = @parse_url( 'placeholder://placeholder' . $url ) ) { |
|
32 | + if ( ! $parts = @parse_url('placeholder://placeholder' . $url)) { |
|
33 | 33 | return $parts; |
34 | 34 | } |
35 | 35 | // Remove the placeholder values |
36 | - unset( $parts['scheme'], $parts['host'] ); |
|
36 | + unset($parts['scheme'], $parts['host']); |
|
37 | 37 | } else { |
38 | 38 | return $parts; |
39 | 39 | } |
40 | 40 | } |
41 | 41 | |
42 | 42 | // < PHP 5.4.7 compat, doesn't detect schemeless URL's host field |
43 | - if ( '//' == substr( $url, 0, 2 ) && ! isset( $parts['host'] ) ) { |
|
44 | - $path_parts = explode( '/', substr( $parts['path'], 2 ), 2 ); |
|
43 | + if ('//' == substr($url, 0, 2) && ! isset($parts['host'])) { |
|
44 | + $path_parts = explode('/', substr($parts['path'], 2), 2); |
|
45 | 45 | $parts['host'] = $path_parts[0]; |
46 | - if ( isset( $path_parts[1] ) ) { |
|
46 | + if (isset($path_parts[1])) { |
|
47 | 47 | $parts['path'] = '/' . $path_parts[1]; |
48 | 48 | } else { |
49 | - unset( $parts['path'] ); |
|
49 | + unset($parts['path']); |
|
50 | 50 | } |
51 | 51 | } |
52 | 52 |