<?php
/**
 * la.plume Micro CMS
 * ==================
 * COPYRIGHT Patrick Taylor http://www.mini-print.com/
 */
?>
	<div id="menu">

<ul>
<?php

if (!empty($_SERVER['PHP_SELF'])) {
	$thisPage = htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'utf-8');
} else if (!empty($_SERVER['SCRIPT_FILENAME'])) {
	$thisPage = htmlspecialchars($_SERVER['SCRIPT_FILENAME'], ENT_QUOTES, 'utf-8');
} else if (!empty($_SERVER['SCRIPT_NAME'])) {
	$thisPage = htmlspecialchars($_SERVER['SCRIPT_NAME'], ENT_QUOTES, 'utf-8');
} else {
	echo "\r\n<li>Page not recognised</li>\r\n";
}

$cms_dir = FALSE;
if (stristr($thisPage, 'cms/')) {
	$cms_dir = TRUE;
}

$thisPage = str_replace("/laplume", "", $thisPage);
$thisPage = str_replace("/cms/", "", $thisPage);
$thisPage = str_replace(".php", "", $thisPage);

if ($thisPage == "index") {
	echo '<li><strong>' . HOME_LINK . '</strong></li>';
	echo "\r\n";
} else {
	if ($cms_dir) {
		echo '<li><a href="' . LOCATION . 'cms/" title="' . HOME_LINK . '">' . HOME_LINK . '</a></li>';
	} else {
		echo '<li><a href="' . LOCATION . '" title="' . HOME_LINK . '">' . HOME_LINK . '</a></li>';
	}
	echo "\r\n";
}

if (strstr($thisPage, "rror404")) {
	$inmenu = "./cms/inc/inmenu.txt";
} else {
	$inmenu = 'inc/inmenu.txt';
}

if (file_exists($inmenu)) {
	$inmenuArray = array();
	$inmenuArray = file($inmenu);
	natcasesort($inmenuArray);

	foreach ($inmenuArray as $file) {
		if (strlen($file) < 2) {
			continue;
		}

		$file = trim($file);

		if ($cms_dir) {
			$link = 'cms/' . $file . '.php';
		} else {
			$link = $file;
		}

		$link = stripslashes($link);
		$anchor = $file;
		$anchor = str_replace(array("-", "_"), " ", $anchor);
		$anchor = stripslashes(ucwords($anchor));
		if (($thisPage == $link) || ($thisPage == $file)) {
			echo '<li><strong>' . $anchor . '</strong></li>';
			echo "\r\n";
		} else {
			echo '<li><a href="' . LOCATION . $link . '" title="' . $anchor . '">' . $anchor . '</a></li>';
			echo "\r\n";
		}
	}
} else {
	echo '<li><strong>Menu Not Found</strong></li>';
	echo "\r\n";
}

if ($thisPage == "contact") {
	echo '<li><strong>Contact</strong></li>';
	echo "\r\n";
} else if ((file_exists('contact.php')) || ($error404 == TRUE)) {
	if ($cms_dir) {
		echo '<li><a href="' . LOCATION . 'cms/contact.php" title="Contact">Contact</a></li>';
	} else {
		echo '<li><a href="' . LOCATION . 'contact" title="Contact">Contact</a></li>';
	}
	echo "\r\n";
}

if ($admin == TRUE) {
	$source = str_replace(".txt", "", $source);
	echo '<li><a href="' . LOCATION . 'cms/admin/index.php?page=' . $source . '">Edit Page</a></li>';
	echo "\r\n";
}

?>
</ul>

	</div>
