| [ XREF Home ] [ Index ] |
PHP Cross Reference of WordPress TrunkProvided by Yoast |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * A File upgrader class for WordPress. 4 * 5 * This set of classes are designed to be used to upgrade/install a local set of files on the filesystem via the Filesystem Abstraction classes. 6 * 7 * @link http://trac.wordpress.org/ticket/7875 consolidate plugin/theme/core upgrade/install functions 8 * 9 * @package WordPress 10 * @subpackage Upgrader 11 * @since 2.8.0 12 */ 13 14 /** 15 * WordPress Upgrader class for Upgrading/Installing a local set of files via the Filesystem Abstraction classes from a Zip file. 16 * 17 * @TODO More Detailed docs, for methods as well. 18 * 19 * @package WordPress 20 * @subpackage Upgrader 21 * @since 2.8.0 22 */ 23 class WP_Upgrader { 24 var $strings = array(); 25 var $skin = null; 26 var $result = array(); 27 28 function __construct($skin = null) { 29 if ( null == $skin ) 30 $this->skin = new WP_Upgrader_Skin(); 31 else 32 $this->skin = $skin; 33 } 34 35 function init() { 36 $this->skin->set_upgrader($this); 37 $this->generic_strings(); 38 } 39 40 function generic_strings() { 41 $this->strings['bad_request'] = __('Invalid Data provided.'); 42 $this->strings['fs_unavailable'] = __('Could not access filesystem.'); 43 $this->strings['fs_error'] = __('Filesystem error.'); 44 $this->strings['fs_no_root_dir'] = __('Unable to locate WordPress Root directory.'); 45 $this->strings['fs_no_content_dir'] = __('Unable to locate WordPress Content directory (wp-content).'); 46 $this->strings['fs_no_plugins_dir'] = __('Unable to locate WordPress Plugin directory.'); 47 $this->strings['fs_no_themes_dir'] = __('Unable to locate WordPress Theme directory.'); 48 /* translators: %s: directory name */ 49 $this->strings['fs_no_folder'] = __('Unable to locate needed folder (%s).'); 50 51 $this->strings['download_failed'] = __('Download failed.'); 52 $this->strings['installing_package'] = __('Installing the latest version…'); 53 $this->strings['folder_exists'] = __('Destination folder already exists.'); 54 $this->strings['mkdir_failed'] = __('Could not create directory.'); 55 $this->strings['bad_package'] = __('Incompatible Archive.'); 56 57 $this->strings['maintenance_start'] = __('Enabling Maintenance mode…'); 58 $this->strings['maintenance_end'] = __('Disabling Maintenance mode…'); 59 } 60 61 function fs_connect( $directories = array() ) { 62 global $wp_filesystem; 63 64 if ( false === ($credentials = $this->skin->request_filesystem_credentials()) ) 65 return false; 66 67 if ( ! WP_Filesystem($credentials) ) { 68 $error = true; 69 if ( is_object($wp_filesystem) && $wp_filesystem->errors->get_error_code() ) 70 $error = $wp_filesystem->errors; 71 $this->skin->request_filesystem_credentials($error); //Failed to connect, Error and request again 72 return false; 73 } 74 75 if ( ! is_object($wp_filesystem) ) 76 return new WP_Error('fs_unavailable', $this->strings['fs_unavailable'] ); 77 78 if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() ) 79 return new WP_Error('fs_error', $this->strings['fs_error'], $wp_filesystem->errors); 80 81 foreach ( (array)$directories as $dir ) { 82 switch ( $dir ) { 83 case ABSPATH: 84 if ( ! $wp_filesystem->abspath() ) 85 return new WP_Error('fs_no_root_dir', $this->strings['fs_no_root_dir']); 86 break; 87 case WP_CONTENT_DIR: 88 if ( ! $wp_filesystem->wp_content_dir() ) 89 return new WP_Error('fs_no_content_dir', $this->strings['fs_no_content_dir']); 90 break; 91 case WP_PLUGIN_DIR: 92 if ( ! $wp_filesystem->wp_plugins_dir() ) 93 return new WP_Error('fs_no_plugins_dir', $this->strings['fs_no_plugins_dir']); 94 break; 95 case WP_CONTENT_DIR . '/themes': 96 if ( ! $wp_filesystem->find_folder(WP_CONTENT_DIR . '/themes') ) 97 return new WP_Error('fs_no_themes_dir', $this->strings['fs_no_themes_dir']); 98 break; 99 default: 100 if ( ! $wp_filesystem->find_folder($dir) ) 101 return new WP_Error('fs_no_folder', sprintf($this->strings['fs_no_folder'], $dir)); 102 break; 103 } 104 } 105 return true; 106 } //end fs_connect(); 107 108 function download_package($package) { 109 110 if ( ! preg_match('!^(http|https|ftp)://!i', $package) && file_exists($package) ) //Local file or remote? 111 return $package; //must be a local file.. 112 113 if ( empty($package) ) 114 return new WP_Error('no_package', $this->strings['no_package']); 115 116 $this->skin->feedback('downloading_package', $package); 117 118 $download_file = download_url($package); 119 120 if ( is_wp_error($download_file) ) 121 return new WP_Error('download_failed', $this->strings['download_failed'], $download_file->get_error_message()); 122 123 return $download_file; 124 } 125 126 function unpack_package($package, $delete_package = true) { 127 global $wp_filesystem; 128 129 $this->skin->feedback('unpack_package'); 130 131 $upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/'; 132 133 //Clean up contents of upgrade directory beforehand. 134 $upgrade_files = $wp_filesystem->dirlist($upgrade_folder); 135 if ( !empty($upgrade_files) ) { 136 foreach ( $upgrade_files as $file ) 137 $wp_filesystem->delete($upgrade_folder . $file['name'], true); 138 } 139 140 //We need a working directory 141 $working_dir = $upgrade_folder . basename($package, '.zip'); 142 143 // Clean up working directory 144 if ( $wp_filesystem->is_dir($working_dir) ) 145 $wp_filesystem->delete($working_dir, true); 146 147 // Unzip package to working directory 148 $result = unzip_file($package, $working_dir); //TODO optimizations, Copy when Move/Rename would suffice? 149 150 // Once extracted, delete the package if required. 151 if ( $delete_package ) 152 unlink($package); 153 154 if ( is_wp_error($result) ) { 155 $wp_filesystem->delete($working_dir, true); 156 return $result; 157 } 158 159 return $working_dir; 160 } 161 162 function install_package($args = array()) { 163 global $wp_filesystem; 164 $defaults = array( 'source' => '', 'destination' => '', //Please always pass these 165 'clear_destination' => false, 'clear_working' => false, 166 'hook_extra' => array()); 167 168 $args = wp_parse_args($args, $defaults); 169 extract($args); 170 171 @set_time_limit( 300 ); 172 173 if ( empty($source) || empty($destination) ) 174 return new WP_Error('bad_request', $this->strings['bad_request']); 175 176 $this->skin->feedback('installing_package'); 177 178 $res = apply_filters('upgrader_pre_install', true, $hook_extra); 179 if ( is_wp_error($res) ) 180 return $res; 181 182 //Retain the Original source and destinations 183 $remote_source = $source; 184 $local_destination = $destination; 185 186 $source_files = array_keys( $wp_filesystem->dirlist($remote_source) ); 187 $remote_destination = $wp_filesystem->find_folder($local_destination); 188 189 //Locate which directory to copy to the new folder, This is based on the actual folder holding the files. 190 if ( 1 == count($source_files) && $wp_filesystem->is_dir( trailingslashit($source) . $source_files[0] . '/') ) //Only one folder? Then we want its contents. 191 $source = trailingslashit($source) . trailingslashit($source_files[0]); 192 elseif ( count($source_files) == 0 ) 193 return new WP_Error('bad_package', $this->strings['bad_package']); //There are no files? 194 //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. 195 196 //Hook ability to change the source file location.. 197 $source = apply_filters('upgrader_source_selection', $source, $remote_source, $this); 198 if ( is_wp_error($source) ) 199 return $source; 200 201 //Has the source location changed? If so, we need a new source_files list. 202 if ( $source !== $remote_source ) 203 $source_files = array_keys( $wp_filesystem->dirlist($source) ); 204 205 //Protection against deleting files in any important base directories. 206 if ( in_array( $destination, array(ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes') ) ) { 207 $remote_destination = trailingslashit($remote_destination) . trailingslashit(basename($source)); 208 $destination = trailingslashit($destination) . trailingslashit(basename($source)); 209 } 210 211 if ( $clear_destination ) { 212 //We're going to clear the destination if theres something there 213 $this->skin->feedback('remove_old'); 214 $removed = true; 215 if ( $wp_filesystem->exists($remote_destination) ) 216 $removed = $wp_filesystem->delete($remote_destination, true); 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']); 223 } elseif ( $wp_filesystem->exists($remote_destination) ) { 224 //If we're not clearing the destination folder and something exists there allready, Bail. 225 //But first check to see if there are actually any files in the folder. 226 $_files = $wp_filesystem->dirlist($remote_destination); 227 if ( ! empty($_files) ) { 228 $wp_filesystem->delete($remote_source, true); //Clear out the source files. 229 return new WP_Error('folder_exists', $this->strings['folder_exists'], $remote_destination ); 230 } 231 } 232 233 //Create destination if needed 234 if ( !$wp_filesystem->exists($remote_destination) ) 235 if ( !$wp_filesystem->mkdir($remote_destination, FS_CHMOD_DIR) ) 236 return new WP_Error('mkdir_failed', $this->strings['mkdir_failed'], $remote_destination); 237 238 // Copy new version of item into place. 239 $result = copy_dir($source, $remote_destination); 240 if ( is_wp_error($result) ) { 241 if ( $clear_working ) 242 $wp_filesystem->delete($remote_source, true); 243 return $result; 244 } 245 246 //Clear the Working folder? 247 if ( $clear_working ) 248 $wp_filesystem->delete($remote_source, true); 249 250 $destination_name = basename( str_replace($local_destination, '', $destination) ); 251 if ( '.' == $destination_name ) 252 $destination_name = ''; 253 254 $this->result = compact('local_source', 'source', 'source_name', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination', 'delete_source_dir'); 255 256 $res = apply_filters('upgrader_post_install', true, $hook_extra, $this->result); 257 if ( is_wp_error($res) ) { 258 $this->result = $res; 259 return $res; 260 } 261 262 //Bombard the calling function will all the info which we've just used. 263 return $this->result; 264 } 265 266 function run($options) { 267 268 $defaults = array( 'package' => '', //Please always pass this. 269 'destination' => '', //And this 270 'clear_destination' => false, 271 'clear_working' => true, 272 'is_multi' => false, 273 'hook_extra' => array() //Pass any extra $hook_extra args here, this will be passed to any hooked filters. 274 ); 275 276 $options = wp_parse_args($options, $defaults); 277 extract($options); 278 279 //Connect to the Filesystem first. 280 $res = $this->fs_connect( array(WP_CONTENT_DIR, $destination) ); 281 if ( ! $res ) //Mainly for non-connected filesystem. 282 return false; 283 284 if ( is_wp_error($res) ) { 285 $this->skin->error($res); 286 return $res; 287 } 288 289 if ( !$is_multi ) // call $this->header separately if running multiple times 290 $this->skin->header(); 291 292 $this->skin->before(); 293 294 //Download the package (Note, This just returns the filename of the file if the package is a local file) 295 $download = $this->download_package( $package ); 296 if ( is_wp_error($download) ) { 297 $this->skin->error($download); 298 $this->skin->after(); 299 return $download; 300 } 301 302 $delete_package = ($download != $package); // Do not delete a "local" file 303 304 //Unzip's the file into a temporary directory 305 $working_dir = $this->unpack_package( $download, $delete_package ); 306 if ( is_wp_error($working_dir) ) { 307 $this->skin->error($working_dir); 308 $this->skin->after(); 309 return $working_dir; 310 } 311 312 //With the given options, this installs it to the destination directory. 313 $result = $this->install_package( array( 314 'source' => $working_dir, 315 'destination' => $destination, 316 'clear_destination' => $clear_destination, 317 'clear_working' => $clear_working, 318 'hook_extra' => $hook_extra 319 ) ); 320 $this->skin->set_result($result); 321 if ( is_wp_error($result) ) { 322 $this->skin->error($result); 323 $this->skin->feedback('process_failed'); 324 } else { 325 //Install Suceeded 326 $this->skin->feedback('process_success'); 327 } 328 $this->skin->after(); 329 330 if ( !$is_multi ) 331 $this->skin->footer(); 332 333 return $result; 334 } 335 336 function maintenance_mode($enable = false) { 337 global $wp_filesystem; 338 $file = $wp_filesystem->abspath() . '.maintenance'; 339 if ( $enable ) { 340 $this->skin->feedback('maintenance_start'); 341 // Create maintenance file to signal that we are upgrading 342 $maintenance_string = '<?php $upgrading = ' . time() . '; ?>'; 343 $wp_filesystem->delete($file); 344 $wp_filesystem->put_contents($file, $maintenance_string, FS_CHMOD_FILE); 345 } else if ( !$enable && $wp_filesystem->exists($file) ) { 346 $this->skin->feedback('maintenance_end'); 347 $wp_filesystem->delete($file); 348 } 349 } 350 351 } 352 353 /** 354 * Plugin Upgrader class for WordPress Plugins, It is designed to upgrade/install plugins from a local zip, remote zip URL, or uploaded zip file. 355 * 356 * @TODO More Detailed docs, for methods as well. 357 * 358 * @package WordPress 359 * @subpackage Upgrader 360 * @since 2.8.0 361 */ 362 class Plugin_Upgrader extends WP_Upgrader { 363 364 var $result; 365 var $bulk = false; 366 var $show_before = ''; 367 368 function upgrade_strings() { 369 $this->strings['up_to_date'] = __('The plugin is at the latest version.'); 370 $this->strings['no_package'] = __('Update package not available.'); 371 $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>…'); 372 $this->strings['unpack_package'] = __('Unpacking the update…'); 373 $this->strings['deactivate_plugin'] = __('Deactivating the plugin…'); 374 $this->strings['remove_old'] = __('Removing the old version of the plugin…'); 375 $this->strings['remove_old_failed'] = __('Could not remove the old plugin.'); 376 $this->strings['process_failed'] = __('Plugin update failed.'); 377 $this->strings['process_success'] = __('Plugin updated successfully.'); 378 } 379 380 function install_strings() { 381 $this->strings['no_package'] = __('Install package not available.'); 382 $this->strings['downloading_package'] = __('Downloading install package from <span class="code">%s</span>…'); 383 $this->strings['unpack_package'] = __('Unpacking the package…'); 384 $this->strings['installing_package'] = __('Installing the plugin…'); 385 $this->strings['process_failed'] = __('Plugin install failed.'); 386 $this->strings['process_success'] = __('Plugin installed successfully.'); 387 } 388 389 function install($package) { 390 391 $this->init(); 392 $this->install_strings(); 393 394 $this->run(array( 395 'package' => $package, 396 'destination' => WP_PLUGIN_DIR, 397 'clear_destination' => false, //Do not overwrite files. 398 'clear_working' => true, 399 'hook_extra' => array() 400 )); 401 402 // Force refresh of plugin update information 403 delete_site_transient('update_plugins'); 404 405 } 406 407 function upgrade($plugin) { 408 409 $this->init(); 410 $this->upgrade_strings(); 411 412 $current = get_site_transient( 'update_plugins' ); 413 if ( !isset( $current->response[ $plugin ] ) ) { 414 $this->skin->before(); 415 $this->skin->set_result(false); 416 $this->skin->error('up_to_date'); 417 $this->skin->after(); 418 return false; 419 } 420 421 // Get the URL to the zip file 422 $r = $current->response[ $plugin ]; 423 424 add_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'), 10, 2); 425 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4); 426 //'source_selection' => array(&$this, 'source_selection'), //theres a track ticket to move up the directory for zip's which are made a bit differently, useful for non-.org plugins. 427 428 $this->run(array( 429 'package' => $r->package, 430 'destination' => WP_PLUGIN_DIR, 431 'clear_destination' => true, 432 'clear_working' => true, 433 'hook_extra' => array( 434 'plugin' => $plugin 435 ) 436 )); 437 438 // Cleanup our hooks, incase something else does a upgrade on this connection. 439 remove_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade')); 440 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin')); 441 442 if ( ! $this->result || is_wp_error($this->result) ) 443 return $this->result; 444 445 // Force refresh of plugin update information 446 delete_site_transient('update_plugins'); 447 } 448 449 function bulk_upgrade($plugins) { 450 451 $this->init(); 452 $this->bulk = true; 453 $this->upgrade_strings(); 454 455 $current = get_site_transient( 'update_plugins' ); 456 457 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4); 458 459 $this->skin->header(); 460 461 // Connect to the Filesystem first. 462 $res = $this->fs_connect( array(WP_CONTENT_DIR, WP_PLUGIN_DIR) ); 463 if ( ! $res ) { 464 $this->skin->footer(); 465 return false; 466 } 467 468 $this->skin->bulk_header(); 469 470 // Only start maintenance mode if running in Multisite OR the plugin is in use 471 $maintenance = is_multisite(); // @TODO: This should only kick in for individual sites if at all possible. 472 foreach ( $plugins as $plugin ) 473 $maintenance = $maintenance || (is_plugin_active($plugin) && isset($current->response[ $plugin ]) ); // Only activate Maintenance mode if a plugin is active AND has an update available 474 if ( $maintenance ) 475 $this->maintenance_mode(true); 476 477 $results = array(); 478 479 $this->update_count = count($plugins); 480 $this->update_current = 0; 481 foreach ( $plugins as $plugin ) { 482 $this->update_current++; 483 $this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true); 484 485 if ( !isset( $current->response[ $plugin ] ) ) { 486 $this->skin->set_result(false); 487 $this->skin->before(); 488 $this->skin->error('up_to_date'); 489 $this->skin->after(); 490 $results[$plugin] = false; 491 continue; 492 } 493 494 // Get the URL to the zip file 495 $r = $current->response[ $plugin ]; 496 497 $this->skin->plugin_active = is_plugin_active($plugin); 498 499 $result = $this->run(array( 500 'package' => $r->package, 501 'destination' => WP_PLUGIN_DIR, 502 'clear_destination' => true, 503 'clear_working' => true, 504 'is_multi' => true, 505 'hook_extra' => array( 506 'plugin' => $plugin 507 ) 508 )); 509 510 $results[$plugin] = $this->result; 511 512 // Prevent credentials auth screen from displaying multiple times 513 if ( false === $result ) 514 break; 515 } //end foreach $plugins 516 517 $this->maintenance_mode(false); 518 519 $this->skin->bulk_footer(); 520 521 $this->skin->footer(); 522 523 // Cleanup our hooks, incase something else does a upgrade on this connection. 524 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin')); 525 526 // Force refresh of plugin update information 527 delete_site_transient('update_plugins'); 528 529 return $results; 530 } 531 532 //return plugin info. 533 function plugin_info() { 534 if ( ! is_array($this->result) ) 535 return false; 536 if ( empty($this->result['destination_name']) ) 537 return false; 538 539 $plugin = get_plugins('/' . $this->result['destination_name']); //Ensure to pass with leading slash 540 if ( empty($plugin) ) 541 return false; 542 543 $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list 544 545 return $this->result['destination_name'] . '/' . $pluginfiles[0]; 546 } 547 548 //Hooked to pre_install 549 function deactivate_plugin_before_upgrade($return, $plugin) { 550 551 if ( is_wp_error($return) ) //Bypass. 552 return $return; 553 554 $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : ''; 555 if ( empty($plugin) ) 556 return new WP_Error('bad_request', $this->strings['bad_request']); 557 558 if ( is_plugin_active($plugin) ) { 559 $this->skin->feedback('deactivate_plugin'); 560 //Deactivate the plugin silently, Prevent deactivation hooks from running. 561 deactivate_plugins($plugin, true); 562 } 563 } 564 565 //Hooked to upgrade_clear_destination 566 function delete_old_plugin($removed, $local_destination, $remote_destination, $plugin) { 567 global $wp_filesystem; 568 569 if ( is_wp_error($removed) ) 570 return $removed; //Pass errors through. 571 572 $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : ''; 573 if ( empty($plugin) ) 574 return new WP_Error('bad_request', $this->strings['bad_request']); 575 576 $plugins_dir = $wp_filesystem->wp_plugins_dir(); 577 $this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) ); 578 579 if ( ! $wp_filesystem->exists($this_plugin_dir) ) //If its already vanished. 580 return $removed; 581 582 // If plugin is in its own directory, recursively delete the directory. 583 if ( strpos($plugin, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory separator AND that its not the root plugin folder 584 $deleted = $wp_filesystem->delete($this_plugin_dir, true); 585 else 586 $deleted = $wp_filesystem->delete($plugins_dir . $plugin); 587 588 if ( ! $deleted ) 589 return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']); 590 591 return true; 592 } 593 } 594 595 /** 596 * Theme Upgrader class for WordPress Themes, It is designed to upgrade/install themes from a local zip, remote zip URL, or uploaded zip file. 597 * 598 * @TODO More Detailed docs, for methods as well. 599 * 600 * @package WordPress 601 * @subpackage Upgrader 602 * @since 2.8.0 603 */ 604 class Theme_Upgrader extends WP_Upgrader { 605 606 var $result; 607 608 function upgrade_strings() { 609 $this->strings['up_to_date'] = __('The theme is at the latest version.'); 610 $this->strings['no_package'] = __('Update package not available.'); 611 $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>…'); 612 $this->strings['unpack_package'] = __('Unpacking the update…'); 613 $this->strings['remove_old'] = __('Removing the old version of the theme…'); 614 $this->strings['remove_old_failed'] = __('Could not remove the old theme.'); 615 $this->strings['process_failed'] = __('Theme update failed.'); 616 $this->strings['process_success'] = __('Theme updated successfully.'); 617 } 618 619 function install_strings() { 620 $this->strings['no_package'] = __('Install package not available.'); 621 $this->strings['downloading_package'] = __('Downloading install package from <span class="code">%s</span>…'); 622 $this->strings['unpack_package'] = __('Unpacking the package…'); 623 $this->strings['installing_package'] = __('Installing the theme…'); 624 $this->strings['process_failed'] = __('Theme install failed.'); 625 $this->strings['process_success'] = __('Theme installed successfully.'); 626 } 627 628 function install($package) { 629 630 $this->init(); 631 $this->install_strings(); 632 633 $options = array( 634 'package' => $package, 635 'destination' => WP_CONTENT_DIR . '/themes', 636 'clear_destination' => false, //Do not overwrite files. 637 'clear_working' => true 638 ); 639 640 $this->run($options); 641 642 if ( ! $this->result || is_wp_error($this->result) ) 643 return $this->result; 644 645 // Force refresh of theme update information 646 delete_site_transient('update_themes'); 647 648 if ( empty($result['destination_name']) ) 649 return false; 650 else 651 return $result['destination_name']; 652 } 653 654 function upgrade($theme) { 655 656 $this->init(); 657 $this->upgrade_strings(); 658 659 // Is an update available? 660 $current = get_site_transient( 'update_themes' ); 661 if ( !isset( $current->response[ $theme ] ) ) { 662 $this->skin->before(); 663 $this->skin->set_result(false); 664 $this->skin->error('up_to_date'); 665 $this->skin->after(); 666 return false; 667 } 668 669 $r = $current->response[ $theme ]; 670 671 add_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2); 672 add_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2); 673 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4); 674 675 $options = array( 676 'package' => $r['package'], 677 'destination' => WP_CONTENT_DIR . '/themes', 678 'clear_destination' => true, 679 'clear_working' => true, 680 'hook_extra' => array( 681 'theme' => $theme 682 ) 683 ); 684 685 $this->run($options); 686 687 if ( ! $this->result || is_wp_error($this->result) ) 688 return $this->result; 689 690 // Force refresh of theme update information 691 delete_site_transient('update_themes'); 692 693 return true; 694 } 695 696 function bulk_upgrade($themes) { 697 698 $this->init(); 699 $this->bulk = true; 700 $this->upgrade_strings(); 701 702 $current = get_site_transient( 'update_themes' ); 703 704 add_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2); 705 add_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2); 706 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4); 707 708 $this->skin->header(); 709 710 // Connect to the Filesystem first. 711 $res = $this->fs_connect( array(WP_CONTENT_DIR) ); 712 if ( ! $res ) { 713 $this->skin->footer(); 714 return false; 715 } 716 717 $this->skin->bulk_header(); 718 719 // Only start maintenance mode if running in Multisite OR the theme is in use 720 $maintenance = is_multisite(); // @TODO: This should only kick in for individual sites if at all possible. 721 foreach ( $themes as $theme ) 722 $maintenance = $maintenance || $theme == get_stylesheet() || $theme == get_template(); 723 if ( $maintenance ) 724 $this->maintenance_mode(true); 725 726 $results = array(); 727 728 $this->update_count = count($themes); 729 $this->update_current = 0; 730 foreach ( $themes as $theme ) { 731 $this->update_current++; 732 733 if ( !isset( $current->response[ $theme ] ) ) { 734 $this->skin->set_result(false); 735 $this->skin->before(); 736 $this->skin->error('up_to_date'); 737 $this->skin->after(); 738 $results[$theme] = false; 739 continue; 740 } 741 742 $this->skin->theme_info = $this->theme_info($theme); 743 744 // Get the URL to the zip file 745 $r = $current->response[ $theme ]; 746 747 $options = array( 748 'package' => $r['package'], 749 'destination' => WP_CONTENT_DIR . '/themes', 750 'clear_destination' => true, 751 'clear_working' => true, 752 'hook_extra' => array( 753 'theme' => $theme 754 ) 755 ); 756 757 $result = $this->run($options); 758 759 $results[$theme] = $this->result; 760 761 // Prevent credentials auth screen from displaying multiple times 762 if ( false === $result ) 763 break; 764 } //end foreach $plugins 765 766 $this->maintenance_mode(false); 767 768 $this->skin->bulk_footer(); 769 770 $this->skin->footer(); 771 772 // Cleanup our hooks, incase something else does a upgrade on this connection. 773 remove_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2); 774 remove_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2); 775 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4); 776 777 // Force refresh of theme update information 778 delete_site_transient('update_themes'); 779 780 return $results; 781 } 782 783 function current_before($return, $theme) { 784 785 if ( is_wp_error($return) ) 786 return $return; 787 788 $theme = isset($theme['theme']) ? $theme['theme'] : ''; 789 790 if ( $theme != get_stylesheet() ) //If not current 791 return $return; 792 //Change to maintenance mode now. 793 if ( ! $this->bulk ) 794 $this->maintenance_mode(true); 795 796 return $return; 797 } 798 function current_after($return, $theme) { 799 if ( is_wp_error($return) ) 800 return $return; 801 802 $theme = isset($theme['theme']) ? $theme['theme'] : ''; 803 804 if ( $theme != get_stylesheet() ) //If not current 805 return $return; 806 807 //Ensure stylesheet name hasnt changed after the upgrade: 808 // @TODO: Note, This doesnt handle the Template changing, or the Template name changing. 809 if ( $theme == get_stylesheet() && $theme != $this->result['destination_name'] ) { 810 $theme_info = $this->theme_info(); 811 $stylesheet = $this->result['destination_name']; 812 $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet; 813 switch_theme($template, $stylesheet, true); 814 } 815 816 //Time to remove maintenance mode 817 if ( ! $this->bulk ) 818 $this->maintenance_mode(false); 819 return $return; 820 } 821 822 function delete_old_theme($removed, $local_destination, $remote_destination, $theme) { 823 global $wp_filesystem; 824 825 $theme = isset($theme['theme']) ? $theme['theme'] : ''; 826 827 if ( is_wp_error($removed) || empty($theme) ) 828 return $removed; //Pass errors through. 829 830 $themes_dir = $wp_filesystem->wp_themes_dir(); 831 if ( $wp_filesystem->exists( trailingslashit($themes_dir) . $theme ) ) 832 if ( ! $wp_filesystem->delete( trailingslashit($themes_dir) . $theme, true ) ) 833 return false; 834 return true; 835 } 836 837 function theme_info($theme = null) { 838 839 if ( empty($theme) ) { 840 if ( !empty($this->result['destination_name']) ) 841 $theme = $this->result['destination_name']; 842 else 843 return false; 844 } 845 return get_theme_data(WP_CONTENT_DIR . '/themes/' . $theme . '/style.css'); 846 } 847 848 } 849 850 /** 851 * Core Upgrader class for WordPress. It allows for WordPress to upgrade itself in combiantion with the wp-admin/includes/update-core.php file 852 * 853 * @TODO More Detailed docs, for methods as well. 854 * 855 * @package WordPress 856 * @subpackage Upgrader 857 * @since 2.8.0 858 */ 859 class Core_Upgrader extends WP_Upgrader { 860 861 function upgrade_strings() { 862 $this->strings['up_to_date'] = __('WordPress is at the latest version.'); 863 $this->strings['no_package'] = __('Update package not available.'); 864 $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>…'); 865 $this->strings['unpack_package'] = __('Unpacking the update…'); 866 $this->strings['copy_failed'] = __('Could not copy files.'); 867 } 868 869 function upgrade($current) { 870 global $wp_filesystem; 871 872 $this->init(); 873 $this->upgrade_strings(); 874 875 if ( !empty($feedback) ) 876 add_filter('update_feedback', $feedback); 877 878 // Is an update available? 879 if ( !isset( $current->response ) || $current->response == 'latest' ) 880 return new WP_Error('up_to_date', $this->strings['up_to_date']); 881 882 $res = $this->fs_connect( array(ABSPATH, WP_CONTENT_DIR) ); 883 if ( is_wp_error($res) ) 884 return $res; 885 886 $wp_dir = trailingslashit($wp_filesystem->abspath()); 887 888 $download = $this->download_package( $current->package ); 889 if ( is_wp_error($download) ) 890 return $download; 891 892 $working_dir = $this->unpack_package( $download ); 893 if ( is_wp_error($working_dir) ) 894 return $working_dir; 895 896 // Copy update-core.php from the new version into place. 897 if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) { 898 $wp_filesystem->delete($working_dir, true); 899 return new WP_Error('copy_failed', $this->strings['copy_failed']); 900 } 901 $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE); 902 903 require (ABSPATH . 'wp-admin/includes/update-core.php'); 904 905 return update_core($working_dir, $wp_dir); 906 } 907 908 } 909 910 /** 911 * Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes. 912 * 913 * @TODO More Detailed docs, for methods as well. 914 * 915 * @package WordPress 916 * @subpackage Upgrader 917 * @since 2.8.0 918 */ 919 class WP_Upgrader_Skin { 920 921 var $upgrader; 922 var $done_header = false; 923 var $result = false; 924 925 function __construct($args = array()) { 926 $defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false ); 927 $this->options = wp_parse_args($args, $defaults); 928 } 929 930 function set_upgrader(&$upgrader) { 931 if ( is_object($upgrader) ) 932 $this->upgrader =& $upgrader; 933 $this->add_strings(); 934 } 935 936 function add_strings() { 937 } 938 939 function set_result($result) { 940 $this->result = $result; 941 } 942 943 function request_filesystem_credentials($error = false) { 944 $url = $this->options['url']; 945 $context = $this->options['context']; 946 if ( !empty($this->options['nonce']) ) 947 $url = wp_nonce_url($url, $this->options['nonce']); 948 return request_filesystem_credentials($url, '', $error, $context); //Possible to bring inline, Leaving as is for now. 949 } 950 951 function header() { 952 if ( $this->done_header ) 953 return; 954 $this->done_header = true; 955 echo '<div class="wrap">'; 956 echo screen_icon(); 957 echo '<h2>' . $this->options['title'] . '</h2>'; 958 } 959 function footer() { 960 echo '</div>'; 961 } 962 963 function error($errors) { 964 if ( ! $this->done_header ) 965 $this->header(); 966 if ( is_string($errors) ) { 967 $this->feedback($errors); 968 } elseif ( is_wp_error($errors) && $errors->get_error_code() ) { 969 foreach ( $errors->get_error_messages() as $message ) { 970 if ( $errors->get_error_data() ) 971 $this->feedback($message . ' ' . $errors->get_error_data() ); 972 else 973 $this->feedback($message); 974 } 975 } 976 } 977 978 function feedback($string) { 979 if ( isset( $this->upgrader->strings[$string] ) ) 980 $string = $this->upgrader->strings[$string]; 981 982 if ( strpos($string, '%') !== false ) { 983 $args = func_get_args(); 984 $args = array_splice($args, 1); 985 if ( !empty($args) ) 986 $string = vsprintf($string, $args); 987 } 988 if ( empty($string) ) 989 return; 990 show_message($string); 991 } 992 function before() {} 993 function after() {} 994 995 } 996 997 /** 998 * Plugin Upgrader Skin for WordPress Plugin Upgrades. 999 * 1000 * @TODO More Detailed docs, for methods as well. 1001 * 1002 * @package WordPress 1003 * @subpackage Upgrader 1004 * @since 2.8.0 1005 */ 1006 class Plugin_Upgrader_Skin extends WP_Upgrader_Skin { 1007 var $plugin = ''; 1008 var $plugin_active = false; 1009 var $plugin_network_active = false; 1010 1011 function __construct($args = array()) { 1012 $defaults = array( 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => __('Update Plugin') ); 1013 $args = wp_parse_args($args, $defaults); 1014 1015 $this->plugin = $args['plugin']; 1016 1017 $this->plugin_active = is_plugin_active( $this->plugin ); 1018 $this->plugin_network_active = is_plugin_active_for_network( $this->plugin ); 1019 1020 parent::__construct($args); 1021 } 1022 1023 function after() { 1024 $this->plugin = $this->upgrader->plugin_info(); 1025 if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){ 1026 show_message(__('Reactivating the plugin…')); 1027 echo '<iframe style="border:0;overflow:hidden" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&networkwide=' . $this->plugin_network_active . '&plugin=' . $this->plugin, 'activate-plugin_' . $this->plugin) .'"></iframe>'; 1028 } 1029 1030 $update_actions = array( 1031 'activate_plugin' => '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $this->plugin, 'activate-plugin_' . $this->plugin) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>', 1032 'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>' 1033 ); 1034 if ( $this->plugin_active ) 1035 unset( $update_actions['activate_plugin'] ); 1036 if ( ! $this->result || is_wp_error($this->result) ) 1037 unset( $update_actions['activate_plugin'] ); 1038 1039 $update_actions = apply_filters('update_plugin_complete_actions', $update_actions, $this->plugin); 1040 if ( ! empty($update_actions) ) 1041 $this->feedback(implode(' | ', (array)$update_actions)); 1042 } 1043 1044 function before() { 1045 if ( $this->upgrader->show_before ) { 1046 echo $this->upgrader->show_before; 1047 $this->upgrader->show_before = ''; 1048 } 1049 } 1050 } 1051 1052 /** 1053 * Plugin Upgrader Skin for WordPress Plugin Upgrades. 1054 * 1055 * @package WordPress 1056 * @subpackage Upgrader 1057 * @since 3.0.0 1058 */ 1059 class Bulk_Upgrader_Skin extends WP_Upgrader_Skin { 1060 var $in_loop = false; 1061 var $error = false; 1062 1063 function __construct($args = array()) { 1064 $defaults = array( 'url' => '', 'nonce' => '' ); 1065 $args = wp_parse_args($args, $defaults); 1066 1067 parent::__construct($args); 1068 } 1069 1070 function add_strings() { 1071 $this->upgrader->strings['skin_upgrade_start'] = __('The update process is starting. This process may take a while on some hosts, so please be patient.'); 1072 $this->upgrader->strings['skin_update_failed_error'] = __('An error occurred while updating %1$s: <strong>%2$s</strong>.'); 1073 $this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.'); 1074 $this->upgrader->strings['skin_update_successful'] = __('%1$s updated successfully.').' <a onclick="%2$s" href="#" class="hide-if-no-js"><span>'.__('Show Details').'</span><span class="hidden">'.__('Hide Details').'</span>.</a>'; 1075 $this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.'); 1076 } 1077 1078 function feedback($string) { 1079 if ( isset( $this->upgrader->strings[$string] ) ) 1080 $string = $this->upgrader->strings[$string]; 1081 1082 if ( strpos($string, '%') !== false ) { 1083 $args = func_get_args(); 1084 $args = array_splice($args, 1); 1085 if ( !empty($args) ) 1086 $string = vsprintf($string, $args); 1087 } 1088 if ( empty($string) ) 1089 return; 1090 if ( $this->in_loop ) 1091 echo "$string<br />\n"; 1092 else 1093 echo "<p>$string</p>\n"; 1094 } 1095 1096 function header() { 1097 // Nothing, This will be displayed within a iframe. 1098 } 1099 1100 function footer() { 1101 // Nothing, This will be displayed within a iframe. 1102 } 1103 function error($error) { 1104 if ( is_string($error) && isset( $this->upgrader->strings[$error] ) ) 1105 $this->error = $this->upgrader->strings[$error]; 1106 1107 if ( is_wp_error($error) ) { 1108 foreach ( $error->get_error_messages() as $emessage ) { 1109 if ( $error->get_error_data() ) 1110 $messages[] = $emessage . ' ' . $error->get_error_data(); 1111 else 1112 $messages[] = $emessage; 1113 } 1114 $this->error = implode(', ', $messages); 1115 } 1116 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>'; 1117 } 1118 1119 function bulk_header() { 1120 $this->feedback('skin_upgrade_start'); 1121 } 1122 1123 function bulk_footer() { 1124 $this->feedback('skin_upgrade_end'); 1125 } 1126 1127 function before($title = '') { 1128 $this->in_loop = true; 1129 printf( '<h4>' . $this->upgrader->strings['skin_before_update_header'] . ' <img alt="" src="' . admin_url( 'images/wpspin_light.gif' ) . '" class="hidden waiting-' . $this->upgrader->update_current . '" style="vertical-align:middle;" /></h4>', $title, $this->upgrader->update_current, $this->upgrader->update_count); 1130 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').show();</script>'; 1131 echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr($this->upgrader->update_current) . '"><p>'; 1132 $this->flush_output(); 1133 } 1134 1135 function after($title = '') { 1136 echo '</p></div>'; 1137 if ( $this->error || ! $this->result ) { 1138 if ( $this->error ) 1139 echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, $this->error) . '</p></div>'; 1140 else 1141 echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '</p></div>'; 1142 1143 echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').show();</script>'; 1144 } 1145 if ( !empty($this->result) && !is_wp_error($this->result) ) { 1146 echo '<div class="updated"><p>' . sprintf($this->upgrader->strings['skin_update_successful'], $title, 'jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').toggle();jQuery(\'span\', this).toggle(); return false;') . '</p></div>'; 1147 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>'; 1148 } 1149 1150 $this->reset(); 1151 $this->flush_output(); 1152 } 1153 1154 function reset() { 1155 $this->in_loop = false; 1156 $this->error = false; 1157 } 1158 1159 function flush_output() { 1160 wp_ob_end_flush_all(); 1161 flush(); 1162 } 1163 } 1164 1165 class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin { 1166 var $plugin_info = array(); // Plugin_Upgrader::bulk() will fill this in. 1167 1168 function __construct($args = array()) { 1169 parent::__construct($args); 1170 } 1171 1172 function add_strings() { 1173 parent::add_strings(); 1174 $this->upgrader->strings['skin_before_update_header'] = __('Updating Plugin %1$s (%2$d/%3$d)'); 1175 } 1176 1177 function before() { 1178 parent::before($this->plugin_info['Title']); 1179 } 1180 1181 function after() { 1182 parent::after($this->plugin_info['Title']); 1183 } 1184 function bulk_footer() { 1185 parent::bulk_footer(); 1186 $update_actions = array( 1187 'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>', 1188 'updates_page' => '<a href="' . self_admin_url('update-core.php') . '" title="' . esc_attr__('Go to WordPress Updates page') . '" target="_parent">' . __('Return to WordPress Updates') . '</a>' 1189 ); 1190 1191 $update_actions = apply_filters('update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info); 1192 if ( ! empty($update_actions) ) 1193 $this->feedback(implode(' | ', (array)$update_actions)); 1194 } 1195 } 1196 1197 class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin { 1198 var $theme_info = array(); // Theme_Upgrader::bulk() will fill this in. 1199 1200 function __construct($args = array()) { 1201 parent::__construct($args); 1202 } 1203 1204 function add_strings() { 1205 parent::add_strings(); 1206 $this->upgrader->strings['skin_before_update_header'] = __('Updating Theme %1$s (%2$d/%3$d)'); 1207 } 1208 1209 function before() { 1210 parent::before($this->theme_info['Name']); 1211 } 1212 1213 function after() { 1214 parent::after($this->theme_info['Name']); 1215 } 1216 function bulk_footer() { 1217 parent::bulk_footer(); 1218 $update_actions = array( 1219 'themes_page' => '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Go to themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>', 1220 'updates_page' => '<a href="' . self_admin_url('update-core.php') . '" title="' . esc_attr__('Go to WordPress Updates page') . '" target="_parent">' . __('Return to WordPress Updates') . '</a>' 1221 ); 1222 1223 $update_actions = apply_filters('update_bulk_theme_complete_actions', $update_actions, $this->theme_info); 1224 if ( ! empty($update_actions) ) 1225 $this->feedback(implode(' | ', (array)$update_actions)); 1226 } 1227 } 1228 1229 /** 1230 * Plugin Installer Skin for WordPress Plugin Installer. 1231 * 1232 * @TODO More Detailed docs, for methods as well. 1233 * 1234 * @package WordPress 1235 * @subpackage Upgrader 1236 * @since 2.8.0 1237 */ 1238 class Plugin_Installer_Skin extends WP_Upgrader_Skin { 1239 var $api; 1240 var $type; 1241 1242 function __construct($args = array()) { 1243 $defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' ); 1244 $args = wp_parse_args($args, $defaults); 1245 1246 $this->type = $args['type']; 1247 $this->api = isset($args['api']) ? $args['api'] : array(); 1248 1249 parent::__construct($args); 1250 } 1251 1252 function before() { 1253 if ( !empty($this->api) ) 1254 $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin <strong>%s %s</strong>.'), $this->api->name, $this->api->version); 1255 } 1256 1257 function after() { 1258 1259 $plugin_file = $this->upgrader->plugin_info(); 1260 1261 $install_actions = array(); 1262 1263 $from = isset($_GET['from']) ? stripslashes($_GET['from']) : 'plugins'; 1264 1265 if ( 'import' == $from ) 1266 $install_actions['activate_plugin'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&from=import&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin & Run Importer') . '</a>'; 1267 else 1268 $install_actions['activate_plugin'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>'; 1269 1270 if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) { 1271 $install_actions['network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&networkwide=1&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin for all sites in this network') . '" target="_parent">' . __('Network Activate') . '</a>'; 1272 unset( $install_actions['activate_plugin'] ); 1273 } 1274 1275 if ( 'import' == $from ) 1276 $install_actions['importers_page'] = '<a href="' . admin_url('import.php') . '" title="' . esc_attr__('Return to Importers') . '" target="_parent">' . __('Return to Importers') . '</a>'; 1277 else if ( $this->type == 'web' ) 1278 $install_actions['plugins_page'] = '<a href="' . self_admin_url('plugin-install.php') . '" title="' . esc_attr__('Return to Plugin Installer') . '" target="_parent">' . __('Return to Plugin Installer') . '</a>'; 1279 else 1280 $install_actions['plugins_page'] = '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Return to Plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>'; 1281 1282 1283 if ( ! $this->result || is_wp_error($this->result) ) { 1284 unset( $install_actions['activate_plugin'] ); 1285 unset( $install_actions['network_activate'] ); 1286 } 1287 $install_actions = apply_filters('install_plugin_complete_actions', $install_actions, $this->api, $plugin_file); 1288 if ( ! empty($install_actions) ) 1289 $this->feedback(implode(' | ', (array)$install_actions)); 1290 } 1291 } 1292 1293 /** 1294 * Theme Installer Skin for the WordPress Theme Installer. 1295 * 1296 * @TODO More Detailed docs, for methods as well. 1297 * 1298 * @package WordPress 1299 * @subpackage Upgrader 1300 * @since 2.8.0 1301 */ 1302 class Theme_Installer_Skin extends WP_Upgrader_Skin { 1303 var $api; 1304 var $type; 1305 1306 function __construct($args = array()) { 1307 $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' ); 1308 $args = wp_parse_args($args, $defaults); 1309 1310 $this->type = $args['type']; 1311 $this->api = isset($args['api']) ? $args['api'] : array(); 1312 1313 parent::__construct($args); 1314 } 1315 1316 function before() { 1317 if ( !empty($this->api) ) { 1318 /* translators: 1: theme name, 2: version */ 1319 $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the theme <strong>%1$s %2$s</strong>.'), $this->api->name, $this->api->version); 1320 } 1321 } 1322 1323 function after() { 1324 if ( empty($this->upgrader->result['destination_name']) ) 1325 return; 1326 1327 $theme_info = $this->upgrader->theme_info(); 1328 if ( empty($theme_info) ) 1329 return; 1330 $name = $theme_info['Name']; 1331 $stylesheet = $this->upgrader->result['destination_name']; 1332 $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet; 1333 1334 $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'preview_iframe' => 1, 'TB_iframe' => 'true' ), trailingslashit(esc_url(get_option('home'))) ) ); 1335 $activate_link = wp_nonce_url("themes.php?action=activate&template=" . urlencode($template) . "&stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template); 1336 1337 $install_actions = array( 1338 'preview' => '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview “%s”'), $name)) . '">' . __('Preview') . '</a>', 1339 'activate' => '<a href="' . $activate_link . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate “%s”'), $name ) ) . '">' . __('Activate') . '</a>' 1340 ); 1341 1342 if ( $this->type == 'web' ) 1343 $install_actions['themes_page'] = '<a href="' . self_admin_url('theme-install.php') . '" title="' . esc_attr__('Return to Theme Installer') . '" target="_parent">' . __('Return to Theme Installer') . '</a>'; 1344 else 1345 $install_actions['themes_page'] = '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>'; 1346 1347 if ( ! $this->result || is_wp_error($this->result) || is_network_admin() ) 1348 unset( $install_actions['activate'], $install_actions['preview'] ); 1349 1350 $install_actions = apply_filters('install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info); 1351 if ( ! empty($install_actions) ) 1352 $this->feedback(implode(' | ', (array)$install_actions)); 1353 } 1354 } 1355 1356 /** 1357 * Theme Upgrader Skin for WordPress Theme Upgrades. 1358 * 1359 * @TODO More Detailed docs, for methods as well. 1360 * 1361 * @package WordPress 1362 * @subpackage Upgrader 1363 * @since 2.8.0 1364 */ 1365 class Theme_Upgrader_Skin extends WP_Upgrader_Skin { 1366 var $theme = ''; 1367 1368 function __construct($args = array()) { 1369 $defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Update Theme') ); 1370 $args = wp_parse_args($args, $defaults); 1371 1372 $this->theme = $args['theme']; 1373 1374 parent::__construct($args); 1375 } 1376 1377 function after() { 1378 1379 $update_actions = array(); 1380 if ( !empty($this->upgrader->result['destination_name']) && 1381 ($theme_info = $this->upgrader->theme_info()) && 1382 !empty($theme_info) ) { 1383 1384 $name = $theme_info['Name']; 1385 $stylesheet = $this->upgrader->result['destination_name']; 1386 $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet; 1387 1388 $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), trailingslashit(esc_url(get_option('home'))) ) ); 1389 $activate_link = wp_nonce_url("themes.php?action=activate&template=" . urlencode($template) . "&stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template); 1390 1391 $update_actions['preview'] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview “%s”'), $name)) . '">' . __('Preview') . '</a>'; 1392 $update_actions['activate'] = '<a href="' . $activate_link . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate “%s”'), $name ) ) . '">' . __('Activate') . '</a>'; 1393 1394 if ( ( ! $this->result || is_wp_error($this->result) ) || $stylesheet == get_stylesheet() ) 1395 unset($update_actions['preview'], $update_actions['activate']); 1396 } 1397 1398 $update_actions['themes_page'] = '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Return to Themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>'; 1399 1400 $update_actions = apply_filters('update_theme_complete_actions', $update_actions, $this->theme); 1401 if ( ! empty($update_actions) ) 1402 $this->feedback(implode(' | ', (array)$update_actions)); 1403 } 1404 } 1405 1406 /** 1407 * Upgrade Skin helper for File uploads. This class handles the upload process and passes it as if its a local file to the Upgrade/Installer functions. 1408 * 1409 * @TODO More Detailed docs, for methods as well. 1410 * 1411 * @package WordPress 1412 * @subpackage Upgrader 1413 * @since 2.8.0 1414 */ 1415 class File_Upload_Upgrader { 1416 var $package; 1417 var $filename; 1418 1419 function __construct($form, $urlholder) { 1420 if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) ) 1421 wp_die($uploads['error']); 1422 1423 if ( empty($_FILES[$form]['name']) && empty($_GET[$urlholder]) ) 1424 wp_die(__('Please select a file')); 1425 1426 if ( !empty($_FILES) ) 1427 $this->filename = $_FILES[$form]['name']; 1428 else if ( isset($_GET[$urlholder]) ) 1429 $this->filename = $_GET[$urlholder]; 1430 1431 //Handle a newly uploaded file, Else assume its already been uploaded 1432 if ( !empty($_FILES) ) { 1433 $this->filename = wp_unique_filename( $uploads['basedir'], $this->filename ); 1434 $this->package = $uploads['basedir'] . '/' . $this->filename; 1435 1436 // Move the file to the uploads dir 1437 if ( false === @ move_uploaded_file( $_FILES[$form]['tmp_name'], $this->package) ) 1438 wp_die( sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'])); 1439 } else { 1440 $this->package = $uploads['basedir'] . '/' . $this->filename; 1441 } 1442 } 1443 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jun 1 08:30:02 2011 |
Cross-referenced by PHPXref 0.7 Provided by Yoast and awesome WordPress Hosting |