Exemplo n.º 1
0
 /**
  * Output the rating percentage in the column
  *
  * @param $column_name
  * @param $post_id
  */
 public function column_content($column_name, $post_id)
 {
     if ($column_name !== 'wpkb-rating') {
         return;
     }
     $rating = $this->rating->get_post_rating_perc($post_id);
     if ($rating === 0) {
         echo '-';
         return;
     }
     $color = $this->percent2Color($rating, 200);
     echo sprintf('<span style="color: #%s">%s%%</span> (%d)', $color, $rating, count($this->rating->get_post_ratings($post_id)));
 }
Exemplo n.º 2
0
 /**
  * @param \WP_Post $post
  */
 public function show_meta_box($post)
 {
     $ratings = $this->rating->get_post_ratings($post->ID);
     $average_rating = $this->rating->get_post_average($post->ID);
     if (count($ratings) === 0) {
         echo '<p>No ratings for this article.</p>';
         return;
     }
     echo '<style type="text/css" scoped>.wpkb-ratings-table { border-collapse: collapse; } .wpkb-ratings-table th, .wpkb-ratings-table td{ border: 1px solid #eee; padding: 3px 6px; }</style>';
     echo sprintf('<p>This article has an average score of <span style="border-bottom: 4px solid #%s;">%.2f</span> based on %d rating(s).', $this->percent2Color($average_rating), ceil($average_rating / 20), count($ratings));
     echo '<table class="wpkb-ratings-table" border="0">';
     echo '<tr><th></th><th>Rating</th><th>IP address</th><th>Time</th><th>Message</th></tr>';
     foreach ($ratings as $rating) {
         printf('<tr><td style="background: #%s;"></td><td>%d</td><td>%s</td><td><span title="%s">%s ago</span></td><td>%s</td></tr>', $this->percent2Color($rating->percentage), $rating->rating, $rating->author_IP, '', human_time_diff(strtotime($rating->comment->comment_date_gmt)), $rating->message);
     }
     echo '</table>';
     // reset form
     $delete_link = add_query_arg(array('wpkb_action' => 'delete_post_ratings', 'post_id' => get_the_ID()));
     echo '<p>Use the following button to reset all ratings for this article.</p>';
     echo '<p><a class="button" onclick="return confirm(\'Are you sure you want to delete all ratings for this article?\');" href="' . $delete_link . '">Reset Ratings</a></p>';
 }