<?PHP

//LatestNewsRSSGenerator.php
//Read Gambling news database and generate XML/RSS content with latest 5 syndicatable stories
//Automated version that does not work with IE6
//Jamie Sambells


require_once('/home/gambling/www/Connections/scraper.php');
define("XML_FILE", "/home/gambling/www/syndicate/ln.xml");

function replaceEntities($string)
{
    return strtr($string,array(
                              '&'  => '&amp;',
                              '>'  => '&gt;',
                              '<'  => '&lt;',
                              '"'  => '&quot;',
                              '\'' => '&apos;',
                              '�'  => '&#163;',
                              '�'  => '&yen;',
                              '�'  => '&euro;',
                              '$'  => '&#36;' ));
}

mysql_select_db($database_scraper, $scraper);
$query_showNewStories = "SELECT story_id, story_title, story_short_text, story_date FROM stories WHERE Syndicatable = '1' ORDER BY story_date DESC LIMIT 5";
$showNewStories = mysql_query($query_showNewStories, $scraper) or die(mysql_error());
$row_showNewStories = mysql_fetch_assoc($showNewStories);
$totalRows_showNewStories = mysql_num_rows($showNewStories);

echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n";
echo "<rss version=\"2.0\">\n";
echo "<channel>\n";
echo "<title>Gambling.co.uk Latest News</title>\n";
echo "<link>http://www.gambling.co.uk/news/gambling-news-archive-0.html</link>\n";
echo "<description>Latests 5 gambling news stories provided by gambling.co.uk</description>\n";

do 
{
	$description = $row_showNewStories['story_short_text']."<br><a href='http://www.gambling.co.uk/news/gambling-news.html?story=".$row_showNewStories['story_id']."' target=_blank>...Full Story</a>";
	echo "<item>";
	echo "<title>".replaceEntities($row_showNewStories['story_title'])."</title>";
	echo "<link>".replaceEntities("http://www.gambling.co.uk/news/gambling-news.html?story=".$row_showNewStories['story_id'])."</link>";
	echo '<guid isPermaLink="true">'.replaceEntities("http://www.gambling.co.uk/news/gambling-news.html?story=".$row_showNewStories['story_id']).'</guid>';
	echo "<pubDate>".date('D, d M Y h:i:s', strtotime($row_showNewStories['story_date']))." GMT</pubDate>";
	echo "<description>".replaceEntities($description)."</description>";
	echo "</item>";
		
} while ($row_showNewStories = mysql_fetch_assoc($showNewStories)); 

echo "</channel></rss>";

?>
