';
include '../../mainfile.php';
include_once XOOPS_ROOT_PATH.'/class/template.php';
$tpl = new XoopsTpl();
$tpl->xoops_setCaching(0);

$db =&Database::getInstance();
$myts =&MyTextSanitizer::getInstance();
$category_rss = isset($_GET['categoryID']) ? $_GET['categoryID'] : 0;

if ($category_rss<=0){
	$result = $db->query("SELECT * FROM ".$db->prefix("lxentries")."  ORDER BY 'datesub' DESC LIMIT 0,50");
} else {
	$result = $db->query("SELECT * FROM ".$db->prefix("lxentries")." WHERE categoryID='$category_rss' ORDER BY `datesub` DESC LIMIT 0,50");
	$info = $db->fetchArray($db->query("SELECT * FROM ".$db->prefix("lxcategories")." WHERE categoryID='$category_rss'"));
}

if ($category_rss > 0){
	$tpl->assign('channel_title', htmlspecialchars($xoopsConfig['sitename']." - ".sprintf(_MD_LX_INCATS, $info['name']), ENT_QUOTES, 'ISO-8859-1'));	
	$tpl->assign('channel_link', XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname').'/category.php?categoryID='.$category_rss);
	$tpl->assign('channel_desc', sprintf(_MD_LX_INCATS_DESC, $info['name'], $xoopsConfig['sitename']));
	$tpl->assign('channel_lastbuild', formatTimestamp(time(), 'rss'));
	$tpl->assign('channel_generator', 'Lexikon 1.17 RC2');
	$tpl->assign('channel_category', 'Categories');
	$tpl->assign('channel_editor', $xoopsConfig['adminmail']);
	$tpl->assign('channel_webmaster', $xoopsConfig['adminmail']);
	$tpl->assign('channel_language', _LANGCODE);
	$tpl->assign('image_url', XOOPS_URL.'/images/logo.gif');
	$dimention = getimagesize(XOOPS_ROOT_PATH.'/images/logo.gif');
	if (empty($dimention[0])) {
		$width = 128;
	} else {
		$width = ($dimention[0] > 128) ? 128 : $dimention[0];
	}
	if (empty($dimention[1])) {
		$height = 128;
	} else {
		$height = ($dimention[1] > 128) ? 128 : $dimention[1];
	}
	$tpl->assign('image_width',$width);
	$tpl->assign('image_height',$height);
} else {
	$tpl->assign('channel_title', htmlspecialchars($xoopsConfig['sitename'] ." - ".sprintf(_MD_LX_INCATS, $xoopsModule->getVar('dirname')), ENT_QUOTES, 'ISO-8859-1'));
	$tpl->assign('channel_link', XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname'));
	$tpl->assign('channel_desc', sprintf(_MD_LX_LASTDESC, $xoopsConfig['sitename']));
	$tpl->assign('channel_lastbuild', formatTimestamp(time(), 'rss'));
	$tpl->assign('channel_generator', 'Lexikon 1.01');
	$tpl->assign('channel_category', 'Entries');
	$tpl->assign('channel_editor', $xoopsConfig['adminmail']);
	$tpl->assign('channel_webmaster', $xoopsConfig['adminmail']);
	$tpl->assign('channel_language', _LANGCODE);
	$tpl->assign('image_url', XOOPS_URL.'/images/logo.gif');
	$dimention = getimagesize(XOOPS_ROOT_PATH.'/images/logo.gif');
	if (empty($dimention[0])) {
		$width = 128;
	} else {
		$width = ($dimention[0] > 128) ? 128 : $dimention[0];
	}
	if (empty($dimention[1])) {
		$height = 128;
	} else {
		$height = ($dimention[1] > 128) ? 128 : $dimention[1];
	}
	$tpl->assign('image_width',$width);
	$tpl->assign('image_height',$height);
}
while ($row=$db->fetchArray($result)){
	$tpl->append('items', array('title' =>htmlspecialchars($row['term'], ENT_QUOTES, 'ISO-8859-1'), 'link' => XOOPS_URL.'/modules/lexikon/entry.php?entryID='.$row['entryID'], 'guid' => XOOPS_URL.'/modules/lexikon/entry.php?entryID='.$row['entryID'], 'pubdate' => date($xoopsModuleConfig['dateformat'], $row['datesub']),  'description' => htmlspecialchars($myts->makeTareaData4Show($row['definition']), ENT_QUOTES)));	
}

$tpl->display(XOOPS_ROOT_PATH.'/modules/lexikon/templates/lx_rss.xml');

?>
