+++ /dev/null
-<?php\r
-/**\r
- * File and input handling routines\r
- * \r
- * This class parses command-line options, and works with files to\r
- * generate lists of files to parse based on the ignore/include options\r
- * \r
- * phpDocumentor :: automatic documentation generator\r
- * \r
- * PHP versions 4 and 5\r
- *\r
- * Copyright (c) 2000-2006 Joshua Eichorn, Gregory Beaver\r
- * \r
- * LICENSE:\r
- * \r
- * This library is free software; you can redistribute it\r
- * and/or modify it under the terms of the GNU Lesser General\r
- * Public License as published by the Free Software Foundation;\r
- * either version 2.1 of the License, or (at your option) any\r
- * later version.\r
- * \r
- * This library is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
- * Lesser General Public License for more details.\r
- * \r
- * You should have received a copy of the GNU Lesser General Public\r
- * License along with this library; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
- *\r
- * @package phpDocumentor\r
- * @author Joshua Eichorn <jeichorn@phpdoc.org>\r
- * @author Gregory Beaver <cellog@php.net>\r
- * @copyright 2000-2006 Joshua Eichorn, Gregory Beaver\r
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL\r
- * @version CVS: $Id: Io.inc,v 1.18 2007/12/08 01:31:50 ashnazg Exp $\r
- * @filesource\r
- * @link http://www.phpdoc.org\r
- * @link http://pear.php.net/PhpDocumentor\r
- * @since 0.1\r
- */\r
-/**\r
- * Class to handle file and user io opperations\r
- *\r
- * @author Joshua Eichorn <jeichorn@phpdoc.org>\r
- * @author Gregory Beaver <cellog@php.net>\r
- * @version $Id: Io.inc,v 1.18 2007/12/08 01:31:50 ashnazg Exp $\r
- * @package phpDocumentor\r
- */\r
-class Io \r
-{\r
- \r
- /**\r
- * Holds all the options that are avaible to the cmd line interface\r
- * and to the different web interfaces\r
- */\r
- var $phpDocOptions;\r
- /**\r
- * Format: array(array(regexp-ready string to search for whole path,\r
- * regexp-ready string to search for basename of ignore strings),...)\r
- * @var false|array\r
- */\r
- var $ignore;\r
- /**\r
- * A specific array of values that boolean-based arguments can understand,\r
- * aided by the {@link decideOnOrOff()} helper method.\r
- * \r
- * Use lowercase letters always, to simplify string comparisons\r
- * @var array \r
- */\r
- var $valid_booleans = array\r
- (\r
- '', ' ', 'on', 'y', 'yes', 'true', '1', \r
- 'off', 'n', 'no', 'false', '0'\r
-\r
- );\r
- \r
- /**\r
- * creates an array $this->phpDocOptions and sets program options in it.\r
- * Array is in the format of:\r
- * <pre>\r
- * [filename][tag][] = "f";\r
- * [filename][tag][] = "-file";\r
- * [filename][desc] "name of file to parse"\r
- * </pre>\r
- */\r
- function Io()\r
- {\r
- $this->phpDocOptions['filename']['tag'] = array( "-f", "--filename");\r
- $this->phpDocOptions['filename']['desc'] = "name of file(s) to parse ',' file1,file2. Can contain complete path and * ? wildcards";\r
- $this->phpDocOptions['filename']['type'] = "path";\r
-\r
- $this->phpDocOptions['directory']['tag'] = array( "-d", "--directory");\r
- $this->phpDocOptions['directory']['desc'] = "name of a directory(s) to parse directory1,directory2";\r
- $this->phpDocOptions['directory']['type'] = "path";\r
-\r
- $this->phpDocOptions['examplesdir']['tag'] = array( "-ed", "--examplesdir");\r
- $this->phpDocOptions['examplesdir']['desc'] = "full path of the directory to look for example files from @example tags";\r
- $this->phpDocOptions['examplesdir']['type'] = "path";\r
-\r
- $this->phpDocOptions['templatebase']['tag'] = array( "-tb", "--templatebase");\r
- $this->phpDocOptions['templatebase']['desc'] = "base location of all templates for this parse.";\r
- $this->phpDocOptions['templatebase']['type'] = "path";\r
-\r
- $this->phpDocOptions['target']['tag'] = array("-t", "--target");\r
- $this->phpDocOptions['target']['desc'] = "path where to save the generated files";\r
- $this->phpDocOptions['target']['type'] = "path";\r
- \r
- $this->phpDocOptions['ignore']['tag'] = array("-i", "--ignore");\r
- $this->phpDocOptions['ignore']['desc'] = "file(s) that will be ignored, multiple separated by ','. Wildcards * and ? are ok";\r
- $this->phpDocOptions['ignore']['type'] = "path";\r
-\r
- $this->phpDocOptions['ignoresymlinks']['tag'] = array("-is", "--ignoresymlinks");\r
- $this->phpDocOptions['ignoresymlinks']['desc'] = "ignore symlinks to other files or directories, default is off";\r
- $this->phpDocOptions['ignoresymlinks']['type'] = "set";\r
- $this->phpDocOptions['ignoresymlinks']['validvalues'] = $this->valid_booleans;\r
-\r
- $this->phpDocOptions['ignoretags']['tag'] = array("-it", "--ignore-tags");\r
- $this->phpDocOptions['ignoretags']['desc'] = "tags to ignore for this parse. @package, @subpackage, @access and @ignore may not be ignored.";\r
- $this->phpDocOptions['ignoretags']['type'] = "value";\r
-\r
- $this->phpDocOptions['hidden']['tag'] = array("-dh", "--hidden");\r
- $this->phpDocOptions['hidden']['desc'] = "set equal to on (-dh on) to descend into hidden directories (directories starting with '.'), default is off";\r
- $this->phpDocOptions['hidden']['type'] = "set";\r
- $this->phpDocOptions['hidden']['validvalues'] = $this->valid_booleans;\r
-\r
- $this->phpDocOptions['quiet']['tag'] = array("-q", "--quiet");\r
- $this->phpDocOptions['quiet']['desc'] = "do not display parsing/conversion messages. Useful for cron jobs on/off default off";\r
- $this->phpDocOptions['quiet']['type'] = "set";\r
- $this->phpDocOptions['quiet']['validvalues'] = $this->valid_booleans;\r
-\r
- $this->phpDocOptions['undocumentedelements']['tag'] = array("-ue", "--undocumentedelements");\r
- $this->phpDocOptions['undocumentedelements']['desc'] = "Control whether or not warnings will be shown for undocumented elements. Useful for identifying classes and methods that haven't yet been documented on/off default off";\r
- $this->phpDocOptions['undocumentedelements']['type'] = "set";\r
- $this->phpDocOptions['undocumentedelements']['validvalues'] = $this->valid_booleans;\r
-\r
- $this->phpDocOptions['title']['tag'] = array("-ti","--title");\r
- $this->phpDocOptions['title']['desc'] = "title of generated documentation, default is 'Generated Documentation'";\r
- $this->phpDocOptions['title']['type'] = "value";\r
-\r
- $this->phpDocOptions['help']['tag'] = array("-h", "--help");\r
- $this->phpDocOptions['help']['desc'] = " show this help message";\r
-\r
- $this->phpDocOptions['useconfig']['tag'] = array("-c","--useconfig");\r
- $this->phpDocOptions['useconfig']['desc'] = "Use a Config file in the users/ subdirectory for all command-line options";\r
- $this->phpDocOptions['useconfig']['type'] = "value";\r
-\r
- $this->phpDocOptions['parseprivate']['tag'] = array("-pp","--parseprivate");\r
- $this->phpDocOptions['parseprivate']['desc'] = "parse @internal and elements marked private with @access. Use on/off, default off";\r
- $this->phpDocOptions['parseprivate']['type'] = "set";\r
- $this->phpDocOptions['parseprivate']['validvalues'] = array('on', 'off');\r
-\r
- $this->phpDocOptions['packageoutput']['tag'] = array("-po","--packageoutput");\r
- $this->phpDocOptions['packageoutput']['desc'] = "output documentation only for selected packages. Use a comma-delimited list";\r
- $this->phpDocOptions['packageoutput']['type'] = "value";\r
-\r
- $this->phpDocOptions['defaultpackagename']['tag'] = array("-dn","--defaultpackagename");\r
- $this->phpDocOptions['defaultpackagename']['desc'] = "name to use for the default package. If not specified, uses 'default'";\r
- $this->phpDocOptions['defaultpackagename']['type'] = "value";\r
-\r
- $this->phpDocOptions['defaultcategoryname']['tag'] = array("-dc","--defaultcategoryname");\r
- $this->phpDocOptions['defaultcategoryname']['desc'] = "name to use for the default category. If not specified, uses 'default'";\r
- $this->phpDocOptions['defaultcategoryname']['type'] = "value";\r
-\r
- $this->phpDocOptions['output']['tag'] = array("-o","--output");\r
- $this->phpDocOptions['output']['desc'] = "output information to use separated by ','. Format: output:converter:templatedir like \"HTML:frames:phpedit\"";\r
- $this->phpDocOptions['output']['type'] = "value";\r
-\r
- $this->phpDocOptions['converterparams']['tag'] = array("-cp","--converterparams");\r
- $this->phpDocOptions['converterparams']['desc'] = "dynamic parameters for a converter, separate values with commas";\r
- $this->phpDocOptions['converterparams']['type'] = "value";\r
-\r
- $this->phpDocOptions['customtags']['tag'] = array("-ct","--customtags");\r
- $this->phpDocOptions['customtags']['desc'] = "custom tags, will be recognized and put in tags[] instead of unknowntags[]";\r
- $this->phpDocOptions['customtags']['type'] = "value";\r
-\r
- $this->phpDocOptions['sourcecode']['tag'] = array("-s","--sourcecode");\r
- $this->phpDocOptions['sourcecode']['desc'] = "generate highlighted sourcecode for every parsed file (PHP 4.3.0+ only) on/off default off";\r
- $this->phpDocOptions['sourcecode']['type'] = "set";\r
- $this->phpDocOptions['sourcecode']['validvalues'] = array('on', 'off');\r
-\r
- $this->phpDocOptions['javadocdesc']['tag'] = array("-j","--javadocdesc");\r
- $this->phpDocOptions['javadocdesc']['desc'] = "JavaDoc-compliant description parsing. Use on/off, default off (more flexibility)";\r
- $this->phpDocOptions['javadocdesc']['type'] = "set";\r
- $this->phpDocOptions['javadocdesc']['validvalues'] = array('on', 'off');\r
-\r
- $this->phpDocOptions['pear']['tag'] = array("-p","--pear");\r
- $this->phpDocOptions['pear']['desc'] = "Parse a PEAR-style repository (package is directory, _members are @access private) on/off default off";\r
- $this->phpDocOptions['pear']['type'] = "set";\r
- $this->phpDocOptions['pear']['validvalues'] = array('on', 'off');\r
-\r
- $this->phpDocOptions['readmeinstallchangelog']['tag'] = array("-ric","--readmeinstallchangelog");\r
- $this->phpDocOptions['readmeinstallchangelog']['desc'] = "Specify custom filenames to parse like README, INSTALL or CHANGELOG files";\r
- $this->phpDocOptions['readmeinstallchangelog']['type'] = "value";\r
-\r
- $this->phpDocOptions['general']['message'] ="You can have multiple directories and multiple files, as well as a combination of both options";\r
- }\r
-\r
- \r
- /**\r
- * create the help message for display on the command-line\r
- * @return string a string containing a help message\r
- */\r
- function displayHelpMsg()\r
- {\r
- unset($ret);\r
- $ret = "\n";\r
- foreach($this->phpDocOptions as $data)\r
- {\r
- unset($tag);\r
- $tag = "";\r
- if (isset($data['tag']))\r
- {\r
- if (is_array($data['tag'])) {\r
- foreach($data['tag'] as $param) {\r
- $tag .= "$param ";\r
- }\r
- }\r
- $taglen = 34;\r
- $outputwidth = 79;\r
- $tagspace = str_repeat(" ",$taglen);\r
- $tmp = " ".trim($tag).$tagspace;\r
- $tmp = substr($tmp,0,$taglen);\r
- $d = wordwrap(ltrim($data['desc']),($outputwidth-$taglen));\r
- $dt = explode("\n",$d);\r
- $dt[0] = $tmp .$dt[0];\r
- for($i=1;$i<count($dt);$i++)\r
- {\r
- $dt[$i] = $tagspace.$dt[$i];\r
- }\r
- $ret .= implode("\n",$dt)."\n\n";\r
- \r
- }\r
- }\r
- $ret .= "\n".wordwrap($data['message'],$outputwidth)."\n";\r
- return $ret; \r
- }\r
- \r
- /**\r
- * calls {@link file_exists()} for each value in include_path,\r
- * then calls {@link is_readable()} when it finds the file\r
- * @param string\r
- * @return boolean\r
- */\r
- function isIncludeable($filename)\r
- {\r
- $test = realpath($filename);\r
- if ($test && is_readable($test)) {\r
- return true; // for absolute paths\r
- }\r
- $ip = get_include_path();\r
- if (PHPDOCUMENTOR_WINDOWS)\r
- {\r
- $ip = explode(';', $ip);\r
- } else {\r
- $ip = explode(':', $ip);\r
- }\r
- foreach($ip as $path)\r
- {\r
- if ($a = realpath($path . DIRECTORY_SEPARATOR . $filename))\r
- {\r
- if (is_readable($a))\r
- {\r
- return true;\r
- }\r
- }\r
- }\r
- return false;\r
- }\r
-\r
- /**\r
- * Parses $_SERVER['argv'] and creates a setup array\r
- * @return array a setup array\r
- * @global array command-line arguments\r
- * @todo replace with Console_* ?\r
- */\r
- function parseArgv()\r
- {\r
- global $argv;\r
-\r
- // defaults for setting\r
- $setting['hidden'] = "off";\r
- $setting['ignoresymlinks'] = 'off';\r
- $setting['template'] = 'templates' . PATH_DELIMITER .'default' . PATH_DELIMITER;\r
-\r
- $valnext = "junk";\r
- $data = array();\r
- if(isset($argv) && is_array($argv))\r
- {\r
- foreach ($argv as $cmd)\r
- {\r
- if ($cmd == '--') {\r
- continue;\r
- }\r
- if ($cmd == '-h' || $cmd == '--help')\r
- {\r
- echo $this->displayHelpMsg();\r
- die();\r
- }\r
-\r
- // at first, set the arg value as if we\r
- // already know it's formatted normally, e.g.\r
- // -q on\r
- $setting[$valnext] = $cmd;\r
-\r
- if (isset($data['type']) && $data['type'] == 'set') {\r
-\r
- if ($valnext !== 'junk' && strpos(trim($cmd),'-') === 0) {\r
- // if valnext isn't 'junk' (i.e it was an arg option) \r
- // then the first arg needs an implicit "" as its value, e.g.\r
- // ... -q -pp ... ===> ... -q '' -pp ... \r
- $setting[$valnext] = '';\r
-\r
- } else if (!in_array(strtolower($cmd), $data['validvalues'], true)) {\r
- // the arg value is not a valid value\r
- addErrorDie(PDERROR_INVALID_VALUES, $valnext, $cmd,\r
- '(' . implode(', ', $data['validvalues']) . ')');\r
- }\r
- }\r
-\r
- foreach( $this->phpDocOptions as $name => $data )\r
- {\r
- if (!empty($data['tag']))\r
- {\r
- if (in_array($cmd,$data['tag']))\r
- {\r
- $valnext = $name;\r
- break;\r
- } \r
- else\r
- {\r
- $valnext = "junk";\r
- }\r
- }\r
- }\r
-\r
- if ($valnext == 'junk' && (strpos(trim($cmd),'-') === 0)) {\r
- // this indicates the last arg of the command \r
- // is an arg option (-) that was preceded by unrecognized "junk"\r
- addErrorDie(PDERROR_UNKNOWN_COMMANDLINE,$cmd);\r
-\r
- } else if ($valnext != 'junk' && (strpos(trim($cmd),'-') === 0)) {\r
- // this indicates the last arg of the command \r
- // is an arg option (-) without an arg value\r
- \r
- // add an empty arg "value" for this arg "option"\r
- $setting[$valnext] = '';\r
- }\r
-\r
-\r
- }\r
- } else\r
- {\r
- echo "Please use php-cli.exe in windows, or set register_argc_argv On";\r
- die;\r
- }\r
- /* $setting will always have at least 3 elements\r
- [hidden] => off\r
- [ignoresymlinks] => 'off'\r
- [template] => templates/default\r
- */\r
- if (count($setting) < 4) {\r
- echo $this->displayhelpMsg();\r
- die();\r
- }\r
-\r
- return $setting;\r
- }\r
-\r
-\r
- /**\r
- * @return array list of files in a directory\r
- * @param string $directory full path to the directory you want the list of\r
- * @param bool whether to list files that begin with . like .bash_history\r
- * @param bool whether to ignore symlinks\r
- */\r
- function dirList($orig_directory, $hidden = false, $ignore_symlinks = false)\r
- {\r
- $directory = realpath($orig_directory);\r
- $ret = false;\r
- if (! @is_dir($directory))\r
- {\r
- die("directory: '$directory' not found\n");\r
- }\r
- $ret = array();\r
- $d = @dir($directory); // thanks to Jason E Sweat (jsweat@users.sourceforge.net) for fix\r
- while($d && ($entry=$d->read()) !== false) {\r
- if (strcmp($entry,".") == 0 || strcmp($entry,"..") == 0) {\r
- continue;\r
- }\r
-\r
- // skip hidden files, if we're supposed to\r
- if (!$hidden)\r
- {\r
- if (substr($entry,0,1) == ".")\r
- {\r
- phpDocumentor_out("Hidden " . $directory . PATH_DELIMITER . $entry . " Ignored\n");\r
- continue;\r
- }\r
- }\r
-\r
- // skip symlink files, if we're supposed to\r
- if ($ignore_symlinks)\r
- {\r
- if (is_link($directory . PATH_DELIMITER . $entry))\r
- {\r
- phpDocumentor_out("Symlink " . $directory . PATH_DELIMITER . $entry . " Ignored\n");\r
- continue;\r
- }\r
- }\r
- \r
- if (is_file($directory . PATH_DELIMITER . $entry)) {\r
- $ret[] = $directory . PATH_DELIMITER . $entry;\r
- }\r
- if (is_dir($directory . PATH_DELIMITER . $entry)) {\r
- $tmp = $this->dirList($directory . PATH_DELIMITER . $entry, $hidden, $ignore_symlinks);\r
- if (is_array($tmp)) {\r
- foreach($tmp as $ent) {\r
- $ret[] = $ent;\r
- }\r
- }\r
- }\r
- }\r
- if ($d) $d->close();\r
- return $ret;\r
- }\r
-\r
- /**\r
- * Retrieve common directory (case-insensitive in windows)\r
- *\r
- * takes the list of files, and returns the subdirectory they share in common,\r
- * so in this list:\r
- *\r
- * <code>\r
- * array(\r
- * "/dir1/dir2/subdir/dir3/filename.ext",\r
- * "/dir1/dir2/subdir/dir4/filename.ext",\r
- * "/dir1/dir2/mydir/dir5/filename.ext");\r
- * </code>\r
- *\r
- * getBase will return "/dir1/dir2"\r
- * @param array array of strings\r
- */\r
- function getBase($filelist)\r
- {\r
- $masterPath = false;\r
- foreach($filelist as $path)\r
- {\r
- if (!$masterPath)\r
- {\r
- $masterPath = str_replace('\\','/',dirname($path));\r
- } else\r
- {\r
- if (dirname($path) != $masterPath)\r
- {\r
- $mp = split(PATH_DELIMITER,$masterPath);\r
- $np = split(PATH_DELIMITER,str_replace('\\','/',dirname($path)));\r
- if (count($np) < count($mp))\r
- {\r
- $masterPath = join($np, PATH_DELIMITER);\r
- } else\r
- {\r
- $test = false;\r
- $found = false;\r
- for($i=0;$i < count($mp) && $i < count($np);$i++)\r
- {\r
- if (PHPDOCUMENTOR_WINDOWS)\r
- {\r
- if (strtolower($mp[$i]) != strtolower($np[$i])) $found = $i;\r
- } else\r
- {\r
- if ($mp[$i] != $np[$i]) $found = $i;\r
- }\r
- }\r
- if ($found !== false)\r
- {\r
- $mp = array_slice($mp,0,$found);\r
- $masterPath = join($mp,PATH_DELIMITER);\r
- }\r
- }\r
- }\r
- }\r
- }\r
- return $masterPath;\r
- }\r
- \r
- /**\r
- * Retrieve tutorial subdirectories and their contents from the list of\r
- * files to parse\r
- * @param array array of paths (strings)\r
- * @return array array(filelist - tutorials, tutorials)\r
- */\r
- function getTutorials($filelist)\r
- {\r
- $list = $tutorials = array();\r
- foreach($filelist as $file)\r
- {\r
- if (strpos($file,'tutorials/') !== false)\r
- {\r
- $tutedir = explode('/',substr($file,strpos($file,'tutorials/')));\r
- array_shift($tutedir);\r
- if (count($tutedir) <= 3)\r
- {\r
- $res = array();\r
- // kludge - will need to fix for 2.0\r
- $res['category'] = $GLOBALS['phpDocumentor_DefaultCategoryName'];\r
- $res['package'] = array_shift($tutedir);\r
- $res['subpackage'] = '';\r
- if (count($tutedir) > 1)\r
- $res['subpackage'] = array_shift($tutedir);\r
- $f = array_shift($tutedir);\r
- $res['tutename'] = $f;\r
- $f = explode('.',$f);\r
- $res['tutetype'] = array_pop($f);\r
- if ($res['tutetype'] == 'ini') continue;\r
- $res['path'] = $file;\r
- if (@file_exists($file . '.ini'))\r
- {\r
- $res['ini'] = phpDocumentor_parse_ini_file($file . '.ini', true);\r
- } else\r
- {\r
- $res['ini'] = false;\r
- }\r
- $tutorials[] = $res;\r
- }\r
- } else $list[] = $file;\r
- }\r
- return array($list,$tutorials);\r
- }\r
- \r
- /**\r
- * @param string base directory from {@link getBase()}\r
- * @param array file list from {@link dirList()}\r
- * @return array array(filelist - README/INSTALL/CHANGELOG,\r
- * README/INSTALL/CHANGELOG)\r
- */\r
- function getReadmeInstallChangelog($base,$filelist)\r
- {\r
- $list = $ric = array();\r
- $names = $GLOBALS['_phpDocumentor_RIC_files'];\r
- foreach($filelist as $file)\r
- {\r
- if ((dirname($file) == $base) && in_array(strtoupper(basename($file)), $names))\r
- { // be sure to change $this->checkIgnore() if any other files are added here!!\r
- $ric[] = $file;\r
- } else\r
- {\r
- $list[] = $file;\r
- }\r
- }\r
- return array($list,$ric);\r
- }\r
-\r
- /**\r
- * @param string directory\r
- * @param string base directory\r
- * @param array array of ignored items\r
- * @param boolean the "hidden" flag\r
- * @param boolean the "ignoresymlinks" flag\r
- * @uses dirList\r
- * @uses checkIgnore\r
- * @uses setup_dirs\r
- */ \r
- function getDirTree($dir, $base_dir, $ignore = array(), $hidden = false, $ignoresymlinks = false)\r
- {\r
- $allfiles = $this->dirList($dir,$hidden,$ignoresymlinks);\r
- $struc = array();\r
- foreach($allfiles as $file)\r
- {\r
- if ($this->checkIgnore(basename($file),dirname(realpath($file)),$ignore,$ignoresymlinks)) continue;\r
- if (PHPDOCUMENTOR_WINDOWS) {\r
- $path = substr(dirname($file),strlen(str_replace('\\','/',realpath($base_dir))));\r
- } else {\r
- $path = substr(dirname($file),strlen(str_replace('\\','/',realpath($base_dir)))+1);\r
- }\r
- if (!$path) $path = '/';\r
- $parts = pathinfo($file);\r
- if (!isset($parts['extension']))\r
- {\r
- $parts['extension'] = '';\r
- }\r
- $struc[$path][] = array(\r
- 'file' => $parts['basename'],\r
- 'ext' => $parts['extension'],\r
- 'path' => $file);\r
- }\r
- uksort($struc,'strnatcasecmp');\r
- foreach($struc as $key => $ind)\r
- {\r
- usort($ind,'Ioinc_sortfiles');\r
- $struc[$key] = $ind;\r
- $save = $key;\r
- if ($key != '/')\r
- {\r
- $key = explode('/',$key);\r
- while (count($key))\r
- {\r
- array_pop($key);\r
- if (isset($struc[join('/',$key)]))\r
- {\r
- $struc[join('/',$key)][substr($save,strlen(join('/',$key)) + 1)] = $ind;\r
- unset($struc[$save]);\r
- }\r
- }\r
- }\r
- }\r
- foreach($struc as $key => $ind)\r
- {\r
- if ($key != '/')\r
- {\r
- if (count(explode('/',$key)) == 1)\r
- {\r
- $struc['/'][$key] = $struc[$key];\r
- unset($struc[$key]);\r
- }\r
- }\r
- }\r
- $tempstruc = $struc;\r
- unset($tempstruc['/']);\r
- $leftover_dirs = array_keys($tempstruc);\r
- $splitdirs = array();\r
- foreach($leftover_dirs as $dir)\r
- {\r
- $splitdirs[] = explode('/',$dir);\r
- }\r
- $leftover_dirs = array();\r
-\r
- foreach($splitdirs as $dir)\r
- {\r
- $save = join($dir,'/');\r
- $struc['/'] = setup_dirs($struc['/'], $dir, $tempstruc[$save]);\r
- unset($struc[$save]);\r
- }\r
- @uksort($struc['/'],'Ioinc_mystrucsort');\r
- return $struc;\r
- }\r
- \r
- /**\r
- * Reads a file and returns it as a string\r
- * Does basic error checking\r
- *\r
- * file extensions are set in {@link phpdoc.inc}\r
- *\r
- * @global array PHP File extensions, used to validate that $path is a PHP File\r
- * @global array PHP File extensions in a CVS repository, used to validate that $path is a PHP File\r
- * @param string $path\r
- */\r
- function readPhpFile($path, $quietMode = false)\r
- {\r
- global $_phpDocumentor_cvsphpfile_exts, $_phpDocumentor_phpfile_exts;\r
- // tiberiusblue addition\r
- $cvsExt = $_phpDocumentor_cvsphpfile_exts; \r
- $ext = $_phpDocumentor_phpfile_exts;\r
- if (file_exists($path))\r
- {\r
- if (is_file($path))\r
- {\r
- // check extension\r
- $tmp = explode(".",$path);\r
- // tiberiusblue addition\r
- $tmp2 = $tmp;\r
- if (in_array(array_pop($tmp),$ext))\r
- {\r
- phpDocumentor_out(" -- Parsing file\n");\r
- flush();\r
- if (function_exists('file_get_contents')) {\r
- return file_get_contents($path);\r
- }\r
- $fp = fopen($path,"r");\r
- $ret = fread($fp,filesize($path));\r
- fclose($fp);\r
- return $ret;\r
- } elseif (in_array(array_pop($tmp2),$cvsExt)) \r
- { \r
- phpDocumentor_out(" CVS file [EXPERIMENTAL]\n"); \r
- flush();\r
- if (function_exists('file_get_contents')) {\r
- $ret = file_get_contents($path);\r
- } else {\r
- $fp = fopen($path,"r"); \r
- $ret = fread($fp,filesize($path)); \r
- fclose($fp); \r
- }\r
- $ret = strstr($ret,"<?");\r
- $ret = substr($ret,0,strpos($ret,"@\n"));\r
- $ret = str_replace("@@","@",$ret); \r
- return $ret; \r
- } else\r
- {\r
- phpDocumentor_out(" -- File not parsed, not a php file\n");\r
- flush();\r
- }\r
- } else {\r
- phpDocumentor_out(" -- Unable to read file, not a file\n");\r
- flush();\r
- }\r
- } else {\r
- phpDocumentor_out(" -- Unable to read file, file does not exist\n");\r
- flush();\r
- }\r
- }\r
-\r
- /**\r
- * Tell whether to ignore a file or a directory\r
- * allows * and ? wildcards\r
- *\r
- * @author Greg Beaver <cellog@php.net>\r
- * @param string $file just the file name of the file or directory,\r
- * in the case of directories this is the last dir\r
- * @param string $path the path to consider (should be checked by\r
- * realpath() before, and may be relative)\r
- * @param array $ignore\r
- * @param bool\r
- * @param bool Ignore symlinks?\r
- * @return bool true if $path should be ignored, false if it should not\r
- */\r
- function checkIgnore($file,$path,$ignore,$ignore_no_ext = true,$ignoresymlinks = false)\r
- {\r
- global $_phpDocumentor_RIC_files;\r
-\r
- if ($ignoresymlinks && is_link($path . PATH_DELIMITER . $file)) return false;\r
- \r
- if (!count($ignore)) return false;\r
-\r
- if (!isset($this->ignore))\r
- {\r
- $this->_setupIgnore($ignore);\r
- }\r
- if (!$this->ignore)\r
- {\r
- return false;\r
- }\r
-\r
- if ($ignore_no_ext && \r
- !in_array(strtoupper($file), $_phpDocumentor_RIC_files))\r
- {\r
- if (!is_numeric(strpos($file,'.'))) return true;\r
- }\r
- if (is_array($this->ignore))\r
- {\r
- foreach($this->ignore as $match)\r
- {\r
- // match is an array if the ignore parameter was a /path/to/pattern\r
- if (is_array($match))\r
- {\r
- // check to see if the path matches with a path delimiter appended\r
- preg_match('/^' . strtoupper($match[0]).'$/', strtoupper($path) . PATH_DELIMITER,$find);\r
- if (!count($find))\r
- {\r
- // check to see if it matches without an appended path delimiter\r
- preg_match('/^' . strtoupper($match[0]).'$/', strtoupper($path), $find);\r
- }\r
- if (count($find))\r
- {\r
- // check to see if the file matches the file portion of the regex string\r
- preg_match('/^' . strtoupper($match[1]).'$/', strtoupper($file), $find);\r
- if (count($find))\r
- {\r
- return true;\r
- }\r
- }\r
- // check to see if the full path matches the regex\r
- preg_match('/^' . strtoupper($match[0]).'$/',\r
- strtoupper($path . DIRECTORY_SEPARATOR . $file), $find);\r
- if (count($find))\r
- {\r
- return true;\r
- }\r
- } else\r
- {\r
- // ignore parameter was just a pattern with no path delimiters\r
- // check it against the path\r
- preg_match('/^' . strtoupper($match).'$/', strtoupper($path), $find);\r
- if (count($find))\r
- {\r
- return true;\r
- }\r
- // check it against the file only\r
- preg_match('/^' . strtoupper($match).'$/', strtoupper($file), $find);\r
- if (count($find))\r
- {\r
- return true;\r
- }\r
- }\r
- }\r
- }\r
- return false;\r
- }\r
- \r
- /**\r
- * Construct the {@link $ignore} array\r
- * @author Greg Beaver <cellog@php.net>\r
- * @param array strings of files/paths/wildcards to ignore\r
- * @access protected\r
- */\r
- function _setupIgnore($ignore)\r
- {\r
- $ig = array();\r
- if ( ! is_array($ignore))\r
- {\r
- $this->ignore = false;\r
- return;\r
- }\r
- for($i=0; $i<count($ignore);$i++)\r
- {\r
- if (empty($ignore[$i]))\r
- continue;\r
-\r
- $ignore[$i] = strtr($ignore[$i], '\\', '/');\r
- $ignore[$i] = str_replace('//','/',$ignore[$i]);\r
-\r
- if (!is_numeric(strpos($ignore[$i],PATH_DELIMITER)))\r
- {\r
- $ig[] = $this->getRegExpableSearchString($ignore[$i]);\r
- } else\r
- {\r
- if (basename($ignore[$i]) . PATH_DELIMITER == $ignore[$i])\r
- $ig[] = $this->getRegExpableSearchString($ignore[$i]);\r
- else\r
- $ig[] = array($this->getRegExpableSearchString($ignore[$i]),$this->getRegExpableSearchString(basename($ignore[$i])));\r
- }\r
- }\r
- if (count($ig)) $this->ignore = $ig;\r
- }\r
- \r
- /**\r
- * Converts $s into a string that can be used with preg_match\r
- * @param string $s string with wildcards ? and *\r
- * @author Greg Beaver <cellog@php.net>\r
- * @return string converts * to .*, ? to ., etc.\r
- */\r
- function getRegExpableSearchString($s)\r
- {\r
- $y = '\/';\r
- if (DIRECTORY_SEPARATOR == '\\')\r
- {\r
- $y = '\\\\';\r
- }\r
- $s = str_replace('/', DIRECTORY_SEPARATOR, $s);\r
- $x = strtr($s, array('?' => '.','*' => '.*','.' => '\\.','\\' => '\\\\','/' => '\\/',\r
- '[' => '\\[',']' => '\\]','-' => '\\-'));\r
- if (strpos($s, DIRECTORY_SEPARATOR) !== false &&\r
- strrpos($s, DIRECTORY_SEPARATOR) === strlen($s) - 1)\r
- {\r
- $x = "(?:.*$y$x?.*|$x.*)";\r
- }\r
- return $x;\r
- }\r
- \r
- /**\r
- * Removes files from the $dir array that do not match the search string in\r
- * $match\r
- * @param array $dir array of filenames (full path)\r
- * @param string $match search string with wildcards\r
- * @author Greg Beaver <cellog@php.net>\r
- * @return string|array listing of every file in a directory that matches\r
- * the search string\r
- */\r
- function removeNonMatches($dir, $match)\r
- {\r
- $match = $this->getRegExpableSearchString($match);\r
- $nodir = false;\r
- if (!is_array($dir))\r
- {\r
- $dir = array($dir);\r
- $nodir = true;\r
- }\r
- foreach($dir as $i => $file)\r
- {\r
- preg_match('/^'.$match.'$/',basename($file),$find);\r
- if (!count($find)) unset($dir[$i]);\r
- }\r
- if ($nodir) return $dir[0];\r
- return $dir;\r
- }\r
- \r
- /**\r
- * Take a filename with wildcards and return all files that match the\r
- * wildcards\r
- * @param string $file a full path from the -f command-line parameter, with\r
- * potential * and ? wildcards.\r
- * @return mixed if $file contains wildcards, returns an array of matching\r
- * files, otherwise returns false\r
- * @author Greg Beaver <cellog@php.net>\r
- * @uses dirList\r
- * @uses removeNonMatches\r
- */\r
- function getAllFiles($file)\r
- {\r
- $path = realpath(dirname($file));\r
- $file = basename($file);\r
- // any wildcards?\r
- if (is_numeric(strpos($file,'?')) || is_numeric(strpos($file,'*')))\r
- {\r
- $files = $this->dirList($path);\r
- $a = $this->removeNonMatches($files,$file);\r
- return $a;\r
- }\r
- return false;\r
- }\r
-}\r
-\r
-/**#@+\r
- * Sorting functions for the file list\r
- * @param string\r
- * @param string\r
- */\r
-function Ioinc_sortfiles($a, $b)\r
-{\r
- return strnatcasecmp($a['file'],$b['file']);\r
-}\r
-\r
-function Ioinc_mystrucsort($a, $b)\r
-{\r
- if (is_numeric($a) && is_string($b)) return 1;\r
- if (is_numeric($b) && is_string($a)) return -1;\r
- if (is_numeric($a) && is_numeric($b))\r
- {\r
- if ($a > $b) return 1;\r
- if ($a < $b) return -1;\r
- if ($a == $b) return 0;\r
- }\r
- return strnatcasecmp($a,$b);\r
-}\r
-/**#@-*/\r
-\r
-/**\r
- * Recursively add all the subdirectories of $contents to $dir without erasing anything in\r
- * $dir\r
- * @param array\r
- * @param array\r
- * @return array processed $dir\r
- */\r
-function set_dir($dir,$contents)\r
-{\r
- while(list($one,$two) = each($contents))\r
- {\r
- if (isset($dir[$one]))\r
- {\r
- $dir[$one] = set_dir($dir[$one],$contents[$one]);\r
- } else $dir[$one] = $two;\r
- }\r
- return $dir;\r
-}\r
-\r
-/**\r
- * Recursively move contents of $struc into associative array\r
- *\r
- * The contents of $struc have many indexes like 'dir/subdir/subdir2'.\r
- * This function converts them to\r
- * array('dir' => array('subdir' => array('subdir2')))\r
- * @param array struc is array('dir' => array of files in dir,'dir/subdir' => array of files in dir/subdir,...)\r
- * @param array array form of 'dir/subdir/subdir2' array('dir','subdir','subdir2')\r
- * @return array same as struc but with array('dir' => array(file1,file2,'subdir' => array(file1,...)))\r
- */\r
-function setup_dirs($struc,$dir,$contents)\r
-{\r
- if (!count($dir))\r
- {\r
- foreach($contents as $dir => $files)\r
- {\r
- if (is_string($dir))\r
- {\r
- if (strpos($dir,'/'))\r
- {\r
- $test = true;\r
- $a = $contents[$dir];\r
- unset($contents[$dir]);\r
- $b = explode('/',$dir);\r
- $c = array_shift($b);\r
- if (isset($contents[$c]))\r
- {\r
- $contents[$c] = set_dir($contents[$c],setup_dirs(array(),$b,$a));\r
- } else $contents[$c] = setup_dirs(array(),$b,$a);\r
- }\r
- }\r
- }\r
- return $contents;\r
- }\r
- $me = array_shift($dir);\r
- if (!isset($struc[$me])) $struc[$me] = array();\r
- $struc[$me] = setup_dirs($struc[$me],$dir,$contents);\r
- return $struc;\r
-}\r
-\r
-if (!function_exists('get_include_path')) {\r
-function get_include_path()\r
-{\r
- return ini_get('include_path');\r
-}\r
-}\r
-?>\r