Use oEmbed for youtube. Props Viper007Bond. see #10337

git-svn-id: http://svn.automattic.com/wordpress/trunk@12027 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2009-10-13 22:36:24 +00:00
parent 9dbf6545f0
commit 18f11f1fbc
5 changed files with 32 additions and 29 deletions

View File

@ -962,7 +962,7 @@ function current_user_can( $capability ) {
/**
* Whether author of supplied post has capability or role.
*
* @since 2.9
* @since 2.9.0
*
* @param int|object $post Post ID or post object.
* @param string $capability Capability or role name.

View File

@ -37,12 +37,14 @@ class WP_oEmbed {
// The WP_Embed class disables discovery for non-unfiltered_html users,
// so only providers in this array will be used for them.
$this->providers = apply_filters( 'oembed_providers', array(
'http://*.youtube.com/watch*' => 'http://www.youtube.com/oembed',
'http://youtube.com/watch*' => 'http://www.youtube.com/oembed',
'http://blip.tv/file/*' => 'http://blip.tv/oembed/',
'http://*.flickr.com/*' => 'http://www.flickr.com/services/oembed/',
'http://www.hulu.com/watch/*' => 'http://www.hulu.com/api/oembed.{format}',
'http://*.viddler.com/*' => 'http://lab.viddler.com/services/oembed/',
'http://qik.com/*' => 'http://qik.com/api/oembed.{format}',
'http://*.revision3.com/*' => 'http://revision3.com/api/oembed/',
'http://www.hulu.com/watch/*' => 'http://www.hulu.com/api/oembed.{format}',
// Vimeo uses the discovery <link>, so leave this commented to use it as a discovery test
//'http://www.vimeo.com/*' => 'http://www.vimeo.com/api/oembed.{format}',

View File

@ -7,32 +7,6 @@
* @subpackage Embeds
*/
/**
* The YouTube.com embed handler callback. YouTube does not support oEmbed and we want to provide extra customization.
*
* @see WP_Embed::register_handler()
* @see WP_Embed::shortcode()
*
* @param array $matches The regex matches from the provided regex when calling {@link wp_embed_register_handler()}.
* @param array $attr Embed attributes.
* @param string $url The original URL that was matched by the regex.
* @param array $rawattr The original unmodified attributes.
* @return string The embed HTML.
*/
function wp_embed_handler_youtube( $matches, $attr, $url, $rawattr ) {
// If the user supplied a fixed width AND height, use it
if ( !empty($rawattr['width']) && !empty($rawattr['height']) ) {
$width = (int) $rawattr['width'];
$height = (int) $rawattr['height'];
} else {
list( $width, $height ) = wp_expand_dimensions( 425, 344, $attr['width'], $attr['height'] );
}
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 );
}
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' );
/**
* The Google Video embed handler callback. Google Video does not support oEmbed.
*

View File

@ -2358,7 +2358,6 @@ function sanitize_option($option, $value) {
case 'medium_size_h':
case 'large_size_w':
case 'large_size_h':
//case 'embed_size_w':
case 'embed_size_h':
case 'default_post_edit_rows':
case 'mailserver_port':
@ -2375,6 +2374,11 @@ function sanitize_option($option, $value) {
$value = absint( $value );
break;
case 'embed_size_w':
if ( '' !== $value )
$value = absint( $value );
break;
case 'posts_per_page':
case 'posts_per_rss':
$value = (int) $value;

View File

@ -1134,6 +1134,7 @@ $wp_embed = new WP_Embed();
/**
* Register an embed handler. This function should probably only be used for sites that do not support oEmbed.
*
* @since 2.9.0
* @see WP_Embed::register_handler()
*/
function wp_embed_register_handler( $id, $regex, $callback, $priority = 10 ) {
@ -1144,6 +1145,7 @@ function wp_embed_register_handler( $id, $regex, $callback, $priority = 10 ) {
/**
* Unregister a previously registered embed handler.
*
* @since 2.9.0
* @see WP_Embed::unregister_handler()
*/
function wp_embed_unregister_handler( $id, $priority = 10 ) {
@ -1154,6 +1156,8 @@ function wp_embed_unregister_handler( $id, $priority = 10 ) {
/**
* Create default array of embed parameters.
*
* @since 2.9.0
*
* @return array Default embed parameters.
*/
function wp_embed_defaults() {
@ -1177,6 +1181,7 @@ function wp_embed_defaults() {
/**
* Based on a supplied width/height example, return the biggest possible dimensions based on the max width/height.
*
* @since 2.9.0
* @uses wp_constrain_dimensions() This function passes the widths and the heights.
*
* @param int $example_width The width of an example embed.
@ -1197,6 +1202,7 @@ function wp_expand_dimensions( $example_width, $example_height, $max_width, $max
/**
* Attempts to fetch the embed HTML for a provided URL using oEmbed.
*
* @since 2.9.0
* @see WP_oEmbed
*
* @uses _wp_oembed_get_object()
@ -1211,3 +1217,20 @@ function wp_oembed_get( $url, $args = '' ) {
$oembed = _wp_oembed_get_object();
return $oembed->get_html( $url, $args );
}
/**
* Adds a URL format and oEmbed provider URL pair.
*
* @since 2.9.0
* @see WP_oEmbed
*
* @uses _wp_oembed_get_object()
*
* @param string $format The format of URL that this provider can handle. Use asterisks as wildcards.
* @param string $provider The URL to the oEmbed provider.
*/
function wp_oembed_add_provider( $format, $provider ) {
require_once( 'class-oembed.php' );
$oembed = _wp_oembed_get_object();
$oembed->providers[$format] = $provider;
}