Example #1
0
 function results($instance)
 {
     if ($instance["count"] == 0) {
         return array();
     }
     global $gdsw, $wpdb, $table_prefix;
     $select = array("p.ID", "p.post_title", "p.post_name", "p.post_type", "count(r.object_id) as count", "'' as post_permalink");
     $where = array("t.term_taxonomy_id = r.term_taxonomy_id", "r.object_id = p.ID", "p.post_type = 'post'", "p.post_status = 'publish'", "p.ID != " . $gdsw->related_post_id);
     if ($instance["display_post_date"] == 1) {
         $select[] = "p.post_date";
     }
     if ($instance["display_excerpt"] == 1) {
         $select[] = "p.post_content";
         $select[] = "p.post_excerpt";
         $select[] = "'' as excerpt";
     }
     $use_tags = $instance["filter_related"] == "tagcat" || $instance["filter_related"] == "tag";
     $use_cats = $instance["filter_related"] == "tagcat" || $instance["filter_related"] == "cat";
     $relations = $use_tags ? $this->related_tags($gdsw->related_post_id) : array();
     $categories = $use_cats ? $this->related_categories($gdsw->related_post_id) : array();
     foreach ($categories as $cat) {
         $relations[] = $cat;
     }
     $tags = array();
     foreach ($relations as $r) {
         $tags[] = $r->term_id;
     }
     if (count($tags) > 0) {
         $where[] = "t.term_id IN (" . join(", ", $tags) . ")";
     }
     $sql = $this->prepare_sql($instance, "DISTINCT " . join(", ", $select), sprintf("%sterm_taxonomy t, %sterm_relationships r, %sposts p", $table_prefix, $table_prefix, $table_prefix), join(" AND ", $where), "r.object_id", "RAND()", $instance["count"]);
     wp_gdsw_log_sql("widget_gdws_related_posts", $sql);
     return $this->prepare($instance, $wpdb->get_results($sql));
 }
Example #2
0
 function results($instance)
 {
     global $wpdb, $table_prefix;
     $select = array("p.ID", "p.post_title", "p.post_name", "p.post_type", "p.comment_count", "'' as post_permalink");
     $from = array(sprintf("%sposts p", $table_prefix));
     $where = array("p.post_status = 'publish'", "p.comment_count > 0");
     if ($instance["filter_category"] != "") {
         $from[] = sprintf("INNER JOIN %sterm_relationships tr ON tr.object_id = p.ID", $table_prefix);
         $from[] = sprintf("INNER JOIN %sterm_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id", $table_prefix);
         $where[] = sprintf("tt.term_id in (%s)", $instance["filter_category"]);
     }
     if ($instance["filter_published"] != "allp") {
         $days = 0;
         switch ($instance["filter_published"]) {
             case "lwek":
                 $days = 7;
                 break;
             case "lmnt":
                 $days = 31;
                 break;
             case "lyea":
                 $days = 365;
                 break;
         }
         $where[] = sprintf("DATE_SUB(CURDATE(), INTERVAL %s DAY) < p.post_date", $days);
     }
     $sql = $this->prepare_sql($instance, "DISTINCT " . join(", ", $select), join(" ", $from), join(" AND ", $where), "", "p.comment_count DESC", $instance["count"]);
     wp_gdsw_log_sql("widget_gdws_popular_posts", $sql);
     return $this->prepare($instance, $wpdb->get_results($sql));
 }
Example #3
0
 function results($instance)
 {
     global $wpdb, $table_prefix;
     $select = array("p.ID", "p.post_title", "p.post_name", "p.post_type");
     $from = array();
     $where = array();
     $from[] = sprintf("%sposts p", $table_prefix);
     $where[] = "p.post_status = 'future'";
     $where[] = "p.post_type = 'post'";
     if ($instance["display_post_date"] == 1) {
         $select[] = "p.post_date";
     }
     if ($instance["display_excerpt"] == 1) {
         $select[] = "p.post_content";
         $select[] = "p.post_excerpt";
         $select[] = "'' as excerpt";
     }
     if ($instance["filter_category"] != "") {
         $from[] = sprintf("INNER JOIN %sterm_relationships tr ON tr.object_id = p.ID", $table_prefix);
         $from[] = sprintf("INNER JOIN %sterm_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id", $table_prefix);
         $where[] = sprintf("tt.term_id in (%s)", $instance["filter_category"]);
     }
     $sql = $this->prepare_sql($instance, "DISTINCT " . join(", ", $select), join(" ", $from), join(" AND ", $where), "", "p.post_date_gmt ASC", $instance["count"]);
     wp_gdsw_log_sql("widget_gdws_future_posts", $sql);
     return $this->prepare($instance, $wpdb->get_results($sql));
 }
Example #4
0
 function results($instance)
 {
     global $wpdb, $table_prefix;
     $select = array("u.ID", "u.display_name", "u.user_email", "count(*) as posts", "'' as post_permalink", "'' as author_permalink");
     $from = array();
     $where = array("p.post_status = 'publish'", "p.post_type = 'post'");
     $from[] = sprintf("%s u inner join %sposts p on p.post_author = u.ID", $wpdb->users, $table_prefix);
     if ($instance["display_full_name"] == 1) {
         $select[] = "mf.meta_value as first_name";
         $select[] = "ml.meta_value as last_name";
         $from[] = sprintf("left join %susermeta mf on mf.user_id = u.ID and mf.meta_key = 'first_name'", $table_prefix);
         $from[] = sprintf("left join %susermeta ml on ml.user_id = u.ID and ml.meta_key = 'last_name'", $table_prefix);
     }
     if ($instance["filter_category"] != "") {
         $from[] = sprintf("INNER JOIN %sterm_relationships tr ON tr.object_id = p.ID", $table_prefix);
         $from[] = sprintf("INNER JOIN %sterm_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id", $table_prefix);
         $where[] = sprintf("tt.term_id in (%s)", $instance["filter_category"]);
     }
     $sql = $this->prepare_sql($instance, "DISTINCT " . join(", ", $select), join(" ", $from), join(" AND ", $where), "u.ID HAVING count(*) >= " . $instance["filter_min_posts"], "count(*) DESC", $instance["count"]);
     wp_gdsw_log_sql("widget_gdws_posts_authors", $sql);
     return $this->prepare($instance, $wpdb->get_results($sql));
 }
Example #5
0
 function results($instance)
 {
     global $wpdb, $table_prefix;
     $select = array("c.comment_ID", "c.comment_author", "c.comment_author_email", "c.comment_author_url", "p.ID", "p.post_title", "p.post_name", "p.post_type", "'' as post_permalink", "'' as comment_permalink");
     $from = array();
     $where = array("comment_approved = '1'");
     $from[] = sprintf("%scomments c INNER JOIN %sposts p ON c.comment_post_ID = p.ID", $table_prefix, $table_prefix);
     if ($instance["filter_type"] == "ping") {
         $where[] = "comment_type = 'pingback'";
     }
     if ($instance["filter_type"] == "comm") {
         $where[] = "comment_type = ''";
     }
     if ($instance["filter_category"] != "") {
         $from[] = sprintf("INNER JOIN %sterm_relationships tr ON tr.object_id = p.ID", $table_prefix);
         $from[] = sprintf("INNER JOIN %sterm_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id", $table_prefix);
         $where[] = sprintf("tt.term_id in (%s)", $instance["filter_category"]);
     }
     $sql = $this->prepare_sql($instance, "DISTINCT " . join(", ", $select), join(" ", $from), join(" AND ", $where), "", "c.comment_date_gmt DESC", $instance["count"]);
     wp_gdsw_log_sql("widget_gdws_recent_comments", $sql);
     return $this->prepare($instance, $wpdb->get_results($sql));
 }
Example #6
0
 function results($instance)
 {
     global $wpdb, $table_prefix;
     $inner_sql = $this->inner_select($instance);
     $order = "";
     $select = array("x.*");
     $from = array(sprintf("%sgdpt_posts_views v", $wpdb->prefix), sprintf("INNER JOIN (%s) x ON x.ID = v.post_id", $inner_sql));
     $where = array();
     switch ($instance["filter_views"]) {
         case "all":
             $select[] = "sum(v.usr_views + v.vst_views) AS views";
             $order = "sum(v.usr_views + v.vst_views) DESC";
             break;
         case "users":
             $select[] = "sum(v.usr_views) AS views";
             $order = "sum(v.usr_views) DESC";
             break;
         case "visitors":
             $select[] = "sum(v.vst_views) AS views";
             $order = "sum(v.vst_views) DESC";
             break;
     }
     if ($instance["filter_recency"] != "allp") {
         $days = 0;
         if ($instance["filter_recency"] == "tday") {
             $where[] = "v.day = '" . date("Y-m-d") . "'";
         } else {
             switch ($instance["filter_recency"]) {
                 case "lday":
                     $days = 1;
                     break;
                 case "lwek":
                     $days = 7;
                     break;
                 case "lmnt":
                     $days = 31;
                     break;
                 case "lyea":
                     $days = 365;
                     break;
             }
             $where[] = sprintf("DATE_SUB(CURDATE(), INTERVAL %s DAY) < STR_TO_DATE(v.day, '%s')", $days, '%Y-%m-%d');
         }
     }
     $sql = $this->prepare_sql($instance, "DISTINCT " . join(", ", $select), join(" ", $from), join(" AND ", $where), "x.ID", $order, $instance["count"]);
     wp_gdsw_log_sql("widget_gdws_popular_posts", $sql);
     return $this->prepare($instance, $wpdb->get_results($sql));
 }