From ec8b66e9c4d793aa3b34cc2e52eb9031a022b488 Mon Sep 17 00:00:00 2001 From: shish Date: Wed, 16 May 2007 22:59:40 +0000 Subject: [PATCH] initial import of rss for comments git-svn-id: file:///home/shish/svn/shimmie2/trunk@102 7f39781d-f577-437e-ae19-be835c7a54ca --- contrib/rss_comments/main.php | 83 +++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 contrib/rss_comments/main.php diff --git a/contrib/rss_comments/main.php b/contrib/rss_comments/main.php new file mode 100644 index 00000000..598af736 --- /dev/null +++ b/contrib/rss_comments/main.php @@ -0,0 +1,83 @@ +page == "index")) { + global $page; + global $config; + $title = $config->get_string('title'); + + $page->add_header(""); + } + if(is_a($event, 'PageRequestEvent') && ($event->page == "rss")) { + if($event->get_arg(0) == 'comments') { + global $database; + $this->do_rss($database); + } + } + } +// }}} +// output {{{ + private function do_rss($database) { + global $page; + global $config; + $page->set_mode("data"); + $page->set_type("application/xml"); + + $comments = $database->db->GetAll(" + SELECT + users.id as user_id, users.name as user_name, + comments.comment as comment, comments.id as comment_id, + comments.image_id as image_id, comments.owner_ip as poster_ip, + UNIX_TIMESTAMP(posted) AS posted_timestamp + FROM comments + LEFT JOIN users ON comments.owner_id=users.id + ORDER BY comments.id DESC + LIMIT 10 + "); + + $data = ""; + foreach($comments as $comment) { + $image_id = $comment['image_id']; + $comment_id = $comment['comment_id']; + $link = make_link("post/view/$image_id"); + $owner = html_escape($comment['user_name']); + $posted = strftime("%a, %d %b %Y %T %Z", $comment['posted_timestamp']); + $comment = html_escape($comment['comment']); + $content = html_escape("$owner: $comment"); + + $data .= " + + $owner comments on $image_id + $link + $comment_id + $posted + $content + + "; + } + + $title = $config->get_string('title'); + $base_href = $config->get_string('base_href'); + $version = $config->get_string('version'); + $xml = << + + + $title + The latest comments on the image board + $base_href + $version + (c) 2007 Shish + $data + + +EOD; + $page->set_data($xml); + } +// }}} +} +add_event_listener(new RSS_Comments()); +?>