<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[12096] trunk/wp-includes:
  Allow non-admins to use Vimeo and allow regex in oEmbed URL formats.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/12096">12096</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2009-10-23 19:33:24 +0000 (Fri, 23 Oct 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>Allow non-admins to use Vimeo and allow regex in oEmbed URL formats. Props Viper007Bond. see <a href="http://trac.wordpress.org/ticket/10337">#10337</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesclassoembedphp">trunk/wp-includes/class-oembed.php</a></li>
<li><a href="#trunkwpincludesmediaphp">trunk/wp-includes/media.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesclassoembedphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/class-oembed.php (12095 => 12096)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/class-oembed.php        2009-10-23 19:07:34 UTC (rev 12095)
+++ trunk/wp-includes/class-oembed.php        2009-10-23 19:33:24 UTC (rev 12096)
</span><span class="lines">@@ -33,21 +33,18 @@
</span><span class="cx">          * @uses apply_filters() Filters a list of pre-defined oEmbed providers.
</span><span class="cx">          */
</span><span class="cx">         function __construct() {
</span><del>-                // List out some popular sites, mainly ones that don't have discovery tags in their &lt;head&gt;
-                // The WP_Embed class disables discovery for non-unfiltered_html users,
-                // so only providers in this array will be used for them.
</del><ins>+                // List out some popular sites that support oEmbed.
+                // The WP_Embed class disables discovery for non-unfiltered_html users, so only providers in this array will be used for them.
+                // Add to this list using the wp_oembed_add_provider() function
</ins><span class="cx">                 $this-&gt;providers = apply_filters( 'oembed_providers', array(
</span><del>-                        'http://*.youtube.com/watch*' =&gt; 'http://www.youtube.com/oembed',
-                        'http://youtube.com/watch*'   =&gt; 'http://www.youtube.com/oembed',
-                        'http://blip.tv/file/*'       =&gt; 'http://blip.tv/oembed/',
-                        'http://*.flickr.com/*'       =&gt; 'http://www.flickr.com/services/oembed/',
-                        'http://www.hulu.com/watch/*' =&gt; 'http://www.hulu.com/api/oembed.{format}',
-                        'http://*.viddler.com/*'      =&gt; 'http://lab.viddler.com/services/oembed/',
-                        'http://qik.com/*'            =&gt; 'http://qik.com/api/oembed.{format}',
-                        'http://*.revision3.com/*'    =&gt; 'http://revision3.com/api/oembed/',
-
-                        // Vimeo uses the discovery &lt;link&gt;, so leave this commented to use it as a discovery test
-                        //'http://www.vimeo.com/*'      =&gt; 'http://www.vimeo.com/api/oembed.{format}',
</del><ins>+                        'http://www.youtube.com/watch*'   =&gt; array( 'http://www.youtube.com/oembed',            false  ),
+                        'http://blip.tv/file/*'           =&gt; array( 'http://blip.tv/oembed/',                   false ),
+                        '#http://(www\.)?vimeo\.com/.*#i' =&gt; array( 'http://www.vimeo.com/api/oembed.{format}', true  ),
+                        'http://*.flickr.com/*'           =&gt; array( 'http://www.flickr.com/services/oembed/',   false ),
+                        'http://www.hulu.com/watch/*'     =&gt; array( 'http://www.hulu.com/api/oembed.{format}',  false ),
+                        'http://*.viddler.com/*'          =&gt; array( 'http://lab.viddler.com/services/oembed/',  false ),
+                        'http://qik.com/*'                =&gt; array( 'http://qik.com/api/oembed.{format}',       false ),
+                        'http://*.revision3.com/*'        =&gt; array( 'http://revision3.com/api/oembed/',         false ),
</ins><span class="cx">                 ) );
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -68,11 +65,14 @@
</span><span class="cx">                 if ( !isset($args['discover']) )
</span><span class="cx">                         $args['discover'] = true;
</span><span class="cx"> 
</span><del>-                foreach ( $this-&gt;providers as $matchmask =&gt; $providerurl ) {
</del><ins>+                foreach ( $this-&gt;providers as $matchmask =&gt; $data ) {
+                        list( $providerurl, $regex ) = $data;
+
</ins><span class="cx">                         // Turn the asterisk-type provider URLs into regex
</span><del>-                        $regex = '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $matchmask ), '#' ) ) . '#i';
</del><ins>+                        if ( !$regex )
+                                $matchmask = '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $matchmask ), '#' ) ) . '#i';
</ins><span class="cx"> 
</span><del>-                        if ( preg_match( $regex, $url ) ) {
</del><ins>+                        if ( preg_match( $matchmask, $url ) ) {
</ins><span class="cx">                                 $provider = str_replace( '{format}', 'json', $providerurl ); // JSON is easier to deal with than XML
</span><span class="cx">                                 break;
</span><span class="cx">                         }
</span></span></pre></div>
<a id="trunkwpincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/media.php (12095 => 12096)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/media.php        2009-10-23 19:07:34 UTC (rev 12095)
+++ trunk/wp-includes/media.php        2009-10-23 19:33:24 UTC (rev 12096)
</span><span class="lines">@@ -1262,11 +1262,12 @@
</span><span class="cx">  *
</span><span class="cx">  * @uses _wp_oembed_get_object()
</span><span class="cx">  *
</span><del>- * @param string $format The format of URL that this provider can handle. Use asterisks as wildcards.
</del><ins>+ * @param string $format The format of URL that this provider can handle. You can use asterisks as wildcards.
</ins><span class="cx">  * @param string $provider The URL to the oEmbed provider.
</span><ins>+ * @param boolean $regex Whether the $format parameter is in a regex format or not.
</ins><span class="cx">  */
</span><del>-function wp_oembed_add_provider( $format, $provider ) {
</del><ins>+function wp_oembed_add_provider( $format, $provider, $regex = false ) {
</ins><span class="cx">         require_once( 'class-oembed.php' );
</span><span class="cx">         $oembed = _wp_oembed_get_object();
</span><del>-        $oembed-&gt;providers[$format] = $provider;
</del><ins>+        $oembed-&gt;providers[$format] = array( $provider, $regex );
</ins><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>