Exemplo n.º 1
0
Arquivo: data.php Projeto: hewu/blogwp
/**
 * Returns object with all needed rating properties for comment.
 *
 * @global object $comment comment data
 * @global GDStarRating $gdsr main rating class instance
 * @param int $post_id post to get rating for, leave 0 to get post from loop
 * @return object rating post properties
 */
function wp_gdsr_rating_comment($comment_id = 0)
{
    if ($comment_id < 1) {
        global $comment;
        $comment_id = $comment->comment_ID;
    }
    $comment_data = GDSRDatabase::get_comment_data($comment_id);
    if (count($comment_data) == 0) {
        return null;
    }
    return new GDSRCommentRating($comment_data);
}
Exemplo n.º 2
0
 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) . '" }';
 }
Exemplo n.º 3
0
 function render_comment($post, $comment, $user, $override = array())
 {
     if ($this->o["comments_active"] != 1) {
         return "";
     }
     if ($this->is_bot) {
         return "";
     }
     $dbg_allow = "F";
     $allow_vote = true;
     if ($this->is_ban && $this->o["ip_filtering"] == 1) {
         if ($this->o["ip_filtering_restrictive"] == 1) {
             return "";
         } else {
             $allow_vote = false;
         }
         $dbg_allow = "B";
     }
     $rd_unit_width = $this->o["cmm_size"];
     $rd_unit_count = $this->o["cmm_stars"];
     $rd_unit_style = $this->is_ie6 ? $this->o["cmm_style_ie6"] : $this->o["cmm_style"];
     $rd_post_id = intval($post->ID);
     $rd_user_id = intval($user->ID);
     $rd_comment_id = intval($comment->comment_ID);
     $rd_is_page = $post->post_type == "page" ? "1" : "0";
     if ($this->p) {
         $post_data = $this->p;
     } else {
         if (is_single() || is_page()) {
             $this->init_post();
             $post_data = $this->p;
         } else {
             $post_data = GDSRDatabase::get_post_data($rd_post_id);
             if (count($post_data) == 0) {
                 GDSRDatabase::add_default_vote($rd_post_id, $rd_is_page);
                 $post_data = GDSRDatabase::get_post_data($rd_post_id);
             }
         }
     }
     if ($post_data->rules_comments == "H") {
         return "";
     }
     $comment_data = GDSRDatabase::get_comment_data($rd_comment_id);
     if (count($comment_data) == 0) {
         GDSRDatabase::add_empty_comment($rd_comment_id, $rd_post_id);
         $comment_data = GDSRDatabase::get_comment_data($rd_comment_id);
     }
     if ($allow_vote) {
         if ($this->o["cmm_author_vote"] == 1 && $rd_user_id == $comment->user_id && $rd_user_id > 0) {
             $allow_vote = false;
             $dbg_allow = "A";
         }
     }
     if ($allow_vote) {
         if ($post_data->rules_comments == "" || $post_data->rules_comments == "A" || $post_data->rules_comments == "U" && $rd_user_id > 0 || $post_data->rules_comments == "V" && $rd_user_id == 0) {
             $allow_vote = true;
         } else {
             $allow_vote = false;
             $dbg_allow = "R_" . $post_data->rules_comments;
         }
     }
     if ($allow_vote) {
         $allow_vote = GDSRDatabase::check_vote($rd_comment_id, $rd_user_id, 'comment', $_SERVER["REMOTE_ADDR"], $this->o["cmm_logged"] != 1, $this->o["cmm_allow_mixed_ip_votes"] == 1);
         if (!$allow_vote) {
             $dbg_allow = "D";
         }
     }
     if ($allow_vote) {
         $allow_vote = $this->check_cookie($rd_comment_id, "comment");
         if (!$allow_vote) {
             $dbg_allow = "C";
         }
     }
     $votes = 0;
     $score = 0;
     if ($post_data->rules_comments == "A" || $post_data->rules_comments == "N") {
         $votes = $comment_data->user_voters + $comment_data->visitor_voters;
         $score = $comment_data->user_votes + $comment_data->visitor_votes;
     } else {
         if ($post_data->rules_comments == "V") {
             $votes = $comment_data->visitor_voters;
             $score = $comment_data->visitor_votes;
         } else {
             $votes = $comment_data->user_voters;
             $score = $comment_data->user_votes;
         }
     }
     $debug = $rd_user_id == 0 ? "V" : "U";
     $debug .= $rd_user_id == $comment->user_id ? "A" : "N";
     $debug .= ":" . $dbg_allow . " [" . STARRATING_VERSION . "]";
     $tags_css = array();
     $tags_css["CMM_CSS_BLOCK"] = $this->o["cmm_class_block"];
     $tags_css["CMM_CSS_HEADER"] = $this->o["srb_class_header"];
     $tags_css["CMM_CSS_STARS"] = $this->o["cmm_class_stars"];
     $tags_css["CMM_CSS_TEXT"] = $this->o["cmm_class_text"];
     if ($override["tpl"] > 0) {
         $template_id = $override["tpl"];
     } else {
         $template_id = $this->o["default_crb_template"];
     }
     $rating_block = GDSRRenderT2::render_crb($template_id, $rd_comment_id, "ratecmm", "c", $votes, $score, $rd_unit_style, $rd_unit_width, $rd_unit_count, $allow_vote, $rd_user_id, "comment", $tags_css, $this->o["cmm_header_text"], $debug, $this->loader_comment);
     return $rating_block;
 }
Exemplo n.º 4
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);
         }
     }
 }
Exemplo n.º 5
0
function wp_gdget_comment($comment_id)
{
    global $gdsr_cache_posts_cmm_data;
    $cmm = $gdsr_cache_posts_cmm_data->get($comment_id);
    if (!is_null($cmm) && is_object($cmm)) {
        return $cmm;
    } else {
        $cmm = GDSRDatabase::get_comment_data($comment_id);
        if (!is_object($cmm)) {
            return null;
        }
        $gdsr_cache_posts_cmm_data->set($comment_id, $cmm);
        return $cmm;
    }
}