<?php

require_once('include/admin.inc.php');

auth_basic();

$count = isset($_REQUEST['count']) && ctype_digit($_REQUEST['count']) ? $_REQUEST['count'] : 25;

$entries = $mtdb->getAll("SELECT UNIX_TIMESTAMP(s.published) AS pubdate, c.name AS cname, c.email AS cmail, message FROM scratchpad s JOIN contributor c ON s.contributor = c.id ORDER BY s.published DESC LIMIT $count");

header("Content-Type: application/rss+xml;charset=utf-8");

echo "<?xml version=\"1.0\" ?>\n";
?>
<rss version="2.0">
	<channel>
		<title>Megatokyo Admin Scratchpad</title>
		<link>http://www.megatokyo.com/admin</link>
		<description>Listing of administrative events: errors, warnings, and notifications.</description>
		<language>en-us</language>

		<?php foreach($entries as $k=>$v) { ?>
			<item>
				<title><?php echo $v->cname, ': ', htmlentities($v->message, ENT_COMPAT, 'UTF-8') ?></title>
				<author><?php printf('%s (%s)', $v->cmail, $v->cname) ?></author>
				<pubDate><?php echo date( DATE_RFC822, $v->pubdate ) ?></pubDate>
				<guid><?php printf('%s%s/%s/?timestamp=%d', SITE_HOST, SITE_PATH, SITE_ADMIN, $v->pubdate) ?></guid>

				<description><?php echo $v->cname, ': ', htmlentities($v->message, ENT_COMPAT, 'UTF-8') ?></description>
			</item>
		<?php } ?>
	</channel>
</rss>
