示例#1
0
文件: votes.php 项目: hewu/blogwp
 function vote_comment($votes, $id, $tpl_id, $unit_width)
 {
     global $userdata;
     $user = is_object($userdata) ? $userdata->ID : 0;
     $ip = $_SERVER["REMOTE_ADDR"];
     if ($this->g->o["save_user_agent"] == 1) {
         $ua = $_SERVER["HTTP_USER_AGENT"];
     } else {
         $ua = "";
     }
     $vote_value = $votes;
     wp_gdsr_dump("VOTE_CMM", "[CMM: " . $id . "] --" . $votes . "-- [" . $user . "] " . $unit_width . "px");
     $allow_vote = intval($votes) <= $this->g->o["cmm_stars"] && intval($votes) > 0;
     if ($allow_vote) {
         $allow_vote = gdsrFrontHelp::check_cookie($id, 'comment');
     }
     if ($allow_vote) {
         $allow_vote = gdsrBlgDB::check_vote($id, $user, 'comment', $ip, $this->g->o["cmm_logged"] != 1, $this->g->o["cmm_allow_mixed_ip_votes"] == 1);
     }
     if ($allow_vote) {
         gdsrBlgDB::save_vote_comment($id, $user, $ip, $ua, $votes);
         gdsrFrontHelp::save_cookie($id, 'comment');
         do_action("gdsr_vote_rating_comment", $id, $user, $votes);
     }
     $data = GDSRDatabase::get_comment_data($id);
     $post_data = GDSRDatabase::get_post_data($data->post_id);
     $unit_count = $this->g->o["cmm_stars"];
     $votes = $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 = number_format($rating2 * $unit_width, 0);
     include STARRATING_PATH . 'code/t2/templates.php';
     $template = new gdTemplateRender($tpl_id, "CRB");
     $rt = GDSRRenderT2::render_crt($template->dep["CRT"], array("rating" => $rating1, "unit_count" => $unit_count, "votes" => $votes, "vote_value" => $vote_value));
     $rating_width = apply_filters("gdsr_vote_rating_comment_return", $rating_width, $unit_width, $rating1, $vote_value);
     return '{ "status": "ok", "value": "' . $rating_width . '", "rater": "' . str_replace('"', '\\"', $rt) . '" }';
 }
示例#2
0
/**
 * check witch rating plugin exist in wp and rate post
 * @param int $postId
 * @param int $rating
 * @param int $user_id
 * @return bool
 */
