示例#1
0
文件: data.php 项目: hewu/blogwp
/**
 * Returns object with all needed rating properties for post or page.
 *
 * @global object $post post 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_article($post_id = 0)
{
    if ($post_id < 1) {
        global $post;
        $post_id = $post->ID;
    }
    $post_data = GDSRDatabase::get_post_data($post_id);
    if (count($post_data) == 0) {
        return null;
    }
    return new GDSRArticleRating($post_data);
}
 function render_article_rss()
 {
     global $post;
     $rd_post_id = intval($post->ID);
     $post_data = GDSRDatabase::get_post_data($rd_post_id);
     $template_id = $this->g->o["default_ssb_template"];
     $votes = $score = 0;
     $stars = 10;
     if ($this->g->o["rss_datasource"] == "thumbs") {
         if ($rules_articles == "A" || $rules_articles == "N") {
             $votes = $post_data->user_recc_plus + $post_data->user_recc_minus + $post_data->visitor_recc_plus + $post_data->visitor_recc_minus;
             $score = $post_data->user_recc_plus - $post_data->user_recc_minus + $post_data->visitor_recc_plus - $post_data->visitor_recc_minus;
         } else {
             if ($rules_articles == "V") {
                 $votes = $post_data->visitor_recc_plus + $post_data->visitor_recc_minus;
                 $score = $post_data->visitor_recc_plus - $post_data->visitor_recc_minus;
             } else {
                 $votes = $post_data->user_recc_plus + $post_data->user_recc_minus;
                 $score = $post_data->user_recc_plus - $post_data->user_recc_minus;
             }
         }
     } else {
         if ($this->g->o["rss_datasource"] == "standard") {
             $stars = $this->g->o["stars"];
             if ($post_data->rules_articles == "A" || $post_data->rules_articles == "N") {
                 $votes = $post_data->user_voters + $post_data->visitor_voters;
                 $score = $post_data->user_votes + $post_data->visitor_votes;
             } else {
                 if ($post_data->rules_articles == "V") {
                     $votes = $post_data->visitor_voters;
                     $score = $post_data->visitor_votes;
                 } else {
                     $votes = $post_data->user_voters;
                     $score = $post_data->user_votes;
                 }
             }
         } else {
             $data = gdsrBlgDB::get_rss_multi_data($post_id);
             if (count($row) > 0) {
                 $set = wp_gdget_multi_set($data->multi_id);
                 $stars = $set->stars;
                 if ($post_data->rules_articles == "A" || $post_data->rules_articles == "N") {
                     $sum = $data->average_rating_users * $data->total_votes_users + $data->average_rating_visitors * $data->total_votes_visitors;
                     $votes = $data->total_votes_visitors + $data->total_votes_users;
                     $score = number_format($votes == 0 ? 0 : $sum / $votes, 1);
                 } else {
                     if ($post_data->rules_articles == "V") {
                         $votes = $data->total_votes_visitors;
                         $score = $data->average_rating_visitors;
                     } else {
                         $votes = $data->total_votes_users;
                         $score = $data->average_rating_users;
                     }
                 }
             }
         }
     }
     $rating_block = GDSRRenderT2::render_ssb($template_id, array("post_id" => $rd_post_id, "votes" => $votes, "score" => $score, "unit_count" => $stars, "header_text" => $this->g->o["rss_header_text"], "type" => $this->g->o["rss_datasource"]));
     return $rating_block;
 }
示例#3
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) . '" }';
 }
示例#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);
         }
     }
 }
示例#5
0
 function render_multi_rating($post, $user, $settings)
 {
     if ($this->is_bot) {
         return "";
     }
     if (is_feed()) {
         return "";
     }
     $set = gd_get_multi_set($settings["id"]);
     if ($set == null) {
         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";
     }
     if ($settings["read_only"] == 1) {
         $dbg_allow = "RO";
         $allow_vote = false;
     }
     if (is_single() || is_page() && $this->o["display_comment_page"] == 1) {
         $this->init_post();
     }
     $rd_post_id = intval($post->ID);
     $rd_user_id = intval($user->ID);
     $rd_is_page = $post->post_type == "page" ? "1" : "0";
     $remaining = 0;
     $deadline = "";
     if ($this->p) {
         $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_articles == "H") {
         return "";
     }
     if ($allow_vote) {
         if ($this->o["author_vote"] == 1 && $rd_user_id == $post->post_author) {
             $allow_vote = false;
             $dbg_allow = "A";
         }
     }
     if ($allow_vote) {
         if ($post_data->rules_articles == "" || $post_data->rules_articles == "A" || $post_data->rules_articles == "U" && $rd_user_id > 0 || $post_data->rules_articles == "V" && $rd_user_id == 0) {
             $allow_vote = true;
         } else {
             $allow_vote = false;
             $dbg_allow = "R_" . $post_data->rules_articles;
         }
     }
     if ($allow_vote && ($post_data->expiry_type == 'D' || $post_data->expiry_type == 'T')) {
         switch ($post_data->expiry_type) {
             case "D":
                 $remaining = GDSRHelper::expiration_date($post_data->expiry_value);
                 $deadline = $post_data->expiry_value;
                 break;
             case "T":
                 $remaining = GDSRHelper::expiration_countdown($post->post_date, $post_data->expiry_value);
                 $deadline = GDSRHelper::calculate_deadline($remaining);
                 break;
         }
         if ($remaining < 1) {
             GDSRDatabase::lock_post($rd_post_id);
             $allow_vote = false;
             $dbg_allow = "T";
         }
     }
     if ($allow_vote) {
         $allow_vote = GDSRDBMulti::check_vote($rd_post_id, $rd_user_id, $set->multi_id, 'multis', $_SERVER["REMOTE_ADDR"], $this->o["logged"] != 1, $this->o["mur_allow_mixed_ip_votes"] == 1);
         if (!$allow_vote) {
             $dbg_allow = "D";
         }
     }
     if ($allow_vote) {
         $allow_vote = $this->check_cookie($rd_post_id . "#" . $set->multi_id, "multis");
         if (!$allow_vote) {
             $dbg_allow = "C";
         }
     }
     $multi_record_id = GDSRDBMulti::get_vote($rd_post_id, $set->multi_id, count($set->object));
     $multi_data = GDSRDBMulti::get_values($multi_record_id);
     $votes = array();
     foreach ($multi_data as $md) {
         $single_vote = array();
         $single_vote["votes"] = 0;
         $single_vote["score"] = 0;
         if ($post_data->rules_articles == "A" || $post_data->rules_articles == "N") {
             $single_vote["votes"] = $md->user_voters + $md->visitor_voters;
             $single_vote["score"] = $md->user_votes + $md->visitor_votes;
         } else {
             if ($post_data->rules_articles == "V") {
                 $single_vote["votes"] = $md->visitor_voters;
                 $single_vote["score"] = $md->visitor_votes;
             } else {
                 $single_vote["votes"] = $md->user_voters;
                 $single_vote["score"] = $md->user_votes;
             }
         }
         if ($single_vote["votes"] > 0) {
             $rating = $single_vote["score"] / $single_vote["votes"];
         } else {
             $rating = 0;
         }
         if ($rating > $set->stars) {
             $rating = $set->stars;
         }
         $single_vote["rating"] = @number_format($rating, 1);
         $votes[] = $single_vote;
     }
     $debug = $rd_user_id == 0 ? "V" : "U";
     $debug .= $rd_user_id == $post->post_author ? "A" : "N";
     $debug .= ":" . $dbg_allow . " [" . STARRATING_VERSION . "]";
     $tags_css = array();
     $tags_css["MUR_CSS_BLOCK"] = $this->o["mur_class_block"];
     $tags_css["MUR_CSS_HEADER"] = $this->o["mur_class_header"];
     $tags_css["MUR_CSS_TEXT"] = $this->o["mur_class_text"];
     $tags_css["MUR_CSS_BUTTON"] = $this->o["mur_class_button"];
     if ($settings["tpl"] > 0) {
         $template_id = $settings["tpl"];
     } else {
         $template_id = $this->o["default_mrb_template"];
     }
     return GDSRRenderT2::render_mrb($this->o["mur_style"], $template_id, $allow_vote, $votes, $rd_post_id, $set, $this->o["mur_size"], $this->o["mur_header_text"], $tags_css, $settings["average_stars"], $settings["average_size"], $post_data->expiry_type, $remaining, $deadline, $this->o["mur_button_active"] == 1, $this->o["mur_button_text"], $debug, $this->loader_multis);
 }
示例#6
0
function wp_gdget_post($post_id)
{
    global $gdsr_cache_posts_std_data;
    $post = $gdsr_cache_posts_std_data->get($post_id);
    if (!is_null($post) && is_object($post)) {
        return $post;
    } else {
        $post = GDSRDatabase::get_post_data($post_id);
        if (!is_object($post)) {
            return null;
        }
        $gdsr_cache_posts_std_data->set($post_id, $post);
        return $post;
    }
}
示例#7
0
function gd_get_rating_ajax($post)
{
    $rating = GDSRDatabase::get_post_data($post->ID);
    $uservoters = $rating->user_voters;
    $visitorvoters = $rating->visitor_voters;
    $votes = $uservoters + $visitorvotes;
    $uservotes = $rating->user_votes;
    $visitorvotes = $rating->visitor_votes;
    if ($votes > 0) {
        $finalrating = number_format(($visitorvotes + $uservotes) / ($visitorvoters + $uservoters), 1);
    }
    return GDSRRender::render_static_stars("magnovus", "20", "5", $finalrating, "", "", 1);
}