Make WordPress Core

Ticket #2485: commentfeed.diff

File commentfeed.diff, 8.0 KB (added by mdawaffe, 19 years ago)

Allows for more flexibility in comment feeds

  • wp-includes/default-filters.php

     
    7272// RSS filters
    7373add_filter('the_title_rss', 'strip_tags');
    7474add_filter('the_title_rss', 'ent2ncr', 8);
     75add_filter('get_wp_title_rss', 'ent2ncr', 8);
    7576add_filter('the_content_rss', 'ent2ncr', 8);
    7677add_filter('the_excerpt_rss', 'convert_chars');
    7778add_filter('the_excerpt_rss', 'ent2ncr', 8);
  • wp-includes/classes.php

     
    1212        var $current_post = -1;
    1313        var $in_the_loop = false;
    1414        var $post;
     15        var $comments;
    1516
    1617        var $is_single = false;
    1718        var $is_preview = false;
     
    2627        var $is_category = false;
    2728        var $is_search = false;
    2829        var $is_feed = false;
     30        var $is_comment_feed = false;
    2931        var $is_trackback = false;
    3032        var $is_home = false;
    3133        var $is_404 = false;
     
    4648                $this->is_category = false;
    4749                $this->is_search = false;
    4850                $this->is_feed = false;
     51                $this->is_comment_feed = false;
    4952                $this->is_trackback = false;
    5053                $this->is_home = false;
    5154                $this->is_404 = false;
     
    215218                        $this->is_feed = true;
    216219                }
    217220
     221                if ($this->is_feed && ( '' != $qv['withcomments'] || $this->is_single || $this->is_page )) {
     222                        $this->is_comment_feed = true;
     223                }
     224
    218225                if ('' != $qv['tb']) {
    219226                        $this->is_trackback = true;
    220227                }
     
    630637                        }
    631638                }
    632639
     640                if ( $this->is_comment_feed && ( ( $this->is_archive || $this->is_search ) || ( !$this->is_single && !$this->is_page ) ) ) { // Grab the comments then cache the posts
     641                        if ( $this->is_archive || $this->is_search ) {
     642                                $cjoin = "LEFT JOIN $wpdb->posts ON ( $wpdb->comments.comment_post_ID = $wpdb->posts.ID ) $join ";
     643                                $cwhere = "WHERE comment_approved = '1' $where";
     644                                $cgroupby = "GROUP BY $wpdb->comments.comment_id";
     645                        } else if ( !$this->is_single && !$this->is_page ) { // main feed
     646                                $cjoin = "LEFT JOIN $wpdb->posts ON ( $wpdb->comments.comment_post_ID = $wpdb->posts.ID )";
     647                                $cwhere = "WHERE post_status = 'publish' AND comment_approved = '1'";
     648                                $cgroupby = '';
     649                        }
     650                        $cjoin = apply_filters('comment_feed_join', $cjoin);
     651                        $cwhere = apply_filters('comment_feed_where', $cwhere);
     652                        $cgroupby = apply_filters('comment_feed_groupby', $cgroupby);
     653                        $comments_request = "SELECT $distinct $wpdb->comments.* FROM $wpdb->comments $cjoin $cwhere GROUP BY $wpdb->comments.comment_id ORDER BY comment_date_gmt DESC LIMIT " . get_settings('posts_per_rss');
     654                        $this->comments = $wpdb->get_results($comments_request);
     655                        $post_ids = array();
     656                        foreach ( $this->comments as $comment )
     657                                $post_ids[] = (int) $comment->comment_post_ID;
     658                        $post_ids = join(',', $post_ids);
     659                        $join = '';
     660                        $where = " AND $wpdb->posts.ID IN ($post_ids) ";
     661                }
     662
     663
    633664                // Apply post-paging filters on where and join.  Only plugins that
    634665                // manipulate paging queries should use these hooks.
    635666                $where = apply_filters('posts_where_paged', $where);
     
    637668                $groupby = apply_filters('posts_groupby', $groupby);
    638669                $join = apply_filters('posts_join_paged', $join);
    639670                $orderby = "post_" . $q['orderby'];
    640                 $orderby = apply_filters('posts_orderby', $orderby);
     671                $orderby = apply_filters('posts_orderby', $orderby);
     672
    641673                $request = " SELECT $distinct * FROM $wpdb->posts $join WHERE 1=1" . $where . " GROUP BY " . $groupby . " ORDER BY " . $orderby . " $limits";
    642674                $this->request = apply_filters('posts_request', $request);
    643675
    644676                $this->posts = $wpdb->get_results($this->request);
    645677
     678                if ( $this->is_comment_feed && ( $this->is_single || $this->is_page ) ) { // Cache the post then grab its comments
     679                        $cjoin = apply_filters('comment_feed_join', '');
     680                        $cwhere = apply_filters('comment_feed_where', "WHERE comment_post_ID = {$this->posts[0]->ID} AND comment_approved = '1'");
     681                        $comments_request = "SELECT $wpdb->comments.* FROM $wpdb->comments $cjoin $cwhere ORDER BY comment_date_gmt DESC LIMIT " . get_settings('posts_per_rss');
     682                        $this->comments = $wpdb->get_results($comments_request);
     683                }
     684
    646685                // Check post status to determine if post should be displayed.
    647686                if ($this->is_single || $this->is_page) {
    648687                        $status = get_post_status($this->posts[0]);
  • wp-includes/feed-functions.php

     
    99        echo get_bloginfo_rss($show);
    1010}
    1111
     12function get_wp_title_rss() {
     13        return apply_filters( 'get_wp_title_rss', wp_title( '»', false ) );
     14}
     15
    1216function get_the_title_rss() {
    1317        $title = get_the_title();
    1418        $title = apply_filters('the_title', $title);
     
    161165        }
    162166}
    163167
    164 ?>
    165  No newline at end of file
     168?>
  • wp-commentsrss2.php

     
    2020        if ($i < 1) {
    2121                $i++;
    2222?>
    23         <title><?php if (is_single() || is_page() ) { printf(__('Comments on: %s'), get_the_title_rss()); } else { printf(__('Comments for %s'), get_bloginfo_rss("name")); } ?></title>
    24         <link><?php (is_single()) ? permalink_single_rss() : bloginfo_rss("url") ?></link>
    25         <description><?php bloginfo_rss("description") ?></description>
     23        <title><?php printf(__('Comments on: %s'), get_bloginfo_rss('name') . get_wp_title_rss()); ?></title>
     24        <link><?php (is_single() || is_page()) ? permalink_single_rss() : bloginfo_rss("url"); // is_archive || is_search need links ?></link>
     25        <description><?php bloginfo_rss("description"); // need different description for !main_feed ?></description>
    2626        <pubDate><?php echo gmdate('r'); ?></pubDate>
    2727        <generator>http://wordpress.org/?v=<?php echo $wp_version ?></generator>
    2828
    2929<?php
    30                 if (is_single() || is_page()) {
    31                         $comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_author_email,
    32                         comment_author_url, comment_date, comment_date_gmt, comment_content, comment_post_ID,
    33                         $wpdb->posts.ID, $wpdb->posts.post_password FROM $wpdb->comments
    34                         LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE comment_post_ID = '$id'
    35                         AND $wpdb->comments.comment_approved = '1' AND $wpdb->posts.post_status = 'publish'
    36                         AND post_date_gmt < '" . gmdate("Y-m-d H:i:59") . "'
    37                         ORDER BY comment_date_gmt DESC LIMIT " . get_settings('posts_per_rss') );
    38                 } else { // if no post id passed in, we'll just ue the last 10 comments.
    39                         $comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_author_email,
    40                         comment_author_url, comment_date, comment_date_gmt, comment_content, comment_post_ID,
    41                         $wpdb->posts.ID, $wpdb->posts.post_password FROM $wpdb->comments
    42                         LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE $wpdb->posts.post_status = 'publish'
    43                         AND $wpdb->comments.comment_approved = '1' AND post_date_gmt < '" . gmdate("Y-m-d H:i:s") . "' 
    44                         ORDER BY comment_date_gmt DESC LIMIT " . get_settings('posts_per_rss') );
    45                 }
    46         // this line is WordPress' motor, do not delete it.
    47                 if ($comments) {
    48                         foreach ($comments as $comment) {
     30                if ($wp_query->comments) {
     31                        foreach ($wp_query->comments as $comment) {
    4932                                // Some plugins may need to know the metadata
    5033                                // associated with this comment's post:
     34                                $comment_post = get_post($comment->comment_post_ID);
    5135                                get_post_custom($comment->comment_post_ID);
    5236?>
    5337        <item>
     
    6347                <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_comment_time('Y-m-d H:i:s', true), false); ?></pubDate>
    6448                <guid><?php comment_link() ?></guid>
    6549                        <?php
    66                         if (!empty($comment->post_password) && $_COOKIE['wp-postpass'] != $comment->post_password) {
     50                        if (!empty($comment_post->post_password) && $_COOKIE['wp-postpass'] != $comment_post->post_password) {
    6751                        ?>
    6852                <description><?php _e('Protected Comments: Please enter your password to view comments.'); ?></description>
    6953                <content:encoded><![CDATA[<?php echo get_the_password_form() ?>]]></content:encoded>