function wiziapp_do_actual_rating($postId, $rating = 0, $user_id = 0)
{
    $GLOBALS['WiziappLog']->write('info', "Got a rating request with {$postId}::{$rating}::{$user_id}", "wiziapp_do_rating");
    $postId = intval($postId);
    $rating = intval($rating);
    if (filter_var($user_id, FILTER_VALIDATE_IP)) {
        $ip = $user_id;
        $user_id = 0;
    } else {
        $ip = $_SERVER['REMOTE_ADDR'];
        $user_id = intval($user_id);
    }
    if ($rating < 1 && $rating > 5) {
        return false;
    }
    //polldaddy rating
    $id = get_option('pd-rating-posts-id');
    if (function_exists('polldaddy_show_rating_comments') && $id > 0) {
        $url = 'http://polldaddy.com/ratings/rate.php?';
        $url_query = array();
        $url_query['cmd'] = 'get';
        $url_query['id'] = get_option('pd-rating-posts-id');
        $url_query['uid'] = 'wp-post-' . $postId;
        $url_query['item_id'] = '_post_' . $postId;
        $link = $url . http_build_query($url_query);
        $matches = array();
        $get_content = wiziapp_general_http_request('', $link, 'GET');
        $get_content = $get_content['body'];
        preg_match("/\\.token='([a-z0-9]*)/", $get_content, $matches);
        $url_query['token'] = $matches[1];
        preg_match("/\\.avg_rating = ([a-z0-9]*)/", $get_content, $matches);
        $url_query['avg'] = $matches[1];
        preg_match("/\\.votes = ([a-z0-9]*)/", $get_content, $matches);
        $url_query['votes'] = $matches[1];
        $post = get_post($postId);
        $url_query['title'] = str_replace('&amp;', '&', $post->post_title);
        $url_query['permalink'] = $post->guid;
        $url_query['type'] = 'stars';
        $url_query['cmd'] = 'rate';
        $url_query['r'] = $rating;
        $link = $url . http_build_query($url_query);
        wiziapp_general_http_request('', $link, 'GET');
        return true;
    }
    //GD Star rating
    global $gdsr;
    if (is_object($gdsr) && get_class($gdsr) == 'GDStarRating') {
        $ua = $_SERVER["HTTP_USER_AGENT"];
        gdsrBlgDB::save_vote($postId, $user_id, $ip, $ua, $rating);
        gdsrFrontHelp::save_cookie($postId);
        do_action("gdsr_vote_rating_article", $postId, $user_id, $rating);
        return true;
    }
    //WP-PostRatings
    if (function_exists('process_ratings') && $postId > 0 && $user_id > 0) {
        $_GET['rate'] = $rating;
        $_GET['pid'] = $postId;
        global $user_ID;
        $user_ID = $user_id;
        process_ratings();
        return true;
    }
    return false;
}
示例#3
0
 function comment_save($comment_id)
 {
     global $userdata;
     $user_id = is_object($userdata) ? $userdata->ID : 0;
     $user = intval($user_id);
     $ip = $_SERVER["REMOTE_ADDR"];
     if ($this->post_comment["review"] > -1) {
         $comment_data = GDSRDatabase::get_comment_data($comment_id);
         if (count($comment_data) == 0) {
             GDSRDatabase::add_empty_comment($comment_id, $this->post_comment["post_id"], $this->post_comment["review"]);
         } else {
             GDSRDatabase::save_comment_review($comment_id, $this->post_comment["review"]);
         }
     }
     $std_minimum = $this->o["int_comment_std_zero"] == 1 ? -1 : 0;
     $mur_minimum = $this->o["int_comment_mur_zero"] == 1 ? 0 : 1;
     $id = $this->post_comment["post_id"];
     if ($this->post_comment["standard_rating"] > $std_minimum) {
         $votes = $this->post_comment["standard_rating"];
         $ua = $this->o["save_user_agent"] == 1 ? $_SERVER["HTTP_USER_AGENT"] : "";
         $allow_vote = true;
         if ($this->o["cmm_integration_prevent_duplicates"] == 1) {
             $allow_vote = intval($votes) <= $this->o["stars"];
             if ($allow_vote) {
                 $allow_vote = gdsrFrontHelp::check_cookie($id);
             }
             if ($allow_vote) {
                 $allow_vote = gdsrBlgDB::check_vote($id, $user, 'article', $ip, false, false);
             }
         }
         if ($allow_vote) {
             gdsrBlgDB::save_vote($id, $user, $ip, $ua, $votes, $comment_id);
             if ($this->o["cmm_integration_prevent_duplicates"] == 1) {
                 gdsrFrontHelp::save_cookie($id);
             }
             do_action("gdsr_vote_rating_article_integrate", $id, $user, $votes);
         }
     }
     if ($this->post_comment["multi_id"] > 0 && $this->post_comment["multi_rating"] != "") {
         $set_id = $this->post_comment["multi_id"];
         $set = gd_get_multi_set($set_id);
         $values = explode("X", $this->post_comment["multi_rating"]);
         $allow_vote = true;
         foreach ($values as $v) {
             if ($v > $set->stars || $v < $mur_minimum) {
                 $allow_vote = false;
                 break;
             }
         }
         if ($this->o["cmm_integration_prevent_duplicates"] == 1) {
             if ($allow_vote) {
                 $allow_vote = gdsrFrontHelp::check_cookie($id . "#" . $set_id, "multis");
             }
             if ($allow_vote) {
                 $allow_vote = GDSRDBMulti::check_vote($id, $user, $set_id, 'multis', $ip, false, false);
             }
         }
         if ($allow_vote) {
             $ip = $_SERVER["REMOTE_ADDR"];
             $ua = $this->o["save_user_agent"] == 1 ? $_SERVER["HTTP_USER_AGENT"] : "";
             $data = GDSRDatabase::get_post_data($id);
             GDSRDBMulti::save_vote($id, $set->multi_id, $user, $ip, $ua, $values, $data, $comment_id);
             GDSRDBMulti::recalculate_multi_averages($id, $set->multi_id, "", $set, true);
             if ($this->o["cmm_integration_prevent_duplicates"] == 1) {
                 gdsrFrontHelp::save_cookie($id . "#" . $set_id, "multis");
             }
             do_action("gdsr_vote_rating_multis_integrate", $id, $user, $set_id, $values);
         }
     }
 }