This is the code that generates the menu you can see over on the left.
Update: Edd, who uses a slightly modified version of this site, wanted an external link in his nav menu. This required a slight mod to the code, since external pages can't be checked for last-modified times. I also took the opportunity to mark them with their own icon.
<?php // The menu bar is built from the array below. Since the HTML generation // code is recursive, depth is unlimited. Syntax should be fairly obvious // from the current array. // // TODO: either get the heading from the page or set it there -- having it // in two different places doesn't make sense, although an override might. $pageArray = array( "Home" => "/index.php", "Bio of a random hacker" => "/bio.php", "Contact details" => "/contact.php", "Licensing" => "/licensing.php", "Webcomics" => "/comics.php", "Other people" => "/people.php", "Code" => array( "Python random name generator" => "/code/cfnamegencode.php", "PHP syntax highlighter" => "/code/syntaxhlcode.php", "PHP menu generator" => "/code/phpmenucode.php", "xmms sleep script" => "/code/xmmssleepcode.php", "irssi channel beeping script" => "/code/irssichanbeep.php", "Python logfile reader class" => "/code/logfile.php", "Home directory analysis script" => "/code/homediranalysis.php", "Remote execution script" => "/code/remoteexec.php", "Dialup control panel" => "/code/dialupcp.php", "Hamming number calculator" => "/code/hammingnums.php", "PHP python datatype parser" => "/code/pythontypes.php", "Python TOC generator" => "/code/maketoc.php", ), "Shiny stuff" => array( "Campus proxy squid hack" => "/shiny/proxyserver.php", "Phone stuff" => "/shiny/phone.php", ), "Writings" => array( "How to send an electronic notice" => "/writings/notice-netiquette.php", "How to survive Computer Methods pracs" => "/writings/howtosurvivecm.php", "How not to cheat" => "/writings/hownottocheat.php", "Linux for computer scientists" => "/writings/linuxforcompsci.php", "Teach yourself programming" => "/writings/learnprogramming.php", ), ); function iecho($indent, $text) { // Indents the HTML for the menu -- purely making the code look // pretty, no effect on rendering. for ($i=0; $i<$indent; $i++) { echo "\t"; } echo $text; } function isNew($url) { $url = "base" . $url; if (filemtime($url)) { if (time() - filemtime($url) < 604800) { // 604800 secs in a week return true; } } return false; } function isAbsolute($url) { if (strpos($url, "://") != false) { return true; } else { return false; } } function navGen($pageArray) { // Takes the array given in $pageArray and generates the navigation // bar from it. // // TODO: Finish the version that handles authentication, etc. and put // that here. static $indent = 1; $currentFile = get_included_files(); $currentFile = basename($currentFile[0]); iecho($indent, "<ul>\n"); $indent += 1; foreach ($pageArray as $name => $url) { if (is_array($url)) { iecho($indent, "<li>$name\n"); navGen($url); iecho($indent, "</li>\n"); } else { // Is this the current page? if ($url == $currentFile) { $class = " class=\"navcurrent\""; } else { $class = ""; } // Is this page external? if (isAbsolute($url)) { // If so, mark it as such. $icon = "<img src=\"common/external.png\" alt=\"external\" />"; } else { // If it's local, we can check for newness. if (isNew($url)) { $icon = "<img src=\"common/new.png\" alt=\"new\" />"; } else { $icon = ""; } } iecho($indent, "<li>".$icon. "<a$class href=\"$url\">$name</a></li>\n"); } } $indent -= 1; iecho($indent, "</ul>\n"); } ?> <div id="navbar"> <h1>jerith.za.net</h1> <?php navGen($pageArray); ?> </div>