WordPress.org

Make WordPress Core

Changeset 12027


Ignore:
Timestamp:
10/13/09 22:36:24 (5 years ago)
Author:
ryan
Message:

Use oEmbed for youtube. Props Viper007Bond. see #10337

Location:
trunk/wp-includes
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/capabilities.php

    r12023 r12027  
    963963 * Whether author of supplied post has capability or role. 
    964964 * 
    965  * @since 2.9 
     965 * @since 2.9.0 
    966966 * 
    967967 * @param int|object $post Post ID or post object. 
  • trunk/wp-includes/class-oembed.php

    r12023 r12027  
    3838        // so only providers in this array will be used for them. 
    3939        $this->providers = apply_filters( 'oembed_providers', array( 
     40            'http://*.youtube.com/watch*' => 'http://www.youtube.com/oembed', 
     41            'http://youtube.com/watch*'   => 'http://www.youtube.com/oembed', 
    4042            'http://blip.tv/file/*'       => 'http://blip.tv/oembed/', 
    4143            'http://*.flickr.com/*'       => 'http://www.flickr.com/services/oembed/', 
     44            'http://www.hulu.com/watch/*' => 'http://www.hulu.com/api/oembed.{format}', 
    4245            'http://*.viddler.com/*'      => 'http://lab.viddler.com/services/oembed/', 
    4346            'http://qik.com/*'            => 'http://qik.com/api/oembed.{format}', 
    4447            'http://*.revision3.com/*'    => 'http://revision3.com/api/oembed/', 
    45             'http://www.hulu.com/watch/*' => 'http://www.hulu.com/api/oembed.{format}', 
    4648 
    4749            // Vimeo uses the discovery <link>, so leave this commented to use it as a discovery test 
  • trunk/wp-includes/default-embeds.php

    r12023 r12027  
    77 * @subpackage Embeds 
    88 */ 
    9  
    10 /** 
    11  * The YouTube.com embed handler callback. YouTube does not support oEmbed and we want to provide extra customization. 
    12  * 
    13  * @see WP_Embed::register_handler() 
    14  * @see WP_Embed::shortcode() 
    15  * 
    16  * @param array $matches The regex matches from the provided regex when calling {@link wp_embed_register_handler()}. 
    17  * @param array $attr Embed attributes. 
    18  * @param string $url The original URL that was matched by the regex. 
    19  * @param array $rawattr The original unmodified attributes. 
    20  * @return string The embed HTML. 
    21  */ 
    22 function wp_embed_handler_youtube( $matches, $attr, $url, $rawattr ) { 
    23     // If the user supplied a fixed width AND height, use it 
    24     if ( !empty($rawattr['width']) && !empty($rawattr['height']) ) { 
    25         $width  = (int) $rawattr['width']; 
    26         $height = (int) $rawattr['height']; 
    27     } else { 
    28         list( $width, $height ) = wp_expand_dimensions( 425, 344, $attr['width'], $attr['height'] ); 
    29     } 
    30  
    31     return apply_filters( 'embed_youtube', '<object width="' . esc_attr($width) . '" height="' . esc_attr($height) . '"><param name="movie" value="http://www.youtube.com/v/' . esc_attr($matches[3]) . '&amp;hl=en&amp;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' . esc_attr($matches[3]) . '&amp;hl=en&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' . esc_attr($width) . '" height="' . esc_attr($height) . '"></embed></object>', $matches, $attr, $url, $rawattr ); 
    32 } 
    33 wp_embed_register_handler( 'youtube', '#http://(www.youtube|youtube|[A-Za-z]{2}.youtube)\.com/(watch\?v=|w/\?v=|\?v=)([\w-]+)(.*?)#i', 'wp_embed_handler_youtube' ); 
    34  
    359 
    3610/** 
  • trunk/wp-includes/formatting.php

    r12023 r12027  
    23592359        case 'large_size_w': 
    23602360        case 'large_size_h': 
    2361         //case 'embed_size_w': 
    23622361        case 'embed_size_h': 
    23632362        case 'default_post_edit_rows': 
     
    23762375            break; 
    23772376 
     2377        case 'embed_size_w': 
     2378            if ( '' !== $value ) 
     2379                $value = absint( $value ); 
     2380            break; 
     2381 
    23782382        case 'posts_per_page': 
    23792383        case 'posts_per_rss': 
  • trunk/wp-includes/media.php

    r12023 r12027  
    11351135 * Register an embed handler. This function should probably only be used for sites that do not support oEmbed. 
    11361136 * 
     1137 * @since 2.9.0 
    11371138 * @see WP_Embed::register_handler() 
    11381139 */ 
     
    11451146 * Unregister a previously registered embed handler. 
    11461147 * 
     1148 * @since 2.9.0 
    11471149 * @see WP_Embed::unregister_handler() 
    11481150 */ 
     
    11541156/** 
    11551157 * Create default array of embed parameters. 
     1158 * 
     1159 * @since 2.9.0 
    11561160 * 
    11571161 * @return array Default embed parameters. 
     
    11781182 * Based on a supplied width/height example, return the biggest possible dimensions based on the max width/height. 
    11791183 * 
     1184 * @since 2.9.0 
    11801185 * @uses wp_constrain_dimensions() This function passes the widths and the heights. 
    11811186 * 
     
    11981203 * Attempts to fetch the embed HTML for a provided URL using oEmbed. 
    11991204 * 
     1205 * @since 2.9.0 
    12001206 * @see WP_oEmbed 
    12011207 * 
     
    12121218    return $oembed->get_html( $url, $args ); 
    12131219} 
     1220 
     1221/** 
     1222 * Adds a URL format and oEmbed provider URL pair. 
     1223 * 
     1224 * @since 2.9.0 
     1225 * @see WP_oEmbed 
     1226 * 
     1227 * @uses _wp_oembed_get_object() 
     1228 * 
     1229 * @param string $format The format of URL that this provider can handle. Use asterisks as wildcards. 
     1230 * @param string $provider The URL to the oEmbed provider. 
     1231 */ 
     1232function wp_oembed_add_provider( $format, $provider ) { 
     1233    require_once( 'class-oembed.php' ); 
     1234    $oembed = _wp_oembed_get_object(); 
     1235    $oembed->providers[$format] = $provider; 
     1236} 
Note: See TracChangeset for help on using the changeset viewer.