@@ -1,34 +1,34 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * WordPress API for creating bbcode like tags or what WordPress calls |
|
4 | - * "shortcodes." The tag and attribute parsing or regular expression code is |
|
5 | - * based on the Textpattern tag parser. |
|
6 | - * |
|
7 | - * A few examples are below: |
|
8 | - * |
|
9 | - * [shortcode /] |
|
10 | - * [shortcode foo="bar" baz="bing" /] |
|
11 | - * [shortcode foo="bar"]content[/shortcode] |
|
12 | - * |
|
13 | - * Shortcode tags support attributes and enclosed content, but does not entirely |
|
14 | - * support inline shortcodes in other shortcodes. You will have to call the |
|
15 | - * shortcode parser in your function to account for that. |
|
16 | - * |
|
17 | - * {@internal |
|
18 | - * Please be aware that the above note was made during the beta of WordPress 2.6 |
|
19 | - * and in the future may not be accurate. Please update the note when it is no |
|
20 | - * longer the case.}} |
|
21 | - * |
|
22 | - * To apply shortcode tags to content: |
|
23 | - * |
|
24 | - * $out = do_shortcode( $content ); |
|
25 | - * |
|
26 | - * @link https://codex.wordpress.org/Shortcode_API |
|
27 | - * |
|
28 | - * @package WordPress |
|
29 | - * @subpackage Shortcodes |
|
30 | - * @since 2.5.0 |
|
31 | - */ |
|
3 | + * WordPress API for creating bbcode like tags or what WordPress calls |
|
4 | + * "shortcodes." The tag and attribute parsing or regular expression code is |
|
5 | + * based on the Textpattern tag parser. |
|
6 | + * |
|
7 | + * A few examples are below: |
|
8 | + * |
|
9 | + * [shortcode /] |
|
10 | + * [shortcode foo="bar" baz="bing" /] |
|
11 | + * [shortcode foo="bar"]content[/shortcode] |
|
12 | + * |
|
13 | + * Shortcode tags support attributes and enclosed content, but does not entirely |
|
14 | + * support inline shortcodes in other shortcodes. You will have to call the |
|
15 | + * shortcode parser in your function to account for that. |
|
16 | + * |
|
17 | + * {@internal |
|
18 | + * Please be aware that the above note was made during the beta of WordPress 2.6 |
|
19 | + * and in the future may not be accurate. Please update the note when it is no |
|
20 | + * longer the case.}} |
|
21 | + * |
|
22 | + * To apply shortcode tags to content: |
|
23 | + * |
|
24 | + * $out = do_shortcode( $content ); |
|
25 | + * |
|
26 | + * @link https://codex.wordpress.org/Shortcode_API |
|
27 | + * |
|
28 | + * @package WordPress |
|
29 | + * @subpackage Shortcodes |
|
30 | + * @since 2.5.0 |
|
31 | + */ |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * Container for storing shortcode tags and their hook to call for the shortcode |
@@ -426,11 +426,11 @@ discard block |
||
426 | 426 | * @return string Content with placeholders removed. |
427 | 427 | */ |
428 | 428 | function unescape_invalid_shortcodes( $content ) { |
429 | - // Clean up entire string, avoids re-parsing HTML. |
|
430 | - $trans = array( '[' => '[', ']' => ']' ); |
|
431 | - $content = strtr( $content, $trans ); |
|
429 | + // Clean up entire string, avoids re-parsing HTML. |
|
430 | + $trans = array( '[' => '[', ']' => ']' ); |
|
431 | + $content = strtr( $content, $trans ); |
|
432 | 432 | |
433 | - return $content; |
|
433 | + return $content; |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | /** |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | * |
301 | 301 | * @global array $shortcode_tags |
302 | 302 | * |
303 | - * @param array $m Regular expression match array |
|
303 | + * @param string[] $m Regular expression match array |
|
304 | 304 | * @return string|false False on failure. |
305 | 305 | */ |
306 | 306 | function do_shortcode_tag( $m ) { |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | * @since 3.3.0 |
603 | 603 | * |
604 | 604 | * @param array $m RegEx matches against post content. |
605 | - * @return string|false The content stripped of the tag, otherwise false. |
|
605 | + * @return string The content stripped of the tag, otherwise false. |
|
606 | 606 | */ |
607 | 607 | function strip_shortcode_tag( $m ) { |
608 | 608 | // allow [[foo]] syntax for escaping a tag |
@@ -89,20 +89,20 @@ discard block |
||
89 | 89 | function add_shortcode($tag, $func) { |
90 | 90 | global $shortcode_tags; |
91 | 91 | |
92 | - if ( '' == trim( $tag ) ) { |
|
93 | - $message = __( 'Invalid shortcode name: Empty name given.' ); |
|
94 | - _doing_it_wrong( __FUNCTION__, $message, '4.4.0' ); |
|
92 | + if ('' == trim($tag)) { |
|
93 | + $message = __('Invalid shortcode name: Empty name given.'); |
|
94 | + _doing_it_wrong(__FUNCTION__, $message, '4.4.0'); |
|
95 | 95 | return; |
96 | 96 | } |
97 | 97 | |
98 | - if ( 0 !== preg_match( '@[<>&/\[\]\x00-\x20=]@', $tag ) ) { |
|
98 | + if (0 !== preg_match('@[<>&/\[\]\x00-\x20=]@', $tag)) { |
|
99 | 99 | /* translators: 1: shortcode name, 2: space separated list of reserved characters */ |
100 | - $message = sprintf( __( 'Invalid shortcode name: %1$s. Do not use spaces or reserved characters: %2$s' ), $tag, '& / < > [ ] =' ); |
|
101 | - _doing_it_wrong( __FUNCTION__, $message, '4.4.0' ); |
|
100 | + $message = sprintf(__('Invalid shortcode name: %1$s. Do not use spaces or reserved characters: %2$s'), $tag, '& / < > [ ] ='); |
|
101 | + _doing_it_wrong(__FUNCTION__, $message, '4.4.0'); |
|
102 | 102 | return; |
103 | 103 | } |
104 | 104 | |
105 | - $shortcode_tags[ $tag ] = $func; |
|
105 | + $shortcode_tags[$tag] = $func; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -147,9 +147,9 @@ discard block |
||
147 | 147 | * @param string $tag Shortcode tag to check. |
148 | 148 | * @return bool Whether the given shortcode exists. |
149 | 149 | */ |
150 | -function shortcode_exists( $tag ) { |
|
150 | +function shortcode_exists($tag) { |
|
151 | 151 | global $shortcode_tags; |
152 | - return array_key_exists( $tag, $shortcode_tags ); |
|
152 | + return array_key_exists($tag, $shortcode_tags); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -163,20 +163,20 @@ discard block |
||
163 | 163 | * @param string $tag Shortcode tag to check. |
164 | 164 | * @return bool Whether the passed content contains the given shortcode. |
165 | 165 | */ |
166 | -function has_shortcode( $content, $tag ) { |
|
167 | - if ( false === strpos( $content, '[' ) ) { |
|
166 | +function has_shortcode($content, $tag) { |
|
167 | + if (false === strpos($content, '[')) { |
|
168 | 168 | return false; |
169 | 169 | } |
170 | 170 | |
171 | - if ( shortcode_exists( $tag ) ) { |
|
172 | - preg_match_all( '/' . get_shortcode_regex() . '/', $content, $matches, PREG_SET_ORDER ); |
|
173 | - if ( empty( $matches ) ) |
|
171 | + if (shortcode_exists($tag)) { |
|
172 | + preg_match_all('/'.get_shortcode_regex().'/', $content, $matches, PREG_SET_ORDER); |
|
173 | + if (empty($matches)) |
|
174 | 174 | return false; |
175 | 175 | |
176 | - foreach ( $matches as $shortcode ) { |
|
177 | - if ( $tag === $shortcode[2] ) { |
|
176 | + foreach ($matches as $shortcode) { |
|
177 | + if ($tag === $shortcode[2]) { |
|
178 | 178 | return true; |
179 | - } elseif ( ! empty( $shortcode[5] ) && has_shortcode( $shortcode[5], $tag ) ) { |
|
179 | + } elseif ( ! empty($shortcode[5]) && has_shortcode($shortcode[5], $tag)) { |
|
180 | 180 | return true; |
181 | 181 | } |
182 | 182 | } |
@@ -199,31 +199,31 @@ discard block |
||
199 | 199 | * @param bool $ignore_html When true, shortcodes inside HTML elements will be skipped. |
200 | 200 | * @return string Content with shortcodes filtered out. |
201 | 201 | */ |
202 | -function do_shortcode( $content, $ignore_html = false ) { |
|
202 | +function do_shortcode($content, $ignore_html = false) { |
|
203 | 203 | global $shortcode_tags; |
204 | 204 | |
205 | - if ( false === strpos( $content, '[' ) ) { |
|
205 | + if (false === strpos($content, '[')) { |
|
206 | 206 | return $content; |
207 | 207 | } |
208 | 208 | |
209 | - if (empty($shortcode_tags) || !is_array($shortcode_tags)) |
|
209 | + if (empty($shortcode_tags) || ! is_array($shortcode_tags)) |
|
210 | 210 | return $content; |
211 | 211 | |
212 | 212 | // Find all registered tag names in $content. |
213 | - preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches ); |
|
214 | - $tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] ); |
|
213 | + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches); |
|
214 | + $tagnames = array_intersect(array_keys($shortcode_tags), $matches[1]); |
|
215 | 215 | |
216 | - if ( empty( $tagnames ) ) { |
|
216 | + if (empty($tagnames)) { |
|
217 | 217 | return $content; |
218 | 218 | } |
219 | 219 | |
220 | - $content = do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames ); |
|
220 | + $content = do_shortcodes_in_html_tags($content, $ignore_html, $tagnames); |
|
221 | 221 | |
222 | - $pattern = get_shortcode_regex( $tagnames ); |
|
223 | - $content = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $content ); |
|
222 | + $pattern = get_shortcode_regex($tagnames); |
|
223 | + $content = preg_replace_callback("/$pattern/", 'do_shortcode_tag', $content); |
|
224 | 224 | |
225 | 225 | // Always restore square braces so we don't break things like <!--[if IE ]> |
226 | - $content = unescape_invalid_shortcodes( $content ); |
|
226 | + $content = unescape_invalid_shortcodes($content); |
|
227 | 227 | |
228 | 228 | return $content; |
229 | 229 | } |
@@ -250,13 +250,13 @@ discard block |
||
250 | 250 | * @param array $tagnames List of shortcodes to find. Optional. Defaults to all registered shortcodes. |
251 | 251 | * @return string The shortcode search regular expression |
252 | 252 | */ |
253 | -function get_shortcode_regex( $tagnames = null ) { |
|
253 | +function get_shortcode_regex($tagnames = null) { |
|
254 | 254 | global $shortcode_tags; |
255 | 255 | |
256 | - if ( empty( $tagnames ) ) { |
|
257 | - $tagnames = array_keys( $shortcode_tags ); |
|
256 | + if (empty($tagnames)) { |
|
257 | + $tagnames = array_keys($shortcode_tags); |
|
258 | 258 | } |
259 | - $tagregexp = join( '|', array_map('preg_quote', $tagnames) ); |
|
259 | + $tagregexp = join('|', array_map('preg_quote', $tagnames)); |
|
260 | 260 | |
261 | 261 | // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag() |
262 | 262 | // Also, see shortcode_unautop() and shortcode.js. |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | . '\\[\\/\\2\\]' // Closing shortcode tag |
289 | 289 | . ')?' |
290 | 290 | . ')' |
291 | - . '(\\]?)'; // 6: Optional second closing brocket for escaping shortcodes: [[tag]] |
|
291 | + . '(\\]?)'; // 6: Optional second closing brocket for escaping shortcodes: [[tag]] |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | /** |
@@ -303,30 +303,30 @@ discard block |
||
303 | 303 | * @param array $m Regular expression match array |
304 | 304 | * @return string|false False on failure. |
305 | 305 | */ |
306 | -function do_shortcode_tag( $m ) { |
|
306 | +function do_shortcode_tag($m) { |
|
307 | 307 | global $shortcode_tags; |
308 | 308 | |
309 | 309 | // allow [[foo]] syntax for escaping a tag |
310 | - if ( $m[1] == '[' && $m[6] == ']' ) { |
|
310 | + if ($m[1] == '[' && $m[6] == ']') { |
|
311 | 311 | return substr($m[0], 1, -1); |
312 | 312 | } |
313 | 313 | |
314 | 314 | $tag = $m[2]; |
315 | - $attr = shortcode_parse_atts( $m[3] ); |
|
315 | + $attr = shortcode_parse_atts($m[3]); |
|
316 | 316 | |
317 | - if ( ! is_callable( $shortcode_tags[ $tag ] ) ) { |
|
317 | + if ( ! is_callable($shortcode_tags[$tag])) { |
|
318 | 318 | /* translators: %s: shortcode tag */ |
319 | - $message = sprintf( __( 'Attempting to parse a shortcode without a valid callback: %s' ), $tag ); |
|
320 | - _doing_it_wrong( __FUNCTION__, $message, '4.3.0' ); |
|
319 | + $message = sprintf(__('Attempting to parse a shortcode without a valid callback: %s'), $tag); |
|
320 | + _doing_it_wrong(__FUNCTION__, $message, '4.3.0'); |
|
321 | 321 | return $m[0]; |
322 | 322 | } |
323 | 323 | |
324 | - if ( isset( $m[5] ) ) { |
|
324 | + if (isset($m[5])) { |
|
325 | 325 | // enclosing tag - extra parameter |
326 | - return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, $m[5], $tag ) . $m[6]; |
|
326 | + return $m[1].call_user_func($shortcode_tags[$tag], $attr, $m[5], $tag).$m[6]; |
|
327 | 327 | } else { |
328 | 328 | // self-closing tag |
329 | - return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, null, $tag ) . $m[6]; |
|
329 | + return $m[1].call_user_func($shortcode_tags[$tag], $attr, null, $tag).$m[6]; |
|
330 | 330 | } |
331 | 331 | } |
332 | 332 | |
@@ -345,93 +345,93 @@ discard block |
||
345 | 345 | * @param array $tagnames List of shortcodes to find. |
346 | 346 | * @return string Content with shortcodes filtered out. |
347 | 347 | */ |
348 | -function do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames ) { |
|
348 | +function do_shortcodes_in_html_tags($content, $ignore_html, $tagnames) { |
|
349 | 349 | // Normalize entities in unfiltered HTML before adding placeholders. |
350 | - $trans = array( '[' => '[', ']' => ']' ); |
|
351 | - $content = strtr( $content, $trans ); |
|
352 | - $trans = array( '[' => '[', ']' => ']' ); |
|
350 | + $trans = array('[' => '[', ']' => ']'); |
|
351 | + $content = strtr($content, $trans); |
|
352 | + $trans = array('[' => '[', ']' => ']'); |
|
353 | 353 | |
354 | - $pattern = get_shortcode_regex( $tagnames ); |
|
355 | - $textarr = wp_html_split( $content ); |
|
354 | + $pattern = get_shortcode_regex($tagnames); |
|
355 | + $textarr = wp_html_split($content); |
|
356 | 356 | |
357 | - foreach ( $textarr as &$element ) { |
|
358 | - if ( '' == $element || '<' !== $element[0] ) { |
|
357 | + foreach ($textarr as &$element) { |
|
358 | + if ('' == $element || '<' !== $element[0]) { |
|
359 | 359 | continue; |
360 | 360 | } |
361 | 361 | |
362 | - $noopen = false === strpos( $element, '[' ); |
|
363 | - $noclose = false === strpos( $element, ']' ); |
|
364 | - if ( $noopen || $noclose ) { |
|
362 | + $noopen = false === strpos($element, '['); |
|
363 | + $noclose = false === strpos($element, ']'); |
|
364 | + if ($noopen || $noclose) { |
|
365 | 365 | // This element does not contain shortcodes. |
366 | - if ( $noopen xor $noclose ) { |
|
366 | + if ($noopen xor $noclose) { |
|
367 | 367 | // Need to encode stray [ or ] chars. |
368 | - $element = strtr( $element, $trans ); |
|
368 | + $element = strtr($element, $trans); |
|
369 | 369 | } |
370 | 370 | continue; |
371 | 371 | } |
372 | 372 | |
373 | - if ( $ignore_html || '<!--' === substr( $element, 0, 4 ) || '<![CDATA[' === substr( $element, 0, 9 ) ) { |
|
373 | + if ($ignore_html || '<!--' === substr($element, 0, 4) || '<![CDATA[' === substr($element, 0, 9)) { |
|
374 | 374 | // Encode all [ and ] chars. |
375 | - $element = strtr( $element, $trans ); |
|
375 | + $element = strtr($element, $trans); |
|
376 | 376 | continue; |
377 | 377 | } |
378 | 378 | |
379 | - $attributes = wp_kses_attr_parse( $element ); |
|
380 | - if ( false === $attributes ) { |
|
379 | + $attributes = wp_kses_attr_parse($element); |
|
380 | + if (false === $attributes) { |
|
381 | 381 | // Some plugins are doing things like [name] <[email]>. |
382 | - if ( 1 === preg_match( '%^<\s*\[\[?[^\[\]]+\]%', $element ) ) { |
|
383 | - $element = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $element ); |
|
382 | + if (1 === preg_match('%^<\s*\[\[?[^\[\]]+\]%', $element)) { |
|
383 | + $element = preg_replace_callback("/$pattern/", 'do_shortcode_tag', $element); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | // Looks like we found some crazy unfiltered HTML. Skipping it for sanity. |
387 | - $element = strtr( $element, $trans ); |
|
387 | + $element = strtr($element, $trans); |
|
388 | 388 | continue; |
389 | 389 | } |
390 | 390 | |
391 | 391 | // Get element name |
392 | - $front = array_shift( $attributes ); |
|
393 | - $back = array_pop( $attributes ); |
|
392 | + $front = array_shift($attributes); |
|
393 | + $back = array_pop($attributes); |
|
394 | 394 | $matches = array(); |
395 | 395 | preg_match('%[a-zA-Z0-9]+%', $front, $matches); |
396 | 396 | $elname = $matches[0]; |
397 | 397 | |
398 | 398 | // Look for shortcodes in each attribute separately. |
399 | - foreach ( $attributes as &$attr ) { |
|
400 | - $open = strpos( $attr, '[' ); |
|
401 | - $close = strpos( $attr, ']' ); |
|
402 | - if ( false === $open || false === $close ) { |
|
399 | + foreach ($attributes as &$attr) { |
|
400 | + $open = strpos($attr, '['); |
|
401 | + $close = strpos($attr, ']'); |
|
402 | + if (false === $open || false === $close) { |
|
403 | 403 | continue; // Go to next attribute. Square braces will be escaped at end of loop. |
404 | 404 | } |
405 | - $double = strpos( $attr, '"' ); |
|
406 | - $single = strpos( $attr, "'" ); |
|
407 | - if ( ( false === $single || $open < $single ) && ( false === $double || $open < $double ) ) { |
|
405 | + $double = strpos($attr, '"'); |
|
406 | + $single = strpos($attr, "'"); |
|
407 | + if ((false === $single || $open < $single) && (false === $double || $open < $double)) { |
|
408 | 408 | // $attr like '[shortcode]' or 'name = [shortcode]' implies unfiltered_html. |
409 | 409 | // In this specific situation we assume KSES did not run because the input |
410 | 410 | // was written by an administrator, so we should avoid changing the output |
411 | 411 | // and we do not need to run KSES here. |
412 | - $attr = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $attr ); |
|
412 | + $attr = preg_replace_callback("/$pattern/", 'do_shortcode_tag', $attr); |
|
413 | 413 | } else { |
414 | 414 | // $attr like 'name = "[shortcode]"' or "name = '[shortcode]'" |
415 | 415 | // We do not know if $content was unfiltered. Assume KSES ran before shortcodes. |
416 | 416 | $count = 0; |
417 | - $new_attr = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $attr, -1, $count ); |
|
418 | - if ( $count > 0 ) { |
|
417 | + $new_attr = preg_replace_callback("/$pattern/", 'do_shortcode_tag', $attr, -1, $count); |
|
418 | + if ($count > 0) { |
|
419 | 419 | // Sanitize the shortcode output using KSES. |
420 | - $new_attr = wp_kses_one_attr( $new_attr, $elname ); |
|
421 | - if ( '' !== trim( $new_attr ) ) { |
|
420 | + $new_attr = wp_kses_one_attr($new_attr, $elname); |
|
421 | + if ('' !== trim($new_attr)) { |
|
422 | 422 | // The shortcode is safe to use now. |
423 | 423 | $attr = $new_attr; |
424 | 424 | } |
425 | 425 | } |
426 | 426 | } |
427 | 427 | } |
428 | - $element = $front . implode( '', $attributes ) . $back; |
|
428 | + $element = $front.implode('', $attributes).$back; |
|
429 | 429 | |
430 | 430 | // Now encode any remaining [ or ] chars. |
431 | - $element = strtr( $element, $trans ); |
|
431 | + $element = strtr($element, $trans); |
|
432 | 432 | } |
433 | 433 | |
434 | - $content = implode( '', $textarr ); |
|
434 | + $content = implode('', $textarr); |
|
435 | 435 | |
436 | 436 | return $content; |
437 | 437 | } |
@@ -444,10 +444,10 @@ discard block |
||
444 | 444 | * @param string $content Content to search for placeholders. |
445 | 445 | * @return string Content with placeholders removed. |
446 | 446 | */ |
447 | -function unescape_invalid_shortcodes( $content ) { |
|
447 | +function unescape_invalid_shortcodes($content) { |
|
448 | 448 | // Clean up entire string, avoids re-parsing HTML. |
449 | - $trans = array( '[' => '[', ']' => ']' ); |
|
450 | - $content = strtr( $content, $trans ); |
|
449 | + $trans = array('[' => '[', ']' => ']'); |
|
450 | + $content = strtr($content, $trans); |
|
451 | 451 | |
452 | 452 | return $content; |
453 | 453 | } |
@@ -482,13 +482,13 @@ discard block |
||
482 | 482 | $atts = array(); |
483 | 483 | $pattern = get_shortcode_atts_regex(); |
484 | 484 | $text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text); |
485 | - if ( preg_match_all($pattern, $text, $match, PREG_SET_ORDER) ) { |
|
485 | + if (preg_match_all($pattern, $text, $match, PREG_SET_ORDER)) { |
|
486 | 486 | foreach ($match as $m) { |
487 | - if (!empty($m[1])) |
|
487 | + if ( ! empty($m[1])) |
|
488 | 488 | $atts[strtolower($m[1])] = stripcslashes($m[2]); |
489 | - elseif (!empty($m[3])) |
|
489 | + elseif ( ! empty($m[3])) |
|
490 | 490 | $atts[strtolower($m[3])] = stripcslashes($m[4]); |
491 | - elseif (!empty($m[5])) |
|
491 | + elseif ( ! empty($m[5])) |
|
492 | 492 | $atts[strtolower($m[5])] = stripcslashes($m[6]); |
493 | 493 | elseif (isset($m[7]) && strlen($m[7])) |
494 | 494 | $atts[] = stripcslashes($m[7]); |
@@ -497,9 +497,9 @@ discard block |
||
497 | 497 | } |
498 | 498 | |
499 | 499 | // Reject any unclosed HTML elements |
500 | - foreach( $atts as &$value ) { |
|
501 | - if ( false !== strpos( $value, '<' ) ) { |
|
502 | - if ( 1 !== preg_match( '/^[^<]*+(?:<[^>]*+>[^<]*+)*+$/', $value ) ) { |
|
500 | + foreach ($atts as &$value) { |
|
501 | + if (false !== strpos($value, '<')) { |
|
502 | + if (1 !== preg_match('/^[^<]*+(?:<[^>]*+>[^<]*+)*+$/', $value)) { |
|
503 | 503 | $value = ''; |
504 | 504 | } |
505 | 505 | } |
@@ -527,11 +527,11 @@ discard block |
||
527 | 527 | * @param string $shortcode Optional. The name of the shortcode, provided for context to enable filtering |
528 | 528 | * @return array Combined and filtered attribute list. |
529 | 529 | */ |
530 | -function shortcode_atts( $pairs, $atts, $shortcode = '' ) { |
|
531 | - $atts = (array)$atts; |
|
530 | +function shortcode_atts($pairs, $atts, $shortcode = '') { |
|
531 | + $atts = (array) $atts; |
|
532 | 532 | $out = array(); |
533 | 533 | foreach ($pairs as $name => $default) { |
534 | - if ( array_key_exists($name, $atts) ) |
|
534 | + if (array_key_exists($name, $atts)) |
|
535 | 535 | $out[$name] = $atts[$name]; |
536 | 536 | else |
537 | 537 | $out[$name] = $default; |
@@ -550,8 +550,8 @@ discard block |
||
550 | 550 | * @param array $atts The user defined shortcode attributes. |
551 | 551 | * @param string $shortcode The shortcode name. |
552 | 552 | */ |
553 | - if ( $shortcode ) { |
|
554 | - $out = apply_filters( "shortcode_atts_{$shortcode}", $out, $pairs, $atts, $shortcode ); |
|
553 | + if ($shortcode) { |
|
554 | + $out = apply_filters("shortcode_atts_{$shortcode}", $out, $pairs, $atts, $shortcode); |
|
555 | 555 | } |
556 | 556 | |
557 | 557 | return $out; |
@@ -567,31 +567,31 @@ discard block |
||
567 | 567 | * @param string $content Content to remove shortcode tags. |
568 | 568 | * @return string Content without shortcode tags. |
569 | 569 | */ |
570 | -function strip_shortcodes( $content ) { |
|
570 | +function strip_shortcodes($content) { |
|
571 | 571 | global $shortcode_tags; |
572 | 572 | |
573 | - if ( false === strpos( $content, '[' ) ) { |
|
573 | + if (false === strpos($content, '[')) { |
|
574 | 574 | return $content; |
575 | 575 | } |
576 | 576 | |
577 | - if (empty($shortcode_tags) || !is_array($shortcode_tags)) |
|
577 | + if (empty($shortcode_tags) || ! is_array($shortcode_tags)) |
|
578 | 578 | return $content; |
579 | 579 | |
580 | 580 | // Find all registered tag names in $content. |
581 | - preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches ); |
|
582 | - $tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] ); |
|
581 | + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches); |
|
582 | + $tagnames = array_intersect(array_keys($shortcode_tags), $matches[1]); |
|
583 | 583 | |
584 | - if ( empty( $tagnames ) ) { |
|
584 | + if (empty($tagnames)) { |
|
585 | 585 | return $content; |
586 | 586 | } |
587 | 587 | |
588 | - $content = do_shortcodes_in_html_tags( $content, true, $tagnames ); |
|
588 | + $content = do_shortcodes_in_html_tags($content, true, $tagnames); |
|
589 | 589 | |
590 | - $pattern = get_shortcode_regex( $tagnames ); |
|
591 | - $content = preg_replace_callback( "/$pattern/", 'strip_shortcode_tag', $content ); |
|
590 | + $pattern = get_shortcode_regex($tagnames); |
|
591 | + $content = preg_replace_callback("/$pattern/", 'strip_shortcode_tag', $content); |
|
592 | 592 | |
593 | 593 | // Always restore square braces so we don't break things like <!--[if IE ]> |
594 | - $content = unescape_invalid_shortcodes( $content ); |
|
594 | + $content = unescape_invalid_shortcodes($content); |
|
595 | 595 | |
596 | 596 | return $content; |
597 | 597 | } |
@@ -604,11 +604,11 @@ discard block |
||
604 | 604 | * @param array $m RegEx matches against post content. |
605 | 605 | * @return string|false The content stripped of the tag, otherwise false. |
606 | 606 | */ |
607 | -function strip_shortcode_tag( $m ) { |
|
607 | +function strip_shortcode_tag($m) { |
|
608 | 608 | // allow [[foo]] syntax for escaping a tag |
609 | - if ( $m[1] == '[' && $m[6] == ']' ) { |
|
609 | + if ($m[1] == '[' && $m[6] == ']') { |
|
610 | 610 | return substr($m[0], 1, -1); |
611 | 611 | } |
612 | 612 | |
613 | - return $m[1] . $m[6]; |
|
613 | + return $m[1].$m[6]; |
|
614 | 614 | } |
@@ -170,8 +170,9 @@ discard block |
||
170 | 170 | |
171 | 171 | if ( shortcode_exists( $tag ) ) { |
172 | 172 | preg_match_all( '/' . get_shortcode_regex() . '/', $content, $matches, PREG_SET_ORDER ); |
173 | - if ( empty( $matches ) ) |
|
174 | - return false; |
|
173 | + if ( empty( $matches ) ) { |
|
174 | + return false; |
|
175 | + } |
|
175 | 176 | |
176 | 177 | foreach ( $matches as $shortcode ) { |
177 | 178 | if ( $tag === $shortcode[2] ) { |
@@ -206,8 +207,9 @@ discard block |
||
206 | 207 | return $content; |
207 | 208 | } |
208 | 209 | |
209 | - if (empty($shortcode_tags) || !is_array($shortcode_tags)) |
|
210 | - return $content; |
|
210 | + if (empty($shortcode_tags) || !is_array($shortcode_tags)) { |
|
211 | + return $content; |
|
212 | + } |
|
211 | 213 | |
212 | 214 | // Find all registered tag names in $content. |
213 | 215 | preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches ); |
@@ -484,16 +486,17 @@ discard block |
||
484 | 486 | $text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text); |
485 | 487 | if ( preg_match_all($pattern, $text, $match, PREG_SET_ORDER) ) { |
486 | 488 | foreach ($match as $m) { |
487 | - if (!empty($m[1])) |
|
488 | - $atts[strtolower($m[1])] = stripcslashes($m[2]); |
|
489 | - elseif (!empty($m[3])) |
|
490 | - $atts[strtolower($m[3])] = stripcslashes($m[4]); |
|
491 | - elseif (!empty($m[5])) |
|
492 | - $atts[strtolower($m[5])] = stripcslashes($m[6]); |
|
493 | - elseif (isset($m[7]) && strlen($m[7])) |
|
494 | - $atts[] = stripcslashes($m[7]); |
|
495 | - elseif (isset($m[8])) |
|
496 | - $atts[] = stripcslashes($m[8]); |
|
489 | + if (!empty($m[1])) { |
|
490 | + $atts[strtolower($m[1])] = stripcslashes($m[2]); |
|
491 | + } elseif (!empty($m[3])) { |
|
492 | + $atts[strtolower($m[3])] = stripcslashes($m[4]); |
|
493 | + } elseif (!empty($m[5])) { |
|
494 | + $atts[strtolower($m[5])] = stripcslashes($m[6]); |
|
495 | + } elseif (isset($m[7]) && strlen($m[7])) { |
|
496 | + $atts[] = stripcslashes($m[7]); |
|
497 | + } elseif (isset($m[8])) { |
|
498 | + $atts[] = stripcslashes($m[8]); |
|
499 | + } |
|
497 | 500 | } |
498 | 501 | |
499 | 502 | // Reject any unclosed HTML elements |
@@ -531,10 +534,11 @@ discard block |
||
531 | 534 | $atts = (array)$atts; |
532 | 535 | $out = array(); |
533 | 536 | foreach ($pairs as $name => $default) { |
534 | - if ( array_key_exists($name, $atts) ) |
|
535 | - $out[$name] = $atts[$name]; |
|
536 | - else |
|
537 | - $out[$name] = $default; |
|
537 | + if ( array_key_exists($name, $atts) ) { |
|
538 | + $out[$name] = $atts[$name]; |
|
539 | + } else { |
|
540 | + $out[$name] = $default; |
|
541 | + } |
|
538 | 542 | } |
539 | 543 | /** |
540 | 544 | * Filter a shortcode's default attributes. |
@@ -574,8 +578,9 @@ discard block |
||
574 | 578 | return $content; |
575 | 579 | } |
576 | 580 | |
577 | - if (empty($shortcode_tags) || !is_array($shortcode_tags)) |
|
578 | - return $content; |
|
581 | + if (empty($shortcode_tags) || !is_array($shortcode_tags)) { |
|
582 | + return $content; |
|
583 | + } |
|
579 | 584 | |
580 | 585 | // Find all registered tag names in $content. |
581 | 586 | preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches ); |
@@ -1,35 +1,35 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * kses 0.2.2 - HTML/XHTML filter that only allows some elements and attributes |
|
4 | - * Copyright (C) 2002, 2003, 2005 Ulf Harnhammar |
|
5 | - * |
|
6 | - * This program is free software and open source software; you can redistribute |
|
7 | - * it and/or modify it under the terms of the GNU General Public License as |
|
8 | - * published by the Free Software Foundation; either version 2 of the License, |
|
9 | - * or (at your option) any later version. |
|
10 | - * |
|
11 | - * This program is distributed in the hope that it will be useful, but WITHOUT |
|
12 | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|
14 | - * more details. |
|
15 | - * |
|
16 | - * You should have received a copy of the GNU General Public License along |
|
17 | - * with this program; if not, write to the Free Software Foundation, Inc., |
|
18 | - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
|
19 | - * http://www.gnu.org/licenses/gpl.html |
|
20 | - * |
|
21 | - * [kses strips evil scripts!] |
|
22 | - * |
|
23 | - * Added wp_ prefix to avoid conflicts with existing kses users |
|
24 | - * |
|
25 | - * @version 0.2.2 |
|
26 | - * @copyright (C) 2002, 2003, 2005 |
|
27 | - * @author Ulf Harnhammar <http://advogato.org/person/metaur/> |
|
28 | - * |
|
29 | - * @package External |
|
30 | - * @subpackage KSES |
|
31 | - * |
|
32 | - */ |
|
3 | + * kses 0.2.2 - HTML/XHTML filter that only allows some elements and attributes |
|
4 | + * Copyright (C) 2002, 2003, 2005 Ulf Harnhammar |
|
5 | + * |
|
6 | + * This program is free software and open source software; you can redistribute |
|
7 | + * it and/or modify it under the terms of the GNU General Public License as |
|
8 | + * published by the Free Software Foundation; either version 2 of the License, |
|
9 | + * or (at your option) any later version. |
|
10 | + * |
|
11 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
|
12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|
14 | + * more details. |
|
15 | + * |
|
16 | + * You should have received a copy of the GNU General Public License along |
|
17 | + * with this program; if not, write to the Free Software Foundation, Inc., |
|
18 | + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
|
19 | + * http://www.gnu.org/licenses/gpl.html |
|
20 | + * |
|
21 | + * [kses strips evil scripts!] |
|
22 | + * |
|
23 | + * Added wp_ prefix to avoid conflicts with existing kses users |
|
24 | + * |
|
25 | + * @version 0.2.2 |
|
26 | + * @copyright (C) 2002, 2003, 2005 |
|
27 | + * @author Ulf Harnhammar <http://advogato.org/person/metaur/> |
|
28 | + * |
|
29 | + * @package External |
|
30 | + * @subpackage KSES |
|
31 | + * |
|
32 | + */ |
|
33 | 33 | |
34 | 34 | /** |
35 | 35 | * You can override this in a plugin. |
@@ -41,8 +41,9 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @since 1.2.0 |
43 | 43 | */ |
44 | -if ( ! defined( 'CUSTOM_TAGS' ) ) |
|
44 | +if ( ! defined( 'CUSTOM_TAGS' ) ) { |
|
45 | 45 | define( 'CUSTOM_TAGS', false ); |
46 | +} |
|
46 | 47 | |
47 | 48 | // Ensure that these variables are added to the global namespace |
48 | 49 | // (e.g. if using namespaces / autoload in the current PHP environment). |
@@ -519,8 +520,9 @@ discard block |
||
519 | 520 | * @return string Filtered content with only allowed HTML elements |
520 | 521 | */ |
521 | 522 | function wp_kses( $string, $allowed_html, $allowed_protocols = array() ) { |
522 | - if ( empty( $allowed_protocols ) ) |
|
523 | - $allowed_protocols = wp_allowed_protocols(); |
|
523 | + if ( empty( $allowed_protocols ) ) { |
|
524 | + $allowed_protocols = wp_allowed_protocols(); |
|
525 | + } |
|
524 | 526 | $string = wp_kses_no_null( $string, array( 'slash_zero' => 'keep' ) ); |
525 | 527 | $string = wp_kses_js_entities($string); |
526 | 528 | $string = wp_kses_normalize_entities($string); |
@@ -758,16 +760,19 @@ discard block |
||
758 | 760 | function wp_kses_split2($string, $allowed_html, $allowed_protocols) { |
759 | 761 | $string = wp_kses_stripslashes($string); |
760 | 762 | |
761 | - if (substr($string, 0, 1) != '<') |
|
762 | - return '>'; |
|
763 | + if (substr($string, 0, 1) != '<') { |
|
764 | + return '>'; |
|
765 | + } |
|
763 | 766 | // It matched a ">" character |
764 | 767 | |
765 | 768 | if ( '<!--' == substr( $string, 0, 4 ) ) { |
766 | 769 | $string = str_replace( array('<!--', '-->'), '', $string ); |
767 | - while ( $string != ($newstring = wp_kses($string, $allowed_html, $allowed_protocols)) ) |
|
768 | - $string = $newstring; |
|
769 | - if ( $string == '' ) |
|
770 | - return ''; |
|
770 | + while ( $string != ($newstring = wp_kses($string, $allowed_html, $allowed_protocols)) ) { |
|
771 | + $string = $newstring; |
|
772 | + } |
|
773 | + if ( $string == '' ) { |
|
774 | + return ''; |
|
775 | + } |
|
771 | 776 | // prevent multiple dashes in comments |
772 | 777 | $string = preg_replace('/--+/', '-', $string); |
773 | 778 | // prevent three dashes closing a comment |
@@ -776,23 +781,27 @@ discard block |
||
776 | 781 | } |
777 | 782 | // Allow HTML comments |
778 | 783 | |
779 | - if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9]+)([^>]*)>?$%', $string, $matches)) |
|
780 | - return ''; |
|
784 | + if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9]+)([^>]*)>?$%', $string, $matches)) { |
|
785 | + return ''; |
|
786 | + } |
|
781 | 787 | // It's seriously malformed |
782 | 788 | |
783 | 789 | $slash = trim($matches[1]); |
784 | 790 | $elem = $matches[2]; |
785 | 791 | $attrlist = $matches[3]; |
786 | 792 | |
787 | - if ( ! is_array( $allowed_html ) ) |
|
788 | - $allowed_html = wp_kses_allowed_html( $allowed_html ); |
|
793 | + if ( ! is_array( $allowed_html ) ) { |
|
794 | + $allowed_html = wp_kses_allowed_html( $allowed_html ); |
|
795 | + } |
|
789 | 796 | |
790 | - if ( ! isset($allowed_html[strtolower($elem)]) ) |
|
791 | - return ''; |
|
797 | + if ( ! isset($allowed_html[strtolower($elem)]) ) { |
|
798 | + return ''; |
|
799 | + } |
|
792 | 800 | // They are using a not allowed HTML element |
793 | 801 | |
794 | - if ($slash != '') |
|
795 | - return "</$elem>"; |
|
802 | + if ($slash != '') { |
|
803 | + return "</$elem>"; |
|
804 | + } |
|
796 | 805 | // No attributes are allowed for closing elements |
797 | 806 | |
798 | 807 | return wp_kses_attr( $elem, $attrlist, $allowed_html, $allowed_protocols ); |
@@ -816,17 +825,20 @@ discard block |
||
816 | 825 | * @return string Sanitized HTML element |
817 | 826 | */ |
818 | 827 | function wp_kses_attr($element, $attr, $allowed_html, $allowed_protocols) { |
819 | - if ( ! is_array( $allowed_html ) ) |
|
820 | - $allowed_html = wp_kses_allowed_html( $allowed_html ); |
|
828 | + if ( ! is_array( $allowed_html ) ) { |
|
829 | + $allowed_html = wp_kses_allowed_html( $allowed_html ); |
|
830 | + } |
|
821 | 831 | |
822 | 832 | // Is there a closing XHTML slash at the end of the attributes? |
823 | 833 | $xhtml_slash = ''; |
824 | - if (preg_match('%\s*/\s*$%', $attr)) |
|
825 | - $xhtml_slash = ' /'; |
|
834 | + if (preg_match('%\s*/\s*$%', $attr)) { |
|
835 | + $xhtml_slash = ' /'; |
|
836 | + } |
|
826 | 837 | |
827 | 838 | // Are any attributes allowed at all for this element? |
828 | - if ( ! isset($allowed_html[strtolower($element)]) || count($allowed_html[strtolower($element)]) == 0 ) |
|
829 | - return "<$element$xhtml_slash>"; |
|
839 | + if ( ! isset($allowed_html[strtolower($element)]) || count($allowed_html[strtolower($element)]) == 0 ) { |
|
840 | + return "<$element$xhtml_slash>"; |
|
841 | + } |
|
830 | 842 | |
831 | 843 | // Split it |
832 | 844 | $attrarr = wp_kses_hair($attr, $allowed_protocols); |
@@ -934,17 +946,21 @@ discard block |
||
934 | 946 | |
935 | 947 | case 1 : // equals sign or valueless ("selected") |
936 | 948 | |
937 | - if (preg_match('/^\s*=\s*/', $attr)) // equals sign |
|
949 | + if (preg_match('/^\s*=\s*/', $attr)) { |
|
950 | + // equals sign |
|
938 | 951 | { |
939 | 952 | $working = 1; |
953 | + } |
|
940 | 954 | $mode = 2; |
941 | 955 | $attr = preg_replace('/^\s*=\s*/', '', $attr); |
942 | 956 | break; |
943 | 957 | } |
944 | 958 | |
945 | - if (preg_match('/^\s+/', $attr)) // valueless |
|
959 | + if (preg_match('/^\s+/', $attr)) { |
|
960 | + // valueless |
|
946 | 961 | { |
947 | 962 | $working = 1; |
963 | + } |
|
948 | 964 | $mode = 0; |
949 | 965 | if(false === array_key_exists($attrname, $attrarr)) { |
950 | 966 | $attrarr[$attrname] = array ('name' => $attrname, 'value' => '', 'whole' => $attrname, 'vless' => 'y'); |
@@ -956,12 +972,14 @@ discard block |
||
956 | 972 | |
957 | 973 | case 2 : // attribute value, a URL after href= for instance |
958 | 974 | |
959 | - if (preg_match('%^"([^"]*)"(\s+|/?$)%', $attr, $match)) |
|
960 | - // "value" |
|
975 | + if (preg_match('%^"([^"]*)"(\s+|/?$)%', $attr, $match)) { |
|
976 | + // "value" |
|
961 | 977 | { |
962 | 978 | $thisval = $match[1]; |
963 | - if ( in_array(strtolower($attrname), $uris) ) |
|
964 | - $thisval = wp_kses_bad_protocol($thisval, $allowed_protocols); |
|
979 | + } |
|
980 | + if ( in_array(strtolower($attrname), $uris) ) { |
|
981 | + $thisval = wp_kses_bad_protocol($thisval, $allowed_protocols); |
|
982 | + } |
|
965 | 983 | |
966 | 984 | if(false === array_key_exists($attrname, $attrarr)) { |
967 | 985 | $attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname=\"$thisval\"", 'vless' => 'n'); |
@@ -972,12 +990,14 @@ discard block |
||
972 | 990 | break; |
973 | 991 | } |
974 | 992 | |
975 | - if (preg_match("%^'([^']*)'(\s+|/?$)%", $attr, $match)) |
|
976 | - // 'value' |
|
993 | + if (preg_match("%^'([^']*)'(\s+|/?$)%", $attr, $match)) { |
|
994 | + // 'value' |
|
977 | 995 | { |
978 | 996 | $thisval = $match[1]; |
979 | - if ( in_array(strtolower($attrname), $uris) ) |
|
980 | - $thisval = wp_kses_bad_protocol($thisval, $allowed_protocols); |
|
997 | + } |
|
998 | + if ( in_array(strtolower($attrname), $uris) ) { |
|
999 | + $thisval = wp_kses_bad_protocol($thisval, $allowed_protocols); |
|
1000 | + } |
|
981 | 1001 | |
982 | 1002 | if(false === array_key_exists($attrname, $attrarr)) { |
983 | 1003 | $attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname='$thisval'", 'vless' => 'n'); |
@@ -988,12 +1008,14 @@ discard block |
||
988 | 1008 | break; |
989 | 1009 | } |
990 | 1010 | |
991 | - if (preg_match("%^([^\s\"']+)(\s+|/?$)%", $attr, $match)) |
|
992 | - // value |
|
1011 | + if (preg_match("%^([^\s\"']+)(\s+|/?$)%", $attr, $match)) { |
|
1012 | + // value |
|
993 | 1013 | { |
994 | 1014 | $thisval = $match[1]; |
995 | - if ( in_array(strtolower($attrname), $uris) ) |
|
996 | - $thisval = wp_kses_bad_protocol($thisval, $allowed_protocols); |
|
1015 | + } |
|
1016 | + if ( in_array(strtolower($attrname), $uris) ) { |
|
1017 | + $thisval = wp_kses_bad_protocol($thisval, $allowed_protocols); |
|
1018 | + } |
|
997 | 1019 | |
998 | 1020 | if(false === array_key_exists($attrname, $attrarr)) { |
999 | 1021 | $attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname=\"$thisval\"", 'vless' => 'n'); |
@@ -1007,17 +1029,20 @@ discard block |
||
1007 | 1029 | break; |
1008 | 1030 | } // switch |
1009 | 1031 | |
1010 | - if ($working == 0) // not well formed, remove and try again |
|
1032 | + if ($working == 0) { |
|
1033 | + // not well formed, remove and try again |
|
1011 | 1034 | { |
1012 | 1035 | $attr = wp_kses_html_error($attr); |
1036 | + } |
|
1013 | 1037 | $mode = 0; |
1014 | 1038 | } |
1015 | 1039 | } // while |
1016 | 1040 | |
1017 | - if ($mode == 1 && false === array_key_exists($attrname, $attrarr)) |
|
1018 | - // special case, for when the attribute list ends with a valueless |
|
1041 | + if ($mode == 1 && false === array_key_exists($attrname, $attrarr)) { |
|
1042 | + // special case, for when the attribute list ends with a valueless |
|
1019 | 1043 | // attribute like "selected" |
1020 | 1044 | $attrarr[$attrname] = array ('name' => $attrname, 'value' => '', 'whole' => $attrname, 'vless' => 'y'); |
1045 | + } |
|
1021 | 1046 | |
1022 | 1047 | return $attrarr; |
1023 | 1048 | } |
@@ -1148,16 +1173,18 @@ discard block |
||
1148 | 1173 | // greater than the given value. This can be used to avoid Buffer Overflows |
1149 | 1174 | // in WWW clients and various Internet servers. |
1150 | 1175 | |
1151 | - if (strlen($value) > $checkvalue) |
|
1152 | - $ok = false; |
|
1176 | + if (strlen($value) > $checkvalue) { |
|
1177 | + $ok = false; |
|
1178 | + } |
|
1153 | 1179 | break; |
1154 | 1180 | |
1155 | 1181 | case 'minlen' : |
1156 | 1182 | // The minlen check makes sure that the attribute value has a length not |
1157 | 1183 | // smaller than the given value. |
1158 | 1184 | |
1159 | - if (strlen($value) < $checkvalue) |
|
1160 | - $ok = false; |
|
1185 | + if (strlen($value) < $checkvalue) { |
|
1186 | + $ok = false; |
|
1187 | + } |
|
1161 | 1188 | break; |
1162 | 1189 | |
1163 | 1190 | case 'maxval' : |
@@ -1167,20 +1194,24 @@ discard block |
||
1167 | 1194 | // value is not greater than the given value. |
1168 | 1195 | // This check can be used to avoid Denial of Service attacks. |
1169 | 1196 | |
1170 | - if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value)) |
|
1171 | - $ok = false; |
|
1172 | - if ($value > $checkvalue) |
|
1173 | - $ok = false; |
|
1197 | + if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value)) { |
|
1198 | + $ok = false; |
|
1199 | + } |
|
1200 | + if ($value > $checkvalue) { |
|
1201 | + $ok = false; |
|
1202 | + } |
|
1174 | 1203 | break; |
1175 | 1204 | |
1176 | 1205 | case 'minval' : |
1177 | 1206 | // The minval check makes sure that the attribute value is a positive integer, |
1178 | 1207 | // and that it is not smaller than the given value. |
1179 | 1208 | |
1180 | - if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value)) |
|
1181 | - $ok = false; |
|
1182 | - if ($value < $checkvalue) |
|
1183 | - $ok = false; |
|
1209 | + if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value)) { |
|
1210 | + $ok = false; |
|
1211 | + } |
|
1212 | + if ($value < $checkvalue) { |
|
1213 | + $ok = false; |
|
1214 | + } |
|
1184 | 1215 | break; |
1185 | 1216 | |
1186 | 1217 | case 'valueless' : |
@@ -1189,8 +1220,9 @@ discard block |
||
1189 | 1220 | // is a "y" or a "Y", the attribute must not have a value. |
1190 | 1221 | // If the given value is an "n" or an "N", the attribute must have one. |
1191 | 1222 | |
1192 | - if (strtolower($checkvalue) != $vless) |
|
1193 | - $ok = false; |
|
1223 | + if (strtolower($checkvalue) != $vless) { |
|
1224 | + $ok = false; |
|
1225 | + } |
|
1194 | 1226 | break; |
1195 | 1227 | } // switch |
1196 | 1228 | |
@@ -1220,8 +1252,9 @@ discard block |
||
1220 | 1252 | $string = wp_kses_bad_protocol_once($string, $allowed_protocols); |
1221 | 1253 | } while ( $original_string != $string && ++$iterations < 6 ); |
1222 | 1254 | |
1223 | - if ( $original_string != $string ) |
|
1224 | - return ''; |
|
1255 | + if ( $original_string != $string ) { |
|
1256 | + return ''; |
|
1257 | + } |
|
1225 | 1258 | |
1226 | 1259 | return $string; |
1227 | 1260 | } |
@@ -1335,11 +1368,13 @@ discard block |
||
1335 | 1368 | $string = trim( $string2[1] ); |
1336 | 1369 | $protocol = wp_kses_bad_protocol_once2( $string2[0], $allowed_protocols ); |
1337 | 1370 | if ( 'feed:' == $protocol ) { |
1338 | - if ( $count > 2 ) |
|
1339 | - return ''; |
|
1371 | + if ( $count > 2 ) { |
|
1372 | + return ''; |
|
1373 | + } |
|
1340 | 1374 | $string = wp_kses_bad_protocol_once( $string, $allowed_protocols, ++$count ); |
1341 | - if ( empty( $string ) ) |
|
1342 | - return $string; |
|
1375 | + if ( empty( $string ) ) { |
|
1376 | + return $string; |
|
1377 | + } |
|
1343 | 1378 | } |
1344 | 1379 | $string = $protocol . $string; |
1345 | 1380 | } |
@@ -1367,17 +1402,19 @@ discard block |
||
1367 | 1402 | $string2 = strtolower($string2); |
1368 | 1403 | |
1369 | 1404 | $allowed = false; |
1370 | - foreach ( (array) $allowed_protocols as $one_protocol ) |
|
1371 | - if ( strtolower($one_protocol) == $string2 ) { |
|
1405 | + foreach ( (array) $allowed_protocols as $one_protocol ) { |
|
1406 | + if ( strtolower($one_protocol) == $string2 ) { |
|
1372 | 1407 | $allowed = true; |
1408 | + } |
|
1373 | 1409 | break; |
1374 | 1410 | } |
1375 | 1411 | |
1376 | - if ($allowed) |
|
1377 | - return "$string2:"; |
|
1378 | - else |
|
1379 | - return ''; |
|
1380 | -} |
|
1412 | + if ($allowed) { |
|
1413 | + return "$string2:"; |
|
1414 | + } else { |
|
1415 | + return ''; |
|
1416 | + } |
|
1417 | + } |
|
1381 | 1418 | |
1382 | 1419 | /** |
1383 | 1420 | * Converts and fixes HTML entities. |
@@ -1418,8 +1455,9 @@ discard block |
||
1418 | 1455 | function wp_kses_named_entities($matches) { |
1419 | 1456 | global $allowedentitynames; |
1420 | 1457 | |
1421 | - if ( empty($matches[1]) ) |
|
1422 | - return ''; |
|
1458 | + if ( empty($matches[1]) ) { |
|
1459 | + return ''; |
|
1460 | + } |
|
1423 | 1461 | |
1424 | 1462 | $i = $matches[1]; |
1425 | 1463 | return ( ! in_array( $i, $allowedentitynames ) ) ? "&$i;" : "&$i;"; |
@@ -1438,8 +1476,9 @@ discard block |
||
1438 | 1476 | * @return string Correctly encoded entity |
1439 | 1477 | */ |
1440 | 1478 | function wp_kses_normalize_entities2($matches) { |
1441 | - if ( empty($matches[1]) ) |
|
1442 | - return ''; |
|
1479 | + if ( empty($matches[1]) ) { |
|
1480 | + return ''; |
|
1481 | + } |
|
1443 | 1482 | |
1444 | 1483 | $i = $matches[1]; |
1445 | 1484 | if (valid_unicode($i)) { |
@@ -1464,8 +1503,9 @@ discard block |
||
1464 | 1503 | * @return string Correctly encoded entity |
1465 | 1504 | */ |
1466 | 1505 | function wp_kses_normalize_entities3($matches) { |
1467 | - if ( empty($matches[1]) ) |
|
1468 | - return ''; |
|
1506 | + if ( empty($matches[1]) ) { |
|
1507 | + return ''; |
|
1508 | + } |
|
1469 | 1509 | |
1470 | 1510 | $hexchars = $matches[1]; |
1471 | 1511 | return ( ! valid_unicode( hexdec( $hexchars ) ) ) ? "&#x$hexchars;" : '&#x'.ltrim($hexchars,'0').';'; |
@@ -1605,10 +1645,11 @@ discard block |
||
1605 | 1645 | add_filter('title_save_pre', 'wp_filter_kses'); |
1606 | 1646 | |
1607 | 1647 | // Comment filtering |
1608 | - if ( current_user_can( 'unfiltered_html' ) ) |
|
1609 | - add_filter( 'pre_comment_content', 'wp_filter_post_kses' ); |
|
1610 | - else |
|
1611 | - add_filter( 'pre_comment_content', 'wp_filter_kses' ); |
|
1648 | + if ( current_user_can( 'unfiltered_html' ) ) { |
|
1649 | + add_filter( 'pre_comment_content', 'wp_filter_post_kses' ); |
|
1650 | + } else { |
|
1651 | + add_filter( 'pre_comment_content', 'wp_filter_kses' ); |
|
1652 | + } |
|
1612 | 1653 | |
1613 | 1654 | // Post filtering |
1614 | 1655 | add_filter('content_save_pre', 'wp_filter_post_kses'); |
@@ -1669,14 +1710,18 @@ discard block |
||
1669 | 1710 | * @since 2.8.1 |
1670 | 1711 | */ |
1671 | 1712 | function safecss_filter_attr( $css, $deprecated = '' ) { |
1672 | - if ( !empty( $deprecated ) ) |
|
1673 | - _deprecated_argument( __FUNCTION__, '2.8.1' ); // Never implemented |
|
1713 | + if ( !empty( $deprecated ) ) { |
|
1714 | + _deprecated_argument( __FUNCTION__, '2.8.1' ); |
|
1715 | + } |
|
1716 | + // Never implemented |
|
1674 | 1717 | |
1675 | 1718 | $css = wp_kses_no_null($css); |
1676 | 1719 | $css = str_replace(array("\n","\r","\t"), '', $css); |
1677 | 1720 | |
1678 | - if ( preg_match( '%[\\\\(&=}]|/\*%', $css ) ) // remove any inline css containing \ ( & } = or comments |
|
1721 | + if ( preg_match( '%[\\\\(&=}]|/\*%', $css ) ) { |
|
1722 | + // remove any inline css containing \ ( & } = or comments |
|
1679 | 1723 | return ''; |
1724 | + } |
|
1680 | 1725 | |
1681 | 1726 | $css_array = explode( ';', trim( $css ) ); |
1682 | 1727 | |
@@ -1699,25 +1744,29 @@ discard block |
||
1699 | 1744 | 'padding-left', 'padding-right', 'padding-top', 'text-decoration', 'text-indent', 'vertical-align', |
1700 | 1745 | 'width' ) ); |
1701 | 1746 | |
1702 | - if ( empty($allowed_attr) ) |
|
1703 | - return $css; |
|
1747 | + if ( empty($allowed_attr) ) { |
|
1748 | + return $css; |
|
1749 | + } |
|
1704 | 1750 | |
1705 | 1751 | $css = ''; |
1706 | 1752 | foreach ( $css_array as $css_item ) { |
1707 | - if ( $css_item == '' ) |
|
1708 | - continue; |
|
1753 | + if ( $css_item == '' ) { |
|
1754 | + continue; |
|
1755 | + } |
|
1709 | 1756 | $css_item = trim( $css_item ); |
1710 | 1757 | $found = false; |
1711 | 1758 | if ( strpos( $css_item, ':' ) === false ) { |
1712 | 1759 | $found = true; |
1713 | 1760 | } else { |
1714 | 1761 | $parts = explode( ':', $css_item ); |
1715 | - if ( in_array( trim( $parts[0] ), $allowed_attr ) ) |
|
1716 | - $found = true; |
|
1762 | + if ( in_array( trim( $parts[0] ), $allowed_attr ) ) { |
|
1763 | + $found = true; |
|
1764 | + } |
|
1717 | 1765 | } |
1718 | 1766 | if ( $found ) { |
1719 | - if( $css != '' ) |
|
1720 | - $css .= ';'; |
|
1767 | + if( $css != '' ) { |
|
1768 | + $css .= ';'; |
|
1769 | + } |
|
1721 | 1770 | $css .= $css_item; |
1722 | 1771 | } |
1723 | 1772 | } |
@@ -1743,11 +1792,13 @@ discard block |
||
1743 | 1792 | 'role' => true, |
1744 | 1793 | ); |
1745 | 1794 | |
1746 | - if ( true === $value ) |
|
1747 | - $value = array(); |
|
1795 | + if ( true === $value ) { |
|
1796 | + $value = array(); |
|
1797 | + } |
|
1748 | 1798 | |
1749 | - if ( is_array( $value ) ) |
|
1750 | - return array_merge( $value, $global_attributes ); |
|
1799 | + if ( is_array( $value ) ) { |
|
1800 | + return array_merge( $value, $global_attributes ); |
|
1801 | + } |
|
1751 | 1802 | |
1752 | 1803 | return $value; |
1753 | 1804 | } |
@@ -41,14 +41,14 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @since 1.2.0 |
43 | 43 | */ |
44 | -if ( ! defined( 'CUSTOM_TAGS' ) ) |
|
45 | - define( 'CUSTOM_TAGS', false ); |
|
44 | +if ( ! defined('CUSTOM_TAGS')) |
|
45 | + define('CUSTOM_TAGS', false); |
|
46 | 46 | |
47 | 47 | // Ensure that these variables are added to the global namespace |
48 | 48 | // (e.g. if using namespaces / autoload in the current PHP environment). |
49 | 49 | global $allowedposttags, $allowedtags, $allowedentitynames; |
50 | 50 | |
51 | -if ( ! CUSTOM_TAGS ) { |
|
51 | +if ( ! CUSTOM_TAGS) { |
|
52 | 52 | /** |
53 | 53 | * Kses global for default allowable HTML tags. |
54 | 54 | * |
@@ -451,55 +451,55 @@ discard block |
||
451 | 451 | ); |
452 | 452 | |
453 | 453 | $allowedentitynames = array( |
454 | - 'nbsp', 'iexcl', 'cent', 'pound', 'curren', 'yen', |
|
455 | - 'brvbar', 'sect', 'uml', 'copy', 'ordf', 'laquo', |
|
456 | - 'not', 'shy', 'reg', 'macr', 'deg', 'plusmn', |
|
457 | - 'acute', 'micro', 'para', 'middot', 'cedil', 'ordm', |
|
458 | - 'raquo', 'iquest', 'Agrave', 'Aacute', 'Acirc', 'Atilde', |
|
459 | - 'Auml', 'Aring', 'AElig', 'Ccedil', 'Egrave', 'Eacute', |
|
460 | - 'Ecirc', 'Euml', 'Igrave', 'Iacute', 'Icirc', 'Iuml', |
|
461 | - 'ETH', 'Ntilde', 'Ograve', 'Oacute', 'Ocirc', 'Otilde', |
|
462 | - 'Ouml', 'times', 'Oslash', 'Ugrave', 'Uacute', 'Ucirc', |
|
463 | - 'Uuml', 'Yacute', 'THORN', 'szlig', 'agrave', 'aacute', |
|
464 | - 'acirc', 'atilde', 'auml', 'aring', 'aelig', 'ccedil', |
|
465 | - 'egrave', 'eacute', 'ecirc', 'euml', 'igrave', 'iacute', |
|
466 | - 'icirc', 'iuml', 'eth', 'ntilde', 'ograve', 'oacute', |
|
467 | - 'ocirc', 'otilde', 'ouml', 'divide', 'oslash', 'ugrave', |
|
468 | - 'uacute', 'ucirc', 'uuml', 'yacute', 'thorn', 'yuml', |
|
469 | - 'quot', 'amp', 'lt', 'gt', 'apos', 'OElig', |
|
470 | - 'oelig', 'Scaron', 'scaron', 'Yuml', 'circ', 'tilde', |
|
471 | - 'ensp', 'emsp', 'thinsp', 'zwnj', 'zwj', 'lrm', |
|
472 | - 'rlm', 'ndash', 'mdash', 'lsquo', 'rsquo', 'sbquo', |
|
473 | - 'ldquo', 'rdquo', 'bdquo', 'dagger', 'Dagger', 'permil', |
|
474 | - 'lsaquo', 'rsaquo', 'euro', 'fnof', 'Alpha', 'Beta', |
|
475 | - 'Gamma', 'Delta', 'Epsilon', 'Zeta', 'Eta', 'Theta', |
|
476 | - 'Iota', 'Kappa', 'Lambda', 'Mu', 'Nu', 'Xi', |
|
477 | - 'Omicron', 'Pi', 'Rho', 'Sigma', 'Tau', 'Upsilon', |
|
478 | - 'Phi', 'Chi', 'Psi', 'Omega', 'alpha', 'beta', |
|
479 | - 'gamma', 'delta', 'epsilon', 'zeta', 'eta', 'theta', |
|
480 | - 'iota', 'kappa', 'lambda', 'mu', 'nu', 'xi', |
|
481 | - 'omicron', 'pi', 'rho', 'sigmaf', 'sigma', 'tau', |
|
482 | - 'upsilon', 'phi', 'chi', 'psi', 'omega', 'thetasym', |
|
483 | - 'upsih', 'piv', 'bull', 'hellip', 'prime', 'Prime', |
|
484 | - 'oline', 'frasl', 'weierp', 'image', 'real', 'trade', |
|
485 | - 'alefsym', 'larr', 'uarr', 'rarr', 'darr', 'harr', |
|
486 | - 'crarr', 'lArr', 'uArr', 'rArr', 'dArr', 'hArr', |
|
487 | - 'forall', 'part', 'exist', 'empty', 'nabla', 'isin', |
|
488 | - 'notin', 'ni', 'prod', 'sum', 'minus', 'lowast', |
|
489 | - 'radic', 'prop', 'infin', 'ang', 'and', 'or', |
|
490 | - 'cap', 'cup', 'int', 'sim', 'cong', 'asymp', |
|
491 | - 'ne', 'equiv', 'le', 'ge', 'sub', 'sup', |
|
492 | - 'nsub', 'sube', 'supe', 'oplus', 'otimes', 'perp', |
|
493 | - 'sdot', 'lceil', 'rceil', 'lfloor', 'rfloor', 'lang', |
|
494 | - 'rang', 'loz', 'spades', 'clubs', 'hearts', 'diams', |
|
495 | - 'sup1', 'sup2', 'sup3', 'frac14', 'frac12', 'frac34', |
|
454 | + 'nbsp', 'iexcl', 'cent', 'pound', 'curren', 'yen', |
|
455 | + 'brvbar', 'sect', 'uml', 'copy', 'ordf', 'laquo', |
|
456 | + 'not', 'shy', 'reg', 'macr', 'deg', 'plusmn', |
|
457 | + 'acute', 'micro', 'para', 'middot', 'cedil', 'ordm', |
|
458 | + 'raquo', 'iquest', 'Agrave', 'Aacute', 'Acirc', 'Atilde', |
|
459 | + 'Auml', 'Aring', 'AElig', 'Ccedil', 'Egrave', 'Eacute', |
|
460 | + 'Ecirc', 'Euml', 'Igrave', 'Iacute', 'Icirc', 'Iuml', |
|
461 | + 'ETH', 'Ntilde', 'Ograve', 'Oacute', 'Ocirc', 'Otilde', |
|
462 | + 'Ouml', 'times', 'Oslash', 'Ugrave', 'Uacute', 'Ucirc', |
|
463 | + 'Uuml', 'Yacute', 'THORN', 'szlig', 'agrave', 'aacute', |
|
464 | + 'acirc', 'atilde', 'auml', 'aring', 'aelig', 'ccedil', |
|
465 | + 'egrave', 'eacute', 'ecirc', 'euml', 'igrave', 'iacute', |
|
466 | + 'icirc', 'iuml', 'eth', 'ntilde', 'ograve', 'oacute', |
|
467 | + 'ocirc', 'otilde', 'ouml', 'divide', 'oslash', 'ugrave', |
|
468 | + 'uacute', 'ucirc', 'uuml', 'yacute', 'thorn', 'yuml', |
|
469 | + 'quot', 'amp', 'lt', 'gt', 'apos', 'OElig', |
|
470 | + 'oelig', 'Scaron', 'scaron', 'Yuml', 'circ', 'tilde', |
|
471 | + 'ensp', 'emsp', 'thinsp', 'zwnj', 'zwj', 'lrm', |
|
472 | + 'rlm', 'ndash', 'mdash', 'lsquo', 'rsquo', 'sbquo', |
|
473 | + 'ldquo', 'rdquo', 'bdquo', 'dagger', 'Dagger', 'permil', |
|
474 | + 'lsaquo', 'rsaquo', 'euro', 'fnof', 'Alpha', 'Beta', |
|
475 | + 'Gamma', 'Delta', 'Epsilon', 'Zeta', 'Eta', 'Theta', |
|
476 | + 'Iota', 'Kappa', 'Lambda', 'Mu', 'Nu', 'Xi', |
|
477 | + 'Omicron', 'Pi', 'Rho', 'Sigma', 'Tau', 'Upsilon', |
|
478 | + 'Phi', 'Chi', 'Psi', 'Omega', 'alpha', 'beta', |
|
479 | + 'gamma', 'delta', 'epsilon', 'zeta', 'eta', 'theta', |
|
480 | + 'iota', 'kappa', 'lambda', 'mu', 'nu', 'xi', |
|
481 | + 'omicron', 'pi', 'rho', 'sigmaf', 'sigma', 'tau', |
|
482 | + 'upsilon', 'phi', 'chi', 'psi', 'omega', 'thetasym', |
|
483 | + 'upsih', 'piv', 'bull', 'hellip', 'prime', 'Prime', |
|
484 | + 'oline', 'frasl', 'weierp', 'image', 'real', 'trade', |
|
485 | + 'alefsym', 'larr', 'uarr', 'rarr', 'darr', 'harr', |
|
486 | + 'crarr', 'lArr', 'uArr', 'rArr', 'dArr', 'hArr', |
|
487 | + 'forall', 'part', 'exist', 'empty', 'nabla', 'isin', |
|
488 | + 'notin', 'ni', 'prod', 'sum', 'minus', 'lowast', |
|
489 | + 'radic', 'prop', 'infin', 'ang', 'and', 'or', |
|
490 | + 'cap', 'cup', 'int', 'sim', 'cong', 'asymp', |
|
491 | + 'ne', 'equiv', 'le', 'ge', 'sub', 'sup', |
|
492 | + 'nsub', 'sube', 'supe', 'oplus', 'otimes', 'perp', |
|
493 | + 'sdot', 'lceil', 'rceil', 'lfloor', 'rfloor', 'lang', |
|
494 | + 'rang', 'loz', 'spades', 'clubs', 'hearts', 'diams', |
|
495 | + 'sup1', 'sup2', 'sup3', 'frac14', 'frac12', 'frac34', |
|
496 | 496 | 'there4', |
497 | 497 | ); |
498 | 498 | |
499 | - $allowedposttags = array_map( '_wp_add_global_attributes', $allowedposttags ); |
|
499 | + $allowedposttags = array_map('_wp_add_global_attributes', $allowedposttags); |
|
500 | 500 | } else { |
501 | - $allowedtags = wp_kses_array_lc( $allowedtags ); |
|
502 | - $allowedposttags = wp_kses_array_lc( $allowedposttags ); |
|
501 | + $allowedtags = wp_kses_array_lc($allowedtags); |
|
502 | + $allowedposttags = wp_kses_array_lc($allowedposttags); |
|
503 | 503 | } |
504 | 504 | |
505 | 505 | /** |
@@ -522,10 +522,10 @@ discard block |
||
522 | 522 | * @param array $allowed_protocols Optional. Allowed protocol in links. |
523 | 523 | * @return string Filtered content with only allowed HTML elements |
524 | 524 | */ |
525 | -function wp_kses( $string, $allowed_html, $allowed_protocols = array() ) { |
|
526 | - if ( empty( $allowed_protocols ) ) |
|
525 | +function wp_kses($string, $allowed_html, $allowed_protocols = array()) { |
|
526 | + if (empty($allowed_protocols)) |
|
527 | 527 | $allowed_protocols = wp_allowed_protocols(); |
528 | - $string = wp_kses_no_null( $string, array( 'slash_zero' => 'keep' ) ); |
|
528 | + $string = wp_kses_no_null($string, array('slash_zero' => 'keep')); |
|
529 | 529 | $string = wp_kses_js_entities($string); |
530 | 530 | $string = wp_kses_normalize_entities($string); |
531 | 531 | $string = wp_kses_hook($string, $allowed_html, $allowed_protocols); // WP changed the order of these funcs and added args to wp_kses_hook |
@@ -544,12 +544,12 @@ discard block |
||
544 | 544 | * @param string $element The element name to which the attribute belongs. |
545 | 545 | * @return string Filtered attribute. |
546 | 546 | */ |
547 | -function wp_kses_one_attr( $string, $element ) { |
|
547 | +function wp_kses_one_attr($string, $element) { |
|
548 | 548 | $uris = array('xmlns', 'profile', 'href', 'src', 'cite', 'classid', 'codebase', 'data', 'usemap', 'longdesc', 'action'); |
549 | - $allowed_html = wp_kses_allowed_html( 'post' ); |
|
549 | + $allowed_html = wp_kses_allowed_html('post'); |
|
550 | 550 | $allowed_protocols = wp_allowed_protocols(); |
551 | - $string = wp_kses_no_null( $string, array( 'slash_zero' => 'keep' ) ); |
|
552 | - $string = wp_kses_js_entities( $string ); |
|
551 | + $string = wp_kses_no_null($string, array('slash_zero' => 'keep')); |
|
552 | + $string = wp_kses_js_entities($string); |
|
553 | 553 | |
554 | 554 | // Preserve leading and trailing whitespace. |
555 | 555 | $matches = array(); |
@@ -557,40 +557,40 @@ discard block |
||
557 | 557 | $lead = $matches[0]; |
558 | 558 | preg_match('/\s*$/', $string, $matches); |
559 | 559 | $trail = $matches[0]; |
560 | - if ( empty( $trail ) ) { |
|
561 | - $string = substr( $string, strlen( $lead ) ); |
|
560 | + if (empty($trail)) { |
|
561 | + $string = substr($string, strlen($lead)); |
|
562 | 562 | } else { |
563 | - $string = substr( $string, strlen( $lead ), -strlen( $trail ) ); |
|
563 | + $string = substr($string, strlen($lead), -strlen($trail)); |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | // Parse attribute name and value from input. |
567 | - $split = preg_split( '/\s*=\s*/', $string, 2 ); |
|
567 | + $split = preg_split('/\s*=\s*/', $string, 2); |
|
568 | 568 | $name = $split[0]; |
569 | - if ( count( $split ) == 2 ) { |
|
569 | + if (count($split) == 2) { |
|
570 | 570 | $value = $split[1]; |
571 | 571 | |
572 | 572 | // Remove quotes surrounding $value. |
573 | 573 | // Also guarantee correct quoting in $string for this one attribute. |
574 | - if ( '' == $value ) { |
|
574 | + if ('' == $value) { |
|
575 | 575 | $quote = ''; |
576 | 576 | } else { |
577 | 577 | $quote = $value[0]; |
578 | 578 | } |
579 | - if ( '"' == $quote || "'" == $quote ) { |
|
580 | - if ( substr( $value, -1 ) != $quote ) { |
|
579 | + if ('"' == $quote || "'" == $quote) { |
|
580 | + if (substr($value, -1) != $quote) { |
|
581 | 581 | return ''; |
582 | 582 | } |
583 | - $value = substr( $value, 1, -1 ); |
|
583 | + $value = substr($value, 1, -1); |
|
584 | 584 | } else { |
585 | 585 | $quote = '"'; |
586 | 586 | } |
587 | 587 | |
588 | 588 | // Sanitize quotes, angle braces, and entities. |
589 | - $value = esc_attr( $value ); |
|
589 | + $value = esc_attr($value); |
|
590 | 590 | |
591 | 591 | // Sanitize URI values. |
592 | - if ( in_array( strtolower( $name ), $uris ) ) { |
|
593 | - $value = wp_kses_bad_protocol( $value, $allowed_protocols ); |
|
592 | + if (in_array(strtolower($name), $uris)) { |
|
593 | + $value = wp_kses_bad_protocol($value, $allowed_protocols); |
|
594 | 594 | } |
595 | 595 | |
596 | 596 | $string = "$name=$quote$value$quote"; |
@@ -601,10 +601,10 @@ discard block |
||
601 | 601 | } |
602 | 602 | |
603 | 603 | // Sanitize attribute by name. |
604 | - wp_kses_attr_check( $name, $value, $string, $vless, $element, $allowed_html ); |
|
604 | + wp_kses_attr_check($name, $value, $string, $vless, $element, $allowed_html); |
|
605 | 605 | |
606 | 606 | // Restore whitespace. |
607 | - return $lead . $string . $trail; |
|
607 | + return $lead.$string.$trail; |
|
608 | 608 | } |
609 | 609 | |
610 | 610 | /** |
@@ -621,10 +621,10 @@ discard block |
||
621 | 621 | * the name of a field filter such as pre_user_description. |
622 | 622 | * @return array List of allowed tags and their allowed attributes. |
623 | 623 | */ |
624 | -function wp_kses_allowed_html( $context = '' ) { |
|
624 | +function wp_kses_allowed_html($context = '') { |
|
625 | 625 | global $allowedposttags, $allowedtags, $allowedentitynames; |
626 | 626 | |
627 | - if ( is_array( $context ) ) { |
|
627 | + if (is_array($context)) { |
|
628 | 628 | /** |
629 | 629 | * Filter HTML elements allowed for a given context. |
630 | 630 | * |
@@ -634,33 +634,33 @@ discard block |
||
634 | 634 | * @param string $context Context to judge allowed tags by. Allowed values are 'post', |
635 | 635 | * 'data', 'strip', 'entities', 'explicit', or the name of a filter. |
636 | 636 | */ |
637 | - return apply_filters( 'wp_kses_allowed_html', $context, 'explicit' ); |
|
637 | + return apply_filters('wp_kses_allowed_html', $context, 'explicit'); |
|
638 | 638 | } |
639 | 639 | |
640 | - switch ( $context ) { |
|
640 | + switch ($context) { |
|
641 | 641 | case 'post': |
642 | 642 | /** This filter is documented in wp-includes/kses.php */ |
643 | - return apply_filters( 'wp_kses_allowed_html', $allowedposttags, $context ); |
|
643 | + return apply_filters('wp_kses_allowed_html', $allowedposttags, $context); |
|
644 | 644 | |
645 | 645 | case 'user_description': |
646 | 646 | case 'pre_user_description': |
647 | 647 | $tags = $allowedtags; |
648 | 648 | $tags['a']['rel'] = true; |
649 | 649 | /** This filter is documented in wp-includes/kses.php */ |
650 | - return apply_filters( 'wp_kses_allowed_html', $tags, $context ); |
|
650 | + return apply_filters('wp_kses_allowed_html', $tags, $context); |
|
651 | 651 | |
652 | 652 | case 'strip': |
653 | 653 | /** This filter is documented in wp-includes/kses.php */ |
654 | - return apply_filters( 'wp_kses_allowed_html', array(), $context ); |
|
654 | + return apply_filters('wp_kses_allowed_html', array(), $context); |
|
655 | 655 | |
656 | 656 | case 'entities': |
657 | 657 | /** This filter is documented in wp-includes/kses.php */ |
658 | - return apply_filters( 'wp_kses_allowed_html', $allowedentitynames, $context); |
|
658 | + return apply_filters('wp_kses_allowed_html', $allowedentitynames, $context); |
|
659 | 659 | |
660 | 660 | case 'data': |
661 | 661 | default: |
662 | 662 | /** This filter is documented in wp-includes/kses.php */ |
663 | - return apply_filters( 'wp_kses_allowed_html', $allowedtags, $context ); |
|
663 | + return apply_filters('wp_kses_allowed_html', $allowedtags, $context); |
|
664 | 664 | } |
665 | 665 | } |
666 | 666 | |
@@ -677,7 +677,7 @@ discard block |
||
677 | 677 | * @param array $allowed_protocols Allowed protocol in links |
678 | 678 | * @return string Filtered content through 'pre_kses' hook |
679 | 679 | */ |
680 | -function wp_kses_hook( $string, $allowed_html, $allowed_protocols ) { |
|
680 | +function wp_kses_hook($string, $allowed_html, $allowed_protocols) { |
|
681 | 681 | /** |
682 | 682 | * Filter content to be run through kses. |
683 | 683 | * |
@@ -687,7 +687,7 @@ discard block |
||
687 | 687 | * @param array $allowed_html Allowed HTML elements. |
688 | 688 | * @param array $allowed_protocols Allowed protocol in links. |
689 | 689 | */ |
690 | - return apply_filters( 'pre_kses', $string, $allowed_html, $allowed_protocols ); |
|
690 | + return apply_filters('pre_kses', $string, $allowed_html, $allowed_protocols); |
|
691 | 691 | } |
692 | 692 | |
693 | 693 | /** |
@@ -716,11 +716,11 @@ discard block |
||
716 | 716 | * @param array $allowed_protocols Allowed protocols to keep |
717 | 717 | * @return string Content with fixed HTML tags |
718 | 718 | */ |
719 | -function wp_kses_split( $string, $allowed_html, $allowed_protocols ) { |
|
719 | +function wp_kses_split($string, $allowed_html, $allowed_protocols) { |
|
720 | 720 | global $pass_allowed_html, $pass_allowed_protocols; |
721 | 721 | $pass_allowed_html = $allowed_html; |
722 | 722 | $pass_allowed_protocols = $allowed_protocols; |
723 | - return preg_replace_callback( '%(<!--.*?(-->|$))|(<[^>]*(>|$)|>)%', '_wp_kses_split_callback', $string ); |
|
723 | + return preg_replace_callback('%(<!--.*?(-->|$))|(<[^>]*(>|$)|>)%', '_wp_kses_split_callback', $string); |
|
724 | 724 | } |
725 | 725 | |
726 | 726 | /** |
@@ -734,9 +734,9 @@ discard block |
||
734 | 734 | * |
735 | 735 | * @return string |
736 | 736 | */ |
737 | -function _wp_kses_split_callback( $match ) { |
|
737 | +function _wp_kses_split_callback($match) { |
|
738 | 738 | global $pass_allowed_html, $pass_allowed_protocols; |
739 | - return wp_kses_split2( $match[0], $pass_allowed_html, $pass_allowed_protocols ); |
|
739 | + return wp_kses_split2($match[0], $pass_allowed_html, $pass_allowed_protocols); |
|
740 | 740 | } |
741 | 741 | |
742 | 742 | /** |
@@ -766,11 +766,11 @@ discard block |
||
766 | 766 | return '>'; |
767 | 767 | // It matched a ">" character |
768 | 768 | |
769 | - if ( '<!--' == substr( $string, 0, 4 ) ) { |
|
770 | - $string = str_replace( array('<!--', '-->'), '', $string ); |
|
771 | - while ( $string != ($newstring = wp_kses($string, $allowed_html, $allowed_protocols)) ) |
|
769 | + if ('<!--' == substr($string, 0, 4)) { |
|
770 | + $string = str_replace(array('<!--', '-->'), '', $string); |
|
771 | + while ($string != ($newstring = wp_kses($string, $allowed_html, $allowed_protocols))) |
|
772 | 772 | $string = $newstring; |
773 | - if ( $string == '' ) |
|
773 | + if ($string == '') |
|
774 | 774 | return ''; |
775 | 775 | // prevent multiple dashes in comments |
776 | 776 | $string = preg_replace('/--+/', '-', $string); |
@@ -780,7 +780,7 @@ discard block |
||
780 | 780 | } |
781 | 781 | // Allow HTML comments |
782 | 782 | |
783 | - if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9]+)([^>]*)>?$%', $string, $matches)) |
|
783 | + if ( ! preg_match('%^<\s*(/\s*)?([a-zA-Z0-9]+)([^>]*)>?$%', $string, $matches)) |
|
784 | 784 | return ''; |
785 | 785 | // It's seriously malformed |
786 | 786 | |
@@ -788,10 +788,10 @@ discard block |
||
788 | 788 | $elem = $matches[2]; |
789 | 789 | $attrlist = $matches[3]; |
790 | 790 | |
791 | - if ( ! is_array( $allowed_html ) ) |
|
792 | - $allowed_html = wp_kses_allowed_html( $allowed_html ); |
|
791 | + if ( ! is_array($allowed_html)) |
|
792 | + $allowed_html = wp_kses_allowed_html($allowed_html); |
|
793 | 793 | |
794 | - if ( ! isset($allowed_html[strtolower($elem)]) ) |
|
794 | + if ( ! isset($allowed_html[strtolower($elem)])) |
|
795 | 795 | return ''; |
796 | 796 | // They are using a not allowed HTML element |
797 | 797 | |
@@ -799,7 +799,7 @@ discard block |
||
799 | 799 | return "</$elem>"; |
800 | 800 | // No attributes are allowed for closing elements |
801 | 801 | |
802 | - return wp_kses_attr( $elem, $attrlist, $allowed_html, $allowed_protocols ); |
|
802 | + return wp_kses_attr($elem, $attrlist, $allowed_html, $allowed_protocols); |
|
803 | 803 | } |
804 | 804 | |
805 | 805 | /** |
@@ -820,8 +820,8 @@ discard block |
||
820 | 820 | * @return string Sanitized HTML element |
821 | 821 | */ |
822 | 822 | function wp_kses_attr($element, $attr, $allowed_html, $allowed_protocols) { |
823 | - if ( ! is_array( $allowed_html ) ) |
|
824 | - $allowed_html = wp_kses_allowed_html( $allowed_html ); |
|
823 | + if ( ! is_array($allowed_html)) |
|
824 | + $allowed_html = wp_kses_allowed_html($allowed_html); |
|
825 | 825 | |
826 | 826 | // Is there a closing XHTML slash at the end of the attributes? |
827 | 827 | $xhtml_slash = ''; |
@@ -829,7 +829,7 @@ discard block |
||
829 | 829 | $xhtml_slash = ' /'; |
830 | 830 | |
831 | 831 | // Are any attributes allowed at all for this element? |
832 | - if ( ! isset($allowed_html[strtolower($element)]) || count($allowed_html[strtolower($element)]) == 0 ) |
|
832 | + if ( ! isset($allowed_html[strtolower($element)]) || count($allowed_html[strtolower($element)]) == 0) |
|
833 | 833 | return "<$element$xhtml_slash>"; |
834 | 834 | |
835 | 835 | // Split it |
@@ -838,8 +838,8 @@ discard block |
||
838 | 838 | // Go through $attrarr, and save the allowed attributes for this element |
839 | 839 | // in $attr2 |
840 | 840 | $attr2 = ''; |
841 | - foreach ( $attrarr as $arreach ) { |
|
842 | - if ( wp_kses_attr_check( $arreach['name'], $arreach['value'], $arreach['whole'], $arreach['vless'], $element, $allowed_html ) ) { |
|
841 | + foreach ($attrarr as $arreach) { |
|
842 | + if (wp_kses_attr_check($arreach['name'], $arreach['value'], $arreach['whole'], $arreach['vless'], $element, $allowed_html)) { |
|
843 | 843 | $attr2 .= ' '.$arreach['whole']; |
844 | 844 | } |
845 | 845 | } |
@@ -863,31 +863,31 @@ discard block |
||
863 | 863 | * @param array $allowed_html The full list of allowed elements and attributes. |
864 | 864 | * @return bool Is the attribute allowed? |
865 | 865 | */ |
866 | -function wp_kses_attr_check( &$name, &$value, &$whole, $vless, $element, $allowed_html ) { |
|
867 | - $allowed_attr = $allowed_html[strtolower( $element )]; |
|
866 | +function wp_kses_attr_check(&$name, &$value, &$whole, $vless, $element, $allowed_html) { |
|
867 | + $allowed_attr = $allowed_html[strtolower($element)]; |
|
868 | 868 | |
869 | - $name_low = strtolower( $name ); |
|
870 | - if ( ! isset( $allowed_attr[$name_low] ) || '' == $allowed_attr[$name_low] ) { |
|
869 | + $name_low = strtolower($name); |
|
870 | + if ( ! isset($allowed_attr[$name_low]) || '' == $allowed_attr[$name_low]) { |
|
871 | 871 | $name = $value = $whole = ''; |
872 | 872 | return false; |
873 | 873 | } |
874 | 874 | |
875 | - if ( 'style' == $name_low ) { |
|
876 | - $new_value = safecss_filter_attr( $value ); |
|
875 | + if ('style' == $name_low) { |
|
876 | + $new_value = safecss_filter_attr($value); |
|
877 | 877 | |
878 | - if ( empty( $new_value ) ) { |
|
878 | + if (empty($new_value)) { |
|
879 | 879 | $name = $value = $whole = ''; |
880 | 880 | return false; |
881 | 881 | } |
882 | 882 | |
883 | - $whole = str_replace( $value, $new_value, $whole ); |
|
883 | + $whole = str_replace($value, $new_value, $whole); |
|
884 | 884 | $value = $new_value; |
885 | 885 | } |
886 | 886 | |
887 | - if ( is_array( $allowed_attr[$name_low] ) ) { |
|
887 | + if (is_array($allowed_attr[$name_low])) { |
|
888 | 888 | // there are some checks |
889 | - foreach ( $allowed_attr[$name_low] as $currkey => $currval ) { |
|
890 | - if ( ! wp_kses_check_attr_val( $value, $vless, $currkey, $currval ) ) { |
|
889 | + foreach ($allowed_attr[$name_low] as $currkey => $currval) { |
|
890 | + if ( ! wp_kses_check_attr_val($value, $vless, $currkey, $currval)) { |
|
891 | 891 | $name = $value = $whole = ''; |
892 | 892 | return false; |
893 | 893 | } |
@@ -928,10 +928,10 @@ discard block |
||
928 | 928 | switch ($mode) { |
929 | 929 | case 0 : // attribute name, href for instance |
930 | 930 | |
931 | - if ( preg_match('/^([-a-zA-Z:]+)/', $attr, $match ) ) { |
|
931 | + if (preg_match('/^([-a-zA-Z:]+)/', $attr, $match)) { |
|
932 | 932 | $attrname = $match[1]; |
933 | 933 | $working = $mode = 1; |
934 | - $attr = preg_replace( '/^[-a-zA-Z:]+/', '', $attr ); |
|
934 | + $attr = preg_replace('/^[-a-zA-Z:]+/', '', $attr); |
|
935 | 935 | } |
936 | 936 | |
937 | 937 | break; |
@@ -950,8 +950,8 @@ discard block |
||
950 | 950 | { |
951 | 951 | $working = 1; |
952 | 952 | $mode = 0; |
953 | - if(false === array_key_exists($attrname, $attrarr)) { |
|
954 | - $attrarr[$attrname] = array ('name' => $attrname, 'value' => '', 'whole' => $attrname, 'vless' => 'y'); |
|
953 | + if (false === array_key_exists($attrname, $attrarr)) { |
|
954 | + $attrarr[$attrname] = array('name' => $attrname, 'value' => '', 'whole' => $attrname, 'vless' => 'y'); |
|
955 | 955 | } |
956 | 956 | $attr = preg_replace('/^\s+/', '', $attr); |
957 | 957 | } |
@@ -964,11 +964,11 @@ discard block |
||
964 | 964 | // "value" |
965 | 965 | { |
966 | 966 | $thisval = $match[1]; |
967 | - if ( in_array(strtolower($attrname), $uris) ) |
|
967 | + if (in_array(strtolower($attrname), $uris)) |
|
968 | 968 | $thisval = wp_kses_bad_protocol($thisval, $allowed_protocols); |
969 | 969 | |
970 | - if(false === array_key_exists($attrname, $attrarr)) { |
|
971 | - $attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname=\"$thisval\"", 'vless' => 'n'); |
|
970 | + if (false === array_key_exists($attrname, $attrarr)) { |
|
971 | + $attrarr[$attrname] = array('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname=\"$thisval\"", 'vless' => 'n'); |
|
972 | 972 | } |
973 | 973 | $working = 1; |
974 | 974 | $mode = 0; |
@@ -980,11 +980,11 @@ discard block |
||
980 | 980 | // 'value' |
981 | 981 | { |
982 | 982 | $thisval = $match[1]; |
983 | - if ( in_array(strtolower($attrname), $uris) ) |
|
983 | + if (in_array(strtolower($attrname), $uris)) |
|
984 | 984 | $thisval = wp_kses_bad_protocol($thisval, $allowed_protocols); |
985 | 985 | |
986 | - if(false === array_key_exists($attrname, $attrarr)) { |
|
987 | - $attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname='$thisval'", 'vless' => 'n'); |
|
986 | + if (false === array_key_exists($attrname, $attrarr)) { |
|
987 | + $attrarr[$attrname] = array('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname='$thisval'", 'vless' => 'n'); |
|
988 | 988 | } |
989 | 989 | $working = 1; |
990 | 990 | $mode = 0; |
@@ -996,11 +996,11 @@ discard block |
||
996 | 996 | // value |
997 | 997 | { |
998 | 998 | $thisval = $match[1]; |
999 | - if ( in_array(strtolower($attrname), $uris) ) |
|
999 | + if (in_array(strtolower($attrname), $uris)) |
|
1000 | 1000 | $thisval = wp_kses_bad_protocol($thisval, $allowed_protocols); |
1001 | 1001 | |
1002 | - if(false === array_key_exists($attrname, $attrarr)) { |
|
1003 | - $attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname=\"$thisval\"", 'vless' => 'n'); |
|
1002 | + if (false === array_key_exists($attrname, $attrarr)) { |
|
1003 | + $attrarr[$attrname] = array('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname=\"$thisval\"", 'vless' => 'n'); |
|
1004 | 1004 | } |
1005 | 1005 | // We add quotes to conform to W3C's HTML spec. |
1006 | 1006 | $working = 1; |
@@ -1021,7 +1021,7 @@ discard block |
||
1021 | 1021 | if ($mode == 1 && false === array_key_exists($attrname, $attrarr)) |
1022 | 1022 | // special case, for when the attribute list ends with a valueless |
1023 | 1023 | // attribute like "selected" |
1024 | - $attrarr[$attrname] = array ('name' => $attrname, 'value' => '', 'whole' => $attrname, 'vless' => 'y'); |
|
1024 | + $attrarr[$attrname] = array('name' => $attrname, 'value' => '', 'whole' => $attrname, 'vless' => 'y'); |
|
1025 | 1025 | |
1026 | 1026 | return $attrarr; |
1027 | 1027 | } |
@@ -1038,40 +1038,40 @@ discard block |
||
1038 | 1038 | * @param string $element HTML element/tag |
1039 | 1039 | * @return array|bool List of attributes found in $element. Returns false on failure. |
1040 | 1040 | */ |
1041 | -function wp_kses_attr_parse( $element ) { |
|
1041 | +function wp_kses_attr_parse($element) { |
|
1042 | 1042 | $valid = preg_match('%^(<\s*)(/\s*)?([a-zA-Z0-9]+\s*)([^>]*)(>?)$%', $element, $matches); |
1043 | - if ( 1 !== $valid ) { |
|
1043 | + if (1 !== $valid) { |
|
1044 | 1044 | return false; |
1045 | 1045 | } |
1046 | 1046 | |
1047 | - $begin = $matches[1]; |
|
1048 | - $slash = $matches[2]; |
|
1047 | + $begin = $matches[1]; |
|
1048 | + $slash = $matches[2]; |
|
1049 | 1049 | $elname = $matches[3]; |
1050 | - $attr = $matches[4]; |
|
1051 | - $end = $matches[5]; |
|
1050 | + $attr = $matches[4]; |
|
1051 | + $end = $matches[5]; |
|
1052 | 1052 | |
1053 | - if ( '' !== $slash ) { |
|
1053 | + if ('' !== $slash) { |
|
1054 | 1054 | // Closing elements do not get parsed. |
1055 | 1055 | return false; |
1056 | 1056 | } |
1057 | 1057 | |
1058 | 1058 | // Is there a closing XHTML slash at the end of the attributes? |
1059 | - if ( 1 === preg_match( '%\s*/\s*$%', $attr, $matches ) ) { |
|
1059 | + if (1 === preg_match('%\s*/\s*$%', $attr, $matches)) { |
|
1060 | 1060 | $xhtml_slash = $matches[0]; |
1061 | - $attr = substr( $attr, 0, -strlen( $xhtml_slash ) ); |
|
1061 | + $attr = substr($attr, 0, -strlen($xhtml_slash)); |
|
1062 | 1062 | } else { |
1063 | 1063 | $xhtml_slash = ''; |
1064 | 1064 | } |
1065 | 1065 | |
1066 | 1066 | // Split it |
1067 | - $attrarr = wp_kses_hair_parse( $attr ); |
|
1068 | - if ( false === $attrarr ) { |
|
1067 | + $attrarr = wp_kses_hair_parse($attr); |
|
1068 | + if (false === $attrarr) { |
|
1069 | 1069 | return false; |
1070 | 1070 | } |
1071 | 1071 | |
1072 | 1072 | // Make sure all input is returned by adding front and back matter. |
1073 | - array_unshift( $attrarr, $begin . $slash . $elname ); |
|
1074 | - array_push( $attrarr, $xhtml_slash . $end ); |
|
1073 | + array_unshift($attrarr, $begin.$slash.$elname); |
|
1074 | + array_push($attrarr, $xhtml_slash.$end); |
|
1075 | 1075 | |
1076 | 1076 | return $attrarr; |
1077 | 1077 | } |
@@ -1089,8 +1089,8 @@ discard block |
||
1089 | 1089 | * @param string $attr Attribute list from HTML element to closing HTML element tag |
1090 | 1090 | * @return array|bool List of attributes found in $attr. Returns false on failure. |
1091 | 1091 | */ |
1092 | -function wp_kses_hair_parse( $attr ) { |
|
1093 | - if ( '' === $attr ) { |
|
1092 | +function wp_kses_hair_parse($attr) { |
|
1093 | + if ('' === $attr) { |
|
1094 | 1094 | return array(); |
1095 | 1095 | } |
1096 | 1096 | |
@@ -1113,7 +1113,7 @@ discard block |
||
1113 | 1113 | . '|' |
1114 | 1114 | . '(?:\s|$)' // If attribute has no value, space is required. |
1115 | 1115 | . ')' |
1116 | - . '\s*'; // Trailing space is optional except as mentioned above. |
|
1116 | + . '\s*'; // Trailing space is optional except as mentioned above. |
|
1117 | 1117 | |
1118 | 1118 | // Although it is possible to reduce this procedure to a single regexp, |
1119 | 1119 | // we must run that regexp twice to get exactly the expected result. |
@@ -1121,8 +1121,8 @@ discard block |
||
1121 | 1121 | $validation = "%^($regex)+$%"; |
1122 | 1122 | $extraction = "%$regex%"; |
1123 | 1123 | |
1124 | - if ( 1 === preg_match( $validation, $attr ) ) { |
|
1125 | - preg_match_all( $extraction, $attr, $attrarr ); |
|
1124 | + if (1 === preg_match($validation, $attr)) { |
|
1125 | + preg_match_all($extraction, $attr, $attrarr); |
|
1126 | 1126 | return $attrarr[0]; |
1127 | 1127 | } else { |
1128 | 1128 | return false; |
@@ -1171,7 +1171,7 @@ discard block |
||
1171 | 1171 | // value is not greater than the given value. |
1172 | 1172 | // This check can be used to avoid Denial of Service attacks. |
1173 | 1173 | |
1174 | - if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value)) |
|
1174 | + if ( ! preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value)) |
|
1175 | 1175 | $ok = false; |
1176 | 1176 | if ($value > $checkvalue) |
1177 | 1177 | $ok = false; |
@@ -1181,7 +1181,7 @@ discard block |
||
1181 | 1181 | // The minval check makes sure that the attribute value is a positive integer, |
1182 | 1182 | // and that it is not smaller than the given value. |
1183 | 1183 | |
1184 | - if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value)) |
|
1184 | + if ( ! preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value)) |
|
1185 | 1185 | $ok = false; |
1186 | 1186 | if ($value < $checkvalue) |
1187 | 1187 | $ok = false; |
@@ -1222,9 +1222,9 @@ discard block |
||
1222 | 1222 | do { |
1223 | 1223 | $original_string = $string; |
1224 | 1224 | $string = wp_kses_bad_protocol_once($string, $allowed_protocols); |
1225 | - } while ( $original_string != $string && ++$iterations < 6 ); |
|
1225 | + } while ($original_string != $string && ++$iterations < 6); |
|
1226 | 1226 | |
1227 | - if ( $original_string != $string ) |
|
1227 | + if ($original_string != $string) |
|
1228 | 1228 | return ''; |
1229 | 1229 | |
1230 | 1230 | return $string; |
@@ -1241,14 +1241,14 @@ discard block |
||
1241 | 1241 | * @param array $options Set 'slash_zero' => 'keep' when '\0' is allowed. Default is 'remove'. |
1242 | 1242 | * @return string |
1243 | 1243 | */ |
1244 | -function wp_kses_no_null( $string, $options = null ) { |
|
1245 | - if ( ! isset( $options['slash_zero'] ) ) { |
|
1246 | - $options = array( 'slash_zero' => 'remove' ); |
|
1244 | +function wp_kses_no_null($string, $options = null) { |
|
1245 | + if ( ! isset($options['slash_zero'])) { |
|
1246 | + $options = array('slash_zero' => 'remove'); |
|
1247 | 1247 | } |
1248 | 1248 | |
1249 | - $string = preg_replace( '/[\x00-\x08\x0B\x0C\x0E-\x1F]/', '', $string ); |
|
1250 | - if ( 'remove' == $options['slash_zero'] ) { |
|
1251 | - $string = preg_replace( '/\\\\+0+/', '', $string ); |
|
1249 | + $string = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F]/', '', $string); |
|
1250 | + if ('remove' == $options['slash_zero']) { |
|
1251 | + $string = preg_replace('/\\\\+0+/', '', $string); |
|
1252 | 1252 | } |
1253 | 1253 | |
1254 | 1254 | return $string; |
@@ -1279,13 +1279,13 @@ discard block |
||
1279 | 1279 | * @return array Fixed array with all lowercase keys |
1280 | 1280 | */ |
1281 | 1281 | function wp_kses_array_lc($inarray) { |
1282 | - $outarray = array (); |
|
1282 | + $outarray = array(); |
|
1283 | 1283 | |
1284 | - foreach ( (array) $inarray as $inkey => $inval) { |
|
1284 | + foreach ((array) $inarray as $inkey => $inval) { |
|
1285 | 1285 | $outkey = strtolower($inkey); |
1286 | - $outarray[$outkey] = array (); |
|
1286 | + $outarray[$outkey] = array(); |
|
1287 | 1287 | |
1288 | - foreach ( (array) $inval as $inkey2 => $inval2) { |
|
1288 | + foreach ((array) $inval as $inkey2 => $inval2) { |
|
1289 | 1289 | $outkey2 = strtolower($inkey2); |
1290 | 1290 | $outarray[$outkey][$outkey2] = $inval2; |
1291 | 1291 | } // foreach $inval |
@@ -1333,19 +1333,19 @@ discard block |
||
1333 | 1333 | * @param string $allowed_protocols Allowed protocols |
1334 | 1334 | * @return string Sanitized content |
1335 | 1335 | */ |
1336 | -function wp_kses_bad_protocol_once($string, $allowed_protocols, $count = 1 ) { |
|
1337 | - $string2 = preg_split( '/:|�*58;|�*3a;/i', $string, 2 ); |
|
1338 | - if ( isset($string2[1]) && ! preg_match('%/\?%', $string2[0]) ) { |
|
1339 | - $string = trim( $string2[1] ); |
|
1340 | - $protocol = wp_kses_bad_protocol_once2( $string2[0], $allowed_protocols ); |
|
1341 | - if ( 'feed:' == $protocol ) { |
|
1342 | - if ( $count > 2 ) |
|
1336 | +function wp_kses_bad_protocol_once($string, $allowed_protocols, $count = 1) { |
|
1337 | + $string2 = preg_split('/:|�*58;|�*3a;/i', $string, 2); |
|
1338 | + if (isset($string2[1]) && ! preg_match('%/\?%', $string2[0])) { |
|
1339 | + $string = trim($string2[1]); |
|
1340 | + $protocol = wp_kses_bad_protocol_once2($string2[0], $allowed_protocols); |
|
1341 | + if ('feed:' == $protocol) { |
|
1342 | + if ($count > 2) |
|
1343 | 1343 | return ''; |
1344 | - $string = wp_kses_bad_protocol_once( $string, $allowed_protocols, ++$count ); |
|
1345 | - if ( empty( $string ) ) |
|
1344 | + $string = wp_kses_bad_protocol_once($string, $allowed_protocols, ++$count); |
|
1345 | + if (empty($string)) |
|
1346 | 1346 | return $string; |
1347 | 1347 | } |
1348 | - $string = $protocol . $string; |
|
1348 | + $string = $protocol.$string; |
|
1349 | 1349 | } |
1350 | 1350 | |
1351 | 1351 | return $string; |
@@ -1364,15 +1364,15 @@ discard block |
||
1364 | 1364 | * @param string $allowed_protocols Allowed protocols |
1365 | 1365 | * @return string Sanitized content |
1366 | 1366 | */ |
1367 | -function wp_kses_bad_protocol_once2( $string, $allowed_protocols ) { |
|
1367 | +function wp_kses_bad_protocol_once2($string, $allowed_protocols) { |
|
1368 | 1368 | $string2 = wp_kses_decode_entities($string); |
1369 | 1369 | $string2 = preg_replace('/\s/', '', $string2); |
1370 | 1370 | $string2 = wp_kses_no_null($string2); |
1371 | 1371 | $string2 = strtolower($string2); |
1372 | 1372 | |
1373 | 1373 | $allowed = false; |
1374 | - foreach ( (array) $allowed_protocols as $one_protocol ) |
|
1375 | - if ( strtolower($one_protocol) == $string2 ) { |
|
1374 | + foreach ((array) $allowed_protocols as $one_protocol) |
|
1375 | + if (strtolower($one_protocol) == $string2) { |
|
1376 | 1376 | $allowed = true; |
1377 | 1377 | break; |
1378 | 1378 | } |
@@ -1422,11 +1422,11 @@ discard block |
||
1422 | 1422 | function wp_kses_named_entities($matches) { |
1423 | 1423 | global $allowedentitynames; |
1424 | 1424 | |
1425 | - if ( empty($matches[1]) ) |
|
1425 | + if (empty($matches[1])) |
|
1426 | 1426 | return ''; |
1427 | 1427 | |
1428 | 1428 | $i = $matches[1]; |
1429 | - return ( ! in_array( $i, $allowedentitynames ) ) ? "&$i;" : "&$i;"; |
|
1429 | + return ( ! in_array($i, $allowedentitynames)) ? "&$i;" : "&$i;"; |
|
1430 | 1430 | } |
1431 | 1431 | |
1432 | 1432 | /** |
@@ -1442,12 +1442,12 @@ discard block |
||
1442 | 1442 | * @return string Correctly encoded entity |
1443 | 1443 | */ |
1444 | 1444 | function wp_kses_normalize_entities2($matches) { |
1445 | - if ( empty($matches[1]) ) |
|
1445 | + if (empty($matches[1])) |
|
1446 | 1446 | return ''; |
1447 | 1447 | |
1448 | 1448 | $i = $matches[1]; |
1449 | 1449 | if (valid_unicode($i)) { |
1450 | - $i = str_pad(ltrim($i,'0'), 3, '0', STR_PAD_LEFT); |
|
1450 | + $i = str_pad(ltrim($i, '0'), 3, '0', STR_PAD_LEFT); |
|
1451 | 1451 | $i = "&#$i;"; |
1452 | 1452 | } else { |
1453 | 1453 | $i = "&#$i;"; |
@@ -1468,11 +1468,11 @@ discard block |
||
1468 | 1468 | * @return string Correctly encoded entity |
1469 | 1469 | */ |
1470 | 1470 | function wp_kses_normalize_entities3($matches) { |
1471 | - if ( empty($matches[1]) ) |
|
1471 | + if (empty($matches[1])) |
|
1472 | 1472 | return ''; |
1473 | 1473 | |
1474 | 1474 | $hexchars = $matches[1]; |
1475 | - return ( ! valid_unicode( hexdec( $hexchars ) ) ) ? "&#x$hexchars;" : '&#x'.ltrim($hexchars,'0').';'; |
|
1475 | + return ( ! valid_unicode(hexdec($hexchars))) ? "&#x$hexchars;" : '&#x'.ltrim($hexchars, '0').';'; |
|
1476 | 1476 | } |
1477 | 1477 | |
1478 | 1478 | /** |
@@ -1482,10 +1482,10 @@ discard block |
||
1482 | 1482 | * @return bool True if the value was a valid Unicode number |
1483 | 1483 | */ |
1484 | 1484 | function valid_unicode($i) { |
1485 | - return ( $i == 0x9 || $i == 0xa || $i == 0xd || |
|
1485 | + return ($i == 0x9 || $i == 0xa || $i == 0xd || |
|
1486 | 1486 | ($i >= 0x20 && $i <= 0xd7ff) || |
1487 | 1487 | ($i >= 0xe000 && $i <= 0xfffd) || |
1488 | - ($i >= 0x10000 && $i <= 0x10ffff) ); |
|
1488 | + ($i >= 0x10000 && $i <= 0x10ffff)); |
|
1489 | 1489 | } |
1490 | 1490 | |
1491 | 1491 | /** |
@@ -1513,8 +1513,8 @@ discard block |
||
1513 | 1513 | * @param array $match preg match |
1514 | 1514 | * @return string |
1515 | 1515 | */ |
1516 | -function _wp_kses_decode_entities_chr( $match ) { |
|
1517 | - return chr( $match[1] ); |
|
1516 | +function _wp_kses_decode_entities_chr($match) { |
|
1517 | + return chr($match[1]); |
|
1518 | 1518 | } |
1519 | 1519 | |
1520 | 1520 | /** |
@@ -1523,8 +1523,8 @@ discard block |
||
1523 | 1523 | * @param array $match preg match |
1524 | 1524 | * @return string |
1525 | 1525 | */ |
1526 | -function _wp_kses_decode_entities_chr_hexdec( $match ) { |
|
1527 | - return chr( hexdec( $match[1] ) ); |
|
1526 | +function _wp_kses_decode_entities_chr_hexdec($match) { |
|
1527 | + return chr(hexdec($match[1])); |
|
1528 | 1528 | } |
1529 | 1529 | |
1530 | 1530 | /** |
@@ -1535,8 +1535,8 @@ discard block |
||
1535 | 1535 | * @param string $data Content to filter, expected to be escaped with slashes |
1536 | 1536 | * @return string Filtered content |
1537 | 1537 | */ |
1538 | -function wp_filter_kses( $data ) { |
|
1539 | - return addslashes( wp_kses( stripslashes( $data ), current_filter() ) ); |
|
1538 | +function wp_filter_kses($data) { |
|
1539 | + return addslashes(wp_kses(stripslashes($data), current_filter())); |
|
1540 | 1540 | } |
1541 | 1541 | |
1542 | 1542 | /** |
@@ -1547,8 +1547,8 @@ discard block |
||
1547 | 1547 | * @param string $data Content to filter, expected to not be escaped |
1548 | 1548 | * @return string Filtered content |
1549 | 1549 | */ |
1550 | -function wp_kses_data( $data ) { |
|
1551 | - return wp_kses( $data, current_filter() ); |
|
1550 | +function wp_kses_data($data) { |
|
1551 | + return wp_kses($data, current_filter()); |
|
1552 | 1552 | } |
1553 | 1553 | |
1554 | 1554 | /** |
@@ -1562,8 +1562,8 @@ discard block |
||
1562 | 1562 | * @param string $data Post content to filter, expected to be escaped with slashes |
1563 | 1563 | * @return string Filtered post content with allowed HTML tags and attributes intact. |
1564 | 1564 | */ |
1565 | -function wp_filter_post_kses( $data ) { |
|
1566 | - return addslashes( wp_kses( stripslashes( $data ), 'post' ) ); |
|
1565 | +function wp_filter_post_kses($data) { |
|
1566 | + return addslashes(wp_kses(stripslashes($data), 'post')); |
|
1567 | 1567 | } |
1568 | 1568 | |
1569 | 1569 | /** |
@@ -1577,8 +1577,8 @@ discard block |
||
1577 | 1577 | * @param string $data Post content to filter |
1578 | 1578 | * @return string Filtered post content with allowed HTML tags and attributes intact. |
1579 | 1579 | */ |
1580 | -function wp_kses_post( $data ) { |
|
1581 | - return wp_kses( $data, 'post' ); |
|
1580 | +function wp_kses_post($data) { |
|
1581 | + return wp_kses($data, 'post'); |
|
1582 | 1582 | } |
1583 | 1583 | |
1584 | 1584 | /** |
@@ -1592,8 +1592,8 @@ discard block |
||
1592 | 1592 | * @param mixed $data The array, object, or scalar value to inspect. |
1593 | 1593 | * @return mixed The filtered content. |
1594 | 1594 | */ |
1595 | -function wp_kses_post_deep( $data ) { |
|
1596 | - return map_deep( $data, 'wp_kses_post' ); |
|
1595 | +function wp_kses_post_deep($data) { |
|
1596 | + return map_deep($data, 'wp_kses_post'); |
|
1597 | 1597 | } |
1598 | 1598 | |
1599 | 1599 | /** |
@@ -1604,8 +1604,8 @@ discard block |
||
1604 | 1604 | * @param string $data Content to strip all HTML from |
1605 | 1605 | * @return string Filtered content without any HTML |
1606 | 1606 | */ |
1607 | -function wp_filter_nohtml_kses( $data ) { |
|
1608 | - return addslashes( wp_kses( stripslashes( $data ), 'strip' ) ); |
|
1607 | +function wp_filter_nohtml_kses($data) { |
|
1608 | + return addslashes(wp_kses(stripslashes($data), 'strip')); |
|
1609 | 1609 | } |
1610 | 1610 | |
1611 | 1611 | /** |
@@ -1624,10 +1624,10 @@ discard block |
||
1624 | 1624 | add_filter('title_save_pre', 'wp_filter_kses'); |
1625 | 1625 | |
1626 | 1626 | // Comment filtering |
1627 | - if ( current_user_can( 'unfiltered_html' ) ) |
|
1628 | - add_filter( 'pre_comment_content', 'wp_filter_post_kses' ); |
|
1627 | + if (current_user_can('unfiltered_html')) |
|
1628 | + add_filter('pre_comment_content', 'wp_filter_post_kses'); |
|
1629 | 1629 | else |
1630 | - add_filter( 'pre_comment_content', 'wp_filter_kses' ); |
|
1630 | + add_filter('pre_comment_content', 'wp_filter_kses'); |
|
1631 | 1631 | |
1632 | 1632 | // Post filtering |
1633 | 1633 | add_filter('content_save_pre', 'wp_filter_post_kses'); |
@@ -1652,8 +1652,8 @@ discard block |
||
1652 | 1652 | remove_filter('title_save_pre', 'wp_filter_kses'); |
1653 | 1653 | |
1654 | 1654 | // Comment filtering |
1655 | - remove_filter( 'pre_comment_content', 'wp_filter_post_kses' ); |
|
1656 | - remove_filter( 'pre_comment_content', 'wp_filter_kses' ); |
|
1655 | + remove_filter('pre_comment_content', 'wp_filter_post_kses'); |
|
1656 | + remove_filter('pre_comment_content', 'wp_filter_kses'); |
|
1657 | 1657 | |
1658 | 1658 | // Post filtering |
1659 | 1659 | remove_filter('content_save_pre', 'wp_filter_post_kses'); |
@@ -1677,7 +1677,7 @@ discard block |
||
1677 | 1677 | function kses_init() { |
1678 | 1678 | kses_remove_filters(); |
1679 | 1679 | |
1680 | - if ( ! current_user_can( 'unfiltered_html' ) ) { |
|
1680 | + if ( ! current_user_can('unfiltered_html')) { |
|
1681 | 1681 | kses_init_filters(); |
1682 | 1682 | } |
1683 | 1683 | } |
@@ -1691,17 +1691,17 @@ discard block |
||
1691 | 1691 | * @param string $deprecated Not used. |
1692 | 1692 | * @return string Filtered string of CSS rules. |
1693 | 1693 | */ |
1694 | -function safecss_filter_attr( $css, $deprecated = '' ) { |
|
1695 | - if ( !empty( $deprecated ) ) |
|
1696 | - _deprecated_argument( __FUNCTION__, '2.8.1' ); // Never implemented |
|
1694 | +function safecss_filter_attr($css, $deprecated = '') { |
|
1695 | + if ( ! empty($deprecated)) |
|
1696 | + _deprecated_argument(__FUNCTION__, '2.8.1'); // Never implemented |
|
1697 | 1697 | |
1698 | 1698 | $css = wp_kses_no_null($css); |
1699 | - $css = str_replace(array("\n","\r","\t"), '', $css); |
|
1699 | + $css = str_replace(array("\n", "\r", "\t"), '', $css); |
|
1700 | 1700 | |
1701 | - if ( preg_match( '%[\\\\(&=}]|/\*%', $css ) ) // remove any inline css containing \ ( & } = or comments |
|
1701 | + if (preg_match('%[\\\\(&=}]|/\*%', $css)) // remove any inline css containing \ ( & } = or comments |
|
1702 | 1702 | return ''; |
1703 | 1703 | |
1704 | - $css_array = explode( ';', trim( $css ) ); |
|
1704 | + $css_array = explode(';', trim($css)); |
|
1705 | 1705 | |
1706 | 1706 | /** |
1707 | 1707 | * Filter list of allowed CSS attributes. |
@@ -1710,36 +1710,36 @@ discard block |
||
1710 | 1710 | * |
1711 | 1711 | * @param array $attr List of allowed CSS attributes. |
1712 | 1712 | */ |
1713 | - $allowed_attr = apply_filters( 'safe_style_css', array( 'text-align', 'margin', 'color', 'float', |
|
1713 | + $allowed_attr = apply_filters('safe_style_css', array('text-align', 'margin', 'color', 'float', |
|
1714 | 1714 | 'border', 'background', 'background-color', 'border-bottom', 'border-bottom-color', |
1715 | 1715 | 'border-bottom-style', 'border-bottom-width', 'border-collapse', 'border-color', 'border-left', |
1716 | 1716 | 'border-left-color', 'border-left-style', 'border-left-width', 'border-right', 'border-right-color', |
1717 | 1717 | 'border-right-style', 'border-right-width', 'border-spacing', 'border-style', 'border-top', |
1718 | 1718 | 'border-top-color', 'border-top-style', 'border-top-width', 'border-width', 'caption-side', |
1719 | 1719 | 'clear', 'cursor', 'direction', 'font', 'font-family', 'font-size', 'font-style', |
1720 | - 'font-variant', 'font-weight', 'height', 'min-height','max-height' , 'letter-spacing', 'line-height', 'margin-bottom', |
|
1720 | + 'font-variant', 'font-weight', 'height', 'min-height', 'max-height', 'letter-spacing', 'line-height', 'margin-bottom', |
|
1721 | 1721 | 'margin-left', 'margin-right', 'margin-top', 'overflow', 'padding', 'padding-bottom', |
1722 | 1722 | 'padding-left', 'padding-right', 'padding-top', 'text-decoration', 'text-indent', 'vertical-align', |
1723 | - 'width', 'min-width', 'max-width' ) ); |
|
1723 | + 'width', 'min-width', 'max-width')); |
|
1724 | 1724 | |
1725 | - if ( empty($allowed_attr) ) |
|
1725 | + if (empty($allowed_attr)) |
|
1726 | 1726 | return $css; |
1727 | 1727 | |
1728 | 1728 | $css = ''; |
1729 | - foreach ( $css_array as $css_item ) { |
|
1730 | - if ( $css_item == '' ) |
|
1729 | + foreach ($css_array as $css_item) { |
|
1730 | + if ($css_item == '') |
|
1731 | 1731 | continue; |
1732 | - $css_item = trim( $css_item ); |
|
1732 | + $css_item = trim($css_item); |
|
1733 | 1733 | $found = false; |
1734 | - if ( strpos( $css_item, ':' ) === false ) { |
|
1734 | + if (strpos($css_item, ':') === false) { |
|
1735 | 1735 | $found = true; |
1736 | 1736 | } else { |
1737 | - $parts = explode( ':', $css_item ); |
|
1738 | - if ( in_array( trim( $parts[0] ), $allowed_attr ) ) |
|
1737 | + $parts = explode(':', $css_item); |
|
1738 | + if (in_array(trim($parts[0]), $allowed_attr)) |
|
1739 | 1739 | $found = true; |
1740 | 1740 | } |
1741 | - if ( $found ) { |
|
1742 | - if( $css != '' ) |
|
1741 | + if ($found) { |
|
1742 | + if ($css != '') |
|
1743 | 1743 | $css .= ';'; |
1744 | 1744 | $css .= $css_item; |
1745 | 1745 | } |
@@ -1757,7 +1757,7 @@ discard block |
||
1757 | 1757 | * @param array $value An array of attributes. |
1758 | 1758 | * @return array The array of attributes with global attributes added. |
1759 | 1759 | */ |
1760 | -function _wp_add_global_attributes( $value ) { |
|
1760 | +function _wp_add_global_attributes($value) { |
|
1761 | 1761 | $global_attributes = array( |
1762 | 1762 | 'class' => true, |
1763 | 1763 | 'id' => true, |
@@ -1766,11 +1766,11 @@ discard block |
||
1766 | 1766 | 'role' => true, |
1767 | 1767 | ); |
1768 | 1768 | |
1769 | - if ( true === $value ) |
|
1769 | + if (true === $value) |
|
1770 | 1770 | $value = array(); |
1771 | 1771 | |
1772 | - if ( is_array( $value ) ) |
|
1773 | - return array_merge( $value, $global_attributes ); |
|
1772 | + if (is_array($value)) |
|
1773 | + return array_merge($value, $global_attributes); |
|
1774 | 1774 | |
1775 | 1775 | return $value; |
1776 | 1776 | } |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * WordPress Imagick Image Editor |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - * @subpackage Image_Editor |
|
7 | - */ |
|
3 | + * WordPress Imagick Image Editor |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + * @subpackage Image_Editor |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * WordPress Image Editor Class for Image Manipulation through Imagick PHP Module |
@@ -279,7 +279,7 @@ |
||
279 | 279 | * @param int $dst_h The destination height. |
280 | 280 | * @param string $filter_name Optional. The Imagick filter to use when resizing. Default 'FILTER_TRIANGLE'. |
281 | 281 | * @param bool $strip_meta Optional. Strip all profiles, excluding color profiles, from the image. Default true. |
282 | - * @return bool|WP_Error |
|
282 | + * @return null|WP_Error |
|
283 | 283 | */ |
284 | 284 | protected function thumbnail_image( $dst_w, $dst_h, $filter_name = 'FILTER_TRIANGLE', $strip_meta = true ) { |
285 | 285 | $allowed_filters = array( |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | protected $image; |
25 | 25 | |
26 | 26 | public function __destruct() { |
27 | - if ( $this->image instanceof Imagick ) { |
|
27 | + if ($this->image instanceof Imagick) { |
|
28 | 28 | // we don't need the original in memory anymore |
29 | 29 | $this->image->clear(); |
30 | 30 | $this->image->destroy(); |
@@ -45,13 +45,13 @@ discard block |
||
45 | 45 | * @param array $args |
46 | 46 | * @return bool |
47 | 47 | */ |
48 | - public static function test( $args = array() ) { |
|
48 | + public static function test($args = array()) { |
|
49 | 49 | |
50 | 50 | // First, test Imagick's extension and classes. |
51 | - if ( ! extension_loaded( 'imagick' ) || ! class_exists( 'Imagick', false ) || ! class_exists( 'ImagickPixel', false ) ) |
|
51 | + if ( ! extension_loaded('imagick') || ! class_exists('Imagick', false) || ! class_exists('ImagickPixel', false)) |
|
52 | 52 | return false; |
53 | 53 | |
54 | - if ( version_compare( phpversion( 'imagick' ), '2.2.0', '<' ) ) |
|
54 | + if (version_compare(phpversion('imagick'), '2.2.0', '<')) |
|
55 | 55 | return false; |
56 | 56 | |
57 | 57 | $required_methods = array( |
@@ -76,16 +76,16 @@ discard block |
||
76 | 76 | ); |
77 | 77 | |
78 | 78 | // Now, test for deep requirements within Imagick. |
79 | - if ( ! defined( 'imagick::COMPRESSION_JPEG' ) ) |
|
79 | + if ( ! defined('imagick::COMPRESSION_JPEG')) |
|
80 | 80 | return false; |
81 | 81 | |
82 | - $class_methods = array_map( 'strtolower', get_class_methods( 'Imagick' ) ); |
|
83 | - if ( array_diff( $required_methods, $class_methods ) ) { |
|
82 | + $class_methods = array_map('strtolower', get_class_methods('Imagick')); |
|
83 | + if (array_diff($required_methods, $class_methods)) { |
|
84 | 84 | return false; |
85 | 85 | } |
86 | 86 | |
87 | 87 | // HHVM Imagick does not support loading from URL, so fail to allow fallback to GD. |
88 | - if ( defined( 'HHVM_VERSION' ) && isset( $args['path'] ) && preg_match( '|^https?://|', $args['path'] ) ) { |
|
88 | + if (defined('HHVM_VERSION') && isset($args['path']) && preg_match('|^https?://|', $args['path'])) { |
|
89 | 89 | return false; |
90 | 90 | } |
91 | 91 | |
@@ -103,21 +103,21 @@ discard block |
||
103 | 103 | * @param string $mime_type |
104 | 104 | * @return bool |
105 | 105 | */ |
106 | - public static function supports_mime_type( $mime_type ) { |
|
107 | - $imagick_extension = strtoupper( self::get_extension( $mime_type ) ); |
|
106 | + public static function supports_mime_type($mime_type) { |
|
107 | + $imagick_extension = strtoupper(self::get_extension($mime_type)); |
|
108 | 108 | |
109 | - if ( ! $imagick_extension ) |
|
109 | + if ( ! $imagick_extension) |
|
110 | 110 | return false; |
111 | 111 | |
112 | 112 | // setIteratorIndex is optional unless mime is an animated format. |
113 | 113 | // Here, we just say no if you are missing it and aren't loading a jpeg. |
114 | - if ( ! method_exists( 'Imagick', 'setIteratorIndex' ) && $mime_type != 'image/jpeg' ) |
|
114 | + if ( ! method_exists('Imagick', 'setIteratorIndex') && $mime_type != 'image/jpeg') |
|
115 | 115 | return false; |
116 | 116 | |
117 | 117 | try { |
118 | - return ( (bool) @Imagick::queryFormats( $imagick_extension ) ); |
|
118 | + return ((bool) @Imagick::queryFormats($imagick_extension)); |
|
119 | 119 | } |
120 | - catch ( Exception $e ) { |
|
120 | + catch (Exception $e) { |
|
121 | 121 | return false; |
122 | 122 | } |
123 | 123 | } |
@@ -131,34 +131,34 @@ discard block |
||
131 | 131 | * @return true|WP_Error True if loaded; WP_Error on failure. |
132 | 132 | */ |
133 | 133 | public function load() { |
134 | - if ( $this->image instanceof Imagick ) |
|
134 | + if ($this->image instanceof Imagick) |
|
135 | 135 | return true; |
136 | 136 | |
137 | - if ( ! is_file( $this->file ) && ! preg_match( '|^https?://|', $this->file ) ) |
|
138 | - return new WP_Error( 'error_loading_image', __('File doesn’t exist?'), $this->file ); |
|
137 | + if ( ! is_file($this->file) && ! preg_match('|^https?://|', $this->file)) |
|
138 | + return new WP_Error('error_loading_image', __('File doesn’t exist?'), $this->file); |
|
139 | 139 | |
140 | 140 | /** This filter is documented in wp-includes/class-wp-image-editor-imagick.php */ |
141 | 141 | // Even though Imagick uses less PHP memory than GD, set higher limit for users that have low PHP.ini limits |
142 | - @ini_set( 'memory_limit', apply_filters( 'image_memory_limit', WP_MAX_MEMORY_LIMIT ) ); |
|
142 | + @ini_set('memory_limit', apply_filters('image_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
143 | 143 | |
144 | 144 | try { |
145 | - $this->image = new Imagick( $this->file ); |
|
145 | + $this->image = new Imagick($this->file); |
|
146 | 146 | |
147 | - if ( ! $this->image->valid() ) |
|
148 | - return new WP_Error( 'invalid_image', __('File is not an image.'), $this->file); |
|
147 | + if ( ! $this->image->valid()) |
|
148 | + return new WP_Error('invalid_image', __('File is not an image.'), $this->file); |
|
149 | 149 | |
150 | 150 | // Select the first frame to handle animated images properly |
151 | - if ( is_callable( array( $this->image, 'setIteratorIndex' ) ) ) |
|
151 | + if (is_callable(array($this->image, 'setIteratorIndex'))) |
|
152 | 152 | $this->image->setIteratorIndex(0); |
153 | 153 | |
154 | - $this->mime_type = $this->get_mime_type( $this->image->getImageFormat() ); |
|
154 | + $this->mime_type = $this->get_mime_type($this->image->getImageFormat()); |
|
155 | 155 | } |
156 | - catch ( Exception $e ) { |
|
157 | - return new WP_Error( 'invalid_image', $e->getMessage(), $this->file ); |
|
156 | + catch (Exception $e) { |
|
157 | + return new WP_Error('invalid_image', $e->getMessage(), $this->file); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | $updated_size = $this->update_size(); |
161 | - if ( is_wp_error( $updated_size ) ) { |
|
161 | + if (is_wp_error($updated_size)) { |
|
162 | 162 | return $updated_size; |
163 | 163 | } |
164 | 164 | |
@@ -174,25 +174,25 @@ discard block |
||
174 | 174 | * @param int $quality Compression Quality. Range: [1,100] |
175 | 175 | * @return true|WP_Error True if set successfully; WP_Error on failure. |
176 | 176 | */ |
177 | - public function set_quality( $quality = null ) { |
|
178 | - $quality_result = parent::set_quality( $quality ); |
|
179 | - if ( is_wp_error( $quality_result ) ) { |
|
177 | + public function set_quality($quality = null) { |
|
178 | + $quality_result = parent::set_quality($quality); |
|
179 | + if (is_wp_error($quality_result)) { |
|
180 | 180 | return $quality_result; |
181 | 181 | } else { |
182 | 182 | $quality = $this->get_quality(); |
183 | 183 | } |
184 | 184 | |
185 | 185 | try { |
186 | - if ( 'image/jpeg' == $this->mime_type ) { |
|
187 | - $this->image->setImageCompressionQuality( $quality ); |
|
188 | - $this->image->setImageCompression( imagick::COMPRESSION_JPEG ); |
|
186 | + if ('image/jpeg' == $this->mime_type) { |
|
187 | + $this->image->setImageCompressionQuality($quality); |
|
188 | + $this->image->setImageCompression(imagick::COMPRESSION_JPEG); |
|
189 | 189 | } |
190 | 190 | else { |
191 | - $this->image->setImageCompressionQuality( $quality ); |
|
191 | + $this->image->setImageCompressionQuality($quality); |
|
192 | 192 | } |
193 | 193 | } |
194 | - catch ( Exception $e ) { |
|
195 | - return new WP_Error( 'image_quality_error', $e->getMessage() ); |
|
194 | + catch (Exception $e) { |
|
195 | + return new WP_Error('image_quality_error', $e->getMessage()); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | return true; |
@@ -209,24 +209,24 @@ discard block |
||
209 | 209 | * |
210 | 210 | * @return true|WP_Error |
211 | 211 | */ |
212 | - protected function update_size( $width = null, $height = null ) { |
|
212 | + protected function update_size($width = null, $height = null) { |
|
213 | 213 | $size = null; |
214 | - if ( !$width || !$height ) { |
|
214 | + if ( ! $width || ! $height) { |
|
215 | 215 | try { |
216 | 216 | $size = $this->image->getImageGeometry(); |
217 | 217 | } |
218 | - catch ( Exception $e ) { |
|
219 | - return new WP_Error( 'invalid_image', __( 'Could not read image size.' ), $this->file ); |
|
218 | + catch (Exception $e) { |
|
219 | + return new WP_Error('invalid_image', __('Could not read image size.'), $this->file); |
|
220 | 220 | } |
221 | 221 | } |
222 | 222 | |
223 | - if ( ! $width ) |
|
223 | + if ( ! $width) |
|
224 | 224 | $width = $size['width']; |
225 | 225 | |
226 | - if ( ! $height ) |
|
226 | + if ( ! $height) |
|
227 | 227 | $height = $size['height']; |
228 | 228 | |
229 | - return parent::update_size( $width, $height ); |
|
229 | + return parent::update_size($width, $height); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -244,26 +244,26 @@ discard block |
||
244 | 244 | * @param bool $crop |
245 | 245 | * @return bool|WP_Error |
246 | 246 | */ |
247 | - public function resize( $max_w, $max_h, $crop = false ) { |
|
248 | - if ( ( $this->size['width'] == $max_w ) && ( $this->size['height'] == $max_h ) ) |
|
247 | + public function resize($max_w, $max_h, $crop = false) { |
|
248 | + if (($this->size['width'] == $max_w) && ($this->size['height'] == $max_h)) |
|
249 | 249 | return true; |
250 | 250 | |
251 | - $dims = image_resize_dimensions( $this->size['width'], $this->size['height'], $max_w, $max_h, $crop ); |
|
252 | - if ( ! $dims ) |
|
253 | - return new WP_Error( 'error_getting_dimensions', __('Could not calculate resized image dimensions') ); |
|
254 | - list( $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ) = $dims; |
|
251 | + $dims = image_resize_dimensions($this->size['width'], $this->size['height'], $max_w, $max_h, $crop); |
|
252 | + if ( ! $dims) |
|
253 | + return new WP_Error('error_getting_dimensions', __('Could not calculate resized image dimensions')); |
|
254 | + list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = $dims; |
|
255 | 255 | |
256 | - if ( $crop ) { |
|
257 | - return $this->crop( $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h ); |
|
256 | + if ($crop) { |
|
257 | + return $this->crop($src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | // Execute the resize |
261 | - $thumb_result = $this->thumbnail_image( $dst_w, $dst_h ); |
|
262 | - if ( is_wp_error( $thumb_result ) ) { |
|
261 | + $thumb_result = $this->thumbnail_image($dst_w, $dst_h); |
|
262 | + if (is_wp_error($thumb_result)) { |
|
263 | 263 | return $thumb_result; |
264 | 264 | } |
265 | 265 | |
266 | - return $this->update_size( $dst_w, $dst_h ); |
|
266 | + return $this->update_size($dst_w, $dst_h); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | /** |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | * @param bool $strip_meta Optional. Strip all profiles, excluding color profiles, from the image. Default true. |
282 | 282 | * @return bool|WP_Error |
283 | 283 | */ |
284 | - protected function thumbnail_image( $dst_w, $dst_h, $filter_name = 'FILTER_TRIANGLE', $strip_meta = true ) { |
|
284 | + protected function thumbnail_image($dst_w, $dst_h, $filter_name = 'FILTER_TRIANGLE', $strip_meta = true) { |
|
285 | 285 | $allowed_filters = array( |
286 | 286 | 'FILTER_POINT', |
287 | 287 | 'FILTER_BOX', |
@@ -304,10 +304,10 @@ discard block |
||
304 | 304 | * Set the filter value if '$filter_name' name is in our whitelist and the related |
305 | 305 | * Imagick constant is defined or fall back to our default filter. |
306 | 306 | */ |
307 | - if ( in_array( $filter_name, $allowed_filters ) && defined( 'Imagick::' . $filter_name ) ) { |
|
308 | - $filter = constant( 'Imagick::' . $filter_name ); |
|
307 | + if (in_array($filter_name, $allowed_filters) && defined('Imagick::'.$filter_name)) { |
|
308 | + $filter = constant('Imagick::'.$filter_name); |
|
309 | 309 | } else { |
310 | - $filter = defined( 'Imagick::FILTER_TRIANGLE' ) ? Imagick::FILTER_TRIANGLE : false; |
|
310 | + $filter = defined('Imagick::FILTER_TRIANGLE') ? Imagick::FILTER_TRIANGLE : false; |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | /** |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | * |
321 | 321 | * @param bool $strip_meta Whether to strip image metadata during resizing. Default true. |
322 | 322 | */ |
323 | - if ( apply_filters( 'image_strip_meta', $strip_meta ) ) { |
|
323 | + if (apply_filters('image_strip_meta', $strip_meta)) { |
|
324 | 324 | $this->strip_meta(); // Fail silently if not supported. |
325 | 325 | } |
326 | 326 | |
@@ -330,12 +330,12 @@ discard block |
||
330 | 330 | * whenever the output size is less that 1/3 of the original image size (1/3^2 ~= .111), |
331 | 331 | * unless we would be resampling to a scale smaller than 128x128. |
332 | 332 | */ |
333 | - if ( is_callable( array( $this->image, 'sampleImage' ) ) ) { |
|
334 | - $resize_ratio = ( $dst_w / $this->size['width'] ) * ( $dst_h / $this->size['height'] ); |
|
333 | + if (is_callable(array($this->image, 'sampleImage'))) { |
|
334 | + $resize_ratio = ($dst_w / $this->size['width']) * ($dst_h / $this->size['height']); |
|
335 | 335 | $sample_factor = 5; |
336 | 336 | |
337 | - if ( $resize_ratio < .111 && ( $dst_w * $sample_factor > 128 && $dst_h * $sample_factor > 128 ) ) { |
|
338 | - $this->image->sampleImage( $dst_w * $sample_factor, $dst_h * $sample_factor ); |
|
337 | + if ($resize_ratio < .111 && ($dst_w * $sample_factor > 128 && $dst_h * $sample_factor > 128)) { |
|
338 | + $this->image->sampleImage($dst_w * $sample_factor, $dst_h * $sample_factor); |
|
339 | 339 | } |
340 | 340 | } |
341 | 341 | |
@@ -345,27 +345,27 @@ discard block |
||
345 | 345 | * results in better image quality over resizeImage() with default filter |
346 | 346 | * settings and retains backwards compatibility with pre 4.5 functionality. |
347 | 347 | */ |
348 | - if ( is_callable( array( $this->image, 'resizeImage' ) ) && $filter ) { |
|
349 | - $this->image->setOption( 'filter:support', '2.0' ); |
|
350 | - $this->image->resizeImage( $dst_w, $dst_h, $filter, 1 ); |
|
348 | + if (is_callable(array($this->image, 'resizeImage')) && $filter) { |
|
349 | + $this->image->setOption('filter:support', '2.0'); |
|
350 | + $this->image->resizeImage($dst_w, $dst_h, $filter, 1); |
|
351 | 351 | } else { |
352 | - $this->image->scaleImage( $dst_w, $dst_h ); |
|
352 | + $this->image->scaleImage($dst_w, $dst_h); |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | // Set appropriate quality settings after resizing. |
356 | - if ( 'image/jpeg' == $this->mime_type ) { |
|
357 | - if ( is_callable( array( $this->image, 'unsharpMaskImage' ) ) ) { |
|
358 | - $this->image->unsharpMaskImage( 0.25, 0.25, 8, 0.065 ); |
|
356 | + if ('image/jpeg' == $this->mime_type) { |
|
357 | + if (is_callable(array($this->image, 'unsharpMaskImage'))) { |
|
358 | + $this->image->unsharpMaskImage(0.25, 0.25, 8, 0.065); |
|
359 | 359 | } |
360 | 360 | |
361 | - $this->image->setOption( 'jpeg:fancy-upsampling', 'off' ); |
|
361 | + $this->image->setOption('jpeg:fancy-upsampling', 'off'); |
|
362 | 362 | } |
363 | 363 | |
364 | - if ( 'image/png' === $this->mime_type ) { |
|
365 | - $this->image->setOption( 'png:compression-filter', '5' ); |
|
366 | - $this->image->setOption( 'png:compression-level', '9' ); |
|
367 | - $this->image->setOption( 'png:compression-strategy', '1' ); |
|
368 | - $this->image->setOption( 'png:exclude-chunk', 'all' ); |
|
364 | + if ('image/png' === $this->mime_type) { |
|
365 | + $this->image->setOption('png:compression-filter', '5'); |
|
366 | + $this->image->setOption('png:compression-level', '9'); |
|
367 | + $this->image->setOption('png:compression-strategy', '1'); |
|
368 | + $this->image->setOption('png:exclude-chunk', 'all'); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | /* |
@@ -374,30 +374,30 @@ discard block |
||
374 | 374 | * Note that Imagick::getImageAlphaChannel() is only available if Imagick |
375 | 375 | * has been compiled against ImageMagick version 6.4.0 or newer. |
376 | 376 | */ |
377 | - if ( is_callable( array( $this->image, 'getImageAlphaChannel' ) ) |
|
378 | - && is_callable( array( $this->image, 'setImageAlphaChannel' ) ) |
|
379 | - && defined( Imagick::ALPHACHANNEL_UNDEFINED ) |
|
380 | - && defined( Imagick::ALPHACHANNEL_OPAQUE ) |
|
377 | + if (is_callable(array($this->image, 'getImageAlphaChannel')) |
|
378 | + && is_callable(array($this->image, 'setImageAlphaChannel')) |
|
379 | + && defined(Imagick::ALPHACHANNEL_UNDEFINED) |
|
380 | + && defined(Imagick::ALPHACHANNEL_OPAQUE) |
|
381 | 381 | ) { |
382 | - if ( $this->image->getImageAlphaChannel() === Imagick::ALPHACHANNEL_UNDEFINED ) { |
|
383 | - $this->image->setImageAlphaChannel( Imagick::ALPHACHANNEL_OPAQUE ); |
|
382 | + if ($this->image->getImageAlphaChannel() === Imagick::ALPHACHANNEL_UNDEFINED) { |
|
383 | + $this->image->setImageAlphaChannel(Imagick::ALPHACHANNEL_OPAQUE); |
|
384 | 384 | } |
385 | 385 | } |
386 | 386 | |
387 | 387 | // Limit the bit depth of resized images to 8 bits per channel. |
388 | - if ( is_callable( array( $this->image, 'getImageDepth' ) ) && is_callable( array( $this->image, 'setImageDepth' ) ) ) { |
|
389 | - if ( 8 < $this->image->getImageDepth() ) { |
|
390 | - $this->image->setImageDepth( 8 ); |
|
388 | + if (is_callable(array($this->image, 'getImageDepth')) && is_callable(array($this->image, 'setImageDepth'))) { |
|
389 | + if (8 < $this->image->getImageDepth()) { |
|
390 | + $this->image->setImageDepth(8); |
|
391 | 391 | } |
392 | 392 | } |
393 | 393 | |
394 | - if ( is_callable( array( $this->image, 'setInterlaceScheme' ) ) && defined( 'Imagick::INTERLACE_NO' ) ) { |
|
395 | - $this->image->setInterlaceScheme( Imagick::INTERLACE_NO ); |
|
394 | + if (is_callable(array($this->image, 'setInterlaceScheme')) && defined('Imagick::INTERLACE_NO')) { |
|
395 | + $this->image->setInterlaceScheme(Imagick::INTERLACE_NO); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | } |
399 | - catch ( Exception $e ) { |
|
400 | - return new WP_Error( 'image_resize_error', $e->getMessage() ); |
|
399 | + catch (Exception $e) { |
|
400 | + return new WP_Error('image_resize_error', $e->getMessage()); |
|
401 | 401 | } |
402 | 402 | } |
403 | 403 | |
@@ -424,42 +424,42 @@ discard block |
||
424 | 424 | * } |
425 | 425 | * @return array An array of resized images' metadata by size. |
426 | 426 | */ |
427 | - public function multi_resize( $sizes ) { |
|
427 | + public function multi_resize($sizes) { |
|
428 | 428 | $metadata = array(); |
429 | 429 | $orig_size = $this->size; |
430 | 430 | $orig_image = $this->image->getImage(); |
431 | 431 | |
432 | - foreach ( $sizes as $size => $size_data ) { |
|
433 | - if ( ! $this->image ) |
|
432 | + foreach ($sizes as $size => $size_data) { |
|
433 | + if ( ! $this->image) |
|
434 | 434 | $this->image = $orig_image->getImage(); |
435 | 435 | |
436 | - if ( ! isset( $size_data['width'] ) && ! isset( $size_data['height'] ) ) { |
|
436 | + if ( ! isset($size_data['width']) && ! isset($size_data['height'])) { |
|
437 | 437 | continue; |
438 | 438 | } |
439 | 439 | |
440 | - if ( ! isset( $size_data['width'] ) ) { |
|
440 | + if ( ! isset($size_data['width'])) { |
|
441 | 441 | $size_data['width'] = null; |
442 | 442 | } |
443 | - if ( ! isset( $size_data['height'] ) ) { |
|
443 | + if ( ! isset($size_data['height'])) { |
|
444 | 444 | $size_data['height'] = null; |
445 | 445 | } |
446 | 446 | |
447 | - if ( ! isset( $size_data['crop'] ) ) { |
|
447 | + if ( ! isset($size_data['crop'])) { |
|
448 | 448 | $size_data['crop'] = false; |
449 | 449 | } |
450 | 450 | |
451 | - $resize_result = $this->resize( $size_data['width'], $size_data['height'], $size_data['crop'] ); |
|
452 | - $duplicate = ( ( $orig_size['width'] == $size_data['width'] ) && ( $orig_size['height'] == $size_data['height'] ) ); |
|
451 | + $resize_result = $this->resize($size_data['width'], $size_data['height'], $size_data['crop']); |
|
452 | + $duplicate = (($orig_size['width'] == $size_data['width']) && ($orig_size['height'] == $size_data['height'])); |
|
453 | 453 | |
454 | - if ( ! is_wp_error( $resize_result ) && ! $duplicate ) { |
|
455 | - $resized = $this->_save( $this->image ); |
|
454 | + if ( ! is_wp_error($resize_result) && ! $duplicate) { |
|
455 | + $resized = $this->_save($this->image); |
|
456 | 456 | |
457 | 457 | $this->image->clear(); |
458 | 458 | $this->image->destroy(); |
459 | 459 | $this->image = null; |
460 | 460 | |
461 | - if ( ! is_wp_error( $resized ) && $resized ) { |
|
462 | - unset( $resized['path'] ); |
|
461 | + if ( ! is_wp_error($resized) && $resized) { |
|
462 | + unset($resized['path']); |
|
463 | 463 | $metadata[$size] = $resized; |
464 | 464 | } |
465 | 465 | } |
@@ -487,34 +487,34 @@ discard block |
||
487 | 487 | * @param bool $src_abs Optional. If the source crop points are absolute. |
488 | 488 | * @return bool|WP_Error |
489 | 489 | */ |
490 | - public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ) { |
|
491 | - if ( $src_abs ) { |
|
490 | + public function crop($src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false) { |
|
491 | + if ($src_abs) { |
|
492 | 492 | $src_w -= $src_x; |
493 | 493 | $src_h -= $src_y; |
494 | 494 | } |
495 | 495 | |
496 | 496 | try { |
497 | - $this->image->cropImage( $src_w, $src_h, $src_x, $src_y ); |
|
498 | - $this->image->setImagePage( $src_w, $src_h, 0, 0); |
|
497 | + $this->image->cropImage($src_w, $src_h, $src_x, $src_y); |
|
498 | + $this->image->setImagePage($src_w, $src_h, 0, 0); |
|
499 | 499 | |
500 | - if ( $dst_w || $dst_h ) { |
|
500 | + if ($dst_w || $dst_h) { |
|
501 | 501 | // If destination width/height isn't specified, use same as |
502 | 502 | // width/height from source. |
503 | - if ( ! $dst_w ) |
|
503 | + if ( ! $dst_w) |
|
504 | 504 | $dst_w = $src_w; |
505 | - if ( ! $dst_h ) |
|
505 | + if ( ! $dst_h) |
|
506 | 506 | $dst_h = $src_h; |
507 | 507 | |
508 | - $thumb_result = $this->thumbnail_image( $dst_w, $dst_h ); |
|
509 | - if ( is_wp_error( $thumb_result ) ) { |
|
508 | + $thumb_result = $this->thumbnail_image($dst_w, $dst_h); |
|
509 | + if (is_wp_error($thumb_result)) { |
|
510 | 510 | return $thumb_result; |
511 | 511 | } |
512 | 512 | |
513 | 513 | return $this->update_size(); |
514 | 514 | } |
515 | 515 | } |
516 | - catch ( Exception $e ) { |
|
517 | - return new WP_Error( 'image_crop_error', $e->getMessage() ); |
|
516 | + catch (Exception $e) { |
|
517 | + return new WP_Error('image_crop_error', $e->getMessage()); |
|
518 | 518 | } |
519 | 519 | return $this->update_size(); |
520 | 520 | } |
@@ -528,23 +528,23 @@ discard block |
||
528 | 528 | * @param float $angle |
529 | 529 | * @return true|WP_Error |
530 | 530 | */ |
531 | - public function rotate( $angle ) { |
|
531 | + public function rotate($angle) { |
|
532 | 532 | /** |
533 | 533 | * $angle is 360-$angle because Imagick rotates clockwise |
534 | 534 | * (GD rotates counter-clockwise) |
535 | 535 | */ |
536 | 536 | try { |
537 | - $this->image->rotateImage( new ImagickPixel('none'), 360-$angle ); |
|
537 | + $this->image->rotateImage(new ImagickPixel('none'), 360 - $angle); |
|
538 | 538 | |
539 | 539 | // Since this changes the dimensions of the image, update the size. |
540 | 540 | $result = $this->update_size(); |
541 | - if ( is_wp_error( $result ) ) |
|
541 | + if (is_wp_error($result)) |
|
542 | 542 | return $result; |
543 | 543 | |
544 | - $this->image->setImagePage( $this->size['width'], $this->size['height'], 0, 0 ); |
|
544 | + $this->image->setImagePage($this->size['width'], $this->size['height'], 0, 0); |
|
545 | 545 | } |
546 | - catch ( Exception $e ) { |
|
547 | - return new WP_Error( 'image_rotate_error', $e->getMessage() ); |
|
546 | + catch (Exception $e) { |
|
547 | + return new WP_Error('image_rotate_error', $e->getMessage()); |
|
548 | 548 | } |
549 | 549 | return true; |
550 | 550 | } |
@@ -559,16 +559,16 @@ discard block |
||
559 | 559 | * @param bool $vert Flip along Vertical Axis |
560 | 560 | * @return true|WP_Error |
561 | 561 | */ |
562 | - public function flip( $horz, $vert ) { |
|
562 | + public function flip($horz, $vert) { |
|
563 | 563 | try { |
564 | - if ( $horz ) |
|
564 | + if ($horz) |
|
565 | 565 | $this->image->flipImage(); |
566 | 566 | |
567 | - if ( $vert ) |
|
567 | + if ($vert) |
|
568 | 568 | $this->image->flopImage(); |
569 | 569 | } |
570 | - catch ( Exception $e ) { |
|
571 | - return new WP_Error( 'image_flip_error', $e->getMessage() ); |
|
570 | + catch (Exception $e) { |
|
571 | + return new WP_Error('image_flip_error', $e->getMessage()); |
|
572 | 572 | } |
573 | 573 | return true; |
574 | 574 | } |
@@ -583,18 +583,18 @@ discard block |
||
583 | 583 | * @param string $mime_type |
584 | 584 | * @return array|WP_Error {'path'=>string, 'file'=>string, 'width'=>int, 'height'=>int, 'mime-type'=>string} |
585 | 585 | */ |
586 | - public function save( $destfilename = null, $mime_type = null ) { |
|
587 | - $saved = $this->_save( $this->image, $destfilename, $mime_type ); |
|
586 | + public function save($destfilename = null, $mime_type = null) { |
|
587 | + $saved = $this->_save($this->image, $destfilename, $mime_type); |
|
588 | 588 | |
589 | - if ( ! is_wp_error( $saved ) ) { |
|
589 | + if ( ! is_wp_error($saved)) { |
|
590 | 590 | $this->file = $saved['path']; |
591 | 591 | $this->mime_type = $saved['mime-type']; |
592 | 592 | |
593 | 593 | try { |
594 | - $this->image->setImageFormat( strtoupper( $this->get_extension( $this->mime_type ) ) ); |
|
594 | + $this->image->setImageFormat(strtoupper($this->get_extension($this->mime_type))); |
|
595 | 595 | } |
596 | - catch ( Exception $e ) { |
|
597 | - return new WP_Error( 'image_save_error', $e->getMessage(), $this->file ); |
|
596 | + catch (Exception $e) { |
|
597 | + return new WP_Error('image_save_error', $e->getMessage(), $this->file); |
|
598 | 598 | } |
599 | 599 | } |
600 | 600 | |
@@ -608,35 +608,35 @@ discard block |
||
608 | 608 | * @param string $mime_type |
609 | 609 | * @return array|WP_Error |
610 | 610 | */ |
611 | - protected function _save( $image, $filename = null, $mime_type = null ) { |
|
612 | - list( $filename, $extension, $mime_type ) = $this->get_output_format( $filename, $mime_type ); |
|
611 | + protected function _save($image, $filename = null, $mime_type = null) { |
|
612 | + list($filename, $extension, $mime_type) = $this->get_output_format($filename, $mime_type); |
|
613 | 613 | |
614 | - if ( ! $filename ) |
|
615 | - $filename = $this->generate_filename( null, null, $extension ); |
|
614 | + if ( ! $filename) |
|
615 | + $filename = $this->generate_filename(null, null, $extension); |
|
616 | 616 | |
617 | 617 | try { |
618 | 618 | // Store initial Format |
619 | 619 | $orig_format = $this->image->getImageFormat(); |
620 | 620 | |
621 | - $this->image->setImageFormat( strtoupper( $this->get_extension( $mime_type ) ) ); |
|
622 | - $this->make_image( $filename, array( $image, 'writeImage' ), array( $filename ) ); |
|
621 | + $this->image->setImageFormat(strtoupper($this->get_extension($mime_type))); |
|
622 | + $this->make_image($filename, array($image, 'writeImage'), array($filename)); |
|
623 | 623 | |
624 | 624 | // Reset original Format |
625 | - $this->image->setImageFormat( $orig_format ); |
|
625 | + $this->image->setImageFormat($orig_format); |
|
626 | 626 | } |
627 | - catch ( Exception $e ) { |
|
628 | - return new WP_Error( 'image_save_error', $e->getMessage(), $filename ); |
|
627 | + catch (Exception $e) { |
|
628 | + return new WP_Error('image_save_error', $e->getMessage(), $filename); |
|
629 | 629 | } |
630 | 630 | |
631 | 631 | // Set correct file permissions |
632 | - $stat = stat( dirname( $filename ) ); |
|
632 | + $stat = stat(dirname($filename)); |
|
633 | 633 | $perms = $stat['mode'] & 0000666; //same permissions as parent folder, strip off the executable bits |
634 | - @ chmod( $filename, $perms ); |
|
634 | + @ chmod($filename, $perms); |
|
635 | 635 | |
636 | 636 | /** This filter is documented in wp-includes/class-wp-image-editor-gd.php */ |
637 | 637 | return array( |
638 | 638 | 'path' => $filename, |
639 | - 'file' => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ), |
|
639 | + 'file' => wp_basename(apply_filters('image_make_intermediate_size', $filename)), |
|
640 | 640 | 'width' => $this->size['width'], |
641 | 641 | 'height' => $this->size['height'], |
642 | 642 | 'mime-type' => $mime_type, |
@@ -652,22 +652,22 @@ discard block |
||
652 | 652 | * @param string $mime_type |
653 | 653 | * @return true|WP_Error |
654 | 654 | */ |
655 | - public function stream( $mime_type = null ) { |
|
656 | - list( $filename, $extension, $mime_type ) = $this->get_output_format( null, $mime_type ); |
|
655 | + public function stream($mime_type = null) { |
|
656 | + list($filename, $extension, $mime_type) = $this->get_output_format(null, $mime_type); |
|
657 | 657 | |
658 | 658 | try { |
659 | 659 | // Temporarily change format for stream |
660 | - $this->image->setImageFormat( strtoupper( $extension ) ); |
|
660 | + $this->image->setImageFormat(strtoupper($extension)); |
|
661 | 661 | |
662 | 662 | // Output stream of image content |
663 | - header( "Content-Type: $mime_type" ); |
|
663 | + header("Content-Type: $mime_type"); |
|
664 | 664 | print $this->image->getImageBlob(); |
665 | 665 | |
666 | 666 | // Reset Image to original Format |
667 | - $this->image->setImageFormat( $this->get_extension( $this->mime_type ) ); |
|
667 | + $this->image->setImageFormat($this->get_extension($this->mime_type)); |
|
668 | 668 | } |
669 | - catch ( Exception $e ) { |
|
670 | - return new WP_Error( 'image_stream_error', $e->getMessage() ); |
|
669 | + catch (Exception $e) { |
|
670 | + return new WP_Error('image_stream_error', $e->getMessage()); |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | return true; |
@@ -683,14 +683,14 @@ discard block |
||
683 | 683 | */ |
684 | 684 | protected function strip_meta() { |
685 | 685 | |
686 | - if ( ! is_callable( array( $this->image, 'getImageProfiles' ) ) ) { |
|
686 | + if ( ! is_callable(array($this->image, 'getImageProfiles'))) { |
|
687 | 687 | /* translators: %s: ImageMagick method name */ |
688 | - return new WP_Error( 'image_strip_meta_error', sprintf( __( '%s is required to strip image meta.' ), '<code>Imagick::getImageProfiles()</code>' ) ); |
|
688 | + return new WP_Error('image_strip_meta_error', sprintf(__('%s is required to strip image meta.'), '<code>Imagick::getImageProfiles()</code>')); |
|
689 | 689 | } |
690 | 690 | |
691 | - if ( ! is_callable( array( $this->image, 'removeImageProfile' ) ) ) { |
|
691 | + if ( ! is_callable(array($this->image, 'removeImageProfile'))) { |
|
692 | 692 | /* translators: %s: ImageMagick method name */ |
693 | - return new WP_Error( 'image_strip_meta_error', sprintf( __( '%s is required to strip image meta.' ), '<code>Imagick::removeImageProfile()</code>' ) ); |
|
693 | + return new WP_Error('image_strip_meta_error', sprintf(__('%s is required to strip image meta.'), '<code>Imagick::removeImageProfile()</code>')); |
|
694 | 694 | } |
695 | 695 | |
696 | 696 | /* |
@@ -712,14 +712,14 @@ discard block |
||
712 | 712 | |
713 | 713 | try { |
714 | 714 | // Strip profiles. |
715 | - foreach ( $this->image->getImageProfiles( '*', true ) as $key => $value ) { |
|
716 | - if ( ! in_array( $key, $protected_profiles ) ) { |
|
717 | - $this->image->removeImageProfile( $key ); |
|
715 | + foreach ($this->image->getImageProfiles('*', true) as $key => $value) { |
|
716 | + if ( ! in_array($key, $protected_profiles)) { |
|
717 | + $this->image->removeImageProfile($key); |
|
718 | 718 | } |
719 | 719 | } |
720 | 720 | |
721 | - } catch ( Exception $e ) { |
|
722 | - return new WP_Error( 'image_strip_meta_error', $e->getMessage() ); |
|
721 | + } catch (Exception $e) { |
|
722 | + return new WP_Error('image_strip_meta_error', $e->getMessage()); |
|
723 | 723 | } |
724 | 724 | |
725 | 725 | return true; |
@@ -48,11 +48,13 @@ discard block |
||
48 | 48 | public static function test( $args = array() ) { |
49 | 49 | |
50 | 50 | // First, test Imagick's extension and classes. |
51 | - if ( ! extension_loaded( 'imagick' ) || ! class_exists( 'Imagick', false ) || ! class_exists( 'ImagickPixel', false ) ) |
|
52 | - return false; |
|
51 | + if ( ! extension_loaded( 'imagick' ) || ! class_exists( 'Imagick', false ) || ! class_exists( 'ImagickPixel', false ) ) { |
|
52 | + return false; |
|
53 | + } |
|
53 | 54 | |
54 | - if ( version_compare( phpversion( 'imagick' ), '2.2.0', '<' ) ) |
|
55 | - return false; |
|
55 | + if ( version_compare( phpversion( 'imagick' ), '2.2.0', '<' ) ) { |
|
56 | + return false; |
|
57 | + } |
|
56 | 58 | |
57 | 59 | $required_methods = array( |
58 | 60 | 'clear', |
@@ -76,8 +78,9 @@ discard block |
||
76 | 78 | ); |
77 | 79 | |
78 | 80 | // Now, test for deep requirements within Imagick. |
79 | - if ( ! defined( 'imagick::COMPRESSION_JPEG' ) ) |
|
80 | - return false; |
|
81 | + if ( ! defined( 'imagick::COMPRESSION_JPEG' ) ) { |
|
82 | + return false; |
|
83 | + } |
|
81 | 84 | |
82 | 85 | $class_methods = array_map( 'strtolower', get_class_methods( 'Imagick' ) ); |
83 | 86 | if ( array_diff( $required_methods, $class_methods ) ) { |
@@ -106,18 +109,19 @@ discard block |
||
106 | 109 | public static function supports_mime_type( $mime_type ) { |
107 | 110 | $imagick_extension = strtoupper( self::get_extension( $mime_type ) ); |
108 | 111 | |
109 | - if ( ! $imagick_extension ) |
|
110 | - return false; |
|
112 | + if ( ! $imagick_extension ) { |
|
113 | + return false; |
|
114 | + } |
|
111 | 115 | |
112 | 116 | // setIteratorIndex is optional unless mime is an animated format. |
113 | 117 | // Here, we just say no if you are missing it and aren't loading a jpeg. |
114 | - if ( ! method_exists( 'Imagick', 'setIteratorIndex' ) && $mime_type != 'image/jpeg' ) |
|
115 | - return false; |
|
118 | + if ( ! method_exists( 'Imagick', 'setIteratorIndex' ) && $mime_type != 'image/jpeg' ) { |
|
119 | + return false; |
|
120 | + } |
|
116 | 121 | |
117 | 122 | try { |
118 | 123 | return ( (bool) @Imagick::queryFormats( $imagick_extension ) ); |
119 | - } |
|
120 | - catch ( Exception $e ) { |
|
124 | + } catch ( Exception $e ) { |
|
121 | 125 | return false; |
122 | 126 | } |
123 | 127 | } |
@@ -131,11 +135,13 @@ discard block |
||
131 | 135 | * @return true|WP_Error True if loaded; WP_Error on failure. |
132 | 136 | */ |
133 | 137 | public function load() { |
134 | - if ( $this->image instanceof Imagick ) |
|
135 | - return true; |
|
138 | + if ( $this->image instanceof Imagick ) { |
|
139 | + return true; |
|
140 | + } |
|
136 | 141 | |
137 | - if ( ! is_file( $this->file ) && ! preg_match( '|^https?://|', $this->file ) ) |
|
138 | - return new WP_Error( 'error_loading_image', __('File doesn’t exist?'), $this->file ); |
|
142 | + if ( ! is_file( $this->file ) && ! preg_match( '|^https?://|', $this->file ) ) { |
|
143 | + return new WP_Error( 'error_loading_image', __('File doesn’t exist?'), $this->file ); |
|
144 | + } |
|
139 | 145 | |
140 | 146 | /** This filter is documented in wp-includes/class-wp-image-editor-imagick.php */ |
141 | 147 | // Even though Imagick uses less PHP memory than GD, set higher limit for users that have low PHP.ini limits |
@@ -144,16 +150,17 @@ discard block |
||
144 | 150 | try { |
145 | 151 | $this->image = new Imagick( $this->file ); |
146 | 152 | |
147 | - if ( ! $this->image->valid() ) |
|
148 | - return new WP_Error( 'invalid_image', __('File is not an image.'), $this->file); |
|
153 | + if ( ! $this->image->valid() ) { |
|
154 | + return new WP_Error( 'invalid_image', __('File is not an image.'), $this->file); |
|
155 | + } |
|
149 | 156 | |
150 | 157 | // Select the first frame to handle animated images properly |
151 | - if ( is_callable( array( $this->image, 'setIteratorIndex' ) ) ) |
|
152 | - $this->image->setIteratorIndex(0); |
|
158 | + if ( is_callable( array( $this->image, 'setIteratorIndex' ) ) ) { |
|
159 | + $this->image->setIteratorIndex(0); |
|
160 | + } |
|
153 | 161 | |
154 | 162 | $this->mime_type = $this->get_mime_type( $this->image->getImageFormat() ); |
155 | - } |
|
156 | - catch ( Exception $e ) { |
|
163 | + } catch ( Exception $e ) { |
|
157 | 164 | return new WP_Error( 'invalid_image', $e->getMessage(), $this->file ); |
158 | 165 | } |
159 | 166 | |
@@ -186,12 +193,10 @@ discard block |
||
186 | 193 | if ( 'image/jpeg' == $this->mime_type ) { |
187 | 194 | $this->image->setImageCompressionQuality( $quality ); |
188 | 195 | $this->image->setImageCompression( imagick::COMPRESSION_JPEG ); |
189 | - } |
|
190 | - else { |
|
196 | + } else { |
|
191 | 197 | $this->image->setImageCompressionQuality( $quality ); |
192 | 198 | } |
193 | - } |
|
194 | - catch ( Exception $e ) { |
|
199 | + } catch ( Exception $e ) { |
|
195 | 200 | return new WP_Error( 'image_quality_error', $e->getMessage() ); |
196 | 201 | } |
197 | 202 | |
@@ -214,17 +219,18 @@ discard block |
||
214 | 219 | if ( !$width || !$height ) { |
215 | 220 | try { |
216 | 221 | $size = $this->image->getImageGeometry(); |
217 | - } |
|
218 | - catch ( Exception $e ) { |
|
222 | + } catch ( Exception $e ) { |
|
219 | 223 | return new WP_Error( 'invalid_image', __( 'Could not read image size.' ), $this->file ); |
220 | 224 | } |
221 | 225 | } |
222 | 226 | |
223 | - if ( ! $width ) |
|
224 | - $width = $size['width']; |
|
227 | + if ( ! $width ) { |
|
228 | + $width = $size['width']; |
|
229 | + } |
|
225 | 230 | |
226 | - if ( ! $height ) |
|
227 | - $height = $size['height']; |
|
231 | + if ( ! $height ) { |
|
232 | + $height = $size['height']; |
|
233 | + } |
|
228 | 234 | |
229 | 235 | return parent::update_size( $width, $height ); |
230 | 236 | } |
@@ -245,12 +251,14 @@ discard block |
||
245 | 251 | * @return bool|WP_Error |
246 | 252 | */ |
247 | 253 | public function resize( $max_w, $max_h, $crop = false ) { |
248 | - if ( ( $this->size['width'] == $max_w ) && ( $this->size['height'] == $max_h ) ) |
|
249 | - return true; |
|
254 | + if ( ( $this->size['width'] == $max_w ) && ( $this->size['height'] == $max_h ) ) { |
|
255 | + return true; |
|
256 | + } |
|
250 | 257 | |
251 | 258 | $dims = image_resize_dimensions( $this->size['width'], $this->size['height'], $max_w, $max_h, $crop ); |
252 | - if ( ! $dims ) |
|
253 | - return new WP_Error( 'error_getting_dimensions', __('Could not calculate resized image dimensions') ); |
|
259 | + if ( ! $dims ) { |
|
260 | + return new WP_Error( 'error_getting_dimensions', __('Could not calculate resized image dimensions') ); |
|
261 | + } |
|
254 | 262 | list( $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ) = $dims; |
255 | 263 | |
256 | 264 | if ( $crop ) { |
@@ -395,8 +403,7 @@ discard block |
||
395 | 403 | $this->image->setInterlaceScheme( Imagick::INTERLACE_NO ); |
396 | 404 | } |
397 | 405 | |
398 | - } |
|
399 | - catch ( Exception $e ) { |
|
406 | + } catch ( Exception $e ) { |
|
400 | 407 | return new WP_Error( 'image_resize_error', $e->getMessage() ); |
401 | 408 | } |
402 | 409 | } |
@@ -430,8 +437,9 @@ discard block |
||
430 | 437 | $orig_image = $this->image->getImage(); |
431 | 438 | |
432 | 439 | foreach ( $sizes as $size => $size_data ) { |
433 | - if ( ! $this->image ) |
|
434 | - $this->image = $orig_image->getImage(); |
|
440 | + if ( ! $this->image ) { |
|
441 | + $this->image = $orig_image->getImage(); |
|
442 | + } |
|
435 | 443 | |
436 | 444 | if ( ! isset( $size_data['width'] ) && ! isset( $size_data['height'] ) ) { |
437 | 445 | continue; |
@@ -500,10 +508,12 @@ discard block |
||
500 | 508 | if ( $dst_w || $dst_h ) { |
501 | 509 | // If destination width/height isn't specified, use same as |
502 | 510 | // width/height from source. |
503 | - if ( ! $dst_w ) |
|
504 | - $dst_w = $src_w; |
|
505 | - if ( ! $dst_h ) |
|
506 | - $dst_h = $src_h; |
|
511 | + if ( ! $dst_w ) { |
|
512 | + $dst_w = $src_w; |
|
513 | + } |
|
514 | + if ( ! $dst_h ) { |
|
515 | + $dst_h = $src_h; |
|
516 | + } |
|
507 | 517 | |
508 | 518 | $thumb_result = $this->thumbnail_image( $dst_w, $dst_h ); |
509 | 519 | if ( is_wp_error( $thumb_result ) ) { |
@@ -512,8 +522,7 @@ discard block |
||
512 | 522 | |
513 | 523 | return $this->update_size(); |
514 | 524 | } |
515 | - } |
|
516 | - catch ( Exception $e ) { |
|
525 | + } catch ( Exception $e ) { |
|
517 | 526 | return new WP_Error( 'image_crop_error', $e->getMessage() ); |
518 | 527 | } |
519 | 528 | return $this->update_size(); |
@@ -538,12 +547,12 @@ discard block |
||
538 | 547 | |
539 | 548 | // Since this changes the dimensions of the image, update the size. |
540 | 549 | $result = $this->update_size(); |
541 | - if ( is_wp_error( $result ) ) |
|
542 | - return $result; |
|
550 | + if ( is_wp_error( $result ) ) { |
|
551 | + return $result; |
|
552 | + } |
|
543 | 553 | |
544 | 554 | $this->image->setImagePage( $this->size['width'], $this->size['height'], 0, 0 ); |
545 | - } |
|
546 | - catch ( Exception $e ) { |
|
555 | + } catch ( Exception $e ) { |
|
547 | 556 | return new WP_Error( 'image_rotate_error', $e->getMessage() ); |
548 | 557 | } |
549 | 558 | return true; |
@@ -561,13 +570,14 @@ discard block |
||
561 | 570 | */ |
562 | 571 | public function flip( $horz, $vert ) { |
563 | 572 | try { |
564 | - if ( $horz ) |
|
565 | - $this->image->flipImage(); |
|
573 | + if ( $horz ) { |
|
574 | + $this->image->flipImage(); |
|
575 | + } |
|
566 | 576 | |
567 | - if ( $vert ) |
|
568 | - $this->image->flopImage(); |
|
569 | - } |
|
570 | - catch ( Exception $e ) { |
|
577 | + if ( $vert ) { |
|
578 | + $this->image->flopImage(); |
|
579 | + } |
|
580 | + } catch ( Exception $e ) { |
|
571 | 581 | return new WP_Error( 'image_flip_error', $e->getMessage() ); |
572 | 582 | } |
573 | 583 | return true; |
@@ -592,8 +602,7 @@ discard block |
||
592 | 602 | |
593 | 603 | try { |
594 | 604 | $this->image->setImageFormat( strtoupper( $this->get_extension( $this->mime_type ) ) ); |
595 | - } |
|
596 | - catch ( Exception $e ) { |
|
605 | + } catch ( Exception $e ) { |
|
597 | 606 | return new WP_Error( 'image_save_error', $e->getMessage(), $this->file ); |
598 | 607 | } |
599 | 608 | } |
@@ -611,8 +620,9 @@ discard block |
||
611 | 620 | protected function _save( $image, $filename = null, $mime_type = null ) { |
612 | 621 | list( $filename, $extension, $mime_type ) = $this->get_output_format( $filename, $mime_type ); |
613 | 622 | |
614 | - if ( ! $filename ) |
|
615 | - $filename = $this->generate_filename( null, null, $extension ); |
|
623 | + if ( ! $filename ) { |
|
624 | + $filename = $this->generate_filename( null, null, $extension ); |
|
625 | + } |
|
616 | 626 | |
617 | 627 | try { |
618 | 628 | // Store initial Format |
@@ -623,8 +633,7 @@ discard block |
||
623 | 633 | |
624 | 634 | // Reset original Format |
625 | 635 | $this->image->setImageFormat( $orig_format ); |
626 | - } |
|
627 | - catch ( Exception $e ) { |
|
636 | + } catch ( Exception $e ) { |
|
628 | 637 | return new WP_Error( 'image_save_error', $e->getMessage(), $filename ); |
629 | 638 | } |
630 | 639 | |
@@ -665,8 +674,7 @@ discard block |
||
665 | 674 | |
666 | 675 | // Reset Image to original Format |
667 | 676 | $this->image->setImageFormat( $this->get_extension( $this->mime_type ) ); |
668 | - } |
|
669 | - catch ( Exception $e ) { |
|
677 | + } catch ( Exception $e ) { |
|
670 | 678 | return new WP_Error( 'image_stream_error', $e->getMessage() ); |
671 | 679 | } |
672 | 680 |
@@ -215,8 +215,9 @@ discard block |
||
215 | 215 | * @return array The headers of the response. Empty array if incorrect parameter given. |
216 | 216 | */ |
217 | 217 | function wp_remote_retrieve_headers( $response ) { |
218 | - if ( is_wp_error($response) || ! isset($response['headers']) || ! is_array($response['headers'])) |
|
219 | - return array(); |
|
218 | + if ( is_wp_error($response) || ! isset($response['headers']) || ! is_array($response['headers'])) { |
|
219 | + return array(); |
|
220 | + } |
|
220 | 221 | |
221 | 222 | return $response['headers']; |
222 | 223 | } |
@@ -231,11 +232,13 @@ discard block |
||
231 | 232 | * @return string The header value. Empty string on if incorrect parameter given, or if the header doesn't exist. |
232 | 233 | */ |
233 | 234 | function wp_remote_retrieve_header( $response, $header ) { |
234 | - if ( is_wp_error($response) || ! isset($response['headers']) || ! is_array($response['headers'])) |
|
235 | - return ''; |
|
235 | + if ( is_wp_error($response) || ! isset($response['headers']) || ! is_array($response['headers'])) { |
|
236 | + return ''; |
|
237 | + } |
|
236 | 238 | |
237 | - if ( array_key_exists($header, $response['headers']) ) |
|
238 | - return $response['headers'][$header]; |
|
239 | + if ( array_key_exists($header, $response['headers']) ) { |
|
240 | + return $response['headers'][$header]; |
|
241 | + } |
|
239 | 242 | |
240 | 243 | return ''; |
241 | 244 | } |
@@ -251,8 +254,9 @@ discard block |
||
251 | 254 | * @return int|string The response code as an integer. Empty string on incorrect parameter given. |
252 | 255 | */ |
253 | 256 | function wp_remote_retrieve_response_code( $response ) { |
254 | - if ( is_wp_error($response) || ! isset($response['response']) || ! is_array($response['response'])) |
|
255 | - return ''; |
|
257 | + if ( is_wp_error($response) || ! isset($response['response']) || ! is_array($response['response'])) { |
|
258 | + return ''; |
|
259 | + } |
|
256 | 260 | |
257 | 261 | return $response['response']['code']; |
258 | 262 | } |
@@ -268,8 +272,9 @@ discard block |
||
268 | 272 | * @return string The response message. Empty string on incorrect parameter given. |
269 | 273 | */ |
270 | 274 | function wp_remote_retrieve_response_message( $response ) { |
271 | - if ( is_wp_error($response) || ! isset($response['response']) || ! is_array($response['response'])) |
|
272 | - return ''; |
|
275 | + if ( is_wp_error($response) || ! isset($response['response']) || ! is_array($response['response'])) { |
|
276 | + return ''; |
|
277 | + } |
|
273 | 278 | |
274 | 279 | return $response['response']['message']; |
275 | 280 | } |
@@ -283,8 +288,9 @@ discard block |
||
283 | 288 | * @return string The body of the response. Empty string if no body or incorrect parameter given. |
284 | 289 | */ |
285 | 290 | function wp_remote_retrieve_body( $response ) { |
286 | - if ( is_wp_error($response) || ! isset($response['body']) ) |
|
287 | - return ''; |
|
291 | + if ( is_wp_error($response) || ! isset($response['body']) ) { |
|
292 | + return ''; |
|
293 | + } |
|
288 | 294 | |
289 | 295 | return $response['body']; |
290 | 296 | } |
@@ -331,8 +337,9 @@ discard block |
||
331 | 337 | */ |
332 | 338 | function get_http_origin() { |
333 | 339 | $origin = ''; |
334 | - if ( ! empty ( $_SERVER[ 'HTTP_ORIGIN' ] ) ) |
|
335 | - $origin = $_SERVER[ 'HTTP_ORIGIN' ]; |
|
340 | + if ( ! empty ( $_SERVER[ 'HTTP_ORIGIN' ] ) ) { |
|
341 | + $origin = $_SERVER[ 'HTTP_ORIGIN' ]; |
|
342 | + } |
|
336 | 343 | |
337 | 344 | /** |
338 | 345 | * Change the origin of an HTTP request. |
@@ -390,11 +397,13 @@ discard block |
||
390 | 397 | function is_allowed_http_origin( $origin = null ) { |
391 | 398 | $origin_arg = $origin; |
392 | 399 | |
393 | - if ( null === $origin ) |
|
394 | - $origin = get_http_origin(); |
|
400 | + if ( null === $origin ) { |
|
401 | + $origin = get_http_origin(); |
|
402 | + } |
|
395 | 403 | |
396 | - if ( $origin && ! in_array( $origin, get_allowed_http_origins() ) ) |
|
397 | - $origin = ''; |
|
404 | + if ( $origin && ! in_array( $origin, get_allowed_http_origins() ) ) { |
|
405 | + $origin = ''; |
|
406 | + } |
|
398 | 407 | |
399 | 408 | /** |
400 | 409 | * Change the allowed HTTP origin result. |
@@ -426,8 +435,9 @@ discard block |
||
426 | 435 | if ( is_allowed_http_origin( $origin ) ) { |
427 | 436 | @header( 'Access-Control-Allow-Origin: ' . $origin ); |
428 | 437 | @header( 'Access-Control-Allow-Credentials: true' ); |
429 | - if ( 'OPTIONS' === $_SERVER['REQUEST_METHOD'] ) |
|
430 | - exit; |
|
438 | + if ( 'OPTIONS' === $_SERVER['REQUEST_METHOD'] ) { |
|
439 | + exit; |
|
440 | + } |
|
431 | 441 | return $origin; |
432 | 442 | } |
433 | 443 | |
@@ -450,18 +460,22 @@ discard block |
||
450 | 460 | function wp_http_validate_url( $url ) { |
451 | 461 | $original_url = $url; |
452 | 462 | $url = wp_kses_bad_protocol( $url, array( 'http', 'https' ) ); |
453 | - if ( ! $url || strtolower( $url ) !== strtolower( $original_url ) ) |
|
454 | - return false; |
|
463 | + if ( ! $url || strtolower( $url ) !== strtolower( $original_url ) ) { |
|
464 | + return false; |
|
465 | + } |
|
455 | 466 | |
456 | 467 | $parsed_url = @parse_url( $url ); |
457 | - if ( ! $parsed_url || empty( $parsed_url['host'] ) ) |
|
458 | - return false; |
|
468 | + if ( ! $parsed_url || empty( $parsed_url['host'] ) ) { |
|
469 | + return false; |
|
470 | + } |
|
459 | 471 | |
460 | - if ( isset( $parsed_url['user'] ) || isset( $parsed_url['pass'] ) ) |
|
461 | - return false; |
|
472 | + if ( isset( $parsed_url['user'] ) || isset( $parsed_url['pass'] ) ) { |
|
473 | + return false; |
|
474 | + } |
|
462 | 475 | |
463 | - if ( false !== strpbrk( $parsed_url['host'], ':#?[]' ) ) |
|
464 | - return false; |
|
476 | + if ( false !== strpbrk( $parsed_url['host'], ':#?[]' ) ) { |
|
477 | + return false; |
|
478 | + } |
|
465 | 479 | |
466 | 480 | $parsed_home = @parse_url( get_option( 'home' ) ); |
467 | 481 | |
@@ -473,8 +487,10 @@ discard block |
||
473 | 487 | $ip = $host; |
474 | 488 | } else { |
475 | 489 | $ip = gethostbyname( $host ); |
476 | - if ( $ip === $host ) // Error condition for gethostbyname() |
|
490 | + if ( $ip === $host ) { |
|
491 | + // Error condition for gethostbyname() |
|
477 | 492 | $ip = false; |
493 | + } |
|
478 | 494 | } |
479 | 495 | if ( $ip ) { |
480 | 496 | $parts = array_map( 'intval', explode( '.', $ip ) ); |
@@ -494,21 +510,25 @@ discard block |
||
494 | 510 | * @param string $host IP of the requested host. |
495 | 511 | * @param string $url URL of the requested host. |
496 | 512 | */ |
497 | - if ( ! apply_filters( 'http_request_host_is_external', false, $host, $url ) ) |
|
498 | - return false; |
|
513 | + if ( ! apply_filters( 'http_request_host_is_external', false, $host, $url ) ) { |
|
514 | + return false; |
|
515 | + } |
|
499 | 516 | } |
500 | 517 | } |
501 | 518 | } |
502 | 519 | |
503 | - if ( empty( $parsed_url['port'] ) ) |
|
504 | - return $url; |
|
520 | + if ( empty( $parsed_url['port'] ) ) { |
|
521 | + return $url; |
|
522 | + } |
|
505 | 523 | |
506 | 524 | $port = $parsed_url['port']; |
507 | - if ( 80 === $port || 443 === $port || 8080 === $port ) |
|
508 | - return $url; |
|
525 | + if ( 80 === $port || 443 === $port || 8080 === $port ) { |
|
526 | + return $url; |
|
527 | + } |
|
509 | 528 | |
510 | - if ( $parsed_home && $same_host && isset( $parsed_home['port'] ) && $parsed_home['port'] === $port ) |
|
511 | - return $url; |
|
529 | + if ( $parsed_home && $same_host && isset( $parsed_home['port'] ) && $parsed_home['port'] === $port ) { |
|
530 | + return $url; |
|
531 | + } |
|
512 | 532 | |
513 | 533 | return false; |
514 | 534 | } |
@@ -525,8 +545,9 @@ discard block |
||
525 | 545 | * @return bool |
526 | 546 | */ |
527 | 547 | function allowed_http_request_hosts( $is_external, $host ) { |
528 | - if ( ! $is_external && wp_validate_redirect( 'http://' . $host ) ) |
|
529 | - $is_external = true; |
|
548 | + if ( ! $is_external && wp_validate_redirect( 'http://' . $host ) ) { |
|
549 | + $is_external = true; |
|
550 | + } |
|
530 | 551 | return $is_external; |
531 | 552 | } |
532 | 553 | |
@@ -547,12 +568,15 @@ discard block |
||
547 | 568 | function ms_allowed_http_request_hosts( $is_external, $host ) { |
548 | 569 | global $wpdb; |
549 | 570 | static $queried = array(); |
550 | - if ( $is_external ) |
|
551 | - return $is_external; |
|
552 | - if ( $host === get_current_site()->domain ) |
|
553 | - return true; |
|
554 | - if ( isset( $queried[ $host ] ) ) |
|
555 | - return $queried[ $host ]; |
|
571 | + if ( $is_external ) { |
|
572 | + return $is_external; |
|
573 | + } |
|
574 | + if ( $host === get_current_site()->domain ) { |
|
575 | + return true; |
|
576 | + } |
|
577 | + if ( isset( $queried[ $host ] ) ) { |
|
578 | + return $queried[ $host ]; |
|
579 | + } |
|
556 | 580 | $queried[ $host ] = (bool) $wpdb->get_var( $wpdb->prepare( "SELECT domain FROM $wpdb->blogs WHERE domain = %s LIMIT 1", $host ) ); |
557 | 581 | return $queried[ $host ]; |
558 | 582 | } |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Core HTTP Request API |
|
4 | - * |
|
5 | - * Standardizes the HTTP requests for WordPress. Handles cookies, gzip encoding and decoding, chunk |
|
6 | - * decoding, if HTTP 1.1 and various other difficult HTTP protocol implementations. |
|
7 | - * |
|
8 | - * @package WordPress |
|
9 | - * @subpackage HTTP |
|
10 | - */ |
|
3 | + * Core HTTP Request API |
|
4 | + * |
|
5 | + * Standardizes the HTTP requests for WordPress. Handles cookies, gzip encoding and decoding, chunk |
|
6 | + * decoding, if HTTP 1.1 and various other difficult HTTP protocol implementations. |
|
7 | + * |
|
8 | + * @package WordPress |
|
9 | + * @subpackage HTTP |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * Returns the initialized WP_Http Object |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | function _wp_http_get_object() { |
23 | 23 | static $http = null; |
24 | 24 | |
25 | - if ( is_null( $http ) ) { |
|
25 | + if (is_null($http)) { |
|
26 | 26 | $http = new WP_Http(); |
27 | 27 | } |
28 | 28 | return $http; |
@@ -43,10 +43,10 @@ discard block |
||
43 | 43 | * @param array $args Optional. Request arguments. Default empty array. |
44 | 44 | * @return WP_Error|array The response or WP_Error on failure. |
45 | 45 | */ |
46 | -function wp_safe_remote_request( $url, $args = array() ) { |
|
46 | +function wp_safe_remote_request($url, $args = array()) { |
|
47 | 47 | $args['reject_unsafe_urls'] = true; |
48 | 48 | $http = _wp_http_get_object(); |
49 | - return $http->request( $url, $args ); |
|
49 | + return $http->request($url, $args); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -64,10 +64,10 @@ discard block |
||
64 | 64 | * @param array $args Optional. Request arguments. Default empty array. |
65 | 65 | * @return WP_Error|array The response or WP_Error on failure. |
66 | 66 | */ |
67 | -function wp_safe_remote_get( $url, $args = array() ) { |
|
67 | +function wp_safe_remote_get($url, $args = array()) { |
|
68 | 68 | $args['reject_unsafe_urls'] = true; |
69 | 69 | $http = _wp_http_get_object(); |
70 | - return $http->get( $url, $args ); |
|
70 | + return $http->get($url, $args); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -85,10 +85,10 @@ discard block |
||
85 | 85 | * @param array $args Optional. Request arguments. Default empty array. |
86 | 86 | * @return WP_Error|array The response or WP_Error on failure. |
87 | 87 | */ |
88 | -function wp_safe_remote_post( $url, $args = array() ) { |
|
88 | +function wp_safe_remote_post($url, $args = array()) { |
|
89 | 89 | $args['reject_unsafe_urls'] = true; |
90 | 90 | $http = _wp_http_get_object(); |
91 | - return $http->post( $url, $args ); |
|
91 | + return $http->post($url, $args); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -106,10 +106,10 @@ discard block |
||
106 | 106 | * @param array $args Optional. Request arguments. Default empty array. |
107 | 107 | * @return WP_Error|array The response or WP_Error on failure. |
108 | 108 | */ |
109 | -function wp_safe_remote_head( $url, $args = array() ) { |
|
109 | +function wp_safe_remote_head($url, $args = array()) { |
|
110 | 110 | $args['reject_unsafe_urls'] = true; |
111 | 111 | $http = _wp_http_get_object(); |
112 | - return $http->head( $url, $args ); |
|
112 | + return $http->head($url, $args); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | */ |
151 | 151 | function wp_remote_request($url, $args = array()) { |
152 | 152 | $http = _wp_http_get_object(); |
153 | - return $http->request( $url, $args ); |
|
153 | + return $http->request($url, $args); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | */ |
168 | 168 | function wp_remote_get($url, $args = array()) { |
169 | 169 | $http = _wp_http_get_object(); |
170 | - return $http->get( $url, $args ); |
|
170 | + return $http->get($url, $args); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | */ |
185 | 185 | function wp_remote_post($url, $args = array()) { |
186 | 186 | $http = _wp_http_get_object(); |
187 | - return $http->post( $url, $args ); |
|
187 | + return $http->post($url, $args); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | */ |
202 | 202 | function wp_remote_head($url, $args = array()) { |
203 | 203 | $http = _wp_http_get_object(); |
204 | - return $http->head( $url, $args ); |
|
204 | + return $http->head($url, $args); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -212,8 +212,8 @@ discard block |
||
212 | 212 | * @param array $response HTTP response. |
213 | 213 | * @return array The headers of the response. Empty array if incorrect parameter given. |
214 | 214 | */ |
215 | -function wp_remote_retrieve_headers( $response ) { |
|
216 | - if ( is_wp_error($response) || ! isset($response['headers']) || ! is_array($response['headers'])) |
|
215 | +function wp_remote_retrieve_headers($response) { |
|
216 | + if (is_wp_error($response) || ! isset($response['headers']) || ! is_array($response['headers'])) |
|
217 | 217 | return array(); |
218 | 218 | |
219 | 219 | return $response['headers']; |
@@ -228,11 +228,11 @@ discard block |
||
228 | 228 | * @param string $header Header name to retrieve value from. |
229 | 229 | * @return string The header value. Empty string on if incorrect parameter given, or if the header doesn't exist. |
230 | 230 | */ |
231 | -function wp_remote_retrieve_header( $response, $header ) { |
|
232 | - if ( is_wp_error($response) || ! isset($response['headers']) || ! is_array($response['headers'])) |
|
231 | +function wp_remote_retrieve_header($response, $header) { |
|
232 | + if (is_wp_error($response) || ! isset($response['headers']) || ! is_array($response['headers'])) |
|
233 | 233 | return ''; |
234 | 234 | |
235 | - if ( array_key_exists($header, $response['headers']) ) |
|
235 | + if (array_key_exists($header, $response['headers'])) |
|
236 | 236 | return $response['headers'][$header]; |
237 | 237 | |
238 | 238 | return ''; |
@@ -248,8 +248,8 @@ discard block |
||
248 | 248 | * @param array $response HTTP response. |
249 | 249 | * @return int|string The response code as an integer. Empty string on incorrect parameter given. |
250 | 250 | */ |
251 | -function wp_remote_retrieve_response_code( $response ) { |
|
252 | - if ( is_wp_error($response) || ! isset($response['response']) || ! is_array($response['response'])) |
|
251 | +function wp_remote_retrieve_response_code($response) { |
|
252 | + if (is_wp_error($response) || ! isset($response['response']) || ! is_array($response['response'])) |
|
253 | 253 | return ''; |
254 | 254 | |
255 | 255 | return $response['response']['code']; |
@@ -265,8 +265,8 @@ discard block |
||
265 | 265 | * @param array $response HTTP response. |
266 | 266 | * @return string The response message. Empty string on incorrect parameter given. |
267 | 267 | */ |
268 | -function wp_remote_retrieve_response_message( $response ) { |
|
269 | - if ( is_wp_error($response) || ! isset($response['response']) || ! is_array($response['response'])) |
|
268 | +function wp_remote_retrieve_response_message($response) { |
|
269 | + if (is_wp_error($response) || ! isset($response['response']) || ! is_array($response['response'])) |
|
270 | 270 | return ''; |
271 | 271 | |
272 | 272 | return $response['response']['message']; |
@@ -280,8 +280,8 @@ discard block |
||
280 | 280 | * @param array $response HTTP response. |
281 | 281 | * @return string The body of the response. Empty string if no body or incorrect parameter given. |
282 | 282 | */ |
283 | -function wp_remote_retrieve_body( $response ) { |
|
284 | - if ( is_wp_error($response) || ! isset($response['body']) ) |
|
283 | +function wp_remote_retrieve_body($response) { |
|
284 | + if (is_wp_error($response) || ! isset($response['body'])) |
|
285 | 285 | return ''; |
286 | 286 | |
287 | 287 | return $response['body']; |
@@ -295,8 +295,8 @@ discard block |
||
295 | 295 | * @param array $response HTTP response. |
296 | 296 | * @return array An array of `WP_Http_Cookie` objects from the response. Empty array if there are none, or the response is a WP_Error. |
297 | 297 | */ |
298 | -function wp_remote_retrieve_cookies( $response ) { |
|
299 | - if ( is_wp_error( $response ) || empty( $response['cookies'] ) ) { |
|
298 | +function wp_remote_retrieve_cookies($response) { |
|
299 | + if (is_wp_error($response) || empty($response['cookies'])) { |
|
300 | 300 | return array(); |
301 | 301 | } |
302 | 302 | |
@@ -312,15 +312,15 @@ discard block |
||
312 | 312 | * @param string $name The name of the cookie to retrieve. |
313 | 313 | * @return WP_Http_Cookie|string The `WP_Http_Cookie` object. Empty string if the cookie isn't present in the response. |
314 | 314 | */ |
315 | -function wp_remote_retrieve_cookie( $response, $name ) { |
|
316 | - $cookies = wp_remote_retrieve_cookies( $response ); |
|
315 | +function wp_remote_retrieve_cookie($response, $name) { |
|
316 | + $cookies = wp_remote_retrieve_cookies($response); |
|
317 | 317 | |
318 | - if ( empty( $cookies ) ) { |
|
318 | + if (empty($cookies)) { |
|
319 | 319 | return ''; |
320 | 320 | } |
321 | 321 | |
322 | - foreach ( $cookies as $cookie ) { |
|
323 | - if ( $cookie->name === $name ) { |
|
322 | + foreach ($cookies as $cookie) { |
|
323 | + if ($cookie->name === $name) { |
|
324 | 324 | return $cookie; |
325 | 325 | } |
326 | 326 | } |
@@ -337,10 +337,10 @@ discard block |
||
337 | 337 | * @param string $name The name of the cookie to retrieve. |
338 | 338 | * @return string The value of the cookie. Empty string if the cookie isn't present in the response. |
339 | 339 | */ |
340 | -function wp_remote_retrieve_cookie_value( $response, $name ) { |
|
341 | - $cookie = wp_remote_retrieve_cookie( $response, $name ); |
|
340 | +function wp_remote_retrieve_cookie_value($response, $name) { |
|
341 | + $cookie = wp_remote_retrieve_cookie($response, $name); |
|
342 | 342 | |
343 | - if ( ! is_a( $cookie, 'WP_Http_Cookie' ) ) { |
|
343 | + if ( ! is_a($cookie, 'WP_Http_Cookie')) { |
|
344 | 344 | return ''; |
345 | 345 | } |
346 | 346 | |
@@ -358,26 +358,26 @@ discard block |
||
358 | 358 | * |
359 | 359 | * @return bool |
360 | 360 | */ |
361 | -function wp_http_supports( $capabilities = array(), $url = null ) { |
|
361 | +function wp_http_supports($capabilities = array(), $url = null) { |
|
362 | 362 | $http = _wp_http_get_object(); |
363 | 363 | |
364 | - $capabilities = wp_parse_args( $capabilities ); |
|
364 | + $capabilities = wp_parse_args($capabilities); |
|
365 | 365 | |
366 | - $count = count( $capabilities ); |
|
366 | + $count = count($capabilities); |
|
367 | 367 | |
368 | 368 | // If we have a numeric $capabilities array, spoof a wp_remote_request() associative $args array |
369 | - if ( $count && count( array_filter( array_keys( $capabilities ), 'is_numeric' ) ) == $count ) { |
|
370 | - $capabilities = array_combine( array_values( $capabilities ), array_fill( 0, $count, true ) ); |
|
369 | + if ($count && count(array_filter(array_keys($capabilities), 'is_numeric')) == $count) { |
|
370 | + $capabilities = array_combine(array_values($capabilities), array_fill(0, $count, true)); |
|
371 | 371 | } |
372 | 372 | |
373 | - if ( $url && !isset( $capabilities['ssl'] ) ) { |
|
374 | - $scheme = parse_url( $url, PHP_URL_SCHEME ); |
|
375 | - if ( 'https' == $scheme || 'ssl' == $scheme ) { |
|
373 | + if ($url && ! isset($capabilities['ssl'])) { |
|
374 | + $scheme = parse_url($url, PHP_URL_SCHEME); |
|
375 | + if ('https' == $scheme || 'ssl' == $scheme) { |
|
376 | 376 | $capabilities['ssl'] = true; |
377 | 377 | } |
378 | 378 | } |
379 | 379 | |
380 | - return (bool) $http->_get_first_available_transport( $capabilities ); |
|
380 | + return (bool) $http->_get_first_available_transport($capabilities); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | /** |
@@ -389,8 +389,8 @@ discard block |
||
389 | 389 | */ |
390 | 390 | function get_http_origin() { |
391 | 391 | $origin = ''; |
392 | - if ( ! empty ( $_SERVER[ 'HTTP_ORIGIN' ] ) ) |
|
393 | - $origin = $_SERVER[ 'HTTP_ORIGIN' ]; |
|
392 | + if ( ! empty ($_SERVER['HTTP_ORIGIN'])) |
|
393 | + $origin = $_SERVER['HTTP_ORIGIN']; |
|
394 | 394 | |
395 | 395 | /** |
396 | 396 | * Change the origin of an HTTP request. |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | * |
400 | 400 | * @param string $origin The original origin for the request. |
401 | 401 | */ |
402 | - return apply_filters( 'http_origin', $origin ); |
|
402 | + return apply_filters('http_origin', $origin); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
@@ -410,16 +410,16 @@ discard block |
||
410 | 410 | * @return array Array of origin URLs. |
411 | 411 | */ |
412 | 412 | function get_allowed_http_origins() { |
413 | - $admin_origin = parse_url( admin_url() ); |
|
414 | - $home_origin = parse_url( home_url() ); |
|
413 | + $admin_origin = parse_url(admin_url()); |
|
414 | + $home_origin = parse_url(home_url()); |
|
415 | 415 | |
416 | 416 | // @todo preserve port? |
417 | - $allowed_origins = array_unique( array( |
|
418 | - 'http://' . $admin_origin[ 'host' ], |
|
419 | - 'https://' . $admin_origin[ 'host' ], |
|
420 | - 'http://' . $home_origin[ 'host' ], |
|
421 | - 'https://' . $home_origin[ 'host' ], |
|
422 | - ) ); |
|
417 | + $allowed_origins = array_unique(array( |
|
418 | + 'http://'.$admin_origin['host'], |
|
419 | + 'https://'.$admin_origin['host'], |
|
420 | + 'http://'.$home_origin['host'], |
|
421 | + 'https://'.$home_origin['host'], |
|
422 | + )); |
|
423 | 423 | |
424 | 424 | /** |
425 | 425 | * Change the origin types allowed for HTTP requests. |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | * @type string Secure URL for home origin. |
435 | 435 | * } |
436 | 436 | */ |
437 | - return apply_filters( 'allowed_http_origins' , $allowed_origins ); |
|
437 | + return apply_filters('allowed_http_origins', $allowed_origins); |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | /** |
@@ -445,13 +445,13 @@ discard block |
||
445 | 445 | * @param null|string $origin Origin URL. If not provided, the value of get_http_origin() is used. |
446 | 446 | * @return string Origin URL if allowed, empty string if not. |
447 | 447 | */ |
448 | -function is_allowed_http_origin( $origin = null ) { |
|
448 | +function is_allowed_http_origin($origin = null) { |
|
449 | 449 | $origin_arg = $origin; |
450 | 450 | |
451 | - if ( null === $origin ) |
|
451 | + if (null === $origin) |
|
452 | 452 | $origin = get_http_origin(); |
453 | 453 | |
454 | - if ( $origin && ! in_array( $origin, get_allowed_http_origins() ) ) |
|
454 | + if ($origin && ! in_array($origin, get_allowed_http_origins())) |
|
455 | 455 | $origin = ''; |
456 | 456 | |
457 | 457 | /** |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | * @param string $origin Origin URL if allowed, empty string if not. |
463 | 463 | * @param string $origin_arg Original origin string passed into is_allowed_http_origin function. |
464 | 464 | */ |
465 | - return apply_filters( 'allowed_http_origin', $origin, $origin_arg ); |
|
465 | + return apply_filters('allowed_http_origin', $origin, $origin_arg); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | /** |
@@ -481,16 +481,16 @@ discard block |
||
481 | 481 | function send_origin_headers() { |
482 | 482 | $origin = get_http_origin(); |
483 | 483 | |
484 | - if ( is_allowed_http_origin( $origin ) ) { |
|
485 | - @header( 'Access-Control-Allow-Origin: ' . $origin ); |
|
486 | - @header( 'Access-Control-Allow-Credentials: true' ); |
|
487 | - if ( 'OPTIONS' === $_SERVER['REQUEST_METHOD'] ) |
|
484 | + if (is_allowed_http_origin($origin)) { |
|
485 | + @header('Access-Control-Allow-Origin: '.$origin); |
|
486 | + @header('Access-Control-Allow-Credentials: true'); |
|
487 | + if ('OPTIONS' === $_SERVER['REQUEST_METHOD']) |
|
488 | 488 | exit; |
489 | 489 | return $origin; |
490 | 490 | } |
491 | 491 | |
492 | - if ( 'OPTIONS' === $_SERVER['REQUEST_METHOD'] ) { |
|
493 | - status_header( 403 ); |
|
492 | + if ('OPTIONS' === $_SERVER['REQUEST_METHOD']) { |
|
493 | + status_header(403); |
|
494 | 494 | exit; |
495 | 495 | } |
496 | 496 | |
@@ -505,44 +505,44 @@ discard block |
||
505 | 505 | * @param string $url |
506 | 506 | * @return false|string URL or false on failure. |
507 | 507 | */ |
508 | -function wp_http_validate_url( $url ) { |
|
508 | +function wp_http_validate_url($url) { |
|
509 | 509 | $original_url = $url; |
510 | - $url = wp_kses_bad_protocol( $url, array( 'http', 'https' ) ); |
|
511 | - if ( ! $url || strtolower( $url ) !== strtolower( $original_url ) ) |
|
510 | + $url = wp_kses_bad_protocol($url, array('http', 'https')); |
|
511 | + if ( ! $url || strtolower($url) !== strtolower($original_url)) |
|
512 | 512 | return false; |
513 | 513 | |
514 | - $parsed_url = @parse_url( $url ); |
|
515 | - if ( ! $parsed_url || empty( $parsed_url['host'] ) ) |
|
514 | + $parsed_url = @parse_url($url); |
|
515 | + if ( ! $parsed_url || empty($parsed_url['host'])) |
|
516 | 516 | return false; |
517 | 517 | |
518 | - if ( isset( $parsed_url['user'] ) || isset( $parsed_url['pass'] ) ) |
|
518 | + if (isset($parsed_url['user']) || isset($parsed_url['pass'])) |
|
519 | 519 | return false; |
520 | 520 | |
521 | - if ( false !== strpbrk( $parsed_url['host'], ':#?[]' ) ) |
|
521 | + if (false !== strpbrk($parsed_url['host'], ':#?[]')) |
|
522 | 522 | return false; |
523 | 523 | |
524 | - $parsed_home = @parse_url( get_option( 'home' ) ); |
|
524 | + $parsed_home = @parse_url(get_option('home')); |
|
525 | 525 | |
526 | - if ( isset( $parsed_home['host'] ) ) { |
|
527 | - $same_host = ( strtolower( $parsed_home['host'] ) === strtolower( $parsed_url['host'] ) || 'localhost' === strtolower( $parsed_url['host'] ) ); |
|
526 | + if (isset($parsed_home['host'])) { |
|
527 | + $same_host = (strtolower($parsed_home['host']) === strtolower($parsed_url['host']) || 'localhost' === strtolower($parsed_url['host'])); |
|
528 | 528 | } else { |
529 | 529 | $same_host = false; |
530 | 530 | } |
531 | 531 | |
532 | - if ( ! $same_host ) { |
|
533 | - $host = trim( $parsed_url['host'], '.' ); |
|
534 | - if ( preg_match( '#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host ) ) { |
|
532 | + if ( ! $same_host) { |
|
533 | + $host = trim($parsed_url['host'], '.'); |
|
534 | + if (preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host)) { |
|
535 | 535 | $ip = $host; |
536 | 536 | } else { |
537 | - $ip = gethostbyname( $host ); |
|
538 | - if ( $ip === $host ) // Error condition for gethostbyname() |
|
537 | + $ip = gethostbyname($host); |
|
538 | + if ($ip === $host) // Error condition for gethostbyname() |
|
539 | 539 | $ip = false; |
540 | 540 | } |
541 | - if ( $ip ) { |
|
542 | - $parts = array_map( 'intval', explode( '.', $ip ) ); |
|
543 | - if ( 127 === $parts[0] || 10 === $parts[0] || 0 === $parts[0] |
|
544 | - || ( 172 === $parts[0] && 16 <= $parts[1] && 31 >= $parts[1] ) |
|
545 | - || ( 192 === $parts[0] && 168 === $parts[1] ) |
|
541 | + if ($ip) { |
|
542 | + $parts = array_map('intval', explode('.', $ip)); |
|
543 | + if (127 === $parts[0] || 10 === $parts[0] || 0 === $parts[0] |
|
544 | + || (172 === $parts[0] && 16 <= $parts[1] && 31 >= $parts[1]) |
|
545 | + || (192 === $parts[0] && 168 === $parts[1]) |
|
546 | 546 | ) { |
547 | 547 | // If host appears local, reject unless specifically allowed. |
548 | 548 | /** |
@@ -556,20 +556,20 @@ discard block |
||
556 | 556 | * @param string $host IP of the requested host. |
557 | 557 | * @param string $url URL of the requested host. |
558 | 558 | */ |
559 | - if ( ! apply_filters( 'http_request_host_is_external', false, $host, $url ) ) |
|
559 | + if ( ! apply_filters('http_request_host_is_external', false, $host, $url)) |
|
560 | 560 | return false; |
561 | 561 | } |
562 | 562 | } |
563 | 563 | } |
564 | 564 | |
565 | - if ( empty( $parsed_url['port'] ) ) |
|
565 | + if (empty($parsed_url['port'])) |
|
566 | 566 | return $url; |
567 | 567 | |
568 | 568 | $port = $parsed_url['port']; |
569 | - if ( 80 === $port || 443 === $port || 8080 === $port ) |
|
569 | + if (80 === $port || 443 === $port || 8080 === $port) |
|
570 | 570 | return $url; |
571 | 571 | |
572 | - if ( $parsed_home && $same_host && isset( $parsed_home['port'] ) && $parsed_home['port'] === $port ) |
|
572 | + if ($parsed_home && $same_host && isset($parsed_home['port']) && $parsed_home['port'] === $port) |
|
573 | 573 | return $url; |
574 | 574 | |
575 | 575 | return false; |
@@ -586,8 +586,8 @@ discard block |
||
586 | 586 | * @param string $host |
587 | 587 | * @return bool |
588 | 588 | */ |
589 | -function allowed_http_request_hosts( $is_external, $host ) { |
|
590 | - if ( ! $is_external && wp_validate_redirect( 'http://' . $host ) ) |
|
589 | +function allowed_http_request_hosts($is_external, $host) { |
|
590 | + if ( ! $is_external && wp_validate_redirect('http://'.$host)) |
|
591 | 591 | $is_external = true; |
592 | 592 | return $is_external; |
593 | 593 | } |
@@ -606,17 +606,17 @@ discard block |
||
606 | 606 | * @param string $host |
607 | 607 | * @return bool |
608 | 608 | */ |
609 | -function ms_allowed_http_request_hosts( $is_external, $host ) { |
|
609 | +function ms_allowed_http_request_hosts($is_external, $host) { |
|
610 | 610 | global $wpdb; |
611 | 611 | static $queried = array(); |
612 | - if ( $is_external ) |
|
612 | + if ($is_external) |
|
613 | 613 | return $is_external; |
614 | - if ( $host === get_current_site()->domain ) |
|
614 | + if ($host === get_current_site()->domain) |
|
615 | 615 | return true; |
616 | - if ( isset( $queried[ $host ] ) ) |
|
617 | - return $queried[ $host ]; |
|
618 | - $queried[ $host ] = (bool) $wpdb->get_var( $wpdb->prepare( "SELECT domain FROM $wpdb->blogs WHERE domain = %s LIMIT 1", $host ) ); |
|
619 | - return $queried[ $host ]; |
|
616 | + if (isset($queried[$host])) |
|
617 | + return $queried[$host]; |
|
618 | + $queried[$host] = (bool) $wpdb->get_var($wpdb->prepare("SELECT domain FROM $wpdb->blogs WHERE domain = %s LIMIT 1", $host)); |
|
619 | + return $queried[$host]; |
|
620 | 620 | } |
621 | 621 | |
622 | 622 | /** |
@@ -635,30 +635,30 @@ discard block |
||
635 | 635 | * @return bool|array False on failure; Array of URL components on success; |
636 | 636 | * See parse_url()'s return values. |
637 | 637 | */ |
638 | -function wp_parse_url( $url ) { |
|
639 | - $parts = @parse_url( $url ); |
|
640 | - if ( ! $parts ) { |
|
638 | +function wp_parse_url($url) { |
|
639 | + $parts = @parse_url($url); |
|
640 | + if ( ! $parts) { |
|
641 | 641 | // < PHP 5.4.7 compat, trouble with relative paths including a scheme break in the path |
642 | - if ( '/' == $url[0] && false !== strpos( $url, '://' ) ) { |
|
642 | + if ('/' == $url[0] && false !== strpos($url, '://')) { |
|
643 | 643 | // Since we know it's a relative path, prefix with a scheme/host placeholder and try again |
644 | - if ( ! $parts = @parse_url( 'placeholder://placeholder' . $url ) ) { |
|
644 | + if ( ! $parts = @parse_url('placeholder://placeholder'.$url)) { |
|
645 | 645 | return $parts; |
646 | 646 | } |
647 | 647 | // Remove the placeholder values |
648 | - unset( $parts['scheme'], $parts['host'] ); |
|
648 | + unset($parts['scheme'], $parts['host']); |
|
649 | 649 | } else { |
650 | 650 | return $parts; |
651 | 651 | } |
652 | 652 | } |
653 | 653 | |
654 | 654 | // < PHP 5.4.7 compat, doesn't detect schemeless URL's host field |
655 | - if ( '//' == substr( $url, 0, 2 ) && ! isset( $parts['host'] ) ) { |
|
656 | - $path_parts = explode( '/', substr( $parts['path'], 2 ), 2 ); |
|
655 | + if ('//' == substr($url, 0, 2) && ! isset($parts['host'])) { |
|
656 | + $path_parts = explode('/', substr($parts['path'], 2), 2); |
|
657 | 657 | $parts['host'] = $path_parts[0]; |
658 | - if ( isset( $path_parts[1] ) ) { |
|
659 | - $parts['path'] = '/' . $path_parts[1]; |
|
658 | + if (isset($path_parts[1])) { |
|
659 | + $parts['path'] = '/'.$path_parts[1]; |
|
660 | 660 | } else { |
661 | - unset( $parts['path'] ); |
|
661 | + unset($parts['path']); |
|
662 | 662 | } |
663 | 663 | } |
664 | 664 |
@@ -44,17 +44,20 @@ discard block |
||
44 | 44 | * @return bool |
45 | 45 | */ |
46 | 46 | public function do_item( $handle ) { |
47 | - if ( !parent::do_item($handle) ) |
|
48 | - return false; |
|
47 | + if ( !parent::do_item($handle) ) { |
|
48 | + return false; |
|
49 | + } |
|
49 | 50 | |
50 | 51 | $obj = $this->registered[$handle]; |
51 | - if ( null === $obj->ver ) |
|
52 | - $ver = ''; |
|
53 | - else |
|
54 | - $ver = $obj->ver ? $obj->ver : $this->default_version; |
|
52 | + if ( null === $obj->ver ) { |
|
53 | + $ver = ''; |
|
54 | + } else { |
|
55 | + $ver = $obj->ver ? $obj->ver : $this->default_version; |
|
56 | + } |
|
55 | 57 | |
56 | - if ( isset($this->args[$handle]) ) |
|
57 | - $ver = $ver ? $ver . '&' . $this->args[$handle] : $this->args[$handle]; |
|
58 | + if ( isset($this->args[$handle]) ) { |
|
59 | + $ver = $ver ? $ver . '&' . $this->args[$handle] : $this->args[$handle]; |
|
60 | + } |
|
58 | 61 | |
59 | 62 | if ( $this->do_concat ) { |
60 | 63 | if ( $this->in_default_dir($obj->src) && !isset($obj->extra['conditional']) && !isset($obj->extra['alt']) ) { |
@@ -67,10 +70,11 @@ discard block |
||
67 | 70 | } |
68 | 71 | } |
69 | 72 | |
70 | - if ( isset($obj->args) ) |
|
71 | - $media = esc_attr( $obj->args ); |
|
72 | - else |
|
73 | - $media = 'all'; |
|
73 | + if ( isset($obj->args) ) { |
|
74 | + $media = esc_attr( $obj->args ); |
|
75 | + } else { |
|
76 | + $media = 'all'; |
|
77 | + } |
|
74 | 78 | |
75 | 79 | $href = $this->_css_href( $obj->src, $ver, $handle ); |
76 | 80 | if ( empty( $href ) ) { |
@@ -206,8 +210,9 @@ discard block |
||
206 | 210 | $src = $this->base_url . $src; |
207 | 211 | } |
208 | 212 | |
209 | - if ( !empty($ver) ) |
|
210 | - $src = add_query_arg('ver', $ver, $src); |
|
213 | + if ( !empty($ver) ) { |
|
214 | + $src = add_query_arg('ver', $ver, $src); |
|
215 | + } |
|
211 | 216 | |
212 | 217 | /** |
213 | 218 | * Filter an enqueued style's fully-qualified URL. |
@@ -226,12 +231,14 @@ discard block |
||
226 | 231 | * @return bool |
227 | 232 | */ |
228 | 233 | public function in_default_dir($src) { |
229 | - if ( ! $this->default_dirs ) |
|
230 | - return true; |
|
234 | + if ( ! $this->default_dirs ) { |
|
235 | + return true; |
|
236 | + } |
|
231 | 237 | |
232 | 238 | foreach ( (array) $this->default_dirs as $test ) { |
233 | - if ( 0 === strpos($src, $test) ) |
|
234 | - return true; |
|
239 | + if ( 0 === strpos($src, $test) ) { |
|
240 | + return true; |
|
241 | + } |
|
235 | 242 | } |
236 | 243 | return false; |
237 | 244 | } |
@@ -1,12 +1,12 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Dependencies API: WP_Styles class |
|
4 | - * |
|
5 | - * @since 2.6.0 |
|
6 | - * |
|
7 | - * @package WordPress |
|
8 | - * @subpackage Dependencies |
|
9 | - */ |
|
3 | + * Dependencies API: WP_Styles class |
|
4 | + * |
|
5 | + * @since 2.6.0 |
|
6 | + * |
|
7 | + * @package WordPress |
|
8 | + * @subpackage Dependencies |
|
9 | + */ |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Core class used to register styles. |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | * |
125 | 125 | * @param WP_Styles &$this WP_Styles instance, passed by reference. |
126 | 126 | */ |
127 | - do_action_ref_array( 'wp_default_styles', array(&$this) ); |
|
127 | + do_action_ref_array('wp_default_styles', array(&$this)); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -138,40 +138,40 @@ discard block |
||
138 | 138 | * @param string $handle The style's registered handle. |
139 | 139 | * @return bool True on success, false on failure. |
140 | 140 | */ |
141 | - public function do_item( $handle ) { |
|
142 | - if ( !parent::do_item($handle) ) |
|
141 | + public function do_item($handle) { |
|
142 | + if ( ! parent::do_item($handle)) |
|
143 | 143 | return false; |
144 | 144 | |
145 | 145 | $obj = $this->registered[$handle]; |
146 | - if ( null === $obj->ver ) |
|
146 | + if (null === $obj->ver) |
|
147 | 147 | $ver = ''; |
148 | 148 | else |
149 | 149 | $ver = $obj->ver ? $obj->ver : $this->default_version; |
150 | 150 | |
151 | - if ( isset($this->args[$handle]) ) |
|
152 | - $ver = $ver ? $ver . '&' . $this->args[$handle] : $this->args[$handle]; |
|
151 | + if (isset($this->args[$handle])) |
|
152 | + $ver = $ver ? $ver.'&'.$this->args[$handle] : $this->args[$handle]; |
|
153 | 153 | |
154 | - if ( $this->do_concat ) { |
|
155 | - if ( $this->in_default_dir($obj->src) && !isset($obj->extra['conditional']) && !isset($obj->extra['alt']) ) { |
|
154 | + if ($this->do_concat) { |
|
155 | + if ($this->in_default_dir($obj->src) && ! isset($obj->extra['conditional']) && ! isset($obj->extra['alt'])) { |
|
156 | 156 | $this->concat .= "$handle,"; |
157 | 157 | $this->concat_version .= "$handle$ver"; |
158 | 158 | |
159 | - $this->print_code .= $this->print_inline_style( $handle, false ); |
|
159 | + $this->print_code .= $this->print_inline_style($handle, false); |
|
160 | 160 | |
161 | 161 | return true; |
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
165 | - if ( isset($obj->args) ) |
|
166 | - $media = esc_attr( $obj->args ); |
|
165 | + if (isset($obj->args)) |
|
166 | + $media = esc_attr($obj->args); |
|
167 | 167 | else |
168 | 168 | $media = 'all'; |
169 | 169 | |
170 | 170 | // A single item may alias a set of items, by having dependencies, but no source. |
171 | - if ( ! $obj->src ) { |
|
172 | - if ( $inline_style = $this->print_inline_style( $handle, false ) ) { |
|
173 | - $inline_style = sprintf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style ); |
|
174 | - if ( $this->do_concat ) { |
|
171 | + if ( ! $obj->src) { |
|
172 | + if ($inline_style = $this->print_inline_style($handle, false)) { |
|
173 | + $inline_style = sprintf("<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr($handle), $inline_style); |
|
174 | + if ($this->do_concat) { |
|
175 | 175 | $this->print_html .= $inline_style; |
176 | 176 | } else { |
177 | 177 | echo $inline_style; |
@@ -180,13 +180,13 @@ discard block |
||
180 | 180 | return true; |
181 | 181 | } |
182 | 182 | |
183 | - $href = $this->_css_href( $obj->src, $ver, $handle ); |
|
184 | - if ( ! $href ) { |
|
183 | + $href = $this->_css_href($obj->src, $ver, $handle); |
|
184 | + if ( ! $href) { |
|
185 | 185 | return true; |
186 | 186 | } |
187 | 187 | |
188 | 188 | $rel = isset($obj->extra['alt']) && $obj->extra['alt'] ? 'alternate stylesheet' : 'stylesheet'; |
189 | - $title = isset($obj->extra['title']) ? "title='" . esc_attr( $obj->extra['title'] ) . "'" : ''; |
|
189 | + $title = isset($obj->extra['title']) ? "title='".esc_attr($obj->extra['title'])."'" : ''; |
|
190 | 190 | |
191 | 191 | /** |
192 | 192 | * Filter the HTML link tag of an enqueued style. |
@@ -200,19 +200,19 @@ discard block |
||
200 | 200 | * @param string $href The stylesheet's source URL. |
201 | 201 | * @param string $media The stylesheet's media attribute. |
202 | 202 | */ |
203 | - $tag = apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-css' $title href='$href' type='text/css' media='$media' />\n", $handle, $href, $media); |
|
204 | - if ( 'rtl' === $this->text_direction && isset($obj->extra['rtl']) && $obj->extra['rtl'] ) { |
|
205 | - if ( is_bool( $obj->extra['rtl'] ) || 'replace' === $obj->extra['rtl'] ) { |
|
206 | - $suffix = isset( $obj->extra['suffix'] ) ? $obj->extra['suffix'] : ''; |
|
207 | - $rtl_href = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $this->_css_href( $obj->src , $ver, "$handle-rtl" )); |
|
203 | + $tag = apply_filters('style_loader_tag', "<link rel='$rel' id='$handle-css' $title href='$href' type='text/css' media='$media' />\n", $handle, $href, $media); |
|
204 | + if ('rtl' === $this->text_direction && isset($obj->extra['rtl']) && $obj->extra['rtl']) { |
|
205 | + if (is_bool($obj->extra['rtl']) || 'replace' === $obj->extra['rtl']) { |
|
206 | + $suffix = isset($obj->extra['suffix']) ? $obj->extra['suffix'] : ''; |
|
207 | + $rtl_href = str_replace("{$suffix}.css", "-rtl{$suffix}.css", $this->_css_href($obj->src, $ver, "$handle-rtl")); |
|
208 | 208 | } else { |
209 | - $rtl_href = $this->_css_href( $obj->extra['rtl'], $ver, "$handle-rtl" ); |
|
209 | + $rtl_href = $this->_css_href($obj->extra['rtl'], $ver, "$handle-rtl"); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** This filter is documented in wp-includes/class.wp-styles.php */ |
213 | - $rtl_tag = apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-rtl-css' $title href='$rtl_href' type='text/css' media='$media' />\n", $handle, $rtl_href, $media ); |
|
213 | + $rtl_tag = apply_filters('style_loader_tag', "<link rel='$rel' id='$handle-rtl-css' $title href='$rtl_href' type='text/css' media='$media' />\n", $handle, $rtl_href, $media); |
|
214 | 214 | |
215 | - if ( $obj->extra['rtl'] === 'replace' ) { |
|
215 | + if ($obj->extra['rtl'] === 'replace') { |
|
216 | 216 | $tag = $rtl_tag; |
217 | 217 | } else { |
218 | 218 | $tag .= $rtl_tag; |
@@ -220,22 +220,22 @@ discard block |
||
220 | 220 | } |
221 | 221 | |
222 | 222 | $conditional_pre = $conditional_post = ''; |
223 | - if ( isset( $obj->extra['conditional'] ) && $obj->extra['conditional'] ) { |
|
223 | + if (isset($obj->extra['conditional']) && $obj->extra['conditional']) { |
|
224 | 224 | $conditional_pre = "<!--[if {$obj->extra['conditional']}]>\n"; |
225 | 225 | $conditional_post = "<![endif]-->\n"; |
226 | 226 | } |
227 | 227 | |
228 | - if ( $this->do_concat ) { |
|
228 | + if ($this->do_concat) { |
|
229 | 229 | $this->print_html .= $conditional_pre; |
230 | 230 | $this->print_html .= $tag; |
231 | - if ( $inline_style = $this->print_inline_style( $handle, false ) ) { |
|
232 | - $this->print_html .= sprintf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style ); |
|
231 | + if ($inline_style = $this->print_inline_style($handle, false)) { |
|
232 | + $this->print_html .= sprintf("<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr($handle), $inline_style); |
|
233 | 233 | } |
234 | 234 | $this->print_html .= $conditional_post; |
235 | 235 | } else { |
236 | 236 | echo $conditional_pre; |
237 | 237 | echo $tag; |
238 | - $this->print_inline_style( $handle ); |
|
238 | + $this->print_inline_style($handle); |
|
239 | 239 | echo $conditional_post; |
240 | 240 | } |
241 | 241 | |
@@ -252,19 +252,19 @@ discard block |
||
252 | 252 | * @param string $code String containing the CSS styles to be added. |
253 | 253 | * @return bool True on success, false on failure. |
254 | 254 | */ |
255 | - public function add_inline_style( $handle, $code ) { |
|
256 | - if ( ! $code ) { |
|
255 | + public function add_inline_style($handle, $code) { |
|
256 | + if ( ! $code) { |
|
257 | 257 | return false; |
258 | 258 | } |
259 | 259 | |
260 | - $after = $this->get_data( $handle, 'after' ); |
|
261 | - if ( ! $after ) { |
|
260 | + $after = $this->get_data($handle, 'after'); |
|
261 | + if ( ! $after) { |
|
262 | 262 | $after = array(); |
263 | 263 | } |
264 | 264 | |
265 | 265 | $after[] = $code; |
266 | 266 | |
267 | - return $this->add_data( $handle, 'after', $after ); |
|
267 | + return $this->add_data($handle, 'after', $after); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
@@ -278,20 +278,20 @@ discard block |
||
278 | 278 | * Default true. |
279 | 279 | * @return string|bool False if no data exists, inline styles if `$echo` is true, true otherwise. |
280 | 280 | */ |
281 | - public function print_inline_style( $handle, $echo = true ) { |
|
282 | - $output = $this->get_data( $handle, 'after' ); |
|
281 | + public function print_inline_style($handle, $echo = true) { |
|
282 | + $output = $this->get_data($handle, 'after'); |
|
283 | 283 | |
284 | - if ( empty( $output ) ) { |
|
284 | + if (empty($output)) { |
|
285 | 285 | return false; |
286 | 286 | } |
287 | 287 | |
288 | - $output = implode( "\n", $output ); |
|
288 | + $output = implode("\n", $output); |
|
289 | 289 | |
290 | - if ( ! $echo ) { |
|
290 | + if ( ! $echo) { |
|
291 | 291 | return $output; |
292 | 292 | } |
293 | 293 | |
294 | - printf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $output ); |
|
294 | + printf("<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr($handle), $output); |
|
295 | 295 | |
296 | 296 | return true; |
297 | 297 | } |
@@ -309,9 +309,9 @@ discard block |
||
309 | 309 | * @param int|false $group Group level: (int) level, (false) no groups. |
310 | 310 | * @return bool True on success, false on failure. |
311 | 311 | */ |
312 | - public function all_deps( $handles, $recursion = false, $group = false ) { |
|
313 | - $r = parent::all_deps( $handles, $recursion, $group ); |
|
314 | - if ( ! $recursion ) { |
|
312 | + public function all_deps($handles, $recursion = false, $group = false) { |
|
313 | + $r = parent::all_deps($handles, $recursion, $group); |
|
314 | + if ( ! $recursion) { |
|
315 | 315 | /** |
316 | 316 | * Filter the array of enqueued styles before processing for output. |
317 | 317 | * |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | * |
320 | 320 | * @param array $to_do The list of enqueued styles about to be processed. |
321 | 321 | */ |
322 | - $this->to_do = apply_filters( 'print_styles_array', $this->to_do ); |
|
322 | + $this->to_do = apply_filters('print_styles_array', $this->to_do); |
|
323 | 323 | } |
324 | 324 | return $r; |
325 | 325 | } |
@@ -335,12 +335,12 @@ discard block |
||
335 | 335 | * @param string $handle The style's registered handle. |
336 | 336 | * @return string Style's fully-qualified URL. |
337 | 337 | */ |
338 | - public function _css_href( $src, $ver, $handle ) { |
|
339 | - if ( !is_bool($src) && !preg_match('|^(https?:)?//|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) { |
|
340 | - $src = $this->base_url . $src; |
|
338 | + public function _css_href($src, $ver, $handle) { |
|
339 | + if ( ! is_bool($src) && ! preg_match('|^(https?:)?//|', $src) && ! ($this->content_url && 0 === strpos($src, $this->content_url))) { |
|
340 | + $src = $this->base_url.$src; |
|
341 | 341 | } |
342 | 342 | |
343 | - if ( !empty($ver) ) |
|
343 | + if ( ! empty($ver)) |
|
344 | 344 | $src = add_query_arg('ver', $ver, $src); |
345 | 345 | |
346 | 346 | /** |
@@ -351,8 +351,8 @@ discard block |
||
351 | 351 | * @param string $src The source URL of the enqueued style. |
352 | 352 | * @param string $handle The style's registered handle. |
353 | 353 | */ |
354 | - $src = apply_filters( 'style_loader_src', $src, $handle ); |
|
355 | - return esc_url( $src ); |
|
354 | + $src = apply_filters('style_loader_src', $src, $handle); |
|
355 | + return esc_url($src); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | /** |
@@ -364,12 +364,12 @@ discard block |
||
364 | 364 | * @param string $src The source of the enqueued style. |
365 | 365 | * @return bool True if found, false if not. |
366 | 366 | */ |
367 | - public function in_default_dir( $src ) { |
|
368 | - if ( ! $this->default_dirs ) |
|
367 | + public function in_default_dir($src) { |
|
368 | + if ( ! $this->default_dirs) |
|
369 | 369 | return true; |
370 | 370 | |
371 | - foreach ( (array) $this->default_dirs as $test ) { |
|
372 | - if ( 0 === strpos($src, $test) ) |
|
371 | + foreach ((array) $this->default_dirs as $test) { |
|
372 | + if (0 === strpos($src, $test)) |
|
373 | 373 | return true; |
374 | 374 | } |
375 | 375 | return false; |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * WordPress GD Image Editor |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - * @subpackage Image_Editor |
|
7 | - */ |
|
3 | + * WordPress GD Image Editor |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + * @subpackage Image_Editor |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * WordPress Image Editor Class for Image Manipulation through GD |
@@ -24,9 +24,9 @@ discard block |
||
24 | 24 | protected $image; |
25 | 25 | |
26 | 26 | public function __destruct() { |
27 | - if ( $this->image ) { |
|
27 | + if ($this->image) { |
|
28 | 28 | // we don't need the original in memory anymore |
29 | - imagedestroy( $this->image ); |
|
29 | + imagedestroy($this->image); |
|
30 | 30 | } |
31 | 31 | } |
32 | 32 | |
@@ -41,14 +41,14 @@ discard block |
||
41 | 41 | * @param array $args |
42 | 42 | * @return bool |
43 | 43 | */ |
44 | - public static function test( $args = array() ) { |
|
45 | - if ( ! extension_loaded('gd') || ! function_exists('gd_info') ) |
|
44 | + public static function test($args = array()) { |
|
45 | + if ( ! extension_loaded('gd') || ! function_exists('gd_info')) |
|
46 | 46 | return false; |
47 | 47 | |
48 | 48 | // On some setups GD library does not provide imagerotate() - Ticket #11536 |
49 | - if ( isset( $args['methods'] ) && |
|
50 | - in_array( 'rotate', $args['methods'] ) && |
|
51 | - ! function_exists('imagerotate') ){ |
|
49 | + if (isset($args['methods']) && |
|
50 | + in_array('rotate', $args['methods']) && |
|
51 | + ! function_exists('imagerotate')) { |
|
52 | 52 | |
53 | 53 | return false; |
54 | 54 | } |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | * @param string $mime_type |
68 | 68 | * @return bool |
69 | 69 | */ |
70 | - public static function supports_mime_type( $mime_type ) { |
|
70 | + public static function supports_mime_type($mime_type) { |
|
71 | 71 | $image_types = imagetypes(); |
72 | - switch( $mime_type ) { |
|
72 | + switch ($mime_type) { |
|
73 | 73 | case 'image/jpeg': |
74 | 74 | return ($image_types & IMG_JPG) != 0; |
75 | 75 | case 'image/png': |
@@ -90,11 +90,11 @@ discard block |
||
90 | 90 | * @return bool|WP_Error True if loaded successfully; WP_Error on failure. |
91 | 91 | */ |
92 | 92 | public function load() { |
93 | - if ( $this->image ) |
|
93 | + if ($this->image) |
|
94 | 94 | return true; |
95 | 95 | |
96 | - if ( ! is_file( $this->file ) && ! preg_match( '|^https?://|', $this->file ) ) |
|
97 | - return new WP_Error( 'error_loading_image', __('File doesn’t exist?'), $this->file ); |
|
96 | + if ( ! is_file($this->file) && ! preg_match('|^https?://|', $this->file)) |
|
97 | + return new WP_Error('error_loading_image', __('File doesn’t exist?'), $this->file); |
|
98 | 98 | |
99 | 99 | /** |
100 | 100 | * Filter the memory limit allocated for image manipulation. |
@@ -105,23 +105,23 @@ discard block |
||
105 | 105 | * Accepts an integer (bytes), or a shorthand string notation, such as '256M'. |
106 | 106 | */ |
107 | 107 | // Set artificially high because GD uses uncompressed images in memory |
108 | - @ini_set( 'memory_limit', apply_filters( 'image_memory_limit', WP_MAX_MEMORY_LIMIT ) ); |
|
108 | + @ini_set('memory_limit', apply_filters('image_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
109 | 109 | |
110 | - $this->image = @imagecreatefromstring( file_get_contents( $this->file ) ); |
|
110 | + $this->image = @imagecreatefromstring(file_get_contents($this->file)); |
|
111 | 111 | |
112 | - if ( ! is_resource( $this->image ) ) |
|
113 | - return new WP_Error( 'invalid_image', __('File is not an image.'), $this->file ); |
|
112 | + if ( ! is_resource($this->image)) |
|
113 | + return new WP_Error('invalid_image', __('File is not an image.'), $this->file); |
|
114 | 114 | |
115 | - $size = @getimagesize( $this->file ); |
|
116 | - if ( ! $size ) |
|
117 | - return new WP_Error( 'invalid_image', __('Could not read image size.'), $this->file ); |
|
115 | + $size = @getimagesize($this->file); |
|
116 | + if ( ! $size) |
|
117 | + return new WP_Error('invalid_image', __('Could not read image size.'), $this->file); |
|
118 | 118 | |
119 | - if ( function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' ) ) { |
|
120 | - imagealphablending( $this->image, false ); |
|
121 | - imagesavealpha( $this->image, true ); |
|
119 | + if (function_exists('imagealphablending') && function_exists('imagesavealpha')) { |
|
120 | + imagealphablending($this->image, false); |
|
121 | + imagesavealpha($this->image, true); |
|
122 | 122 | } |
123 | 123 | |
124 | - $this->update_size( $size[0], $size[1] ); |
|
124 | + $this->update_size($size[0], $size[1]); |
|
125 | 125 | $this->mime_type = $size['mime']; |
126 | 126 | |
127 | 127 | return $this->set_quality(); |
@@ -137,14 +137,14 @@ discard block |
||
137 | 137 | * @param int $height |
138 | 138 | * @return true |
139 | 139 | */ |
140 | - protected function update_size( $width = false, $height = false ) { |
|
141 | - if ( ! $width ) |
|
142 | - $width = imagesx( $this->image ); |
|
140 | + protected function update_size($width = false, $height = false) { |
|
141 | + if ( ! $width) |
|
142 | + $width = imagesx($this->image); |
|
143 | 143 | |
144 | - if ( ! $height ) |
|
145 | - $height = imagesy( $this->image ); |
|
144 | + if ( ! $height) |
|
145 | + $height = imagesy($this->image); |
|
146 | 146 | |
147 | - return parent::update_size( $width, $height ); |
|
147 | + return parent::update_size($width, $height); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -163,21 +163,21 @@ discard block |
||
163 | 163 | * @param bool $crop |
164 | 164 | * @return true|WP_Error |
165 | 165 | */ |
166 | - public function resize( $max_w, $max_h, $crop = false ) { |
|
167 | - if ( ( $this->size['width'] == $max_w ) && ( $this->size['height'] == $max_h ) ) |
|
166 | + public function resize($max_w, $max_h, $crop = false) { |
|
167 | + if (($this->size['width'] == $max_w) && ($this->size['height'] == $max_h)) |
|
168 | 168 | return true; |
169 | 169 | |
170 | - $resized = $this->_resize( $max_w, $max_h, $crop ); |
|
170 | + $resized = $this->_resize($max_w, $max_h, $crop); |
|
171 | 171 | |
172 | - if ( is_resource( $resized ) ) { |
|
173 | - imagedestroy( $this->image ); |
|
172 | + if (is_resource($resized)) { |
|
173 | + imagedestroy($this->image); |
|
174 | 174 | $this->image = $resized; |
175 | 175 | return true; |
176 | 176 | |
177 | - } elseif ( is_wp_error( $resized ) ) |
|
177 | + } elseif (is_wp_error($resized)) |
|
178 | 178 | return $resized; |
179 | 179 | |
180 | - return new WP_Error( 'image_resize_error', __('Image resize failed.'), $this->file ); |
|
180 | + return new WP_Error('image_resize_error', __('Image resize failed.'), $this->file); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -187,22 +187,22 @@ discard block |
||
187 | 187 | * @param bool|array $crop |
188 | 188 | * @return resource|WP_Error |
189 | 189 | */ |
190 | - protected function _resize( $max_w, $max_h, $crop = false ) { |
|
191 | - $dims = image_resize_dimensions( $this->size['width'], $this->size['height'], $max_w, $max_h, $crop ); |
|
192 | - if ( ! $dims ) { |
|
193 | - return new WP_Error( 'error_getting_dimensions', __('Could not calculate resized image dimensions'), $this->file ); |
|
190 | + protected function _resize($max_w, $max_h, $crop = false) { |
|
191 | + $dims = image_resize_dimensions($this->size['width'], $this->size['height'], $max_w, $max_h, $crop); |
|
192 | + if ( ! $dims) { |
|
193 | + return new WP_Error('error_getting_dimensions', __('Could not calculate resized image dimensions'), $this->file); |
|
194 | 194 | } |
195 | - list( $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ) = $dims; |
|
195 | + list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = $dims; |
|
196 | 196 | |
197 | - $resized = wp_imagecreatetruecolor( $dst_w, $dst_h ); |
|
198 | - imagecopyresampled( $resized, $this->image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ); |
|
197 | + $resized = wp_imagecreatetruecolor($dst_w, $dst_h); |
|
198 | + imagecopyresampled($resized, $this->image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); |
|
199 | 199 | |
200 | - if ( is_resource( $resized ) ) { |
|
201 | - $this->update_size( $dst_w, $dst_h ); |
|
200 | + if (is_resource($resized)) { |
|
201 | + $this->update_size($dst_w, $dst_h); |
|
202 | 202 | return $resized; |
203 | 203 | } |
204 | 204 | |
205 | - return new WP_Error( 'image_resize_error', __('Image resize failed.'), $this->file ); |
|
205 | + return new WP_Error('image_resize_error', __('Image resize failed.'), $this->file); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
@@ -226,36 +226,36 @@ discard block |
||
226 | 226 | * } |
227 | 227 | * @return array An array of resized images' metadata by size. |
228 | 228 | */ |
229 | - public function multi_resize( $sizes ) { |
|
229 | + public function multi_resize($sizes) { |
|
230 | 230 | $metadata = array(); |
231 | 231 | $orig_size = $this->size; |
232 | 232 | |
233 | - foreach ( $sizes as $size => $size_data ) { |
|
234 | - if ( ! isset( $size_data['width'] ) && ! isset( $size_data['height'] ) ) { |
|
233 | + foreach ($sizes as $size => $size_data) { |
|
234 | + if ( ! isset($size_data['width']) && ! isset($size_data['height'])) { |
|
235 | 235 | continue; |
236 | 236 | } |
237 | 237 | |
238 | - if ( ! isset( $size_data['width'] ) ) { |
|
238 | + if ( ! isset($size_data['width'])) { |
|
239 | 239 | $size_data['width'] = null; |
240 | 240 | } |
241 | - if ( ! isset( $size_data['height'] ) ) { |
|
241 | + if ( ! isset($size_data['height'])) { |
|
242 | 242 | $size_data['height'] = null; |
243 | 243 | } |
244 | 244 | |
245 | - if ( ! isset( $size_data['crop'] ) ) { |
|
245 | + if ( ! isset($size_data['crop'])) { |
|
246 | 246 | $size_data['crop'] = false; |
247 | 247 | } |
248 | 248 | |
249 | - $image = $this->_resize( $size_data['width'], $size_data['height'], $size_data['crop'] ); |
|
250 | - $duplicate = ( ( $orig_size['width'] == $size_data['width'] ) && ( $orig_size['height'] == $size_data['height'] ) ); |
|
249 | + $image = $this->_resize($size_data['width'], $size_data['height'], $size_data['crop']); |
|
250 | + $duplicate = (($orig_size['width'] == $size_data['width']) && ($orig_size['height'] == $size_data['height'])); |
|
251 | 251 | |
252 | - if ( ! is_wp_error( $image ) && ! $duplicate ) { |
|
253 | - $resized = $this->_save( $image ); |
|
252 | + if ( ! is_wp_error($image) && ! $duplicate) { |
|
253 | + $resized = $this->_save($image); |
|
254 | 254 | |
255 | - imagedestroy( $image ); |
|
255 | + imagedestroy($image); |
|
256 | 256 | |
257 | - if ( ! is_wp_error( $resized ) && $resized ) { |
|
258 | - unset( $resized['path'] ); |
|
257 | + if ( ! is_wp_error($resized) && $resized) { |
|
258 | + unset($resized['path']); |
|
259 | 259 | $metadata[$size] = $resized; |
260 | 260 | } |
261 | 261 | } |
@@ -281,34 +281,34 @@ discard block |
||
281 | 281 | * @param bool $src_abs Optional. If the source crop points are absolute. |
282 | 282 | * @return bool|WP_Error |
283 | 283 | */ |
284 | - public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ) { |
|
284 | + public function crop($src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false) { |
|
285 | 285 | // If destination width/height isn't specified, use same as |
286 | 286 | // width/height from source. |
287 | - if ( ! $dst_w ) |
|
287 | + if ( ! $dst_w) |
|
288 | 288 | $dst_w = $src_w; |
289 | - if ( ! $dst_h ) |
|
289 | + if ( ! $dst_h) |
|
290 | 290 | $dst_h = $src_h; |
291 | 291 | |
292 | - $dst = wp_imagecreatetruecolor( $dst_w, $dst_h ); |
|
292 | + $dst = wp_imagecreatetruecolor($dst_w, $dst_h); |
|
293 | 293 | |
294 | - if ( $src_abs ) { |
|
294 | + if ($src_abs) { |
|
295 | 295 | $src_w -= $src_x; |
296 | 296 | $src_h -= $src_y; |
297 | 297 | } |
298 | 298 | |
299 | - if ( function_exists( 'imageantialias' ) ) |
|
300 | - imageantialias( $dst, true ); |
|
299 | + if (function_exists('imageantialias')) |
|
300 | + imageantialias($dst, true); |
|
301 | 301 | |
302 | - imagecopyresampled( $dst, $this->image, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ); |
|
302 | + imagecopyresampled($dst, $this->image, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); |
|
303 | 303 | |
304 | - if ( is_resource( $dst ) ) { |
|
305 | - imagedestroy( $this->image ); |
|
304 | + if (is_resource($dst)) { |
|
305 | + imagedestroy($this->image); |
|
306 | 306 | $this->image = $dst; |
307 | 307 | $this->update_size(); |
308 | 308 | return true; |
309 | 309 | } |
310 | 310 | |
311 | - return new WP_Error( 'image_crop_error', __('Image crop failed.'), $this->file ); |
|
311 | + return new WP_Error('image_crop_error', __('Image crop failed.'), $this->file); |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | /** |
@@ -321,21 +321,21 @@ discard block |
||
321 | 321 | * @param float $angle |
322 | 322 | * @return true|WP_Error |
323 | 323 | */ |
324 | - public function rotate( $angle ) { |
|
325 | - if ( function_exists('imagerotate') ) { |
|
326 | - $transparency = imagecolorallocatealpha( $this->image, 255, 255, 255, 127 ); |
|
327 | - $rotated = imagerotate( $this->image, $angle, $transparency ); |
|
328 | - |
|
329 | - if ( is_resource( $rotated ) ) { |
|
330 | - imagealphablending( $rotated, true ); |
|
331 | - imagesavealpha( $rotated, true ); |
|
332 | - imagedestroy( $this->image ); |
|
324 | + public function rotate($angle) { |
|
325 | + if (function_exists('imagerotate')) { |
|
326 | + $transparency = imagecolorallocatealpha($this->image, 255, 255, 255, 127); |
|
327 | + $rotated = imagerotate($this->image, $angle, $transparency); |
|
328 | + |
|
329 | + if (is_resource($rotated)) { |
|
330 | + imagealphablending($rotated, true); |
|
331 | + imagesavealpha($rotated, true); |
|
332 | + imagedestroy($this->image); |
|
333 | 333 | $this->image = $rotated; |
334 | 334 | $this->update_size(); |
335 | 335 | return true; |
336 | 336 | } |
337 | 337 | } |
338 | - return new WP_Error( 'image_rotate_error', __('Image rotate failed.'), $this->file ); |
|
338 | + return new WP_Error('image_rotate_error', __('Image rotate failed.'), $this->file); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
@@ -348,24 +348,24 @@ discard block |
||
348 | 348 | * @param bool $vert Flip along Vertical Axis |
349 | 349 | * @return true|WP_Error |
350 | 350 | */ |
351 | - public function flip( $horz, $vert ) { |
|
351 | + public function flip($horz, $vert) { |
|
352 | 352 | $w = $this->size['width']; |
353 | 353 | $h = $this->size['height']; |
354 | - $dst = wp_imagecreatetruecolor( $w, $h ); |
|
354 | + $dst = wp_imagecreatetruecolor($w, $h); |
|
355 | 355 | |
356 | - if ( is_resource( $dst ) ) { |
|
356 | + if (is_resource($dst)) { |
|
357 | 357 | $sx = $vert ? ($w - 1) : 0; |
358 | 358 | $sy = $horz ? ($h - 1) : 0; |
359 | 359 | $sw = $vert ? -$w : $w; |
360 | 360 | $sh = $horz ? -$h : $h; |
361 | 361 | |
362 | - if ( imagecopyresampled( $dst, $this->image, 0, 0, $sx, $sy, $w, $h, $sw, $sh ) ) { |
|
363 | - imagedestroy( $this->image ); |
|
362 | + if (imagecopyresampled($dst, $this->image, 0, 0, $sx, $sy, $w, $h, $sw, $sh)) { |
|
363 | + imagedestroy($this->image); |
|
364 | 364 | $this->image = $dst; |
365 | 365 | return true; |
366 | 366 | } |
367 | 367 | } |
368 | - return new WP_Error( 'image_flip_error', __('Image flip failed.'), $this->file ); |
|
368 | + return new WP_Error('image_flip_error', __('Image flip failed.'), $this->file); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | /** |
@@ -378,10 +378,10 @@ discard block |
||
378 | 378 | * @param string|null $mime_type |
379 | 379 | * @return array|WP_Error {'path'=>string, 'file'=>string, 'width'=>int, 'height'=>int, 'mime-type'=>string} |
380 | 380 | */ |
381 | - public function save( $filename = null, $mime_type = null ) { |
|
382 | - $saved = $this->_save( $this->image, $filename, $mime_type ); |
|
381 | + public function save($filename = null, $mime_type = null) { |
|
382 | + $saved = $this->_save($this->image, $filename, $mime_type); |
|
383 | 383 | |
384 | - if ( ! is_wp_error( $saved ) ) { |
|
384 | + if ( ! is_wp_error($saved)) { |
|
385 | 385 | $this->file = $saved['path']; |
386 | 386 | $this->mime_type = $saved['mime-type']; |
387 | 387 | } |
@@ -395,36 +395,36 @@ discard block |
||
395 | 395 | * @param string|null $mime_type |
396 | 396 | * @return WP_Error|array |
397 | 397 | */ |
398 | - protected function _save( $image, $filename = null, $mime_type = null ) { |
|
399 | - list( $filename, $extension, $mime_type ) = $this->get_output_format( $filename, $mime_type ); |
|
398 | + protected function _save($image, $filename = null, $mime_type = null) { |
|
399 | + list($filename, $extension, $mime_type) = $this->get_output_format($filename, $mime_type); |
|
400 | 400 | |
401 | - if ( ! $filename ) |
|
402 | - $filename = $this->generate_filename( null, null, $extension ); |
|
401 | + if ( ! $filename) |
|
402 | + $filename = $this->generate_filename(null, null, $extension); |
|
403 | 403 | |
404 | - if ( 'image/gif' == $mime_type ) { |
|
405 | - if ( ! $this->make_image( $filename, 'imagegif', array( $image, $filename ) ) ) |
|
406 | - return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
404 | + if ('image/gif' == $mime_type) { |
|
405 | + if ( ! $this->make_image($filename, 'imagegif', array($image, $filename))) |
|
406 | + return new WP_Error('image_save_error', __('Image Editor Save Failed')); |
|
407 | 407 | } |
408 | - elseif ( 'image/png' == $mime_type ) { |
|
408 | + elseif ('image/png' == $mime_type) { |
|
409 | 409 | // convert from full colors to index colors, like original PNG. |
410 | - if ( function_exists('imageistruecolor') && ! imageistruecolor( $image ) ) |
|
411 | - imagetruecolortopalette( $image, false, imagecolorstotal( $image ) ); |
|
410 | + if (function_exists('imageistruecolor') && ! imageistruecolor($image)) |
|
411 | + imagetruecolortopalette($image, false, imagecolorstotal($image)); |
|
412 | 412 | |
413 | - if ( ! $this->make_image( $filename, 'imagepng', array( $image, $filename ) ) ) |
|
414 | - return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
413 | + if ( ! $this->make_image($filename, 'imagepng', array($image, $filename))) |
|
414 | + return new WP_Error('image_save_error', __('Image Editor Save Failed')); |
|
415 | 415 | } |
416 | - elseif ( 'image/jpeg' == $mime_type ) { |
|
417 | - if ( ! $this->make_image( $filename, 'imagejpeg', array( $image, $filename, $this->get_quality() ) ) ) |
|
418 | - return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
416 | + elseif ('image/jpeg' == $mime_type) { |
|
417 | + if ( ! $this->make_image($filename, 'imagejpeg', array($image, $filename, $this->get_quality()))) |
|
418 | + return new WP_Error('image_save_error', __('Image Editor Save Failed')); |
|
419 | 419 | } |
420 | 420 | else { |
421 | - return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
421 | + return new WP_Error('image_save_error', __('Image Editor Save Failed')); |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | // Set correct file permissions |
425 | - $stat = stat( dirname( $filename ) ); |
|
425 | + $stat = stat(dirname($filename)); |
|
426 | 426 | $perms = $stat['mode'] & 0000666; //same permissions as parent folder, strip off the executable bits |
427 | - @ chmod( $filename, $perms ); |
|
427 | + @ chmod($filename, $perms); |
|
428 | 428 | |
429 | 429 | /** |
430 | 430 | * Filter the name of the saved image file. |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | */ |
436 | 436 | return array( |
437 | 437 | 'path' => $filename, |
438 | - 'file' => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ), |
|
438 | + 'file' => wp_basename(apply_filters('image_make_intermediate_size', $filename)), |
|
439 | 439 | 'width' => $this->size['width'], |
440 | 440 | 'height' => $this->size['height'], |
441 | 441 | 'mime-type' => $mime_type, |
@@ -451,19 +451,19 @@ discard block |
||
451 | 451 | * @param string $mime_type |
452 | 452 | * @return bool |
453 | 453 | */ |
454 | - public function stream( $mime_type = null ) { |
|
455 | - list( $filename, $extension, $mime_type ) = $this->get_output_format( null, $mime_type ); |
|
454 | + public function stream($mime_type = null) { |
|
455 | + list($filename, $extension, $mime_type) = $this->get_output_format(null, $mime_type); |
|
456 | 456 | |
457 | - switch ( $mime_type ) { |
|
457 | + switch ($mime_type) { |
|
458 | 458 | case 'image/png': |
459 | - header( 'Content-Type: image/png' ); |
|
460 | - return imagepng( $this->image ); |
|
459 | + header('Content-Type: image/png'); |
|
460 | + return imagepng($this->image); |
|
461 | 461 | case 'image/gif': |
462 | - header( 'Content-Type: image/gif' ); |
|
463 | - return imagegif( $this->image ); |
|
462 | + header('Content-Type: image/gif'); |
|
463 | + return imagegif($this->image); |
|
464 | 464 | default: |
465 | - header( 'Content-Type: image/jpeg' ); |
|
466 | - return imagejpeg( $this->image, null, $this->get_quality() ); |
|
465 | + header('Content-Type: image/jpeg'); |
|
466 | + return imagejpeg($this->image, null, $this->get_quality()); |
|
467 | 467 | } |
468 | 468 | } |
469 | 469 | |
@@ -478,10 +478,10 @@ discard block |
||
478 | 478 | * @param array $arguments |
479 | 479 | * @return bool |
480 | 480 | */ |
481 | - protected function make_image( $filename, $function, $arguments ) { |
|
482 | - if ( wp_is_stream( $filename ) ) |
|
481 | + protected function make_image($filename, $function, $arguments) { |
|
482 | + if (wp_is_stream($filename)) |
|
483 | 483 | $arguments[1] = null; |
484 | 484 | |
485 | - return parent::make_image( $filename, $function, $arguments ); |
|
485 | + return parent::make_image($filename, $function, $arguments); |
|
486 | 486 | } |
487 | 487 | } |
@@ -42,8 +42,9 @@ discard block |
||
42 | 42 | * @return bool |
43 | 43 | */ |
44 | 44 | public static function test( $args = array() ) { |
45 | - if ( ! extension_loaded('gd') || ! function_exists('gd_info') ) |
|
46 | - return false; |
|
45 | + if ( ! extension_loaded('gd') || ! function_exists('gd_info') ) { |
|
46 | + return false; |
|
47 | + } |
|
47 | 48 | |
48 | 49 | // On some setups GD library does not provide imagerotate() - Ticket #11536 |
49 | 50 | if ( isset( $args['methods'] ) && |
@@ -90,11 +91,13 @@ discard block |
||
90 | 91 | * @return bool|WP_Error True if loaded successfully; WP_Error on failure. |
91 | 92 | */ |
92 | 93 | public function load() { |
93 | - if ( $this->image ) |
|
94 | - return true; |
|
94 | + if ( $this->image ) { |
|
95 | + return true; |
|
96 | + } |
|
95 | 97 | |
96 | - if ( ! is_file( $this->file ) && ! preg_match( '|^https?://|', $this->file ) ) |
|
97 | - return new WP_Error( 'error_loading_image', __('File doesn’t exist?'), $this->file ); |
|
98 | + if ( ! is_file( $this->file ) && ! preg_match( '|^https?://|', $this->file ) ) { |
|
99 | + return new WP_Error( 'error_loading_image', __('File doesn’t exist?'), $this->file ); |
|
100 | + } |
|
98 | 101 | |
99 | 102 | /** |
100 | 103 | * Filter the memory limit allocated for image manipulation. |
@@ -109,12 +112,14 @@ discard block |
||
109 | 112 | |
110 | 113 | $this->image = @imagecreatefromstring( file_get_contents( $this->file ) ); |
111 | 114 | |
112 | - if ( ! is_resource( $this->image ) ) |
|
113 | - return new WP_Error( 'invalid_image', __('File is not an image.'), $this->file ); |
|
115 | + if ( ! is_resource( $this->image ) ) { |
|
116 | + return new WP_Error( 'invalid_image', __('File is not an image.'), $this->file ); |
|
117 | + } |
|
114 | 118 | |
115 | 119 | $size = @getimagesize( $this->file ); |
116 | - if ( ! $size ) |
|
117 | - return new WP_Error( 'invalid_image', __('Could not read image size.'), $this->file ); |
|
120 | + if ( ! $size ) { |
|
121 | + return new WP_Error( 'invalid_image', __('Could not read image size.'), $this->file ); |
|
122 | + } |
|
118 | 123 | |
119 | 124 | if ( function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' ) ) { |
120 | 125 | imagealphablending( $this->image, false ); |
@@ -138,11 +143,13 @@ discard block |
||
138 | 143 | * @return true |
139 | 144 | */ |
140 | 145 | protected function update_size( $width = false, $height = false ) { |
141 | - if ( ! $width ) |
|
142 | - $width = imagesx( $this->image ); |
|
146 | + if ( ! $width ) { |
|
147 | + $width = imagesx( $this->image ); |
|
148 | + } |
|
143 | 149 | |
144 | - if ( ! $height ) |
|
145 | - $height = imagesy( $this->image ); |
|
150 | + if ( ! $height ) { |
|
151 | + $height = imagesy( $this->image ); |
|
152 | + } |
|
146 | 153 | |
147 | 154 | return parent::update_size( $width, $height ); |
148 | 155 | } |
@@ -164,8 +171,9 @@ discard block |
||
164 | 171 | * @return true|WP_Error |
165 | 172 | */ |
166 | 173 | public function resize( $max_w, $max_h, $crop = false ) { |
167 | - if ( ( $this->size['width'] == $max_w ) && ( $this->size['height'] == $max_h ) ) |
|
168 | - return true; |
|
174 | + if ( ( $this->size['width'] == $max_w ) && ( $this->size['height'] == $max_h ) ) { |
|
175 | + return true; |
|
176 | + } |
|
169 | 177 | |
170 | 178 | $resized = $this->_resize( $max_w, $max_h, $crop ); |
171 | 179 | |
@@ -174,8 +182,9 @@ discard block |
||
174 | 182 | $this->image = $resized; |
175 | 183 | return true; |
176 | 184 | |
177 | - } elseif ( is_wp_error( $resized ) ) |
|
178 | - return $resized; |
|
185 | + } elseif ( is_wp_error( $resized ) ) { |
|
186 | + return $resized; |
|
187 | + } |
|
179 | 188 | |
180 | 189 | return new WP_Error( 'image_resize_error', __('Image resize failed.'), $this->file ); |
181 | 190 | } |
@@ -284,10 +293,12 @@ discard block |
||
284 | 293 | public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ) { |
285 | 294 | // If destination width/height isn't specified, use same as |
286 | 295 | // width/height from source. |
287 | - if ( ! $dst_w ) |
|
288 | - $dst_w = $src_w; |
|
289 | - if ( ! $dst_h ) |
|
290 | - $dst_h = $src_h; |
|
296 | + if ( ! $dst_w ) { |
|
297 | + $dst_w = $src_w; |
|
298 | + } |
|
299 | + if ( ! $dst_h ) { |
|
300 | + $dst_h = $src_h; |
|
301 | + } |
|
291 | 302 | |
292 | 303 | $dst = wp_imagecreatetruecolor( $dst_w, $dst_h ); |
293 | 304 | |
@@ -296,8 +307,9 @@ discard block |
||
296 | 307 | $src_h -= $src_y; |
297 | 308 | } |
298 | 309 | |
299 | - if ( function_exists( 'imageantialias' ) ) |
|
300 | - imageantialias( $dst, true ); |
|
310 | + if ( function_exists( 'imageantialias' ) ) { |
|
311 | + imageantialias( $dst, true ); |
|
312 | + } |
|
301 | 313 | |
302 | 314 | imagecopyresampled( $dst, $this->image, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ); |
303 | 315 | |
@@ -398,26 +410,28 @@ discard block |
||
398 | 410 | protected function _save( $image, $filename = null, $mime_type = null ) { |
399 | 411 | list( $filename, $extension, $mime_type ) = $this->get_output_format( $filename, $mime_type ); |
400 | 412 | |
401 | - if ( ! $filename ) |
|
402 | - $filename = $this->generate_filename( null, null, $extension ); |
|
413 | + if ( ! $filename ) { |
|
414 | + $filename = $this->generate_filename( null, null, $extension ); |
|
415 | + } |
|
403 | 416 | |
404 | 417 | if ( 'image/gif' == $mime_type ) { |
405 | - if ( ! $this->make_image( $filename, 'imagegif', array( $image, $filename ) ) ) |
|
406 | - return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
407 | - } |
|
408 | - elseif ( 'image/png' == $mime_type ) { |
|
418 | + if ( ! $this->make_image( $filename, 'imagegif', array( $image, $filename ) ) ) { |
|
419 | + return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
420 | + } |
|
421 | + } elseif ( 'image/png' == $mime_type ) { |
|
409 | 422 | // convert from full colors to index colors, like original PNG. |
410 | - if ( function_exists('imageistruecolor') && ! imageistruecolor( $image ) ) |
|
411 | - imagetruecolortopalette( $image, false, imagecolorstotal( $image ) ); |
|
423 | + if ( function_exists('imageistruecolor') && ! imageistruecolor( $image ) ) { |
|
424 | + imagetruecolortopalette( $image, false, imagecolorstotal( $image ) ); |
|
425 | + } |
|
412 | 426 | |
413 | - if ( ! $this->make_image( $filename, 'imagepng', array( $image, $filename ) ) ) |
|
414 | - return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
415 | - } |
|
416 | - elseif ( 'image/jpeg' == $mime_type ) { |
|
417 | - if ( ! $this->make_image( $filename, 'imagejpeg', array( $image, $filename, $this->get_quality() ) ) ) |
|
418 | - return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
419 | - } |
|
420 | - else { |
|
427 | + if ( ! $this->make_image( $filename, 'imagepng', array( $image, $filename ) ) ) { |
|
428 | + return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
429 | + } |
|
430 | + } elseif ( 'image/jpeg' == $mime_type ) { |
|
431 | + if ( ! $this->make_image( $filename, 'imagejpeg', array( $image, $filename, $this->get_quality() ) ) ) { |
|
432 | + return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
433 | + } |
|
434 | + } else { |
|
421 | 435 | return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
422 | 436 | } |
423 | 437 | |
@@ -479,8 +493,9 @@ discard block |
||
479 | 493 | * @return bool |
480 | 494 | */ |
481 | 495 | protected function make_image( $filename, $function, $arguments ) { |
482 | - if ( wp_is_stream( $filename ) ) |
|
483 | - $arguments[1] = null; |
|
496 | + if ( wp_is_stream( $filename ) ) { |
|
497 | + $arguments[1] = null; |
|
498 | + } |
|
484 | 499 | |
485 | 500 | return parent::make_image( $filename, $function, $arguments ); |
486 | 501 | } |
@@ -68,7 +68,7 @@ |
||
68 | 68 | |
69 | 69 | /** |
70 | 70 | * @param resource $fh |
71 | - * @return true |
|
71 | + * @return boolean |
|
72 | 72 | */ |
73 | 73 | function export_to_file_handle($fh) { |
74 | 74 | $entries = array_filter( $this->entries, array( $this, 'is_entry_good_for_export' ) ); |
@@ -1,9 +1,9 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * RSS 1 RDF Feed Template for displaying RSS 1 Posts feed. |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - */ |
|
3 | + * RSS 1 RDF Feed Template for displaying RSS 1 Posts feed. |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + */ |
|
7 | 7 | |
8 | 8 | header('Content-Type: ' . feed_content_type('rdf') . '; charset=' . get_option('blog_charset'), true); |
9 | 9 | $more = 1; |
@@ -5,13 +5,13 @@ discard block |
||
5 | 5 | * @package WordPress |
6 | 6 | */ |
7 | 7 | |
8 | -header('Content-Type: ' . feed_content_type('rdf') . '; charset=' . get_option('blog_charset'), true); |
|
8 | +header('Content-Type: '.feed_content_type('rdf').'; charset='.get_option('blog_charset'), true); |
|
9 | 9 | $more = 1; |
10 | 10 | |
11 | 11 | echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; |
12 | 12 | |
13 | 13 | /** This action is documented in wp-includes/feed-rss2.php */ |
14 | -do_action( 'rss_tag_pre', 'rdf' ); |
|
14 | +do_action('rss_tag_pre', 'rdf'); |
|
15 | 15 | ?> |
16 | 16 | <rdf:RDF |
17 | 17 | xmlns="http://purl.org/rss/1.0/" |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @since 2.0.0 |
28 | 28 | */ |
29 | - do_action( 'rdf_ns' ); |
|
29 | + do_action('rdf_ns'); |
|
30 | 30 | ?> |
31 | 31 | > |
32 | 32 | <channel rdf:about="<?php bloginfo_rss("url") ?>"> |
@@ -36,11 +36,11 @@ discard block |
||
36 | 36 | <dc:date><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_lastpostmodified('GMT'), false); ?></dc:date> |
37 | 37 | <sy:updatePeriod><?php |
38 | 38 | /** This filter is documented in wp-includes/feed-rss2.php */ |
39 | - echo apply_filters( 'rss_update_period', 'hourly' ); |
|
39 | + echo apply_filters('rss_update_period', 'hourly'); |
|
40 | 40 | ?></sy:updatePeriod> |
41 | 41 | <sy:updateFrequency><?php |
42 | 42 | /** This filter is documented in wp-includes/feed-rss2.php */ |
43 | - echo apply_filters( 'rss_update_frequency', '1' ); |
|
43 | + echo apply_filters('rss_update_frequency', '1'); |
|
44 | 44 | ?></sy:updateFrequency> |
45 | 45 | <sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase> |
46 | 46 | <?php |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * |
50 | 50 | * @since 2.0.0 |
51 | 51 | */ |
52 | - do_action( 'rdf_header' ); |
|
52 | + do_action('rdf_header'); |
|
53 | 53 | ?> |
54 | 54 | <items> |
55 | 55 | <rdf:Seq> |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | * |
79 | 79 | * @since 2.0.0 |
80 | 80 | */ |
81 | - do_action( 'rdf_item' ); |
|
81 | + do_action('rdf_item'); |
|
82 | 82 | ?> |
83 | 83 | </item> |
84 | -<?php endwhile; ?> |
|
84 | +<?php endwhile; ?> |
|
85 | 85 | </rdf:RDF> |
@@ -68,10 +68,13 @@ |
||
68 | 68 | <?php the_category_rss('rdf') ?> |
69 | 69 | <?php if (get_option('rss_use_excerpt')) : ?> |
70 | 70 | <description><![CDATA[<?php the_excerpt_rss() ?>]]></description> |
71 | -<?php else : ?> |
|
71 | +<?php else { |
|
72 | + : ?> |
|
72 | 73 | <description><![CDATA[<?php the_excerpt_rss() ?>]]></description> |
73 | 74 | <content:encoded><![CDATA[<?php the_content_feed('rdf') ?>]]></content:encoded> |
74 | -<?php endif; ?> |
|
75 | +<?php endif; |
|
76 | +} |
|
77 | +?> |
|
75 | 78 | <?php |
76 | 79 | /** |
77 | 80 | * Fires at the end of each RDF feed item. |
@@ -46,14 +46,14 @@ discard block |
||
46 | 46 | * |
47 | 47 | * @since 2.6.0 |
48 | 48 | */ |
49 | -define('AUTH_KEY', 'put your unique phrase here'); |
|
50 | -define('SECURE_AUTH_KEY', 'put your unique phrase here'); |
|
51 | -define('LOGGED_IN_KEY', 'put your unique phrase here'); |
|
52 | -define('NONCE_KEY', 'put your unique phrase here'); |
|
53 | -define('AUTH_SALT', 'put your unique phrase here'); |
|
49 | +define('AUTH_KEY', 'put your unique phrase here'); |
|
50 | +define('SECURE_AUTH_KEY', 'put your unique phrase here'); |
|
51 | +define('LOGGED_IN_KEY', 'put your unique phrase here'); |
|
52 | +define('NONCE_KEY', 'put your unique phrase here'); |
|
53 | +define('AUTH_SALT', 'put your unique phrase here'); |
|
54 | 54 | define('SECURE_AUTH_SALT', 'put your unique phrase here'); |
55 | -define('LOGGED_IN_SALT', 'put your unique phrase here'); |
|
56 | -define('NONCE_SALT', 'put your unique phrase here'); |
|
55 | +define('LOGGED_IN_SALT', 'put your unique phrase here'); |
|
56 | +define('NONCE_SALT', 'put your unique phrase here'); |
|
57 | 57 | |
58 | 58 | /**#@-*/ |
59 | 59 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * You can have multiple installations in one database if you give each |
64 | 64 | * a unique prefix. Only numbers, letters, and underscores please! |
65 | 65 | */ |
66 | -$table_prefix = 'wp_'; |
|
66 | +$table_prefix = 'wp_'; |
|
67 | 67 | |
68 | 68 | /** |
69 | 69 | * For developers: WordPress debugging mode. |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | /* That's all, stop editing! Happy blogging. */ |
83 | 83 | |
84 | 84 | /** Absolute path to the WordPress directory. */ |
85 | -if ( !defined('ABSPATH') ) |
|
86 | - define('ABSPATH', dirname(__FILE__) . '/'); |
|
85 | +if ( ! defined('ABSPATH')) |
|
86 | + define('ABSPATH', dirname(__FILE__).'/'); |
|
87 | 87 | |
88 | 88 | /** Sets up WordPress vars and included files. */ |
89 | -require_once(ABSPATH . 'wp-settings.php'); |
|
89 | +require_once(ABSPATH.'wp-settings.php'); |
@@ -82,8 +82,9 @@ |
||
82 | 82 | /* That's all, stop editing! Happy blogging. */ |
83 | 83 | |
84 | 84 | /** Absolute path to the WordPress directory. */ |
85 | -if ( !defined('ABSPATH') ) |
|
86 | - define('ABSPATH', dirname(__FILE__) . '/'); |
|
85 | +if ( !defined('ABSPATH') ) { |
|
86 | + define('ABSPATH', dirname(__FILE__) . '/'); |
|
87 | +} |
|
87 | 88 | |
88 | 89 | /** Sets up WordPress vars and included files. */ |
89 | 90 | require_once(ABSPATH . 'wp-settings.php'); |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | /* Path to the WordPress codebase you'd like to test. Add a backslash in the end. */ |
4 | -define( 'ABSPATH', dirname( __FILE__ ) . '/src/' ); |
|
4 | +define('ABSPATH', dirname(__FILE__).'/src/'); |
|
5 | 5 | |
6 | 6 | // Test with multisite enabled. |
7 | 7 | // Alternatively, use the tests/phpunit/multisite.xml configuration file. |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | // define( 'WP_TESTS_FORCE_KNOWN_BUGS', true ); |
13 | 13 | |
14 | 14 | // Test with WordPress debug mode (default). |
15 | -define( 'WP_DEBUG', true ); |
|
15 | +define('WP_DEBUG', true); |
|
16 | 16 | |
17 | 17 | // ** MySQL settings ** // |
18 | 18 | |
@@ -23,19 +23,19 @@ discard block |
||
23 | 23 | // These tests will DROP ALL TABLES in the database with the prefix named below. |
24 | 24 | // DO NOT use a production database or one that is shared with something else. |
25 | 25 | |
26 | -define( 'DB_NAME', 'youremptytestdbnamehere' ); |
|
27 | -define( 'DB_USER', 'yourusernamehere' ); |
|
28 | -define( 'DB_PASSWORD', 'yourpasswordhere' ); |
|
29 | -define( 'DB_HOST', 'localhost' ); |
|
30 | -define( 'DB_CHARSET', 'utf8' ); |
|
31 | -define( 'DB_COLLATE', '' ); |
|
26 | +define('DB_NAME', 'youremptytestdbnamehere'); |
|
27 | +define('DB_USER', 'yourusernamehere'); |
|
28 | +define('DB_PASSWORD', 'yourpasswordhere'); |
|
29 | +define('DB_HOST', 'localhost'); |
|
30 | +define('DB_CHARSET', 'utf8'); |
|
31 | +define('DB_COLLATE', ''); |
|
32 | 32 | |
33 | -$table_prefix = 'wptests_'; // Only numbers, letters, and underscores please! |
|
33 | +$table_prefix = 'wptests_'; // Only numbers, letters, and underscores please! |
|
34 | 34 | |
35 | -define( 'WP_TESTS_DOMAIN', 'example.org' ); |
|
36 | -define( 'WP_TESTS_EMAIL', '[email protected]' ); |
|
37 | -define( 'WP_TESTS_TITLE', 'Test Blog' ); |
|
35 | +define('WP_TESTS_DOMAIN', 'example.org'); |
|
36 | +define('WP_TESTS_EMAIL', '[email protected]'); |
|
37 | +define('WP_TESTS_TITLE', 'Test Blog'); |
|
38 | 38 | |
39 | -define( 'WP_PHP_BINARY', 'php' ); |
|
39 | +define('WP_PHP_BINARY', 'php'); |
|
40 | 40 | |
41 | -define( 'WPLANG', '' ); |
|
41 | +define('WPLANG', ''); |