]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/includes/class-wp-upgrader-skins.php
WordPress 4.0
[autoinstalls/wordpress.git] / wp-admin / includes / class-wp-upgrader-skins.php
index 8c4840764271203981accd913bd917d160228137..8fcee68f3cd96533f20fac5a6347d7fba1fb83a2 100644 (file)
  */
 class WP_Upgrader_Skin {
 
-       var $upgrader;
-       var $done_header = false;
-       var $result = false;
+       public $upgrader;
+       public $done_header = false;
+       public $done_footer = false;
+       public $result = false;
 
-       function __construct($args = array()) {
+       public function __construct($args = array()) {
                $defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false );
                $this->options = wp_parse_args($args, $defaults);
        }
 
-       function set_upgrader(&$upgrader) {
+       public function set_upgrader(&$upgrader) {
                if ( is_object($upgrader) )
                        $this->upgrader =& $upgrader;
                $this->add_strings();
        }
 
-       function add_strings() {
+       public function add_strings() {
        }
 
-       function set_result($result) {
+       public function set_result($result) {
                $this->result = $result;
        }
 
-       function request_filesystem_credentials($error = false) {
+       public function request_filesystem_credentials($error = false) {
                $url = $this->options['url'];
                $context = $this->options['context'];
                if ( !empty($this->options['nonce']) )
@@ -46,18 +47,23 @@ class WP_Upgrader_Skin {
                return request_filesystem_credentials($url, '', $error, $context); //Possible to bring inline, Leaving as is for now.
        }
 
-       function header() {
-               if ( $this->done_header )
+       public function header() {
+               if ( $this->done_header ) {
                        return;
+               }
                $this->done_header = true;
                echo '<div class="wrap">';
                echo '<h2>' . $this->options['title'] . '</h2>';
        }
-       function footer() {
+       public function footer() {
+               if ( $this->done_footer ) {
+                       return;
+               }
+               $this->done_footer = true;
                echo '</div>';
        }
 
-       function error($errors) {
+       public function error($errors) {
                if ( ! $this->done_header )
                        $this->header();
                if ( is_string($errors) ) {
@@ -72,7 +78,7 @@ class WP_Upgrader_Skin {
                }
        }
 
-       function feedback($string) {
+       public function feedback($string) {
                if ( isset( $this->upgrader->strings[$string] ) )
                        $string = $this->upgrader->strings[$string];
 
@@ -89,8 +95,8 @@ class WP_Upgrader_Skin {
                        return;
                show_message($string);
        }
-       function before() {}
-       function after() {}
+       public function before() {}
+       public function after() {}
 
        /**
         * Output JavaScript that calls function to decrement the update counts.
@@ -104,13 +110,22 @@ class WP_Upgrader_Skin {
                if ( ! $this->result || is_wp_error( $this->result ) || 'up_to_date' === $this->result ) {
                        return;
                }
-               echo '<script type="text/javascript">
-                               (function( wp ) {
-                                       if ( wp && wp.updates.decrementCount ) {
-                                               wp.updates.decrementCount( "' . $type . '" );
+
+               if ( defined( 'IFRAME_REQUEST' ) ) {
+                       echo '<script type="text/javascript">
+                                       if ( window.postMessage && JSON ) {
+                                               window.parent.postMessage( JSON.stringify( { action: "decrementUpdateCount", upgradeType: "' . $type . '" } ), window.location.protocol + "//" + window.location.hostname );
                                        }
-                               })( window.wp );
-                       </script>';
+                               </script>';
+               } else {
+                       echo '<script type="text/javascript">
+                                       (function( wp ) {
+                                               if ( wp && wp.updates.decrementCount ) {
+                                                       wp.updates.decrementCount( "' . $type . '" );
+                                               }
+                                       })( window.wp );
+                               </script>';
+               }
        }
 }
 
@@ -122,11 +137,11 @@ class WP_Upgrader_Skin {
  * @since 2.8.0
  */
 class Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
-       var $plugin = '';
-       var $plugin_active = false;
-       var $plugin_network_active = false;
+       public $plugin = '';
+       public $plugin_active = false;
+       public $plugin_network_active = false;
 
-       function __construct($args = array()) {
+       public function __construct($args = array()) {
                $defaults = array( 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => __('Update Plugin') );
                $args = wp_parse_args($args, $defaults);
 
@@ -138,7 +153,7 @@ class Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
                parent::__construct($args);
        }
 
-       function after() {
+       public function after() {
                $this->plugin = $this->upgrader->plugin_info();
                if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){
                        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=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin) .'"></iframe>';
@@ -176,17 +191,17 @@ class Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
  * @since 3.0.0
  */
 class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
-       var $in_loop = false;
-       var $error = false;
+       public $in_loop = false;
+       public $error = false;
 
-       function __construct($args = array()) {
+       public function __construct($args = array()) {
                $defaults = array( 'url' => '', 'nonce' => '' );
                $args = wp_parse_args($args, $defaults);
 
                parent::__construct($args);
        }
 
-       function add_strings() {
+       public 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: <strong>%2$s</strong>');
                $this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.');
@@ -194,7 +209,7 @@ class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
                $this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.');
        }
 
-       function feedback($string) {
+       public function feedback($string) {
                if ( isset( $this->upgrader->strings[$string] ) )
                        $string = $this->upgrader->strings[$string];
 
@@ -215,18 +230,19 @@ class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
                        echo "<p>$string</p>\n";
        }
 
-       function header() {
+       public function header() {
                // Nothing, This will be displayed within a iframe.
        }
 
-       function footer() {
+       public function footer() {
                // Nothing, This will be displayed within a iframe.
        }
-       function error($error) {
+       public function error($error) {
                if ( is_string($error) && isset( $this->upgrader->strings[$error] ) )
                        $this->error = $this->upgrader->strings[$error];
 
                if ( is_wp_error($error) ) {
+                       $messages = array();
                        foreach ( $error->get_error_messages() as $emessage ) {
                                if ( $error->get_error_data() && is_string( $error->get_error_data() ) )
                                        $messages[] = $emessage . ' ' . esc_html( strip_tags( $error->get_error_data() ) );
@@ -238,15 +254,15 @@ class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
                echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
        }
 
-       function bulk_header() {
+       public function bulk_header() {
                $this->feedback('skin_upgrade_start');
        }
 
-       function bulk_footer() {
+       public function bulk_footer() {
                $this->feedback('skin_upgrade_end');
        }
 
-       function before($title = '') {
+       public function before($title = '') {
                $this->in_loop = true;
                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);
                echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').css("display", "inline-block");</script>';
@@ -254,7 +270,7 @@ class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
                $this->flush_output();
        }
 
-       function after($title = '') {
+       public function after($title = '') {
                echo '</p></div>';
                if ( $this->error || ! $this->result ) {
                        if ( $this->error )
@@ -274,57 +290,38 @@ class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
                $this->flush_output();
        }
 
-       function reset() {
+       public function reset() {
                $this->in_loop = false;
                $this->error = false;
        }
 
-       function flush_output() {
+       public function flush_output() {
                wp_ob_end_flush_all();
                flush();
        }
-
-       /**
-        * Output JavaScript that sends message to parent window to decrement the update counts.
-        *
-        * @since 3.9.0
-        *
-        * @param string $type Type of update count to decrement. Likely values include 'plugin',
-        *                     'theme', 'translation', etc.
-        */
-       protected function decrement_update_count( $type ) {
-               if ( ! $this->result || is_wp_error( $this->result ) || 'up_to_date' === $this->result ) {
-                       return;
-               }
-               echo '<script type="text/javascript">
-                               if ( window.postMessage && JSON ) {
-                                       window.parent.postMessage( JSON.stringify( { action: "decrementUpdateCount", upgradeType: "' . $type . '" } ), window.location.protocol + "//" + window.location.hostname );
-                               }
-                       </script>';
-       }
 }
 
 class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
-       var $plugin_info = array(); // Plugin_Upgrader::bulk() will fill this in.
+       public $plugin_info = array(); // Plugin_Upgrader::bulk() will fill this in.
 
-       function __construct($args = array()) {
+       public function __construct($args = array()) {
                parent::__construct($args);
        }
 
-       function add_strings() {
+       public function add_strings() {
                parent::add_strings();
                $this->upgrader->strings['skin_before_update_header'] = __('Updating Plugin %1$s (%2$d/%3$d)');
        }
 
-       function before($title = '') {
+       public function before($title = '') {
                parent::before($this->plugin_info['Title']);
        }
 
-       function after($title = '') {
+       public function after($title = '') {
                parent::after($this->plugin_info['Title']);
                $this->decrement_update_count( 'plugin' );
        }
-       function bulk_footer() {
+       public function bulk_footer() {
                parent::bulk_footer();
                $update_actions =  array(
                        'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>',
@@ -349,27 +346,27 @@ class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
 }
 
 class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin {
-       var $theme_info = array(); // Theme_Upgrader::bulk() will fill this in.
+       public $theme_info = array(); // Theme_Upgrader::bulk() will fill this in.
 
-       function __construct($args = array()) {
+       public function __construct($args = array()) {
                parent::__construct($args);
        }
 
-       function add_strings() {
+       public function add_strings() {
                parent::add_strings();
                $this->upgrader->strings['skin_before_update_header'] = __('Updating Theme %1$s (%2$d/%3$d)');
        }
 
-       function before($title = '') {
+       public function before($title = '') {
                parent::before( $this->theme_info->display('Name') );
        }
 
-       function after($title = '') {
+       public function after($title = '') {
                parent::after( $this->theme_info->display('Name') );
                $this->decrement_update_count( 'theme' );
        }
 
-       function bulk_footer() {
+       public function bulk_footer() {
                parent::bulk_footer();
                $update_actions =  array(
                        'themes_page' => '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Go to themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>',
@@ -401,10 +398,10 @@ class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin {
  * @since 2.8.0
  */
 class Plugin_Installer_Skin extends WP_Upgrader_Skin {
-       var $api;
-       var $type;
+       public $api;
+       public $type;
 
-       function __construct($args = array()) {
+       public function __construct($args = array()) {
                $defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' );
                $args = wp_parse_args($args, $defaults);
 
@@ -414,12 +411,12 @@ class Plugin_Installer_Skin extends WP_Upgrader_Skin {
                parent::__construct($args);
        }
 
-       function before() {
+       public function before() {
                if ( !empty($this->api) )
                        $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin <strong>%s %s</strong>.'), $this->api->name, $this->api->version);
        }
 
-       function after() {
+       public function after() {
 
                $plugin_file = $this->upgrader->plugin_info();
 
@@ -476,10 +473,10 @@ class Plugin_Installer_Skin extends WP_Upgrader_Skin {
  * @since 2.8.0
  */
 class Theme_Installer_Skin extends WP_Upgrader_Skin {
-       var $api;
-       var $type;
+       public $api;
+       public $type;
 
-       function __construct($args = array()) {
+       public function __construct($args = array()) {
                $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' );
                $args = wp_parse_args($args, $defaults);
 
@@ -489,12 +486,12 @@ class Theme_Installer_Skin extends WP_Upgrader_Skin {
                parent::__construct($args);
        }
 
-       function before() {
+       public 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() {
+       public function after() {
                if ( empty($this->upgrader->result['destination_name']) )
                        return;
 
@@ -521,7 +518,9 @@ class Theme_Installer_Skin extends WP_Upgrader_Skin {
 
                $install_actions = array();
                $install_actions['preview']  = '<a href="' . esc_url( $preview_link ) . '" class="hide-if-customize" title="' . esc_attr( sprintf( __('Preview &#8220;%s&#8221;'), $name ) ) . '">' . __('Preview') . '</a>';
-               $install_actions['preview'] .= '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize" title="' . esc_attr( sprintf( __('Preview &#8220;%s&#8221;'), $name ) ) . '">' . __('Live Preview') . '</a>';
+               if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
+                       $install_actions['preview'] .= '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize" title="' . esc_attr( sprintf( __('Preview &#8220;%s&#8221;'), $name ) ) . '">' . __('Live Preview') . '</a>';
+               }
                $install_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $name ) ) . '">' . __('Activate') . '</a>';
 
                if ( is_network_admin() && current_user_can( 'manage_network_themes' ) )
@@ -559,9 +558,9 @@ class Theme_Installer_Skin extends WP_Upgrader_Skin {
  * @since 2.8.0
  */
 class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
-       var $theme = '';
+       public $theme = '';
 
-       function __construct($args = array()) {
+       public function __construct($args = array()) {
                $defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Update Theme') );
                $args = wp_parse_args($args, $defaults);
 
@@ -570,7 +569,7 @@ class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
                parent::__construct($args);
        }
 
-       function after() {
+       public function after() {
                $this->decrement_update_count( 'theme' );
 
                $update_actions = array();
@@ -593,11 +592,14 @@ class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
                        $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
 
                        if ( get_stylesheet() == $stylesheet ) {
-                               if ( current_user_can( 'edit_theme_options' ) )
+                               if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
                                        $update_actions['preview']  = '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize" title="' . esc_attr( sprintf( __('Customize &#8220;%s&#8221;'), $name ) ) . '">' . __('Customize') . '</a>';
+                               }
                        } elseif ( current_user_can( 'switch_themes' ) ) {
                                $update_actions['preview']  = '<a href="' . esc_url( $preview_link ) . '" class="hide-if-customize" title="' . esc_attr( sprintf( __('Preview &#8220;%s&#8221;'), $name ) ) . '">' . __('Preview') . '</a>';
-                               $update_actions['preview'] .= '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize" title="' . esc_attr( sprintf( __('Preview &#8220;%s&#8221;'), $name ) ) . '">' . __('Live Preview') . '</a>';
+                               if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
+                                       $update_actions['preview'] .= '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize" title="' . esc_attr( sprintf( __('Preview &#8220;%s&#8221;'), $name ) ) . '">' . __('Live Preview') . '</a>';
+                               }
                                $update_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $name ) ) . '">' . __('Activate') . '</a>';
                        }
 
@@ -630,21 +632,23 @@ class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
  * @since 3.7.0
  */
 class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin {
-       var $language_update = null;
-       var $done_header = false;
-       var $display_footer_actions = true;
+       public $language_update = null;
+       public $done_header = false;
+       public $done_footer = false;
+       public $display_footer_actions = true;
 
-       function __construct( $args = array() ) {
+       public function __construct( $args = array() ) {
                $defaults = array( 'url' => '', 'nonce' => '', 'title' => __( 'Update Translations' ), 'skip_header_footer' => false );
                $args = wp_parse_args( $args, $defaults );
                if ( $args['skip_header_footer'] ) {
                        $this->done_header = true;
+                       $this->done_footer = true;
                        $this->display_footer_actions = false;
                }
                parent::__construct( $args );
        }
 
-       function before() {
+       public function before() {
                $name = $this->upgrader->get_name_for_update( $this->language_update );
 
                echo '<div class="update-messages lp-show-latest">';
@@ -652,17 +656,17 @@ class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin {
                printf( '<h4>' . __( 'Updating translations for %1$s (%2$s)&#8230;' ) . '</h4>', $name, $this->language_update->language );
        }
 
-       function error( $error ) {
+       public function error( $error ) {
                echo '<div class="lp-error">';
                parent::error( $error );
                echo '</div>';
        }
 
-       function after() {
+       public function after() {
                echo '</div>';
        }
 
-       function bulk_footer() {
+       public function bulk_footer() {
                $this->decrement_update_count( 'translation' );
                $update_actions = array();
                $update_actions['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>';
@@ -678,8 +682,6 @@ class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin {
 
                if ( $update_actions && $this->display_footer_actions )
                        $this->feedback( implode( ' | ', $update_actions ) );
-
-               parent::footer();
        }
 }
 
@@ -696,7 +698,7 @@ class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin {
 class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
        protected $messages = array();
 
-       function request_filesystem_credentials( $error = false, $context = '' ) {
+       public function request_filesystem_credentials( $error = false, $context = '' ) {
                if ( $context )
                        $this->options['context'] = $context;
                // TODO: fix up request_filesystem_credentials(), or split it, to allow us to request a no-output version
@@ -707,11 +709,11 @@ class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
                return $result;
        }
 
-       function get_upgrade_messages() {
+       public function get_upgrade_messages() {
                return $this->messages;
        }
 
-       function feedback( $data ) {
+       public function feedback( $data ) {
                if ( is_wp_error( $data ) )
                        $string = $data->get_error_message();
                else if ( is_array( $data ) )
@@ -747,19 +749,19 @@ class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
                $this->messages[] = $string;
        }
 
-       function header() {
+       public function header() {
                ob_start();
        }
 
-       function footer() {
+       public function footer() {
                $output = ob_get_contents();
                if ( ! empty( $output ) )
                        $this->feedback( $output );
                ob_end_clean();
        }
 
-       function bulk_header() {}
-       function bulk_footer() {}
-       function before() {}
-       function after() {}
+       public function bulk_header() {}
+       public function bulk_footer() {}
+       public function before() {}
+       public function after() {}
 }