<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[4311] sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory: Plugin Directory: Pull reviews from bbPress2 rather than the old bbPress1 support forums.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/4311">4311</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/4311","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>dd32</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-10-31 02:47:42 +0000 (Mon, 31 Oct 2016)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Plugin Directory: Pull reviews from bbPress2 rather than the old bbPress1 support forums.

See <a href="http://meta.trac.wordpress.org/ticket/1579">#1579</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryapiroutesclasspluginphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclasstoolsphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryapiroutesclasspluginphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin.php     2016-10-31 01:40:14 UTC (rev 4310)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin.php       2016-10-31 02:47:42 UTC (rev 4311)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2,6 +2,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> namespace WordPressdotorg\Plugin_Directory\API\Routes;
</span><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\Plugin_Directory\Plugin_Directory;
</span><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\Plugin_Directory\Template;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+use WordPressdotorg\Plugin_Directory\Tools;
</ins><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\Plugin_Directory\API\Base;
</span><span class="cx" style="display: block; padding: 0 10px"> use WP_REST_Server;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -104,7 +105,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $_pages = preg_split( "#<!--section=(.+?)-->#", $post->post_content, - 1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
</span><span class="cx" style="display: block; padding: 0 10px">                for ( $i = 0; $i < count( $_pages ); $i += 2 ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $result['sections'][ $_pages[ $i ] ] = apply_filters( 'the_content', $_pages[ $i + 1 ] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $result['sections'][ $_pages[ $i ] ] = apply_filters( 'the_content', $_pages[ $i + 1 ], $_pages[ $i ] );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px">                $result['sections']['reviews'] = $this->get_plugin_reviews_markup( $post->post_name );
</span><span class="cx" style="display: block; padding: 0 10px">                $result['description'] = $result['sections']['description'];
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -203,12 +204,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="cx" style="display: block; padding: 0 10px">         * Returns a HTML formatted representation of the latest 10 reviews for a plugin.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * This intentionally uses different markup than what the theme uses, as it's for display within the WordPress Administration area.
+        *
</ins><span class="cx" style="display: block; padding: 0 10px">          * @param string $plugin_slug The plugin slug.
</span><span class="cx" style="display: block; padding: 0 10px">         * @return string HTML blob of data.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        protected function get_plugin_reviews_markup( $plugin_slug ) {
</span><span class="cx" style="display: block; padding: 0 10px">                $output = '';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                foreach ( $this->get_plugin_reviews_data( $plugin_slug ) as $review ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         foreach ( Tools::get_plugin_reviews( $plugin_slug, 10 ) as $review ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $output .= $this->get_plugin_reviews_markup_singular( $review );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px">                return $output;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -217,97 +220,52 @@
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="cx" style="display: block; padding: 0 10px">         * Generates a HTML blob for a single review.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @param object $review Single row of data from `self::get_plugin_reviews_data()`
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * @param object $review The review data.
</ins><span class="cx" style="display: block; padding: 0 10px">          * @return string Blob of HTML representing the review.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        protected function get_plugin_reviews_markup_singular( $review ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $reviewer = get_user_by( 'id', $review->topic_poster );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $reviewer = get_user_by( 'id', $review->post_author );
</ins><span class="cx" style="display: block; padding: 0 10px">                 ob_start();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-               // Copied from bb-theme/wporg/_reviews.php, with quite a few things stripped out.
</del><span class="cx" style="display: block; padding: 0 10px"> ?>
</span><span class="cx" style="display: block; padding: 0 10px"> <div class="review">
</span><span class="cx" style="display: block; padding: 0 10px">        <div class="review-head">
</span><span class="cx" style="display: block; padding: 0 10px">                <div class="reviewer-info">
</span><span class="cx" style="display: block; padding: 0 10px">                        <div class="review-title-section">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                <h4 class="review-title"><?php echo $review->topic_title; ?></h4>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         <h4 class="review-title"><?php echo esc_html( $review->post_title ); ?></h4>
</ins><span class="cx" style="display: block; padding: 0 10px">                                 <div class="star-rating"><?php
</span><span class="cx" style="display: block; padding: 0 10px">                                        /* Core has .star-rating .star colour styling, which is why we use a custom wrapper and template */
</span><span class="cx" style="display: block; padding: 0 10px">                                        echo Template::dashicons_stars( array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                'rating' => wporg_get_rating( $review->topic_id ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         'rating' => $review->post_rating,
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 'template' => '<span class="star %1$s"></span>',
</span><span class="cx" style="display: block; padding: 0 10px">                                        ) );
</span><span class="cx" style="display: block; padding: 0 10px">                                ?></div>
</span><span class="cx" style="display: block; padding: 0 10px">                        </div>
</span><span class="cx" style="display: block; padding: 0 10px">                        <p class="reviewer">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                By <a href="https://profiles.wordpress.org/<?php echo $reviewer->user_nicename; ?>"><?php echo get_avatar( $review->topic_poster, 16, 'monsterid' ); ?></a>
-                               <a href="https://profiles.wordpress.org/<?php echo $reviewer->user_nicename; ?>" class="reviewer-name"><?php
-                                       echo $reviewer->display_name;
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         <?php
+                                       $review_author_markup_profile = esc_url( 'https://profiles.wordpress.org/' . $reviewer->user_nicename );
+                                       $review_author_markup  = '<a href="' . $review_author_markup_profile . '">';
+                                       $review_author_markup .= get_avatar( $reviewer->ID, 16, 'monsterid' ) . '</a>';
+                                       $review_author_markup .= '<a href="' . $review_author_markup_profile . '" class="reviewer-name">';
+                                       $review_author_markup .= $reviewer->display_name;
</ins><span class="cx" style="display: block; padding: 0 10px">                                         if ( $reviewer->display_name != $reviewer->user_login ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                echo " <small>({$reviewer->user_login})</small>";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         $review_author_markup .= " <small>({$reviewer->user_login})</small>";
</ins><span class="cx" style="display: block; padding: 0 10px">                                         }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                ?></a><?php
-                                       /* // Display author badge next to the person's name if they're reviewing their own thing
-                                       if ( class_exists( '\WPORG_Extend_Author_Badge' ) ) {
-                                               echo \WPORG_Extend_Author_Badge::get_instance()->show_author_badge( '', $post->post_id );
-                                       } */
-                               ?>,
-                               <span class="review-date"><?php echo gmdate( 'F j, Y', strtotime( $review->topic_start_time ) ); ?></span>
-                               <?php if ( $review->wp_version ) : ?>
-                                       <span class="review-wp-version">for WordPress <?php echo $review->wp_version; ?></span>
-                               <?php endif; ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 $review_author_markup .= '</a>';
+
+                                       printf( __( 'By %1$s on %2$s', 'wporg-plugins' ),
+                                               $review_author_markup,
+                                               '<span class="review-date">' . gmdate( 'F j, Y', strtotime( $review->post_modified ) ) . '</span>'
+                                       );
+                               ?>
</ins><span class="cx" style="display: block; padding: 0 10px">                         </p>
</span><span class="cx" style="display: block; padding: 0 10px">                </div>
</span><span class="cx" style="display: block; padding: 0 10px">        </div>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        <div class="review-body"><?php echo $review->post_text; ?></div>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <div class="review-body"><?php echo $review->post_content; ?></div>
</ins><span class="cx" style="display: block; padding: 0 10px"> </div>
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px">                return ob_get_clean();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        /**
-        * Fetch the latest 10 reviews for a given plugin from the database.
-        *
-        * This uses raw SQL to query the bbPress tables to fetch reviews.
-        *
-        * @param string $plugin_slug The slug of the plugin.
-        * @return array An array of review details.
-        */
-       protected function get_plugin_reviews_data( $plugin_slug ) {
-               global $wpdb;
-               if ( ! defined( 'WPORGPATH' ) || ! defined( 'CUSTOM_USER_TABLE' ) ) {
-                       // Reviews are stored in the main supoport forum, which isn't open source yet.
-                       return array();
-               }
-
-               if ( $reviews = wp_cache_get( $plugin_slug, 'reviews' ) ) {
-                       return $reviews;
-               }
-
-               // The forums are the source for users, and also where reviews live.
-               $table_prefix = str_replace( 'users', '', CUSTOM_USER_TABLE );
-               $forum_id = 18; // The Review Forums ID
-
-               $reviews = $wpdb->get_results( $wpdb->prepare( "
-                       SELECT
-                               t.topic_id, t.topic_title, t.topic_poster, t.topic_start_time,
-                               p.post_text,
-                               tm_wp.meta_value as wp_version
-                       FROM {$table_prefix}topics AS t
-                       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' )
-                       JOIN {$table_prefix}posts as p ON ( t.topic_id = p.topic_id AND post_status = 0 AND post_position = 1 )
-                       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' )
-                       WHERE t.forum_id = %d AND t.topic_status = 0 AND t.topic_sticky = 0 AND tm.meta_value = %s
-                       ORDER BY t.topic_start_time DESC
-                       LIMIT 10",
-                       $forum_id,
-                       $plugin_slug
-               ) );
-
-               wp_cache_set( $plugin_slug, $reviews, 'reviews' );
-               return $reviews;
-       }
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclasstoolsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php 2016-10-31 01:40:14 UTC (rev 4310)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php   2016-10-31 02:47:42 UTC (rev 4311)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -44,24 +44,25 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @param string $plugin_slug The plugin slug.
</span><span class="cx" style="display: block; padding: 0 10px">         * @return array|false
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        public static function get_plugin_reviews( $plugin_slug ) {
-               if ( false === ( $reviews = wp_cache_get( "{$plugin_slug}_reviews", 'wporg-plugins' ) ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function get_plugin_reviews( $plugin_slug, $number = 2 ) {
+               $number = absint( $number );
+               if ( $number < 1 || $number > 100 ) {
+                       $number = 2;
+               }
+               if ( false === ( $reviews = wp_cache_get( "{$plugin_slug}_last{$number}_reviews", 'wporg-plugins' ) ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $reviews = $wpdb->get_results( $wpdb->prepare( "
-                       SELECT posts.post_text AS post_content, topics.topic_title AS post_title, ratings.rating AS post_rating, ratings.user_id AS post_author
-                       FROM ratings
-                               INNER JOIN minibb_topics AS topics ON ( ratings.review_id = topics.topic_id )
-                               INNER JOIN minibb_posts AS posts ON ( ratings.review_id = posts.topic_id )
-                       WHERE
-                               ratings.object_type = 'plugin' AND
-                               ratings.object_slug = %s AND
-                               posts.post_position = 1 AND
-                               topics.topic_status = 0 AND
-                               topics.topic_sticky = 0
-                       ORDER BY ratings.review_id DESC LIMIT 2", $plugin_slug ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $reviews = $wpdb->get_results( $wpdb->prepare(
+                       "SELECT
+                                       post_content, post_title, post_author, post_modified,
+                                       r.rating as post_rating
+                       FROM ratings r
+                               LEFT JOIN wporg_419_posts p ON r.post_id = p.ID
+                       WHERE r.object_type = 'plugin' AND r.object_slug = %s AND p.post_status = 'publish'
+                       ORDER BY r.review_id DESC
+                       LIMIT %d", $plugin_slug, $number ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        wp_cache_set( "{$plugin_slug}_reviews", $reviews, 'wporg-plugins', HOUR_IN_SECONDS );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 wp_cache_set( "{$plugin_slug}_last{$number}_reviews", $reviews, 'wporg-plugins', HOUR_IN_SECONDS );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                return $reviews;
</span></span></pre>
</div>
</div>

</body>
</html>