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) . '" }'; }
/** * 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('&', '&', $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; }
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); } } }