<?php
include 'functions.php';
header('Content-Type: application/rss+xml');
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
echo "<rss version=\"2.0\">";
echo "<channel>";
	echo "<title>Blog-Stalk Recent Posts</title>";
echo "<link>http://www.blog-stalk.com</link>";
echo "<description>Free social networking and blogging</description>";
dbopen();

function cleaned($s)
{
	$symbols = array("&", "'");
	$replacements = array("&#38;","&#39;");
	return str_replace($symbols, $replacements, $s);
}
function goodtime($moment)
{
	return date("D, d M Y H:i:s",$moment);
}

	$resultn=mysql_query("SELECT Subject, PostID, PostBody, Time FROM Posts WHERE Visibility = 1 ORDER BY PostID DESC LIMIT 0, 50");	
	while ($rown=mysql_fetch_row($resultn))
	{
		echo "<item>\n";
			echo "<title>";
				echo cleaned(stripslashes($rown[0]));
			echo "</title>\n";
			echo "<link>";
				echo "http://www.blog-stalk.com/showpost.php?ID=".$rown[1];
			echo "</link>\n";
			echo "<description>";
				echo "<![CDATA[".stripslashes($rown[2])."]]>";				
			echo "</description>\n";
			echo "<pubDate>";
				echo goodtime($rown[3])." +0000";
			echo "</pubDate>";
			echo "<guid>";
				echo "http://www.blog-stalk.com/showpost.php?ID=".$rown[1];
			echo "</guid>\n";
		echo "</item>\n";
	}
echo "</channel>\n</rss>\n";
?>
