]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/plugins.php
Wordpress 2.3.2
[autoinstalls/wordpress.git] / wp-admin / plugins.php
1 <?php
2 require_once('admin.php');
3
4 if ( isset($_GET['action']) ) {
5         if ('activate' == $_GET['action']) {
6                 check_admin_referer('activate-plugin_' . $_GET['plugin']);
7                 $current = get_option('active_plugins');
8                 $plugin = trim($_GET['plugin']);
9                 if ( validate_file($plugin) )
10                         wp_die(__('Invalid plugin.'));
11                 if ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) )
12                         wp_die(__('Plugin file does not exist.'));
13                 if (!in_array($plugin, $current)) {
14                         wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), 'plugins.php?error=true&plugin=' . $plugin)); // we'll override this later if the plugin can be included without fatal error
15                         ob_start();
16                         @include(ABSPATH . PLUGINDIR . '/' . $plugin);
17                         $current[] = $plugin;
18                         sort($current);
19                         update_option('active_plugins', $current);
20                         do_action('activate_' . $plugin);
21                         ob_end_clean();
22                 }
23                 wp_redirect('plugins.php?activate=true'); // overrides the ?error=true one above
24         } elseif ('error_scrape' == $_GET['action']) {
25                 $plugin = trim($_GET['plugin']);
26                 check_admin_referer('plugin-activation-error_' . $plugin);
27                 if ( validate_file($plugin) )
28                         wp_die(__('Invalid plugin.'));
29                 if ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) )
30                         wp_die(__('Plugin file does not exist.'));
31                 include(ABSPATH . PLUGINDIR . '/' . $plugin);
32         } elseif ('deactivate' == $_GET['action']) {
33                 check_admin_referer('deactivate-plugin_' . $_GET['plugin']);
34                 $current = get_option('active_plugins');
35                 array_splice($current, array_search( $_GET['plugin'], $current), 1 ); // Array-fu!
36                 update_option('active_plugins', $current);
37                 do_action('deactivate_' . trim( $_GET['plugin'] ));
38                 wp_redirect('plugins.php?deactivate=true');
39         } elseif ($_GET['action'] == 'deactivate-all') {
40                 check_admin_referer('deactivate-all');
41                 $current = get_option('active_plugins');
42
43                 foreach ($current as $plugin) {
44                         array_splice($current, array_search($plugin, $current), 1);
45                         do_action('deactivate_' . $plugin);
46                 }
47
48                 update_option('active_plugins', array());
49                 wp_redirect('plugins.php?deactivate-all=true');
50         }
51         exit;
52 }
53
54 $title = __('Manage Plugins');
55 require_once('admin-header.php');
56
57 // Clean up options
58 // If any plugins don't exist, axe 'em
59
60 $check_plugins = get_option('active_plugins');
61
62 // Sanity check.  If the active plugin list is not an array, make it an
63 // empty array.
64 if ( !is_array($check_plugins) ) {
65         $check_plugins = array();
66         update_option('active_plugins', $check_plugins);
67 }
68
69 // If a plugin file does not exist, remove it from the list of active
70 // plugins.
71 foreach ($check_plugins as $check_plugin) {
72         if (!file_exists(ABSPATH . PLUGINDIR . '/' . $check_plugin)) {
73                         $current = get_option('active_plugins');
74                         $key = array_search($check_plugin, $current);
75                         if ( false !== $key && NULL !== $key ) {
76                                 unset($current[$key]);
77                                 update_option('active_plugins', $current);
78                         }
79         }
80 }
81 ?>
82
83 <?php if ( isset($_GET['error']) ) : ?>
84         <div id="message" class="updated fade"><p><?php _e('Plugin could not be activated because it triggered a <strong>fatal error</strong>.') ?></p>
85         <?php
86                 $plugin = trim($_GET['plugin']);
87                 if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $plugin) && 1 == strtolower(ini_get('display_errors'))) { ?>
88         <iframe style="border:0" width="100%" height="70px" src="<?php bloginfo('wpurl'); ?>/wp-admin/plugins.php?action=error_scrape&amp;plugin=<?php echo attribute_escape($plugin); ?>&amp;_wpnonce=<?php echo attribute_escape($_GET['_error_nonce']); ?>"></iframe>
89         <?php
90                 }
91         ?>
92         </div>
93 <?php elseif ( isset($_GET['activate']) ) : ?>
94         <div id="message" class="updated fade"><p><?php _e('Plugin <strong>activated</strong>.') ?></p></div>
95 <?php elseif ( isset($_GET['deactivate']) ) : ?>
96         <div id="message" class="updated fade"><p><?php _e('Plugin <strong>deactivated</strong>.') ?></p></div>
97 <?php elseif (isset($_GET['deactivate-all'])) : ?>
98         <div id="message" class="updated fade"><p><?php _e('All plugins <strong>deactivated</strong>.'); ?></p></div>
99 <?php endif; ?>
100
101 <div class="wrap">
102 <h2><?php _e('Plugin Management'); ?></h2>
103 <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>
104 <?php
105
106 if ( get_option('active_plugins') )
107         $current_plugins = get_option('active_plugins');
108
109 $plugins = get_plugins();
110
111 if (empty($plugins)) {
112         echo '<p>';
113         _e("Couldn&#8217;t open plugins directory or there are no plugins available."); // TODO: make more helpful
114         echo '</p>';
115 } else {
116 ?>
117 <table class="widefat plugins">
118         <thead>
119         <tr>
120                 <th><?php _e('Plugin'); ?></th>
121                 <th style="text-align: center"><?php _e('Version'); ?></th>
122                 <th><?php _e('Description'); ?></th>
123                 <th style="text-align: center"<?php if ( current_user_can('edit_plugins') ) echo ' colspan="2"'; ?>><?php _e('Action'); ?></th>
124         </tr>
125         </thead>
126 <?php
127         $style = '';
128
129         foreach($plugins as $plugin_file => $plugin_data) {
130                 $style = ('class="alternate"' == $style|| 'class="alternate active"' == $style) ? '' : 'alternate';
131
132                 if (!empty($current_plugins) && in_array($plugin_file, $current_plugins)) {
133                         $toggle = "<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>";
134                         $plugin_data['Title'] = "<strong>{$plugin_data['Title']}</strong>";
135                         $style .= $style == 'alternate' ? ' active' : 'active';
136                 } else {
137                         $toggle = "<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>";
138                 }
139
140                 $plugins_allowedtags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array());
141
142                 // Sanitize all displayed data
143                 $plugin_data['Title']       = wp_kses($plugin_data['Title'], $plugins_allowedtags);
144                 $plugin_data['Version']     = wp_kses($plugin_data['Version'], $plugins_allowedtags);
145                 $plugin_data['Description'] = wp_kses($plugin_data['Description'], $plugins_allowedtags);
146                 $plugin_data['Author']      = wp_kses($plugin_data['Author'], $plugins_allowedtags);
147
148                 if ( $style != '' )
149                         $style = 'class="' . $style . '"';
150                 if ( is_writable(ABSPATH . PLUGINDIR . '/' . $plugin_file) )
151                         $edit = "<a href='plugin-editor.php?file=$plugin_file' title='".__('Open this file in the Plugin Editor')."' class='edit'>".__('Edit')."</a>";
152                 else
153                         $edit = '';
154
155                 $author = ( empty($plugin_data['Author']) ) ? '' :  ' <cite>' . sprintf( __('By %s'), $plugin_data['Author'] ) . '.</cite>';
156
157                 echo "
158         <tr $style>
159                 <td class='name'>{$plugin_data['Title']}</td>
160                 <td class='vers'>{$plugin_data['Version']}</td>
161                 <td class='desc'><p>{$plugin_data['Description']}$author</p></td>
162                 <td class='togl'>$toggle</td>";
163                 if ( current_user_can('edit_plugins') )
164                 echo "
165                 <td>$edit</td>";
166                 echo"
167         </tr>";
168         do_action( 'after_plugin_row', $plugin_file );
169         }
170 ?>
171
172 <tr>
173         <td colspan="3">&nbsp;</td>
174         <td colspan="2" style="width:12em;"><a href="<?php echo wp_nonce_url('plugins.php?action=deactivate-all', 'deactivate-all'); ?>" class="delete"><?php _e('Deactivate All Plugins'); ?></a></td>
175 </tr>
176
177 </table>
178 <?php
179 }
180 ?>
181
182 <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.'), PLUGINDIR); ?></p>
183
184 <h2><?php _e('Get More Plugins'); ?></h2>
185 <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>
186 <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.'), PLUGINDIR); ?></p>
187
188 </div>
189
190 <?php
191 include('admin-footer.php');
192 ?>