Exemplo n.º 1
0
 function vote_comment_ajax($votes, $id, $tpl_id)
 {
     global $userdata;
     $ip = $_SERVER["REMOTE_ADDR"];
     if ($this->o["save_user_agent"] == 1) {
         $ua = $_SERVER["HTTP_USER_AGENT"];
     } else {
         $ua = "";
     }
     $user = intval($userdata->ID);
     wp_gdsr_dump("VOTE_CMM", "[CMM: " . $id . "] --" . $votes . "-- [" . $user . "]");
     $allow_vote = intval($votes) <= $this->o["cmm_stars"];
     if ($allow_vote) {
         $allow_vote = $this->check_cookie($id, 'comment');
     }
     if ($allow_vote) {
         $allow_vote = GDSRDatabase::check_vote($id, $user, 'comment', $ip, $this->o["cmm_logged"] != 1, $this->o["cmm_allow_mixed_ip_votes"] == 1);
     }
     if ($allow_vote) {
         GDSRDatabase::save_vote_comment($id, $user, $ip, $ua, $votes);
         $this->save_cookie($id, 'comment');
     }
     $data = GDSRDatabase::get_comment_data($id);
     $post_data = GDSRDatabase::get_post_data($data->post_id);
     $unit_width = $this->o["cmm_size"];
     $unit_count = $this->o["cmm_stars"];
     $votes = 0;
     $score = 0;
     if ($post_data->rules_comments == "A" || $post_data->rules_comments == "N") {
         $votes = $data->user_voters + $data->visitor_voters;
         $score = $data->user_votes + $data->visitor_votes;
     } else {
         if ($post_data->rules_comments == "V") {
             $votes = $data->visitor_voters;
             $score = $data->visitor_votes;
         } else {
             $votes = $data->user_voters;
             $score = $data->user_votes;
         }
     }
     if ($votes > 0) {
         $rating2 = $score / $votes;
     } else {
         $rating2 = 0;
     }
     $rating1 = @number_format($rating2, 1);
     $rating_width = $rating2 * $unit_width;
     include $this->plugin_path . 'code/t2/gd-star-t2-templates.php';
     $template = new gdTemplateRender($tpl_id, "CRB");
     $rt = GDSRRenderT2::render_crt($template->dep["CRT"], $rating1, $unit_count, $votes, $post_id);
     return "{ status: 'ok', value: " . $rating_width . ", rater: '" . $rt . "' }";
 }