Wordpress 2.6.2
[autoinstalls/wordpress.git] / wp-admin / plugins.php
1 <?php
2 require_once('admin.php');
3
4 $action = '';
5 foreach( array('activate-selected', 'deactivate-selected', 'delete-selected', 'clear-recent-list') as $action_key ) {
6         if( isset($_POST[$action_key]) ) {
7                 $action = $action_key;
8                 break;
9         }
10 }
11
12 if( isset($_GET['action']) )
13         $action = $_GET['action'];
14
15 $plugin = $_REQUEST['plugin'];
16
17 if( !empty($action) ) {
18         switch( $action ) {
19                 case 'activate':
20                         check_admin_referer('activate-plugin_' . $plugin);
21                         $result = activate_plugin($plugin, 'plugins.php?error=true&plugin=' . $plugin);
22                         if ( is_wp_error( $result ) )
23                                 wp_die( $result->get_error_message() );
24                         $recent = (array)get_option('recently_activated');
25                         if( isset($recent[ $plugin ]) ){
26                                 unset($recent[ $plugin ]);
27                                 update_option('recently_activated', $recent);
28                         }
29                         wp_redirect('plugins.php?activate=true'); // overrides the ?error=true one above
30                         exit;
31                         break;
32                 case 'activate-selected':
33                         check_admin_referer('bulk-manage-plugins');
34                         activate_plugins($_POST['checked'], 'plugins.php?error=true');
35
36                         $recent = (array)get_option('recently_activated');
37                         foreach( (array)$_POST['checked'] as $plugin => $time) {
38                                 if( isset($recent[ $plugin ]) )
39                                         unset($recent[ $plugin ]);
40                         }
41                         if( $recent != get_option('recently_activated') ) //If array changed, update it.
42                                 update_option('recently_activated', $recent);
43
44                         wp_redirect('plugins.php?activate-multi=true');
45                         exit;
46                         break;
47                 case 'error_scrape':
48                         check_admin_referer('plugin-activation-error_' . $plugin);
49                         $valid = validate_plugin($plugin);
50                         if ( is_wp_error($valid) )
51                                 wp_die($valid);
52                         error_reporting( E_ALL ^ E_NOTICE );
53                         @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
54                         include(WP_PLUGIN_DIR . '/' . $plugin);
55                         exit;
56                         break;
57                 case 'deactivate':
58                         check_admin_referer('deactivate-plugin_' . $plugin);
59                         deactivate_plugins($plugin);
60                         update_option('recently_activated', array($plugin => time()) + (array)get_option('recently_activated'));
61                         wp_redirect('plugins.php?deactivate=true');
62                         exit;
63                         break;
64                 case 'deactivate-selected':
65                         check_admin_referer('bulk-manage-plugins');
66                         deactivate_plugins($_POST['checked']);
67                         $deactivated = array();
68                         foreach( (array)$_POST['checked'] as $plugin )
69                                 $deactivated[ $plugin ] = time();
70                         update_option('recently_activated', $deactivated + (array)get_option('recently_activated'));
71                         wp_redirect('plugins.php?deactivate-multi=true');
72                         exit;
73                         break;
74                 case 'delete-selected':
75                         if( ! current_user_can('delete_plugins') )
76                                 wp_die(__('You do not have sufficient permissions to delete plugins for this blog.'));
77                         
78                         check_admin_referer('bulk-manage-plugins');
79                         
80                         $plugins = $_REQUEST['checked']; //$_POST = from the plugin form; $_GET = from the FTP details screen.
81                         include(ABSPATH . 'wp-admin/update.php');
82
83                         $title = __('Delete Plugin');
84                         $parent_file = 'plugins.php';
85                         
86                         if( ! isset($_REQUEST['verify-delete']) ) {
87                                 wp_enqueue_script('jquery');
88                                 require_once('admin-header.php');
89                                 ?>
90                         <div class="wrap">
91                                 <h2><?php _e('Delete Plugin(s)'); ?></h2>               
92                                 <?php
93                                         $files_to_delete = $plugin_info = array();
94                                         foreach( (array) $plugins as $plugin ) {
95                                                 if( '.' == dirname($plugin) ) {
96                                                         $files_to_delete[] = WP_PLUGIN_DIR . '/' . $plugin;
97                                                         if( $data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin) )
98                                                                 $plugin_info[ $plugin ] = $data;
99                                                 } else {
100                                                         //Locate all the files in that folder:
101                                                         $files = list_files( WP_PLUGIN_DIR . '/' . dirname($plugin) );
102                                                         if( $files ) {
103                                                                 $files_to_delete = array_merge($files_to_delete, $files);
104                                                         }
105                                                         //Get plugins list from that folder
106                                                         if ( $folder_plugins = get_plugins( '/' . dirname($plugin)) )
107                                                                 $plugin_info = array_merge($plugin_info, $folder_plugins);
108                                                 }
109                                         }
110                                 ?>
111                                 <p><?php _e('Deleting the selected plugins will remove the following plugin(s) and their files:'); ?></p>
112                                 <p>
113                                         <ul>
114                                                 <?php 
115                                                 foreach( $plugin_info as $plugin )
116                                                         echo '<li>', $plugin['Title'], ' ', __('By'), ' ', $plugin['Author'], '</li>';
117                                                 ?>
118                                         </ul>
119                                 </p>
120                                 <p><?php _e('Are you sure you wish to delete these files?') ?></p>
121                                 <form method="post" action="<?php echo clean_url($_SERVER['REQUEST_URI']); ?>" style="display:inline;">
122                                         <input type="hidden" name="verify-delete" value="1" />
123                                         <input type="hidden" name="delete-selected" value="1" />
124                                         <?php
125                                                 foreach( (array)$plugins as $plugin ) {
126                                                         $plugin = attribute_escape($plugin);
127                                                         echo "<input type='hidden' name='checked[]' value='$plugin' />";
128                                                 }
129                                         ?>
130                                         <?php wp_nonce_field('bulk-manage-plugins') ?>
131                                         <input type="submit" name="submit" value="<?php _e('Yes, Delete these files') ?>" class="button" />
132                                 </form>
133                                 <form method="post" action="<?php echo clean_url(wp_get_referer()); ?>" style="display:inline;">
134                                         <input type="submit" name="submit" value="<?php _e('No, Return me to the plugin list') ?>" class="button" />
135                                 </form>
136
137                                 <p><a href="#" onclick="jQuery('#files-list').toggle(); return false;"><?php _e('Click to view entire list of files which will be deleted'); ?></a></p>
138                                 <div id="files-list" style="display:none;">
139                                         <ul>
140                                         <?php
141                                                 foreach( (array)$files_to_delete as $file ) {
142                                                         $file = str_replace(ABSPATH, '', $file);
143                                                         echo "<li>$file</li>";
144                                                 }
145                                         ?>
146                                         </ul>
147                                 </div>                          
148                         </div>
149                                 <?php
150                                 require_once('admin-footer.php');
151                                 exit;
152                         } //Endif verify-delete
153                         $delete_result = delete_plugins($plugins);
154
155                         wp_cache_delete('plugins', 'plugins');
156                         break;
157                 case 'clear-recent-list':
158                         update_option('recently_activated', array());
159                         break;
160         }
161 }
162
163 wp_enqueue_script('admin-forms');
164
165 $title = __('Manage Plugins');
166 require_once('admin-header.php');
167
168 $invalid = validate_active_plugins();
169 if( !empty($invalid) )
170         foreach($invalid as $plugin_file => $error)
171                 echo '<div id="message" class="error"><p>' . sprintf(__('The plugin <code>%s</code> has been <strong>deactivated</strong> due to an error: %s'), wp_specialchars($plugin_file), $error->get_error_message()) . '</p></div>';
172 ?>
173
174 <?php if ( isset($_GET['error']) ) : ?>
175         <div id="message" class="updated fade"><p><?php _e('Plugin could not be activated because it triggered a <strong>fatal error</strong>.') ?></p>
176         <?php
177                 if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $plugin) ) { ?>
178         <iframe style="border:0" width="100%" height="70px" src="<?php echo admin_url('plugins.php?action=error_scrape&amp;plugin=' . attribute_escape($plugin) . '&amp;_wpnonce=' . attribute_escape($_GET['_error_nonce'])); ?>"></iframe>
179         <?php
180                 }
181         ?>
182         </div>
183 <?php elseif ( 'delete-selected' == $action ) :
184                 if ( is_wp_error($delete_result) ) : ?>
185                 <div id="message" class="updated fade"><p><?php printf( __('Plugin could not be deleted due to an error: %s'), $delete_result->get_error_message() ); ?></p></div>
186                 <?php else : ?>
187                 <div id="message" class="updated fade"><p><?php _e('The selected plugins have been <strong>deleted</strong>.'); ?></p></div>
188                 <?php endif; ?>
189 <?php elseif ( isset($_GET['activate']) ) : ?>
190         <div id="message" class="updated fade"><p><?php _e('Plugin <strong>activated</strong>.') ?></p></div>
191 <?php elseif (isset($_GET['activate-multi'])) : ?>
192         <div id="message" class="updated fade"><p><?php _e('Selected plugins <strong>activated</strong>.'); ?></p></div>
193 <?php elseif ( isset($_GET['deactivate']) ) : ?>
194         <div id="message" class="updated fade"><p><?php _e('Plugin <strong>deactivated</strong>.') ?></p></div>
195 <?php elseif (isset($_GET['deactivate-multi'])) : ?>
196         <div id="message" class="updated fade"><p><?php _e('Selected plugins <strong>deactivated</strong>.'); ?></p></div>
197 <?php endif; ?>
198
199 <div class="wrap">
200 <h2><?php _e('Plugin Management'); ?></h2>
201 <p><?php _e('Plugins extend and expand the functionality of WordPress. Once a plugin is installed, you may activate it or deactivate it here.'); ?></p>
202 <?php
203
204 $all_plugins = get_plugins();
205 $active_plugins = array();
206 $inactive_plugins = array();
207 $recent_plugins = array();
208 $recently_activated = (array)get_option('recently_activated');
209
210 //Clean out any plugins which were deactivated over a week ago.
211 foreach( $recently_activated as $key => $time )
212         if( $time + (7*24*60*60) < time() ) //1 week
213                 unset($recently_activated[ $key ]);
214 if( $recently_activated != get_option('recently_activated') ) //If array changed, update it.
215         update_option('recently_activated', $recently_activated);
216
217 $plugins_allowedtags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array());
218
219 foreach( (array)$all_plugins as $plugin_file => $plugin_data) {
220
221         // Sanitize all displayed data
222         $plugin_data['Title']       = wp_kses($plugin_data['Title'], $plugins_allowedtags);
223         $plugin_data['Version']     = wp_kses($plugin_data['Version'], $plugins_allowedtags);
224         $plugin_data['Description'] = wp_kses($plugin_data['Description'], $plugins_allowedtags);
225         $plugin_data['Author']      = wp_kses($plugin_data['Author'], $plugins_allowedtags);
226         if( ! empty($plugin_data['Author']) )
227                 $plugin_data['Description'] .= ' <cite>' . sprintf( __('By %s'), $plugin_data['Author'] ) . '.</cite>';
228
229         //Filter into individual sections
230         if ( is_plugin_active($plugin_file) ) {
231                 $active_plugins[ $plugin_file ] = $plugin_data;
232         } else {
233                 if ( isset( $recently_activated[ $plugin_file ] ) ) //Was the plugin recently activated?
234                         $recent_plugins[ $plugin_file ] = $plugin_data;
235                 else
236                         $inactive_plugins[ $plugin_file ] = $plugin_data;
237         }
238 }
239
240 ?>
241
242 <?php
243 function print_plugins_table($plugins, $context = '') {
244 ?>
245 <table class="widefat" id="<?php echo $context ?>-plugins-table">
246         <thead>
247         <tr>
248                 <th scope="col" class="check-column"><input type="checkbox" /></th>
249                 <th scope="col"><?php _e('Plugin'); ?></th>
250                 <th scope="col" class="num"><?php _e('Version'); ?></th>
251                 <th scope="col"><?php _e('Description'); ?></th>
252                 <th scope="col" class="action-links"><?php _e('Action'); ?></th>
253         </tr>
254         </thead>
255         <tbody class="plugins">
256 <?php
257
258         if( empty($plugins) ) {
259                 echo '<tr>
260                         <td colspan="6">' . __('No plugins to show') . '</td>
261                 </tr>';
262         }
263         foreach( (array)$plugins as $plugin_file => $plugin_data) {
264                 $action_links = array();
265
266                 if( 'active' == $context )
267                         $action_links[] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;plugin=' . $plugin_file, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '" class="delete">' . __('Deactivate') . '</a>';
268                 else //Available or Recently deactivated
269                         $action_links[] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin') . '" class="edit">' . __('Activate') . '</a>';
270
271                 if ( current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) )
272                         $action_links[] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . __('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>';
273
274                 $action_links = apply_filters('plugin_action_links', $action_links, $plugin_file, $plugin_data, $context);
275
276                 echo "
277         <tr class='$context'>
278                 <th scope='row' class='check-column'><input type='checkbox' name='checked[]' value='" . attribute_escape($plugin_file) . "' /></th>
279                 <td class='name'>{$plugin_data['Title']}</td>
280                 <td class='vers'>{$plugin_data['Version']}</td>
281                 <td class='desc'><p>{$plugin_data['Description']}</p></td>
282                 <td class='togl action-links'>";  
283                 if ( !empty($action_links) )
284                         echo implode(' | ', $action_links);
285                 echo '</td> 
286         </tr>';
287                 do_action( 'after_plugin_row', $plugin_file, $plugin_data, $context );
288         }
289 ?>
290         </tbody>
291 </table>
292 <?php 
293 } //End print_plugins_table()
294 ?>
295
296 <?php if ( ! empty($active_plugins) ) : ?>
297 <h3 id="currently-active"><?php _e('Currently Active Plugins') ?></h3>
298 <form method="post" action="<?php echo admin_url('plugins.php') ?>">
299 <?php wp_nonce_field('bulk-manage-plugins') ?>
300
301 <div class="tablenav">
302         <div class="alignleft">
303                 <input type="submit" name="deactivate-selected" value="<?php _e('Deactivate') ?>" class="button-secondary" />
304         </div>
305 </div>
306 <br class="clear" />
307 <?php print_plugins_table($active_plugins, 'active') ?>
308 </form>
309
310 <p><?php printf(__('If something goes wrong with a plugin and you can&#8217;t use WordPress, delete or rename that file in the <code>%s</code> directory and it will be automatically deactivated.'), WP_PLUGIN_DIR); ?></p>
311 <?php endif; ?>
312
313 <?php if ( ! empty($recent_plugins) ) : ?>
314 <h3 id="recent-plugins"><?php _e('Recently Active Plugins') ?></h3>
315 <p><?php _e('The following plugins were recently active. When a plugin has been inactive for more than 7 days it will be moved to the Inactive plugin list.') ?></p>
316 <form method="post" action="<?php echo admin_url('plugins.php') ?>">
317 <?php wp_nonce_field('bulk-manage-plugins') ?>
318
319 <div class="tablenav">
320         <div class="alignleft">
321                 <input type="submit" name="activate-selected" value="<?php _e('Activate') ?>" class="button-secondary" />
322 <?php if( current_user_can('delete_plugins') ) : ?>
323                 <input type="submit" name="delete-selected" value="<?php _e('Delete') ?>" class="button-secondary" />
324 <?php endif; ?>
325                 <input type="submit" name="clear-recent-list" value="<?php _e('Clear List') ?>" class="button-secondary" />
326         </div>
327 </div>
328 <br class="clear" />
329 <?php print_plugins_table($recent_plugins, 'recent') ?>
330 </form>
331 <?php endif; ?>
332
333 <?php if ( ! empty($inactive_plugins) ) : ?>
334 <h3 id="inactive-plugins"><?php _e('Inactive Plugins') ?></h3>
335 <form method="post" action="<?php echo admin_url('plugins.php') ?>">
336 <?php wp_nonce_field('bulk-manage-plugins') ?>
337
338 <div class="tablenav">
339         <div class="alignleft">
340                 <input type="submit" name="activate-selected" value="<?php _e('Activate') ?>" class="button-secondary" />
341 <?php if( current_user_can('delete_plugins') ) : ?>
342                 <input type="submit" name="delete-selected" value="<?php _e('Delete') ?>" class="button-secondary" />
343 <?php endif; ?>
344         </div>
345 </div>
346 <br class="clear" />
347 <?php print_plugins_table($inactive_plugins, 'inactive') ?>
348 </form>
349 <?php endif; ?>
350
351 <?php if ( empty($all_plugins) ) : ?>
352 <p><?php _e('You do not appear to have any plugins available at this time.') ?></p>
353 <?php endif; ?>
354
355 <h2><?php _e('Get More Plugins'); ?></h2>
356 <p><?php _e('You can find additional plugins for your site in the <a href="http://wordpress.org/extend/plugins/">WordPress plugin directory</a>.'); ?></p>
357 <p><?php printf(__('To install a plugin you generally just need to upload the plugin file into your <code>%s</code> directory. Once a plugin is uploaded, you may activate it here.'), WP_PLUGIN_DIR); ?></p>
358
359 </div>
360
361 <?php
362 include('admin-footer.php');
363 ?>