PDA

View Full Version : RSS feed hack


01-06-2001, 11:57 PM
Hello everyone,

I built a PHP RSS library to include headlines from popular website into my homepage, it worked great and I used it to include my favourite sites slashdot, linuxtoday, and freshmeat of course ;)

but I needed to add my favourite bulletin board site that uses VB, and I searched for RSS support in VB, but I didn't find any, so I downloaded the lite version of VB and installed it, and after 3 hours I have my RSS hack for VB, and it works great, I tested it for the full version and it works fine there :)

I thought someone might be intersted on it, here is the code, it is a stripped down "forumdisplay.php" file with little changes to make it produce RSS file.
Put it in the same directory with "forumdisplay.php", and you call it in the same way "rss.php?forumid=1"

Hope you like it and use it :)


<?php echo '<?xml version="1.0"?>'; ?>

<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN"
"http://my.netscape.com/publish/formats/rss-0.91.dtd">

<rss version="0.91">

<channel>

<?php

echo "<!--\n";
require("global.php");
echo "-->\n";

echo "<title>$bbtitle</title>\n";
echo "<link>$bburl</link>\n";

// set defaults
if (isset($perpage)==0 or $perpage==0) {
$perpage=$maxthreads;
}

$forumid = verifyid("forum",$forumid);


$foruminfo=$DB_site->query_first("SELECT title,description,active FROM forum WHERE forumid=$forumid");
$forumtitle=htmlspecialchars($foruminfo[title]);
if ($foruminfo[active]==0) {
echo "<item><title>Forum Not Active</title></item></channel></rss>";
exit;
}

$description=htmlspecialchars($foruminfo[description]);
$forumtitle=htmlspecialchars($foruminfo[title]);

$threads=$DB_site->query("SELECT threadid,title,lastpost,replycount,postusername FROM thread WHERE forumid=$forumid ORDER BY lastpost DESC LIMIT 0,$perpage");
while ($thread=$DB_site->fetch_array($threads)) {

$threadtitle=htmlspecialchars($thread[title]);
$threadid=$thread[threadid];

$notes=htmlspecialchars($thread[notes]);
$replies=$thread[replycount];
$firstposter=htmlspecialchars($thread[postusername]);
$lastreplydate=date($dateformat,$thread[lastpost]+($timeoffset*3600));
$lastreplytime=date($timeformat,$thread[lastpost]+($timeoffset*3600));

echo "<item>\n";
echo "<title>$threadtitle</title>\n";
echo "<link>". $bburl ."/showthread.php?threadid=$threadid</link>\n";
echo "<description> $firstposter - $replies - $lastreplytime </description>\n";
echo "</item>\n";

}

?>

</channel>

</rss>

01-07-2001, 12:06 PM
do you have a sample of your site ?

01-07-2001, 05:27 PM
<a href="http://www.rayed.f2s.com/vb/rss.php?forumid=1" target="_blank">http://www.rayed.f2s.com/vb/rss.php?forumid=1</a>

of course it won't show anything, you have to save it and view it with normal editor.
the server is free server that a use for testing, sometimes it get very very slow.

01-07-2001, 05:49 PM
yeah freedom2surf really do my head in with the slowness.

X-Fan
04-01-2003, 01:34 PM
Is there any way to have this hack auto-generate a new RSS file for specified forums at the end of each day?

And how can someone display these news feeds on their Web sites, or via a ticker? I'd like to offer an "easy set-up" mehod for people to syndicate my site's news.