Make WordPress Core

Ticket #2485: 2485.diff

File 2485.diff, 9.5 KB (added by rob1n, 17 years ago)
  • wp-includes/feed-atom-comments.php

     
    3131                        $i++;
    3232                }
    3333               
    34                 if (is_single() || is_page()) {
    35                         $comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_author_email,
    36                         comment_author_url, comment_date, comment_date_gmt, comment_content, comment_post_ID,
    37                         $wpdb->posts.ID, $wpdb->posts.post_password FROM $wpdb->comments
    38                         LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE comment_post_ID = '" . get_the_ID() . "'
    39                         AND $wpdb->comments.comment_approved = '1' AND $wpdb->posts.post_status = 'publish'
    40                         AND post_date_gmt < '" . gmdate("Y-m-d H:i:59") . "'
    41                         ORDER BY comment_date_gmt ASC" );
    42                 } else { // if no post id passed in, we'll just use the last posts_per_rss comments.
    43                         $comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_author_email,
    44                         comment_author_url, comment_date, comment_date_gmt, comment_content, comment_post_ID,
    45                         $wpdb->posts.ID, $wpdb->posts.post_password FROM $wpdb->comments
    46                         LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE $wpdb->posts.post_status = 'publish'
    47                         AND $wpdb->comments.comment_approved = '1' AND post_date_gmt < '" . gmdate("Y-m-d H:i:s") . "' 
    48                         ORDER BY comment_date_gmt DESC LIMIT " . get_option('posts_per_rss') );
    49                 }
    50                
    51                 if ($comments) {
    52                         foreach ($comments as $comment) {
     34                if ($wp_query->comments) {
     35                        foreach ($wp_query->comments as $comment) {
    5336                                $GLOBALS['comment'] =& $comment;
     37                               
     38                                $comment_post = get_post($comment_post_ID);
    5439                                get_post_custom($comment->comment_post_ID);
    5540?>
    5641        <entry>
     
    7560                <updated><?php echo mysql2date('D, d M Y H:i:s +0000', get_comment_time('Y-m-d H:i:s', true), false); ?></updated>
    7661                <published><?php echo mysql2date('D, d M Y H:i:s +0000', get_comment_time('Y-m-d H:i:s', true), false); ?></published>
    7762               
    78         <?php if (!empty($comment->post_password) && $_COOKIE['wp-postpass'] != $comment->post_password) { ?>
     63        <?php if (!empty($comment_post->post_password) && $_COOKIE['wp-postpass'] != $comment_post->post_password) { ?>
    7964                <content type="html" xml:base="<?php comment_link(); ?>"><![CDATA[<?php echo get_the_password_form(); ?>]]></content>
    8065        <?php } else { ?>
    8166                <content type="html" xml:base="<?php comment_link(); ?>"><![CDATA[<?php comment_text(); ?>]]></content>
  • wp-includes/feed-rss2-comments.php

     
    1313  while (have_posts()) : the_post();
    1414        if ($i < 1) {
    1515                $i++;
     16        }
    1617?>
    1718        <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>
    1819        <link><?php (is_single()) ? permalink_single_rss() : bloginfo_rss("url") ?></link>
     
    2122        <generator>http://wordpress.org/?v=<?php echo $wp_version ?></generator>
    2223
    2324<?php
    24                 if (is_single() || is_page()) {
    25                         $comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_author_email,
    26                         comment_author_url, comment_date, comment_date_gmt, comment_content, comment_post_ID,
    27                         $wpdb->posts.ID, $wpdb->posts.post_password FROM $wpdb->comments
    28                         LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE comment_post_ID = '" . get_the_ID() . "'
    29                         AND $wpdb->comments.comment_approved = '1' AND $wpdb->posts.post_status = 'publish'
    30                         AND post_date_gmt < '" . gmdate("Y-m-d H:i:59") . "'
    31                         ORDER BY comment_date_gmt ASC" );
    32                 } else { // if no post id passed in, we'll just ue the last 10 comments.
    33                         $comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_author_email,
    34                         comment_author_url, comment_date, comment_date_gmt, comment_content, comment_post_ID,
    35                         $wpdb->posts.ID, $wpdb->posts.post_password FROM $wpdb->comments
    36                         LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE $wpdb->posts.post_status = 'publish'
    37                         AND $wpdb->comments.comment_approved = '1' AND post_date_gmt < '" . gmdate("Y-m-d H:i:s") . "' 
    38                         ORDER BY comment_date_gmt DESC LIMIT " . get_option('posts_per_rss') );
    39                 }
    40         // this line is WordPress' motor, do not delete it.
    41                 if ($comments) {
    42                         foreach ($comments as $comment) {
     25                if ($wp_query->comments) {
     26                        foreach ($wp_query->comments as $comment) {
    4327                                $GLOBALS['comment'] =& $comment;
    44                                 // Some plugins may need to know the metadata
    45                                 // associated with this comment's post:
     28                               
     29                                $comment_post = get_post($comment->comment_post_ID);
    4630                                get_post_custom($comment->comment_post_ID);
    4731?>
    4832        <item>
     
    5943                <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_comment_time('Y-m-d H:i:s', true), false); ?></pubDate>
    6044                <guid><?php comment_link() ?></guid>
    6145                        <?php
    62                         if (!empty($comment->post_password) && $_COOKIE['wp-postpass'] != $comment->post_password) {
     46                        if (!empty($comment_post->post_password) && $_COOKIE['wp-postpass'] != $comment_post->post_password) {
    6347                        ?>
    6448                <description><?php _e('Protected Comments: Please enter your password to view comments.'); ?></description>
    6549                <content:encoded><![CDATA[<?php echo get_the_password_form() ?>]]></content:encoded>
     
    8064endwhile; endif;
    8165?>
    8266</channel>
    83 </rss>
     67</rss>
     68 No newline at end of file
  • wp-includes/feed.php

     
    1010        echo get_bloginfo_rss($show);
    1111}
    1212
     13function get_wp_title_rss($sep = '&raquo;') {
     14        $title = wp_title($sep, false);
     15        $title = apply_filters('get_wp_title_rss', $title);
     16        return $title;
     17}
    1318
    1419function get_the_title_rss() {
    1520        $title = get_the_title();
  • wp-includes/query.php

     
    265265        var $current_post = -1;
    266266        var $in_the_loop = false;
    267267        var $post;
     268       
     269        var $comments;
    268270
    269271        var $found_posts = 0;
    270272        var $max_num_pages = 0;
     
    282284        var $is_category = false;
    283285        var $is_search = false;
    284286        var $is_feed = false;
     287        var $is_comment_feed = false;
    285288        var $is_trackback = false;
    286289        var $is_home = false;
    287290        var $is_404 = false;
     
    305308                $this->is_category = false;
    306309                $this->is_search = false;
    307310                $this->is_feed = false;
     311                $this->is_comment_feed = false;
    308312                $this->is_trackback = false;
    309313                $this->is_home = false;
    310314                $this->is_404 = false;
     
    512516                if ('' != $qv['feed']) {
    513517                        $this->is_feed = true;
    514518                }
     519               
     520                if ($this->is_feed && (!empty($qv['withcomments']) || $this->is_single || $this->is_page)) {
     521                        $this->is_comment_feed = true;
     522                }
    515523
    516524                if ('' != $qv['tb']) {
    517525                        $this->is_trackback = true;
     
    966974                                $limits = 'LIMIT ' . $pgstrt . $q['posts_per_page'];
    967975                        }
    968976                }
     977               
     978                // Comments feeds
     979                if ($this->is_comment_feed && (($this->is_archive || $this->is_search) || (!$this->is_single && !$this->is_page))) {
     980                        if ($this->is_archive || $this->is_search) {
     981                                $cjoin = "LEFT JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) $join ";
     982                                $cwhere = "WHERE comment_approved = '1' $where";
     983                                $cgroupby = "GROUP BY $wpdb->comments.comment_id";
     984                        } elseif (!$this->is_single && !$this->is_page) {
     985                                $cjoin = "LEFT JOIN $wpdb->posts ON ( $wpdb->comments.comment_post_ID = $wpdb->posts.ID )";
     986                                $cwhere = "WHERE post_status = 'publish' AND comment_approved = '1'";
     987                                $cgroupby = '';
     988                        }
     989                       
     990                        $cjoin = apply_filters('comment_feed_join', $cjoin);
     991                        $cwhere = apply_filters('comment_feed_where', $cwhere);
     992                        $cgroupby = apply_filters('comment_feed_groupby', $cgroupby);
     993                       
     994                        $this->comments = $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'));
     995                       
     996                        $post_ids = array();
     997                       
     998                        foreach ($this->comments as $comment) {
     999                                $post_ids[] = (int) $comment->comment_post_ID;
     1000                        }
     1001                       
     1002                        $post_ids = join(',', $post_ids);
     1003                        $join = '';
     1004                        $where = "AND $wpdb->posts.ID IN ($post_ids) ";
     1005                }
    9691006
    9701007                // Apply post-paging filters on where and join.  Only plugins that
    9711008                // manipulate paging queries should use these hooks.
     
    9861023                $this->request = apply_filters('posts_request', $request);
    9871024
    9881025                $this->posts = $wpdb->get_results($this->request);
     1026               
     1027                if ($this->is_comment_feed && ($this->is_single || $this->is_page)) {
     1028                        $cjoin = apply_filters('comment_feed_join', '');
     1029                        $cwhere = apply_filters('comment_feed_where', "WHERE comment_post_ID = {$this->posts[0]->ID} AND comment_approved = '1'");
     1030                        $comments_request = "SELECT $wpdb->comments.* FROM $wpdb->comments $cjoin $cwhere ORDER BY comment_date_gmt DESC LIMIT " . get_settings('posts_per_rss');
     1031                        $this->comments = $wpdb->get_results($comments_request);
     1032                }
     1033               
    9891034                if ( !empty($limits) ) {
    9901035                        $found_posts_query = apply_filters( 'found_posts_query', 'SELECT FOUND_ROWS()' );
    9911036                        $this->found_posts = $wpdb->get_var( $found_posts_query );
    9921037                        $this->found_posts = apply_filters( 'found_posts', $this->found_posts );
    9931038                        $this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']);
    9941039                }
     1040               
    9951041                // Check post status to determine if post should be displayed.
    9961042                if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) {
    9971043                        $status = get_post_status($this->posts[0]);