Home page

<?php
	$sitemap = array();
	$sitemap[""]["#"]                  = "Home page";
	$sitemap["about"]["#"]             = "About us";
	$sitemap["projects"]["#"]          = "Projects";
	$sitemap["projects"]["aqua"]["#"]  =     "AQUA - a ReSTful DB Interface";
	$sitemap["projects"]["jsoox"]["#"] =     "jsoox - JavaScript Object-Oriented eXtension";
	$sitemap["contact"]["#"]           = "Contact";
	$sitemap["contact"]["map"]["#"]    =     "Location";
	
	function createNavigation ($pSitemap, $pLinkURI = "/") {
		$path = "/";
		if (isset($_GET["path"])) {
			$path = rtrim($_GET["path"], "/") . "/";
		}
		$subPages = "";
		foreach ($pSitemap as $k => $v) {
			if ($k != "#") {
				$subPages .= createNavigation($v, rtrim($pLinkURI . $k, "/") . "/");
			}
		}
		if (isset($pSitemap["#"])) {
			$title = $pSitemap["#"];
			if ($pLinkURI == $path) {
				$title = '<strong>' . $title . '</strong>';
			}
			else {
				$active = $pLinkURI != "/" && strpos($path, $pLinkURI) === 0
					? ' class="active"'
					: '';
				$title = '<a' . $active . ' href="?path=' . $pLinkURI . '">' . $title . '</a>';
			}
			$subPages = $subPages ? "<ul>" . $subPages . "</ul>" : "";
			return "<li>" . $title . $subPages . "</li>";
		}
		else {
			return $subPages;
		}
	}
	function getTitle ($pSitemap) {
		$path = "";
		if (isset($_GET["path"])) {
			$path = trim($_GET["path"], "/");
		}
		$container = $pSitemap;
		foreach (explode("/", $path) as $v) {
			$container = $container[$v];
		}
		return $container["#"];
	}
?>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<meta http-equiv="content-type" content="text/html; charset=utf-8" />
		<style type="text/css">
			* { background: #ddf; }
			a, a:link, a:visited, a:hover, a:active, a:focus { text-decoration: none; color: #00b; }
			a.active { font-weight: bold; color: #006; }
			pre { border: 2px inset #ddf; margin-top: 20px; font-family: "Lucida Console", "Courier New", monospace; font-size: 7pt; }
		</style>
		<title><?php echo getTitle($sitemap); ?></title>
	</head>
	<body>
		<h1><?php echo getTitle($sitemap); ?></h1>
		<ul><?php echo createNavigation($sitemap); ?></ul>
		<pre><?php echo htmlspecialchars(file_get_contents(__FILE__)); ?></pre>
	</body>
</html>