Exemplo n.º 1
0
 function vote_article($votes, $id, $tpl_id, $unit_width)
 {
     global $userdata;
     $ip = $_SERVER["REMOTE_ADDR"];
     $ua = $this->g->o["save_user_agent"] == 1 ? $_SERVER["HTTP_USER_AGENT"] : "";
     $user = is_object($userdata) ? $userdata->ID : 0;
     $vote_value = $votes;
     wp_gdsr_dump("VOTE", "[POST: " . $id . "] --" . $votes . "-- [" . $user . "] " . $unit_width . "px");
     $allow_vote = intval($votes) <= $this->g->o["stars"] && intval($votes) > 0;
     if ($allow_vote) {
         $allow_vote = gdsrFrontHelp::check_cookie($id);
     }
     if ($allow_vote) {
         $allow_vote = gdsrBlgDB::check_vote($id, $user, 'article', $ip, $this->g->o["logged"] != 1, $this->g->o["allow_mixed_ip_votes"] == 1);
     }
     if ($allow_vote) {
         gdsrBlgDB::save_vote($id, $user, $ip, $ua, $votes);
         gdsrFrontHelp::save_cookie($id);
         do_action("gdsr_vote_rating_article", $id, $user, $votes);
     }
     $data = GDSRDatabase::get_post_data($id);
     $unit_count = $this->g->o["stars"];
     $votes = $score = 0;
     if ($data->rules_articles == "A" || $data->rules_articles == "N") {
         $votes = $data->user_voters + $data->visitor_voters;
         $score = $data->user_votes + $data->visitor_votes;
     } else {
         if ($data->rules_articles == "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 = @number_format($rating2 * $unit_width, 0);
     include STARRATING_PATH . 'code/t2/templates.php';
     $template = new gdTemplateRender($tpl_id, "SRB");
     $rt = GDSRRenderT2::render_srt_voted($template->dep["SRT"], array("rating" => $rating1, "unit_count" => $unit_count, "votes" => $votes, "id" => $id, "vote" => $vote_value));
     $rating_width = apply_filters("gdsr_vote_rating_article_return", $rating_width, $unit_width, $rating1, $vote_value);
     return '{ "status": "ok", "value": "' . $rating_width . '", "rater": "' . str_replace('"', '\\"', $rt) . '" }';
 }