Media: when calling `pathinfo()`, also pass a `PATHINFO_*` constant to avoid array notices for unset keys.

Props JaworskiMatt.
Fixes #37608.

Built from https://develop.svn.wordpress.org/trunk@38294


git-svn-id: http://core.svn.wordpress.org/trunk@38235 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2016-08-20 23:36:28 +00:00
parent d73964aab6
commit 7ac88c02fa
6 changed files with 42 additions and 38 deletions

View File

@ -77,9 +77,10 @@ $wp_file_descriptions = array(
function get_file_description( $file ) { function get_file_description( $file ) {
global $wp_file_descriptions, $allowed_files; global $wp_file_descriptions, $allowed_files;
$relative_pathinfo = pathinfo( $file ); $dirname = pathinfo( $file, PATHINFO_DIRNAME );
$file_path = $allowed_files[ $file ]; $file_path = $allowed_files[ $file ];
if ( isset( $wp_file_descriptions[ basename( $file ) ] ) && '.' === $relative_pathinfo['dirname'] ) { if ( isset( $wp_file_descriptions[ basename( $file ) ] ) && '.' === $dirname ) {
return $wp_file_descriptions[ basename( $file ) ]; return $wp_file_descriptions[ basename( $file ) ];
} elseif ( file_exists( $file_path ) && is_file( $file_path ) ) { } elseif ( file_exists( $file_path ) && is_file( $file_path ) ) {
$template_data = implode( '', file( $file_path ) ); $template_data = implode( '', file( $file_path ) );

View File

@ -761,28 +761,33 @@ function wp_save_image( $post_id ) {
$backup_sizes = array(); $backup_sizes = array();
// Generate new filename. // Generate new filename.
$path = get_attached_file($post_id); $path = get_attached_file( $post_id );
$path_parts = pathinfo( $path );
$filename = $path_parts['filename']; $basename = pathinfo( $path, PATHINFO_BASENAME );
$dirname = pathinfo( $path, PATHINFO_DIRNAME );
$ext = pathinfo( $path, PATHINFO_EXTENSION );
$filename = pathinfo( $path, PATHINFO_FILENAME );
$suffix = time() . rand(100, 999); $suffix = time() . rand(100, 999);
if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE && if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE &&
isset($backup_sizes['full-orig']) && $backup_sizes['full-orig']['file'] != $path_parts['basename'] ) { isset($backup_sizes['full-orig']) && $backup_sizes['full-orig']['file'] != $basename ) {
if ( 'thumbnail' == $target ) if ( 'thumbnail' == $target ) {
$new_path = "{$path_parts['dirname']}/{$filename}-temp.{$path_parts['extension']}"; $new_path = "{$dirname}/{$filename}-temp.{$ext}";
else } else {
$new_path = $path; $new_path = $path;
}
} else { } else {
while( true ) { while ( true ) {
$filename = preg_replace( '/-e([0-9]+)$/', '', $filename ); $filename = preg_replace( '/-e([0-9]+)$/', '', $filename );
$filename .= "-e{$suffix}"; $filename .= "-e{$suffix}";
$new_filename = "{$filename}.{$path_parts['extension']}"; $new_filename = "{$filename}.{$ext}";
$new_path = "{$path_parts['dirname']}/$new_filename"; $new_path = "{$dirname}/$new_filename";
if ( file_exists($new_path) ) if ( file_exists($new_path) ) {
$suffix++; $suffix++;
else } else {
break; break;
}
} }
} }
@ -792,18 +797,19 @@ function wp_save_image( $post_id ) {
return $return; return $return;
} }
if ( 'nothumb' == $target || 'all' == $target || 'full' == $target || $scaled ) { if ( 'nothumb' === $target || 'all' === $target || 'full' === $target || $scaled ) {
$tag = false; $tag = false;
if ( isset($backup_sizes['full-orig']) ) { if ( isset( $backup_sizes['full-orig'] ) ) {
if ( ( !defined('IMAGE_EDIT_OVERWRITE') || !IMAGE_EDIT_OVERWRITE ) && $backup_sizes['full-orig']['file'] != $path_parts['basename'] ) if ( ( ! defined( 'IMAGE_EDIT_OVERWRITE' ) || ! IMAGE_EDIT_OVERWRITE ) && $backup_sizes['full-orig']['file'] !== $basename ) {
$tag = "full-$suffix"; $tag = "full-$suffix";
}
} else { } else {
$tag = 'full-orig'; $tag = 'full-orig';
} }
if ( $tag ) if ( $tag ) {
$backup_sizes[$tag] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $path_parts['basename']); $backup_sizes[$tag] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $basename );
}
$success = ( $path === $new_path ) || update_attached_file( $post_id, $new_path ); $success = ( $path === $new_path ) || update_attached_file( $post_id, $new_path );
$meta['file'] = _wp_relative_upload_path( $new_path ); $meta['file'] = _wp_relative_upload_path( $new_path );
@ -834,7 +840,7 @@ function wp_save_image( $post_id ) {
if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE && ! empty( $meta['sizes'] ) ) { if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE && ! empty( $meta['sizes'] ) ) {
foreach ( $meta['sizes'] as $size ) { foreach ( $meta['sizes'] as $size ) {
if ( ! empty( $size['file'] ) && preg_match( '/-e[0-9]{13}-/', $size['file'] ) ) { if ( ! empty( $size['file'] ) && preg_match( '/-e[0-9]{13}-/', $size['file'] ) ) {
$delete_file = path_join( $path_parts['dirname'], $size['file'] ); $delete_file = path_join( $dirname, $size['file'] );
wp_delete_file( $delete_file ); wp_delete_file( $delete_file );
} }
} }

View File

@ -284,13 +284,12 @@ function media_handle_upload($file_id, $post_id, $post_data = array(), $override
if ( isset($file['error']) ) if ( isset($file['error']) )
return new WP_Error( 'upload_error', $file['error'] ); return new WP_Error( 'upload_error', $file['error'] );
$name_parts = pathinfo($name); $basename = pathinfo( $name, PATHINFO_BASENAME );
$name = trim( substr( $name, 0, -(1 + strlen($name_parts['extension'])) ) );
$url = $file['url']; $url = $file['url'];
$type = $file['type']; $type = $file['type'];
$file = $file['file']; $file = $file['file'];
$title = $name; $title = $basename;
$content = ''; $content = '';
$excerpt = ''; $excerpt = '';

View File

@ -346,12 +346,8 @@ abstract class WP_Image_Editor {
} }
if ( $filename ) { if ( $filename ) {
$ext = ''; $dir = pathinfo( $filename, PATHINFO_DIRNAME );
$info = pathinfo( $filename ); $ext = pathinfo( $filename, PATHINFO_EXTENSION );
$dir = $info['dirname'];
if ( isset( $info['extension'] ) )
$ext = $info['extension'];
$filename = trailingslashit( $dir ) . wp_basename( $filename, ".$ext" ) . ".{$new_ext}"; $filename = trailingslashit( $dir ) . wp_basename( $filename, ".$ext" ) . ".{$new_ext}";
} }
@ -375,9 +371,8 @@ abstract class WP_Image_Editor {
if ( ! $suffix ) if ( ! $suffix )
$suffix = $this->get_suffix(); $suffix = $this->get_suffix();
$info = pathinfo( $this->file ); $dir = pathinfo( $this->file, PATHINFO_DIRNAME );
$dir = $info['dirname']; $ext = pathinfo( $this->file, PATHINFO_EXTENSION );
$ext = $info['extension'];
$name = wp_basename( $this->file, ".$ext" ); $name = wp_basename( $this->file, ".$ext" );
$new_ext = strtolower( $extension ? $extension : $ext ); $new_ext = strtolower( $extension ? $extension : $ext );

View File

@ -2034,13 +2034,16 @@ function wp_unique_filename( $dir, $filename, $unique_filename_callback = null )
$filename = sanitize_file_name($filename); $filename = sanitize_file_name($filename);
// Separate the filename into a name and extension. // Separate the filename into a name and extension.
$info = pathinfo($filename); $ext = pathinfo( $filename, PATHINFO_EXTENSION );
$ext = !empty($info['extension']) ? '.' . $info['extension'] : ''; $name = pathinfo( $filename, PATHINFO_BASENAME );
$name = basename($filename, $ext); if ( $ext ) {
$ext = '.' . $ext;
}
// Edge case: if file is named '.ext', treat as an empty name. // Edge case: if file is named '.ext', treat as an empty name.
if ( $name === $ext ) if ( $name === $ext ) {
$name = ''; $name = '';
}
/* /*
* Increment the file number until we have a unique file to save in $dir. * Increment the file number until we have a unique file to save in $dir.

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.7-alpha-38293'; $wp_version = '4.7-alpha-38294';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.