function get_widget_standard($widget, $min = 0) { global $table_prefix; $grouping = $widget["grouping"]; $cats = $widget["category"]; $cats_in = $widget["category_toponly"] == 0; if ($cats_in && $cats != "0") { $subs = gdWPGDSR::get_subcategories_ids($widget["category"]); $subs[] = $cats; $cats = join(",", $subs); } if ($widget["categories"] != "") { $cats = $widget["categories"]; $cats_in = true; } $where = array(); $select = ""; $from = ""; $group = ""; if ($widget["bayesian_calculation"] == "0") { $min = 0; } if ($widget["min_votes"] > $min) { $min = $widget["min_votes"]; } if ($min == 0 && $widget["hide_empty"] == "1") { $min = 1; } $where[] = "p.id = d.post_id"; $where[] = "p.post_status = 'publish'"; $extras = ", 0 as votes, 0 as voters, 0 as rating, 0 as bayesian, '' as item_trend_rating, '' as item_trend_voting, '' as permalink, '' as tense, '' as rating_stars, '' as bayesian_stars, '' as review_stars"; if ($cats != "" && $cats != "0" || $grouping == 'category') { $from = sprintf("%sterm_taxonomy t, %sterm_relationships r, ", $table_prefix, $table_prefix); $where[] = "t.term_taxonomy_id = r.term_taxonomy_id"; $where[] = "r.object_id = p.id"; } if ($cats != "" && $cats != "0") { if ($cats_in) { $where[] = "t.term_id in (" . $cats . ")"; } else { $where[] = "t.term_id = " . $cats; } } $col_id = "p.id"; $col_title = "p.post_title"; if ($grouping == 'category') { $from .= sprintf("%sterms x, ", $table_prefix); $where[] = "t.taxonomy = 'category'"; $where[] = "t.term_id = x.term_id"; $select = "x.name as title, t.term_id, count(*) as counter, sum(d.user_votes) as user_votes, sum(d.visitor_votes) as visitor_votes, sum(d.user_voters) as user_voters, sum(d.visitor_voters) as visitor_voters"; $group = "group by t.term_id"; $col_id = "t.term_id"; $col_title = "x.name"; } else { if ($grouping == 'user') { $from .= sprintf("%susers u, ", $table_prefix); $where[] = "u.id = p.post_author"; $select = "u.display_name as title, u.id, count(*) as counter, sum(d.user_votes) as user_votes, sum(d.visitor_votes) as visitor_votes, sum(d.user_voters) as user_voters, sum(d.visitor_voters) as visitor_voters"; $group = "group by u.id"; $col_id = "u.id"; $col_title = "u.display_name"; } else { $select = "p.id as post_id, p.post_author as author, p.post_title as title, p.post_type, p.post_date, d.*, 1 as counter"; } } if ($widget["select"] != "" && $widget["select"] != "postpage") { $where[] = "p.post_type = '" . $widget["select"] . "'"; } 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["hide_noreview"] == "1") { $where[] = "d.review > -1"; } 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)"; } if ($widget["publish_date"] == "range") { $where[] = "p.post_date >= '" . $widget["publish_range_from"] . "' and p.post_date <= '" . $widget["publish_range_to"] . "'"; } else { if ($widget["publish_date"] == "month") { $month = $widget["publish_month"]; if ($month != "" && $month != "0") { $where[] = "year(p.post_date) = " . substr($month, 0, 4); $where[] = "month(p.post_date) = " . substr($month, 4, 2); } } else { if ($widget["publish_date"] == "lastd") { if ($widget["publish_days"] > 0) { $where[] = "TO_DAYS(CURDATE()) - " . $widget["publish_days"] . " <= TO_DAYS(p.post_date)"; } } } } if ($widget["image_from"] == "content") { $select = "p.post_content, " . $select; } $col = $widget["column"]; if ($col == "title") { $col = $col_title; } else { if ($col == "review") { $col = "d.review"; } else { if ($col == "rating" || $col == "bayesian") { if ($widget["show"] == "total") { $col = "(d.user_votes + d.visitor_votes)/(d.user_voters + d.visitor_voters)"; } if ($widget["show"] == "visitors") { $col = "d.visitor_votes/d.visitor_voters"; } if ($widget["show"] == "users") { $col = "d.user_votes/d.user_voters"; } } else { if ($col == "voters") { if ($widget["show"] == "total") { $col = "d.user_votes + d.visitor_votes"; } if ($widget["show"] == "visitors") { $col = "d.visitor_votes"; } if ($widget["show"] == "users") { $col = "d.user_votes"; } } else { if ($col == "counter" && $grouping != "post") { $col = "count(*)"; } else { $col = $col_id; } } } } } $ordering = sprintf("order by %s %s", $col, $sort); $sql = sprintf("select distinct %s%s from %s%sposts p, %sgdsr_data_article d where %s %s %s limit 0, %s", $select, $extras, $from, $table_prefix, $table_prefix, join(" and ", $where), $group, $ordering, $widget["rows"]); wp_gdsr_dump("WIDGET_STANDARD", $sql); return $sql; }
function get_widget_standard($widget, $min = 0) { global $wpdb, $table_prefix; $grouping = $widget["grouping"]; $cats = $widget["category"]; $cats_in = $widget["category_toponly"] == 0; $select = $from = $group = ""; $where = array("p.id = d.post_id", "p.post_status = 'publish'"); $extras = ", 0 as votes, 0 as voters, 0 as rating, 0 as bayesian, '' as item_trend_rating, '' as item_trend_voting, '' as permalink, '' as tense, '' as rating_stars, '' as bayesian_stars, '' as review_stars"; if ($cats_in && $cats != "0") { $subs = gdWPGDSR::get_subcategories_ids($widget["category"]); $subs[] = $cats; $cats = join(",", $subs); } if (isset($widget["categories"]) && $widget["categories"] != "") { $cats = $widget["categories"]; $cats_in = true; } if ($widget["bayesian_calculation"] == "0") { $min = 0; } if ($widget["min_votes"] > $min) { $min = $widget["min_votes"]; } if ($min == 0 && $widget["hide_empty"] == "1") { $min = 1; } if ($cats != "" && $cats != "0" || $grouping == 'category') { $from = sprintf("%sterm_taxonomy t, %sterm_relationships r, ", $table_prefix, $table_prefix); $where[] = "t.term_taxonomy_id = r.term_taxonomy_id"; $where[] = "r.object_id = p.id"; } if ($cats != "" && $cats != "0") { $where[] = "t.taxonomy = 'category'"; if ($cats_in) { $where[] = "t.term_id in (" . $cats . ")"; } else { $where[] = "t.term_id = " . $cats; } } $col_id = "p.id"; $col_title = "p.post_title"; if ($grouping == 'taxonomy') { $from .= sprintf("%sterm_taxonomy tt, %sterm_relationships tr, %sterms tx, ", $table_prefix, $table_prefix, $table_prefix); $where[] = "tt.taxonomy = '" . $widget["taxonomy"] . "'"; $where[] = "tt.term_taxonomy_id = tr.term_taxonomy_id"; $where[] = "tt.term_id = tx.term_id"; $where[] = "tr.object_id = p.id"; $select = "tx.name as title, tx.term_id, tx.slug, count(*) as counter, sum(d.user_votes) as user_votes, sum(d.visitor_votes) as visitor_votes, sum(d.user_voters) as user_voters, sum(d.visitor_voters) as visitor_voters"; $select .= ", sum(d.review) as review"; $group = $col_id = "tt.term_id"; $col_title = "tx.name"; } else { if ($grouping == 'category') { $from .= sprintf("%sterms x, ", $table_prefix); $where[] = "t.taxonomy = 'category'"; $where[] = "t.term_id = x.term_id"; $select = "x.name as title, x.term_id, x.slug, count(*) as counter, sum(d.user_votes) as user_votes, sum(d.visitor_votes) as visitor_votes, sum(d.user_voters) as user_voters, sum(d.visitor_voters) as visitor_voters"; $select .= ", sum(d.review) as review"; $group = $col_id = "t.term_id"; $col_title = "x.name"; } else { if ($grouping == 'user') { $from .= sprintf("%s u, ", $wpdb->users); $where[] = "u.id = p.post_author"; $select = "u.display_name as title, u.user_nicename as slug, u.id, count(*) as counter, sum(d.user_votes) as user_votes, sum(d.visitor_votes) as visitor_votes, sum(d.user_voters) as user_voters, sum(d.visitor_voters) as visitor_voters"; $select .= ", sum(d.review) as review"; $group = $col_id = "u.id"; $col_title = "u.display_name"; } else { $select = "p.id as post_id, p.post_name as slug, p.post_author as author, p.post_title as title, p.post_type, p.post_date, d.*, 1 as counter"; } } } if ($grouping != 'post' && $widget["min_count"] > 0) { $group .= " having count(*) >= " . $widget["min_count"]; } if ($widget["select"] != "" && $widget["select"] != "postpage") { $where[] = "p.post_type = '" . $widget["select"] . "'"; } 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["hide_noreview"] == "1") { $where[] = "d.review > -1"; } $sort = $widget["order"] == "desc" || $widget["order"] == "asc" ? $widget["order"] : ($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)"; } if ($widget["publish_date"] == "range") { $where[] = "p.post_date >= '" . $widget["publish_range_from"] . "' and p.post_date <= '" . $widget["publish_range_to"] . "'"; } else { if ($widget["publish_date"] == "month") { $month = $widget["publish_month"]; if ($month != "" && $month != "0") { $where[] = "year(p.post_date) = " . substr($month, 0, 4); $where[] = "month(p.post_date) = " . substr($month, 4, 2); } } else { if ($widget["publish_date"] == "lastd") { if ($widget["publish_days"] > 0) { $where[] = "TO_DAYS(CURDATE()) - " . $widget["publish_days"] . " <= TO_DAYS(p.post_date)"; } } } } $select = "p.post_content, p.post_excerpt, '' as excerpt, " . $select; $col = $widget["column"]; if ($col == "title") { $col = $col_title; } else { if ($col == "review") { $col = "d.review"; } else { if ($col == "rating" || $col == "bayesian") { if ($widget["show"] == "total") { $col = "(d.user_votes + d.visitor_votes)/(d.user_voters + d.visitor_voters)"; } if ($widget["show"] == "visitors") { $col = "d.visitor_votes/d.visitor_voters"; } if ($widget["show"] == "users") { $col = "d.user_votes/d.user_voters"; } } else { if ($col == "voters") { if ($widget["show"] == "total") { $col = "d.user_votes + d.visitor_votes"; } if ($widget["show"] == "visitors") { $col = "d.visitor_votes"; } if ($widget["show"] == "users") { $col = "d.user_votes"; } } else { if ($col == "counter" && $grouping != "post") { $col = "count(*)"; } else { $col = $col_id; } } } } } $ordering = sprintf("order by %s %s", $col, $sort); $query = array("select" => "distinct " . $select . $extras, "from" => sprintf("%s%sposts p, %sgdsr_data_article d", $from, $table_prefix, $table_prefix), "where" => join(" and ", $where), "group" => $group, "order" => sprintf("%s %s", $col, $sort), "limit" => "0, " . $widget["rows"]); return $query; }
function render_custom_fields($name, $selected = "N", $width = 180, $style = '') { $fields = gdWPGDSR::get_all_custom_fieds(false); ?> <select style="width: <?php echo $width; ?> px; <?php echo $style; ?> " name="<?php echo $name; ?> " id="<?php echo $name; ?> "> <?php foreach ($fields as $s) { echo sprintf('<option value="%s"%s>%s</option>', $s, $selected == $s ? ' selected="selected"' : '', $s); } ?> </select> <?php }
/** * Full uninstall of plugin. */ function init_uninstall() { if (isset($_POST["gdsr_full_uninstall"]) && $_POST["gdsr_full_uninstall"] == __("UNINSTALL", "gd-star-rating")) { require_once STARRATING_PATH . "gdragon/gd_db_install.php"; delete_option('gd-star-rating'); delete_option('widget_gdstarrating'); delete_option('gd-star-rating-import'); delete_option('gd-star-rating-gfx'); delete_option('gd-star-rating-inc'); gdDBInstallGDSR::drop_tables(STARRATING_PATH); gdWPGDSR::deactivate_plugin("gd-star-rating/gd-star-rating.php"); update_option('recently_activated', array("gd-star-rating/gd-star-rating.php" => time()) + (array) get_option('recently_activated')); wp_redirect('index.php'); exit; } }