Making WordPress.org

Changeset 3009


Ignore:
Timestamp:
04/26/2016 07:33:28 AM (10 years ago)
Author:
dd32
Message:

Plugin Directory: Add a Review Widget to the theme, and all the other required things for Widgets.
This adds a namespace to the theme and begins to reduce the duplication of template functionality between wp-admin and the theme.

See #1584.
Fixes #1575.

Location:
sites/trunk/wordpress.org/public_html/wp-content
Files:
3 added
14 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/list-table/class-plugin-posts.php

    r2998 r3009  
    22namespace WordPressdotorg\Plugin_Directory\Admin\List_Table;
    33use \WordPressdotorg\Plugin_Directory\Tools;
     4use \WordPressdotorg\Plugin_Directory\Template;
    45
    56_get_list_table( 'WP_Posts_List_Table' );
     
    159160         */
    160161        public function column_rating( $post ) {
    161                 if ( function_exists( 'wporg_get_dashicons_stars' ) ) {
    162                         echo wporg_get_dashicons_stars( get_post_meta( $post->ID, 'rating', true ) );
    163                 }
     162                echo Template::dashicons_stars( get_post_meta( $post->ID, 'rating', true ) );
    164163        }
    165164
     
    170169         */
    171170        public function column_installs( $post ) {
    172                 $active_installs = get_post_meta( $post->ID, 'active_installs', true );
    173                 if ( $active_installs >= 1000000 ) {
    174                         _e( '1+ million', 'wporg-plugins' );
    175                 } elseif ( $active_installs <= 10 ) {
    176                         _e( 'Less than 10', 'wporg-plugins' );
    177                 } else {
    178                         printf( "%s+", number_format_i18n( $active_installs ) );
    179                 }
     171                echo Template::active_installs( false, $post );
    180172        }
    181173
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    r2998 r3009  
    2222                add_action( 'init', array( $this, 'init' ) );
    2323                add_action( 'init', array( $this, 'register_shortcodes' ) );
     24                add_action( 'widgets_init', array( $this, 'register_widgets' ) );
    2425                add_filter( 'post_type_link', array( $this, 'package_link' ), 10, 2 );
    2526                add_filter( 'pre_insert_term', array( $this, 'pre_insert_term_prevent' ) );
     
    3233
    3334                // Shim in postmeta support for data which doesn't yet live in postmeta
    34                 add_filter( 'get_post_metadata', array( $this, 'filter_shim_postmeta' ), 10, 4 );
     35                add_filter( 'get_post_metadata', array( $this, 'filter_shim_postmeta' ), 10, 3 );
    3536
    3637                // Load the API routes
     
    196197        }
    197198
     199        public function register_widgets() {
     200                register_widget( __NAMESPACE__ . '\Widgets\Metadata' );
     201                register_widget( __NAMESPACE__ . '\Widgets\Ratings' );
     202        }
     203
    198204        /**
    199205         * Upon plugin activation, set up the current site for acting
     
    423429         * @param int               $object_id Object ID.
    424430         * @param string            $meta_key  Meta key.
    425          * @param bool              $single    Whether to return only the first value of the specified $meta_key.
    426          */
    427         public function filter_shim_postmeta( $value, $object_id, $meta_key, $single ) {
     431         */
     432        public function filter_shim_postmeta( $value, $object_id, $meta_key ) {
    428433                switch ( $meta_key ) {
    429434                        case 'downloads':
     
    431436                                $count = Template::get_downloads_count( $post );
    432437
    433                                 return $single ? $count : array( $count );                             
     438                                return array( $count );                         
    434439                                break;
    435440                        case 'rating':
     
    441446                                $rating = wporg_get_rating_avg( 'plugin', $post->post_name );
    442447
    443                                 return $single ? $rating : array( $rating );
     448                                return array( $rating );
     449                                break;
     450                        case 'ratings':
     451                                $post = get_post( $object_id );
     452                                if ( ! function_exists( 'wporg_get_rating_counts' ) ) {
     453                                        break;
     454                                }
     455                                $ratings = wporg_get_rating_counts( 'plugin', $post->post_name );
     456
     457                                return array( $ratings );
    444458                                break;
    445459                }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php

    r2994 r3009  
    1010
    1111        /**
    12          * @param \WP_Post|int $post Optional.
    13          * @return int
    14          */
    15         static function get_active_installs_count( $post = null ) {
     12         * Returns a string representing the number of active installs for an item.
     13         *
     14         * @param bool $full whether to include "actuve installs" suffix. Default: true.
     15         * @return string "1+ million" or "1+ milllion active installs" depending on $full.
     16         */
     17        static function active_installs( $full = true, $post = null ) {
    1618                $post = get_post( $post );
    1719
    18                 return (int) get_post_meta( $post->ID, 'active_installs', true );
    19         }
     20                $count = get_post_meta( $post->ID, 'active_installs', true );
     21       
     22                if ( $count <= 10 ) {
     23                        $text = __( 'Less than 10', 'wporg-plugins' );
     24                } elseif ( $count >= 1000000 ) {
     25                        $text = __( '1+ million', 'wporg-plugins' );
     26                } else {
     27                        $text = number_format_i18n( $count ) . '+';
     28                }
     29                return $full ? sprintf( __( '%s active installs', 'wporg-plugins' ), $text ) : $text;
     30        }
     31
    2032
    2133        /**
     
    276288                ) );
    277289        }
     290
     291        /**
     292         * A helper method to create dashicon stars.
     293         *
     294         * @type int|array {
     295         *    If numeric arg passed, assumed to be 'rating'.
     296         *
     297         *    @type int    $rating   The rating to display.
     298         *    @type string $template The HTML template to use for each star.
     299         *                           %1$s is the class, %2$s is the rating.
     300         * }
     301         * @return string The Rating HTML.
     302         */
     303        static function dashicons_stars( $args = array() ) {
     304                $defaults = array(
     305                        'rating' => 0,
     306                        'template' => '<span class="%1$s"></span>'
     307                );
     308                $r = wp_parse_args( ( is_numeric( $args ) ? array( 'rating' => $args ) : $args ), $defaults );
     309
     310                $rating = round( $r['rating'] / 0.5 ) * 0.5;
     311                $template = $r['template'];
     312                $title_template = __( '%s out of 5 stars', 'wporg-plugins' );
     313                $title = sprintf( $title_template, $rating );
     314
     315                $output = '<div class="wporg-ratings" title="' . esc_attr( $title ) . '" data-title-template="' . esc_attr( $title_template ) . '" data-rating="' . esc_attr( $rating ) . '" style="color:#ffb900;">';
     316                $counter = round( $rating * 2 );
     317                for  ( $i = 1; $i <= 5; $i++ ) {
     318                        switch ($counter) {
     319                        case 0:
     320                                $output .= sprintf( $template, 'dashicons dashicons-star-empty', $i );
     321                                break;
     322                        case 1:
     323                                $output .= sprintf( $template, 'dashicons dashicons-star-half', $i );
     324                                $counter--;
     325                                break;
     326                        default:
     327                                $output .= sprintf( $template, 'dashicons dashicons-star-filled', $i );
     328                                $counter -= 2;
     329                                break;
     330                        }
     331                }
     332                $output .= '</div>';
     333                return $output;
     334        }
     335       
    278336}
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/filter-bar.php

    r2502 r3009  
     1<?php
     2namespace WordPressdotorg\Plugin_Directory\Theme;
     3
     4?>
    15<div class="wrapper">
    26        <div class="col-12 filter-bar">
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/footer.php

    r2499 r3009  
    11<?php
     2namespace WordPressdotorg\Plugin_Directory\Theme;
     3
    24/**
    35 * The template for displaying the footer.
     
    57 * @package wporg-plugins
    68 */
    7 ?>
    8 </div>
    99
    10 <?php require WPORGPATH . 'footer.php';
     10echo '</div>';
     11
     12require WPORGPATH . 'footer.php';
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/functions.php

    r2499 r3009  
    11<?php
     2namespace WordPressdotorg\Plugin_Directory\Theme;
    23
    34/**
     
    1819        ) );
    1920
     21        register_sidebar( array(
     22                'name'          => 'Single Plugin View Sidebar',
     23                'id'            => 'single-plugin-sidebar',
     24                'before_widget' => '<div id="%1$s" class="widget %2$s">',
     25                'after_widget'  => '</div>',
     26        ) );
     27
    2028        // No need for canonical lookups
    21         //remove_action( 'template_redirect', 'redirect_canonical' );
    22         remove_action( 'template_redirect', 'wp_old_slug_redirect' );
     29        remove_action( 'template_redirect', __NAMESPACE__ . '\wp_old_slug_redirect' );
    2330}
    24 add_action( 'after_setup_theme', 'wporg_plugins_setup' );
     31add_action( 'after_setup_theme', __NAMESPACE__ . '\wporg_plugins_setup' );
    2532
    2633/**
     
    4552        add_filter( 'jetpack_implode_frontend_css', '__return_false' );
    4653}
    47 add_action( 'wp_enqueue_scripts', 'wporg_plugins_scripts' );
     54add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\wporg_plugins_scripts' );
    4855
    4956function wporg_plugins_body_class( $classes ) {
     
    5158        return $classes;
    5259}
    53 add_filter( 'body_class', 'wporg_plugins_body_class' );
     60add_filter( 'body_class', __NAMESPACE__ . '\wporg_plugins_body_class' );
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/header.php

    r2499 r3009  
    11<?php
     2namespace WordPressdotorg\Plugin_Directory\Theme;
     3
    24/**
    35 * The header for our theme.
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/index.php

    r2499 r3009  
    1 <?php get_header(); ?>
     1<?php
     2namespace WordPressdotorg\Plugin_Directory\Theme;
     3
     4get_header();
     5?>
    26
    37<?php get_template_part( 'filter-bar' ); ?>
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/page.php

    r2499 r3009  
    1 <?php get_header(); ?>
     1<?php
     2namespace WordPressdotorg\Plugin_Directory\Theme;
     3
     4get_header();
     5?>
    26
    37<?php the_post(); ?>
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/plugin-card.php

    r2998 r3009  
     1<?php
     2namespace WordPressdotorg\Plugin_Directory\Theme;
     3use WordPressdotorg\Plugin_Directory\Template;
     4
     5?>
    16<div class="plugin-card">
    27         <div class="plugin-card-top">
    38
    49                 <a href="<?php the_permalink(); ?>" class="plugin-icon">
    5                         <?php echo WordPressdotorg\Plugin_Directory\Template::get_plugin_icon( $post->post_name, 'html' ); ?>
     10                        <?php echo Template::get_plugin_icon( $post->post_name, 'html' ); ?>
    611                 </a>
    712                 <div class="name column-name">
     
    1621        <div class="plugin-card-bottom">
    1722                <div class="vers column-rating">
    18                         <?php
    19                                 if ( function_exists( 'wporg_get_dashicons_stars' ) ) {
    20                                         echo wporg_get_dashicons_stars( get_post_meta( $post->ID, 'rating', true ) );
    21                                 }
    22                         ?>
     23                        <?php echo Template::dashicons_stars( get_post_meta( $post->ID, 'rating', true ) ); ?>
    2324                </div>
    2425                <div class="column-updated">
     
    2627                </div>
    2728                <div class="column-installs">
    28                         <?php echo worg_plugins_template_active_installs( true ); ?>
     29                        <?php echo Template::active_installs(); ?>
    2930                </div>
    3031                <div class="column-compatibility">
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/single-plugin.php

    r2654 r3009  
    11<?php
     2namespace WordPressdotorg\Plugin_Directory\Theme;
     3use WordPressdotorg\Plugin_Directory\Template;
     4
    25the_post();
    36get_header();
    4 $plugin_banners = WordPressdotorg\Plugin_Directory\Template::get_plugin_banner( $post );
     7$plugin_banners = Template::get_plugin_banner( $post );
    58
    69?>
     
    4649                                                <ul id="sections">
    4750                                                        <?php
    48                                                         foreach ( WordPressdotorg\Plugin_Directory\Template::get_plugin_sections() as $section ) {
     51                                                        foreach ( Template::get_plugin_sections() as $section ) {
    4952                                                                $current = ( $section['slug'] == get_query_var( 'content_page' ) || ( 'description' == $section['slug'] && ! get_query_var( 'content_page' ) ) );
    5053                                                                printf(
     
    6669
    6770                        <div class="" style="width: 212px; float: right;">
    68                                 <p>
    69                                         <strong>Version:</strong> <?php echo wporg_plugins_the_version(); ?><br>
    70                                         <strong>Requires:</strong> <?php printf( __('%s or higher', 'wporg-plugins' ), wporg_plugins_template_requires() ); ?><br>
    71                                         <strong>Compatible up to:</strong> <?php echo wporg_plugins_template_compatible_up_to(); ?><br>
    72                                         <strong>Last Updated: </strong> <?php echo wporg_plugins_template_last_updated(); ?><br>
    73                                         <strong>Active Installs:</strong> <?php echo worg_plugins_template_active_installs( false ); ?><br>
    74                                         <meta itemprop="dateModified" content="<?php the_time('Y-m-d'); ?>" />
    75                                 </p>
     71                                <?php dynamic_sidebar('single-plugin-sidebar'); ?>
    7672                        </div>
    7773
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/style.css

    r2973 r3009  
    14481448        background-color: inherit;
    14491449}
     1450
     1451.widget {
     1452        margin-bottom: 1em;
     1453
     1454}
     1455
     1456/* Ratings */
     1457.widget.plugin-ratings {
     1458        margin: 0 0 1.5em;
     1459        min-height: 26px;
     1460}
     1461
     1462.rtl .dashicons-star-half:before {
     1463        -webkit-transform: rotateY(180deg);
     1464        -ms-transform: rotateY(180deg);
     1465        transform: rotateY(180deg);
     1466}
     1467
     1468.widget.plugin-ratings a.dashicons {
     1469        color: inherit;
     1470}
     1471
     1472.widget.plugin-ratings .description {
     1473        color: #aa9;
     1474        display: inline-block;
     1475        font-style: italic;
     1476        margin: 0 5px;
     1477        vertical-align: text-bottom;
     1478}
     1479.widget.plugin-ratings ul.ratings-list {
     1480        list-style-type: none;
     1481        padding: 0;
     1482        margin: 0 !important;
     1483}
     1484.widget.plugin-ratings .counter-container,
     1485.widget.plugin-ratings .counter-container a {
     1486        display: inline-block;
     1487        width: 100%;
     1488}
     1489.widget.plugin-ratings .counter-label,
     1490.widget.plugin-ratings .counter-count {
     1491        line-height: 1.75;
     1492}
     1493.widget.plugin-ratings .counter-label {
     1494        float: left;
     1495        margin-right: 5px;
     1496        min-width: 55px;
     1497}
     1498.widget.plugin-ratings .counter-back,
     1499.widget.plugin-ratings .counter-bar {
     1500        float: left;
     1501        height: 17px;
     1502}
     1503.widget.plugin-ratings .counter-back {
     1504        background-color: #ececec;
     1505        width: 64%;
     1506        width: -webkit-calc(100% - 88px);
     1507        width: calc(100% - 88px);
     1508}
     1509.widget.plugin-ratings .counter-bar {
     1510        background-color: #ffc733;
     1511}
     1512.widget.plugin-ratings .counter-count {
     1513        float: left;
     1514        margin-left: 5px;
     1515}
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/template-tags.php

    r2986 r3009  
    11<?php
     2namespace WordPressdotorg\Plugin_Directory\Theme;
     3use WordPressdotorg\Plugin_Directory\Template;
    24
    35// Various Template tags
     
    3032
    3133function wporg_plugins_download_link() {
    32         $filename = sprintf( "%s.%s.zip", get_post()->post_name, wporg_plugins_the_version() );
    33         return esc_url( "https://downloads.wordpress.org/plugin/{$filename}" );
    34 }
    35 
    36 function worg_plugins_template_active_installs( $full = true ) {
    37         $count = WordPressdotorg\Plugin_Directory\Template::get_active_installs_count();
    38 
    39         if ( $count <= 10 ) {
    40                 $text = __( 'Less than 10', 'wporg-plugins' );
    41         } elseif ( $count >= 1000000 ) {
    42                 $text = __( '1+ million', 'wporg-plugins' );
    43         } else {
    44                 $text = number_format_i18n( $count ) . '+';
    45         }
    46         return $full ? sprintf( __( '%s active installs', 'wporg-plugins' ), $text ) : $text;
     34        return esc_url( sprintf( "https://downloads.wordpress.org/plugin/%s.%s.zip", get_post()->post_name, wporg_plugins_the_version() ) );
    4735}
    4836
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/view-intro.php

    r2612 r3009  
    11<?php
     2namespace WordPressdotorg\Plugin_Directory\Theme;
     3use WordPressdotorg\Plugin_Directory\Template;
    24
    35if ( is_front_page() && ( ! get_query_var( 'browse' ) || 'featured' == get_query_var( 'browse' ) ) ) {
     
    68                        '<p class="intro">' . __( 'Plugins extend and expand the functionality of WordPress. %1$s plugins with %2$s total downloads are at your fingertips.', 'wporg-plugins' ) . '</p>',
    79                        '<strong>' . number_format_i18n( wp_count_posts( 'plugin' )->publish ) . '</strong>',
    8                         '<strong>' . number_format_i18n( WordPressdotorg\Plugin_Directory\Template::get_total_downloads() ) . '</strong>'
     10                        '<strong>' . number_format_i18n( Template::get_total_downloads() ) . '</strong>'
    911        );
    1012}
Note: See TracChangeset for help on using the changeset viewer.