<?
/*
// lwn.php3
//
// Version: 0.0.1
//
// Author: Cedric Raguenaud
// Lastmod: 28/06/2001
// Homepage: http://www.dcs.napier.ac.uk/~cedric
//
// This is an PHP include of SSI file
//
// PHP:
// <?
// include("lwn.php3");
// ?>
//
// SSI:
// <!--#include virtual="lwn.php3" -->
//
// Feel free to modify the code and e-mail me fixes as you see
// them fit...
//
*/
include_once("Snoopy.class");
// Customize as you like it
$link_prefix = "o <FONT SIZE=-1>";
$link_postfix = "</FONT><BR>\n";
$cache_time = 3600;
$target = "_top";
$name = "lwn";
// End of customizations
$backend = "http://lwn.net/headlines/rss";
$time = split(" ", microtime());
srand((double)microtime()*1000000);
$cache_time_rnd = 300 - rand(0, 600);
$cache_info = "";
$db2 = new myDB($config["sqlserver"], $config["sqluser"], $config["sqlpassword"], $config["sqldatabase"]);
if ($db2) {
$query = "select * from boxes where name = '".addslashes($name)."'";
$db2->setQuery($query);
$r2 = $db2->executequery();
if ($r2 >0) {
if ($db2->hasMoreElements()) {
$row2 = $db2->nextElement();
}
}
if ( ($row2["cache"] == "") || (($row2["time"] + $config["cache_time"] - $time[1]) + $cache_time_rnd < 0) ) {
$snoopy = new Snoopy;
$snoopy->fetch($backend);
{
$lines =0;
$text = explode("\n", $snoopy->results);
$index=0;
$header_passed=!1;
$exit=!1;
while(($index < count($text) ) && (!$exit) && ($lines < $config["linesperbox"])) {
$buffer = ltrim(Chop($text[$index]));
$index++;
if (eregi("<item", $buffer)) {
$buffer = ltrim(Chop($text[$index]));
$index++;
$title = substr($buffer, 7, strlen($buffer)-7-8);
$buffer = ltrim(Chop($text[$index]));
$index++;
$link = substr($buffer, 6, strlen($buffer)-6-7);
$cache_info .= $link_prefix."<a href=\"".$link."\">".$title."</a>".$link_postfix;
}
}
}
$query = "update boxes set cache='".addslashes($cache_info)."', time=".$time[1]." where name = '".addslashes($name)."'";
$db2->setQuery($query);
$r = $db2->executeQuery();
if ($r >0) {
debug("Box ".$name." updated");
} else {
debug("Box ".$name." not updated");
debug(mysql_error());
}
} else {
$cache_info = stripslashes($row2["cache"]);
}
$db2->close();
}
$output = $cache_info;
?>