PageRenderTime 58ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

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

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