HTML
|
|
|
|
<? /* Title: LinkBox class
* By: Mitchell Broome <mbroome@roman.net>
* Date: 3/12/2000
*/
/* Example:
<?
include("linkbox.php3");
$link1 = new LinkBox("PHP Manual", "http://www.php.net/manual", 300);
$link1->Add("Link 1","/whereever");
$link1->Add("Link 2","/another/place");
$link1->Add("Link 3","/one/more");
$link1->Add("sep1","-");
$link1->Add("More:","title");
$link1->Add("Link 4","http://last/one");
$link1->Show();
$link2 = new LinkBox("Freshmeat");
$link2->RDF("http://freshmeat.net/backend/fm.rdf");
$link2->Show();
?>
*/
/*
Title properties are set when the new object is created
$link1 = new LinkBox("Title", "url", "width");
Colors can be set by calling
$link1->Color("object", "#000000");
where "object" is one of the following:
border = #000000 // border color
title_bg = #EEEEEE // title fill
fill = #FFFFFF // body fill
text = #000000 // title text
Members are added to the object by
$link1->Add("Text", "url");
$link1->Add("Title","title");
$link1->Add("Seperator1","-");
Multiple seperators need to be named different things
To make a RDF linkbox:
$link2->RDF("http://path/to/rdf/file","dir",time);
Defaults:
dir = "./rdf/" // place to store cached rdf files
time = 30 // time to cache rdf
If dir and time are left off, defaults are used.
If dir doesn't exist, it is made. The web server has to have
permission to write to the dir cached rdf files are in.
The object is show by
$link1->Show();
*/
class LinkBox{
var $title;
var $width;
var $url;
var $lb_color;
var $newsdir;
var $rdf_flag;
var $rdf_file;
var $agelimit;
function LinkBox($title,$url="",$width=200){
$this->title=$title;
$this->width=$width;
$this->url=$url;
$this->lb_color['border']="#000000";
$this->lb_color['title_bg']="#EEEEEE";
$this->lb_color['fill']="#FFFFFF";
$this->lb_color['text']="#000000";
$this->newsdir="./rdf/";
$this->agelimit=30;
}
function Add($link, $l_url){
$this->menu[$link]=$l_url;
}
function Color($object, $col){
$this->lb_color[$object]=$col;
}
function Show(){
echo "<!-- New LinkBox -->
<TABLE BORDER="0" CELLPADDING="1" CELLSPACING="0" ";
echo " BGCOLOR=" . $this->lb_color[border];
echo " WIDTH=" . $this->width;
echo ""><TR><TD>
<TABLE WIDTH="100%" BORDER="0" CELLSPACING="1" CELLPADDING="3">
<TR><TD ALIGN="center" ";
echo " BGCOLOR=" . $this->lb_color[title_bg];
echo "><B><FONT FACE="Lucida,Verdana,Helvetica,Arial">";
if($this->url!=""){
echo "<a href="$this->url">";
echo "<FONT";
echo " COLOR=" . $this->lb_color[title];
echo ">$this->title</FONT></a>";
}else{
echo "<FONT";
echo " COLOR=" . $this->lb_color[title] . ">";
echo $this->title . "</FONT>";
}
echo "</FONT></B></TD></TR><TR><TD";
echo " BGCOLOR=" . $this->lb_color[fill] . ">";
echo "<SMALL><FONT FACE="Lucida,Verdana,Helvetica,Arial">
";
if(isset($this->rdf_file)){
$fp = fopen($this->newsdir . $this->rdf_file, "r");
if (!$fp) return; //just quit on error
$pagetext = fread($fp, filesize($this->newsdir . $this->rdf_file));
fclose($fp);
// cleanup
$pagetext = ereg_replace("<?xml.*/image>","",$pagetext);
$pagetext = ereg_replace("</rdf.*","",$pagetext);
$pagetext = chop($pagetext);
$items = explode("</item>",$pagetext);
for($i=0;$i<count($items);$i++){
$link = ereg_replace(".*<link>","",$items[$i]);
$link = ereg_replace("</link>.*","",$link);
$title = ereg_replace(".*<title>","",$items[$i]);
$title = ereg_replace("</title>.*","",$title);
if ($title){
$this->menu[$title]=$link;
}
}
}
if(isset($this->menu)){
while(list($k, $v)=each($this->menu)){
switch($v){
case "-":
echo "<hr width=90%>n";
break;
case "title":
echo "$k<br>n";
break;
default:
echo "- <a href="$v">$k</a><BR>n";
break;
}
}
}
echo "</FONT></SMALL></TD></TR></TABLE></TD></TR></TABLE>
<!-- End of LinkBox -->n";
} /* end of Show() */
function RDF($rdf,$tdir="./rdf/",$tmptime=30) {
$this->newsdir=$tdir;
$this->agelimit=$tmptime;
$timeout = 10;
// convert agelimit to seconds
$this->agelimit *= 60;
$timestamp = filectime(basename($rdf));
$age = time() - $timestamp;
$this->rdf_file=ereg_replace(" ","_",$this->title) . ".rdf";
if($age > $this->agelimit) {
$url = parse_url($rdf);
if(!file_exists($this->newsdir)){
mkdir("$this->newsdir", 0700);
}
$fp = fsockopen($url['host'], "80", &$errno, &$errstr, $timeout);
if (!$fp) return; //exit
else {
$local = fopen($this->newsdir . basename($this->rdf_file), "w");
if (!$local) return; //just quit on error
fputs($fp, "GET /" . $url['path'] . " HTTP/1.0rnrn");
while(!feof($fp))
fwrite($local, fgets($fp, 128));
fclose($local);
}
}
} /* end of RDF() */
}
?>
|
|
|
Usage Example
|
<? include("linkbox.php3"); $link1 = new LinkBox("PHP Manual", "http://www.php.net/manual", 300); $link1->Add("Link 1","/whereever"); $link1->Add("Link 2","/another/place");
$link1->Add("Link 3","/one/more");
$link1->Show();
$link2 = new Linkbox("Slashdot Headlines"); $link2->RDF("http://slashdot.org/slashdot.rdf"); $link2->Show(); ?>
|
|
|
Rate This Script
|
|
|
|