forked from Cavemanon/cavepaintings
store enabled exts in a config file, rather than moving directories around
This commit is contained in:
78
ext/rss_comments/main.php
Normal file
78
ext/rss_comments/main.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/*
|
||||
* Name: RSS for Comments
|
||||
* Author: Shish <webmaster@shishnet.org>
|
||||
* Link: http://code.shishnet.org/shimmie2/
|
||||
* License: GPLv2
|
||||
* Description: Self explanatory
|
||||
*/
|
||||
|
||||
class RSS_Comments extends Extension {
|
||||
public function onPostListBuilding(PostListBuildingEvent $event) {
|
||||
global $config, $page;
|
||||
$title = $config->get_string('title');
|
||||
|
||||
$page->add_html_header("<link rel=\"alternate\" type=\"application/rss+xml\" ".
|
||||
"title=\"$title - Comments\" href=\"".make_link("rss/comments")."\" />");
|
||||
}
|
||||
|
||||
public function onPageRequest(PageRequestEvent $event) {
|
||||
global $config, $database, $page;
|
||||
if($event->page_matches("rss/comments")) {
|
||||
$page->set_mode("data");
|
||||
$page->set_type("application/rss+xml");
|
||||
|
||||
$comments = $database->get_all("
|
||||
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_http(make_link("post/view/$image_id"));
|
||||
$owner = html_escape($comment['user_name']);
|
||||
$posted = date(DATE_RSS, $comment['posted_timestamp']);
|
||||
$comment = html_escape($comment['comment']);
|
||||
$content = html_escape("$owner: $comment");
|
||||
|
||||
$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());
|
||||
$version = $config->get_string('version');
|
||||
$xml = <<<EOD
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<rss version="2.0">
|
||||
<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;
|
||||
$page->set_data($xml);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
22
ext/rss_comments/test.php
Normal file
22
ext/rss_comments/test.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
class RSSCommentsTest extends ShimmieWebTestCase {
|
||||
function testImageFeed() {
|
||||
$this->log_in_as_user();
|
||||
$image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx");
|
||||
$this->get_page("post/view/$image_id");
|
||||
$this->set_field('comment', "Test Comment ASDFASDF");
|
||||
$this->click("Post Comment");
|
||||
$this->assert_text("ASDFASDF");
|
||||
$this->log_out();
|
||||
|
||||
$this->get_page('rss/comments');
|
||||
$this->assert_mime("application/rss+xml");
|
||||
$this->assert_no_text("Exception");
|
||||
$this->assert_text("ASDFASDF");
|
||||
|
||||
$this->log_in_as_admin();
|
||||
$this->delete_image($image_id);
|
||||
$this->log_out();
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user