PageRenderTime 83ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/betaimages/chakalos
PHP | 1673 lines | 1143 code | 340 blank | 190 comment | 233 complexity | 9623cee992afe87da108d197d74a2ae9 MD5 | raw file
Possible License(s): BSD-3-Clause

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['remove_old'] = __('Removing the old version of the plugin&#8230;');
  310. $this->strings['remove_old_failed'] = __('Could not remove the old plugin.');
  311. $this->strings['process_failed'] = __('Plugin update failed.');
  312. $this->strings['process_success'] = __('Plugin updated successfully.');
  313. }
  314. function install_strings() {
  315. $this->strings['no_package'] = __('Install package not available.');
  316. $this->strings['downloading_package'] = __('Downloading install package from <span class="code">%s</span>&#8230;');
  317. $this->strings['unpack_package'] = __('Unpacking the package&#8230;');
  318. $this->strings['installing_package'] = __('Installing the plugin&#8230;');
  319. $this->strings['process_failed'] = __('Plugin install failed.');
  320. $this->strings['process_success'] = __('Plugin installed successfully.');
  321. }
  322. function install($package) {
  323. $this->init();
  324. $this->install_strings();
  325. add_filter('upgrader_source_selection', array(&$this, 'check_package') );
  326. $this->run(array(
  327. 'package' => $package,
  328. 'destination' => WP_PLUGIN_DIR,
  329. 'clear_destination' => false, //Do not overwrite files.
  330. 'clear_working' => true,
  331. 'hook_extra' => array()
  332. ));
  333. remove_filter('upgrader_source_selection', array(&$this, 'check_package') );
  334. if ( ! $this->result || is_wp_error($this->result) )
  335. return $this->result;
  336. // Force refresh of plugin update information
  337. delete_site_transient('update_plugins');
  338. wp_cache_delete( 'plugins', '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. wp_cache_delete( 'plugins', 'plugins' );
  374. }
  375. function bulk_upgrade($plugins) {
  376. $this->init();
  377. $this->bulk = true;
  378. $this->upgrade_strings();
  379. $current = get_site_transient( 'update_plugins' );
  380. add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4);
  381. $this->skin->header();
  382. // Connect to the Filesystem first.
  383. $res = $this->fs_connect( array(WP_CONTENT_DIR, WP_PLUGIN_DIR) );
  384. if ( ! $res ) {
  385. $this->skin->footer();
  386. return false;
  387. }
  388. $this->skin->bulk_header();
  389. // Only start maintenance mode if running in Multisite OR the plugin is in use
  390. $maintenance = is_multisite(); // @TODO: This should only kick in for individual sites if at all possible.
  391. foreach ( $plugins as $plugin )
  392. $maintenance = $maintenance || (is_plugin_active($plugin) && isset($current->response[ $plugin ]) ); // Only activate Maintenance mode if a plugin is active AND has an update available
  393. if ( $maintenance )
  394. $this->maintenance_mode(true);
  395. $results = array();
  396. $this->update_count = count($plugins);
  397. $this->update_current = 0;
  398. foreach ( $plugins as $plugin ) {
  399. $this->update_current++;
  400. $this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true);
  401. if ( !isset( $current->response[ $plugin ] ) ) {
  402. $this->skin->set_result(true);
  403. $this->skin->before();
  404. $this->skin->feedback('up_to_date');
  405. $this->skin->after();
  406. $results[$plugin] = true;
  407. continue;
  408. }
  409. // Get the URL to the zip file
  410. $r = $current->response[ $plugin ];
  411. $this->skin->plugin_active = is_plugin_active($plugin);
  412. $result = $this->run(array(
  413. 'package' => $r->package,
  414. 'destination' => WP_PLUGIN_DIR,
  415. 'clear_destination' => true,
  416. 'clear_working' => true,
  417. 'is_multi' => true,
  418. 'hook_extra' => array(
  419. 'plugin' => $plugin
  420. )
  421. ));
  422. $results[$plugin] = $this->result;
  423. // Prevent credentials auth screen from displaying multiple times
  424. if ( false === $result )
  425. break;
  426. } //end foreach $plugins
  427. $this->maintenance_mode(false);
  428. $this->skin->bulk_footer();
  429. $this->skin->footer();
  430. // Cleanup our hooks, in case something else does a upgrade on this connection.
  431. remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'));
  432. // Force refresh of plugin update information
  433. delete_site_transient('update_plugins');
  434. wp_cache_delete( 'plugins', 'plugins' );
  435. return $results;
  436. }
  437. function check_package($source) {
  438. global $wp_filesystem;
  439. if ( is_wp_error($source) )
  440. return $source;
  441. $working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit(WP_CONTENT_DIR), $source);
  442. if ( ! is_dir($working_directory) ) // Sanity check, if the above fails, lets not prevent installation.
  443. return $source;
  444. // Check the folder contains at least 1 valid plugin.
  445. $plugins_found = false;
  446. foreach ( glob( $working_directory . '*.php' ) as $file ) {
  447. $info = get_plugin_data($file, false, false);
  448. if ( !empty( $info['Name'] ) ) {
  449. $plugins_found = true;
  450. break;
  451. }
  452. }
  453. if ( ! $plugins_found )
  454. return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('No valid plugins were found.') );
  455. return $source;
  456. }
  457. //return plugin info.
  458. function plugin_info() {
  459. if ( ! is_array($this->result) )
  460. return false;
  461. if ( empty($this->result['destination_name']) )
  462. return false;
  463. $plugin = get_plugins('/' . $this->result['destination_name']); //Ensure to pass with leading slash
  464. if ( empty($plugin) )
  465. return false;
  466. $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
  467. return $this->result['destination_name'] . '/' . $pluginfiles[0];
  468. }
  469. //Hooked to pre_install
  470. function deactivate_plugin_before_upgrade($return, $plugin) {
  471. if ( is_wp_error($return) ) //Bypass.
  472. return $return;
  473. $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : '';
  474. if ( empty($plugin) )
  475. return new WP_Error('bad_request', $this->strings['bad_request']);
  476. if ( is_plugin_active($plugin) ) {
  477. //Deactivate the plugin silently, Prevent deactivation hooks from running.
  478. deactivate_plugins($plugin, true);
  479. }
  480. }
  481. //Hooked to upgrade_clear_destination
  482. function delete_old_plugin($removed, $local_destination, $remote_destination, $plugin) {
  483. global $wp_filesystem;
  484. if ( is_wp_error($removed) )
  485. return $removed; //Pass errors through.
  486. $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : '';
  487. if ( empty($plugin) )
  488. return new WP_Error('bad_request', $this->strings['bad_request']);
  489. $plugins_dir = $wp_filesystem->wp_plugins_dir();
  490. $this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) );
  491. if ( ! $wp_filesystem->exists($this_plugin_dir) ) //If its already vanished.
  492. return $removed;
  493. // If plugin is in its own directory, recursively delete the directory.
  494. if ( strpos($plugin, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory separator AND that its not the root plugin folder
  495. $deleted = $wp_filesystem->delete($this_plugin_dir, true);
  496. else
  497. $deleted = $wp_filesystem->delete($plugins_dir . $plugin);
  498. if ( ! $deleted )
  499. return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
  500. return true;
  501. }
  502. }
  503. /**
  504. * Theme Upgrader class for WordPress Themes, It is designed to upgrade/install themes from a local zip, remote zip URL, or uploaded zip file.
  505. *
  506. * @TODO More Detailed docs, for methods as well.
  507. *
  508. * @package WordPress
  509. * @subpackage Upgrader
  510. * @since 2.8.0
  511. */
  512. class Theme_Upgrader extends WP_Upgrader {
  513. var $result;
  514. var $bulk = false;
  515. function upgrade_strings() {
  516. $this->strings['up_to_date'] = __('The theme is at the latest version.');
  517. $this->strings['no_package'] = __('Update package not available.');
  518. $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>&#8230;');
  519. $this->strings['unpack_package'] = __('Unpacking the update&#8230;');
  520. $this->strings['remove_old'] = __('Removing the old version of the theme&#8230;');
  521. $this->strings['remove_old_failed'] = __('Could not remove the old theme.');
  522. $this->strings['process_failed'] = __('Theme update failed.');
  523. $this->strings['process_success'] = __('Theme updated successfully.');
  524. }
  525. function install_strings() {
  526. $this->strings['no_package'] = __('Install package not available.');
  527. $this->strings['downloading_package'] = __('Downloading install package from <span class="code">%s</span>&#8230;');
  528. $this->strings['unpack_package'] = __('Unpacking the package&#8230;');
  529. $this->strings['installing_package'] = __('Installing the theme&#8230;');
  530. $this->strings['process_failed'] = __('Theme install failed.');
  531. $this->strings['process_success'] = __('Theme installed successfully.');
  532. /* translators: 1: theme name, 2: version */
  533. $this->strings['process_success_specific'] = __('Successfully installed the theme <strong>%1$s %2$s</strong>.');
  534. $this->strings['parent_theme_search'] = __('This theme requires a parent theme. Checking if it is installed&#8230;');
  535. /* translators: 1: theme name, 2: version */
  536. $this->strings['parent_theme_prepare_install'] = __('Preparing to install <strong>%1$s %2$s</strong>&#8230;');
  537. /* translators: 1: theme name, 2: version */
  538. $this->strings['parent_theme_currently_installed'] = __('The parent theme, <strong>%1$s %2$s</strong>, is currently installed.');
  539. /* translators: 1: theme name, 2: version */
  540. $this->strings['parent_theme_install_success'] = __('Successfully installed the parent theme, <strong>%1$s %2$s</strong>.');
  541. $this->strings['parent_theme_not_found'] = __('<strong>The parent theme could not be found.</strong> You will need to install the parent theme, <strong>%s</strong>, before you can use this child theme.');
  542. }
  543. function check_parent_theme_filter($install_result, $hook_extra, $child_result) {
  544. // Check to see if we need to install a parent theme
  545. $theme_info = $this->theme_info();
  546. if ( ! $theme_info->parent() )
  547. return $install_result;
  548. $this->skin->feedback( 'parent_theme_search' );
  549. if ( ! $theme_info->parent()->errors() ) {
  550. $this->skin->feedback( 'parent_theme_currently_installed', $theme_info->parent()->display('Name'), $theme_info->parent()->display('Version') );
  551. // We already have the theme, fall through.
  552. return $install_result;
  553. }
  554. // We don't have the parent theme, lets install it
  555. $api = themes_api('theme_information', array('slug' => $theme_info->get('Template'), 'fields' => array('sections' => false, 'tags' => false) ) ); //Save on a bit of bandwidth.
  556. if ( ! $api || is_wp_error($api) ) {
  557. $this->skin->feedback( 'parent_theme_not_found', $theme_info->get('Template') );
  558. // Don't show activate or preview actions after install
  559. add_filter('install_theme_complete_actions', array(&$this, 'hide_activate_preview_actions') );
  560. return $install_result;
  561. }
  562. // Backup required data we're going to override:
  563. $child_api = $this->skin->api;
  564. $child_success_message = $this->strings['process_success'];
  565. // Override them
  566. $this->skin->api = $api;
  567. $this->strings['process_success_specific'] = $this->strings['parent_theme_install_success'];//, $api->name, $api->version);
  568. $this->skin->feedback('parent_theme_prepare_install', $api->name, $api->version);
  569. add_filter('install_theme_complete_actions', '__return_false', 999); // Don't show any actions after installing the theme.
  570. // Install the parent theme
  571. $parent_result = $this->run( array(
  572. 'package' => $api->download_link,
  573. 'destination' => WP_CONTENT_DIR . '/themes',
  574. 'clear_destination' => false, //Do not overwrite files.
  575. 'clear_working' => true
  576. ) );
  577. if ( is_wp_error($parent_result) )
  578. add_filter('install_theme_complete_actions', array(&$this, 'hide_activate_preview_actions') );
  579. // Start cleaning up after the parents installation
  580. remove_filter('install_theme_complete_actions', '__return_false', 999);
  581. // Reset child's result and data
  582. $this->result = $child_result;
  583. $this->skin->api = $child_api;
  584. $this->strings['process_success'] = $child_success_message;
  585. return $install_result;
  586. }
  587. function hide_activate_preview_actions($actions) {
  588. unset($actions['activate'], $actions['preview']);
  589. return $actions;
  590. }
  591. function install($package) {
  592. $this->init();
  593. $this->install_strings();
  594. add_filter('upgrader_source_selection', array(&$this, 'check_package') );
  595. add_filter('upgrader_post_install', array(&$this, 'check_parent_theme_filter'), 10, 3);
  596. $options = array(
  597. 'package' => $package,
  598. 'destination' => WP_CONTENT_DIR . '/themes',
  599. 'clear_destination' => false, //Do not overwrite files.
  600. 'clear_working' => true
  601. );
  602. $this->run($options);
  603. remove_filter('upgrader_source_selection', array(&$this, 'check_package') );
  604. remove_filter('upgrader_post_install', array(&$this, 'check_parent_theme_filter'), 10, 3);
  605. if ( ! $this->result || is_wp_error($this->result) )
  606. return $this->result;
  607. // Force refresh of theme update information
  608. wp_clean_themes_cache();
  609. return true;
  610. }
  611. function upgrade($theme) {
  612. $this->init();
  613. $this->upgrade_strings();
  614. // Is an update available?
  615. $current = get_site_transient( 'update_themes' );
  616. if ( !isset( $current->response[ $theme ] ) ) {
  617. $this->skin->before();
  618. $this->skin->set_result(false);
  619. $this->skin->error('up_to_date');
  620. $this->skin->after();
  621. return false;
  622. }
  623. $r = $current->response[ $theme ];
  624. add_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
  625. add_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
  626. add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
  627. $options = array(
  628. 'package' => $r['package'],
  629. 'destination' => WP_CONTENT_DIR . '/themes',
  630. 'clear_destination' => true,
  631. 'clear_working' => true,
  632. 'hook_extra' => array(
  633. 'theme' => $theme
  634. )
  635. );
  636. $this->run($options);
  637. remove_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
  638. remove_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
  639. remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
  640. if ( ! $this->result || is_wp_error($this->result) )
  641. return $this->result;
  642. // Force refresh of theme update information
  643. wp_clean_themes_cache();
  644. return true;
  645. }
  646. function bulk_upgrade($themes) {
  647. $this->init();
  648. $this->bulk = true;
  649. $this->upgrade_strings();
  650. $current = get_site_transient( 'update_themes' );
  651. add_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
  652. add_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
  653. add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
  654. $this->skin->header();
  655. // Connect to the Filesystem first.
  656. $res = $this->fs_connect( array(WP_CONTENT_DIR) );
  657. if ( ! $res ) {
  658. $this->skin->footer();
  659. return false;
  660. }
  661. $this->skin->bulk_header();
  662. // Only start maintenance mode if running in Multisite OR the theme is in use
  663. $maintenance = is_multisite(); // @TODO: This should only kick in for individual sites if at all possible.
  664. foreach ( $themes as $theme )
  665. $maintenance = $maintenance || $theme == get_stylesheet() || $theme == get_template();
  666. if ( $maintenance )
  667. $this->maintenance_mode(true);
  668. $results = array();
  669. $this->update_count = count($themes);
  670. $this->update_current = 0;
  671. foreach ( $themes as $theme ) {
  672. $this->update_current++;
  673. $this->skin->theme_info = $this->theme_info($theme);
  674. if ( !isset( $current->response[ $theme ] ) ) {
  675. $this->skin->set_result(true);
  676. $this->skin->before();
  677. $this->skin->feedback('up_to_date');
  678. $this->skin->after();
  679. $results[$theme] = true;
  680. continue;
  681. }
  682. // Get the URL to the zip file
  683. $r = $current->response[ $theme ];
  684. $options = array(
  685. 'package' => $r['package'],
  686. 'destination' => WP_CONTENT_DIR . '/themes',
  687. 'clear_destination' => true,
  688. 'clear_working' => true,
  689. 'hook_extra' => array(
  690. 'theme' => $theme
  691. )
  692. );
  693. $result = $this->run($options);
  694. $results[$theme] = $this->result;
  695. // Prevent credentials auth screen from displaying multiple times
  696. if ( false === $result )
  697. break;
  698. } //end foreach $plugins
  699. $this->maintenance_mode(false);
  700. $this->skin->bulk_footer();
  701. $this->skin->footer();
  702. // Cleanup our hooks, in case something else does a upgrade on this connection.
  703. remove_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
  704. remove_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
  705. remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
  706. // Force refresh of theme update information
  707. wp_clean_themes_cache();
  708. return $results;
  709. }
  710. function check_package($source) {
  711. global $wp_filesystem;
  712. if ( is_wp_error($source) )
  713. return $source;
  714. // Check the folder contains a valid theme
  715. $working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit(WP_CONTENT_DIR), $source);
  716. if ( ! is_dir($working_directory) ) // Sanity check, if the above fails, lets not prevent installation.
  717. return $source;
  718. // A proper archive should have a style.css file in the single subdirectory
  719. if ( ! file_exists( $working_directory . 'style.css' ) )
  720. return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('The theme is missing the <code>style.css</code> stylesheet.') );
  721. $info = get_file_data( $working_directory . 'style.css', array( 'Name' => 'Theme Name', 'Template' => 'Template' ) );
  722. if ( empty( $info['Name'] ) )
  723. return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __("The <code>style.css</code> stylesheet doesn't contain a valid theme header.") );
  724. // If it's not a child theme, it must have at least an index.php to be legit.
  725. if ( empty( $info['Template'] ) && ! file_exists( $working_directory . 'index.php' ) )
  726. return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('The theme is missing the <code>index.php</code> file.') );
  727. return $source;
  728. }
  729. function current_before($return, $theme) {
  730. if ( is_wp_error($return) )
  731. return $return;
  732. $theme = isset($theme['theme']) ? $theme['theme'] : '';
  733. if ( $theme != get_stylesheet() ) //If not current
  734. return $return;
  735. //Change to maintenance mode now.
  736. if ( ! $this->bulk )
  737. $this->maintenance_mode(true);
  738. return $return;
  739. }
  740. function current_after($return, $theme) {
  741. if ( is_wp_error($return) )
  742. return $return;
  743. $theme = isset($theme['theme']) ? $theme['theme'] : '';
  744. if ( $theme != get_stylesheet() ) // If not current
  745. return $return;
  746. // Ensure stylesheet name hasn't changed after the upgrade:
  747. if ( $theme == get_stylesheet() && $theme != $this->result['destination_name'] ) {
  748. wp_clean_themes_cache();
  749. $stylesheet = $this->result['destination_name'];
  750. switch_theme( $stylesheet );
  751. }
  752. //Time to remove maintenance mode
  753. if ( ! $this->bulk )
  754. $this->maintenance_mode(false);
  755. return $return;
  756. }
  757. function delete_old_theme($removed, $local_destination, $remote_destination, $theme) {
  758. global $wp_filesystem;
  759. $theme = isset($theme['theme']) ? $theme['theme'] : '';
  760. if ( is_wp_error($removed) || empty($theme) )
  761. return $removed; //Pass errors through.
  762. $themes_dir = $wp_filesystem->wp_themes_dir();
  763. if ( $wp_filesystem->exists( trailingslashit($themes_dir) . $theme ) )
  764. if ( ! $wp_filesystem->delete( trailingslashit($themes_dir) . $theme, true ) )
  765. return false;
  766. return true;
  767. }
  768. function theme_info($theme = null) {
  769. if ( empty($theme) ) {
  770. if ( !empty($this->result['destination_name']) )
  771. $theme = $this->result['destination_name'];
  772. else
  773. return false;
  774. }
  775. return wp_get_theme( $theme, WP_CONTENT_DIR . '/themes/' );
  776. }
  777. }
  778. /**
  779. * Core Upgrader class for WordPress. It allows for WordPress to upgrade itself in combination with the wp-admin/includes/update-core.php file
  780. *
  781. * @TODO More Detailed docs, for methods as well.
  782. *
  783. * @package WordPress
  784. * @subpackage Upgrader
  785. * @since 2.8.0
  786. */
  787. class Core_Upgrader extends WP_Upgrader {
  788. function upgrade_strings() {
  789. $this->strings['up_to_date'] = __('WordPress is at the latest version.');
  790. $this->strings['no_package'] = __('Update package not available.');
  791. $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>&#8230;');
  792. $this->strings['unpack_package'] = __('Unpacking the update&#8230;');
  793. $this->strings['copy_failed'] = __('Could not copy files.');
  794. $this->strings['copy_failed_space'] = __('Could not copy files. You may have run out of disk space.' );
  795. }
  796. function upgrade($current) {
  797. global $wp_filesystem, $wp_version;
  798. $this->init();
  799. $this->upgrade_strings();
  800. if ( !empty($feedback) )
  801. add_filter('update_feedback', $feedback);
  802. // Is an update available?
  803. if ( !isset( $current->response ) || $current->response == 'latest' )
  804. return new WP_Error('up_to_date', $this->strings['up_to_date']);
  805. $res = $this->fs_connect( array(ABSPATH, WP_CONTENT_DIR) );
  806. if ( is_wp_error($res) )
  807. return $res;
  808. $wp_dir = trailingslashit($wp_filesystem->abspath());
  809. // If partial update is returned from the API, use that, unless we're doing a reinstall.
  810. // If we cross the new_bundled version number, then use the new_bundled zip.
  811. // Don't though if the constant is set to skip bundled items.
  812. // If the API returns a no_content zip, go with it. Finally, default to the full zip.
  813. if ( $current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version )
  814. $to_download = 'partial';
  815. elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' )
  816. && ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) )
  817. $to_download = 'new_bundled';
  818. elseif ( $current->packages->no_content )
  819. $to_download = 'no_content';
  820. else
  821. $to_download = 'full';
  822. $download = $this->download_package( $current->packages->$to_download );
  823. if ( is_wp_error($download) )
  824. return $download;
  825. $working_dir = $this->unpack_package( $download );
  826. if ( is_wp_error($working_dir) )
  827. return $working_dir;
  828. // Copy update-core.php from the new version into place.
  829. if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) {
  830. $wp_filesystem->delete($working_dir, true);
  831. return new WP_Error('copy_failed', $this->strings['copy_failed']);
  832. }
  833. $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
  834. require(ABSPATH . 'wp-admin/includes/update-core.php');
  835. if ( ! function_exists( 'update_core' ) )
  836. return new WP_Error( 'copy_failed_space', $this->strings['copy_failed_space'] );
  837. return update_core($working_dir, $wp_dir);
  838. }
  839. }
  840. /**
  841. * Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes.
  842. *
  843. * @TODO More Detailed docs, for methods as well.
  844. *
  845. * @package WordPress
  846. * @subpackage Upgrader
  847. * @since 2.8.0
  848. */
  849. class WP_Upgrader_Skin {
  850. var $upgrader;
  851. var $done_header = false;
  852. var $result = false;
  853. function __construct($args = array()) {
  854. $defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false );
  855. $this->options = wp_parse_args($args, $defaults);
  856. }
  857. function set_upgrader(&$upgrader) {
  858. if ( is_object($upgrader) )
  859. $this->upgrader =& $upgrader;
  860. $this->add_strings();
  861. }
  862. function add_strings() {
  863. }
  864. function set_result($result) {
  865. $this->result = $result;
  866. }
  867. function request_filesystem_credentials($error = false) {
  868. $url = $this->options['url'];
  869. $context = $this->options['context'];
  870. if ( !empty($this->options['nonce']) )
  871. $url = wp_nonce_url($url, $this->options['nonce']);
  872. return request_filesystem_credentials($url, '', $error, $context); //Possible to bring inline, Leaving as is for now.
  873. }
  874. function header() {
  875. if ( $this->done_header )
  876. return;
  877. $this->done_header = true;
  878. echo '<div class="wrap">';
  879. echo screen_icon();
  880. echo '<h2>' . $this->options['title'] . '</h2>';
  881. }
  882. function footer() {
  883. echo '</div>';
  884. }
  885. function error($errors) {
  886. if ( ! $this->done_header )
  887. $this->header();
  888. if ( is_string($errors) ) {
  889. $this->feedback($errors);
  890. } elseif ( is_wp_error($errors) && $errors->get_error_code() ) {
  891. foreach ( $errors->get_error_messages() as $message ) {
  892. if ( $errors->get_error_data() )
  893. $this->feedback($message . ' ' . $errors->get_error_data() );
  894. else
  895. $this->feedback($message);
  896. }
  897. }
  898. }
  899. function feedback($string) {
  900. if ( isset( $this->upgrader->strings[$string] ) )
  901. $string = $this->upgrader->strings[$string];
  902. if ( strpos($string, '%') !== false ) {
  903. $args = func_get_args();
  904. $args = array_splice($args, 1);
  905. if ( !empty($args) )
  906. $string = vsprintf($string, $args);
  907. }
  908. if ( empty($string) )
  909. return;
  910. show_message($string);
  911. }
  912. function before() {}
  913. function after() {}
  914. }
  915. /**
  916. * Plugin Upgrader Skin for WordPress Plugin Upgrades.
  917. *
  918. * @TODO More Detailed docs, for methods as well.
  919. *
  920. * @package WordPress
  921. * @subpackage Upgrader
  922. * @since 2.8.0
  923. */
  924. class Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
  925. var $plugin = '';
  926. var $plugin_active = false;
  927. var $plugin_network_active = false;
  928. function __construct($args = array()) {
  929. $defaults = array( 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => __('Update Plugin') );
  930. $args = wp_parse_args($args, $defaults);
  931. $this->plugin = $args['plugin'];
  932. $this->plugin_active = is_plugin_active( $this->plugin );
  933. $this->plugin_network_active = is_plugin_active_for_network( $this->plugin );
  934. parent::__construct($args);
  935. }
  936. function after() {
  937. $this->plugin = $this->upgrader->plugin_info();
  938. if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){
  939. 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>';
  940. }
  941. $update_actions = array(
  942. '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>',
  943. 'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>'
  944. );
  945. if ( $this->plugin_active || ! $this->result || is_wp_error( $this->result ) || ! current_user_can( 'activate_plugins' ) )
  946. unset( $update_actions['activate_plugin'] );
  947. $update_actions = apply_filters('update_plugin_complete_actions', $update_actions, $this->plugin);
  948. if ( ! empty($update_actions) )
  949. $this->feedback(implode(' | ', (array)$update_actions));
  950. }
  951. function before() {
  952. if ( $this->upgrader->show_before ) {
  953. echo $this->upgrader->show_before;
  954. $this->upgrader->show_before = '';
  955. }
  956. }
  957. }
  958. /**
  959. * Plugin Upgrader Skin for WordPress Plugin Upgrades.
  960. *
  961. * @package WordPress
  962. * @subpackage Upgrader
  963. * @since 3.0.0
  964. */
  965. class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
  966. var $in_loop = false;
  967. var $error = false;
  968. function __construct($args = array()) {
  969. $defaults = array( 'url' => '', 'nonce' => '' );
  970. $args = wp_parse_args($args, $defaults);
  971. parent::__construct($args);
  972. }
  973. function add_strings() {
  974. $this->upgrader->strings['skin_upgrade_start'] = __('The update process is starting. This process may take a while on some hosts, so please be patient.');
  975. $this->upgrader->strings['skin_update_failed_error'] = __('An error occurred while updating %1$s: <strong>%2$s</strong>.');
  976. $this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.');
  977. $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>';
  978. $this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.');
  979. }
  980. function feedback($string) {
  981. if ( isset( $this->upgrader->strings[$string] ) )
  982. $string = $this->upgrader->strings[$string];
  983. if ( strpos($string, '%') !== false ) {
  984. $args = func_get_args();
  985. $args = array_splice($args, 1);
  986. if ( !empty($args) )
  987. $string = vsprintf($string, $args);
  988. }
  989. if ( empty($string) )
  990. return;
  991. if ( $this->in_loop )
  992. echo "$string<br />\n";
  993. else
  994. echo "<p>$string</p>\n";
  995. }
  996. function header() {
  997. // Nothing, This will be displayed within a iframe.
  998. }
  999. function footer() {
  1000. // Nothing, This will be displayed within a iframe.
  1001. }
  1002. function error($error) {
  1003. if ( is_string($error) && isset( $this->upgrader->strings[$error] ) )
  1004. $this->error = $this->upgrader->strings[$error];
  1005. if ( is_wp_error($error) ) {
  1006. foreach ( $error->get_error_messages() as $emessage ) {
  1007. if ( $error->get_error_data() )
  1008. $messages[] = $emessage . ' ' . $error->get_error_data();
  1009. else
  1010. $messages[] = $emessage;
  1011. }
  1012. $this->error = implode(', ', $messages);
  1013. }
  1014. echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
  1015. }
  1016. function bulk_header() {
  1017. $this->feedback('skin_upgrade_start');
  1018. }
  1019. function bulk_footer() {
  1020. $this->feedback('skin_upgrade_end');
  1021. }
  1022. function before($title = '') {
  1023. $this->in_loop = true;
  1024. printf( '<h4>' . $this->upgrader->strings['skin_before_update_header'] . ' <span class="spinner waiting-' . $this->upgrader->update_current . '"></span></h4>', $title, $this->upgrader->update_current, $this->upgrader->update_count);
  1025. echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').css("display", "inline-block");</script>';
  1026. echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr($this->upgrader->update_current) . '"><p>';
  1027. $this->flush_output();
  1028. }
  1029. function after($title = '') {
  1030. echo '</p></div>';
  1031. if ( $this->error || ! $this->result ) {
  1032. if ( $this->error )
  1033. echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, $this->error) . '</p></div>';
  1034. else
  1035. echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '</p></div>';
  1036. echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
  1037. }
  1038. if ( !empty($this->result) && !is_wp_error($this->result) ) {
  1039. 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>';
  1040. echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
  1041. }
  1042. $this->reset();
  1043. $this->flush_output();
  1044. }
  1045. function reset() {
  1046. $this->in_loop = false;
  1047. $this->error = false;
  1048. }
  1049. function flush_output() {
  1050. wp_ob_end_flush_all();
  1051. flush();
  1052. }
  1053. }
  1054. class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
  1055. var $plugin_info = array(); // Plugin_Upgrader::bulk() will fill this in.
  1056. function __construct($args = array()) {
  1057. parent::__construct($args);
  1058. }
  1059. function add_strings() {
  1060. parent::add_strings();
  1061. $this->upgrader->strings['skin_before_update_header'] = __('Updating Plugin %1$s (%2$d/%3$d)');
  1062. }
  1063. function before() {
  1064. parent::before($this->plugin_info['Title']);
  1065. }
  1066. function after() {
  1067. parent::after($this->plugin_info['Title']);
  1068. }
  1069. function bulk_footer() {
  1070. parent::bulk_footer();
  1071. $update_actions = array(
  1072. 'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>',
  1073. '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>'
  1074. );
  1075. if ( ! current_user_can( 'activate_plugins' ) )
  1076. unset( $update_actions['plugins_page'] );
  1077. $update_actions = apply_filters('update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info);
  1078. if ( ! empty($update_actions) )
  1079. $this->feedback(implode(' | ', (array)$update_actions));
  1080. }
  1081. }
  1082. class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin {
  1083. var $theme_info = array(); // Theme_Upgrader::bulk() will fill this in.
  1084. function __construct($args = array()) {
  1085. parent::__construct($args);
  1086. }
  1087. function add_strings() {
  1088. parent::add_strings();
  1089. $this->upgrader->strings['skin_before_update_header'] = __('Updating Theme %1$s (%2$d/%3$d)');
  1090. }
  1091. function before() {
  1092. parent::before( $this->theme_info->display('Name') );
  1093. }
  1094. function after() {
  1095. parent::after( $this->theme_info->display('Name') );
  1096. }
  1097. function bulk_footer() {
  1098. parent::bulk_footer();
  1099. $update_actions = array(
  1100. 'themes_page' => '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Go to themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>',
  1101. '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>'
  1102. );
  1103. if ( ! current_user_can( 'switch_themes' ) && ! current_user_can( 'edit_theme_options' ) )
  1104. unset( $update_actions['themes_page'] );
  1105. $update_actions = apply_filters('update_bulk_theme_complete_actions', $update_actions, $this->theme_info );
  1106. if ( ! empty($update_actions) )
  1107. $this->feedback(implode(' | ', (array)$update_actions));
  1108. }
  1109. }
  1110. /**
  1111. * Plugin Installer Skin for WordPress Plugin Installer.
  1112. *
  1113. * @TODO More Detailed docs, for methods as well.
  1114. *
  1115. * @package WordPress
  1116. * @subpackage Upgrader
  1117. * @since 2.8.0
  1118. */
  1119. class Plugin_Installer_Skin extends WP_Upgrader_Skin {
  1120. var $api;
  1121. var $type;
  1122. function __construct($args = array()) {
  1123. $defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' );
  1124. $args = wp_parse_args($args, $defaults);
  1125. $this->type = $args['type'];
  1126. $this->api = isset($args['api']) ? $args['api'] : array();
  1127. parent::__construct($args);
  1128. }
  1129. function before() {
  1130. if ( !empty($this->api) )
  1131. $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin <strong>%s %s</strong>.'), $this->api->name, $this->api->version);
  1132. }
  1133. function after() {
  1134. $plugin_file = $this->upgrader->plugin_info();
  1135. $install_actions = array();
  1136. $from = isset($_GET['from']) ? stripslashes($_GET['from']) : 'plugins';
  1137. if ( 'import' == $from )
  1138. $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="' . e

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