Making WordPress.org

Changeset 4311

Timestamp:
10/31/2016 02:47:42 AM (8 years ago)
Author:
dd32
Message:

Plugin Directory: Pull reviews from bbPress2 rather than the old bbPress1 support forums.

See #1579

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

Legend:

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

    r4310 r4311  
    33use WordPressdotorg\Plugin_Directory\Plugin_Directory;
    44use WordPressdotorg\Plugin_Directory\Template;
     5
    56use WordPressdotorg\Plugin_Directory\API\Base;
    67use WP_REST_Server;
     
    105106        $_pages = preg_split( "#<!--section=(.+?)-->#", $post->post_content, - 1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
    106107        for ( $i = 0; $i < count( $_pages ); $i += 2 ) {
    107             $result['sections'][ $_pages[ $i ] ] = apply_filters( 'the_content', $_pages[ $i + 1 ] );
     108            $result['sections'][ $_pages[ $i ] ] = apply_filters( 'the_content', $_pages[ $i + 1 ] );
    108109        }
    109110        $result['sections']['reviews'] = $this->get_plugin_reviews_markup( $post->post_name );
     
    204205     * Returns a HTML formatted representation of the latest 10 reviews for a plugin.
    205206     *
     207
     208
    206209     * @param string $plugin_slug The plugin slug.
    207210     * @return string HTML blob of data.
     
    209212    protected function get_plugin_reviews_markup( $plugin_slug ) {
    210213        $output = '';
    211         foreach ( $this->get_plugin_reviews_data( $plugin_slug ) as $review ) {
     214        foreach ( ) as $review ) {
    212215            $output .= $this->get_plugin_reviews_markup_singular( $review );
    213216        }
     
    218221     * Generates a HTML blob for a single review.
    219222     *
    220      * @param object $review Single row of data from `self::get_plugin_reviews_data()`
     223     * @param object $review
    221224     * @return string Blob of HTML representing the review.
    222225     */
    223226    protected function get_plugin_reviews_markup_singular( $review ) {
    224         $reviewer = get_user_by( 'id', $review->topic_poster );
     227        $reviewer = get_user_by( 'id', $review->r );
    225228        ob_start();
    226 
    227         // Copied from bb-theme/wporg/_reviews.php, with quite a few things stripped out.
    228229?>
    229230<div class="review">
     
    231232        <div class="reviewer-info">
    232233            <div class="review-title-section">
    233                 <h4 class="review-title"><?php echo $review->topic_title; ?></h4>
     234                <h4 class="review-title"><?php echo ; ?></h4>
    234235                <div class="star-rating"><?php
    235236                    /* Core has .star-rating .star colour styling, which is why we use a custom wrapper and template */
    236237                    echo Template::dashicons_stars( array(
    237                         'rating' => wporg_get_rating( $review->topic_id ),
     238                        'rating' => ,
    238239                        'template' => '<span class="star %1$s"></span>',
    239240                    ) );
     
    241242            </div>
    242243            <p class="reviewer">
    243                 By <a href="https://profiles.wordpress.org/<?php echo $reviewer->user_nicename; ?>"><?php echo get_avatar( $review->topic_poster, 16, 'monsterid' ); ?></a>
    244                 <a href="https://profiles.wordpress.org/<?php echo $reviewer->user_nicename; ?>" class="reviewer-name"><?php
    245                     echo $reviewer->display_name;
    246 
     244                <?php
     245                    $review_author_markup_profile = esc_url( 'https://profiles.wordpress.org/' . $reviewer->user_nicename );
     246                    $review_author_markup  = '<a href="' . $review_author_markup_profile . '">';
     247                    $review_author_markup .= get_avatar( $reviewer->ID, 16, 'monsterid' ) . '</a>';
     248                    $review_author_markup .= '<a href="' . $review_author_markup_profile . '" class="reviewer-name">';
     249                    $review_author_markup .= $reviewer->display_name;
    247250                    if ( $reviewer->display_name != $reviewer->user_login ) {
    248                         echo " <small>({$reviewer->user_login})</small>";
     251                        " <small>({$reviewer->user_login})</small>";
    249252                    }
    250                 ?></a><?php
    251                     /* // Display author badge next to the person's name if they're reviewing their own thing
    252                     if ( class_exists( '\WPORG_Extend_Author_Badge' ) ) {
    253                         echo \WPORG_Extend_Author_Badge::get_instance()->show_author_badge( '', $post->post_id );
    254                     } */
    255                 ?>,
    256                 <span class="review-date"><?php echo gmdate( 'F j, Y', strtotime( $review->topic_start_time ) ); ?></span>
    257                 <?php if ( $review->wp_version ) : ?>
    258                     <span class="review-wp-version">for WordPress <?php echo $review->wp_version; ?></span>
    259                 <?php endif; ?>
     253                    $review_author_markup .= '</a>';
     254
     255                    printf( __( 'By %1$s on %2$s', 'wporg-plugins' ),
     256                        $review_author_markup,
     257                        '<span class="review-date">' . gmdate( 'F j, Y', strtotime( $review->post_modified ) ) . '</span>'
     258                    );
     259                ?>
    260260            </p>
    261261        </div>
    262262    </div>
    263     <div class="review-body"><?php echo $review->post_text; ?></div>
     263    <div class="review-body"><?php echo $review->post_t; ?></div>
    264264</div>
    265265<?php
     
    268268    }
    269269
    270     /**
    271      * Fetch the latest 10 reviews for a given plugin from the database.
    272      *
    273      * This uses raw SQL to query the bbPress tables to fetch reviews.
    274      *
    275      * @param string $plugin_slug The slug of the plugin.
    276      * @return array An array of review details.
    277      */
    278     protected function get_plugin_reviews_data( $plugin_slug ) {
    279         global $wpdb;
    280         if ( ! defined( 'WPORGPATH' ) || ! defined( 'CUSTOM_USER_TABLE' ) ) {
    281             // Reviews are stored in the main supoport forum, which isn't open source yet.
    282             return array();
    283         }
    284 
    285         if ( $reviews = wp_cache_get( $plugin_slug, 'reviews' ) ) {
    286             return $reviews;
    287         }
    288 
    289         // The forums are the source for users, and also where reviews live.
    290         $table_prefix = str_replace( 'users', '', CUSTOM_USER_TABLE );
    291         $forum_id = 18; // The Review Forums ID
    292 
    293         $reviews = $wpdb->get_results( $wpdb->prepare( "
    294             SELECT
    295                 t.topic_id, t.topic_title, t.topic_poster, t.topic_start_time,
    296                 p.post_text,
    297                 tm_wp.meta_value as wp_version
    298             FROM {$table_prefix}topics AS t
    299             JOIN {$table_prefix}meta AS tm ON ( tm.object_type = 'bb_topic' AND t.topic_id = tm.object_id AND tm.meta_key = 'is_plugin' )
    300             JOIN {$table_prefix}posts as p ON ( t.topic_id = p.topic_id AND post_status = 0 AND post_position = 1 )
    301             LEFT JOIN {$table_prefix}meta AS tm_wp ON ( tm_wp.object_type = 'bb_topic' AND t.topic_id = tm_wp.object_id AND tm_wp.meta_key = 'wp_version' )
    302             WHERE t.forum_id = %d AND t.topic_status = 0 AND t.topic_sticky = 0 AND tm.meta_value = %s
    303             ORDER BY t.topic_start_time DESC
    304             LIMIT 10",
    305             $forum_id,
    306             $plugin_slug
    307         ) );
    308 
    309         wp_cache_set( $plugin_slug, $reviews, 'reviews' );
    310         return $reviews;
    311     }
    312270}
    313271
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php

    r4214 r4311  
    4545     * @return array|false
    4646     */
    47     public static function get_plugin_reviews( $plugin_slug ) {
    48         if ( false === ( $reviews = wp_cache_get( "{$plugin_slug}_reviews", 'wporg-plugins' ) ) ) {
     47    public static function get_plugin_reviews( $plugin_slug, $number = 2 ) {
     48        $number = absint( $number );
     49        if ( $number < 1 || $number > 100 ) {
     50            $number = 2;
     51        }
     52        if ( false === ( $reviews = wp_cache_get( "{$plugin_slug}_last{$number}_reviews", 'wporg-plugins' ) ) ) {
    4953            global $wpdb;
    5054
    51             $reviews = $wpdb->get_results( $wpdb->prepare( "
    52             SELECT posts.post_text AS post_content, topics.topic_title AS post_title, ratings.rating AS post_rating, ratings.user_id AS post_author
    53             FROM ratings
    54                 INNER JOIN minibb_topics AS topics ON ( ratings.review_id = topics.topic_id )
    55                 INNER JOIN minibb_posts AS posts ON ( ratings.review_id = posts.topic_id )
    56             WHERE
    57                 ratings.object_type = 'plugin' AND
    58                 ratings.object_slug = %s AND
    59                 posts.post_position = 1 AND
    60                 topics.topic_status = 0 AND
    61                 topics.topic_sticky = 0
    62             ORDER BY ratings.review_id DESC LIMIT 2", $plugin_slug ) );
    63 
    64             wp_cache_set( "{$plugin_slug}_reviews", $reviews, 'wporg-plugins', HOUR_IN_SECONDS );
     55            $reviews = $wpdb->get_results( $wpdb->prepare(
     56            "SELECT
     57                    post_content, post_title, post_author, post_modified,
     58                    r.rating as post_rating
     59            FROM ratings r
     60                LEFT JOIN wporg_419_posts p ON r.post_id = p.ID
     61            WHERE r.object_type = 'plugin' AND r.object_slug = %s AND p.post_status = 'publish'
     62            ORDER BY r.review_id DESC
     63            LIMIT %d", $plugin_slug, $number ) );
     64
     65            wp_cache_set( "{$plugin_slug}_last{$number}_reviews", $reviews, 'wporg-plugins', HOUR_IN_SECONDS );
    6566        }
    6667
Note: See TracChangeset for help on using the changeset viewer.