Make WordPress Core

Changeset 9664


Ignore:
Timestamp:
11/13/2008 06:48:54 PM (16 years ago)
Author:
ryan
Message:

Revert [9523]. fixes #8195 see #7395

Location:
trunk/wp-admin/includes
Files:
3 edited

Legend:

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

    r9663 r9664  
    486486        return new WP_Error('empty_archive', __('Empty archive'));
    487487
    488     //Prepend another directory level if there are files in the root directory of the zip
    489     foreach ( $archive_files as $archive_file ) {
    490         if ( false === strpos($archive_file['filename'], '/') ) {
    491             $to = trailingslashit($to) . basename($file, '.zip');
    492             break;
    493         }
    494     }
    495 
    496488    $path = explode('/', untrailingslashit($to));
    497489    for ( $i = count($path); $i > 0; $i-- ) { //>0 = first element is empty allways for paths starting with '/'
     
    571563        }
    572564    }
    573 }
    574 
    575 /**
    576  * Locates the lowest safe directory in a Plugin folder to copy to the plugins directory.
    577  *
    578  * Note: Desination directory will allways be unique.
    579  *
    580  * @since 2.7.0
    581  *
    582  * @param string $from the Working directory of the plugin files
    583  * @param string $to the proposed destination for the for the plugin files
    584  * @return array an array of the keys 'from' and 'to' for the actual copy.
    585  */
    586 function update_pluginfiles_base_dir($from, $to) {
    587     $files = list_files($from);
    588 
    589     //Remove non-php files
    590     foreach ( (array)$files as $key => $file )
    591         if ( ! preg_match('!.php$!i', $file) )
    592             unset($files[$key]);
    593 
    594     //remove non-plugin files
    595     foreach ( (array)$files as $key => $file ) {
    596         $details = get_plugin_data($file, false, false);
    597         if ( empty($details['Name']) )
    598             unset($files[$key]);
    599     }
    600 
    601     if ( empty($files) )
    602         return false;
    603 
    604     //Left with paths to files which ARE plugins.
    605     $min_num = 100; //assume no zips with deeper paths will come along
    606     $min_file = '';
    607     foreach ( (array)$files as $key => $file ) {
    608         $this_num = substr_count($file, '/');
    609         if ( $this_num < $min_num ) {
    610             $min_file = $file;
    611             $min_num = $this_num;
    612         }
    613     }
    614     unset($min_num);
    615 
    616     $from = dirname($min_file);
    617     //Ensure its a unique install folder, Upgrades delete the folder prior to this.
    618     $to = dirname($to) . '/' . wp_unique_filename(dirname($to), basename($to));
    619 
    620     return compact('from', 'to');
    621565}
    622566
  • trunk/wp-admin/includes/plugin-install.php

    r9619 r9664  
    745745    }
    746746
     747    //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin
     748    $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );
     749
     750    if( $wp_filesystem->exists( $plugins_dir . $filelist[0] ) ) {
     751        $wp_filesystem->delete($working_dir, true);
     752        return new WP_Error('install_folder_exists', __('Folder allready exists.'), $filelist[0] );
     753    }
     754
    747755    apply_filters('install_feedback', __('Installing the plugin'));
    748    
    749     $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );
    750 
    751     //find base plugin directory
    752     $res = update_pluginfiles_base_dir($working_dir . '/' . $filelist[0], $plugins_dir . $filelist[0]);
    753 
    754     //Create folder if not exists.
    755     if( ! $wp_filesystem->exists( $res['to'] ) )
    756         if ( ! $wp_filesystem->mkdir( $res['to'], 0755 ) )
    757             return new WP_Error('mkdir_failed', __('Could not create directory'), $res['to']); 
    758 
    759756    // Copy new version of plugin into place.
    760     $result = copy_dir($res['from'], $res['to']);
     757    $result = copy_dir($working_dir, $plugins_dir);
    761758    if ( is_wp_error($result) ) {
    762759        $wp_filesystem->delete($working_dir, true);
     
    764761    }
    765762
     763    //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin
     764    $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );
     765
    766766    // Remove working directory
    767767    $wp_filesystem->delete($working_dir, true);
    768768
    769     $folder = trailingslashit(str_replace($plugins_dir, '', $res['to']));
     769    if( empty($filelist) )
     770        return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup.
     771
     772    $folder = $filelist[0];
    770773    $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash
    771774    $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
    772775
    773776    //Return the plugin files name.
    774     return $folder . $pluginfiles[0];
     777    return  $folder . '/' . $pluginfiles[0];
    775778}
    776779
     
    837840    }
    838841
     842    //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin
     843    $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );
     844
     845    if( $wp_filesystem->exists( $plugins_dir . $filelist[0] ) ) {
     846        $wp_filesystem->delete($working_dir, true);
     847        return new WP_Error('install_folder_exists', __('Folder allready exists.'), $filelist[0] );
     848    }
     849
    839850    apply_filters('install_feedback', __('Installing the plugin'));
    840    
    841     $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );
    842 
    843     //find base plugin directory
    844     $res = update_pluginfiles_base_dir($working_dir . '/' . $filelist[0], $plugins_dir . $filelist[0]);
    845 
    846     //Create folder if not exists.
    847     if( ! $wp_filesystem->exists( $res['to'] ) ) {
    848         if ( ! $wp_filesystem->mkdir( $res['to'], 0755 ) )
    849             return new WP_Error('mkdir_failed', __('Could not create directory'), $res['to']);
    850     }
    851    
    852851    // Copy new version of plugin into place.
    853     $result = copy_dir($res['from'], $res['to']);
     852    $result = copy_dir($working_dir, $plugins_dir);
    854853    if ( is_wp_error($result) ) {
    855854        $wp_filesystem->delete($working_dir, true);
     
    857856    }
    858857
     858    //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin
     859    $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );
     860
    859861    // Remove working directory
    860862    $wp_filesystem->delete($working_dir, true);
    861863
    862     $folder = trailingslashit(str_replace($plugins_dir, '', $res['to']));
     864    if( empty($filelist) )
     865        return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup.
     866
     867    $folder = $filelist[0];
    863868    $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash
    864869    $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
    865870
    866871    //Return the plugin files name.
    867     return $folder . $pluginfiles[0];
     872    return  $folder . '/' . $pluginfiles[0];
    868873}
    869874
  • trunk/wp-admin/includes/update.php

    r9593 r9664  
    247247
    248248    apply_filters('update_feedback', __('Installing the latest version'));
    249 
     249    // Copy new version of plugin into place.
     250    $result = copy_dir($working_dir, $plugins_dir);
     251    if ( is_wp_error($result) ) {
     252        $wp_filesystem->delete($working_dir, true);
     253        return $result;
     254    }
     255
     256    //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin
    250257    $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );
    251 
    252     //find base plugin directory
    253     $res = update_pluginfiles_base_dir($working_dir . '/' . $filelist[0], $plugins_dir . $filelist[0]);
    254 
    255     //Create folder if not exists.
    256     if( ! $wp_filesystem->exists( $res['to'] ) )
    257         if ( ! $wp_filesystem->mkdir( $res['to'], 0755 ) )
    258             return new WP_Error('mkdir_failed', __('Could not create directory'), $res['to']); 
    259 
    260     // Copy new version of plugin into place.
    261     $result = copy_dir($res['from'], $res['to']);
    262     if ( is_wp_error($result) ) {
    263         $wp_filesystem->delete($working_dir, true);
    264         return $result;
    265     }
    266258
    267259    // Remove working directory
     
    271263    delete_option('update_plugins');
    272264
    273     $folder = trailingslashit(str_replace($plugins_dir, '', $res['to']));
     265    if( empty($filelist) )
     266        return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup.
     267
     268    $folder = $filelist[0];
    274269    $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash
    275270    $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
    276271
    277     //Return the plugin files name.
    278     return $folder . $pluginfiles[0];
     272    return  $folder . '/' . $pluginfiles[0];
    279273}
    280274
Note: See TracChangeset for help on using the changeset viewer.