Ticket #2485: 2485.3.diff
File 2485.3.diff, 16.2 KB (added by , 18 years ago) |
---|
-
wp-includes/query.php
250 250 } 251 251 252 252 /* 253 * Comments loop. 254 */ 255 256 function have_comments() { 257 global $wp_query; 258 return $wp_query->have_comments(); 259 } 260 261 function the_comment() { 262 global $wp_query; 263 return $wp_query->the_comment(); 264 } 265 266 /* 253 267 * WP_Query 254 268 */ 255 269 … … 265 279 var $current_post = -1; 266 280 var $in_the_loop = false; 267 281 var $post; 282 283 var $comments; 284 var $comment_count = 0; 285 var $current_comment = -1; 286 var $comment; 268 287 269 288 var $found_posts = 0; 270 289 var $max_num_pages = 0; … … 282 301 var $is_category = false; 283 302 var $is_search = false; 284 303 var $is_feed = false; 304 var $is_comment_feed = false; 285 305 var $is_trackback = false; 286 306 var $is_home = false; 287 307 var $is_404 = false; … … 305 325 $this->is_category = false; 306 326 $this->is_search = false; 307 327 $this->is_feed = false; 328 $this->is_comment_feed = false; 308 329 $this->is_trackback = false; 309 330 $this->is_home = false; 310 331 $this->is_404 = false; … … 512 533 if ('' != $qv['feed']) { 513 534 $this->is_feed = true; 514 535 } 536 537 if ($this->is_feed && (!empty($qv['withcomments']) || ( empty($qv['withoutcomments']) && $this->is_single || $this->is_page ) )) { 538 $this->is_comment_feed = true; 539 } 515 540 516 541 if ('' != $qv['tb']) { 517 542 $this->is_trackback = true; … … 966 991 $limits = 'LIMIT ' . $pgstrt . $q['posts_per_page']; 967 992 } 968 993 } 994 995 // Comments feeds 996 if ( $this->is_comment_feed && ( $this->is_archive || $this->is_search || !$this->is_singular ) ) { 997 if ( $this->is_archive || $this->is_search ) { 998 $cjoin = "LEFT JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) $join "; 999 $cwhere = "WHERE comment_approved = '1' $where"; 1000 $cgroupby = "GROUP BY $wpdb->comments.comment_id"; 1001 } else { // Other non singular e.g. front 1002 $cjoin = "LEFT JOIN $wpdb->posts ON ( $wpdb->comments.comment_post_ID = $wpdb->posts.ID )"; 1003 $cwhere = "WHERE post_status = 'publish' AND comment_approved = '1'"; 1004 $cgroupby = ''; 1005 } 1006 1007 $cjoin = apply_filters('comment_feed_join', $cjoin); 1008 $cwhere = apply_filters('comment_feed_where', $cwhere); 1009 $cgroupby = apply_filters('comment_feed_groupby', $cgroupby); 1010 1011 $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')); 1012 $this->comment_count = count($this->comments); 969 1013 1014 $post_ids = array(); 1015 1016 foreach ($this->comments as $comment) 1017 $post_ids[] = (int) $comment->comment_post_ID; 1018 1019 $post_ids = join(',', $post_ids); 1020 $join = ''; 1021 if ( $post_ids ) 1022 $where = "AND $wpdb->posts.ID IN ($post_ids) "; 1023 else 1024 $where = "AND 0"; 1025 } 1026 970 1027 // Apply post-paging filters on where and join. Only plugins that 971 1028 // manipulate paging queries should use these hooks. 972 1029 $where = apply_filters('posts_where_paged', $where); … … 986 1043 $this->request = apply_filters('posts_request', $request); 987 1044 988 1045 $this->posts = $wpdb->get_results($this->request); 1046 1047 if ($this->is_comment_feed && $this->is_singular ) { 1048 $cjoin = apply_filters('comment_feed_join', ''); 1049 $cwhere = apply_filters('comment_feed_where', "WHERE comment_post_ID = {$this->posts[0]->ID} AND comment_approved = '1'"); 1050 $comments_request = "SELECT $wpdb->comments.* FROM $wpdb->comments $cjoin $cwhere ORDER BY comment_date_gmt DESC LIMIT " . get_settings('posts_per_rss'); 1051 $this->comments = $wpdb->get_results($comments_request); 1052 $this->comment_count = count($this->comments); 1053 } 1054 989 1055 if ( !empty($limits) ) { 990 1056 $found_posts_query = apply_filters( 'found_posts_query', 'SELECT FOUND_ROWS()' ); 991 1057 $this->found_posts = $wpdb->get_var( $found_posts_query ); 992 1058 $this->found_posts = apply_filters( 'found_posts', $this->found_posts ); 993 1059 $this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']); 994 1060 } 1061 995 1062 // Check post status to determine if post should be displayed. 996 1063 if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) { 997 1064 $status = get_post_status($this->posts[0]); … … 1071 1138 $this->post = $this->posts[0]; 1072 1139 } 1073 1140 } 1141 1142 function next_comment() { 1143 $this->current_comment++; 1144 1145 $this->comment = $this->comments[$this->current_comment]; 1146 return $this->comment; 1147 } 1148 1149 function the_comment() { 1150 global $comment; 1151 1152 $comment = $this->next_comment(); 1153 1154 if ($this->current_comment == 0) { 1155 do_action('comment_loop_start'); 1156 } 1157 } 1158 1159 function have_comments() { 1160 if ($this->current_comment + 1 < $this->comment_count) { 1161 return true; 1162 } elseif ($this->current_comment + 1 == $this->comment_count) { 1163 $this->rewind_comments(); 1164 } 1165 1166 return false; 1167 } 1168 1169 function rewind_comments() { 1170 $this->current_comment = -1; 1171 if ($this->comment_count > 0) { 1172 $this->comment = $this->comments[0]; 1173 } 1174 } 1074 1175 1075 1176 function &query($query) { 1076 1177 $this->parse_query($query); -
wp-includes/feed-rss2-comments.php
7 7 <rss version="2.0" 8 8 xmlns:content="http://purl.org/rss/1.0/modules/content/"> 9 9 <channel> 10 <?php11 $i = 0; 12 if (have_posts()) : 13 while (have_posts()) : the_post(); 14 if ($i < 1) {15 $i++;16 ?> 17 <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>10 <title><?php 11 if ( is_singular() ) 12 printf(__('Comments on: %s'), get_the_title_rss()); 13 elseif ( is_search() ) 14 printf(__('Comments for %s searching on %s'), get_bloginfo_rss( 'name' ), attribute_escape($wp_query->query_vars['s'])); 15 else 16 printf(__('Comments for %s'), get_bloginfo_rss( 'name' ) . get_wp_title_rss()); 17 ?></title> 18 18 <link><?php (is_single()) ? permalink_single_rss() : bloginfo_rss("url") ?></link> 19 19 <description><?php bloginfo_rss("description") ?></description> 20 20 <pubDate><?php echo gmdate('r'); ?></pubDate> 21 21 <generator>http://wordpress.org/?v=<?php echo $wp_version ?></generator> 22 22 23 23 <?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) { 43 $GLOBALS['comment'] =& $comment; 44 // Some plugins may need to know the metadata 45 // associated with this comment's post: 46 get_post_custom($comment->comment_post_ID); 24 if ( have_comments() ) : while ( have_comments() ) : the_comment(); 25 $comment_post = get_post($comment->comment_post_ID); 26 get_post_custom($comment_post->ID); 47 27 ?> 48 28 <item> 49 <title><?php if ( ! (is_single() || is_page()) ) { 50 $title = get_the_title($comment->comment_post_ID); 51 $title = apply_filters('the_title', $title); 52 $title = apply_filters('the_title_rss', $title); 53 printf(__('Comment on %1$s by %2$s'), $title, get_comment_author_rss()); 54 } else { 55 printf(__('By: %s'), get_comment_author_rss()); 56 } ?></title> 29 <title><?php 30 if ( !is_singular() ) { 31 $title = get_the_title($comment_post->ID); 32 $title = apply_filters('the_title', $title); 33 $title = apply_filters('the_title_rss', $title); 34 printf(__('Comment on %1$s by %2$s'), $title, get_comment_author_rss()); 35 } else { 36 printf(__('By: %s'), get_comment_author_rss()); 37 } 38 ?></title> 57 39 <link><?php comment_link() ?></link> 58 40 <author><?php echo get_comment_author_rss() ?></author> 59 41 <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_comment_time('Y-m-d H:i:s', true), false); ?></pubDate> 60 42 <guid><?php comment_link() ?></guid> 61 <?php 62 if (!empty($comment->post_password) && $_COOKIE['wp-postpass'] != $comment->post_password) { 63 ?> 43 <?php if (!empty($comment_post->post_password) && $_COOKIE['wp-postpass'] != $comment_post->post_password) : ?> 64 44 <description><?php _e('Protected Comments: Please enter your password to view comments.'); ?></description> 65 45 <content:encoded><![CDATA[<?php echo get_the_password_form() ?>]]></content:encoded> 66 <?php 67 } else { 68 ?> 46 <?php else : // post pass ?> 69 47 <description><?php comment_text_rss() ?></description> 70 48 <content:encoded><![CDATA[<?php comment_text() ?>]]></content:encoded> 71 <?php 72 } // close check for password 73 do_action('commentrss2_item', $comment->comment_ID, $comment->comment_post_ID); 74 ?> 75 </item> 76 <?php 77 } 78 } 79 } 80 endwhile; endif; 49 <?php endif; // post pass 50 do_action('commentrss2_item', $comment->comment_ID, $comment_post->ID); 81 51 ?> 52 </item> 53 <?php endwhile; endif; ?> 82 54 </channel> 83 55 </rss> -
wp-includes/feed.php
10 10 echo get_bloginfo_rss($show); 11 11 } 12 12 13 function get_wp_title_rss($sep = '»') { 14 $title = wp_title($sep, false); 15 $title = apply_filters('get_wp_title_rss', $title); 16 return $title; 17 } 13 18 14 19 function get_the_title_rss() { 15 20 $title = get_the_title(); … … 177 182 if ($key == 'enclosure') { 178 183 foreach ((array)$val as $enc) { 179 184 $enclosure = split("\n", $enc); 180 echo apply_filters('rss_enclosure', '<enclosure url="' . trim(htmlspecialchars($enclosure[0])) . '" length="' . trim($enclosure[1]) . '" type="' . trim($enclosure[2]) . '" />' . "\n" ;185 echo apply_filters('rss_enclosure', '<enclosure url="' . trim(htmlspecialchars($enclosure[0])) . '" length="' . trim($enclosure[1]) . '" type="' . trim($enclosure[2]) . '" />' . "\n"); 181 186 } 182 187 } 183 188 } … … 192 197 if ($key == 'enclosure') { 193 198 foreach ((array)$val as $enc) { 194 199 $enclosure = split("\n", $enc); 195 echo apply_filters('atom_enclosure', '<link href="' . trim(htmlspecialchars($enclosure[0])) . '" rel="enclosure" length="' . trim($enclosure[1]) . '" type="' . trim($enclosure[2]) . '" />' . "\n" ;200 echo apply_filters('atom_enclosure', '<link href="' . trim(htmlspecialchars($enclosure[0])) . '" rel="enclosure" length="' . trim($enclosure[1]) . '" type="' . trim($enclosure[2]) . '" />' . "\n"); 196 201 } 197 202 } 198 203 } 199 204 } 200 205 201 ?> 202 No newline at end of file 206 ?> -
wp-includes/comment-template.php
290 290 $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND ( comment_approved = '1' OR ( comment_author = '$author_db' AND comment_author_email = '$email_db' AND comment_approved = '0' ) ) ORDER BY comment_date"); 291 291 } 292 292 293 $comments = apply_filters( 'comments_array', $comments, $post->ID ); 293 // keep $comments for legacy's sake (remember $table*? ;) ) 294 $comments = $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID ); 295 $wp_query->comment_count = count($wp_query->comments); 294 296 295 297 define('COMMENTS_TEMPLATE', true); 296 298 $include = apply_filters('comments_template', TEMPLATEPATH . $file ); -
wp-includes/feed-atom-comments.php
8 8 <?php do_action('atom_ns'); ?> 9 9 > 10 10 <title type="text"><?php 11 if ( is_single() || is_page()) {11 if ( is_singular() ) 12 12 printf(__('Comments on: %s'), get_the_title_rss()); 13 } else { 14 printf(__('Comments for %s'), get_bloginfo_rss('name')); 15 } 13 elseif ( is_search() ) 14 printf(__('Comments for %s searching on %s'), get_bloginfo_rss( 'name' ), attribute_escape($wp_query->query_vars['s'])); 15 else 16 printf(__('Comments for %s'), get_bloginfo_rss( 'name' ) . get_wp_title_rss()); 16 17 ?></title> 17 18 <subtitle type="text"><?php bloginfo_rss('description'); ?></subtitle> 18 19 … … 24 25 <id><?php bloginfo_rss('comments_atom_url'); ?></id> 25 26 26 27 <?php 27 $i = 0; 28 if (have_posts()) : 29 while (have_posts()) : the_post(); 30 if ($i < 1) { 31 $i++; 32 } 33 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) { 53 $GLOBALS['comment'] =& $comment; 54 get_post_custom($comment->comment_post_ID); 28 if ( have_comments() ) : while ( have_comments() ) : the_comment(); 29 $comment_post = get_post($comment->comment_post_ID); 30 get_post_custom($comment_post->ID); 55 31 ?> 56 32 <entry> 57 33 <title><?php 58 if ( !(is_single() || is_page())) {59 $title = get_the_title($comment ->comment_post_ID);34 if ( !is_singular() ) { 35 $title = get_the_title($comment_post->ID); 60 36 $title = apply_filters('the_title', $title); 61 37 $title = apply_filters('the_title_rss', $title); 62 38 printf(__('Comment on %1$s by %2$s'), $title, get_comment_author_rss()); … … 69 45 <author> 70 46 <name><?php comment_author_rss(); ?></name> 71 47 <?php if (get_comment_author_url()) echo '<uri>' . get_comment_author_url() . '</uri>'; ?> 48 72 49 </author> 73 50 74 51 <id><?php comment_link(); ?></id> 75 52 <updated><?php echo mysql2date('D, d M Y H:i:s +0000', get_comment_time('Y-m-d H:i:s', true), false); ?></updated> 76 53 <published><?php echo mysql2date('D, d M Y H:i:s +0000', get_comment_time('Y-m-d H:i:s', true), false); ?></published> 77 78 <?php if (!empty($comment->post_password) && $_COOKIE['wp-postpass'] != $comment->post_password) { ?> 54 <?php if (!empty($comment_post->post_password) && $_COOKIE['wp-postpass'] != $comment_post->post_password) : ?> 79 55 <content type="html" xml:base="<?php comment_link(); ?>"><![CDATA[<?php echo get_the_password_form(); ?>]]></content> 80 <?php } else {?>56 <?php else : // post pass ?> 81 57 <content type="html" xml:base="<?php comment_link(); ?>"><![CDATA[<?php comment_text(); ?>]]></content> 82 <?php } ?> 83 </entry> 84 <?php 85 } 86 } 87 88 endwhile; 89 endif; 58 <?php endif; // post pass 59 do_action('comment_atom_entry', $comment->comment_ID, $comment_post->ID); 90 60 ?> 91 </feed> 92 No newline at end of file 61 </entry> 62 <?php endwhile; endif; ?> 63 </feed>