somenamesomedescription
* with this, you type your links as:
* category|name|url|description
* and save it as something like links.txt
* This php script will then produce a hashtable
* from that file, and, unless you choose to change it,
* a page whose main body is:
* a line of anchor tags, each pointing to a category of links
* groups of sorted links, each with an category
* with each link in a category an
*
* example lines from links.txt (note the missing description field in 3):
* help|Linux Documentation Project|http://www.tldp.org/|big collection of docs
* localhelp|documents in /usr/share/doc|usr/share/doc|system docs
* images|photos by foo|~foo/photos/|
* images|drawings by bar|~bar/jpg/index.html|barzart
*
* Now, just because a certain MonopolySoft hates the GPL --
* Released under the GNU GPL: you are free to copy, modify, distribute
* this source. 2002 Terry Vessels
*
* Much thanks to the person going by the chatalias of "f3ew" for his
* suggestion to learn about hashtables. It made a big difference in both
* the simplicity and the speed of this script.
*/
/*
* VARs
* edit to suit
*/
$debug="off";
$_self=__FILE__;
$_self=basename($_self);
$h_name=$HTTP_HOST;
$linkfile="links.txt";
/* html vars */
$doctype ="\n";
$head ="\n";
$head.=" \n";
$head.=" \n";
$head.=" The hostname is POS, which stands for Piles Of Stuff.\n";
$head.= " \n";
/*
* END VARs
*/
/*
* FUNCTIONS
*/
/* function fortune() and function google() were left in for the fun of it */
function fortune()
{
$fort =" \n";
$fort.=" \n";
$fort.=" \n";
$fort.=" \n";
$fort.=" ";
$fort.=shell_exec("/usr/games/fortune -s");
$fort.=" \n";
$fort.=" | \n";
$fort.="
\n";
$fort.="
\n";
$fort.=" \n";
return $fort;
}
function google()
{
$goog =" \n";
$goog.=" \n";
$goog.=" \n";
return $goog;
}
function catlink($linkfile)
{
global $debug, $linkhash;
$links=file($linkfile);
sort($links);
reset($links);
for ($line=0; $line < count($links); $line++) {
// take extra whitespace off the ends
$current=trim($links[$line]);
// preserve any \n included in links.txt
// note: may have to do htmlentities($current)
// if you put some html no-no's in the file
$current=stripcslashes($current);
// category, name, url, description
list($l_c,$l_n,$l_u,$l_d)=explode("|",$current);
$linkhash[$l_c][]=array(
"name" => $l_n,
"url" => $l_u,
"desc" => $l_d
);
}
}
/*
* END FUNCTIONS
*/
/*
* MAIN
*/
$fort=fortune();
$google=google();
catlink($linkfile);
echo $doctype;
echo $head;
echo " \n";
echo "
\n";
echo " \n";
echo " \n";
echo $fort;
echo " \n";
echo " \n";
echo $google;
echo " \n";
echo "
\n";
/* produce a line of anchor tags */
echo " \n";
reset($linkhash);
while (list($key,) = each($linkhash)){
echo " $key \n";
}
echo " \n";
echo "
\n";
echo "
\n";
/* main body of links */
foreach ($linkhash as $cat => $ar){
echo " $cat [top]
\n";
echo " \n";
foreach ($ar as $num => $val){
$_n=$val["name"];
$_u=$val["url"];
$_d=$val["desc"];
echo " - \n";
echo " \n $_n\n";
if ($_d != ""){
echo " $_d \n";
}
echo "
\n";
}
echo "
\n";
echo "
\n";
echo "
\n";
}
echo " \n";
echo "\n";
/*
* END MAIN
*/
?>