Making WordPress.org


Ignore:
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

File:
1 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;
     5use WordPressdotorg\Plugin_Directory\Tools;
    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 ], $_pages[ $i ] );
    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     * This intentionally uses different markup than what the theme uses, as it's for display within the WordPress Administration area.
     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 ( Tools::get_plugin_reviews( $plugin_slug, 10 ) 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 The review data.
    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->post_author );
    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 esc_html( $review->post_title ); ?></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' => $review->post_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                        $review_author_markup .= " <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_content; ?></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
Note: See TracChangeset for help on using the changeset viewer.