wp/wp-includes/class-oembed.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
     1 <?php
     1 <?php
     2 /**
     2 /**
     3  * API for fetching the HTML to embed remote content based on a provided URL.
     3  * API for fetching the HTML to embed remote content based on a provided URL
     4  * Used internally by the {@link WP_Embed} class, but is designed to be generic.
     4  *
       
     5  * Used internally by the WP_Embed class, but is designed to be generic.
     5  *
     6  *
     6  * @link https://codex.wordpress.org/oEmbed oEmbed Codex Article
     7  * @link https://codex.wordpress.org/oEmbed oEmbed Codex Article
     7  * @link http://oembed.com/ oEmbed Homepage
     8  * @link http://oembed.com/ oEmbed Homepage
     8  *
     9  *
     9  * @package WordPress
    10  * @package WordPress
    10  * @subpackage oEmbed
    11  * @subpackage oEmbed
    11  */
    12  */
    12 
    13 
    13 /**
    14 /**
    14  * oEmbed class.
    15  * Core class used to implement oEmbed functionality.
    15  *
    16  *
    16  * @package WordPress
       
    17  * @subpackage oEmbed
       
    18  * @since 2.9.0
    17  * @since 2.9.0
    19  */
    18  */
    20 class WP_oEmbed {
    19 class WP_oEmbed {
       
    20 
       
    21 	/**
       
    22 	 * A list of oEmbed providers.
       
    23 	 *
       
    24 	 * @since 2.9.0
       
    25 	 * @var array
       
    26 	 */
    21 	public $providers = array();
    27 	public $providers = array();
       
    28 
       
    29 	/**
       
    30 	 * A list of an early oEmbed providers.
       
    31 	 *
       
    32 	 * @since 4.0.0
       
    33 	 * @static
       
    34 	 * @var array
       
    35 	 */
    22 	public static $early_providers = array();
    36 	public static $early_providers = array();
    23 
    37 
    24 	private $compat_methods = array( '_fetch_with_format', '_parse_json', '_parse_xml', '_parse_body' );
    38 	/**
    25 
    39 	 * A list of private/protected methods, used for backward compatibility.
    26 	/**
    40 	 *
    27 	 * Constructor
    41 	 * @since 4.2.0
       
    42 	 * @var array
       
    43 	 */
       
    44 	private $compat_methods = array( '_fetch_with_format', '_parse_json', '_parse_xml', '_parse_xml_body' );
       
    45 
       
    46 	/**
       
    47 	 * Constructor.
    28 	 *
    48 	 *
    29 	 * @since 2.9.0
    49 	 * @since 2.9.0
    30 	 */
    50 	 */
    31 	public function __construct() {
    51 	public function __construct() {
       
    52 		$host = urlencode( home_url() );
    32 		$providers = array(
    53 		$providers = array(
    33 			'#http://(www\.)?youtube\.com/watch.*#i'              => array( 'http://www.youtube.com/oembed',                      true  ),
    54 			'#https?://((m|www)\.)?youtube\.com/watch.*#i'                        => array( 'https://www.youtube.com/oembed',                        true  ),
    34 			'#https://(www\.)?youtube\.com/watch.*#i'             => array( 'http://www.youtube.com/oembed?scheme=https',         true  ),
    55 			'#https?://((m|www)\.)?youtube\.com/playlist.*#i'                     => array( 'https://www.youtube.com/oembed',                        true  ),
    35 			'#http://(www\.)?youtube\.com/playlist.*#i'           => array( 'http://www.youtube.com/oembed',                      true  ),
    56 			'#https?://youtu\.be/.*#i'                                            => array( 'https://www.youtube.com/oembed',                        true  ),
    36 			'#https://(www\.)?youtube\.com/playlist.*#i'          => array( 'http://www.youtube.com/oembed?scheme=https',         true  ),
    57 			'#https?://(.+\.)?vimeo\.com/.*#i'                                    => array( 'https://vimeo.com/api/oembed.{format}',                 true  ),
    37 			'#http://youtu\.be/.*#i'                              => array( 'http://www.youtube.com/oembed',                      true  ),
    58 			'#https?://(www\.)?dailymotion\.com/.*#i'                             => array( 'https://www.dailymotion.com/services/oembed',           true  ),
    38 			'#https://youtu\.be/.*#i'                             => array( 'http://www.youtube.com/oembed?scheme=https',         true  ),
    59 			'#https?://dai\.ly/.*#i'                                              => array( 'https://www.dailymotion.com/services/oembed',           true  ),
    39 			'http://blip.tv/*'                                    => array( 'http://blip.tv/oembed/',                             false ),
    60 			'#https?://(www\.)?flickr\.com/.*#i'                                  => array( 'https://www.flickr.com/services/oembed/',               true  ),
    40 			'#https?://(.+\.)?vimeo\.com/.*#i'                    => array( 'http://vimeo.com/api/oembed.{format}',               true  ),
    61 			'#https?://flic\.kr/.*#i'                                             => array( 'https://www.flickr.com/services/oembed/',               true  ),
    41 			'#https?://(www\.)?dailymotion\.com/.*#i'             => array( 'http://www.dailymotion.com/services/oembed',         true  ),
    62 			'#https?://(.+\.)?smugmug\.com/.*#i'                                  => array( 'https://api.smugmug.com/services/oembed/',              true  ),
    42 			'http://dai.ly/*'                                     => array( 'http://www.dailymotion.com/services/oembed',         false ),
    63 			'#https?://(www\.)?hulu\.com/watch/.*#i'                              => array( 'http://www.hulu.com/api/oembed.{format}',               true  ),
    43 			'#https?://(www\.)?flickr\.com/.*#i'                  => array( 'https://www.flickr.com/services/oembed/',            true  ),
    64 			'http://i*.photobucket.com/albums/*'                                  => array( 'http://api.photobucket.com/oembed',                     false ),
    44 			'#https?://flic\.kr/.*#i'                             => array( 'https://www.flickr.com/services/oembed/',            true  ),
    65 			'http://gi*.photobucket.com/groups/*'                                 => array( 'http://api.photobucket.com/oembed',                     false ),
    45 			'#https?://(.+\.)?smugmug\.com/.*#i'                  => array( 'http://api.smugmug.com/services/oembed/',            true  ),
    66 			'#https?://(www\.)?scribd\.com/doc/.*#i'                              => array( 'https://www.scribd.com/services/oembed',                true  ),
    46 			'#https?://(www\.)?hulu\.com/watch/.*#i'              => array( 'http://www.hulu.com/api/oembed.{format}',            true  ),
    67 			'#https?://wordpress\.tv/.*#i'                                        => array( 'https://wordpress.tv/oembed/',                          true  ),
    47 			'http://i*.photobucket.com/albums/*'                  => array( 'http://photobucket.com/oembed',                      false ),
    68 			'#https?://(.+\.)?polldaddy\.com/.*#i'                                => array( 'https://polldaddy.com/oembed/',                         true  ),
    48 			'http://gi*.photobucket.com/groups/*'                 => array( 'http://photobucket.com/oembed',                      false ),
    69 			'#https?://poll\.fm/.*#i'                                             => array( 'https://polldaddy.com/oembed/',                         true  ),
    49 			'#https?://(www\.)?scribd\.com/doc/.*#i'              => array( 'http://www.scribd.com/services/oembed',              true  ),
    70 			'#https?://(www\.)?funnyordie\.com/videos/.*#i'                       => array( 'http://www.funnyordie.com/oembed',                      true  ),
    50 			'#https?://wordpress.tv/.*#i'                         => array( 'http://wordpress.tv/oembed/',                        true  ),
    71 			'#https?://(www\.)?twitter\.com/\w{1,15}/status(es)?/.*#i'            => array( 'https://publish.twitter.com/oembed',                    true  ),
    51 			'#https?://(.+\.)?polldaddy\.com/.*#i'                => array( 'https://polldaddy.com/oembed/',                      true  ),
    72 			'#https?://(www\.)?twitter\.com/\w{1,15}$#i'                          => array( 'https://publish.twitter.com/oembed',                    true  ),
    52 			'#https?://poll\.fm/.*#i'                             => array( 'https://polldaddy.com/oembed/',                      true  ),
    73 			'#https?://(www\.)?twitter\.com/\w{1,15}/likes$#i'                    => array( 'https://publish.twitter.com/oembed',                    true  ),
    53 			'#https?://(www\.)?funnyordie\.com/videos/.*#i'       => array( 'http://www.funnyordie.com/oembed',                   true  ),
    74 			'#https?://(www\.)?twitter\.com/\w{1,15}/lists/.*#i'                  => array( 'https://publish.twitter.com/oembed',                    true  ),
    54 			'#https?://(www\.)?twitter\.com/.+?/status(es)?/.*#i' => array( 'https://api.twitter.com/1/statuses/oembed.{format}', true  ),
    75 			'#https?://(www\.)?twitter\.com/\w{1,15}/timelines/.*#i'              => array( 'https://publish.twitter.com/oembed',                    true  ),
    55 			'#https?://vine.co/v/.*#i'                            => array( 'https://vine.co/oembed.{format}',                    true  ),
    76 			'#https?://(www\.)?twitter\.com/i/moments/.*#i'                       => array( 'https://publish.twitter.com/oembed',                    true  ),
    56  			'#https?://(www\.)?soundcloud\.com/.*#i'              => array( 'http://soundcloud.com/oembed',                       true  ),
    77 			'#https?://(www\.)?soundcloud\.com/.*#i'                              => array( 'https://soundcloud.com/oembed',                         true  ),
    57 			'#https?://(.+?\.)?slideshare\.net/.*#i'              => array( 'https://www.slideshare.net/api/oembed/2',            true  ),
    78 			'#https?://(.+?\.)?slideshare\.net/.*#i'                              => array( 'https://www.slideshare.net/api/oembed/2',               true  ),
    58 			'#https?://instagr(\.am|am\.com)/p/.*#i'              => array( 'https://api.instagram.com/oembed',                   true  ),
    79 			'#https?://(www\.)?instagr(\.am|am\.com)/p/.*#i'                      => array( 'https://api.instagram.com/oembed',                      true  ),
    59 			'#https?://(www\.)?rdio\.com/.*#i'                    => array( 'http://www.rdio.com/api/oembed/',                    true  ),
    80 			'#https?://(open|play)\.spotify\.com/.*#i'                            => array( 'https://embed.spotify.com/oembed/',                     true  ),
    60 			'#https?://rd\.io/x/.*#i'                             => array( 'http://www.rdio.com/api/oembed/',                    true  ),
    81 			'#https?://(.+\.)?imgur\.com/.*#i'                                    => array( 'https://api.imgur.com/oembed',                          true  ),
    61 			'#https?://(open|play)\.spotify\.com/.*#i'            => array( 'https://embed.spotify.com/oembed/',                  true  ),
    82 			'#https?://(www\.)?meetu(\.ps|p\.com)/.*#i'                           => array( 'https://api.meetup.com/oembed',                         true  ),
    62 			'#https?://(.+\.)?imgur\.com/.*#i'                    => array( 'http://api.imgur.com/oembed',                        true  ),
    83 			'#https?://(www\.)?issuu\.com/.+/docs/.+#i'                           => array( 'https://issuu.com/oembed_wp',                           true  ),
    63 			'#https?://(www\.)?meetu(\.ps|p\.com)/.*#i'           => array( 'http://api.meetup.com/oembed',                       true  ),
    84 			'#https?://(www\.)?collegehumor\.com/video/.*#i'                      => array( 'https://www.collegehumor.com/oembed.{format}',          true  ),
    64 			'#https?://(www\.)?issuu\.com/.+/docs/.+#i'           => array( 'http://issuu.com/oembed_wp',                         true  ),
    85 			'#https?://(www\.)?mixcloud\.com/.*#i'                                => array( 'https://www.mixcloud.com/oembed',                       true  ),
    65 			'#https?://(www\.)?collegehumor\.com/video/.*#i'      => array( 'http://www.collegehumor.com/oembed.{format}',        true  ),
    86 			'#https?://(www\.|embed\.)?ted\.com/talks/.*#i'                       => array( 'https://www.ted.com/services/v1/oembed.{format}',       true  ),
    66 			'#https?://(www\.)?mixcloud\.com/.*#i'                => array( 'http://www.mixcloud.com/oembed',                     true  ),
    87 			'#https?://(www\.)?(animoto|video214)\.com/play/.*#i'                 => array( 'https://animoto.com/oembeds/create',                    true  ),
    67 			'#https?://(www\.|embed\.)?ted\.com/talks/.*#i'       => array( 'http://www.ted.com/talks/oembed.{format}',           true  ),
    88 			'#https?://(.+)\.tumblr\.com/post/.*#i'                               => array( 'https://www.tumblr.com/oembed/1.0',                     true  ),
    68 			'#https?://(www\.)?(animoto|video214)\.com/play/.*#i' => array( 'http://animoto.com/oembeds/create',                  true  ),
    89 			'#https?://(www\.)?kickstarter\.com/projects/.*#i'                    => array( 'https://www.kickstarter.com/services/oembed',           true  ),
    69 			'#https?://(.+)\.tumblr\.com/post/.*#i'               => array( 'https://www.tumblr.com/oembed/1.0',                  true  ),
    90 			'#https?://kck\.st/.*#i'                                              => array( 'https://www.kickstarter.com/services/oembed',           true  ),
    70 			'#https?://(www\.)?kickstarter\.com/projects/.*#i'    => array( 'https://www.kickstarter.com/services/oembed',        true  ),
    91 			'#https?://cloudup\.com/.*#i'                                         => array( 'https://cloudup.com/oembed',                            true  ),
    71 			'#https?://kck\.st/.*#i'                              => array( 'https://www.kickstarter.com/services/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  ),
    72 		);
   120 		);
    73 
   121 
    74 		if ( ! empty( self::$early_providers['add'] ) ) {
   122 		if ( ! empty( self::$early_providers['add'] ) ) {
    75 			foreach ( self::$early_providers['add'] as $format => $data ) {
   123 			foreach ( self::$early_providers['add'] as $format => $data ) {
    76 				$providers[ $format ] = $data;
   124 				$providers[ $format ] = $data;
    84 		}
   132 		}
    85 
   133 
    86 		self::$early_providers = array();
   134 		self::$early_providers = array();
    87 
   135 
    88 		/**
   136 		/**
    89 		 * Filter the list of oEmbed providers.
   137 		 * Filters the list of whitelisted oEmbed providers.
    90 		 *
   138 		 *
    91 		 * Discovery is disabled for users lacking the unfiltered_html capability.
   139 		 * Since WordPress 4.4, oEmbed discovery is enabled for all users and allows embedding of sanitized
    92 		 * Only providers in this array will be used for those users.
   140 		 * iframes. The providers in this list are whitelisted, meaning they are trusted and allowed to
       
   141 		 * embed any content, such as iframes, videos, JavaScript, and arbitrary HTML.
    93 		 *
   142 		 *
    94 		 * Supported providers:
   143 		 * Supported providers:
    95 		 *
   144 		 *
    96 		 * | ------------ | -------------------- | ----- | --------- |
   145 		 * |   Provider   |              Flavor               | Supports HTTPS |  Since  |
    97 		 * |   Provider   |        Flavor        |  SSL  |   Since   |
   146 		 * | ------------ | --------------------------------- | :------------: | ------- |
    98 		 * | ------------ | -------------------- | ----- | --------- |
   147 		 * | Dailymotion  | dailymotion.com                   |      Yes       | 2.9.0   |
    99 		 * | Blip         | blip.tv              |   !   | 2.9.0     |
   148 		 * | Flickr       | flickr.com                        |      Yes       | 2.9.0   |
   100 		 * | Dailymotion  | dailymotion.com      |  Yes  | 2.9.0     |
   149 		 * | Hulu         | hulu.com                          |      Yes       | 2.9.0   |
   101 		 * | Flickr       | flickr.com           |  Yes  | 2.9.0     |
   150 		 * | Photobucket  | photobucket.com                   |      No        | 2.9.0   |
   102 		 * | Hulu         | hulu.com             |  Yes  | 2.9.0     |
   151 		 * | Scribd       | scribd.com                        |      Yes       | 2.9.0   |
   103 		 * | Photobucket  | photobucket.com      |   !   | 2.9.0     |
   152 		 * | Vimeo        | vimeo.com                         |      Yes       | 2.9.0   |
   104 		 * | Scribd       | scribd.com           |  Yes  | 2.9.0     |
   153 		 * | WordPress.tv | wordpress.tv                      |      Yes       | 2.9.0   |
   105 		 * | Vimeo        | vimeo.com            |  Yes  | 2.9.0     |
   154 		 * | YouTube      | youtube.com/watch                 |      Yes       | 2.9.0   |
   106 		 * | WordPress.tv | wordpress.tv         |  Yes  | 2.9.0     |
   155 		 * | Funny or Die | funnyordie.com                    |      Yes       | 3.0.0   |
   107 		 * | YouTube      | youtube.com/watch    |  Yes  | 2.9.0     |
   156 		 * | Polldaddy    | polldaddy.com                     |      Yes       | 3.0.0   |
   108 		 * | ------------ | -------------------- | ----- | --------- |
   157 		 * | SmugMug      | smugmug.com                       |      Yes       | 3.0.0   |
   109 		 * | Funny or Die | funnyordie.com       |  Yes  | 3.0.0     |
   158 		 * | YouTube      | youtu.be                          |      Yes       | 3.0.0   |
   110 		 * | Polldaddy    | polldaddy.com        |  Yes  | 3.0.0     |
   159 		 * | Twitter      | twitter.com                       |      Yes       | 3.4.0   |
   111 		 * | SmugMug      | smugmug.com          |  Yes  | 3.0.0     |
   160 		 * | Instagram    | instagram.com                     |      Yes       | 3.5.0   |
   112 		 * | YouTube      | youtu.be             |  Yes  | 3.0.0     |
   161 		 * | Instagram    | instagr.am                        |      Yes       | 3.5.0   |
   113 		 * | ------------ | -------------------- | ----- | --------- |
   162 		 * | Slideshare   | slideshare.net                    |      Yes       | 3.5.0   |
   114 		 * | Twitter      | twitter.com          |  Yes  | 3.4.0     |
   163 		 * | SoundCloud   | soundcloud.com                    |      Yes       | 3.5.0   |
   115 		 * | ------------ | -------------------- | ----- | --------- |
   164 		 * | Dailymotion  | dai.ly                            |      Yes       | 3.6.0   |
   116 		 * | Instagram    | instagram.com        |  Yes  | 3.5.0     |
   165 		 * | Flickr       | flic.kr                           |      Yes       | 3.6.0   |
   117 		 * | Instagram    | instagr.am           |  Yes  | 3.5.0     |
   166 		 * | Spotify      | spotify.com                       |      Yes       | 3.6.0   |
   118 		 * | Slideshare   | slideshare.net       |  Yes  | 3.5.0     |
   167 		 * | Imgur        | imgur.com                         |      Yes       | 3.9.0   |
   119 		 * | SoundCloud   | soundcloud.com       |  Yes  | 3.5.0     |
   168 		 * | Meetup.com   | meetup.com                        |      Yes       | 3.9.0   |
   120 		 * | ------------ | -------------------- | ----- | --------- |
   169 		 * | Meetup.com   | meetu.ps                          |      Yes       | 3.9.0   |
   121 		 * | Dailymotion  | dai.ly               |   !   | 3.6.0     |
   170 		 * | Animoto      | animoto.com                       |      Yes       | 4.0.0   |
   122 		 * | Flickr       | flic.kr              |  Yes  | 3.6.0     |
   171 		 * | Animoto      | video214.com                      |      Yes       | 4.0.0   |
   123 		 * | Rdio         | rdio.com             |  Yes  | 3.6.0     |
   172 		 * | CollegeHumor | collegehumor.com                  |      Yes       | 4.0.0   |
   124 		 * | Rdio         | rd.io                |  Yes  | 3.6.0     |
   173 		 * | Issuu        | issuu.com                         |      Yes       | 4.0.0   |
   125 		 * | Spotify      | spotify.com          |  Yes  | 3.6.0     |
   174 		 * | Mixcloud     | mixcloud.com                      |      Yes       | 4.0.0   |
   126 		 * | ------------ | -------------------- | ----- | --------- |
   175 		 * | Polldaddy    | poll.fm                           |      Yes       | 4.0.0   |
   127 		 * | Imgur        | imgur.com            |  Yes  | 3.9.0     |
   176 		 * | TED          | ted.com                           |      Yes       | 4.0.0   |
   128 		 * | Meetup.com   | meetup.com           |  Yes  | 3.9.0     |
   177 		 * | YouTube      | youtube.com/playlist              |      Yes       | 4.0.0   |
   129 		 * | Meetup.com   | meetu.ps             |  Yes  | 3.9.0     |
   178 		 * | Tumblr       | tumblr.com                        |      Yes       | 4.2.0   |
   130 		 * | ------------ | -------------------- | ----- | --------- |
   179 		 * | Kickstarter  | kickstarter.com                   |      Yes       | 4.2.0   |
   131 		 * | Animoto      | animoto.com          |  Yes  | 4.0.0     |
   180 		 * | Kickstarter  | kck.st                            |      Yes       | 4.2.0   |
   132 		 * | Animoto      | video214.com         |  Yes  | 4.0.0     |
   181 		 * | Cloudup      | cloudup.com                       |      Yes       | 4.3.0   |
   133 		 * | CollegeHumor | collegehumor.com     |  Yes  | 4.0.0     |
   182 		 * | ReverbNation | reverbnation.com                  |      Yes       | 4.4.0   |
   134 		 * | Issuu        | issuu.com            |  Yes  | 4.0.0     |
   183 		 * | VideoPress   | videopress.com                    |      Yes       | 4.4.0   |
   135 		 * | Mixcloud     | mixcloud.com         |  Yes  | 4.0.0     |
   184 		 * | Reddit       | reddit.com                        |      Yes       | 4.4.0   |
   136 		 * | Polldaddy    | poll.fm              |  Yes  | 4.0.0     |
   185 		 * | Speaker Deck | speakerdeck.com                   |      Yes       | 4.4.0   |
   137 		 * | TED          | ted.com              |  Yes  | 4.0.0     |
   186 		 * | Twitter      | twitter.com/timelines             |      Yes       | 4.5.0   |
   138 		 * | YouTube      | youtube.com/playlist |  Yes  | 4.0.0     |
   187 		 * | Twitter      | twitter.com/moments               |      Yes       | 4.5.0   |
   139 		 * | ------------ | -------------------- | ----- | --------- |
   188 		 * | Facebook     | facebook.com                      |      Yes       | 4.7.0   |
   140 		 * | Vine         | vine.co              |  Yes  | 4.1.0     |
   189 		 * | Twitter      | twitter.com/user                  |      Yes       | 4.7.0   |
   141 		 * | ------------ | -------------------- | ----- | --------- |
   190 		 * | Twitter      | twitter.com/likes                 |      Yes       | 4.7.0   |
   142 		 * | Tumblr       | tumblr.com           |  Yes  | 4.2.0     |
   191 		 * | Twitter      | twitter.com/lists                 |      Yes       | 4.7.0   |
   143 		 * | Kickstarter  | kickstarter.com      |  Yes  | 4.2.0     |
   192 		 * | Screencast   | screencast.com                    |      Yes       | 4.8.0   |
   144 		 * | Kickstarter  | kck.st               |  Yes  | 4.2.0     |
   193 		 * | Amazon       | amazon.com|com.mx|com.br|ca       |      Yes       | 4.9.0   |
   145 		 * | ------------ | -------------------- | ----- | --------- |
   194 		 * | Amazon       | amazon.de|fr|it|es|in|nl|ru|co.uk |      Yes       | 4.9.0   |
       
   195 		 * | Amazon       | amazon.co.jp|com.au               |      Yes       | 4.9.0   |
       
   196 		 * | Amazon       | amazon.cn                         |      Yes       | 4.9.0   |
       
   197 		 * | Amazon       | a.co                              |      Yes       | 4.9.0   |
       
   198 		 * | Amazon       | amzn.to|eu|in|asia                |      Yes       | 4.9.0   |
       
   199 		 * | Amazon       | z.cn                              |      Yes       | 4.9.0   |
       
   200 		 * | Someecards   | someecards.com                    |      Yes       | 4.9.0   |
       
   201 		 * | Someecards   | some.ly                           |      Yes       | 4.9.0   |
   146 		 *
   202 		 *
   147 		 * No longer supported providers:
   203 		 * No longer supported providers:
   148 		 *
   204 		 *
   149 		 * | ------------ | -------------------- | ----- | --------- | --------- |
   205 		 * |   Provider   |        Flavor        | Supports HTTPS |   Since   |  Removed  |
   150 		 * |   Provider   |        Flavor        |  SSL  |   Since   |  Removed  |
   206 		 * | ------------ | -------------------- | :------------: | --------- | --------- |
   151 		 * | ------------ | -------------------- | ----- | --------- | --------- |
   207 		 * | Qik          | qik.com              |      Yes       | 2.9.0     | 3.9.0     |
   152 		 * | Qik          | qik.com              |  Yes  | 2.9.0     | 3.9.0     |
   208 		 * | Viddler      | viddler.com          |      Yes       | 2.9.0     | 4.0.0     |
   153 		 * | ------------ | -------------------- | ----- | --------- | --------- |
   209 		 * | Revision3    | revision3.com        |      No        | 2.9.0     | 4.2.0     |
   154 		 * | Viddler      | viddler.com          |  Yes  | 2.9.0     | 4.0.0     |
   210 		 * | Blip         | blip.tv              |      No        | 2.9.0     | 4.4.0     |
   155 		 * | ------------ | -------------------- | ----- | --------- | --------- |
   211 		 * | Rdio         | rdio.com             |      Yes       | 3.6.0     | 4.4.1     |
   156 		 * | Revision3    | revision3.com        |   !   | 2.9.0     | 4.2.0     |
   212 		 * | Rdio         | rd.io                |      Yes       | 3.6.0     | 4.4.1     |
   157 		 * | ------------ | -------------------- | ----- | --------- | --------- |
   213 		 * | Vine         | vine.co              |      Yes       | 4.1.0     | 4.9.0     |
   158 		 *
   214 		 *
   159 		 * @see wp_oembed_add_provider()
   215 		 * @see wp_oembed_add_provider()
   160 		 *
   216 		 *
   161 		 * @since 2.9.0
   217 		 * @since 2.9.0
   162 		 *
   218 		 *
   167 		// Fix any embeds that contain new lines in the middle of the HTML which breaks wpautop().
   223 		// Fix any embeds that contain new lines in the middle of the HTML which breaks wpautop().
   168 		add_filter( 'oembed_dataparse', array($this, '_strip_newlines'), 10, 3 );
   224 		add_filter( 'oembed_dataparse', array($this, '_strip_newlines'), 10, 3 );
   169 	}
   225 	}
   170 
   226 
   171 	/**
   227 	/**
   172 	 * Make private/protected methods readable for backwards compatibility.
   228 	 * Exposes private/protected methods for backward compatibility.
   173 	 *
   229 	 *
   174 	 * @since 4.0.0
   230 	 * @since 4.0.0
   175 	 * @access public
       
   176 	 *
   231 	 *
   177 	 * @param callable $name      Method to call.
   232 	 * @param callable $name      Method to call.
   178 	 * @param array    $arguments Arguments to pass when calling.
   233 	 * @param array    $arguments Arguments to pass when calling.
   179 	 * @return mixed|bool Return value of the callback, false otherwise.
   234 	 * @return mixed|bool Return value of the callback, false otherwise.
   180 	 */
   235 	 */
   187 
   242 
   188 	/**
   243 	/**
   189 	 * Takes a URL and returns the corresponding oEmbed provider's URL, if there is one.
   244 	 * Takes a URL and returns the corresponding oEmbed provider's URL, if there is one.
   190 	 *
   245 	 *
   191 	 * @since 4.0.0
   246 	 * @since 4.0.0
   192 	 * @access public
       
   193 	 *
   247 	 *
   194 	 * @see WP_oEmbed::discover()
   248 	 * @see WP_oEmbed::discover()
   195 	 *
   249 	 *
   196 	 * @param string        $url  The URL to the content.
   250 	 * @param string        $url  The URL to the content.
   197 	 * @param string|array  $args Optional provider arguments.
   251 	 * @param string|array  $args Optional provider arguments.
   198 	 * @return bool|string False on failure, otherwise the oEmbed provider URL.
   252 	 * @return false|string False on failure, otherwise the oEmbed provider URL.
   199 	 */
   253 	 */
   200 	public function get_provider( $url, $args = '' ) {
   254 	public function get_provider( $url, $args = '' ) {
       
   255 		$args = wp_parse_args( $args );
   201 
   256 
   202 		$provider = false;
   257 		$provider = false;
   203 
   258 
   204 		if ( !isset($args['discover']) )
   259 		if ( !isset($args['discover']) )
   205 			$args['discover'] = true;
   260 			$args['discover'] = true;
   224 
   279 
   225 		return $provider;
   280 		return $provider;
   226 	}
   281 	}
   227 
   282 
   228 	/**
   283 	/**
   229 	 * Add an oEmbed provider just-in-time when wp_oembed_add_provider() is called
   284 	 * Adds an oEmbed provider.
   230 	 * before the 'plugins_loaded' hook.
   285 	 *
   231 	 *
   286 	 * The provider is added just-in-time when wp_oembed_add_provider() is called before
   232 	 * The just-in-time addition is for the benefit of the 'oembed_providers' filter.
   287 	 * the {@see 'plugins_loaded'} hook.
   233 	 *
   288 	 *
       
   289 	 * The just-in-time addition is for the benefit of the {@see 'oembed_providers'} filter.
       
   290 	 *
       
   291 	 * @static
   234 	 * @since 4.0.0
   292 	 * @since 4.0.0
   235 	 * @access public
       
   236 	 * @static
       
   237 	 *
   293 	 *
   238 	 * @see wp_oembed_add_provider()
   294 	 * @see wp_oembed_add_provider()
   239 	 *
   295 	 *
   240 	 * @param string $format   Format of URL that this provider can handle. You can use
   296 	 * @param string $format   Format of URL that this provider can handle. You can use
   241 	 *                         asterisks as wildcards.
   297 	 *                         asterisks as wildcards.
   250 
   306 
   251 		self::$early_providers['add'][ $format ] = array( $provider, $regex );
   307 		self::$early_providers['add'][ $format ] = array( $provider, $regex );
   252 	}
   308 	}
   253 
   309 
   254 	/**
   310 	/**
   255 	 * Remove an oEmbed provider just-in-time when wp_oembed_remove_provider() is called
   311 	 * Removes an oEmbed provider.
   256 	 * before the 'plugins_loaded' hook.
   312 	 *
   257 	 *
   313 	 * The provider is removed just-in-time when wp_oembed_remove_provider() is called before
   258 	 * The just-in-time removal is for the benefit of the 'oembed_providers' filter.
   314 	 * the {@see 'plugins_loaded'} hook.
       
   315 	 *
       
   316 	 * The just-in-time removal is for the benefit of the {@see 'oembed_providers'} filter.
   259 	 *
   317 	 *
   260 	 * @since 4.0.0
   318 	 * @since 4.0.0
   261 	 * @access public
       
   262 	 * @static
   319 	 * @static
   263 	 *
   320 	 *
   264 	 * @see wp_oembed_remove_provider()
   321 	 * @see wp_oembed_remove_provider()
   265 	 *
   322 	 *
   266 	 * @param string $format The format of URL that this provider can handle. You can use
   323 	 * @param string $format The format of URL that this provider can handle. You can use
   273 
   330 
   274 		self::$early_providers['remove'][] = $format;
   331 		self::$early_providers['remove'][] = $format;
   275 	}
   332 	}
   276 
   333 
   277 	/**
   334 	/**
       
   335 	 * Takes a URL and attempts to return the oEmbed data.
       
   336 	 *
       
   337 	 * @see WP_oEmbed::fetch()
       
   338 	 *
       
   339 	 * @since 4.8.0
       
   340 	 *
       
   341 	 * @param string       $url  The URL to the content that should be attempted to be embedded.
       
   342 	 * @param array|string $args Optional. Arguments, usually passed from a shortcode. Default empty.
       
   343 	 * @return false|object False on failure, otherwise the result in the form of an object.
       
   344 	 */
       
   345 	public function get_data( $url, $args = '' ) {
       
   346 		$args = wp_parse_args( $args );
       
   347 
       
   348 		$provider = $this->get_provider( $url, $args );
       
   349 
       
   350 		if ( ! $provider ) {
       
   351 			return false;
       
   352 		}
       
   353 
       
   354 		$data = $this->fetch( $provider, $url, $args );
       
   355 
       
   356 		if ( false === $data ) {
       
   357 			return false;
       
   358 		}
       
   359 
       
   360 		return $data;
       
   361 	}
       
   362 
       
   363 	/**
   278 	 * The do-it-all function that takes a URL and attempts to return the HTML.
   364 	 * The do-it-all function that takes a URL and attempts to return the HTML.
   279 	 *
   365 	 *
   280 	 * @see WP_oEmbed::fetch()
   366 	 * @see WP_oEmbed::fetch()
   281 	 * @see WP_oEmbed::data2html()
   367 	 * @see WP_oEmbed::data2html()
   282 	 *
   368 	 *
   283 	 * @param string $url The URL to the content that should be attempted to be embedded.
   369 	 * @since 2.9.0
   284 	 * @param array $args Optional arguments. Usually passed from a shortcode.
   370 	 *
       
   371 	 * @param string       $url  The URL to the content that should be attempted to be embedded.
       
   372 	 * @param array|string $args Optional. Arguments, usually passed from a shortcode. Default empty.
   285 	 * @return false|string False on failure, otherwise the UNSANITIZED (and potentially unsafe) HTML that should be used to embed.
   373 	 * @return false|string False on failure, otherwise the UNSANITIZED (and potentially unsafe) HTML that should be used to embed.
   286 	 */
   374 	 */
   287 	public function get_html( $url, $args = '' ) {
   375 	public function get_html( $url, $args = '' ) {
   288 		$provider = $this->get_provider( $url, $args );
       
   289 
       
   290 		if ( !$provider || false === $data = $this->fetch( $provider, $url, $args ) )
       
   291 			return false;
       
   292 
       
   293 		/**
   376 		/**
   294 		 * Filter the HTML returned by the oEmbed provider.
   377 		 * Filters the oEmbed result before any HTTP requests are made.
       
   378 		 *
       
   379 		 * This allows one to short-circuit the default logic, perhaps by
       
   380 		 * replacing it with a routine that is more optimal for your setup.
       
   381 		 *
       
   382 		 * Passing a non-null value to the filter will effectively short-circuit retrieval,
       
   383 		 * returning the passed value instead.
       
   384 		 *
       
   385 		 * @since 4.5.3
       
   386 		 *
       
   387 		 * @param null|string $result The UNSANITIZED (and potentially unsafe) HTML that should be used to embed. Default null.
       
   388 		 * @param string      $url    The URL to the content that should be attempted to be embedded.
       
   389 		 * @param array       $args   Optional. Arguments, usually passed from a shortcode. Default empty.
       
   390 		 */
       
   391 		$pre = apply_filters( 'pre_oembed_result', null, $url, $args );
       
   392 
       
   393 		if ( null !== $pre ) {
       
   394 			return $pre;
       
   395 		}
       
   396 
       
   397 		$data = $this->get_data( $url, $args );
       
   398 
       
   399 		if ( false === $data ) {
       
   400 			return false;
       
   401 		}
       
   402 
       
   403 		/**
       
   404 		 * Filters the HTML returned by the oEmbed provider.
   295 		 *
   405 		 *
   296 		 * @since 2.9.0
   406 		 * @since 2.9.0
   297 		 *
   407 		 *
   298 		 * @param string $data The returned oEmbed HTML.
   408 		 * @param string $data The returned oEmbed HTML.
   299 		 * @param string $url  URL of the content to be embedded.
   409 		 * @param string $url  URL of the content to be embedded.
   303 	}
   413 	}
   304 
   414 
   305 	/**
   415 	/**
   306 	 * Attempts to discover link tags at the given URL for an oEmbed provider.
   416 	 * Attempts to discover link tags at the given URL for an oEmbed provider.
   307 	 *
   417 	 *
       
   418 	 * @since 2.9.0
       
   419 	 *
   308 	 * @param string $url The URL that should be inspected for discovery `<link>` tags.
   420 	 * @param string $url The URL that should be inspected for discovery `<link>` tags.
   309 	 * @return bool|string False on failure, otherwise the oEmbed provider URL.
   421 	 * @return false|string False on failure, otherwise the oEmbed provider URL.
   310 	 */
   422 	 */
   311 	public function discover( $url ) {
   423 	public function discover( $url ) {
   312 		$providers = array();
   424 		$providers = array();
       
   425 		$args = array(
       
   426 			'limit_response_size' => 153600, // 150 KB
       
   427 		);
   313 
   428 
   314 		/**
   429 		/**
   315 		 * Filter oEmbed remote get arguments.
   430 		 * Filters oEmbed remote get arguments.
   316 		 *
   431 		 *
   317 		 * @since 4.0.0
   432 		 * @since 4.0.0
   318 		 *
   433 		 *
   319 		 * @see WP_Http::request()
   434 		 * @see WP_Http::request()
   320 		 *
   435 		 *
   321 		 * @param array  $args oEmbed remote get arguments.
   436 		 * @param array  $args oEmbed remote get arguments.
   322 		 * @param string $url  URL to be inspected.
   437 		 * @param string $url  URL to be inspected.
   323 		 */
   438 		 */
   324 		$args = apply_filters( 'oembed_remote_get_args', array(), $url );
   439 		$args = apply_filters( 'oembed_remote_get_args', $args, $url );
   325 
   440 
   326 		// Fetch URL content
   441 		// Fetch URL content
   327 		$request = wp_safe_remote_get( $url, $args );
   442 		$request = wp_safe_remote_get( $url, $args );
   328 		if ( $html = wp_remote_retrieve_body( $request ) ) {
   443 		if ( $html = wp_remote_retrieve_body( $request ) ) {
   329 
   444 
   330 			/**
   445 			/**
   331 			 * Filter the link types that contain oEmbed provider URLs.
   446 			 * Filters the link types that contain oEmbed provider URLs.
   332 			 *
   447 			 *
   333 			 * @since 2.9.0
   448 			 * @since 2.9.0
   334 			 *
   449 			 *
   335 			 * @param array $format Array of oEmbed link types. Accepts 'application/json+oembed',
   450 			 * @param array $format Array of oEmbed link types. Accepts 'application/json+oembed',
   336 			 *                      'text/xml+oembed', and 'application/xml+oembed' (incorrect,
   451 			 *                      'text/xml+oembed', and 'application/xml+oembed' (incorrect,
   341 				'text/xml+oembed' => 'xml',
   456 				'text/xml+oembed' => 'xml',
   342 				'application/xml+oembed' => 'xml',
   457 				'application/xml+oembed' => 'xml',
   343 			) );
   458 			) );
   344 
   459 
   345 			// Strip <body>
   460 			// Strip <body>
   346 			$html = substr( $html, 0, stripos( $html, '</head>' ) );
   461 			if ( $html_head_end = stripos( $html, '</head>' ) ) {
       
   462 				$html = substr( $html, 0, $html_head_end );
       
   463 			}
   347 
   464 
   348 			// Do a quick check
   465 			// Do a quick check
   349 			$tagfound = false;
   466 			$tagfound = false;
   350 			foreach ( $linktypes as $linktype => $format ) {
   467 			foreach ( $linktypes as $linktype => $format ) {
   351 				if ( stripos($html, $linktype) ) {
   468 				if ( stripos($html, $linktype) ) {
   379 	}
   496 	}
   380 
   497 
   381 	/**
   498 	/**
   382 	 * Connects to a oEmbed provider and returns the result.
   499 	 * Connects to a oEmbed provider and returns the result.
   383 	 *
   500 	 *
   384 	 * @param string $provider The URL to the oEmbed provider.
   501 	 * @since 2.9.0
   385 	 * @param string $url The URL to the content that is desired to be embedded.
   502 	 *
   386 	 * @param array $args Optional arguments. Usually passed from a shortcode.
   503 	 * @param string       $provider The URL to the oEmbed provider.
   387 	 * @return bool|object False on failure, otherwise the result in the form of an object.
   504 	 * @param string       $url      The URL to the content that is desired to be embedded.
       
   505 	 * @param array|string $args     Optional. Arguments, usually passed from a shortcode. Default empty.
       
   506 	 * @return false|object False on failure, otherwise the result in the form of an object.
   388 	 */
   507 	 */
   389 	public function fetch( $provider, $url, $args = '' ) {
   508 	public function fetch( $provider, $url, $args = '' ) {
   390 		$args = wp_parse_args( $args, wp_embed_defaults( $url ) );
   509 		$args = wp_parse_args( $args, wp_embed_defaults( $url ) );
   391 
   510 
   392 		$provider = add_query_arg( 'maxwidth', (int) $args['width'], $provider );
   511 		$provider = add_query_arg( 'maxwidth', (int) $args['width'], $provider );
   393 		$provider = add_query_arg( 'maxheight', (int) $args['height'], $provider );
   512 		$provider = add_query_arg( 'maxheight', (int) $args['height'], $provider );
   394 		$provider = add_query_arg( 'url', urlencode($url), $provider );
   513 		$provider = add_query_arg( 'url', urlencode($url), $provider );
       
   514 		$provider = add_query_arg( 'dnt', 1, $provider );
   395 
   515 
   396 		/**
   516 		/**
   397 		 * Filter the oEmbed URL to be fetched.
   517 		 * Filters the oEmbed URL to be fetched.
   398 		 *
   518 		 *
   399 		 * @since 2.9.0
   519 		 * @since 2.9.0
       
   520 		 * @since 4.9.0 The `dnt` (Do Not Track) query parameter was added to all oEmbed provider URLs.
   400 		 *
   521 		 *
   401 		 * @param string $provider URL of the oEmbed provider.
   522 		 * @param string $provider URL of the oEmbed provider.
   402 		 * @param string $url      URL of the content to be embedded.
   523 		 * @param string $url      URL of the content to be embedded.
   403 		 * @param array  $args     Optional arguments, usually passed from a shortcode.
   524 		 * @param array  $args     Optional arguments, usually passed from a shortcode.
   404 		 */
   525 		 */
   405 		$provider = apply_filters( 'oembed_fetch_url', $provider, $url, $args );
   526 		$provider = apply_filters( 'oembed_fetch_url', $provider, $url, $args );
   406 
   527 
   407 		foreach( array( 'json', 'xml' ) as $format ) {
   528 		foreach ( array( 'json', 'xml' ) as $format ) {
   408 			$result = $this->_fetch_with_format( $provider, $format );
   529 			$result = $this->_fetch_with_format( $provider, $format );
   409 			if ( is_wp_error( $result ) && 'not-implemented' == $result->get_error_code() )
   530 			if ( is_wp_error( $result ) && 'not-implemented' == $result->get_error_code() )
   410 				continue;
   531 				continue;
   411 			return ( $result && ! is_wp_error( $result ) ) ? $result : false;
   532 			return ( $result && ! is_wp_error( $result ) ) ? $result : false;
   412 		}
   533 		}
   415 
   536 
   416 	/**
   537 	/**
   417 	 * Fetches result from an oEmbed provider for a specific format and complete provider URL
   538 	 * Fetches result from an oEmbed provider for a specific format and complete provider URL
   418 	 *
   539 	 *
   419 	 * @since 3.0.0
   540 	 * @since 3.0.0
   420 	 * @access private
   541 	 *
   421 	 * @param string $provider_url_with_args URL to the provider with full arguments list (url, maxheight, etc.)
   542 	 * @param string $provider_url_with_args URL to the provider with full arguments list (url, maxheight, etc.)
   422 	 * @param string $format Format to use
   543 	 * @param string $format Format to use
   423 	 * @return bool|object False on failure, otherwise the result in the form of an object.
   544 	 * @return false|object|WP_Error False on failure, otherwise the result in the form of an object.
   424 	 */
   545 	 */
   425 	private function _fetch_with_format( $provider_url_with_args, $format ) {
   546 	private function _fetch_with_format( $provider_url_with_args, $format ) {
   426 		$provider_url_with_args = add_query_arg( 'format', $format, $provider_url_with_args );
   547 		$provider_url_with_args = add_query_arg( 'format', $format, $provider_url_with_args );
   427 
   548 
   428 		/** This filter is documented in wp-includes/class-oembed.php */
   549 		/** This filter is documented in wp-includes/class-oembed.php */
   439 
   560 
   440 	/**
   561 	/**
   441 	 * Parses a json response body.
   562 	 * Parses a json response body.
   442 	 *
   563 	 *
   443 	 * @since 3.0.0
   564 	 * @since 3.0.0
   444 	 * @access private
   565 	 *
       
   566 	 * @param string $response_body
       
   567 	 * @return object|false
   445 	 */
   568 	 */
   446 	private function _parse_json( $response_body ) {
   569 	private function _parse_json( $response_body ) {
   447 		return ( ( $data = json_decode( trim( $response_body ) ) ) && is_object( $data ) ) ? $data : false;
   570 		$data = json_decode( trim( $response_body ) );
       
   571 		return ( $data && is_object( $data ) ) ? $data : false;
   448 	}
   572 	}
   449 
   573 
   450 	/**
   574 	/**
   451 	 * Parses an XML response body.
   575 	 * Parses an XML response body.
   452 	 *
   576 	 *
   453 	 * @since 3.0.0
   577 	 * @since 3.0.0
   454 	 * @access private
   578 	 *
       
   579 	 * @param string $response_body
       
   580 	 * @return object|false
   455 	 */
   581 	 */
   456 	private function _parse_xml( $response_body ) {
   582 	private function _parse_xml( $response_body ) {
   457 		if ( ! function_exists( 'libxml_disable_entity_loader' ) )
   583 		if ( ! function_exists( 'libxml_disable_entity_loader' ) )
   458 			return false;
   584 			return false;
   459 
   585 
   467 
   593 
   468 		return $return;
   594 		return $return;
   469 	}
   595 	}
   470 
   596 
   471 	/**
   597 	/**
   472 	 * Helper function for parsing an XML response body.
   598 	 * Serves as a helper function for parsing an XML response body.
   473 	 *
   599 	 *
   474 	 * @since 3.6.0
   600 	 * @since 3.6.0
   475 	 * @access private
   601 	 *
       
   602 	 * @param string $response_body
       
   603 	 * @return stdClass|false
   476 	 */
   604 	 */
   477 	private function _parse_xml_body( $response_body ) {
   605 	private function _parse_xml_body( $response_body ) {
   478 		if ( ! function_exists( 'simplexml_import_dom' ) || ! class_exists( 'DOMDocument' ) )
   606 		if ( ! function_exists( 'simplexml_import_dom' ) || ! class_exists( 'DOMDocument', false ) )
   479 			return false;
   607 			return false;
   480 
   608 
   481 		$dom = new DOMDocument;
   609 		$dom = new DOMDocument;
   482 		$success = $dom->loadXML( $response_body );
   610 		$success = $dom->loadXML( $response_body );
   483 		if ( ! $success )
   611 		if ( ! $success )
   502 
   630 
   503 		return $return;
   631 		return $return;
   504 	}
   632 	}
   505 
   633 
   506 	/**
   634 	/**
   507 	 * Converts a data object from {@link WP_oEmbed::fetch()} and returns the HTML.
   635 	 * Converts a data object from WP_oEmbed::fetch() and returns the HTML.
       
   636 	 *
       
   637 	 * @since 2.9.0
   508 	 *
   638 	 *
   509 	 * @param object $data A data object result from an oEmbed provider.
   639 	 * @param object $data A data object result from an oEmbed provider.
   510 	 * @param string $url The URL to the content that is desired to be embedded.
   640 	 * @param string $url The URL to the content that is desired to be embedded.
   511 	 * @return false|string False on error, otherwise the HTML needed to embed.
   641 	 * @return false|string False on error, otherwise the HTML needed to embed.
   512 	 */
   642 	 */
   541 			default:
   671 			default:
   542 				$return = false;
   672 				$return = false;
   543 		}
   673 		}
   544 
   674 
   545 		/**
   675 		/**
   546 		 * Filter the returned oEmbed HTML.
   676 		 * Filters the returned oEmbed HTML.
   547 		 *
   677 		 *
   548 		 * Use this filter to add support for custom data types, or to filter the result.
   678 		 * Use this filter to add support for custom data types, or to filter the result.
   549 		 *
   679 		 *
   550 		 * @since 2.9.0
   680 		 * @since 2.9.0
   551 		 *
   681 		 *
   555 		 */
   685 		 */
   556 		return apply_filters( 'oembed_dataparse', $return, $data, $url );
   686 		return apply_filters( 'oembed_dataparse', $return, $data, $url );
   557 	}
   687 	}
   558 
   688 
   559 	/**
   689 	/**
   560 	 * Strip any new lines from the HTML.
   690 	 * Strips any new lines from the HTML.
   561 	 *
   691 	 *
   562 	 * @access public
   692 	 * @since 2.9.0 as strip_scribd_newlines()
       
   693 	 * @since 3.0.0
       
   694 	 *
   563 	 * @param string $html Existing HTML.
   695 	 * @param string $html Existing HTML.
   564 	 * @param object $data Data object from WP_oEmbed::data2html()
   696 	 * @param object $data Data object from WP_oEmbed::data2html()
   565 	 * @param string $url The original URL passed to oEmbed.
   697 	 * @param string $url The original URL passed to oEmbed.
   566 	 * @return string Possibly modified $html
   698 	 * @return string Possibly modified $html
   567 	 */
   699 	 */
   592 		$tokens = array_keys( $found );
   724 		$tokens = array_keys( $found );
   593 
   725 
   594 		return str_replace( $tokens, $pre, $stripped );
   726 		return str_replace( $tokens, $pre, $stripped );
   595 	}
   727 	}
   596 }
   728 }
   597 
       
   598 /**
       
   599  * Returns the initialized {@link WP_oEmbed} object
       
   600  *
       
   601  * @since 2.9.0
       
   602  * @access private
       
   603  *
       
   604  * @see WP_oEmbed
       
   605  *
       
   606  * @return WP_oEmbed object.
       
   607  */
       
   608 function _wp_oembed_get_object() {
       
   609 	static $wp_oembed;
       
   610 
       
   611 	if ( is_null($wp_oembed) )
       
   612 		$wp_oembed = new WP_oEmbed();
       
   613 
       
   614 	return $wp_oembed;
       
   615 }