<? 
	header('Content-type: text/xml');

	define("FEED_TYPE", "1");

	// Some generic defines used for internal housekeeping. Do not change these!!!
	if(!defined('DIR_SEP')) {
		define('DIR_SEP', DIRECTORY_SEPARATOR);
	}

	if (!defined('BASE_DIR')) {
		define('BASE_DIR', dirname(__FILE__) . DIR_SEP);
	}


	// Defines that affect the functionality of the script
	if (!defined('TEMPLATE_DIR')) {
		define('TEMPLATE_DIR', BASE_DIR.'templates'.DIR_SEP);
	}


	// Include external libraries and helper functions.
	require_once("tv_template.php");
	require_once("helpers.php");
	require_once("site_config.php");
	require_once("tv_pingengine.php");

	$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_DB);
	// Get an array of all pages present in the database.
	$query = "select * from html_pages";
	$pages = db_array_query($query);

	// Dump the data into the XML file
	echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
?>
<rss version="2.0">
<channel>
<title><?=SITE_TITLE;?></title>
<description><?=SITE_DESCRIPTION;?></description>
<link><?=SITE_URL;?></link>
<copyright><?=SITE_COPYRIGHT;?></copyright>
<lastBuildDate><?=date("r");?></lastBuildDate>
<generator>techvision.ro RSS Feed Creator 1.0</generator>
<? foreach ($pages as $key=>$page) { ?>
		<item> 
			<title><?=$page['title']; ?></title> 
			<description><?=$page['summary'];?></description> 
			<author><?=SITE_AUTHOR;?></author>
			<link><?=$page['url'];?></link> 
			<pubDate><?=date("r"/*, $page['publish_date']*/); ?></pubDate> 
		</item>
<? } ?>
</channel>
</rss>
<?
	// Log the connection request into the database
	$ip = $_SERVER['REMOTE_ADDR'];
	if (isset($_SERVER['HTTP_REFERER'])) {
		$referer = $_SERVER['HTTP_REFERER'];
	} else {
		$referer = '';
	}
	if (isset($_SERVER['HTTP_USER_AGENT'])) {
		$user_agent = $_SERVER['HTTP_USER_AGENT'];
	} else {
		$user_agent = '';
	}
	$query = "INSERT INTO feed_requests (id, feed_type, ip, referer, request_time, user_agent) VALUES (NULL, ".FEED_TYPE.", '$ip', '$referer', CURRENT_TIMESTAMP, '$user_agent')";
	db_gen_query($query);

	db_disconnect();
?>
