~katiekitty/+junk/wordpress-byet

« back to all changes in this revision

Viewing changes to wp-admin/includes/class-wp-upgrader.php

  • Committer: kserver
  • Date: 2010-05-15 01:16:36 UTC
  • Revision ID: kserver@kserver-desktop-20100515011636-mnr1j7t637suptdq
Wordpress 2.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
                        return new WP_Error('fs_error', $this->strings['fs_error'], $wp_filesystem->errors);
82
82
 
83
83
                foreach ( (array)$directories as $dir ) {
84
 
                        if ( ABSPATH == $dir && ! $wp_filesystem->abspath() )
85
 
                                return new WP_Error('fs_no_root_dir', $this->strings['fs_no_root_dir']);
86
 
 
87
 
                        elseif ( WP_CONTENT_DIR == $dir && ! $wp_filesystem->wp_content_dir() )
88
 
                                return new WP_Error('fs_no_content_dir', $this->strings['fs_no_content_dir']);
89
 
 
90
 
                        elseif ( WP_PLUGIN_DIR == $dir && ! $wp_filesystem->wp_plugins_dir() )
91
 
                                return new WP_Error('fs_no_plugins_dir', $this->strings['fs_no_plugins_dir']);
92
 
 
93
 
                        elseif ( WP_CONTENT_DIR . '/themes' == $dir && ! $wp_filesystem->find_folder(WP_CONTENT_DIR . '/themes') )
94
 
                                return new WP_Error('fs_no_themes_dir', $this->strings['fs_no_themes_dir']);
95
 
 
96
 
                        elseif ( ! $wp_filesystem->find_folder($dir) )
97
 
                                return new WP_Error('fs_no_folder', sprintf($strings['fs_no_folder'], $dir));
 
84
                        switch ( $dir ) {
 
85
                                case ABSPATH:
 
86
                                        if ( ! $wp_filesystem->abspath() )
 
87
                                                return new WP_Error('fs_no_root_dir', $this->strings['fs_no_root_dir']);
 
88
                                        break;
 
89
                                case WP_CONTENT_DIR:
 
90
                                        if ( ! $wp_filesystem->wp_content_dir() )
 
91
                                                return new WP_Error('fs_no_content_dir', $this->strings['fs_no_content_dir']);
 
92
                                        break;
 
93
                                case WP_PLUGIN_DIR:
 
94
                                        if ( ! $wp_filesystem->wp_plugins_dir() )
 
95
                                                return new WP_Error('fs_no_plugins_dir', $this->strings['fs_no_plugins_dir']);
 
96
                                        break;
 
97
                                case WP_CONTENT_DIR . '/themes':
 
98
                                        if ( ! $wp_filesystem->find_folder(WP_CONTENT_DIR . '/themes') )
 
99
                                                return new WP_Error('fs_no_themes_dir', $this->strings['fs_no_themes_dir']);
 
100
                                        break;
 
101
                                default:
 
102
                                        if ( ! $wp_filesystem->find_folder($dir) )
 
103
                                                return new WP_Error('fs_no_folder', sprintf($this->strings['fs_no_folder'], $dir));
 
104
                                        break;
 
105
                        }
98
106
                }
99
107
                return true;
100
108
        } //end fs_connect();
202
210
                        $destination = trailingslashit($destination) . trailingslashit(basename($source));
203
211
                }
204
212
 
205
 
                //If we're not clearing the destination folder, and something exists there allready, Bail.
