2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2007-05-16 22:59:40 +00:00
|
|
|
|
2023-01-10 22:44:09 +00:00
|
|
|
namespace Shimmie2;
|
|
|
|
|
2024-06-21 17:29:26 +00:00
|
|
|
use function MicroHTML\LINK;
|
|
|
|
|
2019-09-29 16:37:03 +00:00
|
|
|
class RSSComments extends Extension
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2024-01-15 11:52:35 +00:00
|
|
|
public function onPostListBuilding(PostListBuildingEvent $event): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
global $config, $page;
|
2019-08-02 19:40:03 +00:00
|
|
|
$title = $config->get_string(SetupConfig::TITLE);
|
2007-05-16 22:59:40 +00:00
|
|
|
|
2024-06-21 17:29:26 +00:00
|
|
|
$page->add_html_header(LINK([
|
|
|
|
'rel' => 'alternate',
|
|
|
|
'type' => 'application/rss+xml',
|
|
|
|
'title' => "$title - Comments",
|
|
|
|
'href' => make_link("rss/comments")
|
|
|
|
]));
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2007-05-16 22:59:40 +00:00
|
|
|
|
2024-01-15 11:52:35 +00:00
|
|
|
public function onPageRequest(PageRequestEvent $event): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
global $config, $database, $page;
|
|
|
|
if ($event->page_matches("rss/comments")) {
|
2019-06-19 01:58:28 +00:00
|
|
|
$page->set_mode(PageMode::DATA);
|
2020-06-14 16:05:55 +00:00
|
|
|
$page->set_mime(MimeType::RSS);
|
2007-05-16 22:59:40 +00:00
|
|
|
|
2019-05-28 16:59:38 +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
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$data = "";
|
|
|
|
foreach ($comments as $comment) {
|
|
|
|
$image_id = $comment['image_id'];
|
|
|
|
$comment_id = $comment['comment_id'];
|
|
|
|
$link = make_http(make_link("post/view/$image_id"));
|
|
|
|
$owner = html_escape($comment['user_name']);
|
2024-02-20 00:22:25 +00:00
|
|
|
$posted = date(DATE_RSS, \Safe\strtotime($comment['posted']));
|
2019-05-28 16:59:38 +00:00
|
|
|
$comment = html_escape($comment['comment']);
|
|
|
|
$content = html_escape("$owner: $comment");
|
2007-05-16 22:59:40 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$data .= "
|
2009-05-11 21:09:24 +00:00
|
|
|
<item>
|
|
|
|
<title>$owner comments on $image_id</title>
|
|
|
|
<link>$link</link>
|
|
|
|
<guid isPermaLink=\"false\">$comment_id</guid>
|
|
|
|
<pubDate>$posted</pubDate>
|
|
|
|
<description>$content</description>
|
|
|
|
</item>
|
|
|
|
";
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2009-05-11 21:09:24 +00:00
|
|
|
|
2019-08-02 19:40:03 +00:00
|
|
|
$title = $config->get_string(SetupConfig::TITLE);
|
2019-05-28 16:59:38 +00:00
|
|
|
$base_href = make_http(get_base_href());
|
2024-02-10 19:42:28 +00:00
|
|
|
$version = VERSION;
|
2019-05-28 16:59:38 +00:00
|
|
|
$xml = <<<EOD
|
2007-05-16 22:59:40 +00:00
|
|
|
<?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>
|
2007-05-16 22:59:40 +00:00
|
|
|
<link>$base_href</link>
|
|
|
|
<generator>$version</generator>
|
|
|
|
<copyright>(c) 2007 Shish</copyright>
|
|
|
|
$data
|
|
|
|
</channel>
|
|
|
|
</rss>
|
|
|
|
EOD;
|
2019-05-28 16:59:38 +00:00
|
|
|
$page->set_data($xml);
|
|
|
|
}
|
|
|
|
}
|
2019-08-02 19:54:48 +00:00
|
|
|
|
2024-01-15 11:52:35 +00:00
|
|
|
public function onPageSubNavBuilding(PageSubNavBuildingEvent $event): void
|
2019-08-02 19:54:48 +00:00
|
|
|
{
|
2023-11-11 21:49:12 +00:00
|
|
|
if ($event->parent == "comment") {
|
2019-08-02 19:54:48 +00:00
|
|
|
$event->add_nav_link("comment_rss", new Link('rss/comments'), "Feed");
|
|
|
|
}
|
|
|
|
}
|
2007-05-16 22:59:40 +00:00
|
|
|
}
|