<?php

#include siteconfig
include("../../siteconfig.inc");

# include functions
include("../../functions/database.inc");


$page1 = explode("/pages/", $PHP_SELF);
$page2 = $page1[1];
$page3 = explode("/", $page2);
$page = $page3[0];


# Determine current page & key
$RSS_KEY = array_search($page, $PAGE_DIR);

echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
echo "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">";
echo "
<channel>
	<title>$SITE_NAME $page</title>
	<link>$SITE_URL</link>
	<description>$SITE_NAME</description>
	<generator>$SITE_NAME</generator>
	";
	
$query[get_current_blog] = "SELECT * FROM tbl".$PAGE_TABLELABEL[$RSS_KEY]."_Entries
							ORDER BY EntryDateTime DESC
							LIMIT 0, 5";
$query[gcb_result] = mysql_query($query[get_current_blog]);
while($query[gcb_row] = mysql_fetch_array($query[gcb_result])) {
	extract($query[gcb_row]);

		$EntryContent = nl2br($EntryContent);

		$EntrySubject = str_replace("&","&amp;",$EntrySubject);
		$EntryContent = str_replace("&","&amp;",$EntryContent);
		
		$EntrySubject = str_replace("<","&lt;",$EntrySubject);
		$EntryContent = str_replace("<","&lt;",$EntryContent);

		$EntrySubject = str_replace(">","&gt;",$EntrySubject);
		$EntryContent = str_replace(">","&gt;",$EntryContent);
		
		$EntrySubject = str_replace("'","&apos;",$EntrySubject);
		$EntryContent = str_replace("'","&apos;",$EntryContent);

		echo "
	<item>
		<title>$EntrySubject</title>
		<link>$SITE_URL"."index.php?page=$page&amp;screen=show_entry&amp;entry=$EntryRowID</link>
		<author>$EntryAuthor $SITE_EMAIL</author>
		<pubDate>".date("D, d M Y H:i:s", strtotime($EntryDateTime))." EST</pubDate>
		<guid>$SITE_URL"."index.php?page=$page&amp;screen=show_entry&amp;entry=$EntryRowID</guid>
		<description>";
		
			if (file_exists("images/entries/$EntryRowID.jpg")) 
		{echo "&lt;img  src=\"images/entries/$EntryRowID.jpg\"&gt; &lt;BR&gt;&lt;BR&gt;";}
		
		echo "$EntryContent
		&lt;BR&gt;&lt;BR&gt;";
		
		if ($EntryTags != "") {
	echo "tags: ";
	$tags = explode(",", "$EntryTags");
	
	foreach($tags AS $t_key => $t_id) { 
		 $t_id = trim($t_id); 
		if ($tg == "") {$tg = "1"; echo "&lt;a href=\"$SITE_URL"."index.php?page=$page&amp;tag=$t_id\"&gt;$t_id&lt;/a&gt;";}
		else 
		{echo ", &lt;a href=\"$SITE_URL"."index.php?page=$page&amp;tag=$t_id\"&gt;$t_id&lt;/a&gt;";}
	
	}
	$tg = "";
	}
		
		echo "
		</description>

	</item>			
			";
					
			
}
	
echo "			
</channel>
</rss>";

?>