206
 
                if ( ! $clear_destination && $wp_filesystem->exists($remote_destination) ) {
207
 
                        $wp_filesystem->delete($remote_source, true); //Clear out the source files.
208
 
                        return new WP_Error('folder_exists', $this->strings['folder_exists'], $remote_destination );
209
 
                } else if ( $clear_destination ) {
210
 
                        //We're going to clear the destination if theres something there
211
 
                        $this->skin->feedback('remove_old');
212
 
 
213
 
                        $removed = true;
214
 
                        if ( $wp_filesystem->exists($remote_destination) )
 
213
                if ( $wp_filesystem->exists($remote_destination) ) {
 
214
                        if ( $clear_destination ) {
 
215
                                //We're going to clear the destination if theres something there
 
216
                                $this->skin->feedback('remove_old');
215
217
                                $removed = $wp_filesystem->delete($remote_destination, true);
216
 
 
217
 
                        $removed = apply_filters('upgrader_clear_destination', $removed, $local_destination, $remote_destination, $hook_extra);
218
 
 
219
 
                        if ( is_wp_error($removed) )
220
 
                                return $removed;
221
 
                        else if ( ! $removed )
222
 
                                return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
 
218
                                $removed = apply_filters('upgrader_clear_destination', $removed, $local_destination, $remote_destination, $hook_extra);
 
219
 
 
220
                                if ( is_wp_error($removed) )
 
221
                                        return $removed;
 
222
                                else if ( ! $removed )
 
223
                                        return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
 
224
                        } else {
 
225
                                //If we're not clearing the destination folder and something exists there allready, Bail.
 
226
                                //But first check to see if there are actually any files in the folder.
 
227
                                $_files = $wp_filesystem->dirlist($remote_destination);
 
228
                                if ( ! empty($_files) ) {
 
229
                                        $wp_filesystem->delete($remote_source, true); //Clear out the source files.
 
230
                                        return new WP_Error('folder_exists', $this->strings['folder_exists'], $remote_destination );
 
231
                                }
 
232
                        }
223
233
                }
224
234
 
225
235
                //Create destination if needed
261
271
                                                        'destination' => '', //And this
262
272
                                                        'clear_destination' => false,
263
273
                                                        'clear_working' => true,
 
274
                                                        'is_multi' => false,
264
275
                                                        'hook_extra' => array() //Pass any extra $hook_extra args here, this will be passed to any hooked filters.
265
276
                                                );
266
277
 
277
288
                        return $res;
278
289
                }
279
290
 
280
 
                $this->skin->header();
 
291
                if ( !$is_multi ) // call $this->header separately if running multiple times
 
292
                        $this->skin->header();
 
293
 
281
294
                $this->skin->before();
282
295
 
283
296
                //Download the package (Note, This just returns the filename of the file if the package is a local file)
311
324
                        $this->skin->feedback('process_success');
312
325
                }
313
326
                $this->skin->after();
314
 
                $this->skin->footer();
 
327
 
 
328
                if ( !$is_multi )
 
329
                        $this->skin->footer();
 
330
 
315
331
                return $result;
316
332
        }
317
333
 
344
360
class Plugin_Upgrader extends WP_Upgrader {
345
361
 
346
362
        var $result;
 
363
        var $bulk = false;
 
364
        var $show_before = '';
347
365
 
348
366
        function upgrade_strings() {
349
367
                $this->strings['up_to_date'] = __('The plugin is at the latest version.');
414
432
                                        )
415
433
                                ));
416
434
 
417
 
                //Cleanup our hooks, incase something else does a upgrade on this connection.
 
435
                // Cleanup our hooks, incase something else does a upgrade on this connection.
418
436
                remove_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'));
419
437
                remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'));
420
438
 
425
443
                delete_transient('update_plugins');
426
444
        }
427
445
 
 
446
        function bulk_upgrade($plugins) {
 
447
 
 
448
                $this->init();
 
449
                $this->bulk = true;
 
450
                $this->upgrade_strings();
 
451
 
 
452
                $current = get_transient( 'update_plugins' );
 
453
 
 
454
                add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4);
 
455
 
 
456
                $this->skin->header();
 
457
 
 
458
                // Connect to the Filesystem first.
 
459
                $res = $this->fs_connect( array(WP_CONTENT_DIR, WP_PLUGIN_DIR) );
 
460
                if ( ! $res ) {
 
461
                        $this->skin->footer();
 
462
                        return false;
 
463
                }
 
464
 
 
465
                $this->maintenance_mode(true);
 
466
 
 
467
                $all = count($plugins);
 
468
                $i = 1;
 
469
                foreach ( $plugins as $plugin ) {
 
470
 
 
471
                        $this->show_before = sprintf( '<h4>' . __('Updating plugin %1$d of %2$d...') . '</h4>', $i, $all );
 
472
                        $i++;
 
473
 
 
474
                        if ( !isset( $current->response[ $plugin ] ) ) {
 
475
                                $this->skin->set_result(false);
 
476
                                $this->skin->error('up_to_date');
 
477
                                $this->skin->after();
 
478
                                $results[$plugin] = false;
 
479
                                continue;
 
480
                        }
 
481
 
 
482
                        // Get the URL to the zip file
 
483
                        $r = $current->response[ $plugin ];
 
484
 
 
485
                        $this->skin->plugin_active = is_plugin_active($plugin);
 
486
 
 
487
                        $result = $this->run(array(
 
488
                                                'package' => $r->package,
 
489
                                                'destination' => WP_PLUGIN_DIR,
 
490
                                                'clear_destination' => true,
 
491
                                                'clear_working' => true,
 
492
                                                'is_multi' => true,
 
493
                                                'hook_extra' => array(
 
494
                                                                        'plugin' => $plugin
 
495
                                                )
 
496
                                        ));
 
497
 
 
498
                        $results[$plugin] = $this->result;
 
499
 
 
500
                        // Prevent credentials auth screen from displaying multiple times
 
501
                        if ( false === $result )
 
502
                                break;
 
503
                }
 
504
                $this->maintenance_mode(false);
 
505
                $this->skin->footer();
 
506
 
 
507
                // Cleanup our hooks, incase something else does a upgrade on this connection.
 
508
                remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'));
 
509
 
 
510
                // Force refresh of plugin update information
 
511
                delete_transient('update_plugins');
 
512
 
 
513
                return $results;
 
514
        }
 
515
 
428
516
        //return plugin info.
429
517
        function plugin_info() {
430
518
                if ( ! is_array($this->result) )
560
648
                        $this->skin->after();
561
649
                        return false;
562
650
                }
563
 
                
 
651
 
564
652
                $r = $current->response[ $theme ];
565
653
 
566
654
                add_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
820
908
        }
821
909
 
822
910
        function after() {
 
911
                if ( $this->upgrader->bulk )
 
912
                        return;
 
913
 
823
914
                $this->plugin = $this->upgrader->plugin_info();
824
915
                if( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){
825
916
                        show_message(__('Attempting reactivation of the plugin'));
826
917
                        echo '<iframe style="border:0;overflow:hidden" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&plugin=' . $this->plugin, 'activate-plugin_' . $this->plugin) .'"></iframe>';
827
918
                }
 
919
 
828
920
                $update_actions =  array(
829
921
                        'activate_plugin' => '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $this->plugin, 'activate-plugin_' . $this->plugin) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>',
830
922
                        'plugins_page' => '<a href="' . admin_url('plugins.php') . '" title="' . esc_attr__('Goto plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>'
838
930
                if ( ! empty($update_actions) )
839
931
                        $this->feedback('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$update_actions));
840
932
        }
 
933
 
 
934
        function before() {
 
935
                if ( $this->upgrader->show_before ) {
 
936
                        echo $this->upgrader->show_before;
 
937
                        $this->upgrader->show_before = '';
 
938
                }
 
939
        }
841
940
}
842
941
 
843
942
/**
996
1095
                        $name = $theme_info['Name'];
997
1096
                        $stylesheet = $this->upgrader->result['destination_name'];
998
1097
                        $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet;
999
 
        
 
1098
 
1000
1099
                        $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), trailingslashit(esc_url(get_option('home'))) ) );
1001
1100
                        $activate_link = wp_nonce_url("themes.php?action=activate&amp;template=" . urlencode($template) . "&amp;stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template);
1002
 
        
 
1101
 
1003
1102
                        $update_actions =  array(
1004
1103
                                'preview' => '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $name)) . '">' . __('Preview') . '</a>',
1005
1104
                                'activate' => '<a href="' . $activate_link .  '" class="activatelink" title="' . esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $name ) ) . '">' . __('Activate') . '</a>',