From bc02809fe3c06b414a3c9a58f60f7b0bcaa1ab00 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Wed, 4 Sep 2013 06:35:10 +0000 Subject: [PATCH] Upgrader: Split the UI "skins" out from the main Upgrader file into a seperate file to reduce the length of the files. See #22704 Built from https://develop.svn.wordpress.org/trunk@25227 git-svn-id: http://core.svn.wordpress.org/trunk@25197 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/class-wp-upgrader-skins.php | 529 +++++++++++++++++ wp-admin/includes/class-wp-upgrader.php | 543 +----------------- 2 files changed, 531 insertions(+), 541 deletions(-) create mode 100644 wp-admin/includes/class-wp-upgrader-skins.php diff --git a/wp-admin/includes/class-wp-upgrader-skins.php b/wp-admin/includes/class-wp-upgrader-skins.php new file mode 100644 index 0000000000..b48944f673 --- /dev/null +++ b/wp-admin/includes/class-wp-upgrader-skins.php @@ -0,0 +1,529 @@ + '', 'nonce' => '', 'title' => '', 'context' => false ); + $this->options = wp_parse_args($args, $defaults); + } + + function set_upgrader(&$upgrader) { + if ( is_object($upgrader) ) + $this->upgrader =& $upgrader; + $this->add_strings(); + } + + function add_strings() { + } + + function set_result($result) { + $this->result = $result; + } + + function request_filesystem_credentials($error = false) { + $url = $this->options['url']; + $context = $this->options['context']; + if ( !empty($this->options['nonce']) ) + $url = wp_nonce_url($url, $this->options['nonce']); + return request_filesystem_credentials($url, '', $error, $context); //Possible to bring inline, Leaving as is for now. + } + + function header() { + if ( $this->done_header ) + return; + $this->done_header = true; + echo '
'; + screen_icon(); + echo '

' . $this->options['title'] . '

'; + } + function footer() { + echo '
'; + } + + function error($errors) { + if ( ! $this->done_header ) + $this->header(); + if ( is_string($errors) ) { + $this->feedback($errors); + } elseif ( is_wp_error($errors) && $errors->get_error_code() ) { + foreach ( $errors->get_error_messages() as $message ) { + if ( $errors->get_error_data() ) + $this->feedback($message . ' ' . esc_html( $errors->get_error_data() ) ); + else + $this->feedback($message); + } + } + } + + function feedback($string) { + if ( isset( $this->upgrader->strings[$string] ) ) + $string = $this->upgrader->strings[$string]; + + if ( strpos($string, '%') !== false ) { + $args = func_get_args(); + $args = array_splice($args, 1); + if ( $args ) { + $args = array_map( 'strip_tags', $args ); + $args = array_map( 'esc_html', $args ); + $string = vsprintf($string, $args); + } + } + if ( empty($string) ) + return; + show_message($string); + } + function before() {} + function after() {} + +} + +/** + * Plugin Upgrader Skin for WordPress Plugin Upgrades. + * + * @package WordPress + * @subpackage Upgrader + * @since 2.8.0 + */ +class Plugin_Upgrader_Skin extends WP_Upgrader_Skin { + var $plugin = ''; + var $plugin_active = false; + var $plugin_network_active = false; + + function __construct($args = array()) { + $defaults = array( 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => __('Update Plugin') ); + $args = wp_parse_args($args, $defaults); + + $this->plugin = $args['plugin']; + + $this->plugin_active = is_plugin_active( $this->plugin ); + $this->plugin_network_active = is_plugin_active_for_network( $this->plugin ); + + parent::__construct($args); + } + + function after() { + $this->plugin = $this->upgrader->plugin_info(); + if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){ + echo ''; + } + + $update_actions = array( + 'activate_plugin' => '' . __('Activate Plugin') . '', + 'plugins_page' => '' . __('Return to Plugins page') . '' + ); + if ( $this->plugin_active || ! $this->result || is_wp_error( $this->result ) || ! current_user_can( 'activate_plugins' ) ) + unset( $update_actions['activate_plugin'] ); + + $update_actions = apply_filters('update_plugin_complete_actions', $update_actions, $this->plugin); + if ( ! empty($update_actions) ) + $this->feedback(implode(' | ', (array)$update_actions)); + } + + function before() { + if ( $this->upgrader->show_before ) { + echo $this->upgrader->show_before; + $this->upgrader->show_before = ''; + } + } +} + +/** + * Plugin Upgrader Skin for WordPress Plugin Upgrades. + * + * @package WordPress + * @subpackage Upgrader + * @since 3.0.0 + */ +class Bulk_Upgrader_Skin extends WP_Upgrader_Skin { + var $in_loop = false; + var $error = false; + + function __construct($args = array()) { + $defaults = array( 'url' => '', 'nonce' => '' ); + $args = wp_parse_args($args, $defaults); + + parent::__construct($args); + } + + function add_strings() { + $this->upgrader->strings['skin_upgrade_start'] = __('The update process is starting. This process may take a while on some hosts, so please be patient.'); + $this->upgrader->strings['skin_update_failed_error'] = __('An error occurred while updating %1$s: %2$s'); + $this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.'); + $this->upgrader->strings['skin_update_successful'] = __('%1$s updated successfully.').' '.__('Show Details').'.'; + $this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.'); + } + + function feedback($string) { + if ( isset( $this->upgrader->strings[$string] ) ) + $string = $this->upgrader->strings[$string]; + + if ( strpos($string, '%') !== false ) { + $args = func_get_args(); + $args = array_splice($args, 1); + if ( $args ) { + $args = array_map( 'strip_tags', $args ); + $args = array_map( 'esc_html', $args ); + $string = vsprintf($string, $args); + } + } + if ( empty($string) ) + return; + if ( $this->in_loop ) + echo "$string
\n"; + else + echo "

$string

\n"; + } + + function header() { + // Nothing, This will be displayed within a iframe. + } + + function footer() { + // Nothing, This will be displayed within a iframe. + } + function error($error) { + if ( is_string($error) && isset( $this->upgrader->strings[$error] ) ) + $this->error = $this->upgrader->strings[$error]; + + if ( is_wp_error($error) ) { + foreach ( $error->get_error_messages() as $emessage ) { + if ( $error->get_error_data() ) + $messages[] = $emessage . ' ' . esc_html( $error->get_error_data() ); + else + $messages[] = $emessage; + } + $this->error = implode(', ', $messages); + } + echo ''; + } + + function bulk_header() { + $this->feedback('skin_upgrade_start'); + } + + function bulk_footer() { + $this->feedback('skin_upgrade_end'); + } + + function before($title = '') { + $this->in_loop = true; + printf( '

' . $this->upgrader->strings['skin_before_update_header'] . '

', $title, $this->upgrader->update_current, $this->upgrader->update_count); + echo ''; + echo '

'; + $this->flush_output(); + } + + function after($title = '') { + echo '

'; + if ( $this->error || ! $this->result ) { + if ( $this->error ) + echo '

' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, $this->error) . '

'; + else + echo '

' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '

'; + + echo ''; + } + if ( $this->result && ! is_wp_error( $this->result ) ) { + if ( ! $this->error ) + echo '

' . sprintf($this->upgrader->strings['skin_update_successful'], $title, 'jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').toggle();jQuery(\'span\', this).toggle(); return false;') . '

'; + echo ''; + } + + $this->reset(); + $this->flush_output(); + } + + function reset() { + $this->in_loop = false; + $this->error = false; + } + + function flush_output() { + wp_ob_end_flush_all(); + flush(); + } +} + +class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin { + var $plugin_info = array(); // Plugin_Upgrader::bulk() will fill this in. + + function __construct($args = array()) { + parent::__construct($args); + } + + function add_strings() { + parent::add_strings(); + $this->upgrader->strings['skin_before_update_header'] = __('Updating Plugin %1$s (%2$d/%3$d)'); + } + + function before($title = '') { + parent::before($this->plugin_info['Title']); + } + + function after($title = '') { + parent::after($this->plugin_info['Title']); + } + function bulk_footer() { + parent::bulk_footer(); + $update_actions = array( + 'plugins_page' => '' . __('Return to Plugins page') . '', + 'updates_page' => '' . __('Return to WordPress Updates') . '' + ); + if ( ! current_user_can( 'activate_plugins' ) ) + unset( $update_actions['plugins_page'] ); + + $update_actions = apply_filters('update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info); + if ( ! empty($update_actions) ) + $this->feedback(implode(' | ', (array)$update_actions)); + } +} + +class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin { + var $theme_info = array(); // Theme_Upgrader::bulk() will fill this in. + + function __construct($args = array()) { + parent::__construct($args); + } + + function add_strings() { + parent::add_strings(); + $this->upgrader->strings['skin_before_update_header'] = __('Updating Theme %1$s (%2$d/%3$d)'); + } + + function before($title = '') { + parent::before( $this->theme_info->display('Name') ); + } + + function after($title = '') { + parent::after( $this->theme_info->display('Name') ); + } + + function bulk_footer() { + parent::bulk_footer(); + $update_actions = array( + 'themes_page' => '' . __('Return to Themes page') . '', + 'updates_page' => '' . __('Return to WordPress Updates') . '' + ); + if ( ! current_user_can( 'switch_themes' ) && ! current_user_can( 'edit_theme_options' ) ) + unset( $update_actions['themes_page'] ); + + $update_actions = apply_filters('update_bulk_theme_complete_actions', $update_actions, $this->theme_info ); + if ( ! empty($update_actions) ) + $this->feedback(implode(' | ', (array)$update_actions)); + } +} + +/** + * Plugin Installer Skin for WordPress Plugin Installer. + * + * @package WordPress + * @subpackage Upgrader + * @since 2.8.0 + */ +class Plugin_Installer_Skin extends WP_Upgrader_Skin { + var $api; + var $type; + + function __construct($args = array()) { + $defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' ); + $args = wp_parse_args($args, $defaults); + + $this->type = $args['type']; + $this->api = isset($args['api']) ? $args['api'] : array(); + + parent::__construct($args); + } + + function before() { + if ( !empty($this->api) ) + $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin %s %s.'), $this->api->name, $this->api->version); + } + + function after() { + + $plugin_file = $this->upgrader->plugin_info(); + + $install_actions = array(); + + $from = isset($_GET['from']) ? wp_unslash( $_GET['from'] ) : 'plugins'; + + if ( 'import' == $from ) + $install_actions['activate_plugin'] = '' . __('Activate Plugin & Run Importer') . ''; + else + $install_actions['activate_plugin'] = '' . __('Activate Plugin') . ''; + + if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) { + $install_actions['network_activate'] = '' . __('Network Activate') . ''; + unset( $install_actions['activate_plugin'] ); + } + + if ( 'import' == $from ) + $install_actions['importers_page'] = '' . __('Return to Importers') . ''; + else if ( $this->type == 'web' ) + $install_actions['plugins_page'] = '' . __('Return to Plugin Installer') . ''; + else + $install_actions['plugins_page'] = '' . __('Return to Plugins page') . ''; + + if ( ! $this->result || is_wp_error($this->result) ) { + unset( $install_actions['activate_plugin'], $install_actions['network_activate'] ); + } elseif ( ! current_user_can( 'activate_plugins' ) ) { + unset( $install_actions['activate_plugin'] ); + } + + $install_actions = apply_filters('install_plugin_complete_actions', $install_actions, $this->api, $plugin_file); + if ( ! empty($install_actions) ) + $this->feedback(implode(' | ', (array)$install_actions)); + } +} + +/** + * Theme Installer Skin for the WordPress Theme Installer. + * + * @package WordPress + * @subpackage Upgrader + * @since 2.8.0 + */ +class Theme_Installer_Skin extends WP_Upgrader_Skin { + var $api; + var $type; + + function __construct($args = array()) { + $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' ); + $args = wp_parse_args($args, $defaults); + + $this->type = $args['type']; + $this->api = isset($args['api']) ? $args['api'] : array(); + + parent::__construct($args); + } + + function before() { + if ( !empty($this->api) ) + $this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version); + } + + function after() { + if ( empty($this->upgrader->result['destination_name']) ) + return; + + $theme_info = $this->upgrader->theme_info(); + if ( empty( $theme_info ) ) + return; + + $name = $theme_info->display('Name'); + $stylesheet = $this->upgrader->result['destination_name']; + $template = $theme_info->get_template(); + + $preview_link = add_query_arg( array( + 'preview' => 1, + 'template' => urlencode( $template ), + 'stylesheet' => urlencode( $stylesheet ), + ), trailingslashit( home_url() ) ); + + $activate_link = add_query_arg( array( + 'action' => 'activate', + 'template' => urlencode( $template ), + 'stylesheet' => urlencode( $stylesheet ), + ), admin_url('themes.php') ); + $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet ); + + $install_actions = array(); + $install_actions['preview'] = '' . __('Preview') . ''; + $install_actions['preview'] .= '' . __('Live Preview') . ''; + $install_actions['activate'] = '' . __('Activate') . ''; + + if ( is_network_admin() && current_user_can( 'manage_network_themes' ) ) + $install_actions['network_enable'] = '' . __( 'Network Enable' ) . ''; + + if ( $this->type == 'web' ) + $install_actions['themes_page'] = '' . __('Return to Theme Installer') . ''; + elseif ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) ) + $install_actions['themes_page'] = '' . __('Return to Themes page') . ''; + + if ( ! $this->result || is_wp_error($this->result) || is_network_admin() || ! current_user_can( 'switch_themes' ) ) + unset( $install_actions['activate'], $install_actions['preview'] ); + + $install_actions = apply_filters('install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info); + if ( ! empty($install_actions) ) + $this->feedback(implode(' | ', (array)$install_actions)); + } +} + +/** + * Theme Upgrader Skin for WordPress Theme Upgrades. + * + * @package WordPress + * @subpackage Upgrader + * @since 2.8.0 + */ +class Theme_Upgrader_Skin extends WP_Upgrader_Skin { + var $theme = ''; + + function __construct($args = array()) { + $defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Update Theme') ); + $args = wp_parse_args($args, $defaults); + + $this->theme = $args['theme']; + + parent::__construct($args); + } + + function after() { + + $update_actions = array(); + if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) { + $name = $theme_info->display('Name'); + $stylesheet = $this->upgrader->result['destination_name']; + $template = $theme_info->get_template(); + + $preview_link = add_query_arg( array( + 'preview' => 1, + 'template' => urlencode( $template ), + 'stylesheet' => urlencode( $stylesheet ), + ), trailingslashit( home_url() ) ); + + $activate_link = add_query_arg( array( + 'action' => 'activate', + 'template' => urlencode( $template ), + 'stylesheet' => urlencode( $stylesheet ), + ), admin_url('themes.php') ); + $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet ); + + if ( get_stylesheet() == $stylesheet ) { + if ( current_user_can( 'edit_theme_options' ) ) + $update_actions['preview'] = '' . __('Customize') . ''; + } elseif ( current_user_can( 'switch_themes' ) ) { + $update_actions['preview'] = '' . __('Preview') . ''; + $update_actions['preview'] .= '' . __('Live Preview') . ''; + $update_actions['activate'] = '' . __('Activate') . ''; + } + + if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() ) + unset( $update_actions['preview'], $update_actions['activate'] ); + } + + $update_actions['themes_page'] = '' . __('Return to Themes page') . ''; + + $update_actions = apply_filters('update_theme_complete_actions', $update_actions, $this->theme); + if ( ! empty($update_actions) ) + $this->feedback(implode(' | ', (array)$update_actions)); + } +} \ No newline at end of file diff --git a/wp-admin/includes/class-wp-upgrader.php b/wp-admin/includes/class-wp-upgrader.php index 7ba3eb4ba3..3ab054ae74 100644 --- a/wp-admin/includes/class-wp-upgrader.php +++ b/wp-admin/includes/class-wp-upgrader.php @@ -11,11 +11,11 @@ * @since 2.8.0 */ +require ABSPATH . 'wp-admin/includes/class-wp-upgrader-skins.php'; + /** * WordPress Upgrader class for Upgrading/Installing a local set of files via the Filesystem Abstraction classes from a Zip file. * - * @TODO More Detailed docs, for methods as well. - * * @package WordPress * @subpackage Upgrader * @since 2.8.0 @@ -367,8 +367,6 @@ class WP_Upgrader { /** * Plugin Upgrader class for WordPress Plugins, It is designed to upgrade/install plugins from a local zip, remote zip URL, or uploaded zip file. * - * @TODO More Detailed docs, for methods as well. - * * @package WordPress * @subpackage Upgrader * @since 2.8.0 @@ -653,8 +651,6 @@ class Plugin_Upgrader extends WP_Upgrader { /** * Theme Upgrader class for WordPress Themes, It is designed to upgrade/install themes from a local zip, remote zip URL, or uploaded zip file. * - * @TODO More Detailed docs, for methods as well. - * * @package WordPress * @subpackage Upgrader * @since 2.8.0 @@ -1027,8 +1023,6 @@ class Theme_Upgrader extends WP_Upgrader { /** * Core Upgrader class for WordPress. It allows for WordPress to upgrade itself in combination with the wp-admin/includes/update-core.php file * - * @TODO More Detailed docs, for methods as well. - * * @package WordPress * @subpackage Upgrader * @since 2.8.0 @@ -1101,542 +1095,9 @@ class Core_Upgrader extends WP_Upgrader { } -/** - * Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes. - * - * @TODO More Detailed docs, for methods as well. - * - * @package WordPress - * @subpackage Upgrader - * @since 2.8.0 - */ -class WP_Upgrader_Skin { - - var $upgrader; - var $done_header = false; - var $result = false; - - function __construct($args = array()) { - $defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false ); - $this->options = wp_parse_args($args, $defaults); - } - - function set_upgrader(&$upgrader) { - if ( is_object($upgrader) ) - $this->upgrader =& $upgrader; - $this->add_strings(); - } - - function add_strings() { - } - - function set_result($result) { - $this->result = $result; - } - - function request_filesystem_credentials($error = false) { - $url = $this->options['url']; - $context = $this->options['context']; - if ( !empty($this->options['nonce']) ) - $url = wp_nonce_url($url, $this->options['nonce']); - return request_filesystem_credentials($url, '', $error, $context); //Possible to bring inline, Leaving as is for now. - } - - function header() { - if ( $this->done_header ) - return; - $this->done_header = true; - echo '
'; - screen_icon(); - echo '

' . $this->options['title'] . '

'; - } - function footer() { - echo '
'; - } - - function error($errors) { - if ( ! $this->done_header ) - $this->header(); - if ( is_string($errors) ) { - $this->feedback($errors); - } elseif ( is_wp_error($errors) && $errors->get_error_code() ) { - foreach ( $errors->get_error_messages() as $message ) { - if ( $errors->get_error_data() ) - $this->feedback($message . ' ' . esc_html( $errors->get_error_data() ) ); - else - $this->feedback($message); - } - } - } - - function feedback($string) { - if ( isset( $this->upgrader->strings[$string] ) ) - $string = $this->upgrader->strings[$string]; - - if ( strpos($string, '%') !== false ) { - $args = func_get_args(); - $args = array_splice($args, 1); - if ( $args ) { - $args = array_map( 'strip_tags', $args ); - $args = array_map( 'esc_html', $args ); - $string = vsprintf($string, $args); - } - } - if ( empty($string) ) - return; - show_message($string); - } - function before() {} - function after() {} - -} - -/** - * Plugin Upgrader Skin for WordPress Plugin Upgrades. - * - * @TODO More Detailed docs, for methods as well. - * - * @package WordPress - * @subpackage Upgrader - * @since 2.8.0 - */ -class Plugin_Upgrader_Skin extends WP_Upgrader_Skin { - var $plugin = ''; - var $plugin_active = false; - var $plugin_network_active = false; - - function __construct($args = array()) { - $defaults = array( 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => __('Update Plugin') ); - $args = wp_parse_args($args, $defaults); - - $this->plugin = $args['plugin']; - - $this->plugin_active = is_plugin_active( $this->plugin ); - $this->plugin_network_active = is_plugin_active_for_network( $this->plugin ); - - parent::__construct($args); - } - - function after() { - $this->plugin = $this->upgrader->plugin_info(); - if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){ - echo ''; - } - - $update_actions = array( - 'activate_plugin' => '' . __('Activate Plugin') . '', - 'plugins_page' => '' . __('Return to Plugins page') . '' - ); - if ( $this->plugin_active || ! $this->result || is_wp_error( $this->result ) || ! current_user_can( 'activate_plugins' ) ) - unset( $update_actions['activate_plugin'] ); - - $update_actions = apply_filters('update_plugin_complete_actions', $update_actions, $this->plugin); - if ( ! empty($update_actions) ) - $this->feedback(implode(' | ', (array)$update_actions)); - } - - function before() { - if ( $this->upgrader->show_before ) { - echo $this->upgrader->show_before; - $this->upgrader->show_before = ''; - } - } -} - -/** - * Plugin Upgrader Skin for WordPress Plugin Upgrades. - * - * @package WordPress - * @subpackage Upgrader - * @since 3.0.0 - */ -class Bulk_Upgrader_Skin extends WP_Upgrader_Skin { - var $in_loop = false; - var $error = false; - - function __construct($args = array()) { - $defaults = array( 'url' => '', 'nonce' => '' ); - $args = wp_parse_args($args, $defaults); - - parent::__construct($args); - } - - function add_strings() { - $this->upgrader->strings['skin_upgrade_start'] = __('The update process is starting. This process may take a while on some hosts, so please be patient.'); - $this->upgrader->strings['skin_update_failed_error'] = __('An error occurred while updating %1$s: %2$s'); - $this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.'); - $this->upgrader->strings['skin_update_successful'] = __('%1$s updated successfully.').' '.__('Show Details').'.'; - $this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.'); - } - - function feedback($string) { - if ( isset( $this->upgrader->strings[$string] ) ) - $string = $this->upgrader->strings[$string]; - - if ( strpos($string, '%') !== false ) { - $args = func_get_args(); - $args = array_splice($args, 1); - if ( $args ) { - $args = array_map( 'strip_tags', $args ); - $args = array_map( 'esc_html', $args ); - $string = vsprintf($string, $args); - } - } - if ( empty($string) ) - return; - if ( $this->in_loop ) - echo "$string
\n"; - else - echo "

$string

\n"; - } - - function header() { - // Nothing, This will be displayed within a iframe. - } - - function footer() { - // Nothing, This will be displayed within a iframe. - } - function error($error) { - if ( is_string($error) && isset( $this->upgrader->strings[$error] ) ) - $this->error = $this->upgrader->strings[$error]; - - if ( is_wp_error($error) ) { - foreach ( $error->get_error_messages() as $emessage ) { - if ( $error->get_error_data() ) - $messages[] = $emessage . ' ' . esc_html( $error->get_error_data() ); - else - $messages[] = $emessage; - } - $this->error = implode(', ', $messages); - } - echo ''; - } - - function bulk_header() { - $this->feedback('skin_upgrade_start'); - } - - function bulk_footer() { - $this->feedback('skin_upgrade_end'); - } - - function before($title = '') { - $this->in_loop = true; - printf( '

' . $this->upgrader->strings['skin_before_update_header'] . '

', $title, $this->upgrader->update_current, $this->upgrader->update_count); - echo ''; - echo '

'; - $this->flush_output(); - } - - function after($title = '') { - echo '

'; - if ( $this->error || ! $this->result ) { - if ( $this->error ) - echo '

' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, $this->error) . '

'; - else - echo '

' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '

'; - - echo ''; - } - if ( $this->result && ! is_wp_error( $this->result ) ) { - if ( ! $this->error ) - echo '

' . sprintf($this->upgrader->strings['skin_update_successful'], $title, 'jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').toggle();jQuery(\'span\', this).toggle(); return false;') . '

'; - echo ''; - } - - $this->reset(); - $this->flush_output(); - } - - function reset() { - $this->in_loop = false; - $this->error = false; - } - - function flush_output() { - wp_ob_end_flush_all(); - flush(); - } -} - -class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin { - var $plugin_info = array(); // Plugin_Upgrader::bulk() will fill this in. - - function __construct($args = array()) { - parent::__construct($args); - } - - function add_strings() { - parent::add_strings(); - $this->upgrader->strings['skin_before_update_header'] = __('Updating Plugin %1$s (%2$d/%3$d)'); - } - - function before($title = '') { - parent::before($this->plugin_info['Title']); - } - - function after($title = '') { - parent::after($this->plugin_info['Title']); - } - function bulk_footer() { - parent::bulk_footer(); - $update_actions = array( - 'plugins_page' => '' . __('Return to Plugins page') . '', - 'updates_page' => '' . __('Return to WordPress Updates') . '' - ); - if ( ! current_user_can( 'activate_plugins' ) ) - unset( $update_actions['plugins_page'] ); - - $update_actions = apply_filters('update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info); - if ( ! empty($update_actions) ) - $this->feedback(implode(' | ', (array)$update_actions)); - } -} - -class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin { - var $theme_info = array(); // Theme_Upgrader::bulk() will fill this in. - - function __construct($args = array()) { - parent::__construct($args); - } - - function add_strings() { - parent::add_strings(); - $this->upgrader->strings['skin_before_update_header'] = __('Updating Theme %1$s (%2$d/%3$d)'); - } - - function before($title = '') { - parent::before( $this->theme_info->display('Name') ); - } - - function after($title = '') { - parent::after( $this->theme_info->display('Name') ); - } - - function bulk_footer() { - parent::bulk_footer(); - $update_actions = array( - 'themes_page' => '' . __('Return to Themes page') . '', - 'updates_page' => '' . __('Return to WordPress Updates') . '' - ); - if ( ! current_user_can( 'switch_themes' ) && ! current_user_can( 'edit_theme_options' ) ) - unset( $update_actions['themes_page'] ); - - $update_actions = apply_filters('update_bulk_theme_complete_actions', $update_actions, $this->theme_info ); - if ( ! empty($update_actions) ) - $this->feedback(implode(' | ', (array)$update_actions)); - } -} - -/** - * Plugin Installer Skin for WordPress Plugin Installer. - * - * @TODO More Detailed docs, for methods as well. - * - * @package WordPress - * @subpackage Upgrader - * @since 2.8.0 - */ -class Plugin_Installer_Skin extends WP_Upgrader_Skin { - var $api; - var $type; - - function __construct($args = array()) { - $defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' ); - $args = wp_parse_args($args, $defaults); - - $this->type = $args['type']; - $this->api = isset($args['api']) ? $args['api'] : array(); - - parent::__construct($args); - } - - function before() { - if ( !empty($this->api) ) - $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin %s %s.'), $this->api->name, $this->api->version); - } - - function after() { - - $plugin_file = $this->upgrader->plugin_info(); - - $install_actions = array(); - - $from = isset($_GET['from']) ? wp_unslash( $_GET['from'] ) : 'plugins'; - - if ( 'import' == $from ) - $install_actions['activate_plugin'] = '' . __('Activate Plugin & Run Importer') . ''; - else - $install_actions['activate_plugin'] = '' . __('Activate Plugin') . ''; - - if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) { - $install_actions['network_activate'] = '' . __('Network Activate') . ''; - unset( $install_actions['activate_plugin'] ); - } - - if ( 'import' == $from ) - $install_actions['importers_page'] = '' . __('Return to Importers') . ''; - else if ( $this->type == 'web' ) - $install_actions['plugins_page'] = '' . __('Return to Plugin Installer') . ''; - else - $install_actions['plugins_page'] = '' . __('Return to Plugins page') . ''; - - if ( ! $this->result || is_wp_error($this->result) ) { - unset( $install_actions['activate_plugin'], $install_actions['network_activate'] ); - } elseif ( ! current_user_can( 'activate_plugins' ) ) { - unset( $install_actions['activate_plugin'] ); - } - - $install_actions = apply_filters('install_plugin_complete_actions', $install_actions, $this->api, $plugin_file); - if ( ! empty($install_actions) ) - $this->feedback(implode(' | ', (array)$install_actions)); - } -} - -/** - * Theme Installer Skin for the WordPress Theme Installer. - * - * @TODO More Detailed docs, for methods as well. - * - * @package WordPress - * @subpackage Upgrader - * @since 2.8.0 - */ -class Theme_Installer_Skin extends WP_Upgrader_Skin { - var $api; - var $type; - - function __construct($args = array()) { - $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' ); - $args = wp_parse_args($args, $defaults); - - $this->type = $args['type']; - $this->api = isset($args['api']) ? $args['api'] : array(); - - parent::__construct($args); - } - - function before() { - if ( !empty($this->api) ) - $this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version); - } - - function after() { - if ( empty($this->upgrader->result['destination_name']) ) - return; - - $theme_info = $this->upgrader->theme_info(); - if ( empty( $theme_info ) ) - return; - - $name = $theme_info->display('Name'); - $stylesheet = $this->upgrader->result['destination_name']; - $template = $theme_info->get_template(); - - $preview_link = add_query_arg( array( - 'preview' => 1, - 'template' => urlencode( $template ), - 'stylesheet' => urlencode( $stylesheet ), - ), trailingslashit( home_url() ) ); - - $activate_link = add_query_arg( array( - 'action' => 'activate', - 'template' => urlencode( $template ), - 'stylesheet' => urlencode( $stylesheet ), - ), admin_url('themes.php') ); - $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet ); - - $install_actions = array(); - $install_actions['preview'] = '' . __('Preview') . ''; - $install_actions['preview'] .= '' . __('Live Preview') . ''; - $install_actions['activate'] = '' . __('Activate') . ''; - - if ( is_network_admin() && current_user_can( 'manage_network_themes' ) ) - $install_actions['network_enable'] = '' . __( 'Network Enable' ) . ''; - - if ( $this->type == 'web' ) - $install_actions['themes_page'] = '' . __('Return to Theme Installer') . ''; - elseif ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) ) - $install_actions['themes_page'] = '' . __('Return to Themes page') . ''; - - if ( ! $this->result || is_wp_error($this->result) || is_network_admin() || ! current_user_can( 'switch_themes' ) ) - unset( $install_actions['activate'], $install_actions['preview'] ); - - $install_actions = apply_filters('install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info); - if ( ! empty($install_actions) ) - $this->feedback(implode(' | ', (array)$install_actions)); - } -} - -/** - * Theme Upgrader Skin for WordPress Theme Upgrades. - * - * @TODO More Detailed docs, for methods as well. - * - * @package WordPress - * @subpackage Upgrader - * @since 2.8.0 - */ -class Theme_Upgrader_Skin extends WP_Upgrader_Skin { - var $theme = ''; - - function __construct($args = array()) { - $defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Update Theme') ); - $args = wp_parse_args($args, $defaults); - - $this->theme = $args['theme']; - - parent::__construct($args); - } - - function after() { - - $update_actions = array(); - if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) { - $name = $theme_info->display('Name'); - $stylesheet = $this->upgrader->result['destination_name']; - $template = $theme_info->get_template(); - - $preview_link = add_query_arg( array( - 'preview' => 1, - 'template' => urlencode( $template ), - 'stylesheet' => urlencode( $stylesheet ), - ), trailingslashit( home_url() ) ); - - $activate_link = add_query_arg( array( - 'action' => 'activate', - 'template' => urlencode( $template ), - 'stylesheet' => urlencode( $stylesheet ), - ), admin_url('themes.php') ); - $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet ); - - if ( get_stylesheet() == $stylesheet ) { - if ( current_user_can( 'edit_theme_options' ) ) - $update_actions['preview'] = '' . __('Customize') . ''; - } elseif ( current_user_can( 'switch_themes' ) ) { - $update_actions['preview'] = '' . __('Preview') . ''; - $update_actions['preview'] .= '' . __('Live Preview') . ''; - $update_actions['activate'] = '' . __('Activate') . ''; - } - - if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() ) - unset( $update_actions['preview'], $update_actions['activate'] ); - } - - $update_actions['themes_page'] = '' . __('Return to Themes page') . ''; - - $update_actions = apply_filters('update_theme_complete_actions', $update_actions, $this->theme); - if ( ! empty($update_actions) ) - $this->feedback(implode(' | ', (array)$update_actions)); - } -} - /** * Upgrade Skin helper for File uploads. This class handles the upload process and passes it as if it's a local file to the Upgrade/Installer functions. * - * @TODO More Detailed docs, for methods as well. - * * @package WordPress * @subpackage Upgrader * @since 2.8.0