PageRenderTime 399ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/includes/class-wp-upgrader-skins.php

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