]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/plugins.php
Wordpress 2.7.1
[autoinstalls/wordpress.git] / wp-admin / plugins.php
index 46d2b6115e6a4629fc6481299074ee3a28e97b1f..ab7049198ec58fb1e607f6765477b7a18afcbe75 100644 (file)
@@ -1,4 +1,12 @@
 <?php
+/**
+ * Plugins administration panel.
+ *
+ * @package WordPress
+ * @subpackage Administration
+ */
+
+/** WordPress Administration Bootstrap */
 require_once('admin.php');
 
 $action = '';
@@ -9,10 +17,10 @@ foreach( array('activate-selected', 'deactivate-selected', 'delete-selected', 'c
        }
 }
 
-if( isset($_GET['action']) )
-       $action = $_GET['action'];
+if( isset($_REQUEST['action']) && !empty($_REQUEST['action']) )
+       $action = $_REQUEST['action'];
 
-$plugin = $_REQUEST['plugin'];
+$plugin = isset($_REQUEST['plugin']) ? $_REQUEST['plugin'] : '';
 
 if( !empty($action) ) {
        switch( $action ) {
@@ -20,9 +28,9 @@ if( !empty($action) ) {
                        check_admin_referer('activate-plugin_' . $plugin);
                        $result = activate_plugin($plugin, 'plugins.php?error=true&plugin=' . $plugin);
                        if ( is_wp_error( $result ) )
-                               wp_die( $result->get_error_message() );
+                               wp_die($result);
                        $recent = (array)get_option('recently_activated');
-                       if( isset($recent[ $plugin ]) ){
+                       if ( isset($recent[ $plugin ]) ) {
                                unset($recent[ $plugin ]);
                                update_option('recently_activated', $recent);
                        }
@@ -35,7 +43,7 @@ if( !empty($action) ) {
 
                        $recent = (array)get_option('recently_activated');
                        foreach( (array)$_POST['checked'] as $plugin => $time) {
-                               if( isset($recent[ $plugin ]) )
+                               if ( isset($recent[ $plugin ]) )
                                        unset($recent[ $plugin ]);
                        }
                        if( $recent != get_option('recently_activated') ) //If array changed, update it.
@@ -52,6 +60,7 @@ if( !empty($action) ) {
                        error_reporting( E_ALL ^ E_NOTICE );
                        @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
                        include(WP_PLUGIN_DIR . '/' . $plugin);
+                       do_action('activate_' . $plugin);
                        exit;
                        break;
                case 'deactivate':
@@ -65,34 +74,34 @@ if( !empty($action) ) {
                        check_admin_referer('bulk-manage-plugins');
                        deactivate_plugins($_POST['checked']);
                        $deactivated = array();
-                       foreach( (array)$_POST['checked'] as $plugin )
+                       foreach ( (array)$_POST['checked'] as $plugin )
                                $deactivated[ $plugin ] = time();
                        update_option('recently_activated', $deactivated + (array)get_option('recently_activated'));
                        wp_redirect('plugins.php?deactivate-multi=true');
                        exit;
                        break;
                case 'delete-selected':
-                       if( ! current_user_can('delete_plugins') )
+                       if ( ! current_user_can('delete_plugins') )
                                wp_die(__('You do not have sufficient permissions to delete plugins for this blog.'));
-                       
+
                        check_admin_referer('bulk-manage-plugins');
-                       
+
                        $plugins = $_REQUEST['checked']; //$_POST = from the plugin form; $_GET = from the FTP details screen.
                        include(ABSPATH . 'wp-admin/update.php');
 
                        $title = __('Delete Plugin');
                        $parent_file = 'plugins.php';
-                       
-                       if( ! isset($_REQUEST['verify-delete']) ) {
+
+                       if ( ! isset($_REQUEST['verify-delete']) ) {
                                wp_enqueue_script('jquery');
                                require_once('admin-header.php');
                                ?>
                        <div class="wrap">
-                               <h2><?php _e('Delete Plugin(s)'); ?></h2>               
+                               <h2><?php _e('Delete Plugin(s)'); ?></h2>
                                <?php
                                        $files_to_delete = $plugin_info = array();
-                                       foreach( (array) $plugins as $plugin ) {
-                                               if( '.' == dirname($plugin) ) {
+                                       foreach ( (array) $plugins as $plugin ) {
+                                               if ( '.' == dirname($plugin) ) {
                                                        $files_to_delete[] = WP_PLUGIN_DIR . '/' . $plugin;
                                                        if( $data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin) )
                                                                $plugin_info[ $plugin ] = $data;
@@ -109,23 +118,19 @@ if( !empty($action) ) {
                                        }
                                ?>
                                <p><?php _e('Deleting the selected plugins will remove the following plugin(s) and their files:'); ?></p>
-                               <p>
                                        <ul>
-                                               <?php 
-                                               foreach( $plugin_info as $plugin )
-                                                       echo '<li>', $plugin['Title'], ' ', __('By'), ' ', $plugin['Author'], '</li>';
+                                               <?php
+                                               foreach ( $plugin_info as $plugin )
+                                                       echo '<li>', sprintf(__('%s by %s'), $plugin['Name'], $plugin['Author']), '</li>';
                                                ?>
                                        </ul>
-                               </p>
                                <p><?php _e('Are you sure you wish to delete these files?') ?></p>
                                <form method="post" action="<?php echo clean_url($_SERVER['REQUEST_URI']); ?>" style="display:inline;">
                                        <input type="hidden" name="verify-delete" value="1" />
                                        <input type="hidden" name="delete-selected" value="1" />
                                        <?php
-                                               foreach( (array)$plugins as $plugin ) {
-                                                       $plugin = attribute_escape($plugin);
-                                                       echo "<input type='hidden' name='checked[]' value='$plugin' />";
-                                               }
+                                               foreach ( (array)$plugins as $plugin )
+                                                       echo '<input type="hidden" name="checked[]" value="' . attribute_escape($plugin) . '" />';
                                        ?>
                                        <?php wp_nonce_field('bulk-manage-plugins') ?>
                                        <input type="submit" name="submit" value="<?php _e('Yes, Delete these files') ?>" class="button" />
@@ -138,13 +143,11 @@ if( !empty($action) ) {
                                <div id="files-list" style="display:none;">
                                        <ul>
                                        <?php
-                                               foreach( (array)$files_to_delete as $file ) {
-                                                       $file = str_replace(ABSPATH, '', $file);
-                                                       echo "<li>$file</li>";
-                                               }
+                                               foreach ( (array)$files_to_delete as $file )
+                                                       echo '<li>' . str_replace(WP_PLUGIN_DIR, '', $file) . '</li>';
                                        ?>
                                        </ul>
-                               </div>                          
+                               </div>
                        </div>
                                <?php
                                require_once('admin-footer.php');
@@ -160,14 +163,15 @@ if( !empty($action) ) {
        }
 }
 
-wp_enqueue_script('admin-forms');
+wp_enqueue_script('plugin-install');
+add_thickbox();
 
 $title = __('Manage Plugins');
 require_once('admin-header.php');
 
 $invalid = validate_active_plugins();
-if( !empty($invalid) )
-       foreach($invalid as $plugin_file => $error)
+if ( !empty($invalid) )
+       foreach ( $invalid as $plugin_file => $error )
                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>';
 ?>
 
@@ -197,7 +201,9 @@ if( !empty($invalid) )
 <?php endif; ?>
 
 <div class="wrap">
-<h2><?php _e('Plugin Management'); ?></h2>
+<?php screen_icon(); ?>
+       <h2><?php echo wp_specialchars( $title ); ?></h2>
+
 <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>
 <?php
 
@@ -205,26 +211,19 @@ $all_plugins = get_plugins();
 $active_plugins = array();
 $inactive_plugins = array();
 $recent_plugins = array();
-$recently_activated = (array)get_option('recently_activated');
+$recently_activated = (array) get_option('recently_activated');
 
 //Clean out any plugins which were deactivated over a week ago.
-foreach( $recently_activated as $key => $time )
-       if( $time + (7*24*60*60) < time() ) //1 week
+foreach ( $recently_activated as $key => $time )
+       if ( $time + (7*24*60*60) < time() ) //1 week
                unset($recently_activated[ $key ]);
-if( $recently_activated != get_option('recently_activated') ) //If array changed, update it.
+if ( $recently_activated != get_option('recently_activated') ) //If array changed, update it.
        update_option('recently_activated', $recently_activated);
 
-$plugins_allowedtags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array());
+foreach ( (array)$all_plugins as $plugin_file => $plugin_data) {
 
-foreach( (array)$all_plugins as $plugin_file => $plugin_data) {
-
-       // Sanitize all displayed data
-       $plugin_data['Title']       = wp_kses($plugin_data['Title'], $plugins_allowedtags);
-       $plugin_data['Version']     = wp_kses($plugin_data['Version'], $plugins_allowedtags);
-       $plugin_data['Description'] = wp_kses($plugin_data['Description'], $plugins_allowedtags);
-       $plugin_data['Author']      = wp_kses($plugin_data['Author'], $plugins_allowedtags);
-       if( ! empty($plugin_data['Author']) )
-               $plugin_data['Description'] .= ' <cite>' . sprintf( __('By %s'), $plugin_data['Author'] ) . '.</cite>';
+       //Translate, Apply Markup, Sanitize HTML
+       $plugin_data = _get_plugin_data_markup_translate($plugin_data, true, true);
 
        //Filter into individual sections
        if ( is_plugin_active($plugin_file) ) {
@@ -240,9 +239,15 @@ foreach( (array)$all_plugins as $plugin_file => $plugin_data) {
 ?>
 
 <?php
+/**
+ * @ignore
+ *
+ * @param array $plugins
+ * @param string $context
+ */
 function print_plugins_table($plugins, $context = '') {
 ?>
-<table class="widefat" id="<?php echo $context ?>-plugins-table">
+<table class="widefat" cellspacing="0" id="<?php echo $context ?>-plugins-table">
        <thead>
        <tr>
                <th scope="col" class="check-column"><input type="checkbox" /></th>
@@ -252,26 +257,38 @@ function print_plugins_table($plugins, $context = '') {
                <th scope="col" class="action-links"><?php _e('Action'); ?></th>
        </tr>
        </thead>
+
+       <tfoot>
+       <tr>
+               <th scope="col" class="check-column"><input type="checkbox" /></th>
+               <th scope="col"><?php _e('Plugin'); ?></th>
+               <th scope="col" class="num"><?php _e('Version'); ?></th>
+               <th scope="col"><?php _e('Description'); ?></th>
+               <th scope="col" class="action-links"><?php _e('Action'); ?></th>
+       </tr>
+       </tfoot>
+
        <tbody class="plugins">
 <?php
 
-       if( empty($plugins) ) {
+       if ( empty($plugins) ) {
                echo '<tr>
                        <td colspan="6">' . __('No plugins to show') . '</td>
                </tr>';
        }
-       foreach( (array)$plugins as $plugin_file => $plugin_data) {
+       foreach ( (array)$plugins as $plugin_file => $plugin_data) {
                $action_links = array();
 
-               if( 'active' == $context )
-                       $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>';
-               else //Available or Recently deactivated
+               if ( 'active' == $context )
+                       $action_links[] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;plugin=' . $plugin_file, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Deactivate') . '</a>';
+               else //Inactive or Recently deactivated
                        $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>';
 
                if ( current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) )
                        $action_links[] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . __('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>';
 
-               $action_links = apply_filters('plugin_action_links', $action_links, $plugin_file, $plugin_data, $context);
+               $action_links = apply_filters( 'plugin_action_links', $action_links, $plugin_file, $plugin_data, $context );
+               $action_links = apply_filters( "plugin_action_links_$plugin_file", $action_links, $plugin_file, $plugin_data, $context );
 
                echo "
        <tr class='$context'>
@@ -279,18 +296,47 @@ function print_plugins_table($plugins, $context = '') {
                <td class='name'>{$plugin_data['Title']}</td>
                <td class='vers'>{$plugin_data['Version']}</td>
                <td class='desc'><p>{$plugin_data['Description']}</p></td>
-               <td class='togl action-links'>";  
+               <td class='togl action-links'>";
                if ( !empty($action_links) )
                        echo implode(' | ', $action_links);
-               echo '</td> 
+               echo '</td>
        </tr>';
                do_action( 'after_plugin_row', $plugin_file, $plugin_data, $context );
+               do_action( "after_plugin_row_$plugin_file", $plugin_file, $plugin_data, $context );
        }
 ?>
        </tbody>
 </table>
-<?php 
+<?php
 } //End print_plugins_table()
+
+/**
+ * @ignore
+ *
+ * @param string $context
+ */
+function print_plugin_actions($context) {
+?>
+       <div class="alignleft actions">
+               <select name="action">
+                       <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
+       <?php if( 'active' != $context ) : ?>
+                       <option value="activate-selected"><?php _e('Activate'); ?></option>
+       <?php endif; ?>
+       <?php if ( 'active' == $context ) : ?>
+                       <option value="deactivate-selected"><?php _e('Deactivate'); ?></option>
+       <?php endif; ?>
+       <?php if( current_user_can('delete_plugins') && ( 'recent' == $context || 'inactive' == $context ) ) : ?>
+                       <option value="delete-selected"><?php _e('Delete'); ?></option>
+       <?php endif; ?>
+               </select>
+               <input type="submit" name="doaction_active" value="<?php _e('Apply'); ?>" class="button-secondary action" />
+       <?php if( 'recent' == $context ) : ?>
+               <input type="submit" name="clear-recent-list" value="<?php _e('Clear List') ?>" class="button-secondary" />
+       <?php endif; ?>
+       </div>
+<?php
+}
 ?>
 
 <?php if ( ! empty($active_plugins) ) : ?>
@@ -299,11 +345,9 @@ function print_plugins_table($plugins, $context = '') {
 <?php wp_nonce_field('bulk-manage-plugins') ?>
 
 <div class="tablenav">
-       <div class="alignleft">
-               <input type="submit" name="deactivate-selected" value="<?php _e('Deactivate') ?>" class="button-secondary" />
-       </div>
+<?php print_plugin_actions('active') ?>
 </div>
-<br class="clear" />
+<div class="clear"></div>
 <?php print_plugins_table($active_plugins, 'active') ?>
 </form>
 
@@ -317,15 +361,9 @@ function print_plugins_table($plugins, $context = '') {
 <?php wp_nonce_field('bulk-manage-plugins') ?>
 
 <div class="tablenav">
-       <div class="alignleft">
-               <input type="submit" name="activate-selected" value="<?php _e('Activate') ?>" class="button-secondary" />
-<?php if( current_user_can('delete_plugins') ) : ?>
-               <input type="submit" name="delete-selected" value="<?php _e('Delete') ?>" class="button-secondary" />
-<?php endif; ?>
-               <input type="submit" name="clear-recent-list" value="<?php _e('Clear List') ?>" class="button-secondary" />
-       </div>
+<?php print_plugin_actions('recent') ?>
 </div>
-<br class="clear" />
+<div class="clear"></div>
 <?php print_plugins_table($recent_plugins, 'recent') ?>
 </form>
 <?php endif; ?>
@@ -336,14 +374,9 @@ function print_plugins_table($plugins, $context = '') {
 <?php wp_nonce_field('bulk-manage-plugins') ?>
 
 <div class="tablenav">
-       <div class="alignleft">
-               <input type="submit" name="activate-selected" value="<?php _e('Activate') ?>" class="button-secondary" />
-<?php if( current_user_can('delete_plugins') ) : ?>
-               <input type="submit" name="delete-selected" value="<?php _e('Delete') ?>" class="button-secondary" />
-<?php endif; ?>
-       </div>
+<?php print_plugin_actions('inactive') ?>
 </div>
-<br class="clear" />
+<div class="clear"></div>
 <?php print_plugins_table($inactive_plugins, 'inactive') ?>
 </form>
 <?php endif; ?>
@@ -353,8 +386,9 @@ function print_plugins_table($plugins, $context = '') {
 <?php endif; ?>
 
 <h2><?php _e('Get More Plugins'); ?></h2>
-<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>
-<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>
+<p><?php _e('You can find additional plugins for your site by using the new <a href="plugin-install.php">Plugin Browser/Installer</a> functionality, Or by browsing the <a href="http://wordpress.org/extend/plugins/">WordPress Plugin Directory</a> directly and installing manually.'); ?></p>
+<p><?php printf(__('To <em>manually</em> install a plugin you generally just need to upload the plugin file into your <code>%s</code> directory.'), WP_PLUGIN_DIR); ?></p>
+<p><?php _e('Once a plugin has been installed, you may activate it here.'); ?></p>
 
 </div>