home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / PHP / menusfromdirs.php3.txt < prev    next >
Encoding:
Text File  |  2002-05-06  |  2.5 KB  |  65 lines

  1. Menus from Directories 
  2.  
  3. This is a dynamically generated menu system, that reads from directories .HTML and .php3 files, with a <TITLE> tag on a seperate line. This is a hack for what I needed, but I though it may be useful, you can see it in action at www.action-web.net 
  4.  
  5.  
  6. <?php         
  7.     function echo_link($link, $text, $directory_) { 
  8.                 echo  "<FONT size=2>   <A "; 
  9.                 echo  "HREF=\"$directory_$link\" target=\"main\">$text</A></FONT><BR>\r"; 
  10.         } 
  11.  
  12. /* Call this function from where ever you want generate a menu. 
  13. $dir_name is the full local server directory, and $directory is the 
  14. web based directory. here is an example. 
  15.  
  16. build_menu("/usr/htdocs/mydocs/","/mydocs/") 
  17.  
  18. */ 
  19.  
  20.     function build_menu($dir_name, $directory) { 
  21.  
  22.         $d = dir($dir_name); 
  23.     chdir($dir_name); 
  24.         while($file=$d->read()) { 
  25.  
  26.          /* we don't want this file or any directories, but we do want all 
  27.         .html and .phtml files */ 
  28.  
  29.         if ((is_file($file)) && (eregi( "html$", $file) or eregi( "php3$", $file))) { 
  30.          //if (is_file($file)) { 
  31.          //if (eregi("html$", $file)) { 
  32.                         $fp = fopen( "$file",  "r"); 
  33.                         $build =  ""; 
  34.                         $flag = 0; 
  35.                         for ($i = 0; !feof($fp); $i++) { 
  36.                                 $line = fgets($fp, 1024); 
  37.  
  38.                                  /* The <TITLE> tag MUST be opened at the 
  39.                                 beginning of a new line */ 
  40.  
  41.                                 if (ereg( "^<TITLE>", $line)) 
  42.                                         $flag = 1; 
  43.                                 if ($flag == 1) 
  44.                                         $build = $build.$line; 
  45.                                 if (ereg( "</TITLE>", $line)) 
  46.                                         $flag = 0; 
  47.                         } 
  48.                         if ($build >  "") { 
  49.                                 $build = ereg_replace( "<TITLE>",  "", $build); 
  50.                                 $build = ereg_replace( "</TITLE>",  "", $build); 
  51.                                 $build = trim($build); 
  52.                                 echo_link($file, $build, $directory); 
  53.                         } 
  54.                 } 
  55.     } 
  56.  
  57.          // not sure if this is needed or not, but it does not hurt anything,  
  58.          // for my anyway 
  59.     chdir( "/../"); 
  60.  
  61.          // and finally, close the directory 
  62.         $d->close(); 
  63.     } 
  64. ?>
  65.