<?php 

$dh = opendir($rooturl);
echo '<ul class="menu">';
echo '<li class="menu"><a href="'.$siteurl.'index.php">Home</a></li>'; // hard code the index.php page to top of menu
while (false !== ($file = readdir($dh)) ) 
	{
	if (strpos($file, '.php',1)) // only include files with .php extension
		{ 
		$name = substr($file,0,strrpos($file,'.')); // strip the .php extension
		$menu_status_file = $menu_status.$name.".txt";
		$visibility = @file_get_contents($menu_status_file);
		if ( $visibility == 'hidden' ) 
			{ 
			$hidefile = $file; 
			}
			else
			{
			$hidefile = ''; 
			}	
		if ( $file!='.' && $file!='..' && $file!='index.php' && $file!='page_preview.php' && $file!=$hidefile && $file!='_site_admin.php') 
			{
 			$file_array[] = $file;  
			} 
		}
	}

// Sort files by modified time, earliest to latest
array_multisort( 
array_map( 'filemtime', $file_array ),
SORT_NUMERIC,
SORT_ASC, // Use SORT_ASC in place of SORT_DESC for earliest to latest
$file_array
);

if ( $menu_sort == '1' ) 
	{ 
	sort ($file_array); // sort pages a-z
	}

foreach ($file_array as $value) 
	{ 
	// dynamic auto title script
	$title = substr($value,0,strrpos($value,'.')); // strip the .php extension
	$title1 = str_replace('_and_', ' & ', $title); // convert 'and' to '&'
 	$title2 = str_replace('_', ' ', strtolower($title1)); // convert name to lowercase and replace underscores... 
	$page_title = ucwords($title2); // capitalize first letter 

	$alias = @file_get_contents($menu_alias.$title.".txt");
	if ( $alias != '' )
		{
		$page_title = $alias;
		}
		else
		{
		$page_title = $page_title;
		}

	echo '<li class="menu"><a href="'.$siteurl.$value.'">'.$page_title.'</a></li>'; 
	}
echo '</ul>';
closedir($dh);
?>

<br style="clear:left;">