<?php
/*
// EXPIRY DATA VIEWER - version 1.2
//
// This script is designed to accompany "expirychecker.php4"; it
// allows users to view the previous week's expiry data, which is
// stored in "ExpiryDataLastWeek.xml".
//
//
// martin.bush@lsbu.ac.uk, December 2004.
//
//
// Permission is granted to re-use all or part of this software
// under the terms of the GNU General Public License as published
// by the Free Software Foundation [www.gnu.org/copyleft/gpl.html].
// The author would very much appreciate being informed about any
// re-use of this software . . . thanks!
*/
/*
// INSTRUCTIONS:
// 1) Put this script ("expirydataviewer.php4") into the same
// directory as expirychecker.php4
// 2) This script should be invoked directly from a web browser.
// The correct URL is...
// http://www.lsbu.ac.uk/php4-cgiwrap/???/expirydataviewer.php4
// ...where "???" corresponds to the appropriate path.
*/
//================================================================
// This section based on: http://jp2.php.net/xml_parse_into_struct
//----------------------------------------------------------------
class ExpiredPage {
var $url;
var $owner;
var $expired;
var $message;
function ExpiredPage ($aa) {
foreach ($aa as $k=>$v)
$this->$k = $aa[$k];
}
}
//----------------------------------------------------------------
function readDatabase($file) {
// read the xml database of expired pages
$data = implode("",file($file));
$parser = xml_parser_create();
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
xml_parse_into_struct($parser,$data,$values,$tags);
xml_parser_free($parser);
// loop through the structures
foreach ($tags as $key=>$val) {
if ($key == "expiredpage") {
$molranges = $val;
// each contiguous pair of array entries are the
// lower and upper range for each expiredpage definition
for ($i=0; $i < count($molranges); $i+=2) {
$offset = $molranges[$i] + 1;
$len = $molranges[$i + 1] - $offset;
$tdb[] = parseMol(array_slice($values, $offset, $len));
}
} else {
continue;
}
}
return $tdb;
}
//----------------------------------------------------------------
function parseMol($mvalues) {
for ($i=0; $i < count($mvalues); $i++)
$mol[$mvalues[$i]["tag"]] = $mvalues[$i]["value"];
return new ExpiredPage($mol);
}
//================================================================
/*
// MAIN PROGRAM
*/
$theFile = "ExpiryDataLastWeek.xml";
// open and lock ExpiryDataLastWeek.xml
$theFile_fp = fopen($theFile, "r+");
$lock = flock($theFile_fp, 2);
// continue when lock is obtained
if ($lock) {
// read file contents
$db = readDatabase($theFile);
// rewind and read date on the 5th line of the file
fseek($theFile_fp, 0);
$i = 1;
while ($i < 6):
$line = fgets($theFile_fp);
$i = $i + 1;
endwhile;
$theDate = substr($line, 6, 8);
}
// unlock and close ExpiryDataLastWeek.xml
$lock = flock($theFile_fp, 3);
fclose($theFile_fp);
// Display preamble HTML
echo "<html><head><title>Expiry Checker: List of expired web
pages for week beginning Monday ";
echo $theDate;
echo" </title></head><body><pre>";
echo "<b><u>Expiry Checker: list of expired web pages for week
beginning Monday ";
echo $theDate;
echo "</u></b>\n\n";
// Just in case there were no expired pages last week...
if (count($db)==0) {
echo "\n\n ExpiryDataLastWeek.xml contains no data.\n\n";
} else {
// Pop each ExpiredPage object and display
while ($poppedExpiredPage = (array_pop($db))):
echo "<a href=\"";
echo $poppedExpiredPage->url;
echo "\">";
echo $poppedExpiredPage->url;
echo "</a>";
echo "\nOwner = ";
echo "<a href=\"mailto:";
echo $poppedExpiredPage->owner;
echo "\">";
echo $poppedExpiredPage->owner;
echo "</a>";
echo ", Expired = ";
echo $poppedExpiredPage->expired;
// echo "\nMessage = ";
// echo $poppedExpiredPage->message;
echo "\n\n";
endwhile;
}
// Display ending HTML
echo "</pre></body></head>";
?>
|