Example #1
0
 /**
  * Class constructor.
  *
  * @param object $post_data multi rating results from the database
  * @param int $set_id multi rating set id
  */
 function GDSRArticleMultiRating($post_data, $set_id)
 {
     $this->set = gd_get_multi_set($set_id);
     $this->review = $post_data->average_review;
     $this->user_votes = $post_data->total_votes_users;
     $this->visitor_votes = $post_data->total_votes_visitors;
     $this->votes = $post_data->total_votes_users + $post_data->total_votes_visitors;
     $this->user_rating = $post_data->average_rating_users;
     $this->visitor_rating = $post_data->average_rating_visitors;
     $totals = $this->user_rating * $this->user_votes + $this->visitor_rating * $this->visitor_votes;
     if ($this->votes > 0) {
         $this->rating = number_format($totals / $this->votes, 1);
     }
 }
 function render_multi_editor($settings)
 {
     $multi_id = $settings["multi_id"] == 0 ? $this->g->o["mur_review_set"] : $settings["multi_id"];
     $post_id = $settings["post_id"];
     $init_votes = $settings["votes"];
     $set = gd_get_multi_set($multi_id);
     if (is_null($set)) {
         $set = gd_get_multi_set();
     }
     $multi_id = !is_null($set) ? $set->multi_id : 0;
     if ($multi_id > 0 && $post_id > 0) {
         $vote_id = GDSRDBMulti::get_vote($post_id, $multi_id, count($set->object));
         $multi_data = GDSRDBMulti::get_values($vote_id, 'rvw');
         if (count($multi_data) == 0) {
             GDSRDBMulti::add_empty_review_values($vote_id, count($set->object));
             $multi_data = GDSRDBMulti::get_values($vote_id, 'rvw');
         }
     } else {
         $multi_data = array();
     }
     $votes = array();
     if (count($multi_data) > 0) {
         foreach ($multi_data as $md) {
             $single_vote = array();
             $single_vote["votes"] = 1;
             $single_vote["score"] = $md->user_votes;
             $single_vote["rating"] = $md->user_votes;
             $votes[] = $single_vote;
         }
     } else {
         for ($i = 0; $i < count($set->object); $i++) {
             $iv = isset($init_votes[$i]) ? $init_votes[$i] : 0;
             $votes[] = array("votes" => $iv == 0 ? 0 : 1, "score" => $iv == 0 ? 0 : $iv, "rating" => $iv == 0 ? 0 : $iv);
         }
     }
     if ($settings["admin"]) {
         include $this->g->plugin_path . 'integrate/edit_multi.php';
     } else {
         return GDSRRenderT2::render_mre(intval($settings["tpl"]), array("post_id" => $settings["post_id"], "style" => $settings["style"], "height" => $settings["size"], "votes" => $votes, "set" => $set, "allow_vote" => true));
     }
 }
 function render_multi_custom_values($template_id, $multi_set_id, $custom_id, $votes, $header_text = '', $override = array(), $tags_css = array(), $star_factor = 1)
 {
     $set = gd_get_multi_set($multi_set_id);
     $rd_unit_width = $override["size"];
     $rd_unit_style = $this->g->is_ie6 ? $override["style_ie6"] : $override["style"];
     $rd_unit_width_avg = isset($override["average_size"]) ? $override["average_size"] : $override["style"];
     $rd_unit_style_avg = isset($override["average_stars"]) ? $this->g->is_ie6 ? $override["average_stars_ie6"] : $override["average_stars"] : $override["style"];
     return GDSRRenderT2::render_mrb($template_id, array("style" => $rd_unit_style, "allow_vote" => false, "votes" => $votes, "post_id" => $custom_id, "set" => $set, "height" => $rd_unit_width, "header_text" => $header_text, "tags_css" => array("MUR_CSS_BLOCK" => ""), "avg_style" => $rd_unit_style_avg, "avg_size" => $rd_unit_width_avg, "star_factor" => $star_factor));
 }
Example #4
0
    $number_posts = $number_posts_post;
} else {
    if ($select == "page") {
        $number_posts = $number_posts_page;
    } else {
        $number_posts = $number_posts_all;
    }
}
$max_page = floor($number_posts / $posts_per_page);
if ($max_page * $posts_per_page != $number_posts) {
    $max_page++;
}
if ($max_page > 1) {
    $pager = GDSRHelper::draw_pager($max_page, $page_id, $url, "pg");
}
$set = gd_get_multi_set($set_id);
?>

<script>
function checkAll(form) {
    for (i = 0, n = form.elements.length; i < n; i++) {
        if(form.elements[i].type == "checkbox" && !(form.elements[i].getAttribute('onclick', 2))) {
            if(form.elements[i].checked == true)
                form.elements[i].checked = false;
            else
                form.elements[i].checked = true;
        }
    }
}
</script>
 function add_vote($post_id, $set_id, $user_id, $ip, $ua, $votes)
 {
     global $wpdb, $table_prefix;
     $set = gd_get_multi_set($set_id);
     $data = $table_prefix . 'gdsr_multis_data';
     $trend = $table_prefix . 'gdsr_multis_trend';
     $trend_date = date("Y-m-d");
     $sql_trend = sprintf("SELECT id FROM %s WHERE vote_date = '%s' and post_id = %s and multi_id = %s", $trend, $trend_date, $post_id, $set_id);
     wp_gdsr_dump("TREND_CHECK", $sql_trend);
     $trend_data = intval($wpdb->get_var($sql_trend));
     wp_gdsr_dump("TREND_ID", $trend_data);
     $trend_added = false;
     if ($trend_data == 0) {
         $trend_added = true;
         $sql = sprintf("INSERT INTO %s (post_id, multi_id, vote_date) VALUES (%s, %s, '%s')", $trend, $post_id, $set_id, $trend_date);
         $wpdb->query($sql);
         $trend_id = $wpdb->insert_id;
     } else {
         $trend_id = $trend_data;
     }
     GDSRDBMulti::add_values($trend_id, $user_id, $votes, "trd", $trend_added ? "add" : "edit");
     GDSRDBMulti::recalculate_trend_averages($trend_id, $set);
     $data_id = GDSRDBMulti::get_vote($post_id, $set_id, count($set->object));
     GDSRDBMulti::add_values($data_id, $user_id, $votes);
 }
Example #6
0
/**
 * Save multi rating or review for a post
 *
 * @param int $post_id id of the post to add values
 * @param int $multi_set_id multi set id
 * @param array $values list of values
 */
function gdsr_save_multi_review($post_id, $multi_set_id, $values)
{
    global $gdsr;
    $set = gd_get_multi_set($multi_set_id);
    $clean = array();
    foreach ($values as $v) {
        if ($v < 1) {
            $v = 1;
        }
        $clean[] = $v > $set->stars ? $set->stars : $v;
    }
    $record_id = GDSRDBMulti::get_vote($post_id, $multi_set_id, count($set->object));
    GDSRDBMulti::save_review($record_id, $clean);
    GDSRDBMulti::recalculate_multi_review($record_id, $clean, $set);
}
Example #7
0
 function vote_multis($votes, $post_id, $set_id, $tpl_id, $size)
 {
     global $userdata;
     $ip = $_SERVER["REMOTE_ADDR"];
     if ($this->g->o["save_user_agent"] == 1) {
         $ua = $_SERVER["HTTP_USER_AGENT"];
     } else {
         $ua = "";
     }
     $user = is_object($userdata) ? $userdata->ID : 0;
     $data = GDSRDatabase::get_post_data($post_id);
     $set = gd_get_multi_set($set_id);
     wp_gdsr_dump("VOTE_MUR", "[POST: " . $post_id . "|SET: " . $set_id . "] --" . $votes . "-- [" . $user . "]");
     $values = explode("X", $votes);
     $allow_vote = true;
     foreach ($values as $v) {
         if ($v > $set->stars) {
             $allow_vote = false;
             break;
         }
     }
     $vote_value = GDSRDBMulti::recalculate_multi_vote($values, $set);
     if ($allow_vote) {
         $allow_vote = gdsrFrontHelp::check_cookie($post_id . "#" . $set_id, "multis");
     }
     if ($allow_vote) {
         $allow_vote = GDSRDBMulti::check_vote($post_id, $user, $set_id, 'multis', $ip, $this->g->o["logged"] != 1, $this->g->o["mur_allow_mixed_ip_votes"] == 1);
     }
     $rating = 0;
     $total_votes = 0;
     $json = $summary = array();
     if ($allow_vote) {
         GDSRDBMulti::save_vote($post_id, $set_id, $user, $ip, $ua, $values, $data);
         $summary = GDSRDBMulti::recalculate_multi_averages($post_id, $set_id, $data->rules_articles, $set, true, $size);
         gdsrFrontHelp::save_cookie($post_id . "#" . $set_id, "multis");
         $rating = $summary["total"]["rating"];
         $total_votes = $summary["total"]["votes"];
         $json = $summary["json"];
         do_action("gdsr_vote_rating_multis", $post_id, $user, $set_id, $values, $rating);
     }
     include STARRATING_PATH . 'code/t2/templates.php';
     $template = new gdTemplateRender($tpl_id, "MRB");
     $rt = GDSRRenderT2::render_srt_voted($template->dep["MRT"], array("rating" => $rating, "unit_count" => $set->stars, "votes" => $total_votes, "id" => $post_id, "vote" => $vote_value));
     $json = apply_filters("gdsr_vote_rating_multis_return", $json, $summary, $values);
     $enc_values = "[" . join(",", $json) . "]";
     return '{ "status": "ok", "values": ' . $enc_values . ', "rater": "' . str_replace('"', '\\"', $rt) . '", "average": "' . $rating . '" }';
 }
Example #8
0
 function init_operations()
 {
     $msg = "";
     if (isset($_POST["gdsr_multi_review_form"]) && $_POST["gdsr_multi_review_form"] == "review") {
         $mur_all = $_POST['gdsrmulti'];
         foreach ($mur_all as $post_id => $data) {
             if ($post_id > 0) {
                 foreach ($data as $set_id => $mur) {
                     $set = gd_get_multi_set($set_id);
                     $values = explode("X", $mur);
                     $record_id = GDSRDBMulti::get_vote($post_id, $set_id, count($set->object));
                     GDSRDBMulti::save_review($record_id, $values);
                     GDSRDBMulti::recalculate_multi_review($record_id, $values, $set);
                 }
             }
         }
         $this->custom_actions('init_save_review');
         wp_redirect_self();
         exit;
     }
     if (isset($_POST["gdsr_editcss_rating"])) {
         $rating_css = STARRATING_XTRA_PATH . "css/rating.css";
         if (is_writeable($rating_css)) {
             $newcontent = stripslashes($_POST['gdsr_editcss_contents']);
             $f = fopen($rating_css, 'w+');
             fwrite($f, $newcontent);
             fclose($f);
         }
         wp_redirect_self();
         exit;
     }
     if (isset($_POST['gdsr_debug_clean'])) {
         wp_gdsr_debug_clean();
         wp_redirect_self();
         exit;
     }
     if (isset($_POST['gdsr_cache_clean'])) {
         GDSRHelper::clean_cache(substr(STARRATING_CACHE_PATH, 0, strlen(STARRATING_CACHE_PATH) - 1));
         $this->o["cache_cleanup_last"] = date("r");
         update_option('gd-star-rating', $this->o);
         wp_redirect_self();
         exit;
     }
     if (isset($_POST['gdsr_preview_scan'])) {
         $this->g = gdsrAdmFunc::gfx_scan();
         update_option('gd-star-rating-gfx', $this->g);
         wp_redirect_self();
         exit;
     }
     if (isset($_POST['gdsr_t2_import'])) {
         gdsrAdmDB::insert_extras_templates(STARRATING_XTRA_PATH, false);
         wp_redirect_self();
         exit;
     }
     if (isset($_POST['gdsr_upgrade_tool'])) {
         require_once STARRATING_PATH . "/gdragon/gd_db_install.php";
         gdDBInstallGDSR::delete_tables(STARRATING_PATH);
         gdDBInstallGDSR::create_tables(STARRATING_PATH);
         gdDBInstallGDSR::upgrade_tables(STARRATING_PATH);
         gdDBInstallGDSR::alter_tables(STARRATING_PATH);
         gdDBInstallGDSR::alter_tables(STARRATING_PATH, "idx.txt");
         $this->o["database_upgrade"] = date("r");
         update_option('gd-star-rating', $this->o);
         wp_redirect_self();
         exit;
     }
     if (isset($_POST['gdsr_updatemultilog_tool'])) {
         GDSRDBMulti::recalculate_multi_rating_log();
         wp_redirect_self();
         exit;
     }
     if (isset($_POST['gdsr_mulitrecalc_tool'])) {
         $set_id = $_POST['gdsr_mulitrecalc_set'];
         if ($set_id > 0) {
             GDSRDBMulti::recalculate_set($set_id);
         } else {
             GDSRDBMulti::recalculate_all_sets();
         }
         wp_redirect_self();
         exit;
     }
     if (isset($_POST['gdsr_cleanup_tool'])) {
         if (isset($_POST['gdsr_tools_clean_invalid_log'])) {
             $count = gdsrTlsDB::clean_invalid_log_articles();
             if ($count > 0) {
                 $msg .= $count . " " . __("articles records from log table removed.", "gd-star-rating") . " ";
             }
             $count = gdsrTlsDB::clean_invalid_log_comments();
             if ($count > 0) {
                 $msg .= $count . " " . __("comments records from log table removed.", "gd-star-rating") . " ";
             }
         }
         if (isset($_POST['gdsr_tools_clean_invalid_trend'])) {
             $count = gdsrTlsDB::clean_invalid_trend_articles();
             if ($count > 0) {
                 $msg .= $count . " " . __("articles records from trends log table removed.", "gd-star-rating") . " ";
             }
             $count = gdsrTlsDB::clean_invalid_trend_comments();
             if ($count > 0) {
                 $msg .= $count . " " . __("comments records from trends log table removed.", "gd-star-rating") . " ";
             }
         }
         if (isset($_POST['gdsr_tools_clean_old_posts'])) {
             $count = gdsrTlsDB::clean_dead_articles();
             if ($count > 0) {
                 $msg .= $count . " " . __("dead articles records from articles table.", "gd-star-rating") . " ";
             }
             $count = gdsrTlsDB::clean_revision_articles();
             if ($count > 0) {
                 $msg .= $count . " " . __("post revisions records from articles table.", "gd-star-rating") . " ";
             }
             $count = gdsrTlsDB::clean_dead_comments();
             if ($count > 0) {
                 $msg .= $count . " " . __("dead comments records from comments table.", "gd-star-rating") . " ";
             }
         }
         if (isset($_POST['gdsr_tools_clean_old_posts'])) {
             $count = GDSRDBMulti::clean_dead_articles();
             if ($count > 0) {
                 $msg .= $count . " " . __("dead articles records from multi ratings tables.", "gd-star-rating") . " ";
             }
             $count = GDSRDBMulti::clean_revision_articles();
             if ($count > 0) {
                 $msg .= $count . " " . __("post revisions records from multi ratings tables.", "gd-star-rating") . " ";
             }
         }
         $this->o["database_cleanup"] = date("r");
         $this->o["database_cleanup_msg"] = $msg;
         update_option('gd-star-rating', $this->o);
         wp_redirect_self();
         exit;
     }
     if (isset($_POST['gdsr_post_lock'])) {
         $lock_date = $_POST['gdsr_lock_date'];
         gdsrAdmDB::lock_post_massive($lock_date);
         $this->o["mass_lock"] = $lock_date;
         update_option('gd-star-rating', $this->o);
         wp_redirect_self();
         exit;
     }
     if (isset($_POST['gdsr_rules_set'])) {
         wp_gdsr_dump("POST", $_POST);
         gdsrAdmDB::update_settings_full($_POST["gdsr_article_moderation"], $_POST["gdsr_article_voterules"], $_POST["gdsr_comments_moderation"], $_POST["gdsr_comments_voterules"], $_POST["gdsr_artthumb_moderation"], $_POST["gdsr_artthumb_voterules"], $_POST["gdsr_cmmthumbs_moderation"], $_POST["gdsr_cmmthumbs_voterules"]);
         wp_redirect_self();
         exit;
     }
 }
 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);
 }
Example #10
0
function wp_gdget_multi_set($multi_id)
{
    global $gdsr_cache_multi_sets;
    $set = $gdsr_cache_multi_sets->get($multi_id);
    if (!is_null($set) && is_object($set)) {
        return $set;
    } else {
        $set = gd_get_multi_set($multi_id);
        $gdsr_cache_multi_sets->set($multi_id, $set);
        return $set;
    }
}