From fdd355680625d94a97c22dad364601784f101428 Mon Sep 17 00:00:00 2001 From: scribu Date: Tue, 2 Nov 2010 17:19:55 +0000 Subject: [PATCH] Introduce wp_basename() and use it for media handling. See #11887 git-svn-id: http://svn.automattic.com/wordpress/trunk@16154 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/formatting.php | 14 +++++++++++++- wp-includes/media.php | 12 +++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index bf94266b25..180747c7c3 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -2843,6 +2843,19 @@ function sanitize_text_field($str) { return apply_filters('sanitize_text_field', $filtered, $str); } +/** + * 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 ) ); +} + /** * Forever eliminate "Wordpress" from the planet (or at least the little bit we can influence). * @@ -2850,7 +2863,6 @@ function sanitize_text_field($str) { * * @since 3.0.0 */ - function capital_P_dangit( $text ) { // Simple replacement for titles if ( 'the_title' === current_filter() ) diff --git a/wp-includes/media.php b/wp-includes/media.php index 5358b6e578..9268770f49 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -137,6 +137,7 @@ function image_downsize($id, $size = 'medium') { $meta = wp_get_attachment_metadata($id); $width = $height = 0; $is_intermediate = false; + $img_url_basename = wp_basename($img_url); // plugins can use this to provide resize services if ( $out = apply_filters('image_downsize', false, $id, $size) ) @@ -144,7 +145,7 @@ function image_downsize($id, $size = 'medium') { // try for a new style intermediate size if ( $intermediate = image_get_intermediate_size($id, $size) ) { - $img_url = str_replace(basename($img_url), $intermediate['file'], $img_url); + $img_url = str_replace($img_url_basename, $intermediate['file'], $img_url); $width = $intermediate['width']; $height = $intermediate['height']; $is_intermediate = true; @@ -152,7 +153,7 @@ function image_downsize($id, $size = 'medium') { elseif ( $size == 'thumbnail' ) { // fall back to the old thumbnail if ( ($thumb_file = wp_get_attachment_thumb_file($id)) && $info = getimagesize($thumb_file) ) { - $img_url = str_replace(basename($img_url), basename($thumb_file), $img_url); + $img_url = str_replace($img_url_basename, wp_basename($thumb_file), $img_url); $width = $info[0]; $height = $info[1]; $is_intermediate = true; @@ -436,7 +437,8 @@ function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $de $info = pathinfo($file); $dir = $info['dirname']; $ext = $info['extension']; - $name = basename($file, ".{$ext}"); + $name = wp_basename($file, ".$ext"); + if ( !is_null($dest_path) and $_dest_path = realpath($dest_path) ) $dir = $_dest_path; $destfilename = "{$dir}/{$name}-{$suffix}.{$ext}"; @@ -485,7 +487,7 @@ function image_make_intermediate_size($file, $width, $height, $crop=false) { if ( !is_wp_error($resized_file) && $resized_file && $info = getimagesize($resized_file) ) { $resized_file = apply_filters('image_make_intermediate_size', $resized_file); return array( - 'file' => basename( $resized_file ), + 'file' => wp_basename( $resized_file ), 'width' => $info[0], 'height' => $info[1], ); @@ -606,7 +608,7 @@ function wp_get_attachment_image_src($attachment_id, $size='thumbnail', $icon = if ( $icon && $src = wp_mime_type_icon($attachment_id) ) { $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/crystal' ); - $src_file = $icon_dir . '/' . basename($src); + $src_file = $icon_dir . '/' . wp_basename($src); @list($width, $height) = getimagesize($src_file); } if ( $src && $width && $height )