Make WordPress Core

Changeset 38294


Ignore:
Timestamp:
08/20/2016 11:35:50 PM (8 years ago)
Author:
wonderboymusic
Message:

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

Props JaworskiMatt.
Fixes #37608.

Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/file.php

    r38235 r38294  
    7878    global $wp_file_descriptions, $allowed_files;
    7979
    80     $relative_pathinfo = pathinfo( $file );
     80    $dirname = pathinfo( $file, PATHINFO_DIRNAME );
     81
    8182    $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 ) {
    8384        return $wp_file_descriptions[ basename( $file ) ];
    8485    } elseif ( file_exists( $file_path ) && is_file( $file_path ) ) {
  • trunk/src/wp-admin/includes/image-edit.php

    r38139 r38294  
    762762
    763763    // 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 );
    767770    $suffix = time() . rand(100, 999);
    768771
    769772    if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE &&
    770         isset($backup_sizes['full-orig']) && $backup_sizes['full-orig']['file'] != $path_parts['basename'] ) {
    771 
    772         if ( 'thumbnail' == $target )
    773             $new_path = "{$path_parts['dirname']}/{$filename}-temp.{$path_parts['extension']}";
    774         else
     773        isset($backup_sizes['full-orig']) && $backup_sizes['full-orig']['file'] != $basename ) {
     774
     775        if ( 'thumbnail' == $target ) {
     776            $new_path = "{$dirname}/{$filename}-temp.{$ext}";
     777        } else {
    775778            $new_path = $path;
     779        }
    776780    } else {
    777         while( true ) {
     781        while ( true ) {
    778782            $filename = preg_replace( '/-e([0-9]+)$/', '', $filename );
    779783            $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) ) {
    783787                $suffix++;
    784             else
     788            } else {
    785789                break;
     790            }
    786791        }
    787792    }
     
    793798    }
    794799
    795     if ( 'nothumb' == $target || 'all' == $target || 'full' == $target || $scaled ) {
     800    if ( 'nothumb' === $target || 'all' === $target || 'full' === $target || $scaled ) {
    796801        $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 ) {
    799804                $tag = "full-$suffix";
     805            }
    800806        } else {
    801807            $tag = 'full-orig';
    802808        }
    803809
    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        }
    807813        $success = ( $path === $new_path ) || update_attached_file( $post_id, $new_path );
    808814
     
    835841        foreach ( $meta['sizes'] as $size ) {
    836842            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'] );
    838844                wp_delete_file( $delete_file );
    839845            }
  • trunk/src/wp-admin/includes/media.php

    r38029 r38294  
    285285        return new WP_Error( 'upload_error', $file['error'] );
    286286
    287     $name_parts = pathinfo($name);
    288     $name = trim( substr( $name, 0, -(1 + strlen($name_parts['extension'])) ) );
     287    $basename = pathinfo( $name, PATHINFO_BASENAME );
    289288
    290289    $url = $file['url'];
    291290    $type = $file['type'];
    292291    $file = $file['file'];
    293     $title = $name;
     292    $title = $basename;
    294293    $content = '';
    295294    $excerpt = '';
  • trunk/src/wp-includes/class-wp-image-editor.php

    r37492 r38294  
    347347
    348348        if ( $filename ) {
    349             $ext = '';
    350             $info = pathinfo( $filename );
    351             $dir  = $info['dirname'];
    352 
    353             if ( isset( $info['extension'] ) )
    354                 $ext = $info['extension'];
     349            $dir = pathinfo( $filename, PATHINFO_DIRNAME );
     350            $ext = pathinfo( $filename, PATHINFO_EXTENSION );
    355351
    356352            $filename = trailingslashit( $dir ) . wp_basename( $filename, ".$ext" ) . ".{$new_ext}";
     
    376372            $suffix = $this->get_suffix();
    377373
    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 );
    381376
    382377        $name = wp_basename( $this->file, ".$ext" );
  • trunk/src/wp-includes/functions.php

    r38152 r38294  
    20352035
    20362036    // 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    }
    20402042
    20412043    // Edge case: if file is named '.ext', treat as an empty name.
    2042     if ( $name === $ext )
     2044    if ( $name === $ext ) {
    20432045        $name = '';
     2046    }
    20442047
    20452048    /*
Note: See TracChangeset for help on using the changeset viewer.