<!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>[16154] trunk/wp-includes: Introduce wp_basename()
  and use it for media handling.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/16154">16154</a></dd>
<dt>Author</dt> <dd>scribu</dd>
<dt>Date</dt> <dd>2010-11-02 17:19:55 +0000 (Tue, 02 Nov 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Introduce wp_basename() and use it for media handling. See <a href="http://trac.wordpress.org/ticket/11887">#11887</a></pre>

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

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesformattingphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/formatting.php (16153 => 16154)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/formatting.php        2010-11-02 16:33:23 UTC (rev 16153)
+++ trunk/wp-includes/formatting.php        2010-11-02 17:19:55 UTC (rev 16154)
</span><span class="lines">@@ -2844,13 +2844,25 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><ins>+ * i18n friendly version of basename()
+ *
+ * @since 3.1.0
+ *
+ * @param string $path A path.
+ * @param string $suffix If the filename ends in suffix this will also be cut off.
+ * @return string
+ */
+function wp_basename( $path, $suffix = '' ) {
+        return urldecode( basename( str_replace( '%2F', '/', urlencode( $path ) ), $suffix ) );
+}
+
+/**
</ins><span class="cx">  * Forever eliminate &quot;Wordpress&quot; from the planet (or at least the little bit we can influence).
</span><span class="cx">  *
</span><span class="cx">  * Violating our coding standards for a good function name.
</span><span class="cx">  *
</span><span class="cx">  * @since 3.0.0
</span><span class="cx">  */
</span><del>-
</del><span class="cx"> function capital_P_dangit( $text ) {
</span><span class="cx">         // Simple replacement for titles
</span><span class="cx">         if ( 'the_title' === current_filter() )
</span></span></pre></div>
<a id="trunkwpincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/media.php (16153 => 16154)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/media.php        2010-11-02 16:33:23 UTC (rev 16153)
+++ trunk/wp-includes/media.php        2010-11-02 17:19:55 UTC (rev 16154)
</span><span class="lines">@@ -137,6 +137,7 @@
</span><span class="cx">         $meta = wp_get_attachment_metadata($id);
</span><span class="cx">         $width = $height = 0;
</span><span class="cx">         $is_intermediate = false;
</span><ins>+        $img_url_basename = wp_basename($img_url);
</ins><span class="cx"> 
</span><span class="cx">         // plugins can use this to provide resize services
</span><span class="cx">         if ( $out = apply_filters('image_downsize', false, $id, $size) )
</span><span class="lines">@@ -144,7 +145,7 @@
</span><span class="cx"> 
</span><span class="cx">         // try for a new style intermediate size
</span><span class="cx">         if ( $intermediate = image_get_intermediate_size($id, $size) ) {
</span><del>-                $img_url = str_replace(basename($img_url), $intermediate['file'], $img_url);
</del><ins>+                $img_url = str_replace($img_url_basename, $intermediate['file'], $img_url);
</ins><span class="cx">                 $width = $intermediate['width'];
</span><span class="cx">                 $height = $intermediate['height'];
</span><span class="cx">                 $is_intermediate = true;
</span><span class="lines">@@ -152,7 +153,7 @@
</span><span class="cx">         elseif ( $size == 'thumbnail' ) {
</span><span class="cx">                 // fall back to the old thumbnail
</span><span class="cx">                 if ( ($thumb_file = wp_get_attachment_thumb_file($id)) &amp;&amp; $info = getimagesize($thumb_file) ) {
</span><del>-                        $img_url = str_replace(basename($img_url), basename($thumb_file), $img_url);
</del><ins>+                        $img_url = str_replace($img_url_basename, wp_basename($thumb_file), $img_url);
</ins><span class="cx">                         $width = $info[0];
</span><span class="cx">                         $height = $info[1];
</span><span class="cx">                         $is_intermediate = true;
</span><span class="lines">@@ -436,7 +437,8 @@
</span><span class="cx">         $info = pathinfo($file);
</span><span class="cx">         $dir = $info['dirname'];
</span><span class="cx">         $ext = $info['extension'];
</span><del>-        $name = basename($file, &quot;.{$ext}&quot;);
</del><ins>+        $name = wp_basename($file, &quot;.$ext&quot;);
+
</ins><span class="cx">         if ( !is_null($dest_path) and $_dest_path = realpath($dest_path) )
</span><span class="cx">                 $dir = $_dest_path;
</span><span class="cx">         $destfilename = &quot;{$dir}/{$name}-{$suffix}.{$ext}&quot;;
</span><span class="lines">@@ -485,7 +487,7 @@
</span><span class="cx">                 if ( !is_wp_error($resized_file) &amp;&amp; $resized_file &amp;&amp; $info = getimagesize($resized_file) ) {
</span><span class="cx">                         $resized_file = apply_filters('image_make_intermediate_size', $resized_file);
</span><span class="cx">                         return array(
</span><del>-                                'file' =&gt; basename( $resized_file ),
</del><ins>+                                'file' =&gt; wp_basename( $resized_file ),
</ins><span class="cx">                                 'width' =&gt; $info[0],
</span><span class="cx">                                 'height' =&gt; $info[1],
</span><span class="cx">                         );
</span><span class="lines">@@ -606,7 +608,7 @@
</span><span class="cx"> 
</span><span class="cx">         if ( $icon &amp;&amp; $src = wp_mime_type_icon($attachment_id) ) {
</span><span class="cx">                 $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/crystal' );
</span><del>-                $src_file = $icon_dir . '/' . basename($src);
</del><ins>+                $src_file = $icon_dir . '/' . wp_basename($src);
</ins><span class="cx">                 @list($width, $height) = getimagesize($src_file);
</span><span class="cx">         }
</span><span class="cx">         if ( $src &amp;&amp; $width &amp;&amp; $height )
</span></span></pre>
</div>
</div>

</body>
</html>