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) . '" }'; }
function render_crb($template_id, $rpar = array()) { $rdef = array("cmm_id" => 0, "class" => "", "type" => "", "votes" => 0, "score" => 20, "style" => "oxygen", "unit_width" => 20, "unit_count" => 10, "allow_vote" => true, "user_id" => 0, "typecls" => "", "tags_css" => array(), "header_text" => "", "debug" => "", "wait_msg" => ""); $rpar = wp_parse_args($rpar, $rdef); $rpar = apply_filters('gdsr_t2parameters_crb', $rpar); extract($rpar, EXTR_SKIP); $template = GDSRRenderT2::get_template($template_id, "CRB"); $tpl_render = $template->elm["normal"]; $tpl_render = html_entity_decode($tpl_render); $tpl_render = apply_filters('gdsr_t2render_crb_normal', $tpl_render, $template, $rpar, "normal"); foreach ($tags_css as $tag => $value) { $tpl_render = str_replace('%' . $tag . '%', $value, $tpl_render); } $tpl_render = str_replace("%CMM_HEADER_TEXT%", html_entity_decode($header_text), $tpl_render); $rating2 = $votes > 0 ? $score / $votes : 0; if ($rating2 > $unit_count) { $rating2 = $unit_count; } $rating = @number_format($rating2, 1); $rating_width = $rating2 * $unit_width; $rater_length = $unit_width * $unit_count; $rater_id = $typecls . "_rater_" . $cmm_id; $loader_id = $typecls . "_loader_" . $cmm_id; if (in_array("%CMM_RATING_STARS%", $template->tag["normal"])) { $rating_stars = GDSRRender::rating_stars($style, $unit_width, $rater_id, $class, $rating_width, $allow_vote, $unit_count, $type, $cmm_id, $user_id, $loader_id, $rater_length, $typecls, $wait_msg, $template_id); $tpl_render = str_replace("%CMM_RATING_STARS%", $rating_stars, $tpl_render); } if (in_array("%CMM_RATING_TEXT%", $template->tag["normal"])) { $rating_text = GDSRRenderT2::render_crt($template->dep["CRT"], array("rating" => $rating, "unit_count" => $unit_count, "votes" => $votes)); $voted = $allow_vote ? '' : ' class="voted"'; $rating_text = '<div id="gdr_text_' . $type . $cmm_id . '"' . $voted . '>' . $rating_text . '</div>'; $tpl_render = str_replace("%CMM_RATING_TEXT%", $rating_text, $tpl_render); } if ($debug != '') { $tpl_render = '<div style="display: none">' . $debug . '</div>' . $tpl_render; } return $tpl_render; }
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 . "' }"; }
function render_crb($template_id, $cmm_id, $class, $type, $votes, $score, $style, $unit_width, $unit_count, $allow_vote, $user_id, $typecls, $tags_css, $header_text, $debug = '', $wait_msg = '') { $template = GDSRRenderT2::get_template($template_id, "CRB"); $tpl_render = $template->elm["normal"]; $tpl_render = html_entity_decode($tpl_render); foreach ($tags_css as $tag => $value) { $tpl_render = str_replace('%' . $tag . '%', $value, $tpl_render); } $tpl_render = str_replace("%CMM_HEADER_TEXT%", html_entity_decode($header_text), $tpl_render); $rating2 = $votes > 0 ? $score / $votes : 0; if ($rating2 > $unit_count) { $rating2 = $unit_count; } $rating = @number_format($rating2, 1); $rating_width = $rating2 * $unit_width; $rater_length = $unit_width * $unit_count; $rater_id = $typecls . "_rater_" . $cmm_id; $loader_id = $typecls . "_loader_" . $cmm_id; if (in_array("%CMM_RATING_STARS%", $template->tag["normal"])) { $rating_stars = GDSRRender::rating_stars($style, $unit_width, $rater_id, $class, $rating_width, $allow_vote, $unit_count, $type, $cmm_id, $user_id, $loader_id, $rater_length, $typecls, $wait_msg, $template_id); $tpl_render = str_replace("%CMM_RATING_STARS%", $rating_stars, $tpl_render); } if (in_array("%CMM_RATING_TEXT%", $template->tag["normal"])) { $rating_text = GDSRRenderT2::render_crt($template->dep["CRT"], $rating, $unit_count, $votes, $cmm_id); $rating_text = '<div id="gdr_text_' . $type . $cmm_id . '">' . $rating_text . '</div>'; $tpl_render = str_replace("%CMM_RATING_TEXT%", $rating_text, $tpl_render); } $tpl_render = '<div class="ratingblock">' . $tpl_render; if ($debug != '') { $tpl_render = '<div style="display: none">' . $debug . '</div>' . $tpl_render; } $tpl_render .= '</div>'; return $tpl_render; }