]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/class-bulk-upgrader-skin.php
WordPress 4.7.2
[autoinstalls/wordpress.git] / wp-admin / includes / class-bulk-upgrader-skin.php
1 <?php
2 /**
3  * Upgrader API: Bulk_Upgrader_Skin class
4  *
5  * @package WordPress
6  * @subpackage Upgrader
7  * @since 4.6.0
8  */
9
10 /**
11  * Generic Bulk Upgrader Skin for WordPress Upgrades.
12  *
13  * @since 3.0.0
14  * @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php.
15  *
16  * @see WP_Upgrader_Skin
17  */
18 class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
19         public $in_loop = false;
20         /**
21          * @var string|false
22          */
23         public $error = false;
24
25         /**
26          *
27          * @param array $args
28          */
29         public function __construct($args = array()) {
30                 $defaults = array( 'url' => '', 'nonce' => '' );
31                 $args = wp_parse_args($args, $defaults);
32
33                 parent::__construct($args);
34         }
35
36         /**
37          * @access public
38          */
39         public function add_strings() {
40                 $this->upgrader->strings['skin_upgrade_start'] = __('The update process is starting. This process may take a while on some hosts, so please be patient.');
41                 /* translators: 1: Title of an update, 2: Error message */
42                 $this->upgrader->strings['skin_update_failed_error'] = __('An error occurred while updating %1$s: %2$s');
43                 /* translators: 1: Title of an update */
44                 $this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.');
45                 /* translators: 1: Title of an update */
46                 $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>';
47                 $this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.');
48         }
49
50         /**
51          * @param string $string
52          */
53         public function feedback($string) {
54                 if ( isset( $this->upgrader->strings[$string] ) )
55                         $string = $this->upgrader->strings[$string];
56
57                 if ( strpos($string, '%') !== false ) {
58                         $args = func_get_args();
59                         $args = array_splice($args, 1);
60                         if ( $args ) {
61                                 $args = array_map( 'strip_tags', $args );
62                                 $args = array_map( 'esc_html', $args );
63                                 $string = vsprintf($string, $args);
64                         }
65                 }
66                 if ( empty($string) )
67                         return;
68                 if ( $this->in_loop )
69                         echo "$string<br />\n";
70                 else
71                         echo "<p>$string</p>\n";
72         }
73
74         /**
75          * @access public
76          */
77         public function header() {
78                 // Nothing, This will be displayed within a iframe.
79         }
80
81         /**
82          * @access public
83          */
84         public function footer() {
85                 // Nothing, This will be displayed within a iframe.
86         }
87
88         /**
89          *
90          * @param string|WP_Error $error
91          */
92         public function error($error) {
93                 if ( is_string($error) && isset( $this->upgrader->strings[$error] ) )
94                         $this->error = $this->upgrader->strings[$error];
95
96                 if ( is_wp_error($error) ) {
97                         $messages = array();
98                         foreach ( $error->get_error_messages() as $emessage ) {
99                                 if ( $error->get_error_data() && is_string( $error->get_error_data() ) )
100                                         $messages[] = $emessage . ' ' . esc_html( strip_tags( $error->get_error_data() ) );
101                                 else
102                                         $messages[] = $emessage;
103                         }
104                         $this->error = implode(', ', $messages);
105                 }
106                 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
107         }
108
109         /**
110          * @access public
111          */
112         public function bulk_header() {
113                 $this->feedback('skin_upgrade_start');
114         }
115
116         /**
117          * @access public
118          */
119         public function bulk_footer() {
120                 $this->feedback('skin_upgrade_end');
121         }
122
123         /**
124          *
125          * @param string $title
126          */
127         public function before($title = '') {
128                 $this->in_loop = true;
129                 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 );
130                 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').css("display", "inline-block");</script>';
131                 echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr($this->upgrader->update_current) . '"><p>';
132                 $this->flush_output();
133         }
134
135         /**
136          *
137          * @param string $title
138          */
139         public function after($title = '') {
140                 echo '</p></div>';
141                 if ( $this->error || ! $this->result ) {
142                         if ( $this->error ) {
143                                 echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, '<strong>' . $this->error . '</strong>' ) . '</p></div>';
144                         } else {
145                                 echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '</p></div>';
146                         }
147
148                         echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
149                 }
150                 if ( $this->result && ! is_wp_error( $this->result ) ) {
151                         if ( ! $this->error )
152                                 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>';
153                         echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
154                 }
155
156                 $this->reset();
157                 $this->flush_output();
158         }
159
160         /**
161          * @access public
162          */
163         public function reset() {
164                 $this->in_loop = false;
165                 $this->error = false;
166         }
167
168         /**
169          * @access public
170          */
171         public function flush_output() {
172                 wp_ob_end_flush_all();
173                 flush();
174         }
175 }