home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Blogs / wordpress2.6.exe / wordpress2.6 / wp-admin / update.php < prev    next >
Encoding:
PHP Script  |  2008-06-06  |  6.9 KB  |  175 lines

  1. <?php
  2.  
  3. require_once('admin.php');
  4.  
  5. if ( ! current_user_can('update_plugins') )
  6.     wp_die(__('You do not have sufficient permissions to update plugins for this blog.'));
  7.  
  8. function request_filesystem_credentials($form_post, $type = '', $error = false) {
  9.     $req_cred = apply_filters('request_filesystem_credentials', '', $form_post, $type, $error);
  10.     if ( '' !== $req_cred )
  11.         return $req_cred;
  12.  
  13.     if ( empty($type) )
  14.         $type = get_filesystem_method();
  15.  
  16.     if ( 'direct' == $type )
  17.         return true;
  18.         
  19.     if( ! $credentials = get_option('ftp_credentials') )
  20.         $credentials = array();
  21.     // If defined, set it to that, Else, If POST'd, set it to that, If not, Set it to whatever it previously was(saved details in option)
  22.     $credentials['hostname'] = defined('FTP_HOST') ? FTP_HOST : (!empty($_POST['hostname']) ? $_POST['hostname'] : $credentials['hostname']);
  23.     $credentials['username'] = defined('FTP_USER') ? FTP_USER : (!empty($_POST['username']) ? $_POST['username'] : $credentials['username']);
  24.     $credentials['password'] = defined('FTP_PASS') ? FTP_PASS : (!empty($_POST['password']) ? $_POST['password'] : $credentials['password']);
  25.     $credentials['ssl']      = defined('FTP_SSL')  ? FTP_SSL  : ( isset($_POST['ssl'])      ? $_POST['ssl']      : $credentials['ssl']);
  26.  
  27.     if ( ! $error && !empty($credentials['password']) && !empty($credentials['username']) && !empty($credentials['hostname']) ) {
  28.         $stored_credentials = $credentials;
  29.         unset($stored_credentials['password']);
  30.         update_option('ftp_credentials', $stored_credentials);
  31.         return $credentials;
  32.     }
  33.     $hostname = '';
  34.     $username = '';
  35.     $password = '';
  36.     $ssl = '';
  37.     if ( !empty($credentials) )
  38.         extract($credentials, EXTR_OVERWRITE);
  39.     if( $error )
  40.         echo '<div id="message" class="error"><p>' . __('<strong>Error:</strong> There was an error connecting to the server, Please verify the settings are correct.') . '</p></div>';
  41. ?>
  42. <form action="<?php echo $form_post ?>" method="post">
  43. <div class="wrap">
  44. <h2><?php _e('FTP Connection Information') ?></h2>
  45. <p><?php _e('To perform the requested update, FTP connection information is required.') ?></p>
  46. <table class="form-table">
  47. <tr valign="top">
  48. <th scope="row"><label for="hostname"><?php _e('Hostname:') ?></label></th>
  49. <td><input name="hostname" type="text" id="hostname" value="<?php echo attribute_escape($hostname) ?>"<?php if( defined('FTP_HOST') ) echo ' disabled="disabled"' ?> size="40" /></td>
  50. </tr>
  51. <tr valign="top">
  52. <th scope="row"><label for="username"><?php _e('Username:') ?></label></th>
  53. <td><input name="username" type="text" id="username" value="<?php echo attribute_escape($username) ?>"<?php if( defined('FTP_USER') ) echo ' disabled="disabled"' ?> size="40" /></td>
  54. </tr>
  55. <tr valign="top">
  56. <th scope="row"><label for="password"><?php _e('Password:') ?></label></th>
  57. <td><input name="password" type="password" id="password" value=""<?php if( defined('FTP_PASS') ) echo ' disabled="disabled"' ?> size="40" /><?php if( defined('FTP_PASS') && !empty($password) ) echo '<em>'.__('(Password not shown)').'</em>'; ?></td>
  58. </tr>
  59. <tr valign="top">
  60. <th scope="row"><label for="ssl"><?php _e('Use SSL:') ?></label></th>
  61. <td>
  62. <select name="ssl" id="ssl"<?php if( defined('FTP_SSL') ) echo ' disabled="disabled"' ?>>
  63. <?php
  64. foreach ( array(0 => __('No'), 1 => __('Yes')) as $key => $value ) :
  65.     $selected = ($ssl == $value) ? 'selected="selected"' : '';
  66.     echo "\n\t<option value='$key' $selected>" . $value . '</option>';
  67. endforeach;
  68. ?>
  69. </select>
  70. </td>
  71. </tr>
  72. </table>
  73. <p class="submit">
  74. <input type="submit" name="submit" value="<?php _e('Proceed'); ?>" />
  75. </p>
  76. </div>
  77. </form>
  78. <?php
  79.     return false;
  80. }
  81.  
  82. function show_message($message) {
  83.     if( is_wp_error($message) ){
  84.         if( $message->get_error_data() )
  85.             $message = $message->get_error_message() . ': ' . $message->get_error_data();
  86.         else 
  87.             $message = $message->get_error_message();
  88.     }
  89.     echo "<p>$message</p>\n";
  90. }
  91.  
  92. function do_plugin_upgrade($plugin) {
  93.     global $wp_filesystem;
  94.  
  95.     $url = wp_nonce_url("update.php?action=upgrade-plugin&plugin=$plugin", "upgrade-plugin_$plugin");
  96.     if ( false === ($credentials = request_filesystem_credentials($url)) )
  97.         return;
  98.  
  99.     if ( ! WP_Filesystem($credentials) ) {
  100.         request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again
  101.         return;
  102.     }
  103.  
  104.     echo '<div class="wrap">';
  105.     echo '<h2>' . __('Upgrade Plugin') . '</h2>';
  106.     if ( $wp_filesystem->errors->get_error_code() ) {
  107.         foreach ( $wp_filesystem->errors->get_error_messages() as $message )
  108.             show_message($message);
  109.         echo '</div>';
  110.         return;
  111.     }
  112.  
  113.     $was_activated = is_plugin_active($plugin); //Check now, It'll be deactivated by the next line if it is
  114.  
  115.     $result = wp_update_plugin($plugin, 'show_message');
  116.  
  117.     if ( is_wp_error($result) ) {
  118.         show_message($result);
  119.         show_message( __('Installation Failed') );
  120.     } else {
  121.         //Result is the new plugin file relative to WP_PLUGIN_DIR
  122.         show_message( __('Plugin upgraded successfully') );    
  123.         if( $result && $was_activated ){
  124.             show_message(__('Attempting reactivation of the plugin'));
  125.             echo '<iframe style="border:0" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&plugin=' . $result, 'activate-plugin_' . $result) .'"></iframe>';
  126.         }
  127.     }
  128.     echo '</div>';
  129. }
  130.  
  131. if ( isset($_GET['action']) ) {
  132.     $plugin = isset($_GET['plugin']) ? trim($_GET['plugin']) : '';
  133.  
  134.     if ( 'upgrade-plugin' == $_GET['action'] ) {
  135.         check_admin_referer('upgrade-plugin_' . $plugin);
  136.         $title = __('Upgrade Plugin');
  137.         $parent_file = 'plugins.php';
  138.         require_once('admin-header.php');
  139.         do_plugin_upgrade($plugin);
  140.         include('admin-footer.php');
  141.     } elseif ('activate-plugin' == $_GET['action'] ) {
  142.         check_admin_referer('activate-plugin_' . $plugin);
  143.         if( ! isset($_GET['failure']) && ! isset($_GET['success']) ) {
  144.             wp_redirect( 'update.php?action=activate-plugin&failure=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce'] ); 
  145.             activate_plugin($plugin);
  146.             wp_redirect( 'update.php?action=activate-plugin&success=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce'] ); 
  147.             die();
  148.         }
  149.             ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  150. <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
  151. <head>
  152. <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
  153. <title><?php bloginfo('name') ?> › <?php _e('Plugin Reactivation'); ?> — <?php _e('WordPress'); ?></title>
  154. <?php
  155. wp_admin_css( 'global', true );
  156. wp_admin_css( 'colors', true );
  157. ?>
  158. </head>
  159. <body>
  160. <?php
  161.         if( isset($_GET['success']) )
  162.             echo '<p>' . __('Plugin reactivated successfully.') . '</p>';
  163.  
  164.         if( isset($_GET['failure']) ){
  165.             echo '<p>' . __('Plugin failed to reactivate due to a fatal error.') . '</p>';
  166.             error_reporting( E_ALL ^ E_NOTICE );
  167.             @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
  168.             include(WP_PLUGIN_DIR . '/' . $plugin);
  169.         }
  170.         echo "</body></html>";
  171.     }
  172. }
  173.  
  174. ?>
  175.