Make WordPress Core


Ignore:
Timestamp:
02/24/2007 07:33:29 AM (18 years ago)
Author:
ryan
Message:

Comment feeds everywhere. Props mdawaffe and rob1n. fixes #2485

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/query.php

    r4911 r4934  
    99
    1010    return $wp_query->get($var);
     11}
     12
     13function set_query_var($var, $value) {
     14    global $wp_query;
     15
     16    return $wp_query->set($var, $value);
    1117}
    1218
     
    249255    $wp_query->the_post();
    250256}
     257
     258/*
     259 * Comments loop.
     260 */
     261
     262function have_comments() {
     263    global $wp_query;
     264    return $wp_query->have_comments();
     265}
     266
     267function the_comment() {
     268    global $wp_query;
     269    return $wp_query->the_comment();
     270
    251271
    252272/*
     
    266286    var $in_the_loop = false;
    267287    var $post;
     288   
     289    var $comments;
     290    var $comment_count = 0;
     291    var $current_comment = -1;
     292    var $comment;
    268293
    269294    var $found_posts = 0;
     
    283308    var $is_search = false;
    284309    var $is_feed = false;
     310    var $is_comment_feed = false;
    285311    var $is_trackback = false;
    286312    var $is_home = false;
     
    306332        $this->is_search = false;
    307333        $this->is_feed = false;
     334        $this->is_comment_feed = false;
    308335        $this->is_trackback = false;
    309336        $this->is_home = false;
     
    538565            $this->is_singular = true;
    539566
     567        if ( false !== strpos($qv['feed'], 'comments-') ) {
     568            $this->query_vars['feed'] = $qv['feed'] = str_replace('comments-', '', $qv['feed']);
     569            $qv['withcomments'] = 1;
     570        }
     571
     572        if ( $this->is_feed && (!empty($qv['withcomments']) || ( empty($qv['withoutcomments']) && $this->is_singular ) ) )
     573            $this->is_comment_feed = true;
     574
    540575        if ( ! ($this->is_singular || $this->is_archive || $this->is_search || $this->is_feed || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_comments_popup)) {
    541576            $this->is_home = true;
     
    9671002            }
    9681003        }
     1004       
     1005        // Comments feeds
     1006        if ( $this->is_comment_feed && ( $this->is_archive || $this->is_search || !$this->is_singular ) ) {
     1007            if ( $this->is_archive || $this->is_search ) {
     1008                $cjoin = "LEFT JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) $join ";
     1009                $cwhere = "WHERE comment_approved = '1' $where";
     1010                $cgroupby = "GROUP BY $wpdb->comments.comment_id";
     1011            } else { // Other non singular e.g. front
     1012                $cjoin = "LEFT JOIN $wpdb->posts ON ( $wpdb->comments.comment_post_ID = $wpdb->posts.ID )";
     1013                $cwhere = "WHERE post_status = 'publish' AND comment_approved = '1'";
     1014                $cgroupby = '';
     1015            }
     1016           
     1017            $cjoin = apply_filters('comment_feed_join', $cjoin);
     1018            $cwhere = apply_filters('comment_feed_where', $cwhere);
     1019            $cgroupby = apply_filters('comment_feed_groupby', $cgroupby);
     1020           
     1021            $this->comments = (array) $wpdb->get_results("SELECT $distinct $wpdb->comments.* FROM $wpdb->comments $cjoin $cwhere $cgroupby ORDER BY comment_date_gmt DESC LIMIT " . get_settings('posts_per_rss'));
     1022            $this->comment_count = count($this->comments);
     1023
     1024            $post_ids = array();
     1025           
     1026            foreach ($this->comments as $comment)
     1027                $post_ids[] = (int) $comment->comment_post_ID;
     1028           
     1029            $post_ids = join(',', $post_ids);
     1030            $join = '';
     1031            if ( $post_ids )
     1032                $where = "AND $wpdb->posts.ID IN ($post_ids) ";
     1033            else
     1034                $where = "AND 0";
     1035        }
    9691036
    9701037        // Apply post-paging filters on where and join.  Only plugins that
     
    9871054
    9881055        $this->posts = $wpdb->get_results($this->request);
     1056
     1057        if ( $this->is_comment_feed && $this->is_singular ) {
     1058            $cjoin = apply_filters('comment_feed_join', '');
     1059            $cwhere = apply_filters('comment_feed_where', "WHERE comment_post_ID = {$this->posts[0]->ID} AND comment_approved = '1'");
     1060            $comments_request = "SELECT $wpdb->comments.* FROM $wpdb->comments $cjoin $cwhere ORDER BY comment_date_gmt DESC LIMIT " . get_settings('posts_per_rss');
     1061            $this->comments = $wpdb->get_results($comments_request);
     1062            $this->comment_count = count($this->comments);
     1063        }
     1064       
    9891065        if ( !empty($limits) ) {
    9901066            $found_posts_query = apply_filters( 'found_posts_query', 'SELECT FOUND_ROWS()' );
     
    9931069            $this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']);
    9941070        }
     1071       
    9951072        // Check post status to determine if post should be displayed.
    9961073        if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) {
     
    10721149        }
    10731150    }
     1151   
     1152    function next_comment() {
     1153        $this->current_comment++;
     1154       
     1155        $this->comment = $this->comments[$this->current_comment];
     1156        return $this->comment;
     1157    }
     1158   
     1159    function the_comment() {
     1160        global $comment;
     1161       
     1162        $comment = $this->next_comment();
     1163       
     1164        if ($this->current_comment == 0) {
     1165            do_action('comment_loop_start');
     1166        }
     1167    }
     1168   
     1169    function have_comments() {
     1170        if ($this->current_comment + 1 < $this->comment_count) {
     1171            return true;
     1172        } elseif ($this->current_comment + 1 == $this->comment_count) {
     1173            $this->rewind_comments();
     1174        }
     1175       
     1176        return false;
     1177    }
     1178   
     1179    function rewind_comments() {
     1180        $this->current_comment = -1;
     1181        if ($this->comment_count > 0) {
     1182            $this->comment = $this->comments[0];
     1183        }
     1184    }
    10741185
    10751186    function &query($query) {
Note: See TracChangeset for help on using the changeset viewer.