Make WordPress Core


Ignore:
Timestamp:
07/12/2014 10:07:16 PM (12 years ago)
Author:
ocean90
Message:

Improvements to the plugin information modal:

  • Whitespace/braces cleanup for [29040].
  • Reduce width of modal to 792px, which is the default banner size.
  • Reduce banner height when screen height is smaller than 500px.
  • Remove inline CSS.
  • Re-use tab var in JS.
  • Encode ampersands in links.

props avryl, michalzuber, ocean90.
see #27440.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/plugin-install.php

    r29123 r29125  
    312312        global $tab;
    313313
    314         $api = plugins_api( 'plugin_information', array( 'slug' => wp_unslash( $_REQUEST['plugin'] ), 'is_ssl' => is_ssl(), 'fields' => array( 'banners' => true, 'reviews' => true ) ) );
    315 
    316         if ( is_wp_error( $api ) )
     314        $api = plugins_api( 'plugin_information', array(
     315                'slug' => wp_unslash( $_REQUEST['plugin'] ),
     316                'is_ssl' => is_ssl(),
     317                'fields' => array( 'banners' => true, 'reviews' => true )
     318        ) );
     319
     320        if ( is_wp_error( $api ) ) {
    317321                wp_die( $api );
     322        }
    318323
    319324        $plugins_allowedtags = array(
    … …  
    327332
    328333        $plugins_section_titles = array(
    329                 'description'  => _x('Description',  'Plugin installer section title'),
    330                 'installation' => _x('Installation', 'Plugin installer section title'),
    331                 'faq'          => _x('FAQ',          'Plugin installer section title'),
    332                 'screenshots'  => _x('Screenshots',  'Plugin installer section title'),
    333                 'changelog'    => _x('Changelog',    'Plugin installer section title'),
    334                 'reviews'      => _x('Reviews',      'Plugin installer section title'),
    335                 'other_notes'  => _x('Other Notes',  'Plugin installer section title')
     334                'description'  => _x( 'Description',  'Plugin installer section title' ),
     335                'installation' => _x( 'Installation', 'Plugin installer section title' ),
     336                'faq'          => _x( 'FAQ',          'Plugin installer section title' ),
     337                'screenshots'  => _x( 'Screenshots',  'Plugin installer section title' ),
     338                'changelog'    => _x( 'Changelog',    'Plugin installer section title' ),
     339                'reviews'      => _x( 'Reviews',      'Plugin installer section title' ),
     340                'other_notes'  => _x( 'Other Notes',  'Plugin installer section title' )
    336341        );
    337342
    338         //Sanitize HTML
    339         foreach ( (array)$api->sections as $section_name => $content ) {
    340                 $api->sections[$section_name] = wp_kses($content, $plugins_allowedtags);
     343        // Sanitize HTML
     344        foreach ( (array) $api->sections as $section_name => $content ) {
     345                $api->sections[$section_name] = wp_kses( $content, $plugins_allowedtags );
    341346        }
    342347
    343348        foreach ( array( 'version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug' ) as $key ) {
    344                 if ( isset( $api->$key ) )
     349                if ( isset( $api->$key ) ) {
    345350                        $api->$key = wp_kses( $api->$key, $plugins_allowedtags );
     351                }
    346352        }
    347353
    348354        $_tab = esc_attr( $tab );
    349355
    350         $section = isset( $_REQUEST['section'] ) ? wp_unslash( $_REQUEST['section'] ) : 'description'; //Default to the Description tab, Do not translate, API returns English.
     356        $section = isset( $_REQUEST['section'] ) ? wp_unslash( $_REQUEST['section'] ) : 'description'; // Default to the Description tab, Do not translate, API returns English.
    351357        if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) {
    352358                $section_titles = array_keys( (array) $api->sections );
    … …  
    354360        }
    355361
    356         iframe_header( __('Plugin Install') );
     362        iframe_header( __( 'Plugin Install' ) );
    357363
    358364        $_with_banner = '';
    359365
    360         if ( !empty( $api->banners ) && ( !empty( $api->banners['low'] ) || !empty( $api->banners['high'] ) ) ) {
     366        if ( ! empty( $api->banners ) && ( ! empty( $api->banners['low'] ) || ! empty( $api->banners['high'] ) ) ) {
    361367                $_with_banner = 'with-banner';
    362                 $low  = ( !empty( $api->banners['low'] ) ) ? $api->banners['low'] : $api->banners['high'];
    363                 $high = ( !empty( $api->banners['high'] ) ) ? $api->banners['high'] : $api->banners['low'];
     368                $low  = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low'];
     369                $high = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high'];
    364370                ?>
    365371                <style type="text/css">
    366372                        #plugin-information-title.with-banner {
    367                                 background-image: url(<?php echo $low ?>);
     373                                background-image: url( <?php echo esc_url( $low ); ?> );
    368374                        }
    369                         @media only screen and (-webkit-min-device-pixel-ratio: 1.5) {
     375                        @media only screen and ( -webkit-min-device-pixel-ratio: 1.5 ) {
    370376                                #plugin-information-title.with-banner {
    371                                         background-image: url(<?php echo $high ?>});
     377                                        background-image: url( <?php echo esc_url( $high ); ?> );
    372378                                }
    373379                        }
    … …  
    379385        echo "<div id='{$_tab}-tabs' class='{$_with_banner}'>\n";
    380386
    381         foreach ( (array)$api->sections as $section_name => $content ) {
    382                 if ( 'reviews' == $section_name && ( empty( $api->ratings ) || 0 == array_sum( (array) $api->ratings ) ) )
     387        foreach ( (array) $api->sections as $section_name => $content ) {
     388                if ( 'reviews' === $section_name && ( empty( $api->ratings ) || 0 === array_sum( (array) $api->ratings ) ) ) {
    383389                        continue;
    384 
    385                 if ( isset( $plugins_section_titles[ $section_name ] ) )
     390                }
     391
     392                if ( isset( $plugins_section_titles[ $section_name ] ) ) {
    386393                        $title = $plugins_section_titles[ $section_name ];
    387                 else
     394                } else {
    388395                        $title = ucwords( str_replace( '_', ' ', $section_name ) );
    389 
    390                 $class = ( $section_name == $section ) ? ' class="current"' : '';
     396                }
     397
     398                $class = ( $section_name === $section ) ? ' class="current"' : '';
    391399                $href = add_query_arg( array('tab' => $tab, 'section' => $section_name) );
    392400                $href = esc_url( $href );
    … …  
    401409        <div class="fyi">
    402410                <ul>
    403 <?php if ( ! empty( $api->version ) ) : ?>
    404                         <li><strong><?php _e('Version:') ?></strong> <?php echo $api->version ?></li>
    405 <?php endif; if ( ! empty( $api->author ) ) : ?>
    406                         <li><strong><?php _e('Author:') ?></strong> <?php echo links_add_target($api->author, '_blank') ?></li>
    407 <?php endif; if ( ! empty( $api->last_updated ) ) : ?>
    408                         <li><strong><?php _e('Last Updated:') ?></strong> <span title="<?php echo $api->last_updated ?>"><?php
    409                                                         printf( __('%s ago'), human_time_diff(strtotime($api->last_updated)) ) ?></span></li>
    410 <?php endif; if ( ! empty( $api->requires ) ) : ?>
    411                         <li><strong><?php _e('Requires WordPress Version:') ?></strong> <?php printf(__('%s or higher'), $api->requires) ?></li>
    412 <?php endif; if ( ! empty( $api->tested ) ) : ?>
    413                         <li><strong><?php _e('Compatible up to:') ?></strong> <?php echo $api->tested ?></li>
    414 <?php endif; if ( ! empty( $api->downloaded ) ) : ?>
    415                         <li><strong><?php _e('Downloaded:') ?></strong> <?php printf(_n('%s time', '%s times', $api->downloaded), number_format_i18n($api->downloaded)) ?></li>
    416 <?php endif; if ( ! empty( $api->slug ) && empty( $api->external ) ) : ?>
    417                         <li><a target="_blank" href="https://wordpress.org/plugins/<?php echo $api->slug ?>/"><?php _e('WordPress.org Plugin Page &#187;') ?></a></li>
    418 <?php endif; if ( ! empty( $api->homepage ) ) : ?>
    419                         <li><a target="_blank" href="<?php echo $api->homepage ?>"><?php _e('Plugin Homepage &#187;') ?></a></li>
    420 <?php endif;if ( ! empty( $api->donate_link ) && empty( $api->contributors ) ) : ?>
    421                         <li><a target="_blank" href="<?php echo $api->donate_link ?>"><?php _e('Donate to this plugin &#187;') ?></a></li>
    422 <?php endif; ?>
     411                <?php if ( ! empty( $api->version ) ) { ?>
     412                        <li><strong><?php _e( 'Version:' ); ?></strong> <?php echo $api->version; ?></li>
     413                <?php } if ( ! empty( $api->author ) ) { ?>
     414                        <li><strong><?php _e( 'Author:' ); ?></strong> <?php echo links_add_target( $api->author, '_blank' ); ?></li>
     415                <?php } if ( ! empty( $api->last_updated ) ) { ?>
     416                        <li><strong><?php _e( 'Last Updated:' ); ?></strong> <span title="<?php echo $api->last_updated; ?>">
     417                                <?php printf( __( '%s ago' ), human_time_diff( strtotime( $api->last_updated ) ) ); ?>
     418                        </span></li>
     419                <?php } if ( ! empty( $api->requires ) ) { ?>
     420                        <li><strong><?php _e( 'Requires WordPress Version:' ); ?></strong> <?php printf( __( '%s or higher' ), $api->requires ); ?></li>
     421                <?php } if ( ! empty( $api->tested ) ) { ?>
     422                        <li><strong><?php _e( 'Compatible up to:' ); ?></strong> <?php echo $api->tested; ?></li>
     423                <?php } if ( ! empty( $api->downloaded ) ) { ?>
     424                        <li><strong><?php _e( 'Downloaded:' ); ?></strong> <?php printf( _n( '%s time', '%s times', $api->downloaded ), number_format_i18n( $api->downloaded ) ); ?></li>
     425                <?php } if ( ! empty( $api->slug ) && empty( $api->external ) ) { ?>
     426                        <li><a target="_blank" href="https://wordpress.org/plugins/<?php echo $api->slug; ?>/"><?php _e( 'WordPress.org Plugin Page &#187;' ); ?></a></li>
     427                <?php } if ( ! empty( $api->homepage ) ) { ?>
     428                        <li><a target="_blank" href="<?php echo esc_url( $api->homepage ); ?>"><?php _e( 'Plugin Homepage &#187;' ); ?></a></li>
     429                <?php } if ( ! empty( $api->donate_link ) && empty( $api->contributors ) ) { ?>
     430                        <li><a target="_blank" href="<?php echo $api->donate_link ?>"><?php _e( 'Donate to this plugin &#187;' ); ?></a></li>
     431                <?php } ?>
    423432                </ul>
    424                 <?php if ( ! empty( $api->rating ) ) : ?>
    425                 <h3><?php _e('Average Rating') ?></h3>
     433                <?php if ( ! empty( $api->rating ) ) { ?>
     434                <h3><?php _e( 'Average Rating' ); ?></h3>
    426435                <?php wp_star_rating( array( 'rating' => $api->rating, 'type' => 'percent', 'number' => $api->num_ratings ) ); ?>
    427                 <small><?php printf( _n('(based on %s rating)', '(based on %s ratings)', $api->num_ratings), number_format_i18n($api->num_ratings) ); ?></small>
    428                 <?php endif; ?>
    429                 <?php
     436                <small><?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $api->num_ratings ), number_format_i18n( $api->num_ratings ) ); ?></small>
     437                <?php }
     438
    430439                if ( ! empty( $api->ratings ) && array_sum( (array) $api->ratings ) > 0 ) {
    431                         foreach( $api->ratings as $key=>$ratecount ) {
     440                        foreach( $api->ratings as $key => $ratecount ) {
    432441                                // avoid div-by-zero
    433442                                $_rating = $api->num_ratings ? ( $ratecount / $api->num_ratings ) : 0;
    434443                                ?>
    435444                                <div class="counter-container">
    436                                         <a href="./plugin-install.php?tab=plugin-information&plugin=<?php echo $api->slug; ?>&section=reviews"
    437                                            title="<?php echo esc_attr( sprintf( _n( 'Click to see reviews that provided a rating of %d star', 'Click to see reviews that provided a rating of %d stars', $key ), $key ) ); ?>" -->
    438                                                 <span class="counter-label" style="float:left; margin-right:5px;"><?php echo $key; ?> stars</span>
    439                                                 <span class="counter-back" style="height:17px;width:92px;background-color:#ececec;float:left;">
    440                                                         <span class="counter-bar" style="width: <?php echo 92 * $_rating; ?>px;height:17px;background-color:#fddb5a;float:left;"></span>
     445                                        <a href="<?php echo esc_url( self_admin_url( 'plugin-install.php?tab=plugin-information&amp;plugin=' . $api->slug . '&amp;section=reviews' ) ); ?>"
     446                                           title="<?php echo esc_attr( sprintf( _n( 'Click to see reviews that provided a rating of %d star', 'Click to see reviews that provided a rating of %d stars', $key ), $key ) ); ?>">
     447                                                <span class="counter-label"><?php echo $key; ?> stars</span>
     448                                                <span class="counter-back">
     449                                                        <span class="counter-bar" style="width: <?php echo 92 * $_rating; ?>px;"></span>
    441450                                                </span>
    442451                                        </a>
    443                                         <span class="counter-count" style="margin-left:5px;"><?php echo $ratecount; ?></span>
     452                                        <span class="counter-count"><?php echo $ratecount; ?></span>
    444453                                </div>
    445                         <?php
     454                                <?php
    446455                        }
    447456                }
    448                 if ( ! empty( $api->contributors ) ) : ?>
    449                         <h3><?php _e('Contributors') ?></h3>
     457                if ( ! empty( $api->contributors ) ) { ?>
     458                        <h3><?php _e( 'Contributors' ); ?></h3>
    450459                        <ul class="contributors">
    451460                                <?php
    452461                                foreach ( (array) $api->contributors as $contrib_username => $contrib_profile ) {
    453                                         if ( empty( $contrib_username ) && empty( $contrib_profile ) )
     462                                        if ( empty( $contrib_username ) && empty( $contrib_profile ) ) {
    454463                                                continue;
    455                                         if ( empty( $contrib_username ) )
     464                                        }
     465                                        if ( empty( $contrib_username ) ) {
    456466                                                $contrib_username = preg_replace( '/^.+\/(.+)\/?$/', '\1', $contrib_profile );
     467                                        }
    457468                                        $contrib_username = sanitize_user( $contrib_username );
    458                                         if ( empty( $contrib_profile ) )
    459                                                 echo "<li><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&s=36' width='18' height='18' />{$contrib_username}</li>";
    460                                         else
    461                                                 echo "<li><a href='{$contrib_profile}' target='_blank'><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&s=36' width='18' height='18' />{$contrib_username}</a></li>";
     469                                        if ( empty( $contrib_profile ) ) {
     470                                                echo "<li><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&amp;s=36' width='18' height='18' />{$contrib_username}</li>";
     471                                        } else {
     472                                                echo "<li><a href='{$contrib_profile}' target='_blank'><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&amp;s=36' width='18' height='18' />{$contrib_username}</a></li>";
     473                                        }
    462474                                }
    463475                                ?>
    464476                        </ul>
    465                         <?php if ( ! empty( $api->donate_link ) ) : ?>
    466                                 <a target="_blank" href="<?php echo $api->donate_link ?>"><?php _e('Donate to this plugin &#187;') ?></a>
    467                         <?php endif; ?>
    468                 <?php endif; ?>
     477                        <?php if ( ! empty( $api->donate_link ) ) { ?>
     478                                <a target="_blank" href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin &#187;' ); ?></a>
     479                        <?php } ?>
     480                <?php } ?>
    469481        </div>
    470482        <div id="section-holder" class="wrap">
    471483        <?php
    472                 if ( ! empty( $api->tested ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->tested ) ), $api->tested, '>' ) )
     484                if ( ! empty( $api->tested ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->tested ) ), $api->tested, '>' ) ) {
    473485                        echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been tested</strong> with your current version of WordPress.') . '</p></div>';
    474 
    475                 else if ( ! empty( $api->requires ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->requires ) ), $api->requires, '<' ) )
     486                } else if ( ! empty( $api->requires ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->requires ) ), $api->requires, '<' ) ) {
    476487                        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>';
    477 
    478                 foreach ( (array)$api->sections as $section_name => $content ) {
    479 
     488                }
     489
     490                foreach ( (array) $api->sections as $section_name => $content ) {
    480491                        $content = links_add_base_url( $content, 'https://wordpress.org/plugins/' . $api->slug . '/' );
    481492                        $content = links_add_target( $content, '_blank' );
    … …  
    483494                        $san_section = esc_attr( $section_name );
    484495
    485                         $display = ( $section_name == $section ) ? 'block' : 'none';
     496                        $display = ( $section_name === $section ) ? 'block' : 'none';
    486497
    487498                        echo "\t<div id='section-{$san_section}' class='section' style='display: {$display};'>\n";
    … …  
    492503        echo "</div>\n";
    493504        echo "<div id='$tab-footer'>\n";
    494         if ( ! empty( $api->download_link ) && ( current_user_can('install_plugins') || current_user_can('update_plugins') ) ) {
    495                 $status = install_plugin_install_status($api);
     505        if ( ! empty( $api->download_link ) && ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) ) {
     506                $status = install_plugin_install_status( $api );
    496507                switch ( $status['status'] ) {
    497508                        case 'install':
    498                                 if ( $status['url'] )
    499                                         echo '<a class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __('Install Now') . '</a>';
     509                                if ( $status['url'] ) {
     510                                        echo '<a class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Now' ) . '</a>';
     511                                }
    500512                                break;
    501513                        case 'update_available':
    502                                 if ( $status['url'] )
    503                                         echo '<a class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __('Install Update Now') .'</a>';
     514                                if ( $status['url'] ) {
     515                                        echo '<a class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) .'</a>';
     516                                }
    504517                                break;
    505518                        case 'newer_installed':
    506                                 echo '<a class="button button-primary right disabled">' . sprintf(__('Newer Version (%s) Installed'), $status['version']) . '</a>';
     519                                echo '<a class="button button-primary right disabled">' . sprintf( __( 'Newer Version (%s) Installed'), $status['version'] ) . '</a>';
    507520                                break;
    508521                        case 'latest_installed':
    509                                 echo '<a class="button button-primary right disabled">' . __('Latest Version Installed') . '</a>';
     522                                echo '<a class="button button-primary right disabled">' . __( 'Latest Version Installed' ) . '</a>';
    510523                                break;
    511524                }
Note: See TracChangeset for help on using the changeset viewer.