function find_gfx($gfx, $folder) { $result = null; foreach ($gfx as $s) { if ($s->folder == $folder) { $result = $s; break; } } if (is_null($result)) { wp_gdsr_dump("INVALID_SET_REQUEST", "Requested set name: " . $folder); } return $result; }
function get_widget_comments($widget, $post_id) { global $table_prefix; $where = array(); $select = "p.comment_id, p.comment_author, p.comment_author_email, p.comment_author_url, p.comment_date, p.comment_content, p.user_id, d.*"; $extras = ", 0 as votes, 0 as voters, 0 as rating, '' as permalink, '' as tense, '' as rating_stars"; $min = $widget["min_votes"]; if ($min == 0 && $widget["hide_empty"] == "1") { $min = 1; } $where[] = "d.post_id = " . $post_id; $where[] = "p.comment_id = d.comment_id"; if ($min > 0) { if ($widget["show"] == "total") { $where[] = "(d.user_voters + d.visitor_voters) >= " . $min; } if ($widget["show"] == "visitors") { $where[] = "d.visitor_voters >= " . $min; } if ($widget["show"] == "users") { $where[] = "d.user_voters >= " . $min; } } if ($widget["order"] == "desc" || $widget["order"] == "asc") { $sort = $widget["order"]; } else { $sort = "desc"; } if ($widget["last_voted_days"] == "") { $widget["last_voted_days"] = 0; } if ($widget["last_voted_days"] > 0) { $where[] = "TO_DAYS(CURDATE()) - " . $widget["last_voted_days"] . " <= TO_DAYS(d.last_voted)"; } $sql = sprintf("select distinct %s%s from %scomments p, %sgdsr_data_comment d where %s limit 0, %s", $select, $extras, $table_prefix, $table_prefix, join(" and ", $where), $widget["rows"]); wp_gdsr_dump("WIDGET_COMMENTS", $sql); return $sql; }
function add_vote($id, $user, $ip, $ua, $vote, $comment_id = 0) { global $wpdb, $table_prefix; $articles = $table_prefix . 'gdsr_data_article'; $stats = $table_prefix . 'gdsr_votes_log'; $trend = $table_prefix . 'gdsr_votes_trend'; $trend_date = date("Y-m-d"); $sql_trend = sprintf("SELECT count(*) FROM %s WHERE vote_date = '%s' and vote_type = 'article' and id = %s", $trend, $trend_date, $id); $trend_data = $wpdb->get_var($sql_trend); wp_gdsr_dump("SAVEVOTE_trend_check_sql", $sql_trend); wp_gdsr_dump("SAVEVOTE_trend_check_error", $wpdb->last_error); $trend_added = false; if ($trend_data == 0) { $trend_added = true; if ($user > 0) { $sql = sprintf("INSERT INTO %s (id, vote_type, user_voters, user_votes, vote_date) VALUES (%s, 'article', 1, %s, '%s')", $trend, $id, $vote, $trend_date); $wpdb->query($sql); } else { $sql = sprintf("INSERT INTO %s (id, vote_type, visitor_voters, visitor_votes, vote_date) VALUES (%s, 'article', 1, %s, '%s')", $trend, $id, $vote, $trend_date); $wpdb->query($sql); } wp_gdsr_dump("SAVEVOTE_trend_insert_sql", $sql); wp_gdsr_dump("SAVEVOTE_trend_insert_error", $wpdb->last_error); } if ($user > 0) { $sql = sprintf("UPDATE %s SET user_voters = user_voters + 1, user_votes = user_votes + %s, last_voted = CURRENT_TIMESTAMP WHERE post_id = %s", $articles, $vote, $id); $wpdb->query($sql); wp_gdsr_dump("SAVEVOTE_update_user_sql", $sql); wp_gdsr_dump("SAVEVOTE_update_user", $wpdb->last_error); if (!$trend_added) { $sql = sprintf("UPDATE %s SET user_voters = user_voters + 1, user_votes = user_votes + %s WHERE id = %s and vote_type = 'article' and vote_date = '%s'", $trend, $vote, $id, $trend_date); $wpdb->query($sql); wp_gdsr_dump("SAVEVOTE_trend_added_user_sql", $sql); wp_gdsr_dump("SAVEVOTE_trend_added_user_error", $wpdb->last_error); } } else { $sql = sprintf("UPDATE %s SET visitor_voters = visitor_voters + 1, visitor_votes = visitor_votes + %s, last_voted = CURRENT_TIMESTAMP WHERE post_id = %s", $articles, $vote, $id); $wpdb->query($sql); wp_gdsr_dump("SAVEVOTE_update_visitor_sql", $sql); wp_gdsr_dump("SAVEVOTE_update_visitor_error", $wpdb->last_error); if (!$trend_added) { $sql = sprintf("UPDATE %s SET visitor_voters = visitor_voters + 1, visitor_votes = visitor_votes + %s WHERE id = %s and vote_type = 'article' and vote_date = '%s'", $trend, $vote, $id, $trend_date); $wpdb->query($sql); } wp_gdsr_dump("SAVEVOTE_trend_added_visitor_sql", $sql); wp_gdsr_dump("SAVEVOTE_trend_added_visitor_error", $wpdb->last_error); } $logsql = sprintf("INSERT INTO %s (id, vote_type, user_id, vote, object, voted, ip, user_agent, comment_id) VALUES (%s, 'article', %s, %s, '', '%s', '%s', '%s', %s)", $stats, $id, $user, $vote, str_replace("'", "''", current_time('mysql')), $ip, $ua, $comment_id); $wpdb->query($logsql); wp_gdsr_dump("SAVEVOTE_insert_stats_sql", $sql); wp_gdsr_dump("SAVEVOTE_insert_stats_id", $wpdb->insert_id); wp_gdsr_dump("SAVEVOTE_insert_stats_error", $wpdb->last_error); }
function save_review($record_id, $values) { global $wpdb, $table_prefix; $sql = sprintf("DELETE FROM %sgdsr_multis_values where id = %s and source = 'rvw'", $table_prefix, $record_id); $wpdb->query($sql); for ($i = 0; $i < count($values); $i++) { $sql = sprintf("INSERT INTO %sgdsr_multis_values (id, source, item_id, user_voters, user_votes) VALUES (%s, 'rvw', %s, 1, '%s')", $table_prefix, $record_id, $i, $values[$i]); wp_gdsr_dump("INSERT", $sql); $wpdb->query($sql); } }
function get_post_type($post_id) { global $wpdb; $sql = "SELECT post_type FROM {$wpdb->posts} WHERE ID = " . $post_id; $r = $wpdb->get_row($sql); wp_gdsr_dump("GET_POST_TYPE_sql", $sql); wp_gdsr_dump("GET_POST_TYPE_type", $r); return $r->post_type; }
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 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 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 update_settings_full($upd_am, $upd_ar, $upd_cm, $upd_cr, $upd_atm, $upd_atr, $upd_ctm, $upd_ctr) { global $wpdb, $table_prefix; $dbt_data_article = $table_prefix . 'gdsr_data_article'; $update = array(); if ($upd_am != '') { $update[] = "moderate_articles = '" . $upd_am . "'"; } if ($upd_cm != '') { $update[] = "moderate_comments = '" . $upd_cm . "'"; } if ($upd_ar != '') { $update[] = "rules_articles = '" . $upd_ar . "'"; } if ($upd_cr != '') { $update[] = "rules_comments = '" . $upd_cr . "'"; } if ($upd_atm != '') { $update[] = "recc_moderate_articles = '" . $upd_am . "'"; } if ($upd_ctm != '') { $update[] = "recc_moderate_comments = '" . $upd_cm . "'"; } if ($upd_atr != '') { $update[] = "recc_rules_articles = '" . $upd_ar . "'"; } if ($upd_ctr != '') { $update[] = "recc_rules_comments = '" . $upd_cr . "'"; } if (count($update) > 0) { $updstring = join(", ", $update); $sql = sprintf("update %s set %s", $dbt_data_article, $updstring); wp_gdsr_dump("POST", $sql); $wpdb->query($sql); } }
/** * WordPress action for adding blog header contents */ function wp_head() { $this->f->init_google_rich_snippet(); if (is_feed()) { return; } $this->wp_head_javascript(); $include_cmm_review = $this->o["comments_review_active"] == 1; $include_mur_rating = $this->o["multis_active"] == 1; if ($this->o["external_rating_css"] == 0) { $this->include_rating_css(false); } if ($this->o["debug_wpquery"] == 1) { global $wp_query; wp_gdsr_dump("WP_QUERY", $wp_query->request); } $this->custom_actions('wp_head'); if ($this->o["ie_opacity_fix"] == 1) { gdsrFrontHelp::ie_opacity_fix(); } }