Making WordPress.org


Ignore:
Timestamp:
06/20/2016 05:34:18 PM (7 years ago)
Author:
obenland
Message:

Plugin Directory: Documentation and formatting updates.

See #1584.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php

    r3495 r3511  
    1212     * Returns a string representing the number of active installs for an item.
    1313     *
    14      * @param bool              $full Whether to include "active installs" suffix. Default: true.
     14     * @static
     15     *
     16     * @param bool              $full Optional. Whether to include "active installs" suffix. Default: true.
    1517     * @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
    1618     * @return string "1+ million" or "1+ million active installs" depending on $full.
    1719     */
    18     static function active_installs( $full = true, $post = null ) {
    19         $post = get_post( $post );
    20 
     20    public static function active_installs( $full = true, $post = null ) {
     21        $post  = get_post( $post );
    2122        $count = get_post_meta( $post->ID, 'active_installs', true );
    2223
     
    2829            $text = number_format_i18n( $count ) . '+';
    2930        }
     31
    3032        return $full ? sprintf( __( '%s active installs', 'wporg-plugins' ), $text ) : $text;
    3133    }
    3234
    33 
    34     /**
    35      * @param \WP_Post|int $post Optional.
     35    /**
     36     * Returns the number of downloads for a plugin.
     37     *
     38     * @static
     39     * @global \wpdb $wpdb WordPress database abstraction object.
     40     *
     41     * @param int|\WP_Post|null $post Optional.
    3642     * @return int
    3743     */
    38     static function get_downloads_count( $post = null ) {
     44    public static function get_downloads_count( $post = null ) {
    3945        $post = get_post( $post );
    4046
     
    5258
    5359    /**
     60     * Returns the cumulative number of downloads of all plugins.
     61     *
     62     * @static
     63     * @global \wpdb $wpdb WordPress database abstraction object.
     64     *
    5465     * @return int
    5566     */
    56     static function get_total_downloads() {
     67    public static function get_total_downloads() {
    5768        if ( false === ( $count = wp_cache_get( 'plugin_download_count', 'plugin_download_count' ) ) ) {
    5869            global $wpdb;
     
    6778    /**
    6879     * Displays a plugin's rating with the amount of ratings it has received.
     80     *
     81     * @static
    6982     *
    7083     * @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
     
    87100
    88101    /**
     102     * Returns the available sections for a plugin.
     103     *
     104     * @static
     105     *
    89106     * @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
    90107     * @return array
    91108     */
    92     static function get_plugin_sections( $post = null ) {
     109    public static function get_plugin_sections( $post = null ) {
    93110        $plugin      = get_post( $post );
    94111        $plugin_slug = $plugin->post_name;
     
    109126        $raw_sections = array_unique( array_merge( $raw_sections, $default_sections ) );
    110127
    111         $sections     = array();
    112         $title = $url = '';
    113         $permalink    = get_permalink();
     128        $sections  = array();
     129        $title     = $url = '';
     130        $permalink = get_permalink();
    114131
    115132        foreach ( $raw_sections as $section_slug ) {
     
    183200     * Retrieve the Plugin Icon details for a plugin.
    184201     *
     202     * @static
     203     *
    185204     * @param \WP_Post|string $plugin An instance of a Plugin post, or the plugin slug.
    186      * @param string          $output Output type. 'html' or 'raw'. Default: 'raw'.
     205     * @param string          $output Optional. Output type. 'html' or 'raw'. Default: 'raw'.
    187206     * @return mixed
    188207     */
    189     static function get_plugin_icon( $plugin, $output = 'raw' ) {
     208    public static function get_plugin_icon( $plugin, $output = 'raw' ) {
    190209        $plugin = Plugin_Directory::instance()->get_plugin_post( $plugin );
    191210        if ( ! $plugin ) {
     
    209228                /* false = the resolution of the icon, this is NOT disabled */
    210229                case false && 'icon.svg' == $file:
    211                     $svg   = self::get_asset_url( $plugin_slug, $info );
     230                    $svg = self::get_asset_url( $plugin_slug, $info );
    212231                    break;
    213232            }
     
    226245            // Use the average color of the first known banner as the icon background color
    227246            if ( $color = get_post_meta( $plugin->ID, 'assets_banners_color', true ) ) {
    228                 if ( strlen( $color ) == 6 && strspn( $color, 'abcdef0123456789' ) == 6 ) {
     247                if ( strlen( $color ) === 6 && strspn( $color, 'abcdef0123456789' ) === 6 ) {
    229248                    $icon->setColor( '#' . $color );
    230249                }
     
    236255        switch ( $output ) {
    237256            case 'html':
    238                 $id   = "plugin-icon-{$plugin_slug}";
    239                 $html = "<style type='text/css'>";
     257                $id    = "plugin-icon-{$plugin_slug}";
     258                $html  = "<style type='text/css'>";
    240259                $html .= "#{$id} { background-image: url('{$icon}'); } .plugin-icon { background-size: 128px 128px; height: 128px; width: 128px; }";
    241260                if ( ! empty( $icon_2x ) && ! $generated ) {
     
    257276     * Retrieve the Plugin Icon details for a plugin.
    258277     *
     278     * @static
     279     *
    259280     * @param \WP_Post|string $plugin An instance of a Plugin post, or the plugin slug.
    260      * @param string          $output Output type. 'html' or 'raw'. Default: 'raw'.
     281     * @param string          $output Optional. Output type. 'html' or 'raw'. Default: 'raw'.
    261282     * @return mixed
    262283     */
    263     static function get_plugin_banner( $plugin, $output = 'raw' ) {
     284    public static function get_plugin_banner( $plugin, $output = 'raw' ) {
    264285        $plugin = Plugin_Directory::instance()->get_plugin_post( $plugin );
    265286        if ( ! $plugin ) {
     
    267288        }
    268289
    269         $banner = $banner_2x = false;
     290        $banner      = $banner_2x = false;
    270291        $plugin_slug = $plugin->post_name;
    271292        $raw_banners = get_post_meta( $plugin->ID, 'assets_banners', true );
    272293
    273294        // Split in rtl and non-rtl banners.
    274         $rtl_banners = array_filter( $raw_banners, function( $info ) {
     295        $rtl_banners = array_filter( $raw_banners, function ( $info ) {
    275296            return (bool) stristr( $info['filename'], '-rtl' );
    276297        } );
     
    310331        switch ( $output ) {
    311332            case 'html':
    312                 $id   = "plugin-banner-{$plugin_slug}";
    313                 $html = "<style type='text/css'>";
     333                $id    = "plugin-banner-{$plugin_slug}";
     334                $html  = "<style type='text/css'>";
    314335                $html .= "#{$id} { background-image: url('{$banner}'); }";
    315336                if ( ! empty( $banner_2x ) ) {
     
    329350
    330351    /**
    331      * @param $plugin
    332      * @param $asset
     352     * Generates and returns the URL to a passed asset.
     353     *
     354     * Assets can be screenshots, icons, banners, etc.
     355     *
     356     * @static
     357     *
     358     * @param string $plugin Plugin slug.
     359     * @param array  $asset  Assets folder information.
    333360     * @return string
    334361     */
    335     static function get_asset_url( $plugin, $asset ) {
     362    public static function get_asset_url( $plugin, $asset ) {
    336363        if ( ! empty( $asset['location'] ) && 'plugin' == $asset['location'] ) {
    337             // Screenshots in the plugin folder - /plugins/plugin-name/screenshot-1.png
     364
     365            // Screenshots in the plugin folder - /plugins/plugin-name/screenshot-1.png.
    338366            $format = 'https://s.w.org/plugins/%s/%s?rev=%s';
    339367        } else {
    340             // Images in the assets folder - /plugin-name/assets/screenshot-1.png
     368
     369            // Images in the assets folder - /plugin-name/assets/screenshot-1.png.
    341370            $format = 'https://ps.w.org/%s/assets/%s?rev=%s';
    342371        }
     
    353382     * A helper method to create dashicon stars.
    354383     *
    355      * @type int|array {
     384     * @static
     385     *
     386     * @param int|array $args {
    356387     *    If numeric arg passed, assumed to be 'rating'.
    357388     *
     
    362393     * @return string The Rating HTML.
    363394     */
    364     static function dashicons_stars( $args = array() ) {
    365         $defaults = array(
    366             'rating' => 0,
    367             'template' => '<span class="%1$s"></span>'
    368         );
    369         $r = wp_parse_args( ( is_numeric( $args ) ? array( 'rating' => $args ) : $args ), $defaults );
    370 
    371         $rating = round( $r['rating'] / 0.5 ) * 0.5;
    372         $template = $r['template'];
     395    public static function dashicons_stars( $args = array() ) {
     396        $args = wp_parse_args( ( is_numeric( $args ) ? array( 'rating' => $args ) : $args ), array(
     397            'rating'   => 0,
     398            'template' => '<span class="%1$s"></span>',
     399        ) );
     400
     401        $rating         = round( $args['rating'] / 0.5 ) * 0.5;
     402        $template       = $args['template'];
    373403        $title_template = __( '%s out of 5 stars', 'wporg-plugins' );
    374         $title = sprintf( $title_template, $rating );
    375 
    376         $output = '<div class="wporg-ratings" title="' . esc_attr( $title ) . '" data-title-template="' . esc_attr( $title_template ) . '" data-rating="' . esc_attr( $rating ) . '" style="color:#ffb900;">';
     404        $title          = sprintf( $title_template, $rating );
     405
     406        $output  = '<div class="wporg-ratings" title="' . esc_attr( $title ) . '" data-title-template="' . esc_attr( $title_template ) . '" data-rating="' . esc_attr( $rating ) . '" style="color:#ffb900;">';
    377407        $counter = round( $rating * 2 );
    378         for  ( $i = 1; $i <= 5; $i++ ) {
    379             switch ($counter) {
    380             case 0:
    381                 $output .= sprintf( $template, 'dashicons dashicons-star-empty', $i );
    382                 break;
    383             case 1:
    384                 $output .= sprintf( $template, 'dashicons dashicons-star-half', $i );
    385                 $counter--;
    386                 break;
    387             default:
    388                 $output .= sprintf( $template, 'dashicons dashicons-star-filled', $i );
    389                 $counter -= 2;
    390                 break;
     408        for ( $i = 1; $i <= 5; $i++ ) {
     409            switch ( $counter ) {
     410                case 0:
     411                    $output .= sprintf( $template, 'dashicons dashicons-star-empty', $i );
     412                    break;
     413
     414                case 1:
     415                    $output .= sprintf( $template, 'dashicons dashicons-star-half', $i );
     416                    $counter--;
     417                    break;
     418
     419                default:
     420                    $output  .= sprintf( $template, 'dashicons dashicons-star-filled', $i );
     421                    $counter -= 2;
     422                    break;
    391423            }
    392424        }
    393425        $output .= '</div>';
     426
    394427        return $output;
    395428    }
    396429
    397430    /**
    398      * Generate a Download link for a given plugin & version.
     431     * Generate a download link for a given plugin & version.
    399432     *
    400433     * @param \WP_Post $post    The Plugin Post.
     
    419452     * Properly encodes a string to UTF-8.
    420453     *
     454     * @static
     455     *
    421456     * @param string $string
    422457     * @return string
Note: See TracChangeset for help on using the changeset viewer.