Changeset 42343 for trunk/src/wp-includes/class-oembed.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/class-oembed.php (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-oembed.php
r42151 r42343 50 50 */ 51 51 public function __construct() { 52 $host = urlencode( home_url() );52 $host = urlencode( home_url() ); 53 53 $providers = array( 54 '#https?://((m|www)\.)?youtube\.com/watch.*#i' => array( 'https://www.youtube.com/oembed', true),55 '#https?://((m|www)\.)?youtube\.com/playlist.*#i' => array( 'https://www.youtube.com/oembed', true),56 '#https?://youtu\.be/.*#i' => array( 'https://www.youtube.com/oembed', true),57 '#https?://(.+\.)?vimeo\.com/.*#i' => array( 'https://vimeo.com/api/oembed.{format}', true),58 '#https?://(www\.)?dailymotion\.com/.*#i' => array( 'https://www.dailymotion.com/services/oembed', true),59 '#https?://dai\.ly/.*#i' => array( 'https://www.dailymotion.com/services/oembed', true),60 '#https?://(www\.)?flickr\.com/.*#i' => array( 'https://www.flickr.com/services/oembed/', true),61 '#https?://flic\.kr/.*#i' => array( 'https://www.flickr.com/services/oembed/', true),62 '#https?://(.+\.)?smugmug\.com/.*#i' => array( 'https://api.smugmug.com/services/oembed/', true),63 '#https?://(www\.)?hulu\.com/watch/.*#i' => array( 'http://www.hulu.com/api/oembed.{format}', true),64 'http://i*.photobucket.com/albums/*' => array( 'http://api.photobucket.com/oembed',false ),65 'http://gi*.photobucket.com/groups/*' => array( 'http://api.photobucket.com/oembed',false ),66 '#https?://(www\.)?scribd\.com/doc/.*#i' => array( 'https://www.scribd.com/services/oembed', true),67 '#https?://wordpress\.tv/.*#i' => array( 'https://wordpress.tv/oembed/', true),68 '#https?://(.+\.)?polldaddy\.com/.*#i' => array( 'https://polldaddy.com/oembed/', true),69 '#https?://poll\.fm/.*#i' => array( 'https://polldaddy.com/oembed/', true),70 '#https?://(www\.)?funnyordie\.com/videos/.*#i' => array( 'http://www.funnyordie.com/oembed', true),71 '#https?://(www\.)?twitter\.com/\w{1,15}/status(es)?/.*#i' => array( 'https://publish.twitter.com/oembed', true),72 '#https?://(www\.)?twitter\.com/\w{1,15}$#i' => array( 'https://publish.twitter.com/oembed', true),73 '#https?://(www\.)?twitter\.com/\w{1,15}/likes$#i' => array( 'https://publish.twitter.com/oembed', true),74 '#https?://(www\.)?twitter\.com/\w{1,15}/lists/.*#i' => array( 'https://publish.twitter.com/oembed', true),75 '#https?://(www\.)?twitter\.com/\w{1,15}/timelines/.*#i' => array( 'https://publish.twitter.com/oembed', true),76 '#https?://(www\.)?twitter\.com/i/moments/.*#i' => array( 'https://publish.twitter.com/oembed', true),77 '#https?://(www\.)?soundcloud\.com/.*#i' => array( 'https://soundcloud.com/oembed', true),78 '#https?://(.+?\.)?slideshare\.net/.*#i' => array( 'https://www.slideshare.net/api/oembed/2', true),79 '#https?://(www\.)?instagr(\.am|am\.com)/p/.*#i' => array( 'https://api.instagram.com/oembed', true),80 '#https?://(open|play)\.spotify\.com/.*#i' => array( 'https://embed.spotify.com/oembed/', true),81 '#https?://(.+\.)?imgur\.com/.*#i' => array( 'https://api.imgur.com/oembed', true),82 '#https?://(www\.)?meetu(\.ps|p\.com)/.*#i' => array( 'https://api.meetup.com/oembed', true),83 '#https?://(www\.)?issuu\.com/.+/docs/.+#i' => array( 'https://issuu.com/oembed_wp', true),84 '#https?://(www\.)?collegehumor\.com/video/.*#i' => array( 'https://www.collegehumor.com/oembed.{format}', true),85 '#https?://(www\.)?mixcloud\.com/.*#i' => array( 'https://www.mixcloud.com/oembed', true),86 '#https?://(www\.|embed\.)?ted\.com/talks/.*#i' => array( 'https://www.ted.com/services/v1/oembed.{format}', true),87 '#https?://(www\.)?(animoto|video214)\.com/play/.*#i' => array( 'https://animoto.com/oembeds/create', true),88 '#https?://(.+)\.tumblr\.com/post/.*#i' => array( 'https://www.tumblr.com/oembed/1.0', true),89 '#https?://(www\.)?kickstarter\.com/projects/.*#i' => array( 'https://www.kickstarter.com/services/oembed', true),90 '#https?://kck\.st/.*#i' => array( 'https://www.kickstarter.com/services/oembed', true),91 '#https?://cloudup\.com/.*#i' => array( 'https://cloudup.com/oembed', true),92 '#https?://(www\.)?reverbnation\.com/.*#i' => array( 'https://www.reverbnation.com/oembed', true),93 '#https?://videopress\.com/v/.*#' => array( 'https://public-api.wordpress.com/oembed/?for=' . $host, true),94 '#https?://(www\.)?reddit\.com/r/[^/]+/comments/.*#i' => array( 'https://www.reddit.com/oembed', true),95 '#https?://(www\.)?speakerdeck\.com/.*#i' => array( 'https://speakerdeck.com/oembed.{format}', true),96 '#https?://www\.facebook\.com/.*/posts/.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true),97 '#https?://www\.facebook\.com/.*/activity/.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true),98 '#https?://www\.facebook\.com/.*/photos/.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true),99 '#https?://www\.facebook\.com/photo(s/|\.php).*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true),100 '#https?://www\.facebook\.com/permalink\.php.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true),101 '#https?://www\.facebook\.com/media/.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true),102 '#https?://www\.facebook\.com/questions/.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true),103 '#https?://www\.facebook\.com/notes/.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true),104 '#https?://www\.facebook\.com/.*/videos/.*#i' => array( 'https://www.facebook.com/plugins/video/oembed.json/', true),105 '#https?://www\.facebook\.com/video\.php.*#i' => array( 'https://www.facebook.com/plugins/video/oembed.json/', true),106 '#https?://(www\.)?screencast\.com/.*#i' => array( 'https://api.screencast.com/external/oembed', true),107 '#https?://([a-z0-9-]+\.)?amazon\.(com|com\.mx|com\.br|ca)/.*#i' => array( 'https://read.amazon.com/kp/api/oembed', true),108 '#https?://([a-z0-9-]+\.)?amazon\.(co\.uk|de|fr|it|es|in|nl|ru)/.*#i' => array( 'https://read.amazon.co.uk/kp/api/oembed', true),109 '#https?://([a-z0-9-]+\.)?amazon\.(co\.jp|com\.au)/.*#i' => array( 'https://read.amazon.com.au/kp/api/oembed', true),110 '#https?://([a-z0-9-]+\.)?amazon\.cn/.*#i' => array( 'https://read.amazon.cn/kp/api/oembed', true),111 '#https?://(www\.)?a\.co/.*#i' => array( 'https://read.amazon.com/kp/api/oembed', true),112 '#https?://(www\.)?amzn\.to/.*#i' => array( 'https://read.amazon.com/kp/api/oembed', true),113 '#https?://(www\.)?amzn\.eu/.*#i' => array( 'https://read.amazon.co.uk/kp/api/oembed', true),114 '#https?://(www\.)?amzn\.in/.*#i' => array( 'https://read.amazon.in/kp/api/oembed', true),115 '#https?://(www\.)?amzn\.asia/.*#i' => array( 'https://read.amazon.com.au/kp/api/oembed', true),116 '#https?://(www\.)?z\.cn/.*#i' => array( 'https://read.amazon.cn/kp/api/oembed', true),117 '#https?://www\.someecards\.com/.+-cards/.+#i' => array( 'https://www.someecards.com/v2/oembed/', true),118 '#https?://www\.someecards\.com/usercards/viewcard/.+#i' => array( 'https://www.someecards.com/v2/oembed/', true),119 '#https?://some\.ly\/.+#i' => array( 'https://www.someecards.com/v2/oembed/', true),54 '#https?://((m|www)\.)?youtube\.com/watch.*#i' => array( 'https://www.youtube.com/oembed', true ), 55 '#https?://((m|www)\.)?youtube\.com/playlist.*#i' => array( 'https://www.youtube.com/oembed', true ), 56 '#https?://youtu\.be/.*#i' => array( 'https://www.youtube.com/oembed', true ), 57 '#https?://(.+\.)?vimeo\.com/.*#i' => array( 'https://vimeo.com/api/oembed.{format}', true ), 58 '#https?://(www\.)?dailymotion\.com/.*#i' => array( 'https://www.dailymotion.com/services/oembed', true ), 59 '#https?://dai\.ly/.*#i' => array( 'https://www.dailymotion.com/services/oembed', true ), 60 '#https?://(www\.)?flickr\.com/.*#i' => array( 'https://www.flickr.com/services/oembed/', true ), 61 '#https?://flic\.kr/.*#i' => array( 'https://www.flickr.com/services/oembed/', true ), 62 '#https?://(.+\.)?smugmug\.com/.*#i' => array( 'https://api.smugmug.com/services/oembed/', true ), 63 '#https?://(www\.)?hulu\.com/watch/.*#i' => array( 'http://www.hulu.com/api/oembed.{format}', true ), 64 'http://i*.photobucket.com/albums/*' => array( 'http://api.photobucket.com/oembed', false ), 65 'http://gi*.photobucket.com/groups/*' => array( 'http://api.photobucket.com/oembed', false ), 66 '#https?://(www\.)?scribd\.com/doc/.*#i' => array( 'https://www.scribd.com/services/oembed', true ), 67 '#https?://wordpress\.tv/.*#i' => array( 'https://wordpress.tv/oembed/', true ), 68 '#https?://(.+\.)?polldaddy\.com/.*#i' => array( 'https://polldaddy.com/oembed/', true ), 69 '#https?://poll\.fm/.*#i' => array( 'https://polldaddy.com/oembed/', true ), 70 '#https?://(www\.)?funnyordie\.com/videos/.*#i' => array( 'http://www.funnyordie.com/oembed', true ), 71 '#https?://(www\.)?twitter\.com/\w{1,15}/status(es)?/.*#i' => array( 'https://publish.twitter.com/oembed', true ), 72 '#https?://(www\.)?twitter\.com/\w{1,15}$#i' => array( 'https://publish.twitter.com/oembed', true ), 73 '#https?://(www\.)?twitter\.com/\w{1,15}/likes$#i' => array( 'https://publish.twitter.com/oembed', true ), 74 '#https?://(www\.)?twitter\.com/\w{1,15}/lists/.*#i' => array( 'https://publish.twitter.com/oembed', true ), 75 '#https?://(www\.)?twitter\.com/\w{1,15}/timelines/.*#i' => array( 'https://publish.twitter.com/oembed', true ), 76 '#https?://(www\.)?twitter\.com/i/moments/.*#i' => array( 'https://publish.twitter.com/oembed', true ), 77 '#https?://(www\.)?soundcloud\.com/.*#i' => array( 'https://soundcloud.com/oembed', true ), 78 '#https?://(.+?\.)?slideshare\.net/.*#i' => array( 'https://www.slideshare.net/api/oembed/2', true ), 79 '#https?://(www\.)?instagr(\.am|am\.com)/p/.*#i' => array( 'https://api.instagram.com/oembed', true ), 80 '#https?://(open|play)\.spotify\.com/.*#i' => array( 'https://embed.spotify.com/oembed/', true ), 81 '#https?://(.+\.)?imgur\.com/.*#i' => array( 'https://api.imgur.com/oembed', true ), 82 '#https?://(www\.)?meetu(\.ps|p\.com)/.*#i' => array( 'https://api.meetup.com/oembed', true ), 83 '#https?://(www\.)?issuu\.com/.+/docs/.+#i' => array( 'https://issuu.com/oembed_wp', true ), 84 '#https?://(www\.)?collegehumor\.com/video/.*#i' => array( 'https://www.collegehumor.com/oembed.{format}', true ), 85 '#https?://(www\.)?mixcloud\.com/.*#i' => array( 'https://www.mixcloud.com/oembed', true ), 86 '#https?://(www\.|embed\.)?ted\.com/talks/.*#i' => array( 'https://www.ted.com/services/v1/oembed.{format}', true ), 87 '#https?://(www\.)?(animoto|video214)\.com/play/.*#i' => array( 'https://animoto.com/oembeds/create', true ), 88 '#https?://(.+)\.tumblr\.com/post/.*#i' => array( 'https://www.tumblr.com/oembed/1.0', true ), 89 '#https?://(www\.)?kickstarter\.com/projects/.*#i' => array( 'https://www.kickstarter.com/services/oembed', true ), 90 '#https?://kck\.st/.*#i' => array( 'https://www.kickstarter.com/services/oembed', true ), 91 '#https?://cloudup\.com/.*#i' => array( 'https://cloudup.com/oembed', true ), 92 '#https?://(www\.)?reverbnation\.com/.*#i' => array( 'https://www.reverbnation.com/oembed', true ), 93 '#https?://videopress\.com/v/.*#' => array( 'https://public-api.wordpress.com/oembed/?for=' . $host, true ), 94 '#https?://(www\.)?reddit\.com/r/[^/]+/comments/.*#i' => array( 'https://www.reddit.com/oembed', true ), 95 '#https?://(www\.)?speakerdeck\.com/.*#i' => array( 'https://speakerdeck.com/oembed.{format}', true ), 96 '#https?://www\.facebook\.com/.*/posts/.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ), 97 '#https?://www\.facebook\.com/.*/activity/.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ), 98 '#https?://www\.facebook\.com/.*/photos/.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ), 99 '#https?://www\.facebook\.com/photo(s/|\.php).*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ), 100 '#https?://www\.facebook\.com/permalink\.php.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ), 101 '#https?://www\.facebook\.com/media/.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ), 102 '#https?://www\.facebook\.com/questions/.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ), 103 '#https?://www\.facebook\.com/notes/.*#i' => array( 'https://www.facebook.com/plugins/post/oembed.json/', true ), 104 '#https?://www\.facebook\.com/.*/videos/.*#i' => array( 'https://www.facebook.com/plugins/video/oembed.json/', true ), 105 '#https?://www\.facebook\.com/video\.php.*#i' => array( 'https://www.facebook.com/plugins/video/oembed.json/', true ), 106 '#https?://(www\.)?screencast\.com/.*#i' => array( 'https://api.screencast.com/external/oembed', true ), 107 '#https?://([a-z0-9-]+\.)?amazon\.(com|com\.mx|com\.br|ca)/.*#i' => array( 'https://read.amazon.com/kp/api/oembed', true ), 108 '#https?://([a-z0-9-]+\.)?amazon\.(co\.uk|de|fr|it|es|in|nl|ru)/.*#i' => array( 'https://read.amazon.co.uk/kp/api/oembed', true ), 109 '#https?://([a-z0-9-]+\.)?amazon\.(co\.jp|com\.au)/.*#i' => array( 'https://read.amazon.com.au/kp/api/oembed', true ), 110 '#https?://([a-z0-9-]+\.)?amazon\.cn/.*#i' => array( 'https://read.amazon.cn/kp/api/oembed', true ), 111 '#https?://(www\.)?a\.co/.*#i' => array( 'https://read.amazon.com/kp/api/oembed', true ), 112 '#https?://(www\.)?amzn\.to/.*#i' => array( 'https://read.amazon.com/kp/api/oembed', true ), 113 '#https?://(www\.)?amzn\.eu/.*#i' => array( 'https://read.amazon.co.uk/kp/api/oembed', true ), 114 '#https?://(www\.)?amzn\.in/.*#i' => array( 'https://read.amazon.in/kp/api/oembed', true ), 115 '#https?://(www\.)?amzn\.asia/.*#i' => array( 'https://read.amazon.com.au/kp/api/oembed', true ), 116 '#https?://(www\.)?z\.cn/.*#i' => array( 'https://read.amazon.cn/kp/api/oembed', true ), 117 '#https?://www\.someecards\.com/.+-cards/.+#i' => array( 'https://www.someecards.com/v2/oembed/', true ), 118 '#https?://www\.someecards\.com/usercards/viewcard/.+#i' => array( 'https://www.someecards.com/v2/oembed/', true ), 119 '#https?://some\.ly\/.+#i' => array( 'https://www.someecards.com/v2/oembed/', true ), 120 120 ); 121 121 … … 222 222 223 223 // Fix any embeds that contain new lines in the middle of the HTML which breaks wpautop(). 224 add_filter( 'oembed_dataparse', array( $this, '_strip_newlines'), 10, 3 );224 add_filter( 'oembed_dataparse', array( $this, '_strip_newlines' ), 10, 3 ); 225 225 } 226 226 … … 257 257 $provider = false; 258 258 259 if ( ! isset($args['discover']) )259 if ( ! isset( $args['discover'] ) ) { 260 260 $args['discover'] = true; 261 } 261 262 262 263 foreach ( $this->providers as $matchmask => $data ) { … … 264 265 265 266 // Turn the asterisk-type provider URLs into regex 266 if ( ! $regex ) {267 if ( ! $regex ) { 267 268 $matchmask = '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $matchmask ), '#' ) ) . '#i'; 268 269 $matchmask = preg_replace( '|^#http\\\://|', '#https?\://', $matchmask ); … … 275 276 } 276 277 277 if ( ! $provider && $args['discover'] )278 if ( ! $provider && $args['discover'] ) { 278 279 $provider = $this->discover( $url ); 280 } 279 281 280 282 return $provider; … … 423 425 public function discover( $url ) { 424 426 $providers = array(); 425 $args = array(427 $args = array( 426 428 'limit_response_size' => 153600, // 150 KB 427 429 ); … … 452 454 * used by at least Vimeo). 453 455 */ 454 $linktypes = apply_filters( 'oembed_linktypes', array( 455 'application/json+oembed' => 'json', 456 'text/xml+oembed' => 'xml', 457 'application/xml+oembed' => 'xml', 458 ) ); 456 $linktypes = apply_filters( 457 'oembed_linktypes', array( 458 'application/json+oembed' => 'json', 459 'text/xml+oembed' => 'xml', 460 'application/xml+oembed' => 'xml', 461 ) 462 ); 459 463 460 464 // Strip <body> … … 466 470 $tagfound = false; 467 471 foreach ( $linktypes as $linktype => $format ) { 468 if ( stripos( $html, $linktype) ) {472 if ( stripos( $html, $linktype ) ) { 469 473 $tagfound = true; 470 474 break; … … 476 480 $atts = shortcode_parse_atts( $link ); 477 481 478 if ( ! empty($atts['type']) && !empty($linktypes[$atts['type']]) && !empty($atts['href']) ) {479 $providers[ $linktypes[$atts['type']]] = htmlspecialchars_decode( $atts['href'] );482 if ( ! empty( $atts['type'] ) && ! empty( $linktypes[ $atts['type'] ] ) && ! empty( $atts['href'] ) ) { 483 $providers[ $linktypes[ $atts['type'] ] ] = htmlspecialchars_decode( $atts['href'] ); 480 484 481 485 // Stop here if it's JSON (that's all we need) 482 if ( 'json' == $linktypes[ $atts['type']] )486 if ( 'json' == $linktypes[ $atts['type'] ] ) { 483 487 break; 488 } 484 489 } 485 490 } … … 488 493 489 494 // JSON is preferred to XML 490 if ( ! empty($providers['json']) )495 if ( ! empty( $providers['json'] ) ) { 491 496 return $providers['json']; 492 elseif ( !empty($providers['xml']) )497 } elseif ( ! empty( $providers['xml'] ) ) { 493 498 return $providers['xml']; 494 else 495 return false; 499 } else { 500 return false; 501 } 496 502 } 497 503 … … 511 517 $provider = add_query_arg( 'maxwidth', (int) $args['width'], $provider ); 512 518 $provider = add_query_arg( 'maxheight', (int) $args['height'], $provider ); 513 $provider = add_query_arg( 'url', urlencode( $url), $provider );519 $provider = add_query_arg( 'url', urlencode( $url ), $provider ); 514 520 $provider = add_query_arg( 'dnt', 1, $provider ); 515 521 … … 528 534 foreach ( array( 'json', 'xml' ) as $format ) { 529 535 $result = $this->_fetch_with_format( $provider, $format ); 530 if ( is_wp_error( $result ) && 'not-implemented' == $result->get_error_code() ) 536 if ( is_wp_error( $result ) && 'not-implemented' == $result->get_error_code() ) { 531 537 continue; 538 } 532 539 return ( $result && ! is_wp_error( $result ) ) ? $result : false; 533 540 } … … 551 558 552 559 $response = wp_safe_remote_get( $provider_url_with_args, $args ); 553 if ( 501 == wp_remote_retrieve_response_code( $response ) ) 560 if ( 501 == wp_remote_retrieve_response_code( $response ) ) { 554 561 return new WP_Error( 'not-implemented' ); 555 if ( ! $body = wp_remote_retrieve_body( $response ) ) 556 return false; 562 } 563 if ( ! $body = wp_remote_retrieve_body( $response ) ) { 564 return false; 565 } 557 566 $parse_method = "_parse_$format"; 558 567 return $this->$parse_method( $body ); … … 581 590 */ 582 591 private function _parse_xml( $response_body ) { 583 if ( ! function_exists( 'libxml_disable_entity_loader' ) ) 584 return false; 592 if ( ! function_exists( 'libxml_disable_entity_loader' ) ) { 593 return false; 594 } 585 595 586 596 $loader = libxml_disable_entity_loader( true ); … … 604 614 */ 605 615 private function _parse_xml_body( $response_body ) { 606 if ( ! function_exists( 'simplexml_import_dom' ) || ! class_exists( 'DOMDocument', false ) ) 607 return false; 608 609 $dom = new DOMDocument; 616 if ( ! function_exists( 'simplexml_import_dom' ) || ! class_exists( 'DOMDocument', false ) ) { 617 return false; 618 } 619 620 $dom = new DOMDocument; 610 621 $success = $dom->loadXML( $response_body ); 611 if ( ! $success ) 612 return false; 613 614 if ( isset( $dom->doctype ) ) 615 return false; 622 if ( ! $success ) { 623 return false; 624 } 625 626 if ( isset( $dom->doctype ) ) { 627 return false; 628 } 616 629 617 630 foreach ( $dom->childNodes as $child ) { 618 if ( XML_DOCUMENT_TYPE_NODE === $child->nodeType ) 631 if ( XML_DOCUMENT_TYPE_NODE === $child->nodeType ) { 619 632 return false; 633 } 620 634 } 621 635 622 636 $xml = simplexml_import_dom( $dom ); 623 if ( ! $xml ) 624 return false; 637 if ( ! $xml ) { 638 return false; 639 } 625 640 626 641 $return = new stdClass; … … 642 657 */ 643 658 public function data2html( $data, $url ) { 644 if ( ! is_object( $data ) || empty( $data->type ) ) 645 return false; 659 if ( ! is_object( $data ) || empty( $data->type ) ) { 660 return false; 661 } 646 662 647 663 $return = false; … … 649 665 switch ( $data->type ) { 650 666 case 'photo': 651 if ( empty( $data->url ) || empty( $data->width ) || empty( $data->height ) ) 667 if ( empty( $data->url ) || empty( $data->width ) || empty( $data->height ) ) { 652 668 break; 653 if ( ! is_string( $data->url ) || ! is_numeric( $data->width ) || ! is_numeric( $data->height ) ) 669 } 670 if ( ! is_string( $data->url ) || ! is_numeric( $data->width ) || ! is_numeric( $data->height ) ) { 654 671 break; 655 656 $title = ! empty( $data->title ) && is_string( $data->title ) ? $data->title : ''; 657 $return = '<a href="' . esc_url( $url ) . '"><img src="' . esc_url( $data->url ) . '" alt="' . esc_attr($title) . '" width="' . esc_attr($data->width) . '" height="' . esc_attr($data->height) . '" /></a>'; 672 } 673 674 $title = ! empty( $data->title ) && is_string( $data->title ) ? $data->title : ''; 675 $return = '<a href="' . esc_url( $url ) . '"><img src="' . esc_url( $data->url ) . '" alt="' . esc_attr( $title ) . '" width="' . esc_attr( $data->width ) . '" height="' . esc_attr( $data->height ) . '" /></a>'; 658 676 break; 659 677 660 678 case 'video': 661 679 case 'rich': 662 if ( ! empty( $data->html ) && is_string( $data->html ) ) 680 if ( ! empty( $data->html ) && is_string( $data->html ) ) { 663 681 $return = $data->html; 682 } 664 683 break; 665 684 666 685 case 'link': 667 if ( ! empty( $data->title ) && is_string( $data->title ) ) 686 if ( ! empty( $data->title ) && is_string( $data->title ) ) { 668 687 $return = '<a href="' . esc_url( $url ) . '">' . esc_html( $data->title ) . '</a>'; 688 } 669 689 break; 670 690 … … 703 723 } 704 724 705 $count = 1;706 $found = array();707 $token = '__PRE__';708 $search = array( "\t", "\n", "\r", ' ' );709 $replace = array( '__TAB__', '__NL__', '__CR__', '__SPACE__' );725 $count = 1; 726 $found = array(); 727 $token = '__PRE__'; 728 $search = array( "\t", "\n", "\r", ' ' ); 729 $replace = array( '__TAB__', '__NL__', '__CR__', '__SPACE__' ); 710 730 $tokenized = str_replace( $search, $replace, $html ); 711 731 712 732 preg_match_all( '#(<pre[^>]*>.+?</pre>)#i', $tokenized, $matches, PREG_SET_ORDER ); 713 733 foreach ( $matches as $i => $match ) { 714 $tag_html = str_replace( $replace, $search, $match[0] );734 $tag_html = str_replace( $replace, $search, $match[0] ); 715 735 $tag_token = $token . $i; 716 736 717 737 $found[ $tag_token ] = $tag_html; 718 $html = str_replace( $tag_html, $tag_token, $html, $count );738 $html = str_replace( $tag_html, $tag_token, $html, $count ); 719 739 } 720 740 721 741 $replaced = str_replace( $replace, $search, $html ); 722 742 $stripped = str_replace( array( "\r\n", "\n" ), '', $replaced ); 723 $pre = array_values( $found );724 $tokens = array_keys( $found );743 $pre = array_values( $found ); 744 $tokens = array_keys( $found ); 725 745 726 746 return str_replace( $tokens, $pre, $stripped );
Note: See TracChangeset
for help on using the changeset viewer.