<?php
//variable initialisation
	$db_online = true;
//variable initialisation

//database connection open
	@include("includes/sqlhead.php");
//database connection open

//function inclusion
	@include("includes/functions.php");
//function inclusion

header('Content-type: application/rss+xml');

	$build = date("r");
	$feed = <<<END
<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">
	<channel>
		<title>Ankh-Morpork.de ~ News</title>
		<link>http://www.Ankh-Morpork.de</link>
		<description>Diese Seite wird beim Laden automatisch aktualisiert. Angezeigt werden die letzten 10 News von Ankh-Morpork.de, sowie die Zeit und der Name des Autors.</description>

		<language>de</language>
		<generator>Ankh-Morpork.de 3.0</generator>
		<lastBuildDate>$build</lastBuildDate>
		<image>
			<url>http://www.ankh-morpork.de/img/menu/wappen1024.gif</url>
			<title>Ankh-Morpork.de</title>
			<link>http://www.Ankh-Morpork.de</link>
			<width>144</width>
			<height>200</height>
		</image>

END;
	$np_id = get_page_id("Newsmeldung");

	$start_news_result = mysql_query("SELECT *, date_format(datum, \"%d.%m.%Y\") AS fdatum, date_format(lastupdate, \"%d.%m.%Y\") AS fupdate, date_format(lastupdate, \"%a, %d %b %Y %T +0100\") AS feeddate FROM news WHERE target = \"all\" OR target = \"club\" ORDER BY lastupdate DESC, id DESC LIMIT 10");
	if(mysql_errno() != 0)
	{
		//Leerer Newsfeed
	}else
	{
		while($start_news_row = mysql_fetch_array($start_news_result))
		{
			$headline = $start_news_row[headline];
			if($start_news_row[fupdate] != $start_news_row[fdatum])
				$headline = "UPDATE: ".$headline;
			
			$headline = str_replace("&", "&amp;", $headline);
			$start_news_row[teaser] = str_replace("&", "&amp;", $start_news_row[teaser]);
			$start_news_row[autor] = str_replace("&", "&amp;", $start_news_row[autor]);
			$tmp_autor = str_replace("ä", "ae", $start_news_row[autor]);
			$tmp_autor = str_replace(" ", "", $tmp_autor);
			$start_news_row[autor] = $tmp_autor."@ankh-morpork.de (".$start_news_row[autor].")";
			
			$feed .= <<<END
		<item>
			<title>$start_news_row[fupdate] ~ $headline</title>
			<link>http://www.Ankh-Morpork.de/?seite=$np_id&amp;news=$start_news_row[id]</link>

			<description>$start_news_row[teaser]</description>
			<pubDate>$start_news_row[feeddate]</pubDate>
			<author>$start_news_row[autor]</author>
			<comments>http://www.Ankh-Morpork.de/?seite=$np_id&amp;news=$start_news_row[id]&amp;show_comments=1</comments>
		</item>

END;
		}
	}

	$feed .= <<<END
	</channel>
</rss>
END;

	print $feed;

//database connection close
	if($db_online == true)
		@include("includes/sqlfoot.php");
//database connection close
?>