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