Changeset 11013 for trunk/wp-admin/includes/class-wp-upgrader.php
- Timestamp:
- 04/20/2009 06:18:39 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/class-wp-upgrader.php
r11012 r11013 20 20 var $skin = null; 21 21 var $result = array(); 22 22 23 23 function WP_Upgrader(&$skin = null) { 24 24 return __construct($skin); … … 31 31 $this->skin->set_upgrader($this); 32 32 } 33 33 34 34 function generic_strings() { 35 35 $this->strings['bad_request'] = __('Invalid Data provided.'); … … 47 47 $this->strings['mkdir_failed'] = __('Could not create directory.'); 48 48 $this->strings['bad_package'] = __('Incompatible Archive'); 49 49 50 50 $this->strings['maintenance_start'] = __('Enabling Maintenance mode.'); 51 51 $this->strings['maintenance_end'] = __('Disabling Maintenance mode.'); 52 52 } 53 53 54 54 function fs_connect( $directories = array() ) { 55 55 global $wp_filesystem; 56 56 57 57 if ( false === ($credentials = $this->skin->request_filesystem_credentials()) ) 58 58 return false; 59 59 60 60 if ( ! WP_Filesystem($credentials) ) { 61 61 $error = true; … … 68 68 if ( ! is_object($wp_filesystem) ) 69 69 return new WP_Error('fs_unavailable', $this->strings['fs_unavailable'] ); 70 70 71 71 if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() ) 72 72 return new WP_Error('fs_error', $this->strings['fs_error'], $wp_filesystem->errors); … … 95 95 if ( ! preg_match('!^(http|https|ftp)://!i', $package) && file_exists($package) ) //Local file or remote? 96 96 return $package; //must be a local file.. 97 97 98 98 if ( empty($package) ) 99 99 return new WP_Error('no_package', $this->strings['no_package']); … … 102 102 103 103 $download_file = download_url($package); 104 104 105 105 if ( is_wp_error($download_file) ) 106 106 return new WP_Error('download_failed', $this->strings['download_failed'], $download_file->get_error_message()); 107 107 108 108 return $download_file; 109 109 } 110 110 111 111 function unpack_package($package, $delete_package = true) { 112 112 global $wp_filesystem; 113 113 114 114 $this->skin->feedback('unpack_package'); 115 115 … … 141 141 return $result; 142 142 } 143 143 144 144 return $working_dir; 145 145 } 146 146 147 147 function install_package($args = array()) { 148 148 global $wp_filesystem; … … 158 158 if ( empty($source) || empty($destination) ) 159 159 return new WP_Error('bad_request', $this->strings['bad_request']); 160 160 161 161 $this->skin->feedback('installing_package'); 162 162 … … 168 168 $remote_source = $source; 169 169 $local_destination = $destination; 170 170 171 171 $source_files = array_keys( $wp_filesystem->dirlist($remote_source) ); 172 172 $remote_destination = $wp_filesystem->find_folder($local_destination); … … 178 178 return new WP_Error('bad_package', $this->strings['bad_package']); //There are no files? 179 179 //else //Its only a single file, The upgrader will use the foldername of this file as the destination folder. foldername is based on zip filename. 180 180 181 181 //Hook ability to change the source file location.. 182 182 $source = apply_filters('upgrader_source_selection', $source, $remote_source, $this); 183 183 if ( is_wp_error($source) ) 184 184 return $source; 185 185 186 186 //Has the source location changed? If so, we need a new source_files list. 187 187 if ( $source !== $remote_source ) 188 188 $source_files = array_keys( $wp_filesystem->dirlist($source) ); 189 189 190 190 //Protection against deleting files in any important base directories. 191 191 if ( in_array( $destination, array(ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes') ) ) { … … 213 213 return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']); 214 214 } 215 215 216 216 //Create destination if needed 217 217 if ( !$wp_filesystem->exists($remote_destination) ) 218 218 if ( !$wp_filesystem->mkdir($remote_destination, FS_CHMOD_DIR) ) 219 219 return new WP_Error('mkdir_failed', $this->strings['mkdir_failed'], $remote_destination); 220 220 221 221 // Copy new version of item into place. 222 222 $result = copy_dir($source, $remote_destination); … … 226 226 return $result; 227 227 } 228 229 //Clear the Working folder? 228 229 //Clear the Working folder? 230 230 if ( $clear_working ) 231 231 $wp_filesystem->delete($remote_source, true); 232 232 233 233 $destination_name = basename( str_replace($local_destination, '', $destination) ); 234 234 if ( '.' == $destination_name ) … … 246 246 return $this->result; 247 247 } 248 248 249 249 function run($options) { 250 250 … … 278 278 return $download; 279 279 } 280 280 281 281 //Unzip's the file into a temporary directory 282 282 $working_dir = $this->unpack_package( $download ); … … 287 287 288 288 //With the given options, this installs it to the destination directory. 289 $result = $this->install_package( array( 289 $result = $this->install_package( array( 290 290 'source' => $working_dir, 291 291 'destination' => $destination, … … 306 306 return $result; 307 307 } 308 308 309 309 function maintenance_mode($enable = false) { 310 310 global $wp_filesystem; … … 321 321 } 322 322 } 323 323 324 324 } 325 325 … … 327 327 328 328 var $result; 329 329 330 330 function upgrade_strings() { 331 331 $this->generic_strings(); … … 352 352 353 353 function install($package) { 354 354 355 355 $this->install_strings(); 356 356 … … 362 362 'hook_extra' => array() 363 363 )); 364 364 365 365 // Force refresh of plugin update information 366 366 delete_transient('update_plugins'); … … 369 369 370 370 function upgrade($plugin) { 371 371 372 372 $this->upgrade_strings(); 373 373 374 374 $current = get_transient( 'update_plugins' ); 375 375 if ( !isset( $current->response[ $plugin ] ) ) { … … 381 381 // Get the URL to the zip file 382 382 $r = $current->response[ $plugin ]; 383 383 384 384 add_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'), 10, 2); 385 385 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4); … … 406 406 delete_transient('update_plugins'); 407 407 } 408 408 409 409 //return plugin info. 410 410 function plugin_info() { … … 412 412 return false; 413 413 if ( empty($this->result['destination_name']) ) 414 return false; 414 return false; 415 415 416 416 $plugin = get_plugins('/' . $this->result['destination_name']); //Ensure to pass with leading slash … … 420 420 $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list 421 421 422 return $this->result['destination_name'] . '/' . $pluginfiles[0]; 422 return $this->result['destination_name'] . '/' . $pluginfiles[0]; 423 423 } 424 424 … … 437 437 //Deactivate the plugin silently, Prevent deactivation hooks from running. 438 438 deactivate_plugins($plugin, true); 439 } 439 } 440 440 } 441 441 … … 443 443 function delete_old_plugin($removed, $local_destination, $remote_destination, $plugin) { 444 444 global $wp_filesystem; 445 445 446 446 if ( is_wp_error($removed) ) 447 447 return $removed; //Pass errors through. 448 448 449 449 $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : ''; 450 450 if ( empty($plugin) ) … … 453 453 $plugins_dir = $wp_filesystem->wp_plugins_dir(); 454 454 $this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) ); 455 455 456 456 if ( ! $wp_filesystem->exists($this_plugin_dir) ) //If its already vanished. 457 457 return $removed; 458 458 459 459 // If plugin is in its own directory, recursively delete the directory. 460 460 if ( strpos($plugin, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory seperator AND that its not the root plugin folder … … 465 465 if ( ! $deleted ) 466 466 return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']); 467 467 468 468 return $removed; 469 469 } … … 498 498 499 499 function install($package) { 500 500 501 501 $this->install_strings(); 502 502 … … 507 507 'clear_working' => true 508 508 ); 509 509 510 510 $this->run($options); 511 511 512 512 if ( ! $this->result || is_wp_error($this->result) ) 513 513 return $this->result; 514 514 515 515 // Force refresh of theme update information 516 516 delete_transient('update_themes'); 517 517 518 518 if ( empty($result['destination_name']) ) 519 return false; 519 return false; 520 520 else 521 521 return $result['destination_name']; … … 523 523 524 524 function upgrade($theme) { 525 525 526 526 $this->upgrade_strings(); 527 527 528 528 // Is an update available? 529 529 $current = get_transient( 'update_themes' ); 530 530 if ( !isset( $current->response[ $theme ] ) ) 531 531 return new WP_Error('up_to_date', $this->strings['up_to_date']); 532 532 533 533 $r = $current->response[ $theme ]; 534 534 … … 546 546 ) 547 547 ); 548 548 549 549 $this->run($options); 550 550 … … 557 557 return true; 558 558 } 559 559 560 560 function current_before($return, $theme) { 561 561 562 562 if ( is_wp_error($return) ) 563 563 return $return; … … 593 593 return $return; 594 594 } 595 595 596 596 function delete_old_theme($removed, $local_destination, $remote_destination, $theme) { 597 597 global $wp_filesystem; 598 598 599 599 $theme = isset($theme['theme']) ? $theme['theme'] : ''; 600 600 601 601 if ( is_wp_error($removed) || empty($theme) ) 602 602 return $removed; //Pass errors through. 603 603 604 604 $themes_dir = $wp_filesystem->wp_themes_dir(); 605 605 if ( $wp_filesystem->exists( trailingslashit($themes_dir) . $theme ) ) … … 608 608 return true; 609 609 } 610 610 611 611 function theme_info() { 612 612 if ( empty($this->result['destination_name']) ) … … 632 632 global $wp_filesystem; 633 633 $this->upgrade_strings(); 634 635 634 635 636 636 if ( !empty($feedback) ) 637 637 add_filter('update_feedback', $feedback); 638 638 639 639 // Is an update available? 640 640 if ( !isset( $current->response ) || $current->response == 'latest' ) … … 644 644 if ( is_wp_error($res) ) 645 645 return $res; 646 646 647 647 $wp_dir = trailingslashit($wp_filesystem->abspath()); 648 648 649 649 $download = $this->download_package( $current->package ); 650 650 if ( is_wp_error($download) ) 651 651 return $download; 652 652 653 653 $working_dir = $this->unpack_package( $download ); 654 654 if ( is_wp_error($working_dir) ) … … 661 661 } 662 662 $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE); 663 663 664 664 require(ABSPATH . 'wp-admin/includes/update-core.php'); 665 665 666 666 return update_core($working_dir, $wp_dir); 667 667 } … … 678 678 679 679 class WP_Upgrader_Skin { 680 680 681 681 var $upgrader; 682 682 var $done_header = false; 683 683 684 684 function WP_Upgrader_Skin($args = array()) { 685 685 return __construct($args); … … 689 689 $this->options = wp_parse_args($args, $defaults); 690 690 } 691 691 692 692 function set_upgrader(&$upgrader) { 693 693 if ( is_object($upgrader) ) … … 697 697 $this->result = $result; 698 698 } 699 699 700 700 function request_filesystem_credentials($error = false) { 701 701 $url = $this->options['url']; … … 704 704 return request_filesystem_credentials($url, '', $error); //Possible to bring inline, Leaving as0is for now. 705 705 } 706 706 707 707 function header() { 708 708 if ( $this->done_header ) … … 711 711 echo '<div class="wrap">'; 712 712 echo screen_icon(); 713 echo '<h2>' . $this->options['title'] . '</h2>'; 713 echo '<h2>' . $this->options['title'] . '</h2>'; 714 714 } 715 715 function footer() { 716 716 echo '</div>'; 717 717 } 718 718 719 719 function error($errors) { 720 720 if ( ! $this->done_header ) … … 739 739 return; 740 740 show_message($string); 741 } 741 } 742 742 function before() {} 743 743 function after() {} 744 744 745 745 } 746 746 … … 760 760 761 761 $this->plugin_active = is_plugin_active($this->plugin); 762 762 763 763 parent::__construct($args); 764 764 } 765 765 766 766 function after() { 767 767 $this->plugin = $this->upgrader->plugin_info(); … … 797 797 $defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' ); 798 798 $args = wp_parse_args($args, $defaults); 799 799 800 800 $this->type = $args['type']; 801 801 $this->api = isset($args['api']) ? $args['api'] : array(); 802 802 803 803 parent::__construct($args); 804 804 } … … 808 808 $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin <strong>%s %s</strong>.'), $this->api->name, $this->api->version); 809 809 } 810 810 811 811 function after() { 812 812 … … 843 843 $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' ); 844 844 $args = wp_parse_args($args, $defaults); 845 845 846 846 $this->type = $args['type']; 847 847 $this->api = isset($args['api']) ? $args['api'] : array(); 848 848 849 849 parent::__construct($args); 850 850 } … … 854 854 $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the theme <strong>%s %s</strong>.'), $this->api->name, $this->api->version); 855 855 } 856 856 857 857 function after() { 858 858 if ( empty($this->upgrader->result['destination_name']) ) … … 865 865 $stylesheet = $this->upgrader->result['destination_name']; 866 866 $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet; 867 867 868 868 $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), trailingslashit(clean_url(get_option('home'))) ) ); 869 869 $activate_link = wp_nonce_url("themes.php?action=activate&template=" . urlencode($template) . "&stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template); 870 870 871 871 $install_actions = array( 872 872 'preview' => '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . attribute_escape(sprintf(__('Preview "%s"'), $name)) . '">' . __('Preview') . '</a>', … … 900 900 901 901 $this->theme = $args['theme']; 902 902 903 903 parent::__construct($args); 904 904 } 905 905 906 906 function after() { 907 907 … … 915 915 $stylesheet = $this->upgrader->result['destination_name']; 916 916 $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet; 917 917 918 918 $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), trailingslashit(clean_url(get_option('home'))) ) ); 919 919 $activate_link = wp_nonce_url("themes.php?action=activate&template=" . urlencode($template) . "&stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template); … … 926 926 if ( ( ! $this->result || is_wp_error($this->result) ) || $stylesheet == get_stylesheet() ) 927 927 unset($update_actions['preview'], $update_actions['activate']); 928 928 929 929 $update_actions = apply_filters('update_theme_complete_actions', $update_actions, $this->theme); 930 930 if ( ! empty($update_actions) ) … … 943 943 if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) ) 944 944 wp_die($uploads['error']); 945 945 946 946 if ( empty($_FILES[$form]['name']) && empty($_GET[$urlholder]) ) 947 947 wp_die(__('Please select a file')); 948 948 949 949 if ( !empty($_FILES) ) 950 950 $this->filename = $_FILES[$form]['name']; … … 956 956 $this->filename = wp_unique_filename( $uploads['basedir'], $this->filename ); 957 957 $this->package = $uploads['basedir'] . '/' . $this->filename; 958 958 959 959 // Move the file to the uploads dir 960 960 if ( false === @ move_uploaded_file( $_FILES[$form]['tmp_name'], $this->package) )
Note: See TracChangeset
for help on using the changeset viewer.