<?php
//latestnews.xml
//Benj 10/05/2004

header('Content-type: text/xml');

//Number of items shown on the page:
$numbershown=20;

//Padding for hidden, disabled, or NoRSS Items
$dbpull = $numbershown + 20;

//Address-path to Newsview Page:
$linkpath = "http://www.request-a-song.com/news/viewnews.php?newsid=";

	// Database Retrieval
	include('/vdoms/ras/htdocs/include/db_connect.php');
	mysql_select_db("ras_sql", $DB);

	//Gets and Converts latest NewsDate into timestamp for use in PHP
	$Query = "SELECT UNIX_TIMESTAMP(NewsDate) FROM news ORDER BY NewsDate DESC LIMIT 1";
	$Result = mysql_query($Query, $DB);

	$DocPubStamp = mysql_fetch_array($Result);

//	mysql_close();

	//Generates RSS Formatted Date String for XML Document
	$DocPubDate = date('D, d M Y H:i:s T',$DocPubStamp[0]);

	//Current Year 4-Digit
	$CurrYear = date ('Y');

?>

<rss version="2.0">
<channel>

<title>Request-A-Song.com: Latest News</title>
<link>http://www.request-a-song.com/</link>

	<description>
	The most recent news from Request-A-Song.com.
	</description>

<language>en-us</language>
<copyright>&#169; Copyright <?= $CurrYear ?> Hollow Earth Productions. All Rights Reserved.</copyright>
<pubDate><?= $DocPubDate ?></pubDate>
<lastBuildDate><?= $DocPubDate ?></lastBuildDate>
<category>Request-A-Song.com: Latest News</category>

<image>
<title>Request-A-Song.com</title>
<url>http://www.request-a-song.com/images/rss_logo.gif</url>
<link>http://www.request-a-song.com/</link>
</image>


<?php

	$Query = "SELECT NewsNumber, NewsHeadline, UNIX_TIMESTAMP(NewsDate), NewsBody, FrontPage, SiteNews, SongNews, PubNews, Promo, PressRelease, Hidden, Disabled, NoRSS FROM news ORDER BY NewsDate DESC LIMIT " . $dbpull;
	$Result = mysql_query($Query, $DB);
	$NumRows = mysql_num_rows($Result);


for($i=0; $i<$numbershown; ++$i) {
	$Row = mysql_fetch_array($Result);
	if($Row == FALSE) break;

	if (($Row["Hidden"] == 0) && ($Row["Disabled"] == 0) && ($Row["NoRSS"] == 0))
		{

		$NewsPubDate = date('D, d M Y H:i:s T',$Row[2]);

	$HeadStrip = strip_tags($Row["NewsHeadline"]);
	$Head = htmlspecialchars($HeadStrip, ENT_QUOTES);

	$BodyHTML = htmlspecialchars($Row["NewsBody"], ENT_QUOTES);
	$replace = array("&lt;br&gt;", "&lt;br/&gt;", "&lt;br /&gt;");
	$BodyReplace = str_replace($replace, "&lt;br/&gt;", $BodyHTML);
	$BodyStrip = strip_tags($BodyReplace);
	$Body = substr($BodyStrip,0,1000);
	
		if (strlen($Body) >= 1000) {
			$Body = $Body . "... (continued on site)";
		}


?>

<item>
<title><?= $Head ?></title>
<link>
<?php print $linkpath . $Row["NewsNumber"] ?>
</link>
<guid isPermaLink="true">
<?php print $linkpath . $Row["NewsNumber"] ?>
</guid>
<description>
<?php if (strlen($Row["NewsBody"]) < 1) {

	print "(No additional info)";
	}
	else
	{
	print $Body;
	}
?>

</description>
<pubDate>
<?= $NewsPubDate ?>
</pubDate>
</item>


<?php

		}
		else
		{
		//decrement i by one so it skips over hidden item
		$i--;
		}
	//end of for-loop:
	}

//Close Database
mysql_close();

?>

</channel>
</rss>