isDot()) { $item_path = $item->getPathname(); $extension = $item->getExtension(); switch ($item->getType()) { case "file": scan_file($item_path, $extension); break; case "dir": if (!in_array($item_path, $exclude)) scan_dir($item_path); break; } } } } /** * Function: scan_file * Scans a file in search of documentation. */ function scan_file($pathname, $extension) { if ($extension != "php") return; $file = @file_get_contents($pathname); if ($file === false) return; scan_docs($pathname, $file); } /** * Function: make_place * Makes a string detailing the file where the documentation was found. */ function make_place($pathname) { return str_replace( array(MAIN_DIR.DIR, DIR), array("", "/"), $pathname ); } /** * Function: scan_docs * Scans text for documentation. */ function scan_docs($pathname, $file) { global $docs; if ( preg_match_all( '/\n +\/\*\*\n.+?\n +\*\//s', $file, $matches, PREG_SET_ORDER ) ) { # Add a header for this file. $docs.= "==============================================\n". make_place($pathname)."\n". "==============================================\n\n"; foreach ($matches as $match) { $doc = $match[0]; # Underline the title. $doc = preg_replace_callback('/\n +\/\*\*\n +\* +(.+)\n/', function ($matches) { return $matches[1]."\n".str_repeat( "-", strlen($matches[1]) )."\n"; }, $doc); # Remove leading asterisks. $doc = preg_replace('/\n +\* ?\/?/', "\n", $doc); $docs.= $doc."\n\n"; } } } /** * Function: create_file * Writes the documentation to disk and echoes it. */ function create_file() { global $docs; @file_put_contents( MAIN_DIR.DIR."tools".DIR."api_docs.txt", $docs ); echo fix($docs); } #--------------------------------------------- # Output Starts #--------------------------------------------- ?>