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

<ul>
<li>Existing pages:</li>
<?php

$dirname = "../";

if ($folder = opendir($dirname)) {

	$filesArray = array();
	while (false !== ($file = readdir($folder))) {
		if (strstr($file, '.php')) {
			$filesArray[] = $file;
		}
	}

	$filesArray = array_diff($filesArray, array("contact.php", "error404.php"));

	natcasesort($filesArray);
	foreach ($filesArray as $file) {
		$anchor = str_replace(".php", "", $file);

		if (($cms_dir) && ($file != 'index.php')) {
			$pagename = $file;
		} else {
			$pagename = str_replace(".php", "", $file);
			$pagename = str_replace("index", "", $pagename);
		}
		echo '<li><a href="'. LOCATION . $cms_dir . $pagename . '" title="' . $anchor . '">' . $anchor . '</a>';

		if (COMMENTS && ($pagename != '')) {
			echo ' <span>| <a href="'. LOCATION . 'cms/admin/index.php?page=' . $pagename . '" title="Edit page">edit page</a> | <a href="'. LOCATION . 'cms/admin/comments.php?page=' . $pagename . '" title="Edit comments">edit comments</a></span>';
		} else { // index - omit comments edit link
			echo ' <span>| <a href="'. LOCATION . 'cms/admin/index.php?page=' . $anchor . '" title="Edit page">edit page</a></span>';
		}
		echo "</li>\n";
	}

closedir($folder);

}

?>
</ul>
