diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index bf94266b2..180747c7c 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 5358b6e57..9268770f4 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 )