Site Map

tag. The script will // not try to extract the from these files and will simply use // the document name as the title. $htmltypes=array( ".php", ".html", ".shtm", ".sthml", ".doc", ".xls", ".pdf" ); // files and/or directories to ignore $ignore=array( ".htaccess", "cgi-bin", "images", "index.htm", "index.html", "index.php", "robots.txt" ); /* ============================================== You should not need to make changes below here ============================================== */ $id=0; echo "<ul id=\"list$id\">\n"; $id++; $divs=""; if(substr($startin,strlen($startin)-1,1)=="/") $startin=substr($startin,0,strlen($startin)-1); foreach($types as $type){ if (file_exists($_SERVER['DOCUMENT_ROOT']."$startin/index$type")){ $index=$_SERVER['DOCUMENT_ROOT']."$startin"."/index$type"; break; } } $types=join($types,"|"); $types="($types)"; if(!is_array($htmltypes)) $htmltypes=array(); if(count($htmltypes)==0) $htmltypes=$types; if(!$imgpath) $imgpath="."; echo "<li><img src=\"$imgpath/server.gif\" align=\"middle\" alt=\"\" /><strong><a href=\"$startin/\">".getTitle($index)."</a></strong>\n"; showlist($_SERVER['DOCUMENT_ROOT']."$startin"); echo "</li></ul>\n"; if (is_array($divs)){ $divs="'".join($divs,"','")."'"; echo "<script type=\"text/javascript\">\n"; echo "//<![CDATA[\n"; echo "d=Array($divs);\n"; echo "for (i=0;i<d.length;i++){\n"; echo "\ttoggle('list'+d[i],'img'+d[i]);\n"; echo "}\n"; echo "//]]>\n"; echo "</script>\n"; } function showlist($path){ global $ignore, $id, $divs, $imgpath, $types; $dirs=array(); $files=array(); if(is_dir($path)){ if ($dir = @opendir($path)) { while (($file = readdir($dir)) !== false) { if ($file!="." && $file!=".." && !in_array($file,$ignore)){ if (is_dir("$path/$file")){ if (file_exists("$path/$file/index.php")) $dirs[$file]=getTitle("$path/$file/index.php"); elseif (file_exists("$path/$file/index.html")) $dirs[$file]=getTitle("$path/$file/index.html"); elseif (file_exists("$path/$file/index.htm")) $dirs[$file]=getTitle("$path/$file/index.htm"); else $dirs[$file]=$file; } else { if (ereg("$types$", $file)){ $files[$file]=getTitle("$path/$file"); if (strlen($files[$file])==0) $files[$file]=$file; } } } } closedir($dir); } natcasesort($dirs); $url=str_replace($_SERVER['DOCUMENT_ROOT'],"",$path); $n=substr_count("$url/$","/"); $indent=str_pad("",$n-1,"\t"); echo "$indent<ul id=\"list$id\">\n"; if ($n>1) $divs[]="$id"; $imgsrc="minus"; foreach($dirs as $d=>$t){ $id++; echo "$indent\t<li><a href=\"javascript:toggle('list$id','img$id')\"><img src=\"$imgpath/$imgsrc.gif\" id=\"img$id\" align=\"middle\" border=\"0\" alt=\"\" /></a>"; echo "<img src=\"$imgpath/folder.gif\" alt=\"\" align=\"middle\" />"; echo " <strong><a href=\"$url/$d/\">$t</a></strong>\n"; showlist("$path/$d"); echo "$indent\t</li>\n"; } natcasesort($files); $id++; foreach($files as $f=>$t){ echo "$indent\t<li><img style=\"padding-left:20px;\" src=\"$imgpath/html.gif\" alt=\"\" border=\"0\" /> <a href=\"$url/$f\">$t</a></li>\n"; } echo "$indent</ul>\n"; } } function getTitle($file){ global $htmltypes; $title=""; $p=pathinfo($file); if(!in_array(strtolower($p['extension']),$htmltypes)){ $f=file_get_contents($file); if(preg_match("'<title>(.+)'i", $f, $matches)){ $title=$matches[1]; } } $title=$title?$title:basename($file); return htmlentities(trim(strip_tags($title))); } ?>