wp/wp-admin/includes/class-wp-upgrader-skins.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 16 a86126ab1dd4
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
     5  * @package WordPress
     5  * @package WordPress
     6  * @subpackage Upgrader
     6  * @subpackage Upgrader
     7  * @since 2.8.0
     7  * @since 2.8.0
     8  */
     8  */
     9 
     9 
    10 /**
    10 _deprecated_file( basename( __FILE__ ), '4.7.0', 'class-wp-upgrader.php' );
    11  * Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes.
       
    12  *
       
    13  * @package WordPress
       
    14  * @subpackage Upgrader
       
    15  * @since 2.8.0
       
    16  */
       
    17 class WP_Upgrader_Skin {
       
    18 
    11 
    19 	public $upgrader;
    12 /** WP_Upgrader_Skin class */
    20 	public $done_header = false;
    13 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader-skin.php';
    21 	public $done_footer = false;
       
    22 	public $result = false;
       
    23 	public $options = array();
       
    24 
    14 
    25 	public function __construct($args = array()) {
    15 /** Plugin_Upgrader_Skin class */
    26 		$defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false );
    16 require_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader-skin.php';
    27 		$this->options = wp_parse_args($args, $defaults);
       
    28 	}
       
    29 
    17 
    30 	/**
    18 /** Theme_Upgrader_Skin class */
    31 	 * @param WP_Upgrader $upgrader
    19 require_once ABSPATH . 'wp-admin/includes/class-theme-upgrader-skin.php';
    32 	 */
       
    33 	public function set_upgrader(&$upgrader) {
       
    34 		if ( is_object($upgrader) )
       
    35 			$this->upgrader =& $upgrader;
       
    36 		$this->add_strings();
       
    37 	}
       
    38 
    20 
    39 	public function add_strings() {
    21 /** Bulk_Upgrader_Skin class */
    40 	}
    22 require_once ABSPATH . 'wp-admin/includes/class-bulk-upgrader-skin.php';
    41 
    23 
    42 	public function set_result($result) {
    24 /** Bulk_Plugin_Upgrader_Skin class */
    43 		$this->result = $result;
    25 require_once ABSPATH . 'wp-admin/includes/class-bulk-plugin-upgrader-skin.php';
    44 	}
       
    45 
    26 
    46 	public function request_filesystem_credentials( $error = false, $context = false, $allow_relaxed_file_ownership = false ) {
    27 /** Bulk_Theme_Upgrader_Skin class */
    47 		$url = $this->options['url'];
    28 require_once ABSPATH . 'wp-admin/includes/class-bulk-theme-upgrader-skin.php';
    48 		if ( ! $context ) {
       
    49 			$context = $this->options['context'];
       
    50 		}
       
    51 		if ( !empty($this->options['nonce']) ) {
       
    52 			$url = wp_nonce_url($url, $this->options['nonce']);
       
    53 		}
       
    54 
    29 
    55 		$extra_fields = array();
    30 /** Plugin_Installer_Skin class */
       
    31 require_once ABSPATH . 'wp-admin/includes/class-plugin-installer-skin.php';
    56 
    32 
    57 		return request_filesystem_credentials( $url, '', $error, $context, $extra_fields, $allow_relaxed_file_ownership );
    33 /** Theme_Installer_Skin class */
    58 	}
    34 require_once ABSPATH . 'wp-admin/includes/class-theme-installer-skin.php';
    59 
    35 
    60 	public function header() {
    36 /** Language_Pack_Upgrader_Skin class */
    61 		if ( $this->done_header ) {
    37 require_once ABSPATH . 'wp-admin/includes/class-language-pack-upgrader-skin.php';
    62 			return;
       
    63 		}
       
    64 		$this->done_header = true;
       
    65 		echo '<div class="wrap">';
       
    66 		echo '<h2>' . $this->options['title'] . '</h2>';
       
    67 	}
       
    68 	public function footer() {
       
    69 		if ( $this->done_footer ) {
       
    70 			return;
       
    71 		}
       
    72 		$this->done_footer = true;
       
    73 		echo '</div>';
       
    74 	}
       
    75 
    38 
    76 	public function error($errors) {
    39 /** Automatic_Upgrader_Skin class */
    77 		if ( ! $this->done_header )
    40 require_once ABSPATH . 'wp-admin/includes/class-automatic-upgrader-skin.php';
    78 			$this->header();
       
    79 		if ( is_string($errors) ) {
       
    80 			$this->feedback($errors);
       
    81 		} elseif ( is_wp_error($errors) && $errors->get_error_code() ) {
       
    82 			foreach ( $errors->get_error_messages() as $message ) {
       
    83 				if ( $errors->get_error_data() && is_string( $errors->get_error_data() ) )
       
    84 					$this->feedback($message . ' ' . esc_html( strip_tags( $errors->get_error_data() ) ) );
       
    85 				else
       
    86 					$this->feedback($message);
       
    87 			}
       
    88 		}
       
    89 	}
       
    90 
    41 
    91 	public function feedback($string) {
    42 /** WP_Ajax_Upgrader_Skin class */
    92 		if ( isset( $this->upgrader->strings[$string] ) )
    43 require_once ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php';
    93 			$string = $this->upgrader->strings[$string];
       
    94 
       
    95 		if ( strpos($string, '%') !== false ) {
       
    96 			$args = func_get_args();
       
    97 			$args = array_splice($args, 1);
       
    98 			if ( $args ) {
       
    99 				$args = array_map( 'strip_tags', $args );
       
   100 				$args = array_map( 'esc_html', $args );
       
   101 				$string = vsprintf($string, $args);
       
   102 			}
       
   103 		}
       
   104 		if ( empty($string) )
       
   105 			return;
       
   106 		show_message($string);
       
   107 	}
       
   108 	public function before() {}
       
   109 	public function after() {}
       
   110 
       
   111 	/**
       
   112 	 * Output JavaScript that calls function to decrement the update counts.
       
   113 	 *
       
   114 	 * @since 3.9.0
       
   115 	 *
       
   116 	 * @param string $type Type of update count to decrement. Likely values include 'plugin',
       
   117 	 *                     'theme', 'translation', etc.
       
   118 	 */
       
   119 	protected function decrement_update_count( $type ) {
       
   120 		if ( ! $this->result || is_wp_error( $this->result ) || 'up_to_date' === $this->result ) {
       
   121 			return;
       
   122 		}
       
   123 
       
   124 		if ( defined( 'IFRAME_REQUEST' ) ) {
       
   125 			echo '<script type="text/javascript">
       
   126 					if ( window.postMessage && JSON ) {
       
   127 						window.parent.postMessage( JSON.stringify( { action: "decrementUpdateCount", upgradeType: "' . $type . '" } ), window.location.protocol + "//" + window.location.hostname );
       
   128 					}
       
   129 				</script>';
       
   130 		} else {
       
   131 			echo '<script type="text/javascript">
       
   132 					(function( wp ) {
       
   133 						if ( wp && wp.updates.decrementCount ) {
       
   134 							wp.updates.decrementCount( "' . $type . '" );
       
   135 						}
       
   136 					})( window.wp );
       
   137 				</script>';
       
   138 		}
       
   139 	}
       
   140 
       
   141 	public function bulk_header() {}
       
   142 	public function bulk_footer() {}
       
   143 }
       
   144 
       
   145 /**
       
   146  * Plugin Upgrader Skin for WordPress Plugin Upgrades.
       
   147  *
       
   148  * @package WordPress
       
   149  * @subpackage Upgrader
       
   150  * @since 2.8.0
       
   151  */
       
   152 class Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
       
   153 	public $plugin = '';
       
   154 	public $plugin_active = false;
       
   155 	public $plugin_network_active = false;
       
   156 
       
   157 	public function __construct($args = array()) {
       
   158 		$defaults = array( 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => __('Update Plugin') );
       
   159 		$args = wp_parse_args($args, $defaults);
       
   160 
       
   161 		$this->plugin = $args['plugin'];
       
   162 
       
   163 		$this->plugin_active = is_plugin_active( $this->plugin );
       
   164 		$this->plugin_network_active = is_plugin_active_for_network( $this->plugin );
       
   165 
       
   166 		parent::__construct($args);
       
   167 	}
       
   168 
       
   169 	public function after() {
       
   170 		$this->plugin = $this->upgrader->plugin_info();
       
   171 		if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){
       
   172 			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>';
       
   173 		}
       
   174 
       
   175 		$this->decrement_update_count( 'plugin' );
       
   176 
       
   177 		$update_actions =  array(
       
   178 			'activate_plugin' => '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>',
       
   179 			'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>'
       
   180 		);
       
   181 		if ( $this->plugin_active || ! $this->result || is_wp_error( $this->result ) || ! current_user_can( 'activate_plugins' ) )
       
   182 			unset( $update_actions['activate_plugin'] );
       
   183 
       
   184 		/**
       
   185 		 * Filter the list of action links available following a single plugin update.
       
   186 		 *
       
   187 		 * @since 2.7.0
       
   188 		 *
       
   189 		 * @param array  $update_actions Array of plugin action links.
       
   190 		 * @param string $plugin         Path to the plugin file.
       
   191 		 */
       
   192 		$update_actions = apply_filters( 'update_plugin_complete_actions', $update_actions, $this->plugin );
       
   193 
       
   194 		if ( ! empty($update_actions) )
       
   195 			$this->feedback(implode(' | ', (array)$update_actions));
       
   196 	}
       
   197 }
       
   198 
       
   199 /**
       
   200  * Plugin Upgrader Skin for WordPress Plugin Upgrades.
       
   201  *
       
   202  * @package WordPress
       
   203  * @subpackage Upgrader
       
   204  * @since 3.0.0
       
   205  */
       
   206 class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
       
   207 	public $in_loop = false;
       
   208 	/**
       
   209 	 * @var string|false
       
   210 	 */
       
   211 	public $error = false;
       
   212 
       
   213 	public function __construct($args = array()) {
       
   214 		$defaults = array( 'url' => '', 'nonce' => '' );
       
   215 		$args = wp_parse_args($args, $defaults);
       
   216 
       
   217 		parent::__construct($args);
       
   218 	}
       
   219 
       
   220 	public function add_strings() {
       
   221 		$this->upgrader->strings['skin_upgrade_start'] = __('The update process is starting. This process may take a while on some hosts, so please be patient.');
       
   222 		$this->upgrader->strings['skin_update_failed_error'] = __('An error occurred while updating %1$s: <strong>%2$s</strong>');
       
   223 		$this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.');
       
   224 		$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>';
       
   225 		$this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.');
       
   226 	}
       
   227 
       
   228 	/**
       
   229 	 * @param string $string
       
   230 	 */
       
   231 	public function feedback($string) {
       
   232 		if ( isset( $this->upgrader->strings[$string] ) )
       
   233 			$string = $this->upgrader->strings[$string];
       
   234 
       
   235 		if ( strpos($string, '%') !== false ) {
       
   236 			$args = func_get_args();
       
   237 			$args = array_splice($args, 1);
       
   238 			if ( $args ) {
       
   239 				$args = array_map( 'strip_tags', $args );
       
   240 				$args = array_map( 'esc_html', $args );
       
   241 				$string = vsprintf($string, $args);
       
   242 			}
       
   243 		}
       
   244 		if ( empty($string) )
       
   245 			return;
       
   246 		if ( $this->in_loop )
       
   247 			echo "$string<br />\n";
       
   248 		else
       
   249 			echo "<p>$string</p>\n";
       
   250 	}
       
   251 
       
   252 	public function header() {
       
   253 		// Nothing, This will be displayed within a iframe.
       
   254 	}
       
   255 
       
   256 	public function footer() {
       
   257 		// Nothing, This will be displayed within a iframe.
       
   258 	}
       
   259 	public function error($error) {
       
   260 		if ( is_string($error) && isset( $this->upgrader->strings[$error] ) )
       
   261 			$this->error = $this->upgrader->strings[$error];
       
   262 
       
   263 		if ( is_wp_error($error) ) {
       
   264 			$messages = array();
       
   265 			foreach ( $error->get_error_messages() as $emessage ) {
       
   266 				if ( $error->get_error_data() && is_string( $error->get_error_data() ) )
       
   267 					$messages[] = $emessage . ' ' . esc_html( strip_tags( $error->get_error_data() ) );
       
   268 				else
       
   269 					$messages[] = $emessage;
       
   270 			}
       
   271 			$this->error = implode(', ', $messages);
       
   272 		}
       
   273 		echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
       
   274 	}
       
   275 
       
   276 	public function bulk_header() {
       
   277 		$this->feedback('skin_upgrade_start');
       
   278 	}
       
   279 
       
   280 	public function bulk_footer() {
       
   281 		$this->feedback('skin_upgrade_end');
       
   282 	}
       
   283 
       
   284 	public function before($title = '') {
       
   285 		$this->in_loop = true;
       
   286 		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);
       
   287 		echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').css("display", "inline-block");</script>';
       
   288 		echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr($this->upgrader->update_current) . '"><p>';
       
   289 		$this->flush_output();
       
   290 	}
       
   291 
       
   292 	public function after($title = '') {
       
   293 		echo '</p></div>';
       
   294 		if ( $this->error || ! $this->result ) {
       
   295 			if ( $this->error )
       
   296 				echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, $this->error) . '</p></div>';
       
   297 			else
       
   298 				echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '</p></div>';
       
   299 
       
   300 			echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
       
   301 		}
       
   302 		if ( $this->result && ! is_wp_error( $this->result ) ) {
       
   303 			if ( ! $this->error )
       
   304 				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>';
       
   305 			echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
       
   306 		}
       
   307 
       
   308 		$this->reset();
       
   309 		$this->flush_output();
       
   310 	}
       
   311 
       
   312 	public function reset() {
       
   313 		$this->in_loop = false;
       
   314 		$this->error = false;
       
   315 	}
       
   316 
       
   317 	public function flush_output() {
       
   318 		wp_ob_end_flush_all();
       
   319 		flush();
       
   320 	}
       
   321 }
       
   322 
       
   323 class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
       
   324 	public $plugin_info = array(); // Plugin_Upgrader::bulk() will fill this in.
       
   325 
       
   326 	public function add_strings() {
       
   327 		parent::add_strings();
       
   328 		$this->upgrader->strings['skin_before_update_header'] = __('Updating Plugin %1$s (%2$d/%3$d)');
       
   329 	}
       
   330 
       
   331 	public function before($title = '') {
       
   332 		parent::before($this->plugin_info['Title']);
       
   333 	}
       
   334 
       
   335 	public function after($title = '') {
       
   336 		parent::after($this->plugin_info['Title']);
       
   337 		$this->decrement_update_count( 'plugin' );
       
   338 	}
       
   339 	public function bulk_footer() {
       
   340 		parent::bulk_footer();
       
   341 		$update_actions =  array(
       
   342 			'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>',
       
   343 			'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>'
       
   344 		);
       
   345 		if ( ! current_user_can( 'activate_plugins' ) )
       
   346 			unset( $update_actions['plugins_page'] );
       
   347 
       
   348 		/**
       
   349 		 * Filter the list of action links available following bulk plugin updates.
       
   350 		 *
       
   351 		 * @since 3.0.0
       
   352 		 *
       
   353 		 * @param array $update_actions Array of plugin action links.
       
   354 		 * @param array $plugin_info    Array of information for the last-updated plugin.
       
   355 		 */
       
   356 		$update_actions = apply_filters( 'update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info );
       
   357 
       
   358 		if ( ! empty($update_actions) )
       
   359 			$this->feedback(implode(' | ', (array)$update_actions));
       
   360 	}
       
   361 }
       
   362 
       
   363 class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin {
       
   364 	public $theme_info = array(); // Theme_Upgrader::bulk() will fill this in.
       
   365 
       
   366 	public function add_strings() {
       
   367 		parent::add_strings();
       
   368 		$this->upgrader->strings['skin_before_update_header'] = __('Updating Theme %1$s (%2$d/%3$d)');
       
   369 	}
       
   370 
       
   371 	public function before($title = '') {
       
   372 		parent::before( $this->theme_info->display('Name') );
       
   373 	}
       
   374 
       
   375 	public function after($title = '') {
       
   376 		parent::after( $this->theme_info->display('Name') );
       
   377 		$this->decrement_update_count( 'theme' );
       
   378 	}
       
   379 
       
   380 	public function bulk_footer() {
       
   381 		parent::bulk_footer();
       
   382 		$update_actions =  array(
       
   383 			'themes_page' => '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Go to themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>',
       
   384 			'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>'
       
   385 		);
       
   386 		if ( ! current_user_can( 'switch_themes' ) && ! current_user_can( 'edit_theme_options' ) )
       
   387 			unset( $update_actions['themes_page'] );
       
   388 
       
   389 		/**
       
   390 		 * Filter the list of action links available following bulk theme updates.
       
   391 		 *
       
   392 		 * @since 3.0.0
       
   393 		 *
       
   394 		 * @param array $update_actions Array of theme action links.
       
   395 		 * @param array $theme_info     Array of information for the last-updated theme.
       
   396 		 */
       
   397 		$update_actions = apply_filters( 'update_bulk_theme_complete_actions', $update_actions, $this->theme_info );
       
   398 
       
   399 		if ( ! empty($update_actions) )
       
   400 			$this->feedback(implode(' | ', (array)$update_actions));
       
   401 	}
       
   402 }
       
   403 
       
   404 /**
       
   405  * Plugin Installer Skin for WordPress Plugin Installer.
       
   406  *
       
   407  * @package WordPress
       
   408  * @subpackage Upgrader
       
   409  * @since 2.8.0
       
   410  */
       
   411 class Plugin_Installer_Skin extends WP_Upgrader_Skin {
       
   412 	public $api;
       
   413 	public $type;
       
   414 
       
   415 	public function __construct($args = array()) {
       
   416 		$defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' );
       
   417 		$args = wp_parse_args($args, $defaults);
       
   418 
       
   419 		$this->type = $args['type'];
       
   420 		$this->api = isset($args['api']) ? $args['api'] : array();
       
   421 
       
   422 		parent::__construct($args);
       
   423 	}
       
   424 
       
   425 	public function before() {
       
   426 		if ( !empty($this->api) )
       
   427 			$this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin <strong>%s %s</strong>.'), $this->api->name, $this->api->version);
       
   428 	}
       
   429 
       
   430 	public function after() {
       
   431 
       
   432 		$plugin_file = $this->upgrader->plugin_info();
       
   433 
       
   434 		$install_actions = array();
       
   435 
       
   436 		$from = isset($_GET['from']) ? wp_unslash( $_GET['from'] ) : 'plugins';
       
   437 
       
   438 		if ( 'import' == $from )
       
   439 			$install_actions['activate_plugin'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;from=import&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin &amp; Run Importer') . '</a>';
       
   440 		else
       
   441 			$install_actions['activate_plugin'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>';
       
   442 
       
   443 		if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
       
   444 			$install_actions['network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin for all sites in this network') . '" target="_parent">' . __('Network Activate') . '</a>';
       
   445 			unset( $install_actions['activate_plugin'] );
       
   446 		}
       
   447 
       
   448 		if ( 'import' == $from ) {
       
   449 			$install_actions['importers_page'] = '<a href="' . admin_url('import.php') . '" title="' . esc_attr__('Return to Importers') . '" target="_parent">' . __('Return to Importers') . '</a>';
       
   450 		} elseif ( $this->type == 'web' ) {
       
   451 			$install_actions['plugins_page'] = '<a href="' . self_admin_url('plugin-install.php') . '" title="' . esc_attr__('Return to Plugin Installer') . '" target="_parent">' . __('Return to Plugin Installer') . '</a>';
       
   452 		} else {
       
   453 			$install_actions['plugins_page'] = '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Return to Plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>';
       
   454 		}
       
   455 
       
   456 		if ( ! $this->result || is_wp_error($this->result) ) {
       
   457 			unset( $install_actions['activate_plugin'], $install_actions['network_activate'] );
       
   458 		} elseif ( ! current_user_can( 'activate_plugins' ) ) {
       
   459 			unset( $install_actions['activate_plugin'] );
       
   460 		}
       
   461 
       
   462 		/**
       
   463 		 * Filter the list of action links available following a single plugin installation.
       
   464 		 *
       
   465 		 * @since 2.7.0
       
   466 		 *
       
   467 		 * @param array  $install_actions Array of plugin action links.
       
   468 		 * @param object $api             Object containing WordPress.org API plugin data. Empty
       
   469 		 *                                for non-API installs, such as when a plugin is installed
       
   470 		 *                                via upload.
       
   471 		 * @param string $plugin_file     Path to the plugin file.
       
   472 		 */
       
   473 		$install_actions = apply_filters( 'install_plugin_complete_actions', $install_actions, $this->api, $plugin_file );
       
   474 
       
   475 		if ( ! empty($install_actions) )
       
   476 			$this->feedback(implode(' | ', (array)$install_actions));
       
   477 	}
       
   478 }
       
   479 
       
   480 /**
       
   481  * Theme Installer Skin for the WordPress Theme Installer.
       
   482  *
       
   483  * @package WordPress
       
   484  * @subpackage Upgrader
       
   485  * @since 2.8.0
       
   486  */
       
   487 class Theme_Installer_Skin extends WP_Upgrader_Skin {
       
   488 	public $api;
       
   489 	public $type;
       
   490 
       
   491 	public function __construct($args = array()) {
       
   492 		$defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' );
       
   493 		$args = wp_parse_args($args, $defaults);
       
   494 
       
   495 		$this->type = $args['type'];
       
   496 		$this->api = isset($args['api']) ? $args['api'] : array();
       
   497 
       
   498 		parent::__construct($args);
       
   499 	}
       
   500 
       
   501 	public function before() {
       
   502 		if ( !empty($this->api) )
       
   503 			$this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version);
       
   504 	}
       
   505 
       
   506 	public function after() {
       
   507 		if ( empty($this->upgrader->result['destination_name']) )
       
   508 			return;
       
   509 
       
   510 		$theme_info = $this->upgrader->theme_info();
       
   511 		if ( empty( $theme_info ) )
       
   512 			return;
       
   513 
       
   514 		$name       = $theme_info->display('Name');
       
   515 		$stylesheet = $this->upgrader->result['destination_name'];
       
   516 		$template   = $theme_info->get_template();
       
   517 
       
   518 		$preview_link = add_query_arg( array(
       
   519 			'preview'    => 1,
       
   520 			'template'   => urlencode( $template ),
       
   521 			'stylesheet' => urlencode( $stylesheet ),
       
   522 		), trailingslashit( home_url() ) );
       
   523 
       
   524 		$activate_link = add_query_arg( array(
       
   525 			'action'     => 'activate',
       
   526 			'template'   => urlencode( $template ),
       
   527 			'stylesheet' => urlencode( $stylesheet ),
       
   528 		), admin_url('themes.php') );
       
   529 		$activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
       
   530 
       
   531 		$install_actions = array();
       
   532 		$install_actions['preview']  = '<a href="' . esc_url( $preview_link ) . '" class="hide-if-customize" title="' . esc_attr( sprintf( __('Preview &#8220;%s&#8221;'), $name ) ) . '">' . __('Preview') . '</a>';
       
   533 		if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
       
   534 			$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>';
       
   535 		}
       
   536 		$install_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $name ) ) . '">' . __('Activate') . '</a>';
       
   537 
       
   538 		if ( is_network_admin() && current_user_can( 'manage_network_themes' ) )
       
   539 			$install_actions['network_enable'] = '<a href="' . esc_url( wp_nonce_url( 'themes.php?action=enable&amp;theme=' . urlencode( $stylesheet ), 'enable-theme_' . $stylesheet ) ) . '" title="' . esc_attr__( 'Enable this theme for all sites in this network' ) . '" target="_parent">' . __( 'Network Enable' ) . '</a>';
       
   540 
       
   541 		if ( $this->type == 'web' )
       
   542 			$install_actions['themes_page'] = '<a href="' . self_admin_url('theme-install.php') . '" title="' . esc_attr__('Return to Theme Installer') . '" target="_parent">' . __('Return to Theme Installer') . '</a>';
       
   543 		elseif ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) )
       
   544 			$install_actions['themes_page'] = '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>';
       
   545 
       
   546 		if ( ! $this->result || is_wp_error($this->result) || is_network_admin() || ! current_user_can( 'switch_themes' ) )
       
   547 			unset( $install_actions['activate'], $install_actions['preview'] );
       
   548 
       
   549 		/**
       
   550 		 * Filter the list of action links available following a single theme installation.
       
   551 		 *
       
   552 		 * @since 2.8.0
       
   553 		 *
       
   554 		 * @param array    $install_actions Array of theme action links.
       
   555 		 * @param object   $api             Object containing WordPress.org API theme data.
       
   556 		 * @param string   $stylesheet      Theme directory name.
       
   557 		 * @param WP_Theme $theme_info      Theme object.
       
   558 		 */
       
   559 		$install_actions = apply_filters( 'install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info );
       
   560 		if ( ! empty($install_actions) )
       
   561 			$this->feedback(implode(' | ', (array)$install_actions));
       
   562 	}
       
   563 }
       
   564 
       
   565 /**
       
   566  * Theme Upgrader Skin for WordPress Theme Upgrades.
       
   567  *
       
   568  * @package WordPress
       
   569  * @subpackage Upgrader
       
   570  * @since 2.8.0
       
   571  */
       
   572 class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
       
   573 	public $theme = '';
       
   574 
       
   575 	public function __construct($args = array()) {
       
   576 		$defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Update Theme') );
       
   577 		$args = wp_parse_args($args, $defaults);
       
   578 
       
   579 		$this->theme = $args['theme'];
       
   580 
       
   581 		parent::__construct($args);
       
   582 	}
       
   583 
       
   584 	public function after() {
       
   585 		$this->decrement_update_count( 'theme' );
       
   586 
       
   587 		$update_actions = array();
       
   588 		if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) {
       
   589 			$name       = $theme_info->display('Name');
       
   590 			$stylesheet = $this->upgrader->result['destination_name'];
       
   591 			$template   = $theme_info->get_template();
       
   592 
       
   593 			$preview_link = add_query_arg( array(
       
   594 				'preview'    => 1,
       
   595 				'template'   => urlencode( $template ),
       
   596 				'stylesheet' => urlencode( $stylesheet ),
       
   597 			), trailingslashit( home_url() ) );
       
   598 
       
   599 			$activate_link = add_query_arg( array(
       
   600 				'action'     => 'activate',
       
   601 				'template'   => urlencode( $template ),
       
   602 				'stylesheet' => urlencode( $stylesheet ),
       
   603 			), admin_url('themes.php') );
       
   604 			$activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
       
   605 
       
   606 			if ( get_stylesheet() == $stylesheet ) {
       
   607 				if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
       
   608 					$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>';
       
   609 				}
       
   610 			} elseif ( current_user_can( 'switch_themes' ) ) {
       
   611 				$update_actions['preview']  = '<a href="' . esc_url( $preview_link ) . '" class="hide-if-customize" title="' . esc_attr( sprintf( __('Preview &#8220;%s&#8221;'), $name ) ) . '">' . __('Preview') . '</a>';
       
   612 				if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
       
   613 					$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>';
       
   614 				}
       
   615 				$update_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $name ) ) . '">' . __('Activate') . '</a>';
       
   616 			}
       
   617 
       
   618 			if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() )
       
   619 				unset( $update_actions['preview'], $update_actions['activate'] );
       
   620 		}
       
   621 
       
   622 		$update_actions['themes_page'] = '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Return to Themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>';
       
   623 
       
   624 		/**
       
   625 		 * Filter the list of action links available following a single theme update.
       
   626 		 *
       
   627 		 * @since 2.8.0
       
   628 		 *
       
   629 		 * @param array  $update_actions Array of theme action links.
       
   630 		 * @param string $theme          Theme directory name.
       
   631 		 */
       
   632 		$update_actions = apply_filters( 'update_theme_complete_actions', $update_actions, $this->theme );
       
   633 
       
   634 		if ( ! empty($update_actions) )
       
   635 			$this->feedback(implode(' | ', (array)$update_actions));
       
   636 	}
       
   637 }
       
   638 
       
   639 /**
       
   640  * Translation Upgrader Skin for WordPress Translation Upgrades.
       
   641  *
       
   642  * @package WordPress
       
   643  * @subpackage Upgrader
       
   644  * @since 3.7.0
       
   645  */
       
   646 class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin {
       
   647 	public $language_update = null;
       
   648 	public $done_header = false;
       
   649 	public $done_footer = false;
       
   650 	public $display_footer_actions = true;
       
   651 
       
   652 	public function __construct( $args = array() ) {
       
   653 		$defaults = array( 'url' => '', 'nonce' => '', 'title' => __( 'Update Translations' ), 'skip_header_footer' => false );
       
   654 		$args = wp_parse_args( $args, $defaults );
       
   655 		if ( $args['skip_header_footer'] ) {
       
   656 			$this->done_header = true;
       
   657 			$this->done_footer = true;
       
   658 			$this->display_footer_actions = false;
       
   659 		}
       
   660 		parent::__construct( $args );
       
   661 	}
       
   662 
       
   663 	public function before() {
       
   664 		$name = $this->upgrader->get_name_for_update( $this->language_update );
       
   665 
       
   666 		echo '<div class="update-messages lp-show-latest">';
       
   667 
       
   668 		printf( '<h4>' . __( 'Updating translations for %1$s (%2$s)&#8230;' ) . '</h4>', $name, $this->language_update->language );
       
   669 	}
       
   670 
       
   671 	public function error( $error ) {
       
   672 		echo '<div class="lp-error">';
       
   673 		parent::error( $error );
       
   674 		echo '</div>';
       
   675 	}
       
   676 
       
   677 	public function after() {
       
   678 		echo '</div>';
       
   679 	}
       
   680 
       
   681 	public function bulk_footer() {
       
   682 		$this->decrement_update_count( 'translation' );
       
   683 		$update_actions = array();
       
   684 		$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>';
       
   685 
       
   686 		/**
       
   687 		 * Filter the list of action links available following a translations update.
       
   688 		 *
       
   689 		 * @since 3.7.0
       
   690 		 *
       
   691 		 * @param array $update_actions Array of translations update links.
       
   692 		 */
       
   693 		$update_actions = apply_filters( 'update_translations_complete_actions', $update_actions );
       
   694 
       
   695 		if ( $update_actions && $this->display_footer_actions )
       
   696 			$this->feedback( implode( ' | ', $update_actions ) );
       
   697 	}
       
   698 }
       
   699 
       
   700 /**
       
   701  * Upgrader Skin for Automatic WordPress Upgrades
       
   702  *
       
   703  * This skin is designed to be used when no output is intended, all output
       
   704  * is captured and stored for the caller to process and log/email/discard.
       
   705  *
       
   706  * @package WordPress
       
   707  * @subpackage Upgrader
       
   708  * @since 3.7.0
       
   709  */
       
   710 class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
       
   711 	protected $messages = array();
       
   712 
       
   713 	public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) {
       
   714 		if ( $context ) {
       
   715 			$this->options['context'] = $context;
       
   716 		}
       
   717 		// TODO: fix up request_filesystem_credentials(), or split it, to allow us to request a no-output version
       
   718 		// This will output a credentials form in event of failure, We don't want that, so just hide with a buffer
       
   719 		ob_start();
       
   720 		$result = parent::request_filesystem_credentials( $error, $context, $allow_relaxed_file_ownership );
       
   721 		ob_end_clean();
       
   722 		return $result;
       
   723 	}
       
   724 
       
   725 	public function get_upgrade_messages() {
       
   726 		return $this->messages;
       
   727 	}
       
   728 
       
   729 	/**
       
   730 	 * @param string|array|WP_Error $data
       
   731 	 */
       
   732 	public function feedback( $data ) {
       
   733 		if ( is_wp_error( $data ) ) {
       
   734 			$string = $data->get_error_message();
       
   735 		} elseif ( is_array( $data ) ) {
       
   736 			return;
       
   737 		} else {
       
   738 			$string = $data;
       
   739 		}
       
   740 		if ( ! empty( $this->upgrader->strings[ $string ] ) )
       
   741 			$string = $this->upgrader->strings[ $string ];
       
   742 
       
   743 		if ( strpos( $string, '%' ) !== false ) {
       
   744 			$args = func_get_args();
       
   745 			$args = array_splice( $args, 1 );
       
   746 			if ( ! empty( $args ) )
       
   747 				$string = vsprintf( $string, $args );
       
   748 		}
       
   749 
       
   750 		$string = trim( $string );
       
   751 
       
   752 		// Only allow basic HTML in the messages, as it'll be used in emails/logs rather than direct browser output.
       
   753 		$string = wp_kses( $string, array(
       
   754 			'a' => array(
       
   755 				'href' => true
       
   756 			),
       
   757 			'br' => true,
       
   758 			'em' => true,
       
   759 			'strong' => true,
       
   760 		) );
       
   761 
       
   762 		if ( empty( $string ) )
       
   763 			return;
       
   764 
       
   765 		$this->messages[] = $string;
       
   766 	}
       
   767 
       
   768 	public function header() {
       
   769 		ob_start();
       
   770 	}
       
   771 
       
   772 	public function footer() {
       
   773 		$output = ob_get_contents();
       
   774 		if ( ! empty( $output ) )
       
   775 			$this->feedback( $output );
       
   776 		ob_end_clean();
       
   777 	}
       
   778 
       
   779 	public function bulk_header() {}
       
   780 	public function bulk_footer() {}
       
   781 	public function before() {}
       
   782 	public function after() {}
       
   783 }