- Home
// web root
$web_root = '/var/www/www-co';
// current directory
$cur_dir = getcwd();
$dirs = explode ("/",$cur_dir);
// establish the directories we want to follow from web_root
$dirs = array_splice ($dirs, 4);
if ($cur_dir == $web_root) {
$next_dir = '';
}
else {
$next_dir = $dirs[0];
}
$level = count($dirs);
// start at web_root
chdir($web_root);
$cur_dir = getcwd();
recurs ($next_dir, $dirs, 0, '/', $level );
function recurs ( $next_dir, $dirs, $level, $absolute_dir, $max_level )
{
// function to recurs from web_root down through $dirs looking for
// menu.txt in each directory and creating a HTML menu as we go
// read menu.txt
if (is_file( 'menu.txt' ))
{
$lines= file( 'menu.txt' );
// print menu items
// indent
if ($level > 0) echo "
\n";
foreach ($lines as $line) {
$bits = explode ("|", $line);
$menu_dir = trim($bits[1]);
$menu_title = trim($bits[0]);
// print menu item
if ($absolute_dir == '/') {
echo "- $menu_title\n";
}
else {
echo "
- $menu_title\n";
}
if ( $next_dir == $menu_dir ) {
if (is_dir ( $next_dir )) {
// if we find next_dir then call ourself
chdir ($next_dir);
if ($absolute_dir == '/') {
$new_absolute_dir = '/' . $next_dir;
}
else {
$new_absolute_dir = $absolute_dir . '/' . $next_dir;
}
if ( $level+1 < $max_level ) {
$next_dir = $dirs[$level+1];
}
else {
$next_dir='';
}
recurs ( $next_dir, $dirs, ($level+1), $new_absolute_dir, $max_level);
}
}
}
echo "
\n";
return;
}
else {
return;
}
}
?>
|
|
|