Exemplo n.º 1
0
 /**
  * Code for StarComments shortcode implementation
  *
  * @param array $atts
  */
 function shortcode_starcomments($atts = array())
 {
     $rating = "";
     $sett = shortcode_atts($this->default_shortcode_starcomments, $atts);
     if ($sett["post"] == 0) {
         global $post;
         $sett["post"] = $post->ID;
         $sett["comments"] = $post->comment_count;
     } else {
         $post = get_post($sett["post"]);
         $sett["comments"] = $post->comment_count;
     }
     if ($post->ID > 0) {
         $rows = GDSRDatabase::get_comments_aggregation($sett["post"], $sett["show"]);
         $totel_comments = count($rows);
         $total_voters = 0;
         $total_votes = 0;
         $calc_rating = 0;
         foreach ($rows as $row) {
             switch ($sett["show"]) {
                 default:
                 case "total":
                     $total_voters += $row->user_voters + $row->visitor_voters;
                     $total_votes += $row->user_votes + $row->visitor_votes;
                     break;
                 case "users":
                     $total_voters += $row->user_voters;
                     $total_votes += $row->user_votes;
                     break;
                 case "visitors":
                     $total_voters += $row->visitor_voters;
                     $total_votes += $row->visitor_votes;
                     break;
             }
         }
         if ($total_voters > 0) {
             $calc_rating = $total_votes / $total_voters;
         }
         $calc_rating = number_format($calc_rating, 1);
         $rating = GDSRRenderT2::render_car($sett["tpl"], $total_voters, $calc_rating, $sett["comments"], $this->is_ie6 ? $this->o["cmm_aggr_style_ie6"] : $this->o["cmm_aggr_style"], $this->o['cmm_aggr_size'], $this->o["cmm_stars"]);
     }
     return $rating;
 }