This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/rss_comments/main.php

81 lines
2.3 KiB
PHP
Raw Normal View History

<?php
2009-08-20 22:37:17 +00:00
/*
* Name: RSS for Comments
* Author: Shish <webmaster@shishnet.org>
2012-02-10 04:04:37 +00:00
* Link: http://code.shishnet.org/shimmie2/
* License: GPLv2
2009-10-09 12:30:21 +00:00
* Description: Self explanatory
*/
class RSS_Comments extends Extension {
2015-09-20 22:24:26 +00:00
protected $db_support = ['mysql', 'sqlite']; // pgsql has no UNIX_TIMESTAMP
public function onPostListBuilding(PostListBuildingEvent $event) {
2009-05-11 21:09:24 +00:00
global $config, $page;
$title = $config->get_string('title');
$page->add_html_header("<link rel=\"alternate\" type=\"application/rss+xml\" ".
2009-05-11 21:09:24 +00:00
"title=\"$title - Comments\" href=\"".make_link("rss/comments")."\" />");
}
public function onPageRequest(PageRequestEvent $event) {
2009-05-11 21:09:24 +00:00
global $config, $database, $page;
if($event->page_matches("rss/comments")) {
$page->set_mode("data");
$page->set_type("application/rss+xml");
2009-05-11 21:09:24 +00:00
$comments = $database->get_all("
2015-09-27 20:09:27 +00:00
SELECT
2009-05-11 21:09:24 +00:00
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,
2015-09-27 20:09:27 +00:00
comments.posted as posted
FROM comments
LEFT JOIN users ON comments.owner_id=users.id
ORDER BY comments.id DESC
LIMIT 10
");
2009-01-04 19:18:37 +00:00
2009-05-11 21:09:24 +00:00
$data = "";
foreach($comments as $comment) {
$image_id = $comment['image_id'];
$comment_id = $comment['comment_id'];
2009-07-24 07:09:24 +00:00
$link = make_http(make_link("post/view/$image_id"));
2009-05-11 21:09:24 +00:00
$owner = html_escape($comment['user_name']);
2015-09-27 20:09:27 +00:00
$posted = date(DATE_RSS, strtotime($comment['posted']));
2009-05-11 21:09:24 +00:00
$comment = html_escape($comment['comment']);
$content = html_escape("$owner: $comment");
2009-05-11 21:09:24 +00:00
$data .= "
<item>
<title>$owner comments on $image_id</title>
<link>$link</link>
<guid isPermaLink=\"false\">$comment_id</guid>
<pubDate>$posted</pubDate>
<description>$content</description>
</item>
";
}
$title = $config->get_string('title');
$base_href = make_http(get_base_href());
2009-05-11 21:09:24 +00:00
$version = $config->get_string('version');
$xml = <<<EOD
<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0">
2009-05-11 21:09:24 +00:00
<channel>
<title>$title</title>
<description>The latest comments on the image board</description>
<link>$base_href</link>
<generator>$version</generator>
<copyright>(c) 2007 Shish</copyright>
$data
</channel>
</rss>
EOD;
2009-05-11 21:09:24 +00:00
$page->set_data($xml);
}
}
}