]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/class-wp-upgrader-skins.php
WordPress 3.8.1
[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         var $upgrader;
20         var $done_header = false;
21         var $result = false;
22
23         function __construct($args = array()) {
24                 $defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false );
25                 $this->options = wp_parse_args($args, $defaults);
26         }
27
28         function set_upgrader(&$upgrader) {
29                 if ( is_object($upgrader) )
30                         $this->upgrader =& $upgrader;
31                 $this->add_strings();
32         }
33
34         function add_strings() {
35         }
36
37         function set_result($result) {
38                 $this->result = $result;
39         }
40
41         function request_filesystem_credentials($error = false) {
42                 $url = $this->options['url'];
43                 $context = $this->options['context'];
44                 if ( !empty($this->options['nonce']) )
45                         $url = wp_nonce_url($url, $this->options['nonce']);
46                 return request_filesystem_credentials($url, '', $error, $context); //Possible to bring inline, Leaving as is for now.
47         }
48
49         function header() {
50                 if ( $this->done_header )
51                         return;
52                 $this->done_header = true;
53                 echo '<div class="wrap">';
54                 echo '<h2>' . $this->options['title'] . '</h2>';
55         }
56         function footer() {
57                 echo '</div>';
58         }
59
60         function error($errors) {
61                 if ( ! $this->done_header )
62                         $this->header();
63                 if ( is_string($errors) ) {
64                         $this->feedback($errors);
65                 } elseif ( is_wp_error($errors) && $errors->get_error_code() ) {
66                         foreach ( $errors->get_error_messages() as $message ) {
67                                 if ( $errors->get_error_data() && is_string( $errors->get_error_data() ) )
68                                         $this->feedback($message . ' ' . esc_html( $errors->get_error_data() ) );
69                                 else
70                                         $this->feedback($message);
71                         }
72                 }
73         }
74
75         function feedback($string) {
76                 if ( isset( $this->upgrader->strings[$string] ) )
77                         $string = $this->upgrader->strings[$string];
78
79                 if ( strpos($string, '%') !== false ) {
80                         $args = func_get_args();
81                         $args = array_splice($args, 1);
82                         if ( $args ) {
83                                 $args = array_map( 'strip_tags', $args );
84                                 $args = array_map( 'esc_html', $args );
85                                 $string = vsprintf($string, $args);
86                         }
87                 }
88                 if ( empty($string) )
89                         return;
90                 show_message($string);
91         }
92         function before() {}
93         function after() {}
94
95 }
96
97 /**
98  * Plugin Upgrader Skin for WordPress Plugin Upgrades.
99  *
100  * @package WordPress
101  * @subpackage Upgrader
102  * @since 2.8.0
103  */
104 class Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
105         var $plugin = '';
106         var $plugin_active = false;
107         var $plugin_network_active = false;
108
109         function __construct($args = array()) {
110                 $defaults = array( 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => __('Update Plugin') );
111                 $args = wp_parse_args($args, $defaults);
112
113                 $this->plugin = $args['plugin'];
114
115                 $this->plugin_active = is_plugin_active( $this->plugin );
116                 $this->plugin_network_active = is_plugin_active_for_network( $this->plugin );
117
118                 parent::__construct($args);
119         }
120
121         function after() {
122                 $this->plugin = $this->upgrader->plugin_info();
123                 if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){
124                         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>';
125                 }
126
127                 $update_actions =  array(
128                         '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>',
129                         'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>'
130                 );
131                 if ( $this->plugin_active || ! $this->result || is_wp_error( $this->result ) || ! current_user_can( 'activate_plugins' ) )
132                         unset( $update_actions['activate_plugin'] );
133
134                 $update_actions = apply_filters('update_plugin_complete_actions', $update_actions, $this->plugin);
135                 if ( ! empty($update_actions) )
136                         $this->feedback(implode(' | ', (array)$update_actions));
137         }
138 }
139
140 /**
141  * Plugin Upgrader Skin for WordPress Plugin Upgrades.
142  *
143  * @package WordPress
144  * @subpackage Upgrader
145  * @since 3.0.0
146  */
147 class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
148         var $in_loop = false;
149         var $error = false;
150
151         function __construct($args = array()) {
152                 $defaults = array( 'url' => '', 'nonce' => '' );
153                 $args = wp_parse_args($args, $defaults);
154
155                 parent::__construct($args);
156         }
157
158         function add_strings() {
159                 $this->upgrader->strings['skin_upgrade_start'] = __('The update process is starting. This process may take a while on some hosts, so please be patient.');
160                 $this->upgrader->strings['skin_update_failed_error'] = __('An error occurred while updating %1$s: <strong>%2$s</strong>');
161                 $this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.');
162                 $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>';
163                 $this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.');
164         }
165
166         function feedback($string) {
167                 if ( isset( $this->upgrader->strings[$string] ) )
168                         $string = $this->upgrader->strings[$string];
169
170                 if ( strpos($string, '%') !== false ) {
171                         $args = func_get_args();
172                         $args = array_splice($args, 1);
173                         if ( $args ) {
174                                 $args = array_map( 'strip_tags', $args );
175                                 $args = array_map( 'esc_html', $args );
176                                 $string = vsprintf($string, $args);
177                         }
178                 }
179                 if ( empty($string) )
180                         return;
181                 if ( $this->in_loop )
182                         echo "$string<br />\n";
183                 else
184                         echo "<p>$string</p>\n";
185         }
186
187         function header() {
188                 // Nothing, This will be displayed within a iframe.
189         }
190
191         function footer() {
192                 // Nothing, This will be displayed within a iframe.
193         }
194         function error($error) {
195                 if ( is_string($error) && isset( $this->upgrader->strings[$error] ) )
196                         $this->error = $this->upgrader->strings[$error];
197
198                 if ( is_wp_error($error) ) {
199                         foreach ( $error->get_error_messages() as $emessage ) {
200                                 if ( $error->get_error_data() && is_string( $error->get_error_data() ) )
201                                         $messages[] = $emessage . ' ' . esc_html( $error->get_error_data() );
202                                 else
203                                         $messages[] = $emessage;
204                         }
205                         $this->error = implode(', ', $messages);
206                 }
207                 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
208         }
209
210         function bulk_header() {
211                 $this->feedback('skin_upgrade_start');
212         }
213
214         function bulk_footer() {
215                 $this->feedback('skin_upgrade_end');
216         }
217
218         function before($title = '') {
219                 $this->in_loop = true;
220                 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);
221                 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').css("display", "inline-block");</script>';
222                 echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr($this->upgrader->update_current) . '"><p>';
223                 $this->flush_output();
224         }
225
226         function after($title = '') {
227                 echo '</p></div>';
228                 if ( $this->error || ! $this->result ) {
229                         if ( $this->error )
230                                 echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, $this->error) . '</p></div>';
231                         else
232                                 echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '</p></div>';
233
234                         echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
235                 }
236                 if ( $this->result && ! is_wp_error( $this->result ) ) {
237                         if ( ! $this->error )
238                                 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>';
239                         echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
240                 }
241
242                 $this->reset();
243                 $this->flush_output();
244         }
245
246         function reset() {
247                 $this->in_loop = false;
248                 $this->error = false;
249         }
250
251         function flush_output() {
252                 wp_ob_end_flush_all();
253                 flush();
254         }
255 }
256
257 class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
258         var $plugin_info = array(); // Plugin_Upgrader::bulk() will fill this in.
259
260         function __construct($args = array()) {
261                 parent::__construct($args);
262         }
263
264         function add_strings() {
265                 parent::add_strings();
266                 $this->upgrader->strings['skin_before_update_header'] = __('Updating Plugin %1$s (%2$d/%3$d)');
267         }
268
269         function before($title = '') {
270                 parent::before($this->plugin_info['Title']);
271         }
272
273         function after($title = '') {
274                 parent::after($this->plugin_info['Title']);
275         }
276         function bulk_footer() {
277                 parent::bulk_footer();
278                 $update_actions =  array(
279                         'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>',
280                         '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>'
281                 );
282                 if ( ! current_user_can( 'activate_plugins' ) )
283                         unset( $update_actions['plugins_page'] );
284
285                 $update_actions = apply_filters('update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info);
286                 if ( ! empty($update_actions) )
287                         $this->feedback(implode(' | ', (array)$update_actions));
288         }
289 }
290
291 class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin {
292         var $theme_info = array(); // Theme_Upgrader::bulk() will fill this in.
293
294         function __construct($args = array()) {
295                 parent::__construct($args);
296         }
297
298         function add_strings() {
299                 parent::add_strings();
300                 $this->upgrader->strings['skin_before_update_header'] = __('Updating Theme %1$s (%2$d/%3$d)');
301         }
302
303         function before($title = '') {
304                 parent::before( $this->theme_info->display('Name') );
305         }
306
307         function after($title = '') {
308                 parent::after( $this->theme_info->display('Name') );
309         }
310
311         function bulk_footer() {
312                 parent::bulk_footer();
313                 $update_actions =  array(
314                         'themes_page' => '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Go to themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>',
315                         '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>'
316                 );
317                 if ( ! current_user_can( 'switch_themes' ) && ! current_user_can( 'edit_theme_options' ) )
318                         unset( $update_actions['themes_page'] );
319
320                 $update_actions = apply_filters('update_bulk_theme_complete_actions', $update_actions, $this->theme_info );
321                 if ( ! empty($update_actions) )
322                         $this->feedback(implode(' | ', (array)$update_actions));
323         }
324 }
325
326 /**
327  * Plugin Installer Skin for WordPress Plugin Installer.
328  *
329  * @package WordPress
330  * @subpackage Upgrader
331  * @since 2.8.0
332  */
333 class Plugin_Installer_Skin extends WP_Upgrader_Skin {
334         var $api;
335         var $type;
336
337         function __construct($args = array()) {
338                 $defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' );
339                 $args = wp_parse_args($args, $defaults);
340
341                 $this->type = $args['type'];
342                 $this->api = isset($args['api']) ? $args['api'] : array();
343
344                 parent::__construct($args);
345         }
346
347         function before() {
348                 if ( !empty($this->api) )
349                         $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin <strong>%s %s</strong>.'), $this->api->name, $this->api->version);
350         }
351
352         function after() {
353
354                 $plugin_file = $this->upgrader->plugin_info();
355
356                 $install_actions = array();
357
358                 $from = isset($_GET['from']) ? wp_unslash( $_GET['from'] ) : 'plugins';
359
360                 if ( 'import' == $from )
361                         $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>';
362                 else
363                         $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>';
364
365                 if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
366                         $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>';
367                         unset( $install_actions['activate_plugin'] );
368                 }
369
370                 if ( 'import' == $from )
371                         $install_actions['importers_page'] = '<a href="' . admin_url('import.php') . '" title="' . esc_attr__('Return to Importers') . '" target="_parent">' . __('Return to Importers') . '</a>';
372                 else if ( $this->type == 'web' )
373                         $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>';
374                 else
375                         $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>';
376
377                 if ( ! $this->result || is_wp_error($this->result) ) {
378                         unset( $install_actions['activate_plugin'], $install_actions['network_activate'] );
379                 } elseif ( ! current_user_can( 'activate_plugins' ) ) {
380                         unset( $install_actions['activate_plugin'] );
381                 }
382
383                 $install_actions = apply_filters('install_plugin_complete_actions', $install_actions, $this->api, $plugin_file);
384                 if ( ! empty($install_actions) )
385                         $this->feedback(implode(' | ', (array)$install_actions));
386         }
387 }
388
389 /**
390  * Theme Installer Skin for the WordPress Theme Installer.
391  *
392  * @package WordPress
393  * @subpackage Upgrader
394  * @since 2.8.0
395  */
396 class Theme_Installer_Skin extends WP_Upgrader_Skin {
397         var $api;
398         var $type;
399
400         function __construct($args = array()) {
401                 $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' );
402                 $args = wp_parse_args($args, $defaults);
403
404                 $this->type = $args['type'];
405                 $this->api = isset($args['api']) ? $args['api'] : array();
406
407                 parent::__construct($args);
408         }
409
410         function before() {
411                 if ( !empty($this->api) )
412                         $this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version);
413         }
414
415         function after() {
416                 if ( empty($this->upgrader->result['destination_name']) )
417                         return;
418
419                 $theme_info = $this->upgrader->theme_info();
420                 if ( empty( $theme_info ) )
421                         return;
422
423                 $name       = $theme_info->display('Name');
424                 $stylesheet = $this->upgrader->result['destination_name'];
425                 $template   = $theme_info->get_template();
426
427                 $preview_link = add_query_arg( array(
428                         'preview'    => 1,
429                         'template'   => urlencode( $template ),
430                         'stylesheet' => urlencode( $stylesheet ),
431                 ), trailingslashit( home_url() ) );
432
433                 $activate_link = add_query_arg( array(
434                         'action'     => 'activate',
435                         'template'   => urlencode( $template ),
436                         'stylesheet' => urlencode( $stylesheet ),
437                 ), admin_url('themes.php') );
438                 $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
439
440                 $install_actions = array();
441                 $install_actions['preview']  = '<a href="' . esc_url( $preview_link ) . '" class="hide-if-customize" title="' . esc_attr( sprintf( __('Preview &#8220;%s&#8221;'), $name ) ) . '">' . __('Preview') . '</a>';
442                 $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>';
443                 $install_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $name ) ) . '">' . __('Activate') . '</a>';
444
445                 if ( is_network_admin() && current_user_can( 'manage_network_themes' ) )
446                         $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>';
447
448                 if ( $this->type == 'web' )
449                         $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>';
450                 elseif ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) )
451                         $install_actions['themes_page'] = '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>';
452
453                 if ( ! $this->result || is_wp_error($this->result) || is_network_admin() || ! current_user_can( 'switch_themes' ) )
454                         unset( $install_actions['activate'], $install_actions['preview'] );
455
456                 $install_actions = apply_filters('install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info);
457                 if ( ! empty($install_actions) )
458                         $this->feedback(implode(' | ', (array)$install_actions));
459         }
460 }
461
462 /**
463  * Theme Upgrader Skin for WordPress Theme Upgrades.
464  *
465  * @package WordPress
466  * @subpackage Upgrader
467  * @since 2.8.0
468  */
469 class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
470         var $theme = '';
471
472         function __construct($args = array()) {
473                 $defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Update Theme') );
474                 $args = wp_parse_args($args, $defaults);
475
476                 $this->theme = $args['theme'];
477
478                 parent::__construct($args);
479         }
480
481         function after() {
482
483                 $update_actions = array();
484                 if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) {
485                         $name       = $theme_info->display('Name');
486                         $stylesheet = $this->upgrader->result['destination_name'];
487                         $template   = $theme_info->get_template();
488
489                         $preview_link = add_query_arg( array(
490                                 'preview'    => 1,
491                                 'template'   => urlencode( $template ),
492                                 'stylesheet' => urlencode( $stylesheet ),
493                         ), trailingslashit( home_url() ) );
494
495                         $activate_link = add_query_arg( array(
496                                 'action'     => 'activate',
497                                 'template'   => urlencode( $template ),
498                                 'stylesheet' => urlencode( $stylesheet ),
499                         ), admin_url('themes.php') );
500                         $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
501
502                         if ( get_stylesheet() == $stylesheet ) {
503                                 if ( current_user_can( 'edit_theme_options' ) )
504                                         $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>';
505                         } elseif ( current_user_can( 'switch_themes' ) ) {
506                                 $update_actions['preview']  = '<a href="' . esc_url( $preview_link ) . '" class="hide-if-customize" title="' . esc_attr( sprintf( __('Preview &#8220;%s&#8221;'), $name ) ) . '">' . __('Preview') . '</a>';
507                                 $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>';
508                                 $update_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $name ) ) . '">' . __('Activate') . '</a>';
509                         }
510
511                         if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() )
512                                 unset( $update_actions['preview'], $update_actions['activate'] );
513                 }
514
515                 $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>';
516
517                 $update_actions = apply_filters('update_theme_complete_actions', $update_actions, $this->theme);
518                 if ( ! empty($update_actions) )
519                         $this->feedback(implode(' | ', (array)$update_actions));
520         }
521 }
522
523 /**
524  * Translation Upgrader Skin for WordPress Translation Upgrades.
525  *
526  * @package WordPress
527  * @subpackage Upgrader
528  * @since 3.7.0
529  */
530 class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin {
531         var $language_update = null;
532         var $done_header = false;
533         var $display_footer_actions = true;
534
535         function __construct( $args = array() ) {
536                 $defaults = array( 'url' => '', 'nonce' => '', 'title' => __( 'Update Translations' ), 'skip_header_footer' => false );
537                 $args = wp_parse_args( $args, $defaults );
538                 if ( $args['skip_header_footer'] ) {
539                         $this->done_header = true;
540                         $this->display_footer_actions = false;
541                 }
542                 parent::__construct( $args );
543         }
544
545         function before() {
546                 $name = $this->upgrader->get_name_for_update( $this->language_update );
547
548                 echo '<div class="update-messages lp-show-latest">';
549
550                 printf( '<h4>' . __( 'Updating translations for %1$s (%2$s)&#8230;' ) . '</h4>', $name, $this->language_update->language );
551         }
552
553         function error( $error ) {
554                 echo '<div class="lp-error">';
555                 parent::error( $error );
556                 echo '</div>';
557         }
558
559         function after() {
560                 echo '</div>';
561         }
562
563         function bulk_footer() {
564                 $update_actions = array();
565                 $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>';
566                 $update_actions = apply_filters( 'update_translations_complete_actions', $update_actions );
567
568                 if ( $update_actions && $this->display_footer_actions )
569                         $this->feedback( implode( ' | ', $update_actions ) );
570
571                 parent::footer();
572         }
573 }
574
575 /**
576  * Upgrader Skin for Automatic WordPress Upgrades
577  *
578  * This skin is designed to be used when no output is intended, all output
579  * is captured and stored for the caller to process and log/email/discard.
580  *
581  * @package WordPress
582  * @subpackage Upgrader
583  * @since 3.7.0
584  */
585 class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
586         protected $messages = array();
587
588         function request_filesystem_credentials( $error = false, $context = '' ) {
589                 if ( $context )
590                         $this->options['context'] = $context;
591                 // TODO: fix up request_filesystem_credentials(), or split it, to allow us to request a no-output version
592                 // This will output a credentials form in event of failure, We don't want that, so just hide with a buffer
593                 ob_start();
594                 $result = parent::request_filesystem_credentials( $error );
595                 ob_end_clean();
596                 return $result;
597         }
598
599         function get_upgrade_messages() {
600                 return $this->messages;
601         }
602
603         function feedback( $data ) {
604                 if ( is_wp_error( $data ) )
605                         $string = $data->get_error_message();
606                 else if ( is_array( $data ) )
607                         return;
608                 else
609                         $string = $data;
610
611                 if ( ! empty( $this->upgrader->strings[ $string ] ) )
612                         $string = $this->upgrader->strings[ $string ];
613
614                 if ( strpos( $string, '%' ) !== false ) {
615                         $args = func_get_args();
616                         $args = array_splice( $args, 1 );
617                         if ( ! empty( $args ) )
618                                 $string = vsprintf( $string, $args );
619                 }
620
621                 $string = trim( $string );
622
623                 // Only allow basic HTML in the messages, as it'll be used in emails/logs rather than direct browser output.
624                 $string = wp_kses( $string, array(
625                         'a' => array(
626                                 'href' => true
627                         ),
628                         'br' => true,
629                         'em' => true,
630                         'strong' => true,
631                 ) );
632
633                 if ( empty( $string ) )
634                         return;
635
636                 $this->messages[] = $string;
637         }
638
639         function header() {
640                 ob_start();
641         }
642
643         function footer() {
644                 $output = ob_get_contents();
645                 if ( ! empty( $output ) )
646                         $this->feedback( $output );
647                 ob_end_clean();
648         }
649
650         function bulk_header() {}
651         function bulk_footer() {}
652         function before() {}
653         function after() {}
654 }