<?
/**********************************************************************************
* rss.php
* Version: 1.00
* Author: Rogers Cadenhead
* Date: 05/21/2004
* http://www.cadenhead.org/workbench/
*
**********************************************************************************
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This work is hereby released into the Public Domain. To view a copy of the public
domain dedication, visit http://creativecommons.org/licenses/publicdomain/ or
send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
94305, USA.
**********************************************************************************/
// prepare HTML text for use as UTF-8 character data in XML
function cleanText($intext) {
return utf8_encode(
htmlspecialchars(
stripslashes($intext)));
}
// set the file's content type and character set
// this must be called before any output
header("Content-Type: text/xml;charset=utf-8");
// retrieve database records
$db = mysql_pconnect("HOST", "USER", "PASS");
// the file db_connect.php contains only one line:
// $db = mysql_pconnect("localhost", "usernameHere", "passwordHere");
// it should be readable only by the user running the Web server
// and saved outside of the directory tree that holds Web pages
if (!$db)
{
error_log("Error: Could not connect to database in rss.php.");
exit;
}
// store items from the database in the $result1 array
mysql_select_db("DATABASE");
$query1 = "SELECT dl_links.name, dl_links.author, dl_links.description,
dl_categories.name, dl_categories.thumb, dl_links.date, dl_symlinks.sym_id,
dl_links.comments, dl_links.did, dl_categories.cid, dl_links.fileType,
dl_links.maskName, dl_links.download
FROM dl_links
INNER JOIN dl_symlinks ON dl_links.did = dl_symlinks.sym_did
INNER JOIN dl_categories ON dl_symlinks.sym_catid = dl_categories.cid
ORDER BY dl_links.date DESC
LIMIT 0 , 10";
$result1 = mysql_query($query1);
$phpversion = phpversion();
// display RSS 2.0 channel information
ECHO <<<END
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Wiisave Latest Uploads</title>
<link>http://www.wiisave.com</link>
<description>Wiisave RSS</description>
<language>en-us</language>
<generator>PHP/$phpversion</generator>
END;
// loop through the array pulling database fields for each item
for ($i = 0; $i < mysql_num_rows($result1); $i++) {
@$row = mysql_fetch_array($result1);
$title = cleanText($row[0]);
$link = "http://www.wiisave.com/?dlid=".
cleanText($row[6]);
$description = cleanText($row[2]);
$guid = $row[6];
$pubDate = date("r", strtotime($row[5]));
$enc_url = 'http://wiisave.com/downloads/'.$row[11];
$enc_filesize = filesize('downloads/'.$row[11]);
$enc_mime = $row[10];
$category = $row[3];
$comments = $row[12];
// display an item
ECHO <<<END
<item>
<title>$title</title>
<link>$link</link>
<description>$description</description>
<pubDate>$pubDate</pubDate>
<guid isPermaLink="false">$link</guid>
<enclosure length="$enc_filesize" url="$enc_url" type="$enc_mime" />
<category>$category</category>
<comments>$comments</comments>
</item>
END;
}
ECHO <<<END
</channel>
</rss>
END;
?>