Changeset 4311 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin.php
- Timestamp:
- 10/31/2016 02:47:42 AM (8 years ago)
- 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 3 3 use WordPressdotorg\Plugin_Directory\Plugin_Directory; 4 4 use WordPressdotorg\Plugin_Directory\Template; 5 use WordPressdotorg\Plugin_Directory\Tools; 5 6 use WordPressdotorg\Plugin_Directory\API\Base; 6 7 use WP_REST_Server; … … 105 106 $_pages = preg_split( "#<!--section=(.+?)-->#", $post->post_content, - 1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY ); 106 107 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 ] ); 108 109 } 109 110 $result['sections']['reviews'] = $this->get_plugin_reviews_markup( $post->post_name ); … … 204 205 * Returns a HTML formatted representation of the latest 10 reviews for a plugin. 205 206 * 207 * This intentionally uses different markup than what the theme uses, as it's for display within the WordPress Administration area. 208 * 206 209 * @param string $plugin_slug The plugin slug. 207 210 * @return string HTML blob of data. … … 209 212 protected function get_plugin_reviews_markup( $plugin_slug ) { 210 213 $output = ''; 211 foreach ( $this->get_plugin_reviews_data( $plugin_slug) as $review ) {214 foreach ( Tools::get_plugin_reviews( $plugin_slug, 10 ) as $review ) { 212 215 $output .= $this->get_plugin_reviews_markup_singular( $review ); 213 216 } … … 218 221 * Generates a HTML blob for a single review. 219 222 * 220 * @param object $review Single row of data from `self::get_plugin_reviews_data()`223 * @param object $review The review data. 221 224 * @return string Blob of HTML representing the review. 222 225 */ 223 226 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 ); 225 228 ob_start(); 226 227 // Copied from bb-theme/wporg/_reviews.php, with quite a few things stripped out.228 229 ?> 229 230 <div class="review"> … … 231 232 <div class="reviewer-info"> 232 233 <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> 234 235 <div class="star-rating"><?php 235 236 /* Core has .star-rating .star colour styling, which is why we use a custom wrapper and template */ 236 237 echo Template::dashicons_stars( array( 237 'rating' => wporg_get_rating( $review->topic_id ),238 'rating' => $review->post_rating, 238 239 'template' => '<span class="star %1$s"></span>', 239 240 ) ); … … 241 242 </div> 242 243 <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; 247 250 if ( $reviewer->display_name != $reviewer->user_login ) { 248 echo" <small>({$reviewer->user_login})</small>";251 $review_author_markup .= " <small>({$reviewer->user_login})</small>"; 249 252 } 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 ?> 260 260 </p> 261 261 </div> 262 262 </div> 263 <div class="review-body"><?php echo $review->post_ text; ?></div>263 <div class="review-body"><?php echo $review->post_content; ?></div> 264 264 </div> 265 265 <?php … … 268 268 } 269 269 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 ID292 293 $reviews = $wpdb->get_results( $wpdb->prepare( "294 SELECT295 t.topic_id, t.topic_title, t.topic_poster, t.topic_start_time,296 p.post_text,297 tm_wp.meta_value as wp_version298 FROM {$table_prefix}topics AS t299 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 = %s303 ORDER BY t.topic_start_time DESC304 LIMIT 10",305 $forum_id,306 $plugin_slug307 ) );308 309 wp_cache_set( $plugin_slug, $reviews, 'reviews' );310 return $reviews;311 }312 270 } 313 271
Note: See TracChangeset
for help on using the changeset viewer.