Make WordPress Core

Ticket #18289: 18289_1.patch

File 18289_1.patch, 17.7 KB (added by csixty4, 13 years ago)

Patch to provide requested functionality

  • wp-admin/includes/plugin-install.php

     
    236236 * Display plugin information in dialog box form.
    237237 *
    238238 * @since 2.7.0
     239 * @param array $data content, title
     240 * @param boolean $framed whether to wrap in admin interface
     241 * @return array $data filtered data (if called as filter)
    239242 */
    240 function install_plugin_information() {
    241         global $tab;
     243function install_plugin_information($data, $framed) {
    242244
    243         $api = plugins_api('plugin_information', array('slug' => stripslashes( $_REQUEST['plugin'] ) ));
     245    global $tab;
    244246
    245         if ( is_wp_error($api) )
    246                 wp_die($api);
     247    $api = plugins_api('plugin_information', array('slug' => stripslashes( $_REQUEST['plugin'] ) ));
    247248
    248         $plugins_allowedtags = array('a' => array('href' => array(), 'title' => array(), 'target' => array()),
    249                                                                 'abbr' => array('title' => array()), 'acronym' => array('title' => array()),
    250                                                                 'code' => array(), 'pre' => array(), 'em' => array(), 'strong' => array(),
    251                                                                 'div' => array(), 'p' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(),
    252                                                                 'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(),
    253                                                                 'img' => array('src' => array(), 'class' => array(), 'alt' => array()));
    254         //Sanitize HTML
    255         foreach ( (array)$api->sections as $section_name => $content )
    256                 $api->sections[$section_name] = wp_kses($content, $plugins_allowedtags);
    257         foreach ( array('version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug') as $key )
    258                 $api->$key = wp_kses($api->$key, $plugins_allowedtags);
     249    if ( is_wp_error($api) )
     250        wp_die($api);
    259251
    260         $section = isset($_REQUEST['section']) ? stripslashes( $_REQUEST['section'] ) : 'description'; //Default to the Description tab, Do not translate, API returns English.
    261         if ( empty($section) || ! isset($api->sections[ $section ]) )
    262                 $section = array_shift( $section_titles = array_keys((array)$api->sections) );
     252    $plugins_allowedtags = array('a' => array('href' => array(), 'title' => array(), 'target' => array()),
     253                                'abbr' => array('title' => array()), 'acronym' => array('title' => array()),
     254                                'code' => array(), 'pre' => array(), 'em' => array(), 'strong' => array(),
     255                                'div' => array(), 'p' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(),
     256                                'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(),
     257                                'img' => array('src' => array(), 'class' => array(), 'alt' => array()));
     258    //Sanitize HTML
     259    foreach ( (array)$api->sections as $section_name => $content )
     260        $api->sections[$section_name] = wp_kses($content, $plugins_allowedtags);
     261    foreach ( array('version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug') as $key )
     262        $api->$key = wp_kses($api->$key, $plugins_allowedtags);
    263263
    264         iframe_header( __('Plugin Install') );
    265         echo "<div id='$tab-header'>\n";
    266         echo "<ul id='sidemenu'>\n";
    267         foreach ( (array)$api->sections as $section_name => $content ) {
     264    $section = isset($_REQUEST['section']) ? stripslashes( $_REQUEST['section'] ) : 'description'; //Default to the Description tab, Do not translate, API returns English.
     265    if ( empty($section) || ! isset($api->sections[ $section ]) )
     266        $section = array_shift( $section_titles = array_keys((array)$api->sections) );
    268267
    269                 $title = $section_name;
    270                 $title = ucwords(str_replace('_', ' ', $title));
     268    $contents = '';
    271269
    272                 $class = ( $section_name == $section ) ? ' class="current"' : '';
    273                 $href = add_query_arg( array('tab' => $tab, 'section' => $section_name) );
    274                 $href = esc_url($href);
    275                 $san_title = esc_attr(sanitize_title_with_dashes($title));
    276                 echo "\t<li><a name='$san_title' target='' href='$href'$class>$title</a></li>\n";
    277         }
    278         echo "</ul>\n";
    279         echo "</div>\n";
    280         ?>
    281         <div class="alignright fyi">
    282                 <?php if ( ! empty($api->download_link) && ( current_user_can('install_plugins') || current_user_can('update_plugins') ) ) : ?>
    283                 <p class="action-button">
    284                 <?php
    285                 $status = install_plugin_install_status($api);
    286                 switch ( $status['status'] ) {
    287                         case 'install':
    288                                 if ( $status['url'] )
    289                                         echo '<a href="' . $status['url'] . '" target="_parent">' . __('Install Now') . '</a>';
    290                                 break;
    291                         case 'update_available':
    292                                 if ( $status['url'] )
    293                                         echo '<a href="' . $status['url'] . '" target="_parent">' . __('Install Update Now') .'</a>';
    294                                 break;
    295                         case 'newer_installed':
    296                                 echo '<a>' . sprintf(__('Newer Version (%s) Installed'), $status['version']) . '</a>';
    297                                 break;
    298                         case 'latest_installed':
    299                                 echo '<a>' . __('Latest Version Installed') . '</a>';
    300                                 break;
    301                 }
    302                 ?>
    303                 </p>
    304                 <?php endif; ?>
    305                 <h2 class="mainheader"><?php /* translators: For Your Information */ _e('FYI') ?></h2>
    306                 <ul>
    307 <?php if ( ! empty($api->version) ) : ?>
    308                         <li><strong><?php _e('Version:') ?></strong> <?php echo $api->version ?></li>
    309 <?php endif; if ( ! empty($api->author) ) : ?>
    310                         <li><strong><?php _e('Author:') ?></strong> <?php echo links_add_target($api->author, '_blank') ?></li>
    311 <?php endif; if ( ! empty($api->last_updated) ) : ?>
    312                         <li><strong><?php _e('Last Updated:') ?></strong> <span title="<?php echo $api->last_updated ?>"><?php
    313                                                         printf( __('%s ago'), human_time_diff(strtotime($api->last_updated)) ) ?></span></li>
    314 <?php endif; if ( ! empty($api->requires) ) : ?>
    315                         <li><strong><?php _e('Requires WordPress Version:') ?></strong> <?php printf(__('%s or higher'), $api->requires) ?></li>
    316 <?php endif; if ( ! empty($api->tested) ) : ?>
    317                         <li><strong><?php _e('Compatible up to:') ?></strong> <?php echo $api->tested ?></li>
    318 <?php endif; if ( ! empty($api->downloaded) ) : ?>
    319                         <li><strong><?php _e('Downloaded:') ?></strong> <?php printf(_n('%s time', '%s times', $api->downloaded), number_format_i18n($api->downloaded)) ?></li>
    320 <?php endif; if ( ! empty($api->slug) && empty($api->external) ) : ?>
    321                         <li><a target="_blank" href="http://wordpress.org/extend/plugins/<?php echo $api->slug ?>/"><?php _e('WordPress.org Plugin Page &#187;') ?></a></li>
    322 <?php endif; if ( ! empty($api->homepage) ) : ?>
    323                         <li><a target="_blank" href="<?php echo $api->homepage ?>"><?php _e('Plugin Homepage  &#187;') ?></a></li>
    324 <?php endif; ?>
    325                 </ul>
    326                 <?php if ( ! empty($api->rating) ) : ?>
    327                 <h2><?php _e('Average Rating') ?></h2>
    328                 <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)); ?>">
    329                         <div class="star star-rating" style="width: <?php echo esc_attr($api->rating) ?>px"></div>
    330                         <div class="star star5"><img src="<?php echo admin_url('images/star.png?v=20110615'); ?>" alt="<?php _e('5 stars') ?>" /></div>
    331                         <div class="star star4"><img src="<?php echo admin_url('images/star.png?v=20110615'); ?>" alt="<?php _e('4 stars') ?>" /></div>
    332                         <div class="star star3"><img src="<?php echo admin_url('images/star.png?v=20110615'); ?>" alt="<?php _e('3 stars') ?>" /></div>
    333                         <div class="star star2"><img src="<?php echo admin_url('images/star.png?v=20110615'); ?>" alt="<?php _e('2 stars') ?>" /></div>
    334                         <div class="star star1"><img src="<?php echo admin_url('images/star.png?v=20110615'); ?>" alt="<?php _e('1 star') ?>" /></div>
    335                 </div>
    336                 <small><?php printf(_n('(based on %s rating)', '(based on %s ratings)', $api->num_ratings), number_format_i18n($api->num_ratings)); ?></small>
    337                 <?php endif; ?>
    338         </div>
    339         <div id="section-holder" class="wrap">
    340         <?php
    341                 if ( !empty($api->tested) && version_compare( substr($GLOBALS['wp_version'], 0, strlen($api->tested)), $api->tested, '>') )
    342                         echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been tested</strong> with your current version of WordPress.') . '</p></div>';
     270    $contents .= "<div id='$tab-header'>\n";
     271    $contents .= "<ul id='sidemenu'>\n";
     272    foreach ( (array)$api->sections as $section_name => $content ) {
    343273
    344                 else if ( !empty($api->requires) && version_compare( substr($GLOBALS['wp_version'], 0, strlen($api->requires)), $api->requires, '<') )
    345                         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>';
     274        $title = $section_name;
     275        $title = ucwords(str_replace('_', ' ', $title));
    346276
    347                 foreach ( (array)$api->sections as $section_name => $content ) {
    348                         $title = $section_name;
    349                         $title[0] = strtoupper($title[0]);
    350                         $title = str_replace('_', ' ', $title);
     277        $class = ( $section_name == $section ) ? ' class="current"' : '';
     278        $href = add_query_arg( array('tab' => $tab, 'section' => $section_name) );
     279        $href = esc_url($href);
     280        $san_title = esc_attr(sanitize_title_with_dashes($title));
     281        $contents .= "\t<li><a name='$san_title' target='' href='$href'$class>$title</a></li>\n";
     282    }
     283    $contents .= "</ul>\n";
     284    $contents .= "</div>\n";
     285    $contents .= '<div class="alignright fyi">';
    351286
    352                         $content = links_add_base_url($content, 'http://wordpress.org/extend/plugins/' . $api->slug . '/');
    353                         $content = links_add_target($content, '_blank');
     287    if ( ! empty($api->download_link) && ( current_user_can('install_plugins') || current_user_can('update_plugins') ) ) {
    354288
    355                         $san_title = esc_attr(sanitize_title_with_dashes($title));
     289        $contents .= '<p class="action-button">';
     290        $status = install_plugin_install_status($api);
     291        switch ( $status['status'] ) {
     292            case 'install':
     293                if ( $status['url'] )
     294                    $contents .= '<a href="' . $status['url'] . '" target="_parent">' . __('Install Now') . '</a>';
     295                break;
     296            case 'update_available':
     297                if ( $status['url'] )
     298                    $contents .= '<a href="' . $status['url'] . '" target="_parent">' . __('Install Update Now') .'</a>';
     299                break;
     300            case 'newer_installed':
     301                $contents .= '<a>' . sprintf(__('Newer Version (%s) Installed'), $status['version']) . '</a>';
     302                break;
     303            case 'latest_installed':
     304                $contents .= '<a>' . __('Latest Version Installed') . '</a>';
     305                break;
     306        }
     307        $contents .= '</p>';
     308       
     309    }
     310         
     311    $contents .= '<h2 class="mainheader">' . /* translators: For Your Information */ __('FYI') . '</h2>';
     312    $contents .= '<ul>';
     313    if ( ! empty($api->version) ) {
     314        $contents .= '<li><strong>' . __('Version:') . '</strong> ' . $api->version . '</li>';
     315    }
     316    if ( ! empty($api->author) ) {
     317        $contents .= '<li><strong>' . __('Author:') . '</strong> ' . links_add_target($api->author, '_blank') . '</li>';
     318    }
     319    if ( ! empty($api->last_updated) ) {
     320        $contents .= '<li><strong>' . __('Last Updated:') . '</strong> <span title="' . $api->last_updated . '">' .
     321                        sprintf( __('%s ago'), human_time_diff(strtotime($api->last_updated)) ) . '</span></li>';
     322    }
     323    if ( ! empty($api->requires) ) {
     324        $contents .= '<li><strong>' . __('Requires WordPress Version:') . '</strong> ' . sprintf(__('%s or higher'), $api->requires) . '</li>';
     325    }
     326    if ( ! empty($api->tested) ) {
     327        $contents .= '<li><strong>' . __('Compatible up to:') . '</strong> ' . $api->tested . '</li>';
     328    }
     329    if ( ! empty($api->downloaded) ) {
     330        $contents .= '<li><strong>' . __('Downloaded:') . '</strong> ' . sprintf(_n('%s time', '%s times', $api->downloaded), number_format_i18n($api->downloaded)) . '</li>';
     331    }
     332    if ( ! empty($api->slug) && empty($api->external) ) {
     333        $contents .= '<li><a target="_blank" href="http://wordpress.org/extend/plugins/' . $api->slug . '">' . __('WordPress.org Plugin Page &#187;') . '</a></li>';
     334    }
     335    if ( ! empty($api->homepage) ) {
     336        $contents .= '<li><a target="_blank" href="' . $api->homepage . '">' . __('Plugin Homepage  &#187;') . '</a></li>';
     337    }
     338    $contents .= '</ul>';
     339   
     340    if ( ! empty($api->rating) ) {
     341    $contents .= '<h2>' . __('Average Rating') . '</h2>';
     342    $contents .= '<div class="star-holder" title="' . sprintf(_n('(based on %s rating)', '(based on %s ratings)', $api->num_ratings), number_format_i18n($api->num_ratings)) . '">';
    356343
    357                         $display = ( $section_name == $section ) ? 'block' : 'none';
     344    $contents .= '<div class="star star-rating" style="width: ' . esc_attr($api->rating) . 'px"></div>';
     345    $contents .= '<div class="star star5"><img src="' . admin_url('images/star.png?v=20110615') . '" alt="' . __('5 stars') . '" /></div>';
     346    $contents .= '<div class="star star4"><img src="' . admin_url('images/star.png?v=20110615') . '" alt="' . __('4 stars') . '" /></div>';
     347    $contents .= '<div class="star star3"><img src="' . admin_url('images/star.png?v=20110615') . '" alt="' . __('3 stars') . '" /></div>';
     348    $contents .= '<div class="star star2"><img src="' . admin_url('images/star.png?v=20110615') . '" alt="' . __('2 stars') . '" /></div>';
     349    $contents .= '<div class="star star1"><img src="' . admin_url('images/star.png?v=20110615') . '" alt="' . __('1 star') . '" /></div>';
    358350
    359                         echo "\t<div id='section-{$san_title}' class='section' style='display: {$display};'>\n";
    360                         echo "\t\t<h2 class='long-header'>$title</h2>";
    361                         echo $content;
    362                         echo "\t</div>\n";
    363                 }
    364         echo "</div>\n";
     351    $contents .= '</div>';
     352    $contents .= '<small>' . sprintf(_n('(based on %s rating)', '(based on %s ratings)', $api->num_ratings), number_format_i18n($api->num_ratings)) . '</small>';
     353    }
     354    $contents .= '</div>';
     355    $contents .= '<div id="section-holder" class="wrap">';
    365356
    366         iframe_footer();
    367         exit;
     357    if ( !empty($api->tested) && version_compare( substr($GLOBALS['wp_version'], 0, strlen($api->tested)), $api->tested, '>') )
     358        $contents .= '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been tested</strong> with your current version of WordPress.') . '</p></div>';
     359
     360    else if ( !empty($api->requires) && version_compare( substr($GLOBALS['wp_version'], 0, strlen($api->requires)), $api->requires, '<') )
     361        $contents .= '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been marked as compatible</strong> with your version of WordPress.') . '</p></div>';
     362
     363    foreach ( (array)$api->sections as $section_name => $content ) {
     364        $title = $section_name;
     365        $title[0] = strtoupper($title[0]);
     366        $title = str_replace('_', ' ', $title);
     367
     368        $content = links_add_base_url($content, 'http://wordpress.org/extend/plugins/' . $api->slug . '/');
     369        $content = links_add_target($content, '_blank');
     370
     371        $san_title = esc_attr(sanitize_title_with_dashes($title));
     372
     373        $display = ( $section_name == $section ) ? 'block' : 'none';
     374
     375        $contents .= "\t<div id='section-{$san_title}' class='section' style='display: {$display};'>\n";
     376        $contents .= "\t\t<h2 class='long-header'>$title</h2>";
     377        $contents .= $content;
     378        $contents .= "\t</div>\n";
     379    }
     380    $contents .= "</div>\n";
     381
     382    if($framed) {
     383        iframe_header( __('Plugin Install') );
     384        echo $contents;
     385        iframe_footer();
     386        exit;
     387    }
     388    else {
     389        $data['contents'] = $contents;
     390        $data['title'] = $api->name;
     391        return $data;
     392    }
    368393}
    369 add_action('install_plugins_pre_plugin-information', 'install_plugin_information');
     394add_filter('install_plugins_pre_plugin-information', 'install_plugin_information', 10, 2);
     395add_action('install_plugins_pre_plugin-information', 'install_plugin_information', 10, 2);
  • wp-admin/plugin-install.php

     
    66 * @subpackage Administration
    77 */
    88// TODO route this pages via a specific iframe handler instead of the do_action below
    9 if ( !defined( 'IFRAME_REQUEST' ) && isset( $_GET['tab'] ) && ( 'plugin-information' == $_GET['tab'] ) )
     9if ( !defined( 'IFRAME_REQUEST' ) && isset( $_GET['tab'] ) && ( 'plugin-information' == $_GET['tab'] ) && ( !isset($_GET['wrapped']) ) )
    1010        define( 'IFRAME_REQUEST', true );
    1111
    1212/** WordPress Administration Bootstrap */
     
    3434
    3535$body_id = $tab;
    3636
    37 do_action('install_plugins_pre_' . $tab); //Used to override the general interface, Eg, install or plugin information.
     37if(defined('IFRAME_REQUEST')) {
     38        do_action('install_plugins_pre_' . $tab, array(), defined('IFRAME_REQUEST')); //Used to override the general interface, Eg, install or plugin information.
     39}
     40else {
     41        $data = array('contents' => '', 'title' => $title);
     42        $data = apply_filters('install_plugins_pre_' . $tab, $data, defined('IFRAME_REQUEST')); //Used to override the general interface, Eg, install or plugin information.
     43}
    3844
    3945add_contextual_help($current_screen,
    4046        '<p>' . sprintf(__('Plugins hook into WordPress to extend its functionality with custom features. Plugins are developed independently from WordPress core by thousands of developers all over the world. All plugins in the official <a href="%s" target="_blank">WordPress.org Plugin Directory</a> are compatible with the license WordPress uses. You can find new plugins to install by searching or browsing the Directory right here in your own Plugins section.'), 'http://wordpress.org/extend/plugins/') . '</p>' .
     
    5056?>
    5157<div class="wrap">
    5258<?php screen_icon(); ?>
    53 <h2><?php echo esc_html( $title ); ?></h2>
     59<h2><?php echo esc_html( $data['title'] ); ?></h2>
    5460
    5561<?php $wp_list_table->views(); ?>
    56 
     62<?php echo $data['contents']; ?>
    5763<br class="clear" />
    5864<?php do_action('install_plugins_' . $tab, $paged); ?>
    5965</div>