Make WordPress Core


Ignore:
Timestamp:
10/23/2009 07:33:24 PM (15 years ago)
Author:
ryan
Message:

Allow non-admins to use Vimeo and allow regex in oEmbed URL formats. Props Viper007Bond. see #10337

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-oembed.php

    r12042 r12096  
    3434     */
    3535    function __construct() {
    36         // List out some popular sites, mainly ones that don't have discovery tags in their <head>
    37         // The WP_Embed class disables discovery for non-unfiltered_html users,
    38         // so only providers in this array will be used for them.
     36        // List out some popular sites that support oEmbed.
     37        // The WP_Embed class disables discovery for non-unfiltered_html users, so only providers in this array will be used for them.
     38        // Add to this list using the wp_oembed_add_provider() function
    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',
    42             'http://blip.tv/file/*'       => 'http://blip.tv/oembed/',
    43             'http://*.flickr.com/*'       => 'http://www.flickr.com/services/oembed/',
    44             'http://www.hulu.com/watch/*' => 'http://www.hulu.com/api/oembed.{format}',
    45             'http://*.viddler.com/*'      => 'http://lab.viddler.com/services/oembed/',
    46             'http://qik.com/*'            => 'http://qik.com/api/oembed.{format}',
    47             'http://*.revision3.com/*'    => 'http://revision3.com/api/oembed/',
    48 
    49             // Vimeo uses the discovery <link>, so leave this commented to use it as a discovery test
    50             //'http://www.vimeo.com/*'      => 'http://www.vimeo.com/api/oembed.{format}',
     40            'http://www.youtube.com/watch*'   => array( 'http://www.youtube.com/oembed',            false  ),
     41            'http://blip.tv/file/*'           => array( 'http://blip.tv/oembed/',                   false ),
     42            '#http://(www\.)?vimeo\.com/.*#i' => array( 'http://www.vimeo.com/api/oembed.{format}', true  ),
     43            'http://*.flickr.com/*'           => array( 'http://www.flickr.com/services/oembed/',   false ),
     44            'http://www.hulu.com/watch/*'     => array( 'http://www.hulu.com/api/oembed.{format}',  false ),
     45            'http://*.viddler.com/*'          => array( 'http://lab.viddler.com/services/oembed/',  false ),
     46            'http://qik.com/*'                => array( 'http://qik.com/api/oembed.{format}',       false ),
     47            'http://*.revision3.com/*'        => array( 'http://revision3.com/api/oembed/',         false ),
    5148        ) );
    5249    }
     
    6966            $args['discover'] = true;
    7067
    71         foreach ( $this->providers as $matchmask => $providerurl ) {
     68        foreach ( $this->providers as $matchmask => $data ) {
     69            list( $providerurl, $regex ) = $data;
     70
    7271            // Turn the asterisk-type provider URLs into regex
    73             $regex = '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $matchmask ), '#' ) ) . '#i';
    74 
    75             if ( preg_match( $regex, $url ) ) {
     72            if ( !$regex )
     73                $matchmask = '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $matchmask ), '#' ) ) . '#i';
     74
     75            if ( preg_match( $matchmask, $url ) ) {
    7676                $provider = str_replace( '{format}', 'json', $providerurl ); // JSON is easier to deal with than XML
    7777                break;
Note: See TracChangeset for help on using the changeset viewer.