PageRenderTime 60ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-admin/includes/class-wp-upgrader.php

https://bitbucket.org/aqge/deptandashboard
PHP | 1566 lines | 1082 code | 309 blank | 175 comment | 209 complexity | d916019404761c67a7b3ff16d428d6d9 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  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. * WordPress Upgrader class for Upgrading/Installing a local set of files via the Filesystem Abstraction classes from a Zip file.
  15. *
  16. * @TODO More Detailed docs, for methods as well.
  17. *
  18. * @package WordPress
  19. * @subpackage Upgrader
  20. * @since 2.8.0
  21. */
  22. class WP_Upgrader {
  23. var $strings = array();
  24. var $skin = null;
  25. var $result = array();
  26. function __construct($skin = null) {
  27. if ( null == $skin )
  28. $this->skin = new WP_Upgrader_Skin();
  29. else
  30. $this->skin = $skin;
  31. }
  32. function init() {
  33. $this->skin->set_upgrader($this);
  34. $this->generic_strings();
  35. }
  36. function generic_strings() {
  37. $this->strings['bad_request'] = __('Invalid Data provided.');
  38. $this->strings['fs_unavailable'] = __('Could not access filesystem.');
  39. $this->strings['fs_error'] = __('Filesystem error.');
  40. $this->strings['fs_no_root_dir'] = __('Unable to locate WordPress Root directory.');
  41. $this->strings['fs_no_content_dir'] = __('Unable to locate WordPress Content directory (wp-content).');
  42. $this->strings['fs_no_plugins_dir'] = __('Unable to locate WordPress Plugin directory.');
  43. $this->strings['fs_no_themes_dir'] = __('Unable to locate WordPress Theme directory.');
  44. /* translators: %s: directory name */
  45. $this->strings['fs_no_folder'] = __('Unable to locate needed folder (%s).');
  46. $this->strings['download_failed'] = __('Download failed.');
  47. $this->strings['installing_package'] = __('Installing the latest version&#8230;');
  48. $this->strings['folder_exists'] = __('Destination folder already exists.');
  49. $this->strings['mkdir_failed'] = __('Could not create directory.');
  50. $this->strings['incompatible_archive'] = __('The package could not be installed.');
  51. $this->strings['maintenance_start'] = __('Enabling Maintenance mode&#8230;');
  52. $this->strings['maintenance_end'] = __('Disabling Maintenance mode&#8230;');
  53. }
  54. function fs_connect( $directories = array() ) {
  55. global $wp_filesystem;
  56. if ( false === ($credentials = $this->skin->request_filesystem_credentials()) )
  57. return false;
  58. if ( ! WP_Filesystem($credentials) ) {
  59. $error = true;
  60. if ( is_object($wp_filesystem) && $wp_filesystem->errors->get_error_code() )
  61. $error = $wp_filesystem->errors;
  62. $this->skin->request_filesystem_credentials($error); //Failed to connect, Error and request again
  63. return false;
  64. }
  65. if ( ! is_object($wp_filesystem) )
  66. return new WP_Error('fs_unavailable', $this->strings['fs_unavailable'] );
  67. if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() )
  68. return new WP_Error('fs_error', $this->strings['fs_error'], $wp_filesystem->errors);
  69. foreach ( (array)$directories as $dir ) {
  70. switch ( $dir ) {
  71. case ABSPATH:
  72. if ( ! $wp_filesystem->abspath() )
  73. return new WP_Error('fs_no_root_dir', $this->strings['fs_no_root_dir']);
  74. break;
  75. case WP_CONTENT_DIR:
  76. if ( ! $wp_filesystem->wp_content_dir() )
  77. return new WP_Error('fs_no_content_dir', $this->strings['fs_no_content_dir']);
  78. break;
  79. case WP_PLUGIN_DIR:
  80. if ( ! $wp_filesystem->wp_plugins_dir() )
  81. return new WP_Error('fs_no_plugins_dir', $this->strings['fs_no_plugins_dir']);
  82. break;
  83. case WP_CONTENT_DIR . '/themes':
  84. if ( ! $wp_filesystem->find_folder(WP_CONTENT_DIR . '/themes') )
  85. return new WP_Error('fs_no_themes_dir', $this->strings['fs_no_themes_dir']);
  86. break;
  87. default:
  88. if ( ! $wp_filesystem->find_folder($dir) )
  89. return new WP_Error('fs_no_folder', sprintf($this->strings['fs_no_folder'], $dir));
  90. break;
  91. }
  92. }
  93. return true;
  94. } //end fs_connect();
  95. function download_package($package) {
  96. if ( ! preg_match('!^(http|https|ftp)://!i', $package) && file_exists($package) ) //Local file or remote?
  97. return $package; //must be a local file..
  98. if ( empty($package) )
  99. return new WP_Error('no_package', $this->strings['no_package']);
  100. $this->skin->feedback('downloading_package', $package);
  101. $download_file = download_url($package);
  102. if ( is_wp_error($download_file) )
  103. return new WP_Error('download_failed', $this->strings['download_failed'], $download_file->get_error_message());
  104. return $download_file;
  105. }
  106. function unpack_package($package, $delete_package = true) {
  107. global $wp_filesystem;
  108. $this->skin->feedback('unpack_package');
  109. $upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/';
  110. //Clean up contents of upgrade directory beforehand.
  111. $upgrade_files = $wp_filesystem->dirlist($upgrade_folder);
  112. if ( !empty($upgrade_files) ) {
  113. foreach ( $upgrade_files as $file )
  114. $wp_filesystem->delete($upgrade_folder . $file['name'], true);
  115. }
  116. //We need a working directory
  117. $working_dir = $upgrade_folder . basename($package, '.zip');
  118. // Clean up working directory
  119. if ( $wp_filesystem->is_dir($working_dir) )
  120. $wp_filesystem->delete($working_dir, true);
  121. // Unzip package to working directory
  122. $result = unzip_file($package, $working_dir); //TODO optimizations, Copy when Move/Rename would suffice?
  123. // Once extracted, delete the package if required.
  124. if ( $delete_package )
  125. unlink($package);
  126. if ( is_wp_error($result) ) {
  127. $wp_filesystem->delete($working_dir, true);
  128. if ( 'incompatible_archive' == $result->get_error_code() ) {
  129. return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], $result->get_error_data() );
  130. }
  131. return $result;
  132. }
  133. return $working_dir;
  134. }
  135. function install_package($args = array()) {
  136. global $wp_filesystem;
  137. $defaults = array( 'source' => '', 'destination' => '', //Please always pass these
  138. 'clear_destination' => false, 'clear_working' => false,
  139. 'hook_extra' => array());
  140. $args = wp_parse_args($args, $defaults);
  141. extract($args);
  142. @set_time_limit( 300 );
  143. if ( empty($source) || empty($destination) )
  144. return new WP_Error('bad_request', $this->strings['bad_request']);
  145. $this->skin->feedback('installing_package');
  146. $res = apply_filters('upgrader_pre_install', true, $hook_extra);
  147. if ( is_wp_error($res) )
  148. return $res;
  149. //Retain the Original source and destinations
  150. $remote_source = $source;
  151. $local_destination = $destination;
  152. $source_files = array_keys( $wp_filesystem->dirlist($remote_source) );
  153. $remote_destination = $wp_filesystem->find_folder($local_destination);
  154. //Locate which directory to copy to the new folder, This is based on the actual folder holding the files.
  155. if ( 1 == count($source_files) && $wp_filesystem->is_dir( trailingslashit($source) . $source_files[0] . '/') ) //Only one folder? Then we want its contents.
  156. $source = trailingslashit($source) . trailingslashit($source_files[0]);
  157. elseif ( count($source_files) == 0 )
  158. return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __( 'The plugin contains no files.' ) ); //There are no files?
  159. 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.
  160. $source = trailingslashit($source);
  161. //Hook ability to change the source file location..
  162. $source = apply_filters('upgrader_source_selection', $source, $remote_source, $this);
  163. if ( is_wp_error($source) )
  164. return $source;
  165. //Has the source location changed? If so, we need a new source_files list.
  166. if ( $source !== $remote_source )
  167. $source_files = array_keys( $wp_filesystem->dirlist($source) );
  168. //Protection against deleting files in any important base directories.
  169. if ( in_array( $destination, array(ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes') ) ) {
  170. $remote_destination = trailingslashit($remote_destination) . trailingslashit(basename($source));
  171. $destination = trailingslashit($destination) . trailingslashit(basename($source));
  172. }
  173. if ( $clear_destination ) {
  174. //We're going to clear the destination if there's something there
  175. $this->skin->feedback('remove_old');
  176. $removed = true;
  177. if ( $wp_filesystem->exists($remote_destination) )
  178. $removed = $wp_filesystem->delete($remote_destination, true);
  179. $removed = apply_filters('upgrader_clear_destination', $removed, $local_destination, $remote_destination, $hook_extra);
  180. if ( is_wp_error($removed) )
  181. return $removed;
  182. else if ( ! $removed )
  183. return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
  184. } elseif ( $wp_filesystem->exists($remote_destination) ) {
  185. //If we're not clearing the destination folder and something exists there already, Bail.
  186. //But first check to see if there are actually any files in the folder.
  187. $_files = $wp_filesystem->dirlist($remote_destination);
  188. if ( ! empty($_files) ) {
  189. $wp_filesystem->delete($remote_source, true); //Clear out the source files.
  190. return new WP_Error('folder_exists', $this->strings['folder_exists'], $remote_destination );
  191. }
  192. }
  193. //Create destination if needed
  194. if ( !$wp_filesystem->exists($remote_destination) )
  195. if ( !$wp_filesystem->mkdir($remote_destination, FS_CHMOD_DIR) )
  196. return new WP_Error('mkdir_failed', $this->strings['mkdir_failed'], $remote_destination);
  197. // Copy new version of item into place.
  198. $result = copy_dir($source, $remote_destination);
  199. if ( is_wp_error($result) ) {
  200. if ( $clear_working )
  201. $wp_filesystem->delete($remote_source, true);
  202. return $result;
  203. }
  204. //Clear the Working folder?
  205. if ( $clear_working )
  206. $wp_filesystem->delete($remote_source, true);
  207. $destination_name = basename( str_replace($local_destination, '', $destination) );
  208. if ( '.' == $destination_name )
  209. $destination_name = '';
  210. $this->result = compact('local_source', 'source', 'source_name', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination', 'delete_source_dir');
  211. $res = apply_filters('upgrader_post_install', true, $hook_extra, $this->result);
  212. if ( is_wp_error($res) ) {
  213. $this->result = $res;
  214. return $res;
  215. }
  216. //Bombard the calling function will all the info which we've just used.
  217. return $this->result;
  218. }
  219. function run($options) {
  220. $defaults = array( 'package' => '', //Please always pass this.
  221. 'destination' => '', //And this
  222. 'clear_destination' => false,
  223. 'clear_working' => true,
  224. 'is_multi' => false,
  225. 'hook_extra' => array() //Pass any extra $hook_extra args here, this will be passed to any hooked filters.
  226. );
  227. $options = wp_parse_args($options, $defaults);
  228. extract($options);
  229. //Connect to the Filesystem first.
  230. $res = $this->fs_connect( array(WP_CONTENT_DIR, $destination) );
  231. if ( ! $res ) //Mainly for non-connected filesystem.
  232. return false;
  233. if ( is_wp_error($res) ) {
  234. $this->skin->error($res);
  235. return $res;
  236. }
  237. if ( !$is_multi ) // call $this->header separately if running multiple times
  238. $this->skin->header();
  239. $this->skin->before();
  240. //Download the package (Note, This just returns the filename of the file if the package is a local file)
  241. $download = $this->download_package( $package );
  242. if ( is_wp_error($download) ) {
  243. $this->skin->error($download);
  244. $this->skin->after();
  245. return $download;
  246. }
  247. $delete_package = ($download != $package); // Do not delete a "local" file
  248. //Unzips the file into a temporary directory
  249. $working_dir = $this->unpack_package( $download, $delete_package );
  250. if ( is_wp_error($working_dir) ) {
  251. $this->skin->error($working_dir);
  252. $this->skin->after();
  253. return $working_dir;
  254. }
  255. //With the given options, this installs it to the destination directory.
  256. $result = $this->install_package( array(
  257. 'source' => $working_dir,
  258. 'destination' => $destination,
  259. 'clear_destination' => $clear_destination,
  260. 'clear_working' => $clear_working,
  261. 'hook_extra' => $hook_extra
  262. ) );
  263. $this->skin->set_result($result);
  264. if ( is_wp_error($result) ) {
  265. $this->skin->error($result);
  266. $this->skin->feedback('process_failed');
  267. } else {
  268. //Install Succeeded
  269. $this->skin->feedback('process_success');
  270. }
  271. $this->skin->after();
  272. if ( !$is_multi )
  273. $this->skin->footer();
  274. return $result;
  275. }
  276. function maintenance_mode($enable = false) {
  277. global $wp_filesystem;
  278. $file = $wp_filesystem->abspath() . '.maintenance';
  279. if ( $enable ) {
  280. $this->skin->feedback('maintenance_start');
  281. // Create maintenance file to signal that we are upgrading
  282. $maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
  283. $wp_filesystem->delete($file);
  284. $wp_filesystem->put_contents($file, $maintenance_string, FS_CHMOD_FILE);
  285. } else if ( !$enable && $wp_filesystem->exists($file) ) {
  286. $this->skin->feedback('maintenance_end');
  287. $wp_filesystem->delete($file);
  288. }
  289. }
  290. }
  291. /**
  292. * Plugin Upgrader class for WordPress Plugins, It is designed to upgrade/install plugins from a local zip, remote zip URL, or uploaded zip file.
  293. *
  294. * @TODO More Detailed docs, for methods as well.
  295. *
  296. * @package WordPress
  297. * @subpackage Upgrader
  298. * @since 2.8.0
  299. */
  300. class Plugin_Upgrader extends WP_Upgrader {
  301. var $result;
  302. var $bulk = false;
  303. var $show_before = '';
  304. function upgrade_strings() {
  305. $this->strings['up_to_date'] = __('The plugin is at the latest version.');
  306. $this->strings['no_package'] = __('Update package not available.');
  307. $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>&#8230;');
  308. $this->strings['unpack_package'] = __('Unpacking the update&#8230;');
  309. $this->strings['deactivate_plugin'] = __('Deactivating the plugin&#8230;');
  310. $this->strings['remove_old'] = __('Removing the old version of the plugin&#8230;');
  311. $this->strings['remove_old_failed'] = __('Could not remove the old plugin.');
  312. $this->strings['process_failed'] = __('Plugin update failed.');
  313. $this->strings['process_success'] = __('Plugin updated successfully.');
  314. }
  315. function install_strings() {
  316. $this->strings['no_package'] = __('Install package not available.');
  317. $this->strings['downloading_package'] = __('Downloading install package from <span class="code">%s</span>&#8230;');
  318. $this->strings['unpack_package'] = __('Unpacking the package&#8230;');
  319. $this->strings['installing_package'] = __('Installing the plugin&#8230;');
  320. $this->strings['process_failed'] = __('Plugin install failed.');
  321. $this->strings['process_success'] = __('Plugin installed successfully.');
  322. }
  323. function install($package) {
  324. $this->init();
  325. $this->install_strings();
  326. add_filter('upgrader_source_selection', array(&$this, 'check_package') );
  327. $this->run(array(
  328. 'package' => $package,
  329. 'destination' => WP_PLUGIN_DIR,
  330. 'clear_destination' => false, //Do not overwrite files.
  331. 'clear_working' => true,
  332. 'hook_extra' => array()
  333. ));
  334. remove_filter('upgrader_source_selection', array(&$this, 'check_package') );
  335. if ( ! $this->result || is_wp_error($this->result) )
  336. return $this->result;
  337. // Force refresh of plugin update information
  338. delete_site_transient('update_plugins');
  339. return true;
  340. }
  341. function upgrade($plugin) {
  342. $this->init();
  343. $this->upgrade_strings();
  344. $current = get_site_transient( 'update_plugins' );
  345. if ( !isset( $current->response[ $plugin ] ) ) {
  346. $this->skin->before();
  347. $this->skin->set_result(false);
  348. $this->skin->error('up_to_date');
  349. $this->skin->after();
  350. return false;
  351. }
  352. // Get the URL to the zip file
  353. $r = $current->response[ $plugin ];
  354. add_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'), 10, 2);
  355. add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4);
  356. //'source_selection' => array(&$this, 'source_selection'), //there's a trac ticket to move up the directory for zip's which are made a bit differently, useful for non-.org plugins.
  357. $this->run(array(
  358. 'package' => $r->package,
  359. 'destination' => WP_PLUGIN_DIR,
  360. 'clear_destination' => true,
  361. 'clear_working' => true,
  362. 'hook_extra' => array(
  363. 'plugin' => $plugin
  364. )
  365. ));
  366. // Cleanup our hooks, in case something else does a upgrade on this connection.
  367. remove_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'));
  368. remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'));
  369. if ( ! $this->result || is_wp_error($this->result) )
  370. return $this->result;
  371. // Force refresh of plugin update information
  372. delete_site_transient('update_plugins');
  373. }
  374. function bulk_upgrade($plugins) {
  375. $this->init();
  376. $this->bulk = true;
  377. $this->upgrade_strings();
  378. $current = get_site_transient( 'update_plugins' );
  379. add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4);
  380. $this->skin->header();
  381. // Connect to the Filesystem first.
  382. $res = $this->fs_connect( array(WP_CONTENT_DIR, WP_PLUGIN_DIR) );
  383. if ( ! $res ) {
  384. $this->skin->footer();
  385. return false;
  386. }
  387. $this->skin->bulk_header();
  388. // Only start maintenance mode if running in Multisite OR the plugin is in use
  389. $maintenance = is_multisite(); // @TODO: This should only kick in for individual sites if at all possible.
  390. foreach ( $plugins as $plugin )
  391. $maintenance = $maintenance || (is_plugin_active($plugin) && isset($current->response[ $plugin ]) ); // Only activate Maintenance mode if a plugin is active AND has an update available
  392. if ( $maintenance )
  393. $this->maintenance_mode(true);
  394. $results = array();
  395. $this->update_count = count($plugins);
  396. $this->update_current = 0;
  397. foreach ( $plugins as $plugin ) {
  398. $this->update_current++;
  399. $this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true);
  400. if ( !isset( $current->response[ $plugin ] ) ) {
  401. $this->skin->set_result(false);
  402. $this->skin->before();
  403. $this->skin->error('up_to_date');
  404. $this->skin->after();
  405. $results[$plugin] = false;
  406. continue;
  407. }
  408. // Get the URL to the zip file
  409. $r = $current->response[ $plugin ];
  410. $this->skin->plugin_active = is_plugin_active($plugin);
  411. $result = $this->run(array(
  412. 'package' => $r->package,
  413. 'destination' => WP_PLUGIN_DIR,
  414. 'clear_destination' => true,
  415. 'clear_working' => true,
  416. 'is_multi' => true,
  417. 'hook_extra' => array(
  418. 'plugin' => $plugin
  419. )
  420. ));
  421. $results[$plugin] = $this->result;
  422. // Prevent credentials auth screen from displaying multiple times
  423. if ( false === $result )
  424. break;
  425. } //end foreach $plugins
  426. $this->maintenance_mode(false);
  427. $this->skin->bulk_footer();
  428. $this->skin->footer();
  429. // Cleanup our hooks, in case something else does a upgrade on this connection.
  430. remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'));
  431. // Force refresh of plugin update information
  432. delete_site_transient('update_plugins');
  433. return $results;
  434. }
  435. function check_package($source) {
  436. global $wp_filesystem;
  437. if ( is_wp_error($source) )
  438. return $source;
  439. $working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit(WP_CONTENT_DIR), $source);
  440. if ( ! is_dir($working_directory) ) // Sanity check, if the above fails, lets not prevent installation.
  441. return $source;
  442. // Check the folder contains at least 1 valid plugin.
  443. $plugins_found = false;
  444. foreach ( glob( $working_directory . '*.php' ) as $file ) {
  445. $info = get_plugin_data($file, false, false);
  446. if ( !empty( $info['Name'] ) ) {
  447. $plugins_found = true;
  448. break;
  449. }
  450. }
  451. if ( ! $plugins_found )
  452. return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('No valid plugins were found.') );
  453. return $source;
  454. }
  455. //return plugin info.
  456. function plugin_info() {
  457. if ( ! is_array($this->result) )
  458. return false;
  459. if ( empty($this->result['destination_name']) )
  460. return false;
  461. $plugin = get_plugins('/' . $this->result['destination_name']); //Ensure to pass with leading slash
  462. if ( empty($plugin) )
  463. return false;
  464. $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
  465. return $this->result['destination_name'] . '/' . $pluginfiles[0];
  466. }
  467. //Hooked to pre_install
  468. function deactivate_plugin_before_upgrade($return, $plugin) {
  469. if ( is_wp_error($return) ) //Bypass.
  470. return $return;
  471. $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : '';
  472. if ( empty($plugin) )
  473. return new WP_Error('bad_request', $this->strings['bad_request']);
  474. if ( is_plugin_active($plugin) ) {
  475. $this->skin->feedback('deactivate_plugin');
  476. //Deactivate the plugin silently, Prevent deactivation hooks from running.
  477. deactivate_plugins($plugin, true);
  478. }
  479. }
  480. //Hooked to upgrade_clear_destination
  481. function delete_old_plugin($removed, $local_destination, $remote_destination, $plugin) {
  482. global $wp_filesystem;
  483. if ( is_wp_error($removed) )
  484. return $removed; //Pass errors through.
  485. $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : '';
  486. if ( empty($plugin) )
  487. return new WP_Error('bad_request', $this->strings['bad_request']);
  488. $plugins_dir = $wp_filesystem->wp_plugins_dir();
  489. $this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) );
  490. if ( ! $wp_filesystem->exists($this_plugin_dir) ) //If its already vanished.
  491. return $removed;
  492. // If plugin is in its own directory, recursively delete the directory.
  493. if ( strpos($plugin, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory separator AND that its not the root plugin folder
  494. $deleted = $wp_filesystem->delete($this_plugin_dir, true);
  495. else
  496. $deleted = $wp_filesystem->delete($plugins_dir . $plugin);
  497. if ( ! $deleted )
  498. return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
  499. return true;
  500. }
  501. }
  502. /**
  503. * Theme Upgrader class for WordPress Themes, It is designed to upgrade/install themes from a local zip, remote zip URL, or uploaded zip file.
  504. *
  505. * @TODO More Detailed docs, for methods as well.
  506. *
  507. * @package WordPress
  508. * @subpackage Upgrader
  509. * @since 2.8.0
  510. */
  511. class Theme_Upgrader extends WP_Upgrader {
  512. var $result;
  513. var $bulk = false;
  514. function upgrade_strings() {
  515. $this->strings['up_to_date'] = __('The theme is at the latest version.');
  516. $this->strings['no_package'] = __('Update package not available.');
  517. $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>&#8230;');
  518. $this->strings['unpack_package'] = __('Unpacking the update&#8230;');
  519. $this->strings['remove_old'] = __('Removing the old version of the theme&#8230;');
  520. $this->strings['remove_old_failed'] = __('Could not remove the old theme.');
  521. $this->strings['process_failed'] = __('Theme update failed.');
  522. $this->strings['process_success'] = __('Theme updated successfully.');
  523. }
  524. function install_strings() {
  525. $this->strings['no_package'] = __('Install package not available.');
  526. $this->strings['downloading_package'] = __('Downloading install package from <span class="code">%s</span>&#8230;');
  527. $this->strings['unpack_package'] = __('Unpacking the package&#8230;');
  528. $this->strings['installing_package'] = __('Installing the theme&#8230;');
  529. $this->strings['process_failed'] = __('Theme install failed.');
  530. $this->strings['process_success'] = __('Theme installed successfully.');
  531. }
  532. function install($package) {
  533. $this->init();
  534. $this->install_strings();
  535. add_filter('upgrader_source_selection', array(&$this, 'check_package') );
  536. $options = array(
  537. 'package' => $package,
  538. 'destination' => WP_CONTENT_DIR . '/themes',
  539. 'clear_destination' => false, //Do not overwrite files.
  540. 'clear_working' => true
  541. );
  542. $this->run($options);
  543. remove_filter('upgrader_source_selection', array(&$this, 'check_package') );
  544. if ( ! $this->result || is_wp_error($this->result) )
  545. return $this->result;
  546. // Force refresh of theme update information
  547. delete_site_transient('update_themes');
  548. return true;
  549. }
  550. function upgrade($theme) {
  551. $this->init();
  552. $this->upgrade_strings();
  553. // Is an update available?
  554. $current = get_site_transient( 'update_themes' );
  555. if ( !isset( $current->response[ $theme ] ) ) {
  556. $this->skin->before();
  557. $this->skin->set_result(false);
  558. $this->skin->error('up_to_date');
  559. $this->skin->after();
  560. return false;
  561. }
  562. $r = $current->response[ $theme ];
  563. add_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
  564. add_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
  565. add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
  566. $options = array(
  567. 'package' => $r['package'],
  568. 'destination' => WP_CONTENT_DIR . '/themes',
  569. 'clear_destination' => true,
  570. 'clear_working' => true,
  571. 'hook_extra' => array(
  572. 'theme' => $theme
  573. )
  574. );
  575. $this->run($options);
  576. remove_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
  577. remove_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
  578. remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
  579. if ( ! $this->result || is_wp_error($this->result) )
  580. return $this->result;
  581. // Force refresh of theme update information
  582. delete_site_transient('update_themes');
  583. return true;
  584. }
  585. function bulk_upgrade($themes) {
  586. $this->init();
  587. $this->bulk = true;
  588. $this->upgrade_strings();
  589. $current = get_site_transient( 'update_themes' );
  590. add_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
  591. add_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
  592. add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
  593. $this->skin->header();
  594. // Connect to the Filesystem first.
  595. $res = $this->fs_connect( array(WP_CONTENT_DIR) );
  596. if ( ! $res ) {
  597. $this->skin->footer();
  598. return false;
  599. }
  600. $this->skin->bulk_header();
  601. // Only start maintenance mode if running in Multisite OR the theme is in use
  602. $maintenance = is_multisite(); // @TODO: This should only kick in for individual sites if at all possible.
  603. foreach ( $themes as $theme )
  604. $maintenance = $maintenance || $theme == get_stylesheet() || $theme == get_template();
  605. if ( $maintenance )
  606. $this->maintenance_mode(true);
  607. $results = array();
  608. $this->update_count = count($themes);
  609. $this->update_current = 0;
  610. foreach ( $themes as $theme ) {
  611. $this->update_current++;
  612. if ( !isset( $current->response[ $theme ] ) ) {
  613. $this->skin->set_result(false);
  614. $this->skin->before();
  615. $this->skin->error('up_to_date');
  616. $this->skin->after();
  617. $results[$theme] = false;
  618. continue;
  619. }
  620. $this->skin->theme_info = $this->theme_info($theme);
  621. // Get the URL to the zip file
  622. $r = $current->response[ $theme ];
  623. $options = array(
  624. 'package' => $r['package'],
  625. 'destination' => WP_CONTENT_DIR . '/themes',
  626. 'clear_destination' => true,
  627. 'clear_working' => true,
  628. 'hook_extra' => array(
  629. 'theme' => $theme
  630. )
  631. );
  632. $result = $this->run($options);
  633. $results[$theme] = $this->result;
  634. // Prevent credentials auth screen from displaying multiple times
  635. if ( false === $result )
  636. break;
  637. } //end foreach $plugins
  638. $this->maintenance_mode(false);
  639. $this->skin->bulk_footer();
  640. $this->skin->footer();
  641. // Cleanup our hooks, in case something else does a upgrade on this connection.
  642. remove_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
  643. remove_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
  644. remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
  645. // Force refresh of theme update information
  646. delete_site_transient('update_themes');
  647. return $results;
  648. }
  649. function check_package($source) {
  650. global $wp_filesystem;
  651. if ( is_wp_error($source) )
  652. return $source;
  653. // Check the folder contains a valid theme
  654. $working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit(WP_CONTENT_DIR), $source);
  655. if ( ! is_dir($working_directory) ) // Sanity check, if the above fails, lets not prevent installation.
  656. return $source;
  657. if ( ! file_exists( $working_directory . 'style.css' ) ) // A proper archive should have a style.css file in the single subdirectory
  658. return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('The theme is missing the <code>style.css</code> stylesheet.') );
  659. $info = get_theme_data( $working_directory . 'style.css' );
  660. if ( empty($info['Name']) )
  661. return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __("The <code>style.css</code> stylesheet doesn't contain a valid theme header.") );
  662. if ( empty($info['Template']) && ! file_exists( $working_directory . 'index.php' ) ) // If no template is set, it must have at least an index.php to be legit.
  663. return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('The theme is missing the <code>index.php</code> file.') );
  664. return $source;
  665. }
  666. function current_before($return, $theme) {
  667. if ( is_wp_error($return) )
  668. return $return;
  669. $theme = isset($theme['theme']) ? $theme['theme'] : '';
  670. if ( $theme != get_stylesheet() ) //If not current
  671. return $return;
  672. //Change to maintenance mode now.
  673. if ( ! $this->bulk )
  674. $this->maintenance_mode(true);
  675. return $return;
  676. }
  677. function current_after($return, $theme) {
  678. if ( is_wp_error($return) )
  679. return $return;
  680. $theme = isset($theme['theme']) ? $theme['theme'] : '';
  681. if ( $theme != get_stylesheet() ) //If not current
  682. return $return;
  683. //Ensure stylesheet name hasnt changed after the upgrade:
  684. // @TODO: Note, This doesn't handle the Template changing, or the Template name changing.
  685. if ( $theme == get_stylesheet() && $theme != $this->result['destination_name'] ) {
  686. $theme_info = $this->theme_info();
  687. $stylesheet = $this->result['destination_name'];
  688. $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet;
  689. switch_theme($template, $stylesheet, true);
  690. }
  691. //Time to remove maintenance mode
  692. if ( ! $this->bulk )
  693. $this->maintenance_mode(false);
  694. return $return;
  695. }
  696. function delete_old_theme($removed, $local_destination, $remote_destination, $theme) {
  697. global $wp_filesystem;
  698. $theme = isset($theme['theme']) ? $theme['theme'] : '';
  699. if ( is_wp_error($removed) || empty($theme) )
  700. return $removed; //Pass errors through.
  701. $themes_dir = $wp_filesystem->wp_themes_dir();
  702. if ( $wp_filesystem->exists( trailingslashit($themes_dir) . $theme ) )
  703. if ( ! $wp_filesystem->delete( trailingslashit($themes_dir) . $theme, true ) )
  704. return false;
  705. return true;
  706. }
  707. function theme_info($theme = null) {
  708. if ( empty($theme) ) {
  709. if ( !empty($this->result['destination_name']) )
  710. $theme = $this->result['destination_name'];
  711. else
  712. return false;
  713. }
  714. return get_theme_data(WP_CONTENT_DIR . '/themes/' . $theme . '/style.css');
  715. }
  716. }
  717. /**
  718. * Core Upgrader class for WordPress. It allows for WordPress to upgrade itself in combination with the wp-admin/includes/update-core.php file
  719. *
  720. * @TODO More Detailed docs, for methods as well.
  721. *
  722. * @package WordPress
  723. * @subpackage Upgrader
  724. * @since 2.8.0
  725. */
  726. class Core_Upgrader extends WP_Upgrader {
  727. function upgrade_strings() {
  728. $this->strings['up_to_date'] = __('WordPress is at the latest version.');
  729. $this->strings['no_package'] = __('Update package not available.');
  730. $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>&#8230;');
  731. $this->strings['unpack_package'] = __('Unpacking the update&#8230;');
  732. $this->strings['copy_failed'] = __('Could not copy files.');
  733. }
  734. function upgrade($current) {
  735. global $wp_filesystem, $wp_version;
  736. $this->init();
  737. $this->upgrade_strings();
  738. if ( !empty($feedback) )
  739. add_filter('update_feedback', $feedback);
  740. // Is an update available?
  741. if ( !isset( $current->response ) || $current->response == 'latest' )
  742. return new WP_Error('up_to_date', $this->strings['up_to_date']);
  743. $res = $this->fs_connect( array(ABSPATH, WP_CONTENT_DIR) );
  744. if ( is_wp_error($res) )
  745. return $res;
  746. $wp_dir = trailingslashit($wp_filesystem->abspath());
  747. // If partial update is returned from the API, use that, unless we're doing a reinstall.
  748. // If we cross the new_bundled version number, then use the new_bundled zip.
  749. // Don't though if the constant is set to skip bundled items.
  750. // If the API returns a no_content zip, go with it. Finally, default to the full zip.
  751. if ( $current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version )
  752. $to_download = 'partial';
  753. elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' )
  754. && ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) )
  755. $to_download = 'new_bundled';
  756. elseif ( $current->packages->no_content )
  757. $to_download = 'no_content';
  758. else
  759. $to_download = 'full';
  760. $download = $this->download_package( $current->packages->$to_download );
  761. if ( is_wp_error($download) )
  762. return $download;
  763. $working_dir = $this->unpack_package( $download );
  764. if ( is_wp_error($working_dir) )
  765. return $working_dir;
  766. // Copy update-core.php from the new version into place.
  767. if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) {
  768. $wp_filesystem->delete($working_dir, true);
  769. return new WP_Error('copy_failed', $this->strings['copy_failed']);
  770. }
  771. $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
  772. require(ABSPATH . 'wp-admin/includes/update-core.php');
  773. return update_core($working_dir, $wp_dir);
  774. }
  775. }
  776. /**
  777. * Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes.
  778. *
  779. * @TODO More Detailed docs, for methods as well.
  780. *
  781. * @package WordPress
  782. * @subpackage Upgrader
  783. * @since 2.8.0
  784. */
  785. class WP_Upgrader_Skin {
  786. var $upgrader;
  787. var $done_header = false;
  788. var $result = false;
  789. function __construct($args = array()) {
  790. $defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false );
  791. $this->options = wp_parse_args($args, $defaults);
  792. }
  793. function set_upgrader(&$upgrader) {
  794. if ( is_object($upgrader) )
  795. $this->upgrader =& $upgrader;
  796. $this->add_strings();
  797. }
  798. function add_strings() {
  799. }
  800. function set_result($result) {
  801. $this->result = $result;
  802. }
  803. function request_filesystem_credentials($error = false) {
  804. $url = $this->options['url'];
  805. $context = $this->options['context'];
  806. if ( !empty($this->options['nonce']) )
  807. $url = wp_nonce_url($url, $this->options['nonce']);
  808. return request_filesystem_credentials($url, '', $error, $context); //Possible to bring inline, Leaving as is for now.
  809. }
  810. function header() {
  811. if ( $this->done_header )
  812. return;
  813. $this->done_header = true;
  814. echo '<div class="wrap">';
  815. echo screen_icon();
  816. echo '<h2>' . $this->options['title'] . '</h2>';
  817. }
  818. function footer() {
  819. echo '</div>';
  820. }
  821. function error($errors) {
  822. if ( ! $this->done_header )
  823. $this->header();
  824. if ( is_string($errors) ) {
  825. $this->feedback($errors);
  826. } elseif ( is_wp_error($errors) && $errors->get_error_code() ) {
  827. foreach ( $errors->get_error_messages() as $message ) {
  828. if ( $errors->get_error_data() )
  829. $this->feedback($message . ' ' . $errors->get_error_data() );
  830. else
  831. $this->feedback($message);
  832. }
  833. }
  834. }
  835. function feedback($string) {
  836. if ( isset( $this->upgrader->strings[$string] ) )
  837. $string = $this->upgrader->strings[$string];
  838. if ( strpos($string, '%') !== false ) {
  839. $args = func_get_args();
  840. $args = array_splice($args, 1);
  841. if ( !empty($args) )
  842. $string = vsprintf($string, $args);
  843. }
  844. if ( empty($string) )
  845. return;
  846. show_message($string);
  847. }
  848. function before() {}
  849. function after() {}
  850. }
  851. /**
  852. * Plugin Upgrader Skin for WordPress Plugin Upgrades.
  853. *
  854. * @TODO More Detailed docs, for methods as well.
  855. *
  856. * @package WordPress
  857. * @subpackage Upgrader
  858. * @since 2.8.0
  859. */
  860. class Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
  861. var $plugin = '';
  862. var $plugin_active = false;
  863. var $plugin_network_active = false;
  864. function __construct($args = array()) {
  865. $defaults = array( 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => __('Update Plugin') );
  866. $args = wp_parse_args($args, $defaults);
  867. $this->plugin = $args['plugin'];
  868. $this->plugin_active = is_plugin_active( $this->plugin );
  869. $this->plugin_network_active = is_plugin_active_for_network( $this->plugin );
  870. parent::__construct($args);
  871. }
  872. function after() {
  873. $this->plugin = $this->upgrader->plugin_info();
  874. if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){
  875. show_message(__('Reactivating the plugin&#8230;'));
  876. 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>';
  877. }
  878. $update_actions = array(
  879. '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>',
  880. 'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>'
  881. );
  882. if ( $this->plugin_active )
  883. unset( $update_actions['activate_plugin'] );
  884. if ( ! $this->result || is_wp_error($this->result) )
  885. unset( $update_actions['activate_plugin'] );
  886. $update_actions = apply_filters('update_plugin_complete_actions', $update_actions, $this->plugin);
  887. if ( ! empty($update_actions) )
  888. $this->feedback(implode(' | ', (array)$update_actions));
  889. }
  890. function before() {
  891. if ( $this->upgrader->show_before ) {
  892. echo $this->upgrader->show_before;
  893. $this->upgrader->show_before = '';
  894. }
  895. }
  896. }
  897. /**
  898. * Plugin Upgrader Skin for WordPress Plugin Upgrades.
  899. *
  900. * @package WordPress
  901. * @subpackage Upgrader
  902. * @since 3.0.0
  903. */
  904. class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
  905. var $in_loop = false;
  906. var $error = false;
  907. function __construct($args = array()) {
  908. $defaults = array( 'url' => '', 'nonce' => '' );
  909. $args = wp_parse_args($args, $defaults);
  910. parent::__construct($args);
  911. }
  912. function add_strings() {
  913. $this->upgrader->strings['skin_upgrade_start'] = __('The update process is starting. This process may take a while on some hosts, so please be patient.');
  914. $this->upgrader->strings['skin_update_failed_error'] = __('An error occurred while updating %1$s: <strong>%2$s</strong>.');
  915. $this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.');
  916. $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>';
  917. $this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.');
  918. }
  919. function feedback($string) {
  920. if ( isset( $this->upgrader->strings[$string] ) )
  921. $string = $this->upgrader->strings[$string];
  922. if ( strpos($string, '%') !== false ) {
  923. $args = func_get_args();
  924. $args = array_splice($args, 1);
  925. if ( !empty($args) )
  926. $string = vsprintf($string, $args);
  927. }
  928. if ( empty($string) )
  929. return;
  930. if ( $this->in_loop )
  931. echo "$string<br />\n";
  932. else
  933. echo "<p>$string</p>\n";
  934. }
  935. function header() {
  936. // Nothing, This will be displayed within a iframe.
  937. }
  938. function footer() {
  939. // Nothing, This will be displayed within a iframe.
  940. }
  941. function error($error) {
  942. if ( is_string($error) && isset( $this->upgrader->strings[$error] ) )
  943. $this->error = $this->upgrader->strings[$error];
  944. if ( is_wp_error($error) ) {
  945. foreach ( $error->get_error_messages() as $emessage ) {
  946. if ( $error->get_error_data() )
  947. $messages[] = $emessage . ' ' . $error->get_error_data();
  948. else
  949. $messages[] = $emessage;
  950. }
  951. $this->error = implode(', ', $messages);
  952. }
  953. echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
  954. }
  955. function bulk_header() {
  956. $this->feedback('skin_upgrade_start');
  957. }
  958. function bulk_footer() {
  959. $this->feedback('skin_upgrade_end');
  960. }
  961. function before($title = '') {
  962. $this->in_loop = true;
  963. 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);
  964. echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
  965. echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr($this->upgrader->update_current) . '"><p>';
  966. $this->flush_output();
  967. }
  968. function after($title = '') {
  969. echo '</p></div>';
  970. if ( $this->error || ! $this->result ) {
  971. if ( $this->error )
  972. echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, $this->error) . '</p></div>';
  973. else
  974. echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '</p></div>';
  975. echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
  976. }
  977. if ( !empty($this->result) && !is_wp_error($this->result) ) {
  978. 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>';
  979. echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
  980. }
  981. $this->reset();
  982. $this->flush_output();
  983. }
  984. function reset() {
  985. $this->in_loop = false;
  986. $this->error = false;
  987. }
  988. function flush_output() {
  989. wp_ob_end_flush_all();
  990. flush();
  991. }
  992. }
  993. class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
  994. var $plugin_info = array(); // Plugin_Upgrader::bulk() will fill this in.
  995. function __construct($args = array()) {
  996. parent::__construct($args);
  997. }
  998. function add_strings() {
  999. parent::add_strings();
  1000. $this->upgrader->strings['skin_before_update_header'] = __('Updating Plugin %1$s (%2$d/%3$d)');
  1001. }
  1002. function before() {
  1003. parent::before($this->plugin_info['Title']);
  1004. }
  1005. function after() {
  1006. parent::after($this->plugin_info['Title']);
  1007. }
  1008. function bulk_footer() {
  1009. parent::bulk_footer();
  1010. $update_actions = array(
  1011. 'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>',
  1012. '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>'
  1013. );
  1014. $update_actions = apply_filters('update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info);
  1015. if ( ! empty($update_actions) )
  1016. $this->feedback(implode(' | ', (array)$update_actions));
  1017. }
  1018. }
  1019. class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin {
  1020. var $theme_info = array(); // Theme_Upgrader::bulk() will fill this in.
  1021. function __construct($args = array()) {
  1022. parent::__construct($args);
  1023. }
  1024. function add_strings() {
  1025. parent::add_strings();
  1026. $this->upgrader->strings['skin_before_update_header'] = __('Updating Theme %1$s (%2$d/%3$d)');
  1027. }
  1028. function before() {
  1029. parent::before($this->theme_info['Name']);
  1030. }
  1031. function after() {
  1032. parent::after($this->theme_info['Name']);
  1033. }
  1034. function bulk_footer() {
  1035. parent::bulk_footer();
  1036. $update_actions = array(
  1037. 'themes_page' => '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Go to themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>',
  1038. '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>'
  1039. );
  1040. $update_actions = apply_filters('update_bulk_theme_complete_actions', $update_actions, $this->theme_info);
  1041. if ( ! empty($update_actions) )
  1042. $this->feedback(implode(' | ', (array)$update_actions));
  1043. }
  1044. }
  1045. /**
  1046. * Plugin Installer Skin for WordPress Plugin Installer.
  1047. *
  1048. * @TODO More Detailed docs, for methods as well.
  1049. *
  1050. * @package WordPress
  1051. * @subpackage Upgrader
  1052. * @since 2.8.0
  1053. */
  1054. class Plugin_Installer_Skin extends WP_Upgrader_Skin {
  1055. var $api;
  1056. var $type;
  1057. function __construct($args = array()) {
  1058. $defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' );
  1059. $args = wp_parse_args($args, $defaults);
  1060. $this->type = $args['type'];
  1061. $this->api = isset($args['api']) ? $args['api'] : array();
  1062. parent::__construct($args);
  1063. }
  1064. function before() {
  1065. if ( !empty($this->api) )
  1066. $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin <strong>%s %s</strong>.'), $this->api->name, $this->api->version);
  1067. }
  1068. function after() {
  1069. $plugin_file = $this->upgrader->plugin_info();
  1070. $install_actions = array();
  1071. $from = isset($_GET['from']) ? stripslashes($_GET['from']) : 'plugins';
  1072. if ( 'import' == $from )
  1073. $install_actions['activate_plugin'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;from=import&amp;plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin &amp; Run Importer') . '</a>';
  1074. else
  1075. $install_actions['activate_plugin'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>';
  1076. if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
  1077. $install_actions['network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin for all sites in this network') . '" target="_parent">' . __('Network Activate') . '</a>';
  1078. unset( $install_actions['activate_plugin'] );
  1079. }
  1080. if ( 'import' == $from )
  1081. $install_actions['importers_page'] = '<a href="' . admin_url('import.php') . '" title="' . esc_attr__('Return to Importers') . '" target="_parent">' . __('Return to Importers') . '</a>';
  1082. else if ( $this->type == 'web' )
  1083. $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>';
  1084. else
  1085. $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>';
  1086. if ( ! $this->result || is_wp_error($this->result) ) {
  1087. unset( $install_actions['activate_plugin'] );
  1088. unset( $install_actions['network_activate'] );
  1089. }
  1090. $install_actions = apply_filters('install_plugin_complete_actions', $install_actions, $this->api, $plugin_file);
  1091. if ( ! empty($install_actions) )
  1092. $this->feedback(implode(' | ', (array)$install_actions));
  1093. }
  1094. }
  1095. /**
  1096. * Theme Installer Skin for the WordPress Theme Installer.
  1097. *
  1098. * @TODO More Detailed docs, for methods as well.
  1099. *
  1100. * @package WordPress
  1101. * @subpackage Upgrader
  1102. * @since 2.8.0
  1103. */
  1104. class Theme_Installer_Skin extends WP_Upgrader_Skin {
  1105. var $api;
  1106. var $type;
  1107. function __construct($args = array()) {
  1108. $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' );
  1109. $args = wp_parse_args($args, $defaults);
  1110. $this->type = $args['type'];
  1111. $this->api = isset($args['api']) ? $args['api'] : array();
  1112. parent::__construct($args);
  1113. }
  1114. function before() {
  1115. if ( !empty($this->api) ) {
  1116. /* translators: 1: theme name, 2: version */
  1117. $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the theme <strong>%1$s %2$s</strong>.'), $this->api->name, $this->api->version);
  1118. }
  1119. }
  1120. function after() {
  1121. if ( empty($this->upgrader->result['destination_name']) )
  1122. return;
  1123. $theme_info = $this->upgrader->theme_info();
  1124. if ( empty($theme_info) )
  1125. return;
  1126. $name = $theme_info['Name'];
  1127. $stylesheet = $this->upgrader->result['destination_name'];
  1128. $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet;
  1129. $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'))) ) );
  1130. $activate_link = wp_nonce_url("themes.php?action=activate&amp;template=" . urlencode($template) . "&amp;stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template);
  1131. $install_actions = array(
  1132. 'preview' => '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $name)) . '">' . __('Preview') . '</a>',
  1133. 'activate' => '<a href="' . $activate_link . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate &#8220;%s&#…

Large files files are truncated, but you can click here to view the full file