]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/update.php
Wordpress 2.5.1
[autoinstalls/wordpress.git] / wp-admin / update.php
1 <?php
2
3 require_once('admin.php');
4
5 if ( !current_user_can('edit_plugins') )
6                 wp_die('<p>'.__('You do not have sufficient permissions to update plugins for this blog.').'</p>');
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  : (!empty($_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"><?php _e('Hostname:') ?></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"><?php _e('Username:') ?></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"><?php _e('Password:') ?></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"><?php _e('Use SSL:') ?></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         } else {
120                 //Result is the new plugin file relative to PLUGINDIR
121                 show_message(__('Plugin upgraded successfully'));       
122                 if( $result && $was_activated ){
123                         show_message(__('Attempting reactivation of the plugin'));
124                         echo '<iframe style="border:0" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&plugin=' . $result, 'activate-plugin_' . $result) .'"></iframe>';
125                 }
126         }
127         echo '</div>';
128 }
129
130 if ( isset($_GET['action']) ) {
131         $plugin = isset($_GET['plugin']) ? trim($_GET['plugin']) : '';
132
133         if ( 'upgrade-plugin' == $_GET['action'] ) {
134                 check_admin_referer('upgrade-plugin_' . $plugin);
135                 $title = __('Upgrade Plugin');
136                 $parent_file = 'plugins.php';
137                 require_once('admin-header.php');
138                 do_plugin_upgrade($plugin);
139                 include('admin-footer.php');
140         } elseif ('activate-plugin' == $_GET['action'] ) {
141                 check_admin_referer('activate-plugin_' . $plugin);
142                 if( ! isset($_GET['failure']) && ! isset($_GET['success']) ) {
143                         wp_redirect( 'update.php?action=activate-plugin&failure=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce'] ); 
144                         activate_plugin($plugin);
145                         wp_redirect( 'update.php?action=activate-plugin&success=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce'] ); 
146                         die();
147                 }
148                         ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
149 <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
150 <head>
151 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
152 <title><?php bloginfo('name') ?> &rsaquo; <?php _e('Plugin Reactivation'); ?> &#8212; <?php _e('WordPress'); ?></title>
153 <?php
154 wp_admin_css( 'css/global' );
155 wp_admin_css( 'css/colors' );
156 ?>
157 </head>
158 <body>
159 <?php
160                 if( isset($_GET['success']) )
161                         echo '<p>' . __('Plugin reactivated successfully.') . '</p>';
162
163                 if( isset($_GET['failure']) ){
164                         echo '<p>' . __('Plugin failed to reactivate due to a fatal error.') . '</p>';
165                         error_reporting( E_ALL ^ E_NOTICE );
166                         @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
167                         include(ABSPATH . PLUGINDIR . '/' . $plugin);
168                 }
169                 echo "</body></html>";
170         }
171 }
172
173 ?>