root/tags/2.0.8/wp-commentsrss2.php

Revision 3314, 3.5 kB (checked in by ryan, 3 years ago)

Add post titles to site comment feed. Add some gettext. fixes #2067 #1987

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php
2
3 if (empty($wp)) {
4     require_once('wp-config.php');
5     wp('feed=rss2&withcomments=1');
6 }
7
8 header('Content-type: text/xml;charset=' . get_settings('blog_charset'), true);
9
10 echo '<?xml version="1.0" encoding="'.get_settings('blog_charset').'"?'.'>';
11 ?>
12 <!-- generator="wordpress/<?php echo $wp_version ?>" -->
13 <rss version="2.0"
14     xmlns:content="http://purl.org/rss/1.0/modules/content/">
15 <channel>
16 <?php
17 $i = 0;
18 if (have_posts()) :
19   while (have_posts()) : the_post();
20     if ($i < 1) {
21         $i++;
22 ?>
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>
26     <pubDate><?php echo gmdate('r'); ?></pubDate>
27     <generator>http://wordpress.org/?v=<?php echo $wp_version ?></generator>
28
29 <?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 IN ('publish', 'static', 'object')
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 IN ('publish', 'static', 'object')
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) {
49                 // Some plugins may need to know the metadata
50                 // associated with this comment's post:
51                 get_post_custom($comment->comment_post_ID);
52 ?>
53     <item>
54         <title><?php if ( ! (is_single() || is_page()) ) {
55             $title = get_the_title($comment->comment_post_ID);
56             $title = apply_filters('the_title', $title);
57             $title = apply_filters('the_title_rss', $title);
58             printf(__('Comment on %1$s by %2$s'), $title, get_comment_author_rss());
59         } else {   
60             printf(__('by: %s'), get_comment_author_rss());           
61         } ?></title>
62         <link><?php comment_link() ?></link>
63         <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_comment_time('Y-m-d H:i:s', true), false); ?></pubDate>
64         <guid><?php comment_link() ?></guid>
65             <?php
66             if (!empty($comment->post_password) && $_COOKIE['wp-postpass'] != $comment->post_password) {
67             ?>
68         <description><?php _e('Protected Comments: Please enter your password to view comments.'); ?></description>
69         <content:encoded><![CDATA[<?php echo get_the_password_form() ?>]]></content:encoded>
70             <?php
71             } else {
72             ?>
73         <description><?php comment_text_rss() ?></description>
74         <content:encoded><![CDATA[<?php comment_text() ?>]]></content:encoded>
75             <?php
76             } // close check for password
77             ?>
78     </item>
79 <?php
80             }
81         }
82     }
83 endwhile; endif;
84 ?>
85 </channel>
86 </rss>
87
Note: See TracBrowser for help on using the browser.