Make WordPress Core


Ignore:
Timestamp:
11/05/2008 05:07:45 PM (18 years ago)
Author:
ryan
Message:

Support installation of plugins living in a subdir in svn. Props DD32. fixes #7395

File:
1 edited

Legend:

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

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