Ticket #37608: 37608.diff
File 37608.diff, 6.4 KB (added by , 8 years ago) |
---|
-
src/wp-admin/includes/file.php
77 77 function get_file_description( $file ) { 78 78 global $wp_file_descriptions, $allowed_files; 79 79 80 $relative_pathinfo = pathinfo( $file ); 80 $dirname = pathinfo( $file, PATHINFO_DIRNAME ); 81 81 82 $file_path = $allowed_files[ $file ]; 82 if ( isset( $wp_file_descriptions[ basename( $file ) ] ) && '.' === $ relative_pathinfo['dirname']) {83 if ( isset( $wp_file_descriptions[ basename( $file ) ] ) && '.' === $dirname ) { 83 84 return $wp_file_descriptions[ basename( $file ) ]; 84 85 } elseif ( file_exists( $file_path ) && is_file( $file_path ) ) { 85 86 $template_data = implode( '', file( $file_path ) ); -
src/wp-admin/includes/image-edit.php
761 761 $backup_sizes = array(); 762 762 763 763 // Generate new filename. 764 $path = get_attached_file($post_id); 765 $path_parts = pathinfo( $path ); 766 $filename = $path_parts['filename']; 764 $path = get_attached_file( $post_id ); 765 766 $basename = pathinfo( $path, PATHINFO_BASENAME ); 767 $dirname = pathinfo( $path, PATHINFO_DIRNAME ); 768 $ext = pathinfo( $path, PATHINFO_EXTENSION ); 769 $filename = pathinfo( $path, PATHINFO_FILENAME ); 767 770 $suffix = time() . rand(100, 999); 768 771 769 772 if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE && 770 isset($backup_sizes['full-orig']) && $backup_sizes['full-orig']['file'] != $ path_parts['basename']) {773 isset($backup_sizes['full-orig']) && $backup_sizes['full-orig']['file'] != $basename ) { 771 774 772 if ( 'thumbnail' == $target ) 773 $new_path = "{$ path_parts['dirname']}/{$filename}-temp.{$path_parts['extension']}";774 else775 if ( 'thumbnail' == $target ) { 776 $new_path = "{$dirname}/{$filename}-temp.{$ext}"; 777 } else { 775 778 $new_path = $path; 779 } 776 780 } else { 777 while ( true ) {781 while ( true ) { 778 782 $filename = preg_replace( '/-e([0-9]+)$/', '', $filename ); 779 783 $filename .= "-e{$suffix}"; 780 $new_filename = "{$filename}.{$ path_parts['extension']}";781 $new_path = "{$ path_parts['dirname']}/$new_filename";782 if ( file_exists($new_path) ) 784 $new_filename = "{$filename}.{$ext}"; 785 $new_path = "{$dirname}/$new_filename"; 786 if ( file_exists($new_path) ) { 783 787 $suffix++; 784 else788 } else { 785 789 break; 790 } 786 791 } 787 792 } 788 793 … … 792 797 return $return; 793 798 } 794 799 795 if ( 'nothumb' == $target || 'all' == $target || 'full'== $target || $scaled ) {800 if ( 'nothumb' === $target || 'all' === $target || 'full' === $target || $scaled ) { 796 801 $tag = false; 797 if ( isset( $backup_sizes['full-orig']) ) {798 if ( ( ! defined('IMAGE_EDIT_OVERWRITE') || !IMAGE_EDIT_OVERWRITE ) && $backup_sizes['full-orig']['file'] != $path_parts['basename'] )802 if ( isset( $backup_sizes['full-orig'] ) ) { 803 if ( ( ! defined( 'IMAGE_EDIT_OVERWRITE' ) || ! IMAGE_EDIT_OVERWRITE ) && $backup_sizes['full-orig']['file'] !== $basename ) { 799 804 $tag = "full-$suffix"; 805 } 800 806 } else { 801 807 $tag = 'full-orig'; 802 808 } 803 809 804 if ( $tag ) 805 $backup_sizes[$tag] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $ path_parts['basename']);806 810 if ( $tag ) { 811 $backup_sizes[$tag] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $basename ); 812 } 807 813 $success = ( $path === $new_path ) || update_attached_file( $post_id, $new_path ); 808 814 809 815 $meta['file'] = _wp_relative_upload_path( $new_path ); … … 834 840 if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE && ! empty( $meta['sizes'] ) ) { 835 841 foreach ( $meta['sizes'] as $size ) { 836 842 if ( ! empty( $size['file'] ) && preg_match( '/-e[0-9]{13}-/', $size['file'] ) ) { 837 $delete_file = path_join( $ path_parts['dirname'], $size['file'] );843 $delete_file = path_join( $dirname, $size['file'] ); 838 844 wp_delete_file( $delete_file ); 839 845 } 840 846 } -
src/wp-admin/includes/media.php
284 284 if ( isset($file['error']) ) 285 285 return new WP_Error( 'upload_error', $file['error'] ); 286 286 287 $name_parts = pathinfo($name); 288 $name = trim( substr( $name, 0, -(1 + strlen($name_parts['extension'])) ) ); 287 $basename = pathinfo( $name, PATHINFO_BASENAME ); 289 288 290 289 $url = $file['url']; 291 290 $type = $file['type']; 292 291 $file = $file['file']; 293 $title = $ name;292 $title = $basename; 294 293 $content = ''; 295 294 $excerpt = ''; 296 295 -
src/wp-includes/class-wp-image-editor.php
346 346 } 347 347 348 348 if ( $filename ) { 349 $ext = ''; 350 $info = pathinfo( $filename ); 351 $dir = $info['dirname']; 349 $dir = pathinfo( $filename, PATHINFO_DIRNAME ); 350 $ext = pathinfo( $filename, PATHINFO_EXTENSION ); 352 351 353 if ( isset( $info['extension'] ) )354 $ext = $info['extension'];355 356 352 $filename = trailingslashit( $dir ) . wp_basename( $filename, ".$ext" ) . ".{$new_ext}"; 357 353 } 358 354 … … 375 371 if ( ! $suffix ) 376 372 $suffix = $this->get_suffix(); 377 373 378 $info = pathinfo( $this->file ); 379 $dir = $info['dirname']; 380 $ext = $info['extension']; 374 $dir = pathinfo( $this->file, PATHINFO_DIRNAME ); 375 $ext = pathinfo( $this->file, PATHINFO_EXTENSION ); 381 376 382 377 $name = wp_basename( $this->file, ".$ext" ); 383 378 $new_ext = strtolower( $extension ? $extension : $ext ); -
src/wp-includes/functions.php
2034 2034 $filename = sanitize_file_name($filename); 2035 2035 2036 2036 // Separate the filename into a name and extension. 2037 $info = pathinfo($filename); 2038 $ext = !empty($info['extension']) ? '.' . $info['extension'] : ''; 2039 $name = basename($filename, $ext); 2037 $ext = pathinfo( $filename, PATHINFO_EXTENSION ); 2038 $name = pathinfo( $filename, PATHINFO_BASENAME ); 2039 if ( $ext ) { 2040 $ext = '.' . $ext; 2041 } 2040 2042 2041 2043 // Edge case: if file is named '.ext', treat as an empty name. 2042 if ( $name === $ext ) 2044 if ( $name === $ext ) { 2043 2045 $name = ''; 2046 } 2044 2047 2045 2048 /* 2046 2049 * Increment the file number until we have a unique file to save in $dir.