Ticket #1785: wp-commentsatom.php

File wp-commentsatom.php, 3.7 KB (added by kurtmckee, 7 years ago)
Line 
1<?php 
2if ( empty($feed) ) {
3        $feed = 'atom';
4        $withcomments = 1;
5        $doing_rss = 1;
6        require('wp-blog-header.php');
7}
8
9        header('Content-type: application/atom+xml;charset=' . get_settings('blog_charset'), true);
10        echo '<?xml version="1.0" encoding="'.get_settings('blog_charset').'"?'.'>'; 
11?>
12
13<?php echo '<?xml-stylesheet href="'; ?><?php bloginfo('stylesheet_directory'); ?><?php echo '/atom.css" type="text/css"'.'?>'; ?>
14
15<?php
16$i = 0;
17if (have_posts()) :
18  while (have_posts()) : the_post();
19        if ($i < 1) {
20                $i++;
21?>
22
23<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom">
24        <title>
25                <?php if (is_single() || is_page()) {
26                        echo "Comments on: "; the_title_rss();
27                } else {
28                        bloginfo_rss("name"); echo " Comments";
29                } ?>
30        </title>
31        <?php if (bloginfo_rss("description")) { ?>
32                <subtitle><?php bloginfo_rss("description") ?></subtitle>
33        <?php } ?>
34        <id><?php bloginfo('url') ?>/comments/</id>
35        <link href="<?php (is_single()) ? permalink_single_rss() : bloginfo_rss("url") ?>" rel="alternate" type="<?php bloginfo('html_type'); ?>"/>
36        <link href="<?php bloginfo_rss("comments_rss2_url") ?>" rel="self" type="application/atom+xml"/>
37        <updated><?php echo gmdate('Y-m-d\TH:i:s\Z'); ?></updated>
38        <rights>Copyright <?php echo mysql2date('Y', get_lastpostdate('blog')); ?></rights>
39        <author>
40                <name>Various authors</name>
41        </author>
42        <generator version="<?php echo $wp_version ?>" uri="http://wordpress.org/">Wordpress</generator>
43
44        <?php 
45                if (is_single() || is_page()) {
46                        $comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_author_email,
47                        comment_author_url, comment_date, comment_date_gmt, comment_content, comment_post_ID,
48                        $wpdb->posts.ID, $wpdb->posts.post_password FROM $wpdb->comments 
49                        LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE comment_post_ID = '$id'
50                        AND $wpdb->comments.comment_approved = '1' AND ($wpdb->posts.post_status = 'publish' OR $wpdb->posts.post_status = 'page')
51                        AND post_date < '".date("Y-m-d H:i:59")."'
52                        ORDER BY comment_date LIMIT " . get_settings('posts_per_rss') );
53                } else { // if no post id passed in, we'll just ue the last 10 comments.
54                        $comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_author_email,
55                        comment_author_url, comment_date, comment_date_gmt, comment_content, comment_post_ID,
56                        $wpdb->posts.ID, $wpdb->posts.post_password FROM $wpdb->comments 
57                        LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE $wpdb->posts.post_status = 'publish'
58                        AND $wpdb->comments.comment_approved = '1' AND post_date < '".date("Y-m-d H:i:s")."' 
59                        ORDER BY comment_date DESC LIMIT " . get_settings('posts_per_rss') );
60                }
61                // this line is WordPress' motor, do not delete it.
62                if ($comments) {
63                        foreach ($comments as $comment) {
64                ?>
65
66        <entry>
67                <title>by: <?php comment_author_rss() ?></title>
68                <link href="<?php comment_link() ?>" rel="alternate" type="text/html" />
69                <author>
70                        <name><?php comment_author_rss() ?></name>
71                        <?php if (get_comment_author_url()) {
72                                echo '<uri>'.get_comment_author_url().'</uri>';
73                        } ?>
74                </author>
75                <id><?php permalink_single_rss() ?><?php /*echo $comment->comment_post_ID;*/ echo "#comment-"; comment_ID(); ?></id>
76                <updated><?php echo get_comment_time('Y-m-d\TH:i:s\Z', true); ?></updated>
77                <published><?php echo get_comment_time('Y-m-d\TH:i:s\Z', true); ?></published>
78
79                <?php if (!empty($comment->post_password) && $_COOKIE['wp-postpass'] != $comment->post_password) { ?>
80                        <content
81                                type="html"
82                                xml:base="<?php permalink_single_rss() ?>">
83                                <![CDATA[<?php echo get_the_password_form() ?>]]>
84                        </content>
85                <?php } else { ?>
86                        <content
87                                type="html"
88                                xml:base="<?php permalink_single_rss() ?>">
89                                <![CDATA[<?php comment_text() ?>]]>
90                        </content>
91                <?php } // close check for password ?>
92        </entry>
93
94                <?php } } } endwhile; endif; ?>
95
96</feed>