<?php
//top_dl_songs.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 Songs
$dbpull = $numbershown + 20;

//Address-path to Songview Page:
$linkpath = "http://www.request-a-song.com/songs/viewsong.php?songid=";

	// Database Retrieval
	include('/vdoms/ras/htdocs/include/db_connect.php');
	mysql_select_db("ras_sql", $DB);

	//Generates RSS Formatted Date String for XML Document
	$DocPubDate = date('D, d M Y H:i:s T');

	//Current Year 4-Digit
	$CurrYear = date ('Y');

?>

<rss version="2.0">
<channel>

<title>Request-A-Song.com: Top <?= $numbershown ?> Most Downloaded Songs</title>
<link>http://www.request-a-song.com/</link>

	<description>
	The top <?= $numbershown ?> most downloaded songs on 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: Top <?= $numbershown ?> Most Downloaded Songs</category>
<ttl>60</ttl>

<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 SongNumber, Title, ReleaseDate, RequesterName, RequesterNamePublish, RequesterEmail, RequesterEmailPublish, ArtistComments, ArtistCommentsActive, Hidden, Disabled, NoRSS, DownloadRank FROM songs ORDER BY DownloadRank ASC 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))
		{

	$TitleStrip = strip_tags($Row["Title"]);
	$Title = htmlspecialchars($TitleStrip, ENT_QUOTES);

	$BodyHTML = htmlspecialchars($Row["ArtistComments"], 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)";
		}

	sscanf($Row["ReleaseDate"], "%d-%d-%d %d:%d:%d", $Year, $Month, $Day, $Hour, $Minute, $Second);
	$Timestamp = mktime($Hour, $Minute, $Second, $Month, $Day, $Year, -1);
	$ReleaseDate = date("F j, Y", $Timestamp);

?>

<item>
<title><?= $i+1 ?>. <?= $Title ?></title>
<link>
<?php print $linkpath . $Row["SongNumber"] ?>
</link>
<guid isPermaLink="true">
<?php print $linkpath . $Row["SongNumber"] ?>
</guid>
<description>
&lt;b&gt;Release Date:&lt;/b&gt;
&lt;br/&gt;
<?= $ReleaseDate ?>
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;Artist Comments:&lt;/b&gt;
&lt;br/&gt;

<?php if ($Row["ArtistCommentsActive"] == 1) {

	print $Body;
	}
	else
	{
	print "(No artist comments)";
	}
?>

</description>
<pubDate>
<?= $DocPubDate ?>
</pubDate>
</item>


<?php

		}
		else
		{
		//decrement i by one so it skips over hidden song
		$i--;
		}
	//end of for-loop:
	}

//Close Database
mysql_close();

?>

</channel>
</rss>