<?php	
	ob_start();
	
	$entry = $db->query("SELECT * FROM entry ORDER BY time DESC LIMIT 0, 50")->result_array();
	
	foreach ($entry AS $key => $item)
	{
		$entry[$key]['picture'] = $db->query("SELECT * FROM picture WHERE entryid = " . $item['id'])->row_array();
	}
	
	$title = SITE_NAME . ' - RSS';
	
	echo urldecode('%3C%3Fxml+version=%221.0%22+encoding=%22utf-8%22%3F%3E');
?><rss version="2.0">
<channel>
<title><?php echo $title; ?></title>
<link><?php echo BASE_URL; ?></link>
<description>Powered by PageCookery Microblog v<?php echo $pcm_version; ?> Build <?php echo $pcm_build; ?></description>
<language>zh</language>
	<?php foreach ($entry AS $key => $item) { ?>
	<item>
	    <title><?php echo Format::Date($item['time']); ?> #<?php echo get_username_by_id($item['userid']); ?></title>
	    <link><?php echo BASE_URL; ?>?act=view&amp;id=<?php echo $item['id']; ?></link>
	    <description><![CDATA[<strong><?php echo get_username_by_id($item['userid']); ?></strong> <?php echo get_prefix($item['prefix']); ?> <?php echo $item['content']; ?>
		<?php if ($item['picture']['id']) { ?>
			<p class="image"><a href="<?php echo get_picture_url($item['picture']['id'], 'o'); ?>" title="<?php echo $item['picture']['filename']; ?>"><img src="<?php echo get_picture_url($item['picture']['id'], 'm'); ?>" alt="<?php echo $item['picture']['filename']; ?>" /></a></p>
		<?php } ?>
		<p style="font: 10px Arial; margin-top: 10px; text-align: right;">
			<span class="entry-meta"><?php echo Format::Time($item['time'], 1); ?> from <?php echo $item['from']; ?></span>
		</p>]]></description>
	    <pubDate><?php echo Format::Date($item['time'], 'D, j M Y H:i:s' , 0); ?> +0000</pubDate>
	</item>
	<?php } ?>
</channel>
</rss>
<?php
	
	$data = ob_get_contents(); 
	
	ob_end_clean();
	
	file_put_contents('rss.xml', $data);