mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Replace usages of basename() with wp_basename() in order to support multibyte filenames
This is focused on the pieces of code that touch media files and the tests that support them. `basename` isn't multibyte compatible out of the box. See http://php.net/basename and https://bugs.php.net/bug.php?id=62119. See #43170. Props Viper007Bond. git-svn-id: https://develop.svn.wordpress.org/trunk@44785 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1360,7 +1360,7 @@ final class WP_Customize_Manager {
|
||||
if ( ! $attachment_id ) {
|
||||
|
||||
// Copy file to temp location so that original file won't get deleted from theme after sideloading.
|
||||
$temp_file_name = wp_tempnam( basename( $file_path ) );
|
||||
$temp_file_name = wp_tempnam( wp_basename( $file_path ) );
|
||||
if ( $temp_file_name && copy( $file_path, $temp_file_name ) ) {
|
||||
$file_array['tmp_name'] = $temp_file_name;
|
||||
}
|
||||
@@ -1621,7 +1621,7 @@ final class WP_Customize_Manager {
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
$file_name = basename( $attachment['file'] );
|
||||
$file_name = wp_basename( $attachment['file'] );
|
||||
|
||||
// Skip file types that are not recognized.
|
||||
$checked_filetype = wp_check_filetype( $file_name );
|
||||
@@ -4594,7 +4594,7 @@ final class WP_Customize_Manager {
|
||||
|
||||
if ( $this->return_url ) {
|
||||
$return_url = $this->return_url;
|
||||
} elseif ( $referer && ! in_array( basename( parse_url( $referer, PHP_URL_PATH ) ), $excluded_referer_basenames, true ) ) {
|
||||
} elseif ( $referer && ! in_array( wp_basename( parse_url( $referer, PHP_URL_PATH ) ), $excluded_referer_basenames, true ) ) {
|
||||
$return_url = $referer;
|
||||
} elseif ( $this->preview_url ) {
|
||||
$return_url = $this->preview_url;
|
||||
|
||||
@@ -92,7 +92,7 @@ class WP_Customize_Media_Control extends WP_Customize_Control {
|
||||
'url' => $this->setting->default,
|
||||
'type' => $type,
|
||||
'icon' => wp_mime_type_icon( $type ),
|
||||
'title' => basename( $this->setting->default ),
|
||||
'title' => wp_basename( $this->setting->default ),
|
||||
);
|
||||
|
||||
if ( 'image' === $type ) {
|
||||
|
||||
@@ -1878,7 +1878,7 @@ function get_attachment_icon_src( $id = 0, $fullsize = false ) {
|
||||
if ( !$fullsize && $src = wp_get_attachment_thumb_url( $post->ID ) ) {
|
||||
// We have a thumbnail desired, specified and existing
|
||||
|
||||
$src_file = basename($src);
|
||||
$src_file = wp_basename($src);
|
||||
} elseif ( wp_attachment_is_image( $post->ID ) ) {
|
||||
// We have an image without a thumbnail
|
||||
|
||||
@@ -1888,7 +1888,7 @@ function get_attachment_icon_src( $id = 0, $fullsize = false ) {
|
||||
// No thumb, no image. We'll look for a mime-related icon instead.
|
||||
|
||||
$icon_dir = apply_filters( 'icon_dir', get_template_directory() . '/images' );
|
||||
$src_file = $icon_dir . '/' . basename($src);
|
||||
$src_file = $icon_dir . '/' . wp_basename($src);
|
||||
}
|
||||
|
||||
if ( !isset($src) || !$src )
|
||||
@@ -3058,7 +3058,7 @@ function remove_custom_background() {
|
||||
*/
|
||||
function get_theme_data( $theme_file ) {
|
||||
_deprecated_function( __FUNCTION__, '3.4.0', 'wp_get_theme()' );
|
||||
$theme = new WP_Theme( basename( dirname( $theme_file ) ), dirname( dirname( $theme_file ) ) );
|
||||
$theme = new WP_Theme( wp_basename( dirname( $theme_file ) ), dirname( dirname( $theme_file ) ) );
|
||||
|
||||
$theme_data = array(
|
||||
'Name' => $theme->get('Name'),
|
||||
|
||||
@@ -2096,7 +2096,7 @@ function wp_upload_dir( $time = null, $create_dir = true, $refresh_cache = false
|
||||
if ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) {
|
||||
$error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir'];
|
||||
} else {
|
||||
$error_path = basename( $uploads['basedir'] ) . $uploads['subdir'];
|
||||
$error_path = wp_basename( $uploads['basedir'] ) . $uploads['subdir'];
|
||||
}
|
||||
|
||||
$uploads['error'] = sprintf(
|
||||
@@ -2381,7 +2381,7 @@ function wp_upload_bits( $name, $deprecated, $bits, $time = null ) {
|
||||
if ( 0 === strpos( $upload['basedir'], ABSPATH ) ) {
|
||||
$error_path = str_replace( ABSPATH, '', $upload['basedir'] ) . $upload['subdir'];
|
||||
} else {
|
||||
$error_path = basename( $upload['basedir'] ) . $upload['subdir'];
|
||||
$error_path = wp_basename( $upload['basedir'] ) . $upload['subdir'];
|
||||
}
|
||||
|
||||
$message = sprintf(
|
||||
|
||||
@@ -2871,7 +2871,7 @@ function get_attachment_taxonomies( $attachment, $output = 'names' ) {
|
||||
}
|
||||
|
||||
$file = get_attached_file( $attachment->ID );
|
||||
$filename = basename( $file );
|
||||
$filename = wp_basename( $file );
|
||||
|
||||
$objects = array( 'attachment' );
|
||||
|
||||
|
||||
@@ -5474,7 +5474,7 @@ function wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file ) {
|
||||
if ( ! empty( $meta['thumb'] ) ) {
|
||||
// Don't delete the thumb if another attachment uses it.
|
||||
if ( ! $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s AND post_id <> %d", '%' . $wpdb->esc_like( $meta['thumb'] ) . '%', $post_id ) ) ) {
|
||||
$thumbfile = str_replace( basename( $file ), $meta['thumb'], $file );
|
||||
$thumbfile = str_replace( wp_basename( $file ), $meta['thumb'], $file );
|
||||
if ( ! empty( $thumbfile ) ) {
|
||||
$thumbfile = path_join( $uploadpath['basedir'], $thumbfile );
|
||||
$thumbdir = path_join( $uploadpath['basedir'], dirname( $file ) );
|
||||
@@ -5490,7 +5490,7 @@ function wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file ) {
|
||||
if ( isset( $meta['sizes'] ) && is_array( $meta['sizes'] ) ) {
|
||||
$intermediate_dir = path_join( $uploadpath['basedir'], dirname( $file ) );
|
||||
foreach ( $meta['sizes'] as $size => $sizeinfo ) {
|
||||
$intermediate_file = str_replace( basename( $file ), $sizeinfo['file'], $file );
|
||||
$intermediate_file = str_replace( wp_basename( $file ), $sizeinfo['file'], $file );
|
||||
if ( ! empty( $intermediate_file ) ) {
|
||||
$intermediate_file = path_join( $uploadpath['basedir'], $intermediate_file );
|
||||
|
||||
@@ -5616,7 +5616,7 @@ function wp_get_attachment_url( $attachment_id = 0 ) {
|
||||
$url = str_replace( $uploads['basedir'], $uploads['baseurl'], $file );
|
||||
} elseif ( false !== strpos( $file, 'wp-content/uploads' ) ) {
|
||||
// Get the directory name relative to the basedir (back compat for pre-2.7 uploads)
|
||||
$url = trailingslashit( $uploads['baseurl'] . '/' . _wp_get_attachment_relative_path( $file ) ) . basename( $file );
|
||||
$url = trailingslashit( $uploads['baseurl'] . '/' . _wp_get_attachment_relative_path( $file ) ) . wp_basename( $file );
|
||||
} else {
|
||||
// It's a newly-uploaded file, therefore $file is relative to the basedir.
|
||||
$url = $uploads['baseurl'] . "/$file";
|
||||
@@ -5704,7 +5704,7 @@ function wp_get_attachment_thumb_file( $post_id = 0 ) {
|
||||
|
||||
$file = get_attached_file( $post->ID );
|
||||
|
||||
if ( ! empty( $imagedata['thumb'] ) && ( $thumbfile = str_replace( basename( $file ), $imagedata['thumb'], $file ) ) && file_exists( $thumbfile ) ) {
|
||||
if ( ! empty( $imagedata['thumb'] ) && ( $thumbfile = str_replace( wp_basename( $file ), $imagedata['thumb'], $file ) ) && file_exists( $thumbfile ) ) {
|
||||
/**
|
||||
* Filters the attachment thumbnail file path.
|
||||
*
|
||||
@@ -5744,7 +5744,7 @@ function wp_get_attachment_thumb_url( $post_id = 0 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$url = str_replace( basename( $url ), basename( $thumb ), $url );
|
||||
$url = str_replace( wp_basename( $url ), wp_basename( $thumb ), $url );
|
||||
|
||||
/**
|
||||
* Filters the attachment thumbnail URL.
|
||||
@@ -5896,7 +5896,7 @@ function wp_mime_type_icon( $mime = 0 ) {
|
||||
$uri = array_shift( $dirs );
|
||||
if ( $dh = opendir( $dir ) ) {
|
||||
while ( false !== $file = readdir( $dh ) ) {
|
||||
$file = basename( $file );
|
||||
$file = wp_basename( $file );
|
||||
if ( substr( $file, 0, 1 ) == '.' ) {
|
||||
continue;
|
||||
}
|
||||
@@ -5915,9 +5915,9 @@ function wp_mime_type_icon( $mime = 0 ) {
|
||||
}
|
||||
|
||||
$types = array();
|
||||
// Icon basename - extension = MIME wildcard.
|
||||
// Icon wp_basename - extension = MIME wildcard.
|
||||
foreach ( $icon_files as $file => $uri ) {
|
||||
$types[ preg_replace( '/^([^.]*).*$/', '$1', basename( $file ) ) ] =& $icon_files[ $file ];
|
||||
$types[ preg_replace( '/^([^.]*).*$/', '$1', wp_basename( $file ) ) ] =& $icon_files[ $file ];
|
||||
}
|
||||
|
||||
if ( ! empty( $mime ) ) {
|
||||
|
||||
@@ -114,7 +114,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
||||
return $file;
|
||||
}
|
||||
|
||||
$name = basename( $file['file'] );
|
||||
$name = wp_basename( $file['file'] );
|
||||
$name_parts = pathinfo( $name );
|
||||
$name = trim( substr( $name, 0, -( 1 + strlen( $name_parts['extension'] ) ) ) );
|
||||
|
||||
@@ -143,7 +143,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
||||
$attachment->guid = $url;
|
||||
|
||||
if ( empty( $attachment->post_title ) ) {
|
||||
$attachment->post_title = preg_replace( '/\.[^.]+$/', '', basename( $file ) );
|
||||
$attachment->post_title = preg_replace( '/\.[^.]+$/', '', wp_basename( $file ) );
|
||||
}
|
||||
|
||||
// $post_parent is inherited from $attachment['post_parent'].
|
||||
|
||||
Reference in New Issue
Block a user