Making WordPress.org

Changeset 3511


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

Plugin Directory: Documentation and formatting updates.

See #1584.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
7 edited

Legend:

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

    r3225 r3511  
    22namespace WordPressdotorg\Plugin_Directory;
    33use WordPressdotorg\Plugin_Directory\Tools;
     4
    45/**
    56 * Manages the capabilities for the WordPress.org plugins directory.
    … …  
    1112        /**
    1213         * Filters a user's capabilities depending on specific context and/or privilege.
     14         *
     15         * @static
    1316         *
    1417         * @param array  $required_caps Returns the user's actual capabilities.
    … …  
    7275        }
    7376
     77        /**
     78         * Sets up custom roles and makes them available.
     79         *
     80         * @static
     81         */
    7482        public static function add_roles() {
    7583                $committer = array(
    76                         'read' => true,
     84                        'read'                    => true,
    7785                        'plugin_dashboard_access' => true,
    78                         'plugin_edit_own' => true,
    79                         'plugin_set_category' => true,
    80                         'plugin_add_committer' => true,
    81                         'plugin_edit_others' => true,
     86                        'plugin_edit_own'         => true,
     87                        'plugin_set_category'     => true,
     88                        'plugin_add_committer'    => true,
     89                        'plugin_edit_others'      => true,
    8290                );
    8391
    8492                $reviewer = array_merge( $committer, array(
    85                         'moderate_comments' => true,
     93                        'moderate_comments'   => true,
    8694                        'plugin_edit_pending' => true,
    87                         'plugin_review' => true,
     95                        'plugin_review'       => true,
    8896                ) );
    8997
    9098                $admin = array_merge( $reviewer, array(
    91                         'plugin_approve' => true,
    92                         'plugin_reject' => true,
    93                         'plugin_disable' => true,
    94                         'plugin_close' => true,
     99                        'plugin_approve'     => true,
     100                        'plugin_reject'      => true,
     101                        'plugin_disable'     => true,
     102                        'plugin_close'       => true,
    95103                        'plugin_set_section' => true, // Special categories.
    96                         'manage_categories' => true, // Let them assign these special categories.
     104                        'manage_categories'  => true, // Let them assign these special categories.
    97105                ) );
    98106
    99107                // Remove the roles first, incase we've changed the permission set.
    100108                remove_role( 'plugin_committer' );
    101                 remove_role( 'plugin_reviewer' );
    102                 remove_role( 'plugin_admin' );
     109                remove_role( 'plugin_reviewer'  );
     110                remove_role( 'plugin_admin'     );
    103111                add_role( 'plugin_committer', 'Plugin Committer', $committer );
    104                 add_role( 'plugin_reviewer',  'Plugin Reviewer',  $reviewer );
    105                 add_role( 'plugin_admin',     'Plugin Admin',     $admin );
     112                add_role( 'plugin_reviewer',  'Plugin Reviewer',  $reviewer  );
     113                add_role( 'plugin_admin',     'Plugin Admin',     $admin     );
    106114
    107                 foreach( array( 'contributor', 'author', 'editor', 'administrator' ) as $role ) {
     115                foreach ( array( 'contributor', 'author', 'editor', 'administrator' ) as $role ) {
    108116                        $wp_role = get_role( $role );
    109117
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-i18n.php

    r3438 r3511  
    77 * @package WordPressdotorg\Plugin_Directory
    88 */
    9 class i18n {
     9class I18n {
    1010
    1111        /**
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-markdown.php

    r3180 r3511  
    1515class Markdown extends \Michelf\MarkdownExtra {
    1616
     17        /**
     18         * @param string $text
     19         * @return string
     20         */
    1721        public function transform( $text ) {
    1822                $text = $this->code_trick( trim( $text ) );
    19                 // Convert any `= Section =` headers into a real header
     23
     24                // Convert any `= Section =` headers into a real header.
    2025                $text = preg_replace( '/^[\s]*=[\s]+(.+?)[\s]+=/m', "\n" . '<h4>$1</h4>' . "\n", $text );
    2126
    … …  
    2530        }
    2631
     32        /**
     33         * @access protected
     34         *
     35         * @param string $text
     36         * @return string
     37         */
    2738        protected function code_trick( $text ) {
    28                 // when doing markdown, first take any user formatted code blocks and turn them into backticks so that
    29                 // markdown will preserve things like underscores in code blocks
     39
     40                /*
     41                 * When doing markdown, first take any user formatted code blocks and turn them into backticks so that
     42                 * markdown will preserve things like underscores in code blocks.
     43                 */
    3044                $text = preg_replace_callback( "!(<pre><code>|<code>)(.*?)(</code></pre>|</code>)!s", array( $this, 'code_trick_decodeit_cb' ), $text );
    3145                $text = str_replace( array( "\r\n", "\r" ), "\n", $text );
    3246
    33                 // Markdown can do inline code, we convert bbPress style block level code to Markdown style
     47                // Markdown can do inline code, we convert bbPress style block level code to Markdown style.
    3448                $text = preg_replace_callback( "!(^|\n)([ \t]*?)`(.*?)`!s", array( $this, 'code_trick_indent_cb' ), $text );
    3549
    … …  
    3751        }
    3852
     53        /**
     54         * @access protected
     55         *
     56         * @param array $matches
     57         * @return string
     58         */
    3959        protected function code_trick_indent_cb( $matches ) {
    4060                $text = $matches[3];
    … …  
    4464        }
    4565
     66        /**
     67         * @access protected
     68         *
     69         * @param array $matches
     70         * @return string
     71         */
    4672        protected function code_trick_decodeit_cb( $matches ) {
    47                 $text        = $matches[2];
    4873                $trans_table = array_flip( get_html_translation_table( HTML_ENTITIES ) );
    49                 $text        = strtr( $text, $trans_table );
    50                 $text        = str_replace( '<br />', '', $text );
    51                 $text        = str_replace( '&#38;', '&', $text );
    52                 $text        = str_replace( '&#39;', "'", $text );
     74
     75                $text = $matches[2];
     76                $text = strtr( $text, $trans_table );
     77                $text = str_replace( '<br />', '', $text );
     78                $text = str_replace( '&#38;', '&', $text );
     79                $text = str_replace( '&#39;', "'", $text );
    5380
    5481                if ( '<pre><code>' == $matches[1] ) {
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    r3506 r3511  
    1212
    1313        /**
    14          * Local cache for translated content injected into meta
     14         * Local cache for translated content injected into meta.
     15         *
     16         * @access private
     17         *
     18         * @var array
    1519         */
    1620        private $i18n_meta = array();
    … …  
    1822        /**
    1923         * Fetch the instance of the Plugin_Directory class.
     24         *
     25         * @static
    2026         */
    2127        public static function instance() {
    … …  
    2531        }
    2632
     33        /**
     34         * Plugin_Directory constructor.
     35         *
     36         * @access private
     37         */
    2738        private function __construct() {
    2839                add_action( 'init', array( $this, 'init' ) );
    … …  
    4455                add_filter( 'oembed_providers', array( $this, 'oembed_whitelist' ) );
    4556
    46                 // Shim in postmeta support for data which doesn't yet live in postmeta
     57                // Shim in postmeta support for data which doesn't yet live in postmeta.
    4758                add_filter( 'get_post_metadata', array( $this, 'filter_shim_postmeta' ), 10, 3 );
    4859
    4960                add_filter( 'map_meta_cap', array( __NAMESPACE__ . '\Capabilities', 'map_meta_cap' ), 10, 4 );
    5061
    51                 // Load the API routes
     62                // Load the API routes.
    5263                add_action( 'rest_api_init', array( __NAMESPACE__ . '\API\Base', 'load_routes' ) );
    5364
    54                 // Load all Admin-specific items.
    55                 // Cannot be included on `admin_init` to allow access to menu hooks
     65                /*
     66                 * Load all Admin-specific items.
     67                 * Cannot be included on `admin_init` to allow access to menu hooks.
     68                 */
    5669                if ( defined( 'WP_ADMIN' ) && WP_ADMIN ) {
    5770                        Customizations::instance();
    5871
    59                         add_action( 'wp_insert_post_data', array( __NAMESPACE__ . '\Admin\Status_Transitions', 'can_change_post_status' ), 10, 2 );
     72                        add_action( 'wp_insert_post_data',    array( __NAMESPACE__ . '\Admin\Status_Transitions', 'can_change_post_status' ), 10, 2 );
    6073                        add_action( 'transition_post_status', array( __NAMESPACE__ . '\Admin\Status_Transitions', 'instance' ) );
    6174                }
    … …  
    7487
    7588                register_post_type( 'plugin', array(
    76                         'labels'          => array(
     89                        'labels'       => array(
    7790                                'name'               => __( 'Plugins',                   'wporg-plugins' ),
    7891                                'singular_name'      => __( 'Plugin',                    'wporg-plugins' ),
    … …  
    105118                                'delete_posts'       => 'do_not_allow',
    106119                                'create_posts'       => 'do_not_allow',
    107                         )
     120                        ),
    108121                ) );
    109122
    … …  
    148161                        'capabilities'      => array(
    149162                                'assign_terms' => 'plugin_set_category',
    150                         )
     163                        ),
    151164                ) );
    152165
    … …  
    156169                        'rewrite'           => false,
    157170                        'labels'            => array(
    158                                 'name'          => __( 'Built For', 'wporg-plugins' ),
     171                                'name' => __( 'Built For', 'wporg-plugins' ),
    159172                        ),
    160173                        'public'            => true,
    … …  
    164177                        'capabilities'      => array(
    165178                                'assign_terms' => 'plugin_set_category',
    166                         )
     179                        ),
    167180                ) );
    168181
    … …  
    172185                        'rewrite'           => false,
    173186                        'labels'            => array(
    174                                 'name'          => __( 'Business Model', 'wporg-plugins' ),
     187                                'name' => __( 'Business Model', 'wporg-plugins' ),
    175188                        ),
    176189                        'public'            => true,
    … …  
    180193                        'capabilities'      => array(
    181194                                'assign_terms' => 'plugin_set_category',
    182                         )
     195                        ),
    183196                ) );
    184197
    … …  
    220233                // /browse/ should be the popular archive view.
    221234                add_rewrite_rule( '^browse$', 'index.php?browse=popular', 'top' );
     235
    222236                // Create an archive for a users favorites too.
    223237                add_rewrite_rule( '^browse/favorites/([^/]+)$', 'index.php?browse=favorites&favorites_user=$matches[1]', 'top' );
    224238
    225                 // Handle the old plugin tabs URLs
     239                // Handle the old plugin tabs URLs.
    226240                add_rewrite_rule( '^([^/]+)/(installation|faq|screenshots|changelog|stats|developers|other_notes)$', 'index.php?redirect_plugin_tab=$matches[1]/#$matches[2]', 'top' );
    227241
    … …  
    229243                //Capabilities::add_roles();
    230244
    231                 // When this plugin is used in the context of a Rosetta site, handle it gracefully
     245                // When this plugin is used in the context of a Rosetta site, handle it gracefully.
    232246                if ( 'wordpress.org' != $_SERVER['HTTP_HOST'] && defined( 'WPORG_PLUGIN_DIRECTORY_BLOGID' ) ) {
    233247                        add_filter( 'option_home',    array( $this, 'rosetta_network_localize_url' ) );
    … …  
    236250
    237251                if ( 'en_US' != get_locale() ) {
    238                         add_filter( 'get_term', array( __NAMESPACE__ . '\i18n', 'translate_term' ) );
     252                        add_filter( 'get_term', array( __NAMESPACE__ . '\I18n', 'translate_term' ) );
    239253                        add_filter( 'the_content', array( $this, 'translate_post_content' ), 1, 2 );
    240254                        add_filter( 'the_title', array( $this, 'translate_post_title' ), 1, 2 );
    … …  
    250264                // When Jetpack syncs, we want to add filters to inject additional metadata for Jetpack, so it syncs for ElasticSearch indexing.
    251265                add_action( 'shutdown', array( $this, 'append_meta_for_jetpack' ), 8 );
    252 
    253266        }
    254267
    … …  
    263276        }
    264277
     278        /**
     279         *  Register the Widgets used plugin detail pages.
     280         */
    265281        public function register_widgets() {
    266                 register_widget( __NAMESPACE__ . '\Widgets\Donate' );
    267                 register_widget( __NAMESPACE__ . '\Widgets\Meta' );
     282                register_widget( __NAMESPACE__ . '\Widgets\Donate'  );
     283                register_widget( __NAMESPACE__ . '\Widgets\Meta'    );
    268284                register_widget( __NAMESPACE__ . '\Widgets\Ratings' );
    269285                register_widget( __NAMESPACE__ . '\Widgets\Support' );
    … …  
    391407                }
    392408                if ( 'plugin_built_for' == $term->taxonomy ) {
     409
    393410                        // Term slug = Post Slug = /%postname%/
    394411                        return trailingslashit( home_url( $term->slug ) );
    … …  
    429446                }
    430447
    431                 switch ( $wp_query->query_vars['browse'] ) {
     448                switch ( $wp_query->get( 'browse' ) ) {
    432449                        case 'favorites':
    433450                                $favorites_user = wp_get_current_user();
    434                                 if ( !empty( $wp_query->query_vars['favorites_user'] ) ) {
     451                                if ( ! empty( $wp_query->query_vars['favorites_user'] ) ) {
    435452                                        $favorites_user = $wp_query->query_vars['favorites_user'];
    436                                 } elseif ( !empty( $_GET['favorites_user'] ) ) {
     453                                } elseif ( ! empty( $_GET['favorites_user'] ) ) {
    437454                                        $favorites_user = $_GET['favorites_user'];
    438455                                }
    … …  
    450467                                        $wp_query->query_vars['p'] = -1;
    451468                                }
    452 
    453469                                break;
    454470
    455471                        case 'new':
    456                                 $wp_query->query_vars['orderby']  = 'post_modified';
     472                                $wp_query->query_vars['orderby'] = 'post_modified';
    457473                                break;
    458474                }
    459475
    460                 if ( isset( $wp_query->query['browse'] ) ) {
    461                         if ( 'beta' != $wp_query->query['browse'] && 'featured' != $wp_query->query['browse'] ) {
    462                                 unset( $wp_query->query_vars['browse'] );
    463 
    464                                 add_filter( 'the_posts', function( $posts, $wp_query ) {
    465                                         // Fix the queried object for the archive view
    466                                         if ( ! $wp_query->queried_object && isset( $wp_query->query['browse'] ) ) {
    467                                                 $wp_query->query_vars['browse'] = $wp_query->query['browse'];
    468                                                 $wp_query->queried_object = get_term_by( 'slug', $wp_query->query['browse'], 'plugin_section' );
    469                                         }
    470                                         return $posts;
    471                                 }, 10, 2 );
    472 
    473                         }
     476                if ( isset( $wp_query->query['browse'] ) && 'beta' != $wp_query->query['browse'] && 'featured' != $wp_query->query['browse'] ) {
     477                        unset( $wp_query->query_vars['browse'] );
     478
     479                        add_filter( 'the_posts', function( $posts, $wp_query ) {
     480
     481                                // Fix the queried object for the archive view.
     482                                if ( ! $wp_query->queried_object && isset( $wp_query->query['browse'] ) ) {
     483                                        $wp_query->query_vars['browse'] = $wp_query->query['browse'];
     484                                        $wp_query->queried_object       = get_term_by( 'slug', $wp_query->query['browse'], 'plugin_section' );
     485                                }
     486
     487                                return $posts;
     488                        }, 10, 2 );
    474489                }
    475490
    … …  
    485500         * @param string $content Post content.
    486501         * @param string $section Optional. Which readme section to translate.
     502         * @param int    $post_id Optional. Post ID. Default: 0.
    487503         * @return string
    488504         */
    489         public function translate_post_content( $content, $section = null, $post_id = null ) {
     505        public function translate_post_content( $content, $section = null, $post_id = 0 ) {
    490506                if ( is_null( $section ) ) {
    491507                        return $content;
    … …  
    514530         * Returns the requested page's excerpt, translated.
    515531         *
    516          * @param string $excerpt
    517          * @param \WP_Post $post
     532         * @param string       $excerpt
     533         * @param int|\WP_Post $post
    518534         * @return string
    519535         */
    … …  
    523539
    524540        /**
    525          * Shutdown action that will add a filter to inject additional postmeta containing translated content if Jetpack is syncing.
    526          *
     541         * Shutdown action that will add a filter to inject additional postmeta containing translated content if Jetpack
     542         * is syncing.
    527543         */
    528544        public function append_meta_for_jetpack() {
    529                 // Guess if a Jetpack sync is scheduled to run. It runs during shutdown at a lower priority than this action, so we can get in first.
    530                 // Fetching the extra meta to inject is expensive, so we only want to do this if a sync is likely.
    531                 if ( class_exists( 'Jetpack' ) && !empty(\Jetpack::$instance->sync->sync) ) {
     545
     546                /*
     547                 * Guess if a Jetpack sync is scheduled to run. It runs during shutdown at a lower priority than this action,
     548                 * so we can get in first.Fetching the extra meta to inject is expensive, so we only want to do this if a sync
     549                 * is likely.
     550                 */
     551                if ( class_exists( 'Jetpack' ) && ! empty( \Jetpack::$instance->sync->sync ) ) {
    532552                        add_filter( 'wporg_plugins_custom_meta_fields', array( $this, 'filter_post_meta_i18n' ), 10, 2 );
    533553                }
    534 
    535554        }
    536555
    … …  
    538557         * Filter for wporg_plugins_custom_meta_fields to inject translated content for ES.
    539558         *
     559         * @global string $locale Current locale.
     560         *
    540561         * @param array $meta
    541          * @param int $post_id
     562         * @param int   $post_id
    542563         * @return array
    543564         */
    544565        public function filter_post_meta_i18n( $meta, $post_id ) {
    545                 // Prevent recursion and repeat runs
     566
     567                // Prevent recursion and repeat runs.
    546568                remove_filter( 'wporg_plugins_custom_meta_fields', array( $this, 'filter_post_meta_i18n' ) );
    547569
    548570                if ( $post_id <= 200 ) {
    549                         $locales_to_sync = array( 'fr_FR', 'es_ES' ); // This should probably be a list of available translations for the plugin readme.
     571
     572                        // This should probably be a list of available translations for the plugin readme.
     573                        $locales_to_sync = array(
     574                                'fr_FR',
     575                                'es_ES',
     576                        );
    550577
    551578                        global $locale;
    552579                        $_locale = $locale;
     580
    553581                        foreach ( $locales_to_sync as $locale ) {
    554                                 $this->i18n_meta[$post_id]['title_'.$locale] = $this->translate_post_title( get_the_title( $post_id ), $post_id );
    555                                 $this->i18n_meta[$post_id]['excerpt_'.$locale] = $this->translate_post_excerpt( get_the_excerpt( $post_id ), $post_id );
    556 
    557                                 // Split up the content to translate it in sections
    558                                 $content = '';
     582                                $this->i18n_meta[ $post_id ][ 'title_' . $locale ]  = $this->translate_post_title( get_the_title( $post_id ), $post_id );
     583                                $this->i18n_meta[ $post_id ][ 'excerpt_' . $locale ] = $this->translate_post_excerpt( get_the_excerpt( $post_id ), $post_id );
     584
     585                                // Split up the content to translate it in sections.
     586                                $content  = '';
    559587                                $sections = $this->split_post_content_into_pages( get_the_content( $post_id ) );
    560588                                foreach ( $sections as $section => $section_content ) {
    561589                                        $content .= $this->translate_post_content( $section_content, $section, $post_id );
    562590                                }
    563                                 $this->i18n_meta[$post_id]['content_'.$locale] = $content;
    564 
     591                                $this->i18n_meta[ $post_id ][ 'content_' . $locale ] = $content;
    565592                        }
    566593
    567594                        $locale = $_locale;
    568595
    569                         $meta = array_merge( $meta, array_keys( $this->i18n_meta[$post_id] ) );
    570                 }
    571 
    572                 add_filter( 'wporg_plugins_custom_meta_fields', array( $this, 'filter_post_meta_i18n'), 10, 2 );
     596                        $meta = array_merge( $meta, array_keys( $this->i18n_meta[ $post_id ] ) );
     597                }
     598
     599                add_filter( 'wporg_plugins_custom_meta_fields', array( $this, 'filter_post_meta_i18n' ), 10, 2 );
     600
    573601                return $meta;
    574602        }
    575 
    576603
    577604        /**
    … …  
    583610        public function filter_allowed_post_types( $allowed_post_types ) {
    584611                $allowed_post_types[] = 'plugin';
     612
    585613                return $allowed_post_types;
    586614        }
    … …  
    588616        /**
    589617         * Filters the available public query vars to add our custom parameters.
     618         *
     619         * @param array $vars Public query vars.
     620         * @return array
    590621         */
    591622        public function filter_query_vars( $vars ) {
    592623                $vars[] = 'favorites_user';
    593624                $vars[] = 'redirect_plugin_tab';
     625
    594626                return $vars;
    595627        }
    … …  
    602634         */
    603635        public function filter_jetpack_options( $new_value ) {
    604                 if ( is_array( $new_value ) && array_key_exists( 'public', $new_value ) )
     636                if ( is_array( $new_value ) && array_key_exists( 'public', $new_value ) ) {
    605637                        $new_value['public'] = 1;
     638                }
    606639
    607640                return $new_value;
    … …  
    621654         */
    622655        function redirect_old_plugin_urls() {
    623                 // Handle a redirect for /$plugin/$tab_name/ to /$plugin/#$tab_name
     656
     657                // Handle a redirect for /$plugin/$tab_name/ to /$plugin/#$tab_name.
    624658                if ( get_query_var( 'redirect_plugin_tab' ) ) {
    625659                        wp_safe_redirect( site_url( get_query_var( 'redirect_plugin_tab' ) ) );
    … …  
    630664                if ( is_404() ) {
    631665
    632                         // [1] => plugins [2] => example-plugin-name [2..] => random()
     666                        // [1] => plugins [2] => example-plugin-name [2..] => random().
    633667                        $path = explode( '/', $_SERVER['REQUEST_URI'] );
    634668
    … …  
    646680                        }
    647681
    648                         // The about page is now over at /developers/
     682                        // The about page is now over at /developers/.
    649683                        if ( 'about' === $path[2] ) {
    650                                 wp_safe_redirect( home_url('/developers/' . ( ( isset( $path[3] ) && 'add' == $path[3] ) ? 'add/' : '' ) ) );
     684                                wp_safe_redirect( home_url( '/developers/' . ( ( isset( $path[3] ) && 'add' == $path[3] ) ? 'add/' : '' ) ) );
    651685                                die();
    652686                        }
    653687
    654                         // Otherwise, handle a plugin redirect
     688                        // Otherwise, handle a plugin redirect.
    655689                        if ( $plugin = self::get_plugin_post( $path[2] ) ) {
    656690                                $is_disabled = in_array( $plugin->post_status, array( 'disabled', 'closed' ), true );
    657691
    658692                                if ( $is_disabled && current_user_can( 'edit_post', $plugin ) ) {
    659                                         wp_safe_redirect( add_query_arg( array( 'post' => $plugin->ID, 'action' => 'edit' ), admin_url( 'post.php' ) ) );
     693                                        wp_safe_redirect( add_query_arg( array(
     694                                                'post'   => $plugin->ID,
     695                                                'action' => 'edit',
     696                                        ), admin_url( 'post.php' ) ) );
    660697                                        die();
    661698                                } else if ( ! $is_disabled ) {
    … …  
    672709                }
    673710
    674                 // new-style Search links
     711                // new-style Search links.
    675712                if ( get_query_var( 's' ) && isset( $_GET['s'] ) ) {
    676713                        wp_safe_redirect( site_url( '/search/' . urlencode( get_query_var( 's' ) ) . '/' ) );
    … …  
    706743                                }
    707744                        }
     745
    708746                        return false;
    709747                } );
    … …  
    722760                switch ( $meta_key ) {
    723761                        case 'downloads':
    724                                 $post = get_post( $object_id );
     762                                $post  = get_post( $object_id );
    725763                                $count = Template::get_downloads_count( $post );
    726 
    727                                 return array( $count );
     764                                $value = array( $count );
    728765                                break;
     766
    729767                        case 'rating':
    730768                                $post = get_post( $object_id );
    … …  
    733771                                        break;
    734772                                }
     773
    735774                                $rating = wporg_get_rating_avg( 'plugin', $post->post_name );
    736 
    737                                 return array( $rating );
     775                                $value  = array( $rating );
    738776                                break;
     777
    739778                        case 'ratings':
    740779                                $post = get_post( $object_id );
    … …  
    742781                                        break;
    743782                                }
     783
    744784                                $ratings = wporg_get_rating_counts( 'plugin', $post->post_name );
    745 
    746                                 return array( $ratings );
     785                                $value   = array( $ratings );
    747786                                break;
     787
    748788                        case false:
     789
    749790                                // In the event $meta_key is false, the caller wants all meta fields, so we'll append our custom ones here too.
    750791                                remove_filter( 'get_post_metadata', array( $this, 'filter_shim_postmeta' ) );
    … …  
    760801
    761802                                foreach ( $custom_meta_fields as $key ) {
    762                                         // When WordPress calls `get_post_meta( $post_id, false )` it expects an array of maybe_serialize()'d data
     803
     804                                        // When WordPress calls `get_post_meta( $post_id, false )` it expects an array of maybe_serialize()'d data.
    763805                                        $shimed_data = $this->filter_shim_postmeta( false, $object_id, $key );
    764806                                        if ( $shimed_data ) {
    … …  
    766808                                        }
    767809                                }
    768 
    769810                                break;
     811
    770812                        default:
    771813                                if ( isset( $this->i18n_meta[ $object_id ][ $meta_key ] ) ) {
    … …  
    774816                                break;
    775817                }
     818
    776819                return $value;
    777820        }
    … …  
    823866         * Retrieve the WP_Post object representing a given plugin.
    824867         *
    825          * @param $plugin_slug string|\WP_Post The slug of the plugin to retrieve.
     868         * @static
     869         * @global \WP_Post $post WordPress post object.
     870         *
     871         * @param string|\WP_Post $plugin_slug The slug of the plugin to retrieve.
    826872         * @return \WP_Post|bool
    827873         */
    828         static public function get_plugin_post( $plugin_slug ) {
     874        public static function get_plugin_post( $plugin_slug ) {
    829875                global $post;
     876
    830877                if ( $plugin_slug instanceof \WP_Post ) {
    831878                        return $plugin_slug;
    832879                }
     880
    833881                // Use the global $post object when it matches to avoid hitting the database.
    834                 if ( !empty( $post ) && 'plugin' == $post->post_type && $plugin_slug == $post->post_name ) {
     882                if ( ! empty( $post ) && 'plugin' == $post->post_type && $plugin_slug == $post->post_name ) {
    835883                        return $post;
    836884                }
    … …  
    841889                        // We have a $post.
    842890                } else {
     891
    843892                        // get_post_by_slug();
    844893                        $posts = get_posts( array(
    … …  
    847896                                'post_status' => array( 'publish', 'pending', 'disabled', 'closed', 'draft', 'approved' ),
    848897                        ) );
     898
    849899                        if ( ! $posts ) {
    850900                                $post = false;
    … …  
    861911        /**
    862912         * Create a new post entry for a given plugin slug.
     913         *
     914         * @static
    863915         *
    864916         * @param array $args {
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-i18n.php

    r3468 r3511  
    1414        public $i18n_cache_group = 'plugins-i18n';
    1515
     16        /**
     17         * @var string
     18         */
    1619        public $master_project;
    1720
     21        /**
     22         * @static
     23         *
     24         * @var bool
     25         */
    1826        public static $use_cache = true;
     27
     28        /**
     29         * @static
     30         *
     31         * @var bool
     32         */
    1933        public static $set_cache = true;
    2034
    2135        /**
     36         * @access protected
     37         *
    2238         * @var \wpdb WordPress database abstraction object.
    2339         */
    … …  
    2642        /**
    2743         * Fetch the instance of the Plugin_I18n class.
     44         *
     45         * @static
    2846         */
    2947        public static function instance() {
    … …  
    3149
    3250                global $wpdb;
     51
    3352                return ! is_null( $instance ) ? $instance : $instance = new Plugin_I18n( $wpdb );
    3453        }
    3554
    36         function __construct( $db, $tracker = null ) {
    37                 if ( !empty( $db ) && is_object( $db ) ) {
     55        /**
     56         * Plugin_I18n constructor.
     57         *
     58         * @access private
     59         *
     60         * @param \wpdb $db WordPress database abstraction object.
     61         * @param null $tracker
     62         */
     63        private function __construct( $db, $tracker = null ) {
     64                if ( ! empty( $db ) && is_object( $db ) ) {
    3865                        $this->db = $db;
    3966                }
    … …  
    4370
    4471        /**
    45          * Generates and returns a standard cache key format, for consistency
    46          *
    47          * @param string $slug Plugin slug
    48          * @param string $branch dev|stable
    49          * @param string $suffix Arbitrary cache key suffix, if needed for uniqueness
    50          *
     72         * Generates and returns a standard cache key format, for consistency.
     73         *
     74         * @param string $slug   Plugin slug
     75         * @param string $branch dev|stable
     76         * @param string $suffix Optional. Arbitrary cache key suffix, if needed for uniqueness.
    5177         * @return string Cache key
    5278         */
    53         function cache_key( $slug, $branch, $suffix = null ) {
    54                 // EG keys
    55                 // plugin:press-this:stable-readme:originals
    56                 // plugin:press-this:stable-readme:original:title
    57                 // plugin:press-this:stable-readme:fr:title
     79        public function cache_key( $slug, $branch, $suffix = '' ) {
     80
     81                /*
     82                 * EG keys
     83                 * plugin:press-this:stable-readme:originals
     84                 * plugin:press-this:stable-readme:original:title
     85                 * plugin:press-this:stable-readme:fr:title
     86                 */
    5887                $key = "{$this->master_project}:{$slug}:{$branch}";
    59                 if ( !empty( $suffix ) ) {
     88                if ( ! empty( $suffix ) ) {
    6089                        $key .= ":{$suffix}";
    6190                }
     91
    6292                return $key;
    6393        }
    6494
    6595        /**
    66          * Cache getting, with proper global cache group
    67          *
    68          * @param string $slug Plugin slug
    69          * @param string $branch dev|stable
    70          * @param string $suffix Arbitrary cache key suffix, if needed for uniqueness
    71          *
     96         * Cache getting, with proper global cache group.
     97         *
     98         * @param string $slug   Plugin slug
     99         * @param string $branch dev|stable
     100         * @param string $suffix Optional. Arbitrary cache key suffix, if needed for uniqueness.
    72101         * @return bool|mixed As returned by wp_cache_set()
    73102         */
    74         function cache_get( $slug, $branch, $suffix = null ) {
     103        public function cache_get( $slug, $branch, $suffix = '' ) {
    75104                if ( ! self::$use_cache ) {
    76105                        return false;
    … …  
    78107
    79108                $key = $this->cache_key( $slug, $branch, $suffix );
     109
    80110                return wp_cache_get( $key, $this->i18n_cache_group );
    81111        }
    … …  
    88118         * @param mixed  $content Content to be cached.
    89119         * @param string $suffix  Optional. Arbitrary cache key suffix, if needed for uniqueness.
    90          *
    91120         * @return bool As returned by wp_cache_set()
    92121         */
    93         function cache_set( $slug, $branch, $content, $suffix = null ) {
     122        public function cache_set( $slug, $branch, $content, $suffix = '' ) {
    94123                if ( ! self::$set_cache ) {
    95124                        return false;
    … …  
    97126
    98127                $key = $this->cache_key( $slug, $branch, $suffix );
     128
    99129                return wp_cache_set( $key, $content, $this->i18n_cache_group );
    100130        }
    101131
    102132        /**
    103          * Gets a GlotPress branch ID
    104          *
    105          * @param string $slug Plugin slug
     133         * Gets a GlotPress branch ID.
     134         *
     135         * @param string $slug   Plugin slug
    106136         * @param string $branch dev|stable
    107137         *
    108138         * @return bool|int|mixed
    109139         */
    110         function get_gp_branch_id( $slug, $branch ) {
     140        public function get_gp_branch_id( $slug, $branch ) {
    111141                $cache_suffix = "branch_id";
    112142
    … …  
    130160
    131161        /**
    132          * Gets GlotPress "originals" based on passed parameters
    133          *
    134          * @param string $slug Plugin slug
    135          * @param string $branch dev|stable
    136          * @param string $key Unique key
    137          * @param string $str String to match in GP
    138          *
     162         * Gets GlotPress "originals" based on passed parameters.
     163         *
     164         * @param string $slug   Plugin slug
     165         * @param string $branch dev|stable
     166         * @param string $key    Unique key
     167         * @param string $str    String to match in GP
    139168         * @return array|bool|mixed|null
    140169         */
    141         function get_gp_originals( $slug, $branch, $key, $str ) {
     170        public function get_gp_originals( $slug, $branch, $key, $str ) {
     171
    142172                // Try to get a single original with the whole content first (title, etc), if passed, or get them all otherwise.
    143                 if ( !empty( $key ) && !empty( $str ) ) {
     173                if ( ! empty( $key ) && ! empty( $str ) ) {
    144174                        $originals = $this->search_gp_original( $slug, $branch, $key, $str );
    145                         if ( !empty( $originals ) ) {
     175
     176                        // Do not cache this as originals, search_gp_original() does its own caching.
     177                        if ( ! empty( $originals ) ) {
    146178                                return array( $originals );
    147179                        }
    148                         // Do not cache this as originals, search_gp_original() does its own caching
    149180                }
    150181
    … …  
    167198
    168199                if ( empty( $originals ) ) {
    169                         $originals = array(); // still cache if empty, but as array, never false
     200
     201                        // Still cache if empty, but as array, never false.
     202                        $originals = array();
    170203                }
    171204
    … …  
    176209
    177210        /**
    178          * Get GlotPress translation set ID based on passed params
    179          *
    180          * @param string $slug Plugin slug
     211         * Get GlotPress translation set ID based on passed params.
     212         *
     213         * @param string $slug   Plugin slug
    181214         * @param string $branch dev|stable
    182215         * @param string $locale EG: fr
    183          *
    184216         * @return bool|int|mixed
    185217         */
    186         function get_gp_translation_set_id( $slug, $branch, $locale ) {
     218        public function get_gp_translation_set_id( $slug, $branch, $locale ) {
    187219                $cache_suffix = "{$locale}:translation_set_id";
    188220
    … …  
    202234
    203235                if ( empty( $translation_set_id ) ) {
     236
    204237                        // Don't give up yet. Might be given fr_FR, which actually exists as locale=fr in GP.
    205238                        $translation_set_id = $this->db->get_var( $this->db->prepare(
    206239                                'SELECT id FROM ' . GLOTPRESS_TABLE_PREFIX . 'translation_sets WHERE project_id = %d AND locale = %s',
    207                                 $branch_id, preg_replace( '/^([^-]+)(-.+)?$/', '\1', $locale ) ) );
     240                                $branch_id, preg_replace( '/^([^-]+)(-.+)?$/', '\1', $locale )
     241                        ) );
    208242                }
    209243
    … …  
    218252
    219253        /**
    220          * Searches GlotPress "originals" for the passed string
    221          *
    222          * @param string $slug Plugin slug
    223          * @param string $branch dev|stable
    224          * @param string $key Unique key
    225          * @param string $str String to be searched for
    226          *
     254         * Searches GlotPress "originals" for the passed string.
     255         *
     256         * @param string $slug   Plugin slug
     257         * @param string $branch dev|stable
     258         * @param string $key    Unique key
     259         * @param string $str    String to be searched for
    227260         * @return bool|mixed|null
    228261         */
    229         function search_gp_original( $slug, $branch, $key, $str ) {
     262        public function search_gp_original( $slug, $branch, $key, $str ) {
    230263                $cache_suffix = "original:{$key}";
    231264
    … …  
    255288
    256289        /**
    257          * Somewhat emulated equivalent of __() for content translation drawn directly from the GlotPress DB
    258          *
    259          * @param string $key Unique key, used for caching
     290         * Somewhat emulated equivalent of __() for content translation drawn directly from the GlotPress DB.
     291         *
     292         * @param string $key     Unique key, used for caching
    260293         * @param string $content Content to be translated
    261          * @param array $args Misc arguments, such as BBPress topic id (otherwise acquired from global $topic_id)
    262          *
    263          * @return mixed
    264          */
    265         function translate( $key, $content, $args = array() ) {
     294         * @param array  $args    Optional. Misc arguments, such as BBPress topic id
     295         *                        (otherwise acquired from global $topic_id).
     296         * @return string
     297         */
     298        public function translate( $key, $content, $args = array() ) {
    266299                if ( empty( $key ) || empty( $content ) ) {
    267300                        return $content;
    … …  
    285318                }
    286319
    287                 $server_name  = strtolower( $_SERVER['SERVER_NAME'] );
     320                $server_name = strtolower( $_SERVER['SERVER_NAME'] );
    288321                if ( 'api.wordpress.org' == $server_name ) {
    289                         // Support formats like fr, haz, and en_GB
     322
     323                        // Support formats like fr, haz, and en_GB.
    290324                        if ( ! empty( $_REQUEST['locale'] ) ) {
    291325                                $wp_locale = preg_replace( '/[^a-zA-Z_]/', '', $_REQUEST['locale'] );
    … …  
    309343                }
    310344
    311                 $locale = $gp_locale->slug; // The slug is the locale of a translation set.
    312                 $slug = $post->post_name;
     345                // The slug is the locale of a translation set.
     346                $locale = $gp_locale->slug;
     347                $slug   = $post->post_name;
    313348
    314349                $post->stable_tag = get_post_meta( $post->ID, 'stable_tag', true );
    … …  
    326361                $cache_suffix = "{$locale}:{$key}";
    327362
    328                 // Try the cache
     363                // Try the cache.
    329364                if ( false !== ( $cache = $this->cache_get( $slug, $branch, $cache_suffix ) ) ) {
    330365                        // DEBUG
    … …  
    368403
    369404        /**
    370          * Takes content, searches for $original, and replaces it by $translation
    371          *
    372          * @param string $original English string
    373          * @param string $translation Translation
    374          * @param string $content Content to be searched
    375          *
     405         * Takes content, searches for $original, and replaces it by $translation.
     406         *
     407         * @param string $original    English string.
     408         * @param string $translation Translation.
     409         * @param string $content     Content to be searched.
    376410         * @return mixed
    377411         */
    378         function translate_gp_original( $original, $translation, $content ) {
     412        public function translate_gp_original( $original, $translation, $content ) {
    379413                if ( false === strpos( $content, '<' ) ) {
    380414                        $content = str_replace( $original, $translation, $content );
    381415                } else {
    382416                        $original = preg_quote( $original, '/' );
    383                         $content = preg_replace( "/(<([a-z0-9]*)\b[^>]*>){$original}(<\/\\2>)/m", "\\1{$translation}\\3", $content );
     417                        $content  = preg_replace( "/(<([a-z0-9]*)\b[^>]*>){$original}(<\/\\2>)/m", "\\1{$translation}\\3", $content );
    384418                }
    385419
  • 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
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php

    r3510 r3511  
    1212        /**
    1313         * Retrieve the average color of a specified image.
     14         *
    1415         * This currently relies upon the Jetpack libraries.
    1516         *
    16          * @param $file_location string URL or filepath of image
    17          * @return string|bool Average color as a hex value, False on failure
    18          */
    19         static function get_image_average_color( $file_location ) {
     17         * @static
     18         *
     19         * @param $file_location string URL or filepath of image.
     20         * @return string|bool Average color as a hex value, False on failure.
     21         */
     22        public static function get_image_average_color( $file_location ) {
    2023                if ( ! class_exists( 'Tonesque' ) && function_exists( 'jetpack_require_lib' ) ) {
    2124                        jetpack_require_lib( 'tonesque' );
    2225                }
     26
    2327                if ( ! class_exists( 'Tonesque' ) ) {
    2428                        return false;
    … …  
    3337         * Returns the two latest reviews of a specific plugin.
    3438         *
     39         * @static
    3540         * @global \wpdb $wpdb WordPress database abstraction object.
    3641         *
    … …  
    5459                                posts.post_position = 1
    5560                        ORDER BY ratings.review_id DESC LIMIT 2", $plugin_slug ) );
     61
    5662                        wp_cache_set( "{$plugin_slug}_reviews", $reviews, 'wporg-plugins', HOUR_IN_SECONDS );
    5763                }
    … …  
    6268        /**
    6369         * Retrieve a list of users who have commit to a specific plugin.
     70         *
     71         * @static
     72         * @global \wpdb $wpdb WordPress database abstraction object.
    6473         *
    6574         * @param string $plugin_slug The plugin slug.
    … …  
    6776         */
    6877        public static function get_plugin_committers( $plugin_slug ) {
    69                 global $wpdb;
    70 
    7178                if ( false === ( $committers = wp_cache_get( "{$plugin_slug}_committer", 'wporg-plugins' ) ) ) {
     79                        global $wpdb;
     80
    7281                        $committers = $wpdb->get_col( $wpdb->prepare( 'SELECT user FROM `' . PLUGINS_TABLE_PREFIX . 'svn_access' . '` WHERE path = %s', "/{$plugin_slug}" ) );
    7382
    … …  
    8089        /**
    8190         * Retrieve a list of plugins a specific user has commit to.
     91         *
     92         * @static
     93         * @global \wpdb $wpdb WordPress database abstraction object.
    8294         *
    8395         * @param int|\WP_User $user The user.
    … …  
    8597         */
    8698        public static function get_users_write_access_plugins( $user ) {
    87                 global $wpdb;
    8899                if ( ! $user instanceof \WP_User ) {
    89100                        $user = new \WP_User( $user );
    90101                }
     102
    91103                if ( ! $user->exists() ) {
    92104                        return false;
    … …  
    94106
    95107                if ( false === ( $plugins = wp_cache_get( "{$user->user_login}_committer", 'wporg-plugins' ) ) ) {
     108                        global $wpdb;
     109
    96110                        $plugins = $wpdb->get_col( $wpdb->prepare( 'SELECT path FROM `' . PLUGINS_TABLE_PREFIX . 'svn_access' . '` WHERE user = %s', $user->user_login ) );
    97                         $plugins = array_map( function( $plugin ) { return trim( $plugin, '/' ); }, $plugins );
     111                        $plugins = array_map( function ( $plugin ) {
     112                                return trim( $plugin, '/' );
     113                        }, $plugins );
    98114
    99115                        wp_cache_set( "{$user->user_login}_committer", $plugins, 'wporg-plugins' );
    … …  
    101117
    102118                return $plugins;
    103 
    104119        }
    105120
    106121        /**
    107122         * Grant a user RW access to a plugin.
     123         *
     124         * @static
     125         * @global \wpdb $wpdb WordPress database abstraction object.
    108126         *
    109127         * @param string          $plugin_slug The plugin slug.
    … …  
    124142                $existing_committers = self::get_plugin_committers( $plugin_slug );
    125143                if ( in_array( $user->user_login, $existing_committers, true ) ) {
     144
    126145                        // User already has write access.
    127146                        return true;
    … …  
    131150                wp_cache_delete( "{$user->user_login}_committer", 'wporg-plugins' );
    132151
    133                 return (bool) $wpdb->insert(
    134                         PLUGINS_TABLE_PREFIX . 'svn_access',
    135                         array(
    136                                 'path'   => "/{$plugin_slug}",
    137                                 'user'   => $user->user_login,
    138                                 'access' => 'rw',
    139                         )
    140                 );
     152                return (bool) $wpdb->insert( PLUGINS_TABLE_PREFIX . 'svn_access', array(
     153                        'path'   => "/{$plugin_slug}",
     154                        'user'   => $user->user_login,
     155                        'access' => 'rw',
     156                ) );
    141157        }
    142158
    143159        /**
    144160         * Revoke a users RW access to a plugin.
     161         *
     162         * @static
     163         * @global \wpdb $wpdb WordPress database abstraction object.
    145164         *
    146165         * @param string          $plugin_slug The plugin slug.
    … …  
    162181                wp_cache_delete( "{$user->user_login}_committer", 'wporg-plugins' );
    163182
    164                 return $wpdb->delete(
    165                         PLUGINS_TABLE_PREFIX . 'svn_access',
    166                         array(
    167                                 'path' => "/{$plugin_slug}",
    168                                 'user' => $user->user_login,
    169                         )
    170                 );
     183                return $wpdb->delete( PLUGINS_TABLE_PREFIX . 'svn_access', array(
     184                        'path' => "/{$plugin_slug}",
     185                        'user' => $user->user_login,
     186                ) );
    171187        }
    172188
    … …  
    177193         * emails and cannot unsubscribe.
    178194         *
     195         * @static
     196         *
    179197         * @param string      $plugin_slug The plugin to subscribe to.
    180          * @param int|WP_User $user        The user to subscribe. Default current user.
    181          * @param bool        $subscribe   Whether to subscribe (true) or unsubscribe (false).
    182          *
     198         * @param int|WP_User $user        Optional. The user to subscribe. Default current user.
     199         * @param bool        $subscribe   Optional. Whether to subscribe (true) or unsubscribe (false).
     200         *                                 Default: true.
    183201         * @return bool Whether the user is subscribed.
    184202         */
    … …  
    216234         * function does not respect that status.
    217235         *
     236         * @static
     237         *
    218238         * @param string      $plugin_slug The plugin to subscribe to.
    219          * @param int|WP_User $user        The user to check. Default current user.
    220          *
     239         * @param int|WP_User $user        Optional. The user to check. Default current user.
    221240         * @return bool Whether the specified user is subscribed to commits.
    222241         */
Note: See TracChangeset for help on using the changeset viewer.