/olympia/WebKitSite/blog/wp-admin/update.php

https://github.com/chrisguan/Olympia_on_Desktop · PHP · 193 lines · 133 code · 53 blank · 7 comment · 23 complexity · 746bb374d256f4aa07b0d088230498ce MD5 · raw file

  1. <?php
  2. /**
  3. * Update/Install Plugin/Theme administration panel.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /** WordPress Administration Bootstrap */
  9. require_once('admin.php');
  10. include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
  11. if ( isset($_GET['action']) ) {
  12. $plugin = isset($_REQUEST['plugin']) ? trim($_REQUEST['plugin']) : '';
  13. $theme = isset($_REQUEST['theme']) ? urldecode($_REQUEST['theme']) : '';
  14. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
  15. if ( 'upgrade-plugin' == $action ) {
  16. if ( ! current_user_can('update_plugins') )
  17. wp_die(__('You do not have sufficient permissions to update plugins for this blog.'));
  18. check_admin_referer('upgrade-plugin_' . $plugin);
  19. $title = __('Upgrade Plugin');
  20. $parent_file = 'plugins.php';
  21. $submenu_file = 'plugins.php';
  22. require_once('admin-header.php');
  23. $nonce = 'upgrade-plugin_' . $plugin;
  24. $url = 'update.php?action=upgrade-plugin&plugin=' . $plugin;
  25. $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact('title', 'nonce', 'url', 'plugin') ) );
  26. $upgrader->upgrade($plugin);
  27. include('admin-footer.php');
  28. } elseif ('activate-plugin' == $action ) {
  29. if ( ! current_user_can('update_plugins') )
  30. wp_die(__('You do not have sufficient permissions to update plugins for this blog.'));
  31. check_admin_referer('activate-plugin_' . $plugin);
  32. if( ! isset($_GET['failure']) && ! isset($_GET['success']) ) {
  33. wp_redirect( 'update.php?action=activate-plugin&failure=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce'] );
  34. activate_plugin($plugin);
  35. wp_redirect( 'update.php?action=activate-plugin&success=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce'] );
  36. die();
  37. }
  38. iframe_header( __('Plugin Reactivation'), true );
  39. if( isset($_GET['success']) )
  40. echo '<p>' . __('Plugin reactivated successfully.') . '</p>';
  41. if( isset($_GET['failure']) ){
  42. echo '<p>' . __('Plugin failed to reactivate due to a fatal error.') . '</p>';
  43. error_reporting( E_ALL ^ E_NOTICE );
  44. @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
  45. include(WP_PLUGIN_DIR . '/' . $plugin);
  46. }
  47. iframe_footer();
  48. } elseif ( 'install-plugin' == $action ) {
  49. if ( ! current_user_can('install_plugins') )
  50. wp_die(__('You do not have sufficient permissions to install plugins for this blog.'));
  51. include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api..
  52. check_admin_referer('install-plugin_' . $plugin);
  53. $api = plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
  54. if ( is_wp_error($api) )
  55. wp_die($api);
  56. $title = __('Plugin Install');
  57. $parent_file = 'plugins.php';
  58. $submenu_file = 'plugin-install.php';
  59. require_once('admin-header.php');
  60. $title = sprintf( __('Installing Plugin: %s'), $api->name . ' ' . $api->version );
  61. $nonce = 'install-plugin_' . $plugin;
  62. $url = 'update.php?action=install-plugin&plugin=' . $plugin;
  63. $type = 'web'; //Install plugin type, From Web or an Upload.
  64. $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
  65. $upgrader->install($api->download_link);
  66. include('admin-footer.php');
  67. } elseif ( 'upload-plugin' == $action ) {
  68. if ( ! current_user_can('install_plugins') )
  69. wp_die(__('You do not have sufficient permissions to install plugins for this blog.'));
  70. check_admin_referer('plugin-upload');
  71. $file_upload = new File_Upload_Upgrader('pluginzip', 'package');
  72. $title = __('Upload Plugin');
  73. $parent_file = 'plugins.php';
  74. $submenu_file = 'plugin-install.php';
  75. require_once('admin-header.php');
  76. $title = sprintf( __('Installing Plugin from uploaded file: %s'), basename( $file_upload->filename ) );
  77. $nonce = 'plugin-upload';
  78. $url = add_query_arg(array('package' => $file_upload->filename ), 'update.php?action=upload-plugin');
  79. $type = 'upload'; //Install plugin type, From Web or an Upload.
  80. $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
  81. $upgrader->install( $file_upload->package );
  82. include('admin-footer.php');
  83. } elseif ( 'upgrade-theme' == $action ) {
  84. if ( ! current_user_can('update_themes') )
  85. wp_die(__('You do not have sufficient permissions to update themes for this blog.'));
  86. check_admin_referer('upgrade-theme_' . $theme);
  87. add_thickbox();
  88. wp_enqueue_script('theme-preview');
  89. $title = __('Upgrade Theme');
  90. $parent_file = 'themes.php';
  91. $submenu_file = 'themes.php';
  92. require_once('admin-header.php');
  93. $nonce = 'upgrade-theme_' . $theme;
  94. $url = 'update.php?action=upgrade-theme&theme=' . $theme;
  95. $upgrader = new Theme_Upgrader( new Theme_Upgrader_Skin( compact('title', 'nonce', 'url', 'theme') ) );
  96. $upgrader->upgrade($theme);
  97. include('admin-footer.php');
  98. } elseif ( 'install-theme' == $action ) {
  99. if ( ! current_user_can('install_themes') )
  100. wp_die(__('You do not have sufficient permissions to install themes for this blog.'));
  101. include_once ABSPATH . 'wp-admin/includes/theme-install.php'; //for themes_api..
  102. check_admin_referer('install-theme_' . $theme);
  103. $api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
  104. if ( is_wp_error($api) )
  105. wp_die($api);
  106. add_thickbox();
  107. wp_enqueue_script('theme-preview');
  108. $title = __('Install Themes');
  109. $parent_file = 'themes.php';
  110. $submenu_file = 'theme-install.php';
  111. require_once('admin-header.php');
  112. $title = sprintf( __('Installing theme: %s'), $api->name . ' ' . $api->version );
  113. $nonce = 'install-theme_' . $theme;
  114. $url = 'update.php?action=install-theme&theme=' . $theme;
  115. $type = 'web'; //Install theme type, From Web or an Upload.
  116. $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
  117. $upgrader->install($api->download_link);
  118. include('admin-footer.php');
  119. } elseif ( 'upload-theme' == $action ) {
  120. if ( ! current_user_can('install_themes') )
  121. wp_die(__('You do not have sufficient permissions to install themes for this blog.'));
  122. check_admin_referer('theme-upload');
  123. $file_upload = new File_Upload_Upgrader('themezip', 'package');
  124. $title = __('Upload Theme');
  125. $parent_file = 'themes.php';
  126. $submenu_file = 'theme-install.php';
  127. add_thickbox();
  128. wp_enqueue_script('theme-preview');
  129. require_once('admin-header.php');
  130. $title = sprintf( __('Installing Theme from uploaded file: %s'), basename( $file_upload->filename ) );
  131. $nonce = 'theme-upload';
  132. $url = add_query_arg(array('package' => $file_upload->filename), 'update.php?action=upload-theme');
  133. $type = 'upload'; //Install plugin type, From Web or an Upload.
  134. $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
  135. $upgrader->install( $file_upload->package );
  136. include('admin-footer.php');
  137. } else {
  138. do_action('update-custom_' . $action);
  139. }
  140. }