Changeset 3203
- Timestamp:
- 05/20/2016 10:08:16 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/widgets/class-ratings.php
r3185 r3203 10 10 class Ratings extends \WP_Widget { 11 11 12 /** 13 * Ratings constructor. 14 */ 12 15 public function __construct() { 13 $widget_ops = array( 14 'classname' => 'plugin-ratings', 15 'description' => 'Displays the plugin ratings.', 16 ); 17 parent::__construct( 'plugin_ratings', 'Plugin Ratings', $widget_ops ); 16 parent::__construct( 'plugin_ratings', __( 'Plugin Ratings', 'wporg-plugins' ), array( 17 'classname' => 'plugin-ratings', 18 'description' => __( 'Displays the plugin ratings.', 'wporg-plugins' ), 19 ) ); 18 20 } 19 21 … … 25 27 */ 26 28 public function widget( $args, $instance ) { 27 echo $args['before_widget'];29 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Ratings', 'wporg-plugins' ) : $instance['title'], $instance, $this->id_base ); 28 30 29 $post = get_post(); 30 31 $post = get_post(); 31 32 $rating = get_post_meta( $post->ID, 'rating', true ); 32 33 $ratings = get_post_meta( $post->ID, 'ratings', true ) ?: array(); 33 34 $num_ratings = array_sum( $ratings ); 34 35 35 $user_rating = 0; 36 if ( is_user_logged_in() && function_exists( 'wporg_get_user_rating' ) ) { 37 $user_rating = wporg_get_user_rating( 'plugin', $post->post_name, get_current_user_id() ); 38 if ( ! $user_rating ) { 39 $user_rating = 0; 40 } 41 } 42 36 echo $args['before_widget']; 37 echo $args['before_title'] . $title . $args['after_title']; 43 38 ?> 44 45 39 <meta itemprop="ratingCount" content="<?php echo esc_attr( $num_ratings ) ?>"/> 46 <h4><?php _e( 'Ratings', 'wporg-plugins' ); ?></h4>47 40 48 41 <?php if ( $rating ) : ?> 49 42 <div class="rating"> 50 43 <?php echo Template::dashicons_stars( $rating ); ?> 51 < p class="description"><?php printf( __( '%s out of 5 stars.', 'wporg-plugins' ), '<span itemprop="ratingValue">' . $rating . '</span>' ); ?></p>44 <meta itemprop="ratingValue" content="<?php echo esc_attr( $rating ) ?>"> 52 45 </div> 53 46 <?php else : ?> 54 47 <div class="rating"> 55 <p class="description"><?php _e( 'This plugin has not been rated yet.', 'wporg-plugins' ); ?></p>48 <p><?php _e( 'This plugin has not been rated yet.', 'wporg-plugins' ); ?></p> 56 49 </div> 57 50 <?php endif; // $rating … … 63 56 ?> 64 57 <li class="counter-container"> 65 <a href=" https://wordpress.org/support/view/plugin-reviews/<?php echo $post->post_name; ?>?filter=<?php echo $stars; ?>" title="<?php echo esc_attr( sprintf( _n( 'Click to see reviews that provided a rating of %d star', 'Click to see reviews that provided a rating of %d stars', $stars, 'wporg-plugins' ), $stars )); ?>">58 <a href="<?php echo esc_url( 'https://wordpress.org/support/view/plugin-reviews/' . $post->post_name . '?filter=' . $stars ); ?>"> 66 59 <span class="counter-label"><?php printf( _n( '%d star', '%d stars', $stars, 'wporg-plugin' ), $stars ); ?></span> 67 60 <span class="counter-back"> … … 76 69 endif; // $ratings 77 70 78 if ( is_user_logged_in() ) { 79 echo '<div class="user-rating">'; 80 echo Template::dashicons_stars( array( 81 'rating' => $user_rating, 82 'template' => '<a class="%1$s" href="https://wordpress.org/support/view/plugin-reviews/' . $post->post_name . '?rate=%2$d#postform"></a>' 83 ) ); 84 echo '</div>'; 85 ?> 86 <script> 87 jQuery(document).ready( function($) { 88 var $rating = $( '.user-rating div' ), 89 $stars = $rating.find( '.dashicons' ), 90 current_rating = $rating.data( 'rating' ), 91 rating_clear_timer = 0; 92 93 $stars.mouseover( function() { 94 var $this = $(this), 95 $prev_items = $this.prevAll(), 96 $next_items = $this.nextAll(), 97 rating = $prev_items.length + 1; 98 99 if ( rating_clear_timer ) { 100 clearTimeout( rating_clear_timer ); 101 rating_clear_timer = 0; 102 } 103 104 if ( rating == current_rating ) { 105 return; 106 } 107 108 $this.removeClass( 'dashicons-star-empty' ).addClass( 'dashicons-star-filled' ); 109 $prev_items.removeClass( 'dashicons-star-empty' ).addClass( 'dashicons-star-filled' ); 110 $next_items.removeClass( 'dashicons-star-filled' ).addClass( 'dashicons-star-empty' ); 111 112 $rating.prop( 'title', $rating.data( 'title-template' ).replace( '%s', rating ).replace( '%d', rating ) ); 113 current_rating = rating; 114 } ); 115 $rating.mouseout( function() { 116 var clear_callback = function() { 117 var rating = $rating.data( 'rating' ); 118 if ( rating == current_rating ) { 119 return; 120 } 121 if ( rating ) { 122 $( $stars.get( rating-1 ) ).mouseover(); 123 } else { 124 $stars.removeClass( 'dashicons-star-filled' ).addClass( 'dashicons-star-empty' ); 125 } 126 }; 127 128 if ( ! rating_clear_timer ) { 129 rating_clear_timer = setTimeout( clear_callback, 2000 ); 130 } 131 } ); 132 } ); 133 </script> 134 <?php 135 } 71 if ( is_user_logged_in() ) : ?> 72 <div class="user-rating"> 73 <a class="button button-secondary" href="<?php echo esc_url( 'https://wordpress.org/support/view/plugin-reviews/' . $post->post_name . '#postform' ); ?>"><?php _e( 'Add your review', 'wporg-plugins' ); ?></a> 74 </div> 75 <?php 76 endif; 136 77 137 78 echo $args['after_widget'];
Note: See TracChangeset
for help on using the changeset viewer.