Changeset 9523
- Timestamp:
- 11/05/2008 05:07:45 PM (16 years ago)
- Location:
- trunk/wp-admin/includes
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/file.php
r9493 r9523 483 483 return new WP_Error('empty_archive', __('Empty archive')); 484 484 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 485 493 $path = explode('/', untrailingslashit($to)); 486 494 for ( $i = count($path); $i > 0; $i-- ) { //>0 = first element is empty allways for paths starting with '/' … … 560 568 } 561 569 } 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 */ 583 function 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'); 562 618 } 563 619 -
trunk/wp-admin/includes/plugin-install.php
r9521 r9523 745 745 } 746 746 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 747 apply_filters('install_feedback', __('Installing the plugin')); 748 748 749 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) ); 749 750 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 755 apply_filters('install_feedback', __('Installing the plugin')); 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'] ) ) 757 return new WP_Error('mkdir_failed', __('Could not create directory'), $res['to']); 758 756 759 // Copy new version of plugin into place. 757 $result = copy_dir($ working_dir, $plugins_dir);760 $result = copy_dir($res['from'], $res['to']); 758 761 if ( is_wp_error($result) ) { 759 762 $wp_filesystem->delete($working_dir, true); … … 761 764 } 762 765 763 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin764 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );765 766 766 // Remove working directory 767 767 $wp_filesystem->delete($working_dir, true); 768 768 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]; 769 $folder = trailingslashit(str_replace($plugins_dir, '', $res['to'])); 773 770 $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash 774 771 $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list 775 772 776 773 //Return the plugin files name. 777 return $folder . '/'. $pluginfiles[0];774 return $folder . $pluginfiles[0]; 778 775 } 779 776 … … 840 837 } 841 838 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 839 apply_filters('install_feedback', __('Installing the plugin')); 840 843 841 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) ); 844 842 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 850 apply_filters('install_feedback', __('Installing the plugin')); 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'] ) ) 849 return new WP_Error('mkdir_failed', __('Could not create directory'), $res['to']); 850 851 851 // Copy new version of plugin into place. 852 $result = copy_dir($ working_dir, $plugins_dir);852 $result = copy_dir($res['from'], $res['to']); 853 853 if ( is_wp_error($result) ) { 854 854 $wp_filesystem->delete($working_dir, true); … … 856 856 } 857 857 858 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin859 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );860 861 858 // Remove working directory 862 859 $wp_filesystem->delete($working_dir, true); 863 860 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]; 861 $folder = trailingslashit(str_replace($plugins_dir, '', $res['to'])); 868 862 $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash 869 863 $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list 870 864 871 865 //Return the plugin files name. 872 return $folder . '/'. $pluginfiles[0];866 return $folder . $pluginfiles[0]; 873 867 } 874 868 -
trunk/wp-admin/includes/update.php
r9512 r9523 247 247 248 248 apply_filters('update_feedback', __('Installing the latest version')); 249 250 $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'] ) ) 258 return new WP_Error('mkdir_failed', __('Could not create directory'), $res['to']); 259 249 260 // Copy new version of plugin into place. 250 $result = copy_dir($ working_dir, $plugins_dir);261 $result = copy_dir($res['from'], $res['to']); 251 262 if ( is_wp_error($result) ) { 252 263 $wp_filesystem->delete($working_dir, true); 253 264 return $result; 254 265 } 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 plugin257 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );258 266 259 267 // Remove working directory … … 263 271 delete_option('update_plugins'); 264 272 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]; 273 $folder = trailingslashit(str_replace($plugins_dir, '', $res['to'])); 269 274 $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash 270 275 $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list 271 276 272 return $folder . '/' . $pluginfiles[0]; 277 //Return the plugin files name. 278 return $folder . $pluginfiles[0]; 273 279 } 274 280
Note: See TracChangeset
for help on using the changeset viewer.