<?php 
include_once ('../inc.siteconfig.php');
include_once ('../includes/magicQuotes.php');
include_once ('../includes/dbconnect.php');
include_once ('../includes/functions.php');


include_once ('../includes/classes/Object.php');


$filter = ' AND n.enabled = 1 AND n.deleted = 0 AND n.embargo_datetime <= NOW() AND n.publish = 1';
$query = "SELECT n.id, title, type, content, featured_image_name,thumbname,date, views, n.meta_description
			FROM news AS n 
			WHERE 1 {$filter}
			GROUP BY n.id
			ORDER BY n.`date` DESC, n.id DESC
			LIMIT 10";
			
if(! $result = mysql_query($query) ) {
	$aErrors['MAIN'][] = 'There was a database error.';
} else {
	while( $row = mysql_fetch_array($result) ) {
		$aNews[] = $row;		
	}
}


//$oNews 	= new Object('news');
//$orderBy = '`date` DESC, `id` DESC';
//$filter = "`type` = 'press'";
//$limit = 10;
//$aNews = $oNews->getAllObjects($orderBy, $filter, $limit);


if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
  header("Content-type: application/xhtml+xml");
}
else {
  header("Content-type: text/html");
}

echo '<?xml version="1.0" encoding="UTF-8" ?>';
echo '<rss version="2.0">';
echo '<channel>';
echo '<title>Moredirt - mountain biking news and gossip</title>';
echo '<description>A total resource to mountain biking in the UK. Information and advice, reviews of mountain bikes and equipment.</description>';
echo '<link>http://www.moredirt.com</link>';
echo '<copyright>© Copyright moredirt '.date('Y').', All Rights Reserved.</copyright>';
echo '<language>en-gb</language>';

	foreach ( $aNews as $news ) {
		$parts = explode("\n", $news['content']);

	$news['content'] = $parts[0];
?>		
        <item>
            <title><?php echo utf8_encode(htmlspecialchars($news['title'])); ?></title>
            <description><?php echo  utf8_encode(htmlspecialchars($news['content'])); ?></description>
            <link>http://www.moredirt.com/news_info.php?id=<?php echo $news['id']; ?></link>
            <pubDate><?php echo date('r', strtotime($news['date'])); ?></pubDate>
        </item>
<?php
	}
echo '</channel>';
echo '</rss>';
?>
