Exemplo n.º 1
0
 function render_tcb($template_id, $rpar = array())
 {
     $rdef = array("comment_id" => 0, "votes" => 0, "score" => 0, "votes_plus" => 0, "votes_minus" => 0, "style" => "starrating", "unit_width" => 20, "allow_vote" => true, "user_id" => 0, "tags_css" => array(), "header_text" => "", "debug" => "", "wait_msg" => "");
     $rpar = wp_parse_args($rpar, $rdef);
     $rpar = apply_filters('gdsr_t2parameters_tcb', $rpar);
     extract($rpar, EXTR_SKIP);
     $template = GDSRRenderT2::get_template($template_id, "TCB");
     $tpl_render = $allow_vote ? $template->elm["active"] : $template->elm["inactive"];
     $tpl_render = html_entity_decode($tpl_render);
     $tpl_render = apply_filters('gdsr_t2render_tcb_' . ($allow_vote ? "active" : "inactive"), $tpl_render, $template, $rpar, $allow_vote ? "active" : "inactive");
     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);
     if (in_array("%CMM_THUMBS_TEXT%", $allow_vote ? $template->tag["active"] : $template->tag["inactive"])) {
         $rating_text = GDSRRenderT2::render_tct($template->dep["TCT"], array("votes" => $votes, "score" => $score, "votes_plus" => $votes_plus, "votes_minus" => $votes_minus, "id" => $comment_id));
         $rating_text = '<div id="gdsr_thumb_text_' . $comment_id . '_c" class="gdt-size-' . $unit_width . ($allow_vote ? "" : " voted") . ' gdthumbtext">' . $rating_text . '</div>';
         $tpl_render = str_replace("%CMM_THUMBS_TEXT%", $rating_text, $tpl_render);
     }
     if (in_array("%THUMB_UP%", $allow_vote ? $template->tag["active"] : $template->tag["inactive"])) {
         if ($allow_vote) {
             $rater = sprintf('<div id="gdsr_thumb_%s_c_up" class="gdt-size-%s gdthumb gdup"><a id="gdsrX%sXupXcX%sX%sX%s" class="gdt-%s" rel="nofollow"></a></div>', $comment_id, $unit_width, $comment_id, $template_id, $unit_width, $wait_msg == '' ? "N" : "Y", $style);
             if ($wait_msg != '') {
                 $rater_wait = GDSRRender::rating_wait(sprintf("gdsr_thumb_%s_c_loader_up", $comment_id), $unit_width . "px", 'loadup', $wait_msg);
                 $rater .= sprintf($rater_wait, sprintf("width: %spx; height: %spx;", $unit_width, $unit_width));
             }
         } else {
             $rater = sprintf('<div id="gdsr_thumb_%s_c_up" class="gdt-size-%s gdthumb gdup"><div class="gdt-%s"></div></div>', $comment_id, $unit_width, $style);
         }
         $tpl_render = str_replace("%THUMB_UP%", $rater, $tpl_render);
     }
     if (in_array("%THUMB_DOWN%", $allow_vote ? $template->tag["active"] : $template->tag["inactive"])) {
         if ($allow_vote) {
             $rater = sprintf('<div id="gdsr_thumb_%s_c_dw" class="gdt-size-%s gdthumb gddw"><a id="gdsrX%sXdwXcX%sX%sX%s" class="gdt-%s" rel="nofollow"></a></div>', $comment_id, $unit_width, $comment_id, $template_id, $unit_width, $wait_msg == '' ? "N" : "Y", $style);
             if ($wait_msg != '') {
                 $rater_wait = GDSRRender::rating_wait(sprintf("gdsr_thumb_%s_c_loader_dw", $comment_id), $unit_width . "px", 'loaddw', $wait_msg);
                 $rater .= sprintf($rater_wait, sprintf("width: %spx; height: %spx;", $unit_width, $unit_width));
             }
         } else {
             $rater = sprintf('<div id="gdsr_thumb_%s_c_dw" class="gdt-size-%s gdthumb gddw"><div class="gdt-%s"></div></div>', $comment_id, $unit_width, $style);
         }
         $tpl_render = str_replace("%THUMB_DOWN%", $rater, $tpl_render);
     }
     if ($debug != '') {
         $tpl_render = '<div style="display: none">' . $debug . '</div>' . $tpl_render;
     }
     return $tpl_render;
 }
Exemplo n.º 2
0
 function vote_thumbs_comment($vote, $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;
     wp_gdsr_dump("VOTE THUMB", "[CMM: " . $id . "] --" . $vote . "-- [" . $user . "] " . $unit_width . "px");
     $allow_vote = $vote == "up" || $vote == "dw";
     if ($allow_vote) {
         $allow_vote = gdsrFrontHelp::check_cookie($id, 'cmmthumb');
     }
     if ($allow_vote) {
         $allow_vote = gdsrBlgDB::check_vote($id, $user, 'cmmthumb', $ip, $this->g->o["cmm_logged"] != 1, $this->g->o["cmm_allow_mixed_ip_votes"] == 1);
     }
     $vote_value = $vote == "up" ? 1 : -1;
     if ($allow_vote) {
         gdsrBlgDB::save_vote_comment_thumb($id, $user, $ip, $ua, $vote_value);
         gdsrFrontHelp::save_cookie($id, 'cmmthumb');
         do_action("gdsr_vote_thumb_comment", $id, $user, $vote_value);
     }
     $data = GDSRDatabase::get_comment_data($id);
     $post_data = GDSRDatabase::get_post_data($data->post_id);
     $votes = $score = $votes_plus = $votes_minus = 0;
     if ($post_data->rules_articles == "A" || $post_data->rules_articles == "N") {
         $votes = $data->user_recc_plus + $data->user_recc_minus + $data->visitor_recc_plus + $data->visitor_recc_minus;
         $score = $data->user_recc_plus - $data->user_recc_minus + $data->visitor_recc_plus - $data->visitor_recc_minus;
         $votes_plus = $data->user_recc_plus + $data->visitor_recc_plus;
         $votes_minus = $data->user_recc_minus + $data->visitor_recc_minus;
     } else {
         if ($post_data->rules_articles == "V") {
             $votes = $data->visitor_recc_plus + $data->visitor_recc_minus;
             $score = $data->visitor_recc_plus - $data->visitor_recc_minus;
             $votes_plus = $data->visitor_recc_plus;
             $votes_minus = $data->visitor_recc_minus;
         } else {
             $votes = $data->user_recc_plus + $data->user_recc_minus;
             $score = $data->user_recc_plus - $data->user_recc_minus;
             $votes_plus = $data->user_recc_plus;
             $votes_minus = $data->user_recc_minus;
         }
     }
     include STARRATING_PATH . 'code/t2/templates.php';
     $template = new gdTemplateRender($tpl_id, "TCB");
     $rt = GDSRRenderT2::render_tct($template->dep["TCT"], array("votes" => $votes, "score" => $score, "votes_plus" => $votes_plus, "votes_minus" => $votes_minus, "id" => $id, "vote_value" => $vote_value));
     return '{ "status": "ok", "value": "' . $score . '", "rater": "' . str_replace('"', '\\"', $rt) . '" }';
 }
Exemplo n.º 3
0
 function render_tcb($template_id, $rpar = array())
 {
     $rdef = array("comment_id" => 0, "votes" => 0, "score" => 0, "votes_plus" => 0, "votes_minus" => 0, "style" => "starrating", "unit_width" => 20, "already_voted" => false, "allow_vote" => true, "header_text" => "", "debug" => "", "wait_msg" => "", "tags_css" => array(), "user_id" => 0);
     $rpar = wp_parse_args($rpar, $rdef);
     $rpar = apply_filters('gdsr_t2parameters_tcb', $rpar);
     extract($rpar, EXTR_SKIP);
     $template = GDSRRenderT2::get_template($template_id, "TCB");
     $tpl_render = $allow_vote ? $template->elm["active"] : $template->elm["inactive"];
     $tpl_render = html_entity_decode($tpl_render);
     $tpl_render = apply_filters('gdsr_t2render_tcb_' . ($allow_vote ? "active" : "inactive"), $tpl_render, $template, $rpar, $allow_vote ? "active" : "inactive");
     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);
     $percent = $votes_plus + $votes_minus == 0 ? 0 : $votes_plus * 100 / ($votes_plus + $votes_minus);
     $percent = number_format($percent, 0);
     if ($percent == 0) {
         $percent = gdsr_zero_percentage();
     }
     $score_number = $score;
     $score = $score > 0 ? "+" . $score : $score;
     $css = intval($score_number) == 0 ? "zero" : (intval($score_number) > 0 ? "positive" : "negative");
     if ($already_voted) {
         $css .= " voted";
     }
     if (!$allow_vote) {
         $css .= " inactive";
     }
     $tpl_render = str_replace('%RATING%', apply_filters('gdsr_t2_tag_value', $score, "TCT", "%RATING%"), $tpl_render);
     $tpl_render = str_replace('%PERCENTAGE%', apply_filters('gdsr_t2_tag_value', $percent, "TCT", "%PERCENTAGE%"), $tpl_render);
     $tpl_render = str_replace('%VOTES%', apply_filters('gdsr_t2_tag_value', $votes, "TCT", "%VOTES%"), $tpl_render);
     $tpl_render = str_replace('%VOTES_UP%', apply_filters('gdsr_t2_tag_value', $votes_plus, "TCT", "%VOTES_UP%"), $tpl_render);
     $tpl_render = str_replace('%VOTES_DOWN%', apply_filters('gdsr_t2_tag_value', $votes_minus, "TCT", "%VOTES_DOWN%"), $tpl_render);
     $tpl_render = str_replace('%CSS_AUTO%', apply_filters('gdsr_t2_tag_value', $css, "TAB", "%CSS_AUTO%"), $tpl_render);
     $tpl_render = str_replace('%ID%', $comment_id, $tpl_render);
     if (in_array("%CMM_THUMBS_TEXT%", $allow_vote ? $template->tag["active"] : $template->tag["inactive"])) {
         $rating_text = GDSRRenderT2::render_tct($template->dep["TCT"], array("score_number" => $score_number, "percent" => $percent, "votes" => $votes, "score" => $score, "votes_plus" => $votes_plus, "votes_minus" => $votes_minus, "id" => $comment_id));
         $rating_text = '<div id="gdsr_thumb_text_' . $comment_id . '_c" class="gdt-size-' . $unit_width . ($already_voted ? " voted" : "") . ($allow_vote ? "" : " inactive") . ' gdthumbtext">' . $rating_text . '</div>';
         $tpl_render = str_replace("%CMM_THUMBS_TEXT%", $rating_text, $tpl_render);
     }
     if (in_array("%THUMB_UP%", $allow_vote ? $template->tag["active"] : $template->tag["inactive"])) {
         if ($allow_vote) {
             $rater = sprintf('<div id="gdsr_thumb_%s_c_up" class="gdt-size-%s gdthumb gdup"><a id="gdsrX%sXupXcX%sX%sX%s" class="gdt-%s" rel="nofollow"></a></div>', $comment_id, $unit_width, $comment_id, $template_id, $unit_width, $wait_msg == '' ? "N" : "Y", $style);
             if ($wait_msg != '') {
                 $rater_wait = GDSRRender::rating_wait(sprintf("gdsr_thumb_%s_c_loader_up", $comment_id), $unit_width . "px", ' loadup', $wait_msg);
                 $rater .= sprintf($rater_wait, sprintf("width: %spx; height: %spx;", $unit_width, $unit_width));
             }
         } else {
             $rater = sprintf('<div id="gdsr_thumb_%s_c_up" class="gdt-size-%s gdthumb gdup"><div class="gdt-%s"></div></div>', $comment_id, $unit_width, $style);
         }
         $tpl_render = str_replace("%THUMB_UP%", $rater, $tpl_render);
     }
     if (in_array("%THUMB_DOWN%", $allow_vote ? $template->tag["active"] : $template->tag["inactive"])) {
         if ($allow_vote) {
             $rater = sprintf('<div id="gdsr_thumb_%s_c_dw" class="gdt-size-%s gdthumb gddw"><a id="gdsrX%sXdwXcX%sX%sX%s" class="gdt-%s" rel="nofollow"></a></div>', $comment_id, $unit_width, $comment_id, $template_id, $unit_width, $wait_msg == '' ? "N" : "Y", $style);
             if ($wait_msg != '') {
                 $rater_wait = GDSRRender::rating_wait(sprintf("gdsr_thumb_%s_c_loader_dw", $comment_id), $unit_width . "px", ' loaddw', $wait_msg);
                 $rater .= sprintf($rater_wait, sprintf("width: %spx; height: %spx;", $unit_width, $unit_width));
             }
         } else {
             $rater = sprintf('<div id="gdsr_thumb_%s_c_dw" class="gdt-size-%s gdthumb gddw"><div class="gdt-%s"></div></div>', $comment_id, $unit_width, $style);
         }
         $tpl_render = str_replace("%THUMB_DOWN%", $rater, $tpl_render);
     }
     if ($debug != '') {
         $tpl_render = '<div style="display: none">' . $debug . '</div>' . $tpl_render;
     }
     return $tpl_render;
 }