wp/wp-admin/includes/class-bulk-upgrader-skin.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    21 	 * @var string|false
    21 	 * @var string|false
    22 	 */
    22 	 */
    23 	public $error = false;
    23 	public $error = false;
    24 
    24 
    25 	/**
    25 	/**
    26 	 *
       
    27 	 * @param array $args
    26 	 * @param array $args
    28 	 */
    27 	 */
    29 	public function __construct($args = array()) {
    28 	public function __construct( $args = array() ) {
    30 		$defaults = array( 'url' => '', 'nonce' => '' );
    29 		$defaults = array(
    31 		$args = wp_parse_args($args, $defaults);
    30 			'url'   => '',
       
    31 			'nonce' => '',
       
    32 		);
       
    33 		$args     = wp_parse_args( $args, $defaults );
    32 
    34 
    33 		parent::__construct($args);
    35 		parent::__construct( $args );
    34 	}
    36 	}
    35 
    37 
    36 	/**
    38 	/**
    37 	 */
    39 	 */
    38 	public function add_strings() {
    40 	public function add_strings() {
    39 		$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 		$this->upgrader->strings['skin_upgrade_start'] = __( 'The update process is starting. This process may take a while on some hosts, so please be patient.' );
    40 		/* translators: 1: Title of an update, 2: Error message */
    42 		/* translators: 1: Title of an update, 2: Error message */
    41 		$this->upgrader->strings['skin_update_failed_error'] = __('An error occurred while updating %1$s: %2$s');
    43 		$this->upgrader->strings['skin_update_failed_error'] = __( 'An error occurred while updating %1$s: %2$s' );
    42 		/* translators: 1: Title of an update */
    44 		/* translators: %s: Title of an update */
    43 		$this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.');
    45 		$this->upgrader->strings['skin_update_failed'] = __( 'The update of %s failed.' );
    44 		/* translators: 1: Title of an update */
    46 		/* translators: %s: Title of an update */
    45 		$this->upgrader->strings['skin_update_successful'] = __( '%1$s updated successfully.' );
    47 		$this->upgrader->strings['skin_update_successful'] = __( '%s updated successfully.' );
    46 		$this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.');
    48 		$this->upgrader->strings['skin_upgrade_end']       = __( 'All updates have been completed.' );
    47 	}
    49 	}
    48 
    50 
    49 	/**
    51 	/**
    50 	 *
       
    51 	 * @param string $string
    52 	 * @param string $string
    52 	 */
    53 	 */
    53 	public function feedback($string) {
    54 	public function feedback( $string ) {
    54 		if ( isset( $this->upgrader->strings[$string] ) )
    55 		if ( isset( $this->upgrader->strings[ $string ] ) ) {
    55 			$string = $this->upgrader->strings[$string];
    56 			$string = $this->upgrader->strings[ $string ];
       
    57 		}
    56 
    58 
    57 		if ( strpos($string, '%') !== false ) {
    59 		if ( strpos( $string, '%' ) !== false ) {
    58 			$args = func_get_args();
    60 			$args = func_get_args();
    59 			$args = array_splice($args, 1);
    61 			$args = array_splice( $args, 1 );
    60 			if ( $args ) {
    62 			if ( $args ) {
    61 				$args = array_map( 'strip_tags', $args );
    63 				$args   = array_map( 'strip_tags', $args );
    62 				$args = array_map( 'esc_html', $args );
    64 				$args   = array_map( 'esc_html', $args );
    63 				$string = vsprintf($string, $args);
    65 				$string = vsprintf( $string, $args );
    64 			}
    66 			}
    65 		}
    67 		}
    66 		if ( empty($string) )
    68 		if ( empty( $string ) ) {
    67 			return;
    69 			return;
    68 		if ( $this->in_loop )
    70 		}
       
    71 		if ( $this->in_loop ) {
    69 			echo "$string<br />\n";
    72 			echo "$string<br />\n";
    70 		else
    73 		} else {
    71 			echo "<p>$string</p>\n";
    74 			echo "<p>$string</p>\n";
       
    75 		}
    72 	}
    76 	}
    73 
    77 
    74 	/**
    78 	/**
    75 	 */
    79 	 */
    76 	public function header() {
    80 	public function header() {
    82 	public function footer() {
    86 	public function footer() {
    83 		// Nothing, This will be displayed within a iframe.
    87 		// Nothing, This will be displayed within a iframe.
    84 	}
    88 	}
    85 
    89 
    86 	/**
    90 	/**
    87 	 *
       
    88 	 * @param string|WP_Error $error
    91 	 * @param string|WP_Error $error
    89 	 */
    92 	 */
    90 	public function error($error) {
    93 	public function error( $error ) {
    91 		if ( is_string($error) && isset( $this->upgrader->strings[$error] ) )
    94 		if ( is_string( $error ) && isset( $this->upgrader->strings[ $error ] ) ) {
    92 			$this->error = $this->upgrader->strings[$error];
    95 			$this->error = $this->upgrader->strings[ $error ];
       
    96 		}
    93 
    97 
    94 		if ( is_wp_error($error) ) {
    98 		if ( is_wp_error( $error ) ) {
    95 			$messages = array();
    99 			$messages = array();
    96 			foreach ( $error->get_error_messages() as $emessage ) {
   100 			foreach ( $error->get_error_messages() as $emessage ) {
    97 				if ( $error->get_error_data() && is_string( $error->get_error_data() ) )
   101 				if ( $error->get_error_data() && is_string( $error->get_error_data() ) ) {
    98 					$messages[] = $emessage . ' ' . esc_html( strip_tags( $error->get_error_data() ) );
   102 					$messages[] = $emessage . ' ' . esc_html( strip_tags( $error->get_error_data() ) );
    99 				else
   103 				} else {
   100 					$messages[] = $emessage;
   104 					$messages[] = $emessage;
       
   105 				}
   101 			}
   106 			}
   102 			$this->error = implode(', ', $messages);
   107 			$this->error = implode( ', ', $messages );
   103 		}
   108 		}
   104 		echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
   109 		echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').hide();</script>';
   105 	}
   110 	}
   106 
   111 
   107 	/**
   112 	/**
   108 	 */
   113 	 */
   109 	public function bulk_header() {
   114 	public function bulk_header() {
   110 		$this->feedback('skin_upgrade_start');
   115 		$this->feedback( 'skin_upgrade_start' );
   111 	}
   116 	}
   112 
   117 
   113 	/**
   118 	/**
   114 	 */
   119 	 */
   115 	public function bulk_footer() {
   120 	public function bulk_footer() {
   116 		$this->feedback('skin_upgrade_end');
   121 		$this->feedback( 'skin_upgrade_end' );
   117 	}
   122 	}
   118 
   123 
   119 	/**
   124 	/**
   120 	 *
       
   121 	 * @param string $title
   125 	 * @param string $title
   122 	 */
   126 	 */
   123 	public function before($title = '') {
   127 	public function before( $title = '' ) {
   124 		$this->in_loop = true;
   128 		$this->in_loop = true;
   125 		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 );
   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 );
   126 		echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').css("display", "inline-block");</script>';
   130 		echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').css("display", "inline-block");</script>';
   127 		// This progress messages div gets moved via JavaScript when clicking on "Show details.".
   131 		// This progress messages div gets moved via JavaScript when clicking on "Show details.".
   128 		echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr($this->upgrader->update_current) . '"><p>';
   132 		echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr( $this->upgrader->update_current ) . '"><p>';
   129 		$this->flush_output();
   133 		$this->flush_output();
   130 	}
   134 	}
   131 
   135 
   132 	/**
   136 	/**
   133 	 *
       
   134 	 * @param string $title
   137 	 * @param string $title
   135 	 */
   138 	 */
   136 	public function after($title = '') {
   139 	public function after( $title = '' ) {
   137 		echo '</p></div>';
   140 		echo '</p></div>';
   138 		if ( $this->error || ! $this->result ) {
   141 		if ( $this->error || ! $this->result ) {
   139 			if ( $this->error ) {
   142 			if ( $this->error ) {
   140 				echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, '<strong>' . $this->error . '</strong>' ) . '</p></div>';
   143 				echo '<div class="error"><p>' . sprintf( $this->upgrader->strings['skin_update_failed_error'], $title, '<strong>' . $this->error . '</strong>' ) . '</p></div>';
   141 			} else {
   144 			} else {
   142 				echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '</p></div>';
   145 				echo '<div class="error"><p>' . sprintf( $this->upgrader->strings['skin_update_failed'], $title ) . '</p></div>';
   143 			}
   146 			}
   144 
   147 
   145 			echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
   148 			echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js( $this->upgrader->update_current ) . '\').show();</script>';
   146 		}
   149 		}
   147 		if ( $this->result && ! is_wp_error( $this->result ) ) {
   150 		if ( $this->result && ! is_wp_error( $this->result ) ) {
   148 			if ( ! $this->error ) {
   151 			if ( ! $this->error ) {
   149 				echo '<div class="updated js-update-details" data-update-details="progress-' . esc_attr( $this->upgrader->update_current ) . '">' .
   152 				echo '<div class="updated js-update-details" data-update-details="progress-' . esc_attr( $this->upgrader->update_current ) . '">' .
   150 					'<p>' . sprintf( $this->upgrader->strings['skin_update_successful'], $title ) .
   153 					'<p>' . sprintf( $this->upgrader->strings['skin_update_successful'], $title ) .
   151 					' <button type="button" class="hide-if-no-js button-link js-update-details-toggle" aria-expanded="false">' . __( 'Show details.' ) . '</button>' .
   154 					' <button type="button" class="hide-if-no-js button-link js-update-details-toggle" aria-expanded="false">' . __( 'Show details.' ) . '</button>' .
   152 					'</p></div>';
   155 					'</p></div>';
   153 			}
   156 			}
   154 
   157 
   155 			echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
   158 			echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').hide();</script>';
   156 		}
   159 		}
   157 
   160 
   158 		$this->reset();
   161 		$this->reset();
   159 		$this->flush_output();
   162 		$this->flush_output();
   160 	}
   163 	}
   161 
   164 
   162 	/**
   165 	/**
   163 	 */
   166 	 */
   164 	public function reset() {
   167 	public function reset() {
   165 		$this->in_loop = false;
   168 		$this->in_loop = false;
   166 		$this->error = false;
   169 		$this->error   = false;
   167 	}
   170 	}
   168 
   171 
   169 	/**
   172 	/**
   170 	 */
   173 	 */
   171 	public function flush_output() {
   174 	public function flush_output() {