Comment feeds everywhere. Props mdawaffe and rob1n. fixes #2485
git-svn-id: http://svn.automattic.com/wordpress/trunk@4934 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
9b8e0722d4
commit
4bec99a338
|
@ -290,7 +290,9 @@ function comments_template( $file = '/comments.php' ) {
|
|||
$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");
|
||||
}
|
||||
|
||||
$comments = apply_filters( 'comments_array', $comments, $post->ID );
|
||||
// keep $comments for legacy's sake (remember $table*? ;) )
|
||||
$comments = $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );
|
||||
$wp_query->comment_count = count($wp_query->comments);
|
||||
|
||||
define('COMMENTS_TEMPLATE', true);
|
||||
$include = apply_filters('comments_template', TEMPLATEPATH . $file );
|
||||
|
|
|
@ -8,11 +8,12 @@ echo '<?xml version="1.0" encoding="' . get_option('blog_charset') . '" ?' . '>'
|
|||
<?php do_action('atom_ns'); ?>
|
||||
>
|
||||
<title type="text"><?php
|
||||
if (is_single() || is_page()) {
|
||||
if ( is_singular() )
|
||||
printf(__('Comments on: %s'), get_the_title_rss());
|
||||
} else {
|
||||
printf(__('Comments for %s'), get_bloginfo_rss('name'));
|
||||
}
|
||||
elseif ( is_search() )
|
||||
printf(__('Comments for %s searching on %s'), get_bloginfo_rss( 'name' ), attribute_escape($wp_query->query_vars['s']));
|
||||
else
|
||||
printf(__('Comments for %s'), get_bloginfo_rss( 'name' ) . get_wp_title_rss());
|
||||
?></title>
|
||||
<subtitle type="text"><?php bloginfo_rss('description'); ?></subtitle>
|
||||
|
||||
|
@ -24,39 +25,14 @@ echo '<?xml version="1.0" encoding="' . get_option('blog_charset') . '" ?' . '>'
|
|||
<id><?php bloginfo_rss('comments_atom_url'); ?></id>
|
||||
|
||||
<?php
|
||||
$i = 0;
|
||||
if (have_posts()) :
|
||||
while (have_posts()) : the_post();
|
||||
if ($i < 1) {
|
||||
$i++;
|
||||
}
|
||||
|
||||
if (is_single() || is_page()) {
|
||||
$comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_author_email,
|
||||
comment_author_url, comment_date, comment_date_gmt, comment_content, comment_post_ID,
|
||||
$wpdb->posts.ID, $wpdb->posts.post_password FROM $wpdb->comments
|
||||
LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE comment_post_ID = '" . get_the_ID() . "'
|
||||
AND $wpdb->comments.comment_approved = '1' AND $wpdb->posts.post_status = 'publish'
|
||||
AND post_date_gmt < '" . gmdate("Y-m-d H:i:59") . "'
|
||||
ORDER BY comment_date_gmt ASC" );
|
||||
} else { // if no post id passed in, we'll just use the last posts_per_rss comments.
|
||||
$comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_author_email,
|
||||
comment_author_url, comment_date, comment_date_gmt, comment_content, comment_post_ID,
|
||||
$wpdb->posts.ID, $wpdb->posts.post_password FROM $wpdb->comments
|
||||
LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE $wpdb->posts.post_status = 'publish'
|
||||
AND $wpdb->comments.comment_approved = '1' AND post_date_gmt < '" . gmdate("Y-m-d H:i:s") . "'
|
||||
ORDER BY comment_date_gmt DESC LIMIT " . get_option('posts_per_rss') );
|
||||
}
|
||||
|
||||
if ($comments) {
|
||||
foreach ($comments as $comment) {
|
||||
$GLOBALS['comment'] =& $comment;
|
||||
get_post_custom($comment->comment_post_ID);
|
||||
if ( have_comments() ) : while ( have_comments() ) : the_comment();
|
||||
$comment_post = get_post($comment->comment_post_ID);
|
||||
get_post_custom($comment_post->ID);
|
||||
?>
|
||||
<entry>
|
||||
<title><?php
|
||||
if (!(is_single() || is_page())) {
|
||||
$title = get_the_title($comment->comment_post_ID);
|
||||
if ( !is_singular() ) {
|
||||
$title = get_the_title($comment_post->ID);
|
||||
$title = apply_filters('the_title', $title);
|
||||
$title = apply_filters('the_title_rss', $title);
|
||||
printf(__('Comment on %1$s by %2$s'), $title, get_comment_author_rss());
|
||||
|
@ -69,23 +45,19 @@ if (have_posts()) :
|
|||
<author>
|
||||
<name><?php comment_author_rss(); ?></name>
|
||||
<?php if (get_comment_author_url()) echo '<uri>' . get_comment_author_url() . '</uri>'; ?>
|
||||
|
||||
</author>
|
||||
|
||||
<id><?php comment_link(); ?></id>
|
||||
<updated><?php echo mysql2date('D, d M Y H:i:s +0000', get_comment_time('Y-m-d H:i:s', true), false); ?></updated>
|
||||
<published><?php echo mysql2date('D, d M Y H:i:s +0000', get_comment_time('Y-m-d H:i:s', true), false); ?></published>
|
||||
|
||||
<?php if (!empty($comment->post_password) && $_COOKIE['wp-postpass'] != $comment->post_password) { ?>
|
||||
<?php if (!empty($comment_post->post_password) && $_COOKIE['wp-postpass'] != $comment_post->post_password) : ?>
|
||||
<content type="html" xml:base="<?php comment_link(); ?>"><![CDATA[<?php echo get_the_password_form(); ?>]]></content>
|
||||
<?php } else { ?>
|
||||
<?php else : // post pass ?>
|
||||
<content type="html" xml:base="<?php comment_link(); ?>"><![CDATA[<?php comment_text(); ?>]]></content>
|
||||
<?php } ?>
|
||||
</entry>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
endwhile;
|
||||
endif;
|
||||
<?php endif; // post pass
|
||||
do_action('comment_atom_entry', $comment->comment_ID, $comment_post->ID);
|
||||
?>
|
||||
</entry>
|
||||
<?php endwhile; endif; ?>
|
||||
</feed>
|
|
@ -7,77 +7,49 @@ echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>';
|
|||
<rss version="2.0"
|
||||
xmlns:content="http://purl.org/rss/1.0/modules/content/">
|
||||
<channel>
|
||||
<?php
|
||||
$i = 0;
|
||||
if (have_posts()) :
|
||||
while (have_posts()) : the_post();
|
||||
if ($i < 1) {
|
||||
$i++;
|
||||
?>
|
||||
<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>
|
||||
<title><?php
|
||||
if ( is_singular() )
|
||||
printf(__('Comments on: %s'), get_the_title_rss());
|
||||
elseif ( is_search() )
|
||||
printf(__('Comments for %s searching on %s'), get_bloginfo_rss( 'name' ), attribute_escape($wp_query->query_vars['s']));
|
||||
else
|
||||
printf(__('Comments for %s'), get_bloginfo_rss( 'name' ) . get_wp_title_rss());
|
||||
?></title>
|
||||
<link><?php (is_single()) ? permalink_single_rss() : bloginfo_rss("url") ?></link>
|
||||
<description><?php bloginfo_rss("description") ?></description>
|
||||
<pubDate><?php echo gmdate('r'); ?></pubDate>
|
||||
<generator>http://wordpress.org/?v=<?php echo $wp_version ?></generator>
|
||||
|
||||
<?php
|
||||
if (is_single() || is_page()) {
|
||||
$comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_author_email,
|
||||
comment_author_url, comment_date, comment_date_gmt, comment_content, comment_post_ID,
|
||||
$wpdb->posts.ID, $wpdb->posts.post_password FROM $wpdb->comments
|
||||
LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE comment_post_ID = '" . get_the_ID() . "'
|
||||
AND $wpdb->comments.comment_approved = '1' AND $wpdb->posts.post_status = 'publish'
|
||||
AND post_date_gmt < '" . gmdate("Y-m-d H:i:59") . "'
|
||||
ORDER BY comment_date_gmt ASC" );
|
||||
} else { // if no post id passed in, we'll just ue the last 10 comments.
|
||||
$comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_author_email,
|
||||
comment_author_url, comment_date, comment_date_gmt, comment_content, comment_post_ID,
|
||||
$wpdb->posts.ID, $wpdb->posts.post_password FROM $wpdb->comments
|
||||
LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE $wpdb->posts.post_status = 'publish'
|
||||
AND $wpdb->comments.comment_approved = '1' AND post_date_gmt < '" . gmdate("Y-m-d H:i:s") . "'
|
||||
ORDER BY comment_date_gmt DESC LIMIT " . get_option('posts_per_rss') );
|
||||
}
|
||||
// this line is WordPress' motor, do not delete it.
|
||||
if ($comments) {
|
||||
foreach ($comments as $comment) {
|
||||
$GLOBALS['comment'] =& $comment;
|
||||
// Some plugins may need to know the metadata
|
||||
// associated with this comment's post:
|
||||
get_post_custom($comment->comment_post_ID);
|
||||
if ( have_comments() ) : while ( have_comments() ) : the_comment();
|
||||
$comment_post = get_post($comment->comment_post_ID);
|
||||
get_post_custom($comment_post->ID);
|
||||
?>
|
||||
<item>
|
||||
<title><?php if ( ! (is_single() || is_page()) ) {
|
||||
$title = get_the_title($comment->comment_post_ID);
|
||||
$title = apply_filters('the_title', $title);
|
||||
$title = apply_filters('the_title_rss', $title);
|
||||
printf(__('Comment on %1$s by %2$s'), $title, get_comment_author_rss());
|
||||
} else {
|
||||
printf(__('By: %s'), get_comment_author_rss());
|
||||
} ?></title>
|
||||
<title><?php
|
||||
if ( !is_singular() ) {
|
||||
$title = get_the_title($comment_post->ID);
|
||||
$title = apply_filters('the_title', $title);
|
||||
$title = apply_filters('the_title_rss', $title);
|
||||
printf(__('Comment on %1$s by %2$s'), $title, get_comment_author_rss());
|
||||
} else {
|
||||
printf(__('By: %s'), get_comment_author_rss());
|
||||
}
|
||||
?></title>
|
||||
<link><?php comment_link() ?></link>
|
||||
<author><?php echo get_comment_author_rss() ?></author>
|
||||
<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_comment_time('Y-m-d H:i:s', true), false); ?></pubDate>
|
||||
<guid><?php comment_link() ?></guid>
|
||||
<?php
|
||||
if (!empty($comment->post_password) && $_COOKIE['wp-postpass'] != $comment->post_password) {
|
||||
?>
|
||||
<?php if (!empty($comment_post->post_password) && $_COOKIE['wp-postpass'] != $comment_post->post_password) : ?>
|
||||
<description><?php _e('Protected Comments: Please enter your password to view comments.'); ?></description>
|
||||
<content:encoded><![CDATA[<?php echo get_the_password_form() ?>]]></content:encoded>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<?php else : // post pass ?>
|
||||
<description><?php comment_text_rss() ?></description>
|
||||
<content:encoded><![CDATA[<?php comment_text() ?>]]></content:encoded>
|
||||
<?php
|
||||
} // close check for password
|
||||
do_action('commentrss2_item', $comment->comment_ID, $comment->comment_post_ID);
|
||||
?>
|
||||
</item>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
endwhile; endif;
|
||||
<?php endif; // post pass
|
||||
do_action('commentrss2_item', $comment->comment_ID, $comment_post->ID);
|
||||
?>
|
||||
</item>
|
||||
<?php endwhile; endif; ?>
|
||||
</channel>
|
||||
</rss>
|
||||
|
|
|
@ -10,6 +10,11 @@ function bloginfo_rss($show = '') {
|
|||
echo get_bloginfo_rss($show);
|
||||
}
|
||||
|
||||
function get_wp_title_rss($sep = '»') {
|
||||
$title = wp_title($sep, false);
|
||||
$title = apply_filters('get_wp_title_rss', $title);
|
||||
return $title;
|
||||
}
|
||||
|
||||
function get_the_title_rss() {
|
||||
$title = get_the_title();
|
||||
|
|
|
@ -939,29 +939,18 @@ function bool_from_yn($yn) {
|
|||
}
|
||||
|
||||
function do_feed() {
|
||||
global $wp_query;
|
||||
|
||||
$feed = get_query_var('feed');
|
||||
|
||||
// Remove the pad, if present.
|
||||
$feed = preg_replace('/^_+/', '', $feed);
|
||||
|
||||
if ( $feed == '' || $feed == 'feed' )
|
||||
$feed = 'rss2';
|
||||
|
||||
$for_comments = false;
|
||||
|
||||
if ( is_singular() || get_query_var('withcomments') == 1 )
|
||||
$for_comments = true;
|
||||
|
||||
if ( false !== strpos($feed, 'comments-') ) {
|
||||
$for_comments = true;
|
||||
$feed = str_replace('comments-', '', $feed);
|
||||
}
|
||||
|
||||
if ( get_query_var('withoutcomments') == 1 )
|
||||
$for_comments = false;
|
||||
$feed = 'rss2';
|
||||
|
||||
$hook = 'do_feed_' . $feed;
|
||||
do_action($hook, $for_comments);
|
||||
do_action($hook, $wp_query->is_comment_feed);
|
||||
}
|
||||
|
||||
function do_feed_rdf() {
|
||||
|
|
|
@ -10,6 +10,12 @@ function get_query_var($var) {
|
|||
return $wp_query->get($var);
|
||||
}
|
||||
|
||||
function set_query_var($var, $value) {
|
||||
global $wp_query;
|
||||
|
||||
return $wp_query->set($var, $value);
|
||||
}
|
||||
|
||||
function &query_posts($query) {
|
||||
unset($GLOBALS['wp_query']);
|
||||
$GLOBALS['wp_query'] =& new WP_Query();
|
||||
|
@ -249,6 +255,20 @@ function the_post() {
|
|||
$wp_query->the_post();
|
||||
}
|
||||
|
||||
/*
|
||||
* Comments loop.
|
||||
*/
|
||||
|
||||
function have_comments() {
|
||||
global $wp_query;
|
||||
return $wp_query->have_comments();
|
||||
}
|
||||
|
||||
function the_comment() {
|
||||
global $wp_query;
|
||||
return $wp_query->the_comment();
|
||||
}
|
||||
|
||||
/*
|
||||
* WP_Query
|
||||
*/
|
||||
|
@ -266,6 +286,11 @@ class WP_Query {
|
|||
var $in_the_loop = false;
|
||||
var $post;
|
||||
|
||||
var $comments;
|
||||
var $comment_count = 0;
|
||||
var $current_comment = -1;
|
||||
var $comment;
|
||||
|
||||
var $found_posts = 0;
|
||||
var $max_num_pages = 0;
|
||||
|
||||
|
@ -282,6 +307,7 @@ class WP_Query {
|
|||
var $is_category = false;
|
||||
var $is_search = false;
|
||||
var $is_feed = false;
|
||||
var $is_comment_feed = false;
|
||||
var $is_trackback = false;
|
||||
var $is_home = false;
|
||||
var $is_404 = false;
|
||||
|
@ -305,6 +331,7 @@ class WP_Query {
|
|||
$this->is_category = false;
|
||||
$this->is_search = false;
|
||||
$this->is_feed = false;
|
||||
$this->is_comment_feed = false;
|
||||
$this->is_trackback = false;
|
||||
$this->is_home = false;
|
||||
$this->is_404 = false;
|
||||
|
@ -537,6 +564,14 @@ class WP_Query {
|
|||
if ( $this->is_single || $this->is_page || $this->is_attachment )
|
||||
$this->is_singular = true;
|
||||
|
||||
if ( false !== strpos($qv['feed'], 'comments-') ) {
|
||||
$this->query_vars['feed'] = $qv['feed'] = str_replace('comments-', '', $qv['feed']);
|
||||
$qv['withcomments'] = 1;
|
||||
}
|
||||
|
||||
if ( $this->is_feed && (!empty($qv['withcomments']) || ( empty($qv['withoutcomments']) && $this->is_singular ) ) )
|
||||
$this->is_comment_feed = true;
|
||||
|
||||
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)) {
|
||||
$this->is_home = true;
|
||||
}
|
||||
|
@ -967,6 +1002,38 @@ class WP_Query {
|
|||
}
|
||||
}
|
||||
|
||||
// Comments feeds
|
||||
if ( $this->is_comment_feed && ( $this->is_archive || $this->is_search || !$this->is_singular ) ) {
|
||||
if ( $this->is_archive || $this->is_search ) {
|
||||
$cjoin = "LEFT JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) $join ";
|
||||
$cwhere = "WHERE comment_approved = '1' $where";
|
||||
$cgroupby = "GROUP BY $wpdb->comments.comment_id";
|
||||
} else { // Other non singular e.g. front
|
||||
$cjoin = "LEFT JOIN $wpdb->posts ON ( $wpdb->comments.comment_post_ID = $wpdb->posts.ID )";
|
||||
$cwhere = "WHERE post_status = 'publish' AND comment_approved = '1'";
|
||||
$cgroupby = '';
|
||||
}
|
||||
|
||||
$cjoin = apply_filters('comment_feed_join', $cjoin);
|
||||
$cwhere = apply_filters('comment_feed_where', $cwhere);
|
||||
$cgroupby = apply_filters('comment_feed_groupby', $cgroupby);
|
||||
|
||||
$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'));
|
||||
$this->comment_count = count($this->comments);
|
||||
|
||||
$post_ids = array();
|
||||
|
||||
foreach ($this->comments as $comment)
|
||||
$post_ids[] = (int) $comment->comment_post_ID;
|
||||
|
||||
$post_ids = join(',', $post_ids);
|
||||
$join = '';
|
||||
if ( $post_ids )
|
||||
$where = "AND $wpdb->posts.ID IN ($post_ids) ";
|
||||
else
|
||||
$where = "AND 0";
|
||||
}
|
||||
|
||||
// Apply post-paging filters on where and join. Only plugins that
|
||||
// manipulate paging queries should use these hooks.
|
||||
$where = apply_filters('posts_where_paged', $where);
|
||||
|
@ -986,12 +1053,22 @@ class WP_Query {
|
|||
$this->request = apply_filters('posts_request', $request);
|
||||
|
||||
$this->posts = $wpdb->get_results($this->request);
|
||||
|
||||
if ( $this->is_comment_feed && $this->is_singular ) {
|
||||
$cjoin = apply_filters('comment_feed_join', '');
|
||||
$cwhere = apply_filters('comment_feed_where', "WHERE comment_post_ID = {$this->posts[0]->ID} AND comment_approved = '1'");
|
||||
$comments_request = "SELECT $wpdb->comments.* FROM $wpdb->comments $cjoin $cwhere ORDER BY comment_date_gmt DESC LIMIT " . get_settings('posts_per_rss');
|
||||
$this->comments = $wpdb->get_results($comments_request);
|
||||
$this->comment_count = count($this->comments);
|
||||
}
|
||||
|
||||
if ( !empty($limits) ) {
|
||||
$found_posts_query = apply_filters( 'found_posts_query', 'SELECT FOUND_ROWS()' );
|
||||
$this->found_posts = $wpdb->get_var( $found_posts_query );
|
||||
$this->found_posts = apply_filters( 'found_posts', $this->found_posts );
|
||||
$this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']);
|
||||
}
|
||||
|
||||
// Check post status to determine if post should be displayed.
|
||||
if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) {
|
||||
$status = get_post_status($this->posts[0]);
|
||||
|
@ -1072,6 +1149,40 @@ class WP_Query {
|
|||
}
|
||||
}
|
||||
|
||||
function next_comment() {
|
||||
$this->current_comment++;
|
||||
|
||||
$this->comment = $this->comments[$this->current_comment];
|
||||
return $this->comment;
|
||||
}
|
||||
|
||||
function the_comment() {
|
||||
global $comment;
|
||||
|
||||
$comment = $this->next_comment();
|
||||
|
||||
if ($this->current_comment == 0) {
|
||||
do_action('comment_loop_start');
|
||||
}
|
||||
}
|
||||
|
||||
function have_comments() {
|
||||
if ($this->current_comment + 1 < $this->comment_count) {
|
||||
return true;
|
||||
} elseif ($this->current_comment + 1 == $this->comment_count) {
|
||||
$this->rewind_comments();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function rewind_comments() {
|
||||
$this->current_comment = -1;
|
||||
if ($this->comment_count > 0) {
|
||||
$this->comment = $this->comments[0];
|
||||
}
|
||||
}
|
||||
|
||||
function &query($query) {
|
||||
$this->parse_query($query);
|
||||
return $this->get_posts();
|
||||
|
|
Loading…
Reference in New Issue