<?php
define("MODULE_FILE", true);
include("function/function.php");
get_lang();
Header("Content-Type: application/rss+xml");
Header("Content-Encoding: none");

echo "<?xml version=\"1.0\" encoding=\""._CHARSET."\"?>\n"
."<rss version=\"2.0\">\n"
."<channel>\n"
."<title>".htmlspecialchars($sitename)."</title>\n"
."<link>".$homeurl."</link>\n"
."<description>".htmlspecialchars($site_logo)."</description>\n"
."<generator>SLAED CMS ".$version."</generator>\n"
."<copyright>Copyright (c) SLAED CMS ".$version."</copyright>\n"
."<language>".htmlspecialchars(substr(""._LOCALE."", 0, 2))."</language>\n"
."<lastBuildDate>".date("D, j M Y H:m:s O")."</lastBuildDate>\n\n";

if (intval($_GET['limit']) || intval($_POST['limit'])) {
	$limit = substr(trim(isset($_POST['limit']) ? $_POST['limit'] : $_GET['limit']), 0, 2);
	if (eregi("[^0-9]", $limit)) $limit = "10";
} else {
	$limit = "10";
}
if (intval($_GET['cat']) || intval($_POST['cat'])) {
	$cat = substr(trim(isset($_POST['cat']) ? $_POST['cat'] : $_GET['cat']), 0, 3);
	if (eregi("[^0-9]", $cat)) $cat = "";
} else {
	$cat = "";
}
if (isset($_GET['mod']) || isset($_POST['mod'])) {
	$mod = substr(trim(isset($_POST['mod']) ? $_POST['mod'] : $_GET['mod']), 0, 25);
	if (eregi("[^a-zA-Z_]", $mod)) $mod = "";
} else {
	$mod = "";
}

if ($mod == "Files") {
	$where = ($cat) ? "WHERE cid='$cat' AND status !='0'" : "WHERE status !='0'";
	$result = $db->sql_query("SELECT lid, title, description, date FROM ".$prefix."_files ".$where." ORDER BY lid DESC LIMIT ".$limit."");
	while (list($rlid, $rtitle, $rdescription, $rdate) = $db->sql_fetchrow($result)) {
		echo "<item>\n"
		."<title>".htmlspecialchars($rtitle)."</title>\n"
		."<guid>$homeurl/index.php?name=Files&amp;op=view_file&amp;lid=$rlid</guid>\n"
		."<description>".htmlspecialchars(bb_decode($rdescription))."</description>\n"
		."<comments>$homeurl/index.php?name=Files&amp;op=view_file&amp;lid=$rlid#$rlid</comments>\n"
		."<pubDate>".htmlspecialchars(date("D, j M Y H:m:s O", strtotime($rdate)))."</pubDate>\n"
		."</item>\n\n";
	}
} else {
	$where = ($cat) ? "WHERE topic='$cat' AND time<=NOW() AND status='1'" : "WHERE time<=NOW() AND status='1'";
	$result = $db->sql_query("SELECT sid, title, time, hometext FROM ".$prefix."_stories ".$where." ORDER BY sid DESC LIMIT ".$limit."");
	while (list($rsid, $rtitle, $rtime, $rhometext) = $db->sql_fetchrow($result)) {
		echo "<item>\n"
		."<title>".htmlspecialchars($rtitle)."</title>\n"
		."<guid>$homeurl/index.php?name=News&amp;op=article&amp;sid=$rsid</guid>\n"
		."<description>".htmlspecialchars(bb_decode($rhometext))."</description>\n"
		."<comments>$homeurl/index.php?name=News&amp;op=article&amp;sid=$rsid#$rsid</comments>\n"
		."<pubDate>".htmlspecialchars(date("D, j M Y H:m:s O", strtotime($rtime)))."</pubDate>\n"
		."</item>\n\n";
	}
}
echo "</channel>\n";
echo "</rss>";
?>