]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/plugin-install.php
Wordpress 2.8
[autoinstalls/wordpress.git] / wp-admin / includes / plugin-install.php
1 <?php
2 /**
3  * WordPress Plugin Install Administration API
4  *
5  * @package WordPress
6  * @subpackage Administration
7  */
8
9 /**
10  * Retrieve plugin installer pages from WordPress Plugins API.
11  *
12  * It is possible for a plugin to override the Plugin API result with three
13  * filters. Assume this is for plugins, which can extend on the Plugin Info to
14  * offer more choices. This is very powerful and must be used with care, when
15  * overridding the filters.
16  *
17  * The first filter, 'plugins_api_args', is for the args and gives the action as
18  * the second parameter. The hook for 'plugins_api_args' must ensure that an
19  * object is returned.
20  *
21  * The second filter, 'plugins_api', is the result that would be returned.
22  *
23  * @since 2.7.0
24  *
25  * @param string $action
26  * @param array|object $args Optional. Arguments to serialize for the Plugin Info API.
27  * @return mixed
28  */
29 function plugins_api($action, $args = null) {
30
31         if( is_array($args) )
32                 $args = (object)$args;
33
34         if ( !isset($args->per_page) )
35                 $args->per_page = 24;
36
37         $args = apply_filters('plugins_api_args', $args, $action); //NOTE: Ensure that an object is returned via this filter.
38         $res = apply_filters('plugins_api', false, $action, $args); //NOTE: Allows a plugin to completely override the builtin WordPress.org API.
39
40         if ( ! $res ) {
41                 $request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array( 'body' => array('action' => $action, 'request' => serialize($args))) );
42                 if ( is_wp_error($request) ) {
43                         $res = new WP_Error('plugins_api_failed', __('An Unexpected HTTP Error occurred during the API request.</p> <p><a href="?" onclick="document.location.reload(); return false;">Try again</a>'), $request->get_error_message() );
44                 } else {
45                         $res = unserialize($request['body']);
46                         if ( ! $res )
47                                 $res = new WP_Error('plugins_api_failed', __('An unknown error occurred'), $request['body']);
48                 }
49         }
50
51         return apply_filters('plugins_api_result', $res, $action, $args);
52 }
53
54 /**
55  * Retrieve popular WordPress plugin tags.
56  *
57  * @since 2.7.0
58  *
59  * @param array $args
60  * @return array
61  */
62 function install_popular_tags( $args = array() ) {
63         if ( ! ($cache = wp_cache_get('popular_tags', 'api')) && ! ($cache = get_option('wporg_popular_tags')) )
64                 add_option('wporg_popular_tags', array(), '', 'no'); ///No autoload.
65
66         if ( $cache && $cache->timeout + 3 * 60 * 60 > time() )
67                 return $cache->cached;
68
69         $tags = plugins_api('hot_tags', $args);
70
71         if ( is_wp_error($tags) )
72                 return $tags;
73
74         $cache = (object) array('timeout' => time(), 'cached' => $tags);
75
76         update_option('wporg_popular_tags', $cache);
77         wp_cache_set('popular_tags', $cache, 'api');
78
79         return $tags;
80 }
81 add_action('install_plugins_search', 'install_search', 10, 1);
82
83 /**
84  * Display search results and display as tag cloud.
85  *
86  * @since 2.7.0
87  *
88  * @param string $page
89  */
90 function install_search($page) {
91         $type = isset($_REQUEST['type']) ? stripslashes( $_REQUEST['type'] ) : '';
92         $term = isset($_REQUEST['s']) ? stripslashes( $_REQUEST['s'] ) : '';
93
94         $args = array();
95
96         switch( $type ){
97                 case 'tag':
98                         $args['tag'] = sanitize_title_with_dashes($term);
99                         break;
100                 case 'term':
101                         $args['search'] = $term;
102                         break;
103                 case 'author':
104                         $args['author'] = $term;
105                         break;
106         }
107
108         $args['page'] = $page;
109
110         $api = plugins_api('query_plugins', $args);
111
112         if ( is_wp_error($api) )
113                 wp_die($api);
114
115         add_action('install_plugins_table_header', 'install_search_form');
116
117         display_plugins_table($api->plugins, $api->info['page'], $api->info['pages']);
118
119         return;
120 }
121
122 add_action('install_plugins_dashboard', 'install_dashboard');
123 function install_dashboard() {
124         ?>
125         <p><?php _e('Plugins extend and expand the functionality of WordPress. You may automatically install plugins from the <a href="http://wordpress.org/extend/plugins/">WordPress Plugin Directory</a> or upload a plugin in .zip format via this page.') ?></p>
126
127         <h4><?php _e('Search') ?></h4>
128         <p class="install-help"><?php _e('Search for plugins by keyword, author, or tag.') ?></p>
129         <?php install_search_form(); ?>
130
131         <h4><?php _e('Popular tags') ?></h4>
132         <p class="install-help"><?php _e('You may also browse based on the most popular tags in the Plugin Directory:') ?></p>
133         <?php
134
135         $api_tags = install_popular_tags();
136
137         //Set up the tags in a way which can be interprated by wp_generate_tag_cloud()
138         $tags = array();
139         foreach ( (array)$api_tags as $tag )
140                 $tags[ $tag['name'] ] = (object) array(
141                                                                 'link' => esc_url( admin_url('plugin-install.php?tab=search&type=tag&s=' . urlencode($tag['name'])) ),
142                                                                 'name' => $tag['name'],
143                                                                 'id' => sanitize_title_with_dashes($tag['name']),
144                                                                 'count' => $tag['count'] );
145         echo '<p class="popular-tags">';
146         echo wp_generate_tag_cloud($tags, array( 'single_text' => __('%d plugin'), 'multiple_text' => __('%d plugins') ) );
147         echo '</p><br class="clear" />';
148 }
149
150 /**
151  * Display search form for searching plugins.
152  *
153  * @since 2.7.0
154  */
155 function install_search_form(){
156         $type = isset($_REQUEST['type']) ? stripslashes( $_REQUEST['type'] ) : '';
157         $term = isset($_REQUEST['s']) ? stripslashes( $_REQUEST['s'] ) : '';
158
159         ?><form id="search-plugins" method="post" action="<?php echo admin_url('plugin-install.php?tab=search'); ?>">
160                 <select name="type" id="typeselector">
161                         <option value="term"<?php selected('term', $type) ?>><?php _e('Term'); ?></option>
162                         <option value="author"<?php selected('author', $type) ?>><?php _e('Author'); ?></option>
163                         <option value="tag"<?php selected('tag', $type) ?>><?php echo _x('Tag', 'Plugin Installer'); ?></option>
164                 </select>
165                 <input type="text" name="s" value="<?php echo esc_attr($term) ?>" />
166                 <label class="screen-reader-text" for="plugin-search-input"><?php _e('Search Plugins'); ?></label>
167                 <input type="submit" id="plugin-search-input" name="search" value="<?php esc_attr_e('Search Plugins'); ?>" class="button" />
168         </form><?php
169 }
170
171 add_action('install_plugins_featured', 'install_featured', 10, 1);
172 /**
173  * Display featured plugins.
174  *
175  * @since 2.7.0
176  *
177  * @param string $page
178  */
179 function install_featured($page = 1) {
180         $args = array('browse' => 'featured', 'page' => $page);
181         $api = plugins_api('query_plugins', $args);
182         if ( is_wp_error($api) )
183                 wp_die($api);
184         display_plugins_table($api->plugins, $api->info['page'], $api->info['pages']);
185 }
186
187 add_action('install_plugins_popular', 'install_popular', 10, 1);
188 /**
189  * Display popular plugins.
190  *
191  * @since 2.7.0
192  *
193  * @param string $page
194  */
195 function install_popular($page = 1) {
196         $args = array('browse' => 'popular', 'page' => $page);
197         $api = plugins_api('query_plugins', $args);
198         display_plugins_table($api->plugins, $api->info['page'], $api->info['pages']);
199 }
200
201 add_action('install_plugins_upload', 'install_plugins_upload', 10, 1);
202 /**
203  * Upload from zip
204  * @since 2.8.0
205  *
206  * @param string $page
207  */
208 function install_plugins_upload( $page = 1 ) {
209 ?>
210         <h4><?php _e('Install a plugin in .zip format') ?></h4>
211         <p class="install-help"><?php _e('If you have a plugin in a .zip format, You may install it by uploading it here.') ?></p>
212         <form method="post" enctype="multipart/form-data" action="<?php echo admin_url('update.php?action=upload-plugin') ?>">
213                 <?php wp_nonce_field( 'plugin-upload') ?>
214                 <label class="screen-reader-text" for="pluginzip"><?php _e('Plugin zip file'); ?></label>
215                 <input type="file" id="pluginzip" name="pluginzip" />
216                 <input type="submit" class="button" value="<?php esc_attr_e('Install Now') ?>" />
217         </form>
218 <?php
219 }
220
221 add_action('install_plugins_new', 'install_new', 10, 1);
222 /**
223  * Display new plugins.
224  *
225  * @since 2.7.0
226  *
227  * @param string $page
228  */
229 function install_new($page = 1) {
230         $args = array('browse' => 'new', 'page' => $page);
231         $api = plugins_api('query_plugins', $args);
232         if ( is_wp_error($api) )
233                 wp_die($api);
234         display_plugins_table($api->plugins, $api->info['page'], $api->info['pages']);
235 }
236 add_action('install_plugins_updated', 'install_updated', 10, 1);
237
238
239 /**
240  * Display recently updated plugins.
241  *
242  * @since 2.7.0
243  *
244  * @param string $page
245  */
246 function install_updated($page = 1) {
247         $args = array('browse' => 'updated', 'page' => $page);
248         $api = plugins_api('query_plugins', $args);
249         display_plugins_table($api->plugins, $api->info['page'], $api->info['pages']);
250 }
251
252 /**
253  * Display plugin content based on plugin list.
254  *
255  * @since 2.7.0
256  *
257  * @param array $plugins List of plugins.
258  * @param string $page
259  * @param int $totalpages Number of pages.
260  */
261 function display_plugins_table($plugins, $page = 1, $totalpages = 1){
262         $type = isset($_REQUEST['type']) ? stripslashes( $_REQUEST['type'] ) : '';
263         $term = isset($_REQUEST['s']) ? stripslashes( $_REQUEST['s'] ) : '';
264
265         $plugins_allowedtags = array('a' => array('href' => array(),'title' => array(), 'target' => array()),
266                                                                 'abbr' => array('title' => array()),'acronym' => array('title' => array()),
267                                                                 'code' => array(), 'pre' => array(), 'em' => array(),'strong' => array(),
268                                                                 'ul' => array(), 'ol' => array(), 'li' => array(), 'p' => array(), 'br' => array());
269
270 ?>
271         <div class="tablenav">
272                 <div class="alignleft actions">
273                 <?php do_action('install_plugins_table_header'); ?>
274                 </div>
275                 <?php
276                         $url = esc_url($_SERVER['REQUEST_URI']);
277                         if ( ! empty($term) )
278                                 $url = add_query_arg('s', $term, $url);
279                         if ( ! empty($type) )
280                                 $url = add_query_arg('type', $type, $url);
281
282                         $page_links = paginate_links( array(
283                                 'base' => add_query_arg('paged', '%#%', $url),
284                                 'format' => '',
285                                 'prev_text' => __('&laquo;'),
286                                 'next_text' => __('&raquo;'),
287                                 'total' => $totalpages,
288                                 'current' => $page
289                         ));
290
291                         if ( $page_links )
292                                 echo "\t\t<div class='tablenav-pages'>$page_links</div>";
293 ?>
294                 <br class="clear" />
295         </div>
296         <table class="widefat" id="install-plugins" cellspacing="0">
297                 <thead>
298                         <tr>
299                                 <th scope="col" class="name"><?php _e('Name'); ?></th>
300                                 <th scope="col" class="num"><?php _e('Version'); ?></th>
301                                 <th scope="col" class="num"><?php _e('Rating'); ?></th>
302                                 <th scope="col" class="desc"><?php _e('Description'); ?></th>
303                                 <th scope="col" class="action-links"><?php _e('Actions'); ?></th>
304                         </tr>
305                 </thead>
306
307                 <tfoot>
308                         <tr>
309                                 <th scope="col" class="name"><?php _e('Name'); ?></th>
310                                 <th scope="col" class="num"><?php _e('Version'); ?></th>
311                                 <th scope="col" class="num"><?php _e('Rating'); ?></th>
312                                 <th scope="col" class="desc"><?php _e('Description'); ?></th>
313                                 <th scope="col" class="action-links"><?php _e('Actions'); ?></th>
314                         </tr>
315                 </tfoot>
316
317                 <tbody class="plugins">
318                 <?php
319                         if( empty($plugins) )
320                                 echo '<tr><td colspan="5">', __('No plugins match your request.'), '</td></tr>';
321
322                         foreach( (array) $plugins as $plugin ){
323                                 if ( is_object($plugin) )
324                                         $plugin = (array) $plugin;
325
326                                 $title = wp_kses($plugin['name'], $plugins_allowedtags);
327                                 //Limit description to 400char, and remove any HTML.
328                                 $description = strip_tags($plugin['description']);
329                                 if ( strlen($description) > 400 )
330                                         $description = mb_substr($description, 0, 400) . '&#8230;';
331                                 //remove any trailing entities
332                                 $description = preg_replace('/&[^;\s]{0,6}$/', '', $description);
333                                 //strip leading/trailing & multiple consecutive lines
334                                 $description = trim($description);
335                                 $description = preg_replace("|(\r?\n)+|", "\n", $description);
336                                 //\n => <br>
337                                 $description = nl2br($description);
338                                 $version = wp_kses($plugin['version'], $plugins_allowedtags);
339
340                                 $name = strip_tags($title . ' ' . $version);
341
342                                 $author = $plugin['author'];
343                                 if( ! empty($plugin['author']) )
344                                         $author = ' <cite>' . sprintf( __('By %s'), $author ) . '.</cite>';
345
346                                 $author = wp_kses($author, $plugins_allowedtags);
347
348                                 if( isset($plugin['homepage']) )
349                                         $title = '<a target="_blank" href="' . esc_attr($plugin['homepage']) . '">' . $title . '</a>';
350
351                                 $action_links = array();
352                                 $action_links[] = '<a href="' . admin_url('plugin-install.php?tab=plugin-information&amp;plugin=' . $plugin['slug'] .
353                                                                         '&amp;TB_iframe=true&amp;width=600&amp;height=550') . '" class="thickbox onclick" title="' .
354                                                                         esc_attr($name) . '">' . __('Install') . '</a>';
355
356                                 $action_links = apply_filters('plugin_install_action_links', $action_links, $plugin);
357                         ?>
358                         <tr>
359                                 <td class="name"><?php echo $title; ?></td>
360                                 <td class="vers"><?php echo $version; ?></td>
361                                 <td class="vers">
362                                         <div class="star-holder" title="<?php printf(_n('(based on %s rating)', '(based on %s ratings)', $plugin['num_ratings']), number_format_i18n($plugin['num_ratings'])) ?>">
363                                                 <div class="star star-rating" style="width: <?php echo esc_attr($plugin['rating']) ?>px"></div>
364                                                 <div class="star star5"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('5 stars') ?>" /></div>
365                                                 <div class="star star4"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('4 stars') ?>" /></div>
366                                                 <div class="star star3"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('3 stars') ?>" /></div>
367                                                 <div class="star star2"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('2 stars') ?>" /></div>
368                                                 <div class="star star1"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('1 star') ?>" /></div>
369                                         </div>
370                                 </td>
371                                 <td class="desc"><?php echo $description, $author; ?></td>
372                                 <td class="action-links"><?php if ( !empty($action_links) )     echo implode(' | ', $action_links); ?></td>
373                         </tr>
374                         <?php
375                         }
376                         ?>
377                 </tbody>
378         </table>
379
380         <div class="tablenav">
381                 <?php if ( $page_links )
382                                 echo "\t\t<div class='tablenav-pages'>$page_links</div>"; ?>
383                 <br class="clear" />
384         </div>
385
386 <?php
387 }
388
389 add_action('install_plugins_pre_plugin-information', 'install_plugin_information');
390
391 /**
392  * Display plugin information in dialog box form.
393  *
394  * @since 2.7.0
395  */
396 function install_plugin_information() {
397         global $tab;
398
399         $api = plugins_api('plugin_information', array('slug' => stripslashes( $_REQUEST['plugin'] ) ));
400
401         if ( is_wp_error($api) )
402                 wp_die($api);
403
404         $plugins_allowedtags = array('a' => array('href' => array(), 'title' => array(), 'target' => array()),
405                                                                 'abbr' => array('title' => array()), 'acronym' => array('title' => array()),
406                                                                 'code' => array(), 'pre' => array(), 'em' => array(), 'strong' => array(),
407                                                                 'div' => array(), 'p' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(),
408                                                                 'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(),
409                                                                 'img' => array('src' => array(), 'class' => array(), 'alt' => array()));
410         //Sanitize HTML
411         foreach ( (array)$api->sections as $section_name => $content )
412                 $api->sections[$section_name] = wp_kses($content, $plugins_allowedtags);
413         foreach ( array('version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug') as $key )
414                 $api->$key = wp_kses($api->$key, $plugins_allowedtags);
415
416         $section = isset($_REQUEST['section']) ? stripslashes( $_REQUEST['section'] ) : 'description'; //Default to the Description tab, Do not translate, API returns English.
417         if( empty($section) || ! isset($api->sections[ $section ]) )
418                 $section = array_shift( $section_titles = array_keys((array)$api->sections) );
419
420         iframe_header( __('Plugin Install') );
421         echo "<div id='$tab-header'>\n";
422         echo "<ul id='sidemenu'>\n";
423         foreach ( (array)$api->sections as $section_name => $content ) {
424
425                 $title = $section_name;
426                 $title = ucwords(str_replace('_', ' ', $title));
427
428                 $class = ( $section_name == $section ) ? ' class="current"' : '';
429                 $href = add_query_arg( array('tab' => $tab, 'section' => $section_name) );
430                 $href = esc_url($href);
431                 $san_title = esc_attr(sanitize_title_with_dashes($title));
432                 echo "\t<li><a name='$san_title' target='' href='$href'$class>$title</a></li>\n";
433         }
434         echo "</ul>\n";
435         echo "</div>\n";
436         ?>
437         <div class="alignright fyi">
438                 <?php if ( ! empty($api->download_link) ) : ?>
439                 <p class="action-button">
440                 <?php
441                         //Default to a "new" plugin
442                         $type = 'install';
443                         //Check to see if this plugin is known to be installed, and has an update awaiting it.
444                         $update_plugins = get_option('update_plugins');
445                         if ( is_object( $update_plugins ) ) {
446                                 foreach ( (array)$update_plugins->response as $file => $plugin ) {
447                                         if ( $plugin->slug === $api->slug ) {
448                                                 $type = 'update_available';
449                                                 $update_file = $file;
450                                                 break;
451                                         }
452                                 }
453                         }
454                         if ( 'install' == $type && is_dir( WP_PLUGIN_DIR  . '/' . $api->slug ) ) {
455                                 $installed_plugin = get_plugins('/' . $api->slug);
456                                 if ( ! empty($installed_plugin) ) {
457                                         $key = array_shift( $key = array_keys($installed_plugin) ); //Use the first plugin regardless of the name, Could have issues for multiple-plugins in one directory if they share different version numbers
458                                         if ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '=') ){
459                                                 $type = 'latest_installed';
460                                         } elseif ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '<') ) {
461                                                 $type = 'newer_installed';
462                                                 $newer_version = $installed_plugin[ $key ]['Version'];
463                                         } else {
464                                                 //If the above update check failed, Then that probably means that the update checker has out-of-date information, force a refresh
465                                                 delete_option('update_plugins');
466                                                 $update_file = $api->slug . '/' . $key; //This code branch only deals with a plugin which is in a folder the same name as its slug, Doesnt support plugins which have 'non-standard' names
467                                                 $type = 'update_available';
468                                         }
469                                 }
470                         }
471
472                         switch ( $type ) :
473                                 default:
474                                 case 'install':
475                                         if ( current_user_can('install_plugins') ) :
476                                 ?><a href="<?php echo wp_nonce_url(admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug) ?>" target="_parent"><?php _e('Install Now') ?></a><?php
477                                         endif;
478                                 break;
479                                 case 'update_available':
480                                         if ( current_user_can('update_plugins') ) :
481                                                 ?><a href="<?php echo wp_nonce_url(admin_url('update.php?action=upgrade-plugin&plugin=' . $update_file), 'upgrade-plugin_' . $update_file) ?>" target="_parent"><?php _e('Install Update Now') ?></a><?php
482                                         endif;
483                                 break;
484                                 case 'newer_installed':
485                                         if ( current_user_can('install_plugins') || current_user_can('update_plugins') ) :
486                                         ?><a><?php printf(__('Newer Version (%s) Installed'), $newer_version) ?></a><?php
487                                         endif;
488                                 break;
489                                 case 'latest_installed':
490                                         if ( current_user_can('install_plugins') || current_user_can('update_plugins') ) :
491                                         ?><a><?php _e('Latest Version Installed') ?></a><?php
492                                         endif;
493                                 break;
494                         endswitch; ?>
495                 </p>
496                 <?php endif; ?>
497                 <h2 class="mainheader"><?php _e('FYI') ?></h2>
498                 <ul>
499 <?php if ( ! empty($api->version) ) : ?>
500                         <li><strong><?php _e('Version:') ?></strong> <?php echo $api->version ?></li>
501 <?php endif; if ( ! empty($api->author) ) : ?>
502                         <li><strong><?php _e('Author:') ?></strong> <?php echo links_add_target($api->author, '_blank') ?></li>
503 <?php endif; if ( ! empty($api->last_updated) ) : ?>
504                         <li><strong><?php _e('Last Updated:') ?></strong> <span title="<?php echo $api->last_updated ?>"><?php
505                                                         printf( __('%s ago'), human_time_diff(strtotime($api->last_updated)) ) ?></span></li>
506 <?php endif; if ( ! empty($api->requires) ) : ?>
507                         <li><strong><?php _e('Requires WordPress Version:') ?></strong> <?php printf(__('%s or higher'), $api->requires) ?></li>
508 <?php endif; if ( ! empty($api->tested) ) : ?>
509                         <li><strong><?php _e('Compatible up to:') ?></strong> <?php echo $api->tested ?></li>
510 <?php endif; if ( ! empty($api->downloaded) ) : ?>
511                         <li><strong><?php _e('Downloaded:') ?></strong> <?php printf(_n('%s time', '%s times', $api->downloaded), number_format_i18n($api->downloaded)) ?></li>
512 <?php endif; if ( ! empty($api->slug) ) : ?>
513                         <li><a target="_blank" href="http://wordpress.org/extend/plugins/<?php echo $api->slug ?>/"><?php _e('WordPress.org Plugin Page &#187;') ?></a></li>
514 <?php endif; if ( ! empty($api->homepage) ) : ?>
515                         <li><a target="_blank" href="<?php echo $api->homepage ?>"><?php _e('Plugin Homepage  &#187;') ?></a></li>
516 <?php endif; ?>
517                 </ul>
518                 <h2><?php _e('Average Rating') ?></h2>
519                 <div class="star-holder" title="<?php printf(_n('(based on %s rating)', '(based on %s ratings)', $api->num_ratings), number_format_i18n($api->num_ratings)); ?>">
520                         <div class="star star-rating" style="width: <?php echo esc_attr($api->rating) ?>px"></div>
521                         <div class="star star5"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('5 stars') ?>" /></div>
522                         <div class="star star4"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('4 stars') ?>" /></div>
523                         <div class="star star3"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('3 stars') ?>" /></div>
524                         <div class="star star2"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('2 stars') ?>" /></div>
525                         <div class="star star1"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('1 star') ?>" /></div>
526                 </div>
527                 <small><?php printf(_n('(based on %s rating)', '(based on %s ratings)', $api->num_ratings), number_format_i18n($api->num_ratings)); ?></small>
528         </div>
529         <div id="section-holder" class="wrap">
530         <?php
531                 if ( !empty($api->tested) && version_compare( substr($GLOBALS['wp_version'], 0, strlen($api->tested)), $api->tested, '>') )
532                         echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been tested</strong> with your current version of WordPress.') . '</p></div>';
533
534                 else if ( !empty($api->requires) && version_compare( substr($GLOBALS['wp_version'], 0, strlen($api->requires)), $api->requires, '<') )
535                         echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been marked as compatible</strong> with your version of WordPress.') . '</p></div>';
536
537                 foreach ( (array)$api->sections as $section_name => $content ) {
538                         $title = $section_name;
539                         $title[0] = strtoupper($title[0]);
540                         $title = str_replace('_', ' ', $title);
541
542                         $content = links_add_base_url($content, 'http://wordpress.org/extend/plugins/' . $api->slug . '/');
543                         $content = links_add_target($content, '_blank');
544
545                         $san_title = esc_attr(sanitize_title_with_dashes($title));
546
547                         $display = ( $section_name == $section ) ? 'block' : 'none';
548
549                         echo "\t<div id='section-{$san_title}' class='section' style='display: {$display};'>\n";
550                         echo "\t\t<h2 class='long-header'>$title</h2>";
551                         echo $content;
552                         echo "\t</div>\n";
553                 }
554         echo "</div>\n";
555
556         iframe_footer();
557         exit;
558 }