Make WordPress Core


Ignore:
Timestamp:
04/20/2009 06:18:39 PM (16 years ago)
Author:
ryan
Message:

Trailing whitespace cleanup

File:
1 edited

Legend:

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

    r11012 r11013  
    2020    var $skin = null;
    2121    var $result = array();
    22    
     22
    2323    function WP_Upgrader(&$skin = null) {
    2424        return __construct($skin);
     
    3131        $this->skin->set_upgrader($this);
    3232    }
    33    
     33
    3434    function generic_strings() {
    3535        $this->strings['bad_request'] = __('Invalid Data provided.');
     
    4747        $this->strings['mkdir_failed'] = __('Could not create directory.');
    4848        $this->strings['bad_package'] = __('Incompatible Archive');
    49        
     49
    5050        $this->strings['maintenance_start'] = __('Enabling Maintenance mode.');
    5151        $this->strings['maintenance_end'] = __('Disabling Maintenance mode.');
    5252    }
    53    
     53
    5454    function fs_connect( $directories = array() ) {
    5555        global $wp_filesystem;
    56    
     56
    5757        if ( false === ($credentials = $this->skin->request_filesystem_credentials()) )
    5858            return false;
    59    
     59
    6060        if ( ! WP_Filesystem($credentials) ) {
    6161            $error = true;
     
    6868        if ( ! is_object($wp_filesystem) )
    6969            return new WP_Error('fs_unavailable', $this->strings['fs_unavailable'] );
    70    
     70
    7171        if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() )
    7272            return new WP_Error('fs_error', $this->strings['fs_error'], $wp_filesystem->errors);
     
    9595        if ( ! preg_match('!^(http|https|ftp)://!i', $package) && file_exists($package) ) //Local file or remote?
    9696            return $package; //must be a local file..
    97        
     97
    9898        if ( empty($package) )
    9999            return new WP_Error('no_package', $this->strings['no_package']);
     
    102102
    103103        $download_file = download_url($package);
    104    
     104
    105105        if ( is_wp_error($download_file) )
    106106            return new WP_Error('download_failed', $this->strings['download_failed'], $download_file->get_error_message());
    107        
     107
    108108        return $download_file;
    109109    }
    110    
     110
    111111    function unpack_package($package, $delete_package = true) {
    112112        global $wp_filesystem;
    113        
     113
    114114        $this->skin->feedback('unpack_package');
    115115
     
    141141            return $result;
    142142        }
    143        
     143
    144144        return $working_dir;
    145145    }
    146    
     146
    147147    function install_package($args = array()) {
    148148        global $wp_filesystem;
     
    158158        if ( empty($source) || empty($destination) )
    159159            return new WP_Error('bad_request', $this->strings['bad_request']);
    160        
     160
    161161        $this->skin->feedback('installing_package');
    162162
     
    168168        $remote_source = $source;
    169169        $local_destination = $destination;
    170        
     170
    171171        $source_files = array_keys( $wp_filesystem->dirlist($remote_source) );
    172172        $remote_destination = $wp_filesystem->find_folder($local_destination);
     
    178178            return new WP_Error('bad_package', $this->strings['bad_package']); //There are no files?
    179179        //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
    181181        //Hook ability to change the source file location..
    182182        $source = apply_filters('upgrader_source_selection', $source, $remote_source, $this);
    183183        if ( is_wp_error($source) )
    184184            return $source;
    185        
     185
    186186        //Has the source location changed? If so, we need a new source_files list.
    187187        if ( $source !== $remote_source )
    188188            $source_files = array_keys( $wp_filesystem->dirlist($source) );
    189        
     189
    190190        //Protection against deleting files in any important base directories.
    191191        if ( in_array( $destination, array(ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes') ) ) {
     
    213213                return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
    214214        }
    215        
     215
    216216        //Create destination if needed
    217217        if ( !$wp_filesystem->exists($remote_destination) )
    218218            if ( !$wp_filesystem->mkdir($remote_destination, FS_CHMOD_DIR) )
    219219                return new WP_Error('mkdir_failed', $this->strings['mkdir_failed'], $remote_destination);
    220        
     220
    221221        // Copy new version of item into place.
    222222        $result = copy_dir($source, $remote_destination);
     
    226226            return $result;
    227227        }
    228        
    229         //Clear the Working folder? 
     228
     229        //Clear the Working folder?
    230230        if ( $clear_working )
    231231            $wp_filesystem->delete($remote_source, true);
    232        
     232
    233233        $destination_name = basename( str_replace($local_destination, '', $destination) );
    234234        if ( '.' == $destination_name )
     
    246246        return $this->result;
    247247    }
    248    
     248
    249249    function run($options) {
    250250
     
    278278            return $download;
    279279        }
    280        
     280
    281281        //Unzip's the file into a temporary directory
    282282        $working_dir = $this->unpack_package( $download );
     
    287287
    288288        //With the given options, this installs it to the destination directory.
    289         $result = $this->install_package( array( 
     289        $result = $this->install_package( array(
    290290                                            'source' => $working_dir,
    291291                                            'destination' => $destination,
     
    306306        return $result;
    307307    }
    308    
     308
    309309    function maintenance_mode($enable = false) {
    310310        global $wp_filesystem;
     
    321321        }
    322322    }
    323    
     323
    324324}
    325325
     
    327327
    328328    var $result;
    329    
     329
    330330    function upgrade_strings() {
    331331        $this->generic_strings();
     
    352352
    353353    function install($package) {
    354        
     354
    355355        $this->install_strings();
    356356
     
    362362                    'hook_extra' => array()
    363363                    ));
    364    
     364
    365365        // Force refresh of plugin update information
    366366        delete_transient('update_plugins');
     
    369369
    370370    function upgrade($plugin) {
    371        
     371
    372372        $this->upgrade_strings();
    373        
     373
    374374        $current = get_transient( 'update_plugins' );
    375375        if ( !isset( $current->response[ $plugin ] ) ) {
     
    381381        // Get the URL to the zip file
    382382        $r = $current->response[ $plugin ];
    383        
     383
    384384        add_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'), 10, 2);
    385385        add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4);
     
    406406        delete_transient('update_plugins');
    407407    }
    408    
     408
    409409    //return plugin info.
    410410    function plugin_info() {
     
    412412            return false;
    413413        if ( empty($this->result['destination_name']) )
    414             return false; 
     414            return false;
    415415
    416416        $plugin = get_plugins('/' . $this->result['destination_name']); //Ensure to pass with leading slash
     
    420420        $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
    421421
    422         return $this->result['destination_name'] . '/' . $pluginfiles[0];   
     422        return $this->result['destination_name'] . '/' . $pluginfiles[0];
    423423    }
    424424
     
    437437            //Deactivate the plugin silently, Prevent deactivation hooks from running.
    438438            deactivate_plugins($plugin, true);
    439         }   
     439        }
    440440    }
    441441
     
    443443    function delete_old_plugin($removed, $local_destination, $remote_destination, $plugin) {
    444444        global $wp_filesystem;
    445    
     445
    446446        if ( is_wp_error($removed) )
    447447            return $removed; //Pass errors through.
    448    
     448
    449449        $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : '';
    450450        if ( empty($plugin) )
     
    453453        $plugins_dir = $wp_filesystem->wp_plugins_dir();
    454454        $this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) );
    455        
     455
    456456        if ( ! $wp_filesystem->exists($this_plugin_dir) ) //If its already vanished.
    457457            return $removed;
    458    
     458
    459459        // If plugin is in its own directory, recursively delete the directory.
    460460        if ( strpos($plugin, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory seperator AND that its not the root plugin folder
     
    465465        if ( ! $deleted )
    466466            return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
    467        
     467
    468468        return $removed;
    469469    }
     
    498498
    499499    function install($package) {
    500        
     500
    501501        $this->install_strings();
    502502
     
    507507                        'clear_working' => true
    508508                        );
    509        
     509
    510510        $this->run($options);
    511    
     511
    512512        if ( ! $this->result || is_wp_error($this->result) )
    513513            return $this->result;
    514    
     514
    515515        // Force refresh of theme update information
    516516        delete_transient('update_themes');
    517    
     517
    518518        if ( empty($result['destination_name']) )
    519             return false; 
     519            return false;
    520520        else
    521521            return $result['destination_name'];
     
    523523
    524524    function upgrade($theme) {
    525        
     525
    526526        $this->upgrade_strings();
    527        
     527
    528528        // Is an update available?
    529529        $current = get_transient( 'update_themes' );
    530530        if ( !isset( $current->response[ $theme ] ) )
    531531            return new WP_Error('up_to_date', $this->strings['up_to_date']);
    532        
     532
    533533        $r = $current->response[ $theme ];
    534534
     
    546546                                            )
    547547                        );
    548        
     548
    549549        $this->run($options);
    550550
     
    557557        return true;
    558558    }
    559    
     559
    560560    function current_before($return, $theme) {
    561        
     561
    562562        if ( is_wp_error($return) )
    563563            return $return;
     
    593593        return $return;
    594594    }
    595    
     595
    596596    function delete_old_theme($removed, $local_destination, $remote_destination, $theme) {
    597597        global $wp_filesystem;
    598    
     598
    599599        $theme = isset($theme['theme']) ? $theme['theme'] : '';
    600    
     600
    601601        if ( is_wp_error($removed) || empty($theme) )
    602602            return $removed; //Pass errors through.
    603        
     603
    604604        $themes_dir = $wp_filesystem->wp_themes_dir();
    605605        if ( $wp_filesystem->exists( trailingslashit($themes_dir) . $theme ) )
     
    608608        return true;
    609609    }
    610    
     610
    611611    function theme_info() {
    612612        if ( empty($this->result['destination_name']) )
     
    632632        global $wp_filesystem;
    633633        $this->upgrade_strings();
    634        
    635    
     634
     635
    636636        if ( !empty($feedback) )
    637637            add_filter('update_feedback', $feedback);
    638    
     638
    639639        // Is an update available?
    640640        if ( !isset( $current->response ) || $current->response == 'latest' )
     
    644644        if ( is_wp_error($res) )
    645645            return $res;
    646        
     646
    647647        $wp_dir = trailingslashit($wp_filesystem->abspath());
    648        
     648
    649649        $download = $this->download_package( $current->package );
    650650        if ( is_wp_error($download) )
    651651            return $download;
    652        
     652
    653653        $working_dir = $this->unpack_package( $download );
    654654        if ( is_wp_error($working_dir) )
     
    661661        }
    662662        $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
    663    
     663
    664664        require(ABSPATH . 'wp-admin/includes/update-core.php');
    665    
     665
    666666        return update_core($working_dir, $wp_dir);
    667667    }
     
    678678
    679679class WP_Upgrader_Skin {
    680    
     680
    681681    var $upgrader;
    682682    var $done_header = false;
    683    
     683
    684684    function WP_Upgrader_Skin($args = array()) {
    685685        return __construct($args);
     
    689689        $this->options = wp_parse_args($args, $defaults);
    690690    }
    691    
     691
    692692    function set_upgrader(&$upgrader) {
    693693        if ( is_object($upgrader) )
     
    697697        $this->result = $result;
    698698    }
    699    
     699
    700700    function request_filesystem_credentials($error = false) {
    701701        $url = $this->options['url'];
     
    704704        return request_filesystem_credentials($url, '', $error); //Possible to bring inline, Leaving as0is for now.
    705705    }
    706    
     706
    707707    function header() {
    708708        if ( $this->done_header )
     
    711711        echo '<div class="wrap">';
    712712        echo screen_icon();
    713         echo '<h2>' . $this->options['title'] . '</h2>';   
     713        echo '<h2>' . $this->options['title'] . '</h2>';
    714714    }
    715715    function footer() {
    716716        echo '</div>';
    717717    }
    718    
     718
    719719    function error($errors) {
    720720        if ( ! $this->done_header )
     
    739739            return;
    740740        show_message($string);
    741     }   
     741    }
    742742    function before() {}
    743743    function after() {}
    744    
     744
    745745}
    746746
     
    760760
    761761        $this->plugin_active = is_plugin_active($this->plugin);
    762        
     762
    763763        parent::__construct($args);
    764764    }
    765    
     765
    766766    function after() {
    767767        $this->plugin = $this->upgrader->plugin_info();
     
    797797        $defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' );
    798798        $args = wp_parse_args($args, $defaults);
    799        
     799
    800800        $this->type = $args['type'];
    801801        $this->api = isset($args['api']) ? $args['api'] : array();
    802        
     802
    803803        parent::__construct($args);
    804804    }
     
    808808            $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin <strong>%s %s</strong>.'), $this->api->name, $this->api->version);
    809809    }
    810    
     810
    811811    function after() {
    812812
     
    843843        $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' );
    844844        $args = wp_parse_args($args, $defaults);
    845        
     845
    846846        $this->type = $args['type'];
    847847        $this->api = isset($args['api']) ? $args['api'] : array();
    848        
     848
    849849        parent::__construct($args);
    850850    }
     
    854854            $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the theme <strong>%s %s</strong>.'), $this->api->name, $this->api->version);
    855855    }
    856    
     856
    857857    function after() {
    858858        if ( empty($this->upgrader->result['destination_name']) )
     
    865865        $stylesheet = $this->upgrader->result['destination_name'];
    866866        $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet;
    867        
     867
    868868        $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), trailingslashit(clean_url(get_option('home'))) ) );
    869869        $activate_link = wp_nonce_url("themes.php?action=activate&amp;template=" . urlencode($template) . "&amp;stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template);
    870        
     870
    871871        $install_actions = array(
    872872            'preview' => '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . attribute_escape(sprintf(__('Preview "%s"'), $name)) . '">' . __('Preview') . '</a>',
     
    900900
    901901        $this->theme = $args['theme'];
    902        
     902
    903903        parent::__construct($args);
    904904    }
    905    
     905
    906906    function after() {
    907907
     
    915915        $stylesheet = $this->upgrader->result['destination_name'];
    916916        $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet;
    917        
     917
    918918        $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), trailingslashit(clean_url(get_option('home'))) ) );
    919919        $activate_link = wp_nonce_url("themes.php?action=activate&amp;template=" . urlencode($template) . "&amp;stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template);
     
    926926        if ( ( ! $this->result || is_wp_error($this->result) ) || $stylesheet == get_stylesheet() )
    927927            unset($update_actions['preview'], $update_actions['activate']);
    928    
     928
    929929        $update_actions = apply_filters('update_theme_complete_actions', $update_actions, $this->theme);
    930930        if ( ! empty($update_actions) )
     
    943943        if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) )
    944944            wp_die($uploads['error']);
    945        
     945
    946946        if ( empty($_FILES[$form]['name']) && empty($_GET[$urlholder]) )
    947947            wp_die(__('Please select a file'));
    948    
     948
    949949        if ( !empty($_FILES) )
    950950            $this->filename = $_FILES[$form]['name'];
     
    956956            $this->filename = wp_unique_filename( $uploads['basedir'], $this->filename );
    957957            $this->package = $uploads['basedir'] . '/' . $this->filename;
    958    
     958
    959959            // Move the file to the uploads dir
    960960            if ( false === @ move_uploaded_file( $_FILES[$form]['tmp_name'], $this->package) )
Note: See TracChangeset for help on using the changeset viewer.