]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/class-oembed.php
WordPress 4.1.2
[autoinstalls/wordpress.git] / wp-includes / class-oembed.php
1 <?php
2 /**
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.
5  *
6  * @link http://codex.wordpress.org/oEmbed oEmbed Codex Article
7  * @link http://oembed.com/ oEmbed Homepage
8  *
9  * @package WordPress
10  * @subpackage oEmbed
11  */
12
13 /**
14  * oEmbed class.
15  *
16  * @package WordPress
17  * @subpackage oEmbed
18  * @since 2.9.0
19  */
20 class WP_oEmbed {
21         public $providers = array();
22         public static $early_providers = array();
23
24         /**
25          * Constructor
26          *
27          * @since 2.9.0
28          */
29         public function __construct() {
30                 $providers = array(
31                         '#http://(www\.)?youtube\.com/watch.*#i'              => array( 'http://www.youtube.com/oembed',                      true  ),
32                         '#https://(www\.)?youtube\.com/watch.*#i'             => array( 'http://www.youtube.com/oembed?scheme=https',         true  ),
33                         '#http://(www\.)?youtube\.com/playlist.*#i'           => array( 'http://www.youtube.com/oembed',                      true  ),
34                         '#https://(www\.)?youtube\.com/playlist.*#i'          => array( 'http://www.youtube.com/oembed?scheme=https',         true  ),
35                         '#http://youtu\.be/.*#i'                              => array( 'http://www.youtube.com/oembed',                      true  ),
36                         '#https://youtu\.be/.*#i'                             => array( 'http://www.youtube.com/oembed?scheme=https',         true  ),
37                         'http://blip.tv/*'                                    => array( 'http://blip.tv/oembed/',                             false ),
38                         '#https?://(.+\.)?vimeo\.com/.*#i'                    => array( 'http://vimeo.com/api/oembed.{format}',               true  ),
39                         '#https?://(www\.)?dailymotion\.com/.*#i'             => array( 'http://www.dailymotion.com/services/oembed',         true  ),
40                         'http://dai.ly/*'                                     => array( 'http://www.dailymotion.com/services/oembed',         false ),
41                         '#https?://(www\.)?flickr\.com/.*#i'                  => array( 'https://www.flickr.com/services/oembed/',            true  ),
42                         '#https?://flic\.kr/.*#i'                             => array( 'https://www.flickr.com/services/oembed/',            true  ),
43                         '#https?://(.+\.)?smugmug\.com/.*#i'                  => array( 'http://api.smugmug.com/services/oembed/',            true  ),
44                         '#https?://(www\.)?hulu\.com/watch/.*#i'              => array( 'http://www.hulu.com/api/oembed.{format}',            true  ),
45                         'http://revision3.com/*'                              => array( 'http://revision3.com/api/oembed/',                   false ),
46                         'http://i*.photobucket.com/albums/*'                  => array( 'http://photobucket.com/oembed',                      false ),
47                         'http://gi*.photobucket.com/groups/*'                 => array( 'http://photobucket.com/oembed',                      false ),
48                         '#https?://(www\.)?scribd\.com/doc/.*#i'              => array( 'http://www.scribd.com/services/oembed',              true  ),
49                         '#https?://wordpress.tv/.*#i'                         => array( 'http://wordpress.tv/oembed/',                        true ),
50                         '#https?://(.+\.)?polldaddy\.com/.*#i'                => array( 'https://polldaddy.com/oembed/',                      true  ),
51                         '#https?://poll\.fm/.*#i'                             => array( 'https://polldaddy.com/oembed/',                      true  ),
52                         '#https?://(www\.)?funnyordie\.com/videos/.*#i'       => array( 'http://www.funnyordie.com/oembed',                   true  ),
53                         '#https?://(www\.)?twitter\.com/.+?/status(es)?/.*#i' => array( 'https://api.twitter.com/1/statuses/oembed.{format}', true  ),
54                         '#https?://vine.co/v/.*#i'                            => array( 'https://vine.co/oembed.{format}',                    true  ),
55                         '#https?://(www\.)?soundcloud\.com/.*#i'              => array( 'http://soundcloud.com/oembed',                       true  ),
56                         '#https?://(.+?\.)?slideshare\.net/.*#i'              => array( 'https://www.slideshare.net/api/oembed/2',            true  ),
57                         '#http://instagr(\.am|am\.com)/p/.*#i'                => array( 'http://api.instagram.com/oembed',                    true  ),
58                         '#https?://(www\.)?rdio\.com/.*#i'                    => array( 'http://www.rdio.com/api/oembed/',                    true  ),
59                         '#https?://rd\.io/x/.*#i'                             => array( 'http://www.rdio.com/api/oembed/',                    true  ),
60                         '#https?://(open|play)\.spotify\.com/.*#i'            => array( 'https://embed.spotify.com/oembed/',                  true  ),
61                         '#https?://(.+\.)?imgur\.com/.*#i'                    => array( 'http://api.imgur.com/oembed',                        true  ),
62                         '#https?://(www\.)?meetu(\.ps|p\.com)/.*#i'           => array( 'http://api.meetup.com/oembed',                       true  ),
63                         '#https?://(www\.)?issuu\.com/.+/docs/.+#i'           => array( 'http://issuu.com/oembed_wp',                         true  ),
64                         '#https?://(www\.)?collegehumor\.com/video/.*#i'      => array( 'http://www.collegehumor.com/oembed.{format}',        true  ),
65                         '#https?://(www\.)?mixcloud\.com/.*#i'                => array( 'http://www.mixcloud.com/oembed',                     true  ),
66                         '#https?://(www\.|embed\.)?ted\.com/talks/.*#i'       => array( 'http://www.ted.com/talks/oembed.{format}',           true  ),
67                         '#https?://(www\.)?(animoto|video214)\.com/play/.*#i' => array( 'http://animoto.com/oembeds/create',                  true  ),
68                 );
69
70                 if ( ! empty( self::$early_providers['add'] ) ) {
71                         foreach ( self::$early_providers['add'] as $format => $data ) {
72                                 $providers[ $format ] = $data;
73                         }
74                 }
75
76                 if ( ! empty( self::$early_providers['remove'] ) ) {
77                         foreach ( self::$early_providers['remove'] as $format ) {
78                                 unset( $providers[ $format ] );
79                         }
80                 }
81
82                 self::$early_providers = array();
83
84                 /**
85                  * Filter the list of oEmbed providers.
86                  *
87                  * Discovery is disabled for users lacking the unfiltered_html capability.
88                  * Only providers in this array will be used for those users.
89                  *
90                  * Supported providers:
91                  *
92                  * | ------------ | -------------------- | ----- | --------- |
93                  * |   Provider   |        Flavor        |  SSL  |   Since   |
94                  * | ------------ | -------------------- | ----- | --------- |
95                  * | Blip         | blip.tv              |       | 2.9.0     |
96                  * | Dailymotion  | dailymotion.com      |  Yes  | 2.9.0     |
97                  * | Flickr       | flickr.com           |  Yes  | 2.9.0     |
98                  * | Hulu         | hulu.com             |  Yes  | 2.9.0     |
99                  * | Photobucket  | photobucket.com      |       | 2.9.0     |
100                  * | Revision3    | revision3.com        |       | 2.9.0     |
101                  * | Scribd       | scribd.com           |  Yes  | 2.9.0     |
102                  * | Vimeo        | vimeo.com            |  Yes  | 2.9.0     |
103                  * | WordPress.tv | wordpress.tv         |  Yes  | 2.9.0     |
104                  * | YouTube      | youtube.com/watch    |  Yes  | 2.9.0     |
105                  * | ------------ | -------------------- | ----- | --------- |
106                  * | Funny or Die | funnyordie.com       |  Yes  | 3.0.0     |
107                  * | Polldaddy    | polldaddy.com        |  Yes  | 3.0.0     |
108                  * | SmugMug      | smugmug.com          |  Yes  | 3.0.0     |
109                  * | YouTube      | youtu.be             |  Yes  | 3.0.0     |
110                  * | ------------ | -------------------- | ----- | --------- |
111                  * | Twitter      | twitter.com          |  Yes  | 3.4.0     |
112                  * | ------------ | -------------------- | ----- | --------- |
113                  * | Instagram    | instagram.com        |       | 3.5.0     |
114                  * | Instagram    | instagr.am           |       | 3.5.0     |
115                  * | Slideshare   | slideshare.net       |  Yes  | 3.5.0     |
116                  * | SoundCloud   | soundcloud.com       |  Yes  | 3.5.0     |
117                  * | ------------ | -------------------- | ----- | --------- |
118                  * | Dailymotion  | dai.ly               |       | 3.6.0     |
119                  * | Flickr       | flic.kr              |  Yes  | 3.6.0     |
120                  * | Rdio         | rdio.com             |  Yes  | 3.6.0     |
121                  * | Rdio         | rd.io                |  Yes  | 3.6.0     |
122                  * | Spotify      | spotify.com          |  Yes  | 3.6.0     |
123                  * | ------------ | -------------------- | ----- | --------- |
124                  * | Imgur        | imgur.com            |  Yes  | 3.9.0     |
125                  * | Meetup.com   | meetup.com           |  Yes  | 3.9.0     |
126                  * | Meetup.com   | meetu.ps             |  Yes  | 3.9.0     |
127                  * | ------------ | -------------------- | ----- | --------- |
128                  * | Animoto      | animoto.com          |  Yes  | 4.0.0     |
129                  * | Animoto      | video214.com         |  Yes  | 4.0.0     |
130                  * | CollegeHumor | collegehumor.com     |  Yes  | 4.0.0     |
131                  * | Issuu        | issuu.com            |  Yes  | 4.0.0     |
132                  * | Mixcloud     | mixcloud.com         |  Yes  | 4.0.0     |
133                  * | Polldaddy    | poll.fm              |  Yes  | 4.0.0     |
134                  * | TED          | ted.com              |  Yes  | 4.0.0     |
135                  * | YouTube      | youtube.com/playlist |  Yes  | 4.0.0     |
136                  * | ------------ | -------------------- | ----- | --------- |
137                  * | Vine         | vine.co              |  Yes  | 4.1.0     |
138                  * | ------------ | -------------------- | ----- | --------- |
139                  *
140                  * No longer supported providers:
141                  *
142                  * | ------------ | -------------------- | ----- | --------- | --------- |
143                  * |   Provider   |        Flavor        |  SSL  |   Since   |  Removed  |
144                  * | ------------ | -------------------- | ----- | --------- | --------- |
145                  * | Qik          | qik.com              |  Yes  | 2.9.0     | 3.9.0     |
146                  * | ------------ | -------------------- | ----- | --------- | --------- |
147                  * | Viddler      | viddler.com          |  Yes  | 2.9.0     | 4.0.0     |
148                  * | ------------ | -------------------- | ----- | --------- | --------- |
149                  *
150                  * @see wp_oembed_add_provider()
151                  *
152                  * @since 2.9.0
153                  *
154                  * @param array $providers An array of popular oEmbed providers.
155                  */
156                 $this->providers = apply_filters( 'oembed_providers', $providers );
157
158                 // Fix any embeds that contain new lines in the middle of the HTML which breaks wpautop().
159                 add_filter( 'oembed_dataparse', array($this, '_strip_newlines'), 10, 3 );
160         }
161
162         /**
163          * Make private/protected methods readable for backwards compatibility.
164          *
165          * @since 4.0.0
166          * @access public
167          *
168          * @param callable $name      Method to call.
169          * @param array    $arguments Arguments to pass when calling.
170          * @return mixed|bool Return value of the callback, false otherwise.
171          */
172         public function __call( $name, $arguments ) {
173                 return call_user_func_array( array( $this, $name ), $arguments );
174         }
175
176         /**
177          * Takes a URL and returns the corresponding oEmbed provider's URL, if there is one.
178          *
179          * @since 4.0.0
180          * @access public
181          *
182          * @see WP_oEmbed::discover()
183          *
184          * @param string        $url  The URL to the content.
185          * @param string|array  $args Optional provider arguments.
186          * @return bool|string False on failure, otherwise the oEmbed provider URL.
187          */
188         public function get_provider( $url, $args = '' ) {
189
190                 $provider = false;
191
192                 if ( !isset($args['discover']) )
193                         $args['discover'] = true;
194
195                 foreach ( $this->providers as $matchmask => $data ) {
196                         list( $providerurl, $regex ) = $data;
197
198                         // Turn the asterisk-type provider URLs into regex
199                         if ( !$regex ) {
200                                 $matchmask = '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $matchmask ), '#' ) ) . '#i';
201                                 $matchmask = preg_replace( '|^#http\\\://|', '#https?\://', $matchmask );
202                         }
203
204                         if ( preg_match( $matchmask, $url ) ) {
205                                 $provider = str_replace( '{format}', 'json', $providerurl ); // JSON is easier to deal with than XML
206                                 break;
207                         }
208                 }
209
210                 if ( !$provider && $args['discover'] )
211                         $provider = $this->discover( $url );
212
213                 return $provider;
214         }
215
216         /**
217          * Add an oEmbed provider just-in-time when wp_oembed_add_provider() is called
218          * before the 'plugins_loaded' hook.
219          *
220          * The just-in-time addition is for the benefit of the 'oembed_providers' filter.
221          *
222          * @since 4.0.0
223          * @access public
224          * @static
225          *
226          * @see wp_oembed_add_provider()
227          *
228          * @param string $format   Format of URL that this provider can handle. You can use
229          *                         asterisks as wildcards.
230          * @param string $provider The URL to the oEmbed provider..
231          * @param bool   $regex    Optional. Whether the $format parameter is in a regex format.
232          *                         Default false.
233          */
234         public static function _add_provider_early( $format, $provider, $regex = false ) {
235                 if ( empty( self::$early_providers['add'] ) ) {
236                         self::$early_providers['add'] = array();
237                 }
238
239                 self::$early_providers['add'][ $format ] = array( $provider, $regex );
240         }
241
242         /**
243          * Remove an oEmbed provider just-in-time when wp_oembed_remove_provider() is called
244          * before the 'plugins_loaded' hook.
245          *
246          * The just-in-time removal is for the benefit of the 'oembed_providers' filter.
247          *
248          * @since 4.0.0
249          * @access public
250          * @static
251          *
252          * @see wp_oembed_remove_provider()
253          *
254          * @param string $format The format of URL that this provider can handle. You can use
255          *                       asterisks as wildcards.
256          */
257         public static function _remove_provider_early( $format ) {
258                 if ( empty( self::$early_providers['remove'] ) ) {
259                         self::$early_providers['remove'] = array();
260                 }
261
262                 self::$early_providers['remove'][] = $format;
263         }
264
265         /**
266          * The do-it-all function that takes a URL and attempts to return the HTML.
267          *
268          * @see WP_oEmbed::fetch()
269          * @see WP_oEmbed::data2html()
270          *
271          * @param string $url The URL to the content that should be attempted to be embedded.
272          * @param array $args Optional arguments. Usually passed from a shortcode.
273          * @return false|string False on failure, otherwise the UNSANITIZED (and potentially unsafe) HTML that should be used to embed.
274          */
275         function get_html( $url, $args = '' ) {
276                 $provider = $this->get_provider( $url, $args );
277
278                 if ( !$provider || false === $data = $this->fetch( $provider, $url, $args ) )
279                         return false;
280
281                 /**
282                  * Filter the HTML returned by the oEmbed provider.
283                  *
284                  * @since 2.9.0
285                  *
286                  * @param string $data The returned oEmbed HTML.
287                  * @param string $url  URL of the content to be embedded.
288                  * @param array  $args Optional arguments, usually passed from a shortcode.
289                  */
290                 return apply_filters( 'oembed_result', $this->data2html( $data, $url ), $url, $args );
291         }
292
293         /**
294          * Attempts to discover link tags at the given URL for an oEmbed provider.
295          *
296          * @param string $url The URL that should be inspected for discovery `<link>` tags.
297          * @return bool|string False on failure, otherwise the oEmbed provider URL.
298          */
299         public function discover( $url ) {
300                 $providers = array();
301
302                 /**
303                  * Filter oEmbed remote get arguments.
304                  *
305                  * @since 4.0.0
306                  *
307                  * @see WP_Http::request()
308                  *
309                  * @param array  $args oEmbed remote get arguments.
310                  * @param string $url  URL to be inspected.
311                  */
312                 $args = apply_filters( 'oembed_remote_get_args', array(), $url );
313
314                 // Fetch URL content
315                 $request = wp_safe_remote_get( $url, $args );
316                 if ( $html = wp_remote_retrieve_body( $request ) ) {
317
318                         /**
319                          * Filter the link types that contain oEmbed provider URLs.
320                          *
321                          * @since 2.9.0
322                          *
323                          * @param array $format Array of oEmbed link types. Accepts 'application/json+oembed',
324                          *                      'text/xml+oembed', and 'application/xml+oembed' (incorrect,
325                          *                      used by at least Vimeo).
326                          */
327                         $linktypes = apply_filters( 'oembed_linktypes', array(
328                                 'application/json+oembed' => 'json',
329                                 'text/xml+oembed' => 'xml',
330                                 'application/xml+oembed' => 'xml',
331                         ) );
332
333                         // Strip <body>
334                         $html = substr( $html, 0, stripos( $html, '</head>' ) );
335
336                         // Do a quick check
337                         $tagfound = false;
338                         foreach ( $linktypes as $linktype => $format ) {
339                                 if ( stripos($html, $linktype) ) {
340                                         $tagfound = true;
341                                         break;
342                                 }
343                         }
344
345                         if ( $tagfound && preg_match_all( '/<link([^<>]+)>/i', $html, $links ) ) {
346                                 foreach ( $links[1] as $link ) {
347                                         $atts = shortcode_parse_atts( $link );
348
349                                         if ( !empty($atts['type']) && !empty($linktypes[$atts['type']]) && !empty($atts['href']) ) {
350                                                 $providers[$linktypes[$atts['type']]] = $atts['href'];
351
352                                                 // Stop here if it's JSON (that's all we need)
353                                                 if ( 'json' == $linktypes[$atts['type']] )
354                                                         break;
355                                         }
356                                 }
357                         }
358                 }
359
360                 // JSON is preferred to XML
361                 if ( !empty($providers['json']) )
362                         return $providers['json'];
363                 elseif ( !empty($providers['xml']) )
364                         return $providers['xml'];
365                 else
366                         return false;
367         }
368
369         /**
370          * Connects to a oEmbed provider and returns the result.
371          *
372          * @param string $provider The URL to the oEmbed provider.
373          * @param string $url The URL to the content that is desired to be embedded.
374          * @param array $args Optional arguments. Usually passed from a shortcode.
375          * @return bool|object False on failure, otherwise the result in the form of an object.
376          */
377         public function fetch( $provider, $url, $args = '' ) {
378                 $args = wp_parse_args( $args, wp_embed_defaults( $url ) );
379
380                 $provider = add_query_arg( 'maxwidth', (int) $args['width'], $provider );
381                 $provider = add_query_arg( 'maxheight', (int) $args['height'], $provider );
382                 $provider = add_query_arg( 'url', urlencode($url), $provider );
383
384                 /**
385                  * Filter the oEmbed URL to be fetched.
386                  *
387                  * @since 2.9.0
388                  *
389                  * @param string $provider URL of the oEmbed provider.
390                  * @param string $url      URL of the content to be embedded.
391                  * @param array  $args     Optional arguments, usually passed from a shortcode.
392                  */
393                 $provider = apply_filters( 'oembed_fetch_url', $provider, $url, $args );
394
395                 foreach( array( 'json', 'xml' ) as $format ) {
396                         $result = $this->_fetch_with_format( $provider, $format );
397                         if ( is_wp_error( $result ) && 'not-implemented' == $result->get_error_code() )
398                                 continue;
399                         return ( $result && ! is_wp_error( $result ) ) ? $result : false;
400                 }
401                 return false;
402         }
403
404         /**
405          * Fetches result from an oEmbed provider for a specific format and complete provider URL
406          *
407          * @since 3.0.0
408          * @access private
409          * @param string $provider_url_with_args URL to the provider with full arguments list (url, maxheight, etc.)
410          * @param string $format Format to use
411          * @return bool|object False on failure, otherwise the result in the form of an object.
412          */
413         private function _fetch_with_format( $provider_url_with_args, $format ) {
414                 $provider_url_with_args = add_query_arg( 'format', $format, $provider_url_with_args );
415
416                 /** This filter is documented in wp-includes/class-oembed.php */
417                 $args = apply_filters( 'oembed_remote_get_args', array(), $provider_url_with_args );
418
419                 $response = wp_safe_remote_get( $provider_url_with_args, $args );
420                 if ( 501 == wp_remote_retrieve_response_code( $response ) )
421                         return new WP_Error( 'not-implemented' );
422                 if ( ! $body = wp_remote_retrieve_body( $response ) )
423                         return false;
424                 $parse_method = "_parse_$format";
425                 return $this->$parse_method( $body );
426         }
427
428         /**
429          * Parses a json response body.
430          *
431          * @since 3.0.0
432          * @access private
433          */
434         private function _parse_json( $response_body ) {
435                 return ( ( $data = json_decode( trim( $response_body ) ) ) && is_object( $data ) ) ? $data : false;
436         }
437
438         /**
439          * Parses an XML response body.
440          *
441          * @since 3.0.0
442          * @access private
443          */
444         private function _parse_xml( $response_body ) {
445                 if ( ! function_exists( 'libxml_disable_entity_loader' ) )
446                         return false;
447
448                 $loader = libxml_disable_entity_loader( true );
449                 $errors = libxml_use_internal_errors( true );
450
451                 $return = $this->_parse_xml_body( $response_body );
452
453                 libxml_use_internal_errors( $errors );
454                 libxml_disable_entity_loader( $loader );
455
456                 return $return;
457         }
458
459         /**
460          * Helper function for parsing an XML response body.
461          *
462          * @since 3.6.0
463          * @access private
464          */
465         private function _parse_xml_body( $response_body ) {
466                 if ( ! function_exists( 'simplexml_import_dom' ) || ! class_exists( 'DOMDocument' ) )
467                         return false;
468
469                 $dom = new DOMDocument;
470                 $success = $dom->loadXML( $response_body );
471                 if ( ! $success )
472                         return false;
473
474                 if ( isset( $dom->doctype ) )
475                         return false;
476
477                 foreach ( $dom->childNodes as $child ) {
478                         if ( XML_DOCUMENT_TYPE_NODE === $child->nodeType )
479                                 return false;
480                 }
481
482                 $xml = simplexml_import_dom( $dom );
483                 if ( ! $xml )
484                         return false;
485
486                 $return = new stdClass;
487                 foreach ( $xml as $key => $value ) {
488                         $return->$key = (string) $value;
489                 }
490
491                 return $return;
492         }
493
494         /**
495          * Converts a data object from {@link WP_oEmbed::fetch()} and returns the HTML.
496          *
497          * @param object $data A data object result from an oEmbed provider.
498          * @param string $url The URL to the content that is desired to be embedded.
499          * @return false|string False on error, otherwise the HTML needed to embed.
500          */
501         public function data2html( $data, $url ) {
502                 if ( ! is_object( $data ) || empty( $data->type ) )
503                         return false;
504
505                 $return = false;
506
507                 switch ( $data->type ) {
508                         case 'photo':
509                                 if ( empty( $data->url ) || empty( $data->width ) || empty( $data->height ) )
510                                         break;
511                                 if ( ! is_string( $data->url ) || ! is_numeric( $data->width ) || ! is_numeric( $data->height ) )
512                                         break;
513
514                                 $title = ! empty( $data->title ) && is_string( $data->title ) ? $data->title : '';
515                                 $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>';
516                                 break;
517
518                         case 'video':
519                         case 'rich':
520                                 if ( ! empty( $data->html ) && is_string( $data->html ) )
521                                         $return = $data->html;
522                                 break;
523
524                         case 'link':
525                                 if ( ! empty( $data->title ) && is_string( $data->title ) )
526                                         $return = '<a href="' . esc_url( $url ) . '">' . esc_html( $data->title ) . '</a>';
527                                 break;
528
529                         default:
530                                 $return = false;
531                 }
532
533                 /**
534                  * Filter the returned oEmbed HTML.
535                  *
536                  * Use this filter to add support for custom data types, or to filter the result.
537                  *
538                  * @since 2.9.0
539                  *
540                  * @param string $return The returned oEmbed HTML.
541                  * @param object $data   A data object result from an oEmbed provider.
542                  * @param string $url    The URL of the content to be embedded.
543                  */
544                 return apply_filters( 'oembed_dataparse', $return, $data, $url );
545         }
546
547         /**
548          * Strip any new lines from the HTML.
549          *
550          * @access public
551          * @param string $html Existing HTML.
552          * @param object $data Data object from WP_oEmbed::data2html()
553          * @param string $url The original URL passed to oEmbed.
554          * @return string Possibly modified $html
555          */
556         public function _strip_newlines( $html, $data, $url ) {
557                 if ( false !== strpos( $html, "\n" ) )
558                         $html = str_replace( array( "\r\n", "\n" ), '', $html );
559
560                 return $html;
561         }
562 }
563
564 /**
565  * Returns the initialized {@link WP_oEmbed} object
566  *
567  * @since 2.9.0
568  * @access private
569  *
570  * @see WP_oEmbed
571  *
572  * @return WP_oEmbed object.
573  */
574 function _wp_oembed_get_object() {
575         static $wp_oembed;
576
577         if ( is_null($wp_oembed) )
578                 $wp_oembed = new WP_oEmbed();
579
580         return $wp_oembed;
581 }