64ba62479259d6d6521fa42c611ea504fd966b95
[atutor.git] / mods / phpdoc2 / PhpDocumentor / phpDocumentor / Setup.inc.php
1 <?php\r
2 /**\r
3  * This was all in {@link phpdoc.inc}, and now encapsulates the complexity\r
4  * \r
5  * phpDocumentor :: automatic documentation generator\r
6  * \r
7  * PHP versions 4 and 5\r
8  *\r
9  * Copyright (c) 2002-2006 Gregory Beaver\r
10  * \r
11  * LICENSE:\r
12  * \r
13  * This library is free software; you can redistribute it\r
14  * and/or modify it under the terms of the GNU Lesser General\r
15  * Public License as published by the Free Software Foundation;\r
16  * either version 2.1 of the License, or (at your option) any\r
17  * later version.\r
18  * \r
19  * This library is distributed in the hope that it will be useful,\r
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
22  * Lesser General Public License for more details.\r
23  * \r
24  * You should have received a copy of the GNU Lesser General Public\r
25  * License along with this library; if not, write to the Free Software\r
26  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
27  *\r
28  * @package    phpDocumentor\r
29  * @author     Gregory Beaver <cellog@php.net>\r
30  * @copyright  2002-2006 Gregory Beaver\r
31  * @license    http://www.opensource.org/licenses/lgpl-license.php LGPL\r
32  * @version    CVS: $Id: Setup.inc.php,v 1.27 2007/12/09 23:40:07 ashnazg Exp $\r
33  * @link       http://www.phpdoc.org\r
34  * @link       http://pear.php.net/PhpDocumentor\r
35  * @since      1.2\r
36  */\r
37 error_reporting(E_ALL);\r
38 \r
39 /** ensure top-level PhpDocumentor dir is in include path */\r
40 set_include_path(get_include_path() . PATH_SEPARATOR . dirname(dirname(__FILE__)));\r
41 \r
42 /** common settings */\r
43 include_once("phpDocumentor/common.inc.php");\r
44 \r
45 include_once("phpDocumentor/Io.inc");\r
46 include_once("phpDocumentor/Publisher.inc");\r
47 include_once("phpDocumentor/Classes.inc");\r
48 include_once("phpDocumentor/ProceduralPages.inc");\r
49 include_once("phpDocumentor/IntermediateParser.inc");\r
50 include_once("phpDocumentor/WordParser.inc");\r
51 include_once("phpDocumentor/EventStack.inc");\r
52 include_once("phpDocumentor/ParserData.inc");\r
53 include_once("phpDocumentor/InlineTags.inc");\r
54 include_once("phpDocumentor/DocBlockTags.inc");\r
55 include_once("phpDocumentor/DescHTML.inc");\r
56 include_once("phpDocumentor/ParserDocBlock.inc");\r
57 include_once("phpDocumentor/ParserElements.inc");\r
58 include_once("phpDocumentor/Parser.inc");\r
59 include_once("phpDocumentor/phpDocumentorTWordParser.inc");\r
60 include_once("phpDocumentor/phpDocumentorTParser.inc");\r
61 include_once("phpDocumentor/HighlightParser.inc");\r
62 include_once("phpDocumentor/TutorialHighlightParser.inc");\r
63 include_once("phpDocumentor/ParserDescCleanup.inc");\r
64 include_once("phpDocumentor/PackagePageElements.inc");\r
65 include_once("phpDocumentor/XMLpackagePageParser.inc");\r
66 include_once("phpDocumentor/LinkClasses.inc");\r
67 include_once("phpDocumentor/Converter.inc");\r
68 include_once("phpDocumentor/Errors.inc");\r
69 if (isset($_GET))\r
70 {\r
71 /**\r
72  * $interface is either 'web' or is not set at all\r
73  * @global array $interface\r
74  */\r
75     if (isset($_GET['interface'])) $interface = $_GET['interface'];\r
76 /**\r
77  * $_phpDocumentor_setting is either the value from the web interface, or is set up by {@link Io::parseArgv()}\r
78  * @global array $_phpDocumentor_setting\r
79  */\r
80     if (isset($_GET['setting'])) $_phpDocumentor_setting = $_GET['setting'];\r
81 }\r
82 \r
83 /**\r
84  * default package name, set using -dn --defaultpackagename\r
85  * @global string $GLOBALS['phpDocumentor_DefaultPackageName']\r
86  * @name $phpDocumentor_DefaultPackageName\r
87  */\r
88 $GLOBALS['phpDocumentor_DefaultPackageName'] = 'default';\r
89 \r
90 /**\r
91  * default package name, set using -dn --defaultcategoryname\r
92  * @global string $GLOBALS['phpDocumentor_DefaultCategoryName']\r
93  * @name $phpDocumentor_DefaultCategoryName\r
94  */\r
95 $GLOBALS['phpDocumentor_DefaultCategoryName'] = 'default';\r
96 \r
97 /**\r
98  * @package phpDocumentor\r
99  */\r
100 class phpDocumentor_setup\r
101 {\r
102     /**\r
103      * The main parser\r
104      * @var Parser|phpDocumentorTParser\r
105      */\r
106     var $parse;\r
107     /**\r
108      * Used to parse command-line options\r
109      * @var Io\r
110      */\r
111     var $setup;\r
112     /**\r
113      * Used to organize output from the Parser before Conversion\r
114      * @var phpDocumentor_IntermediateParser\r
115      */\r
116     var $render = false;\r
117     /**\r
118      * Packages to create documentation for\r
119      * @var string\r
120      */\r
121     var $packages = false;\r
122     /**\r
123      * contents of --filename commandline\r
124      * @tutorial phpDocumentor.howto.pkg#using.command-line.filename\r
125      * @var string\r
126      */\r
127     var $files = '';\r
128     /**\r
129      * contents of --directory commandline\r
130      * @tutorial phpDocumentor.howto.pkg#using.command-line.directory\r
131      * @var string\r
132      */\r
133     var $dirs = '';\r
134     /**\r
135      * contents of --hidden commandline\r
136      * @tutorial phpDocumentor.howto.pkg#using.command-line.hidden\r
137      * @var boolean\r
138      */\r
139     var $hidden = false;\r
140     /**\r
141      * time that parsing was started, used for informative timing of output\r
142      * @access private\r
143      */\r
144     var $parse_start_time;\r
145     /**\r
146      * contents of --ignore commandline\r
147      * @tutorial phpDocumentor.howto.pkg#using.command-line.ignore\r
148      * @var string\r
149      */\r
150     var $ignore_files = array();\r
151     /**\r
152      * contents of --ignoresymlinks commandline\r
153      * @var boolean\r
154      */\r
155     var $ignoresymlinks = false;\r
156 \r
157     /**\r
158      * Checks PHP version, makes sure it is 4.2.0+, and chooses the\r
159      * phpDocumentorTParser if version is 4.3.0+\r
160      * @uses parseIni()\r
161      */\r
162     function phpDocumentor_setup()\r
163     {\r
164         global $_phpDocumentor_cvsphpfile_exts, $_phpDocumentor_setting;\r
165         if (!function_exists('is_a'))\r
166         {\r
167             print "phpDocumentor requires PHP version 4.2.0 or greater to function";\r
168             exit;\r
169         }\r
170 \r
171         $this->setup = new Io;\r
172         if (!isset($interface) && !isset($_GET['interface']) && !isset($_phpDocumentor_setting))\r
173         {\r
174             // Parse the argv settings\r
175             $_phpDocumentor_setting = $this->setup->parseArgv();\r
176         }\r
177         if (isset($_phpDocumentor_setting['useconfig']) &&\r
178              !empty($_phpDocumentor_setting['useconfig'])) {\r
179             $this->readConfigFile($_phpDocumentor_setting['useconfig']);\r
180         }\r
181 \r
182         // set runtime to a large value since this can take quite a while\r
183         // we can only set_time_limit when not in safe_mode bug #912064\r
184         if (!ini_get('safe_mode'))\r
185         {\r
186             set_time_limit(0);    // unlimited runtime\r
187         } else\r
188         {\r
189             phpDocumentor_out("time_limit cannot be set since your in safe_mode, please edit time_limit in your php.ini to allow enough time for phpDocumentor to run"); \r
190         }\r
191   \r
192         $phpver = phpversion();\r
193         $phpdocver = PHPDOCUMENTOR_VER;\r
194         if (isset($_GET['interface'])) {\r
195             $phpver = "<b>$phpver</b>";\r
196             $phpdocver = "<b>$phpdocver</b>";\r
197         }\r
198         phpDocumentor_out("PHP Version $phpver\n");\r
199         phpDocumentor_out("phpDocumentor version $phpdocver\n\n");\r
200 \r
201         $this->parseIni();\r
202         $this->setMemoryLimit();\r
203 \r
204         if (tokenizer_ext)\r
205         {\r
206             phpDocumentor_out("using tokenizer Parser\n");\r
207             $this->parse = new phpDocumentorTParser;\r
208         } else\r
209         {\r
210             phpDocumentor_out("No Tokenizer support detected, so using default (slower) Parser..." . PHP_EOL);\r
211 \r
212             if (version_compare(phpversion(), '4.3.0', '<')) {\r
213                 phpDocumentor_out("    for faster parsing, recompile PHP with --enable-tokenizer." . PHP_EOL );\r
214             } else {\r
215                 phpDocumentor_out("    for faster parsing, recompile PHP without --disable-tokenizer." . PHP_EOL );\r
216             }\r
217 \r
218             $this->parse = new Parser;\r
219         }\r
220     }\r
221     \r
222     /**\r
223      * Get phpDocumentor settings from a user configuration file\r
224      * @param string user configuration file\r
225      */\r
226     function readConfigFile($file)\r
227     {\r
228         global $_phpDocumentor_setting, $_phpDocumentor_options;\r
229         // security\r
230         $file = str_replace(array('..','.ini','\\'),array('','','/'),$file);\r
231         if (is_file($file . '.ini'))\r
232         {\r
233             $_phpDocumentor_setting = phpDocumentor_parse_ini_file($file.'.ini');\r
234         } else\r
235         {\r
236             if ('@DATA-DIR@' != '@'.'DATA-DIR@')\r
237             {\r
238                 $configdir = str_replace('\\','/', '@DATA-DIR@/PhpDocumentor') . PATH_DELIMITER . 'user' . PATH_DELIMITER;\r
239             } else {\r
240                 $configdir = str_replace('\\','/',$GLOBALS['_phpDocumentor_install_dir']) . PATH_DELIMITER . 'user' . PATH_DELIMITER;\r
241             }\r
242             if (isset($_phpDocumentor_options['userdir'])) $configdir = $_phpDocumentor_options['userdir'];\r
243             if (substr($configdir,-1) != '/')\r
244             {\r
245                 $configdir .= '/';\r
246             }\r
247             $_phpDocumentor_setting = phpDocumentor_parse_ini_file( $configdir . $file . '.ini');\r
248             if (empty($_phpDocumentor_setting['defaultpackagename']))\r
249             {\r
250                 $_phpDocumentor_setting['defaultpackagename'] = 'default';\r
251             }\r
252         }\r
253         // don't want a loop condition!\r
254         unset($_phpDocumentor_setting['useconfig']);\r
255     }\r
256     \r
257     /**\r
258      * Get phpDocumentor settings from command-line or web interface\r
259      */\r
260     function readCommandLineSettings()\r
261     {\r
262         global $_phpDocumentor_setting,$interface,$_phpDocumentor_RIC_files;\r
263         // subscribe $render class to $parse class events\r
264         if (!isset($_phpDocumentor_setting['junk'])) $_phpDocumentor_setting['junk'] = '';\r
265         if (!isset($_phpDocumentor_setting['title'])) $_phpDocumentor_setting['title'] = 'Generated Documentation';\r
266         $temp_title = $_phpDocumentor_setting['title'];\r
267         $this->render = new phpDocumentor_IntermediateParser($temp_title);\r
268         if (isset($_phpDocumentor_setting['help']) || $_phpDocumentor_setting['junk'] == "-h" || $_phpDocumentor_setting['junk'] == "--help")\r
269         {\r
270             echo $this->setup->displayHelpMsg();\r
271             die();\r
272         }\r
273 \r
274         // set to parse hidden files\r
275         $this->hidden = (isset($_phpDocumentor_setting['hidden'])) ? decideOnOrOff($_phpDocumentor_setting['hidden']) : false;\r
276 \r
277         // set to parse through symlinks\r
278         $this->ignoresymlinks = (isset($_phpDocumentor_setting['ignoresymlinks'])) ? decideOnOrOff($_phpDocumentor_setting['ignoresymlinks']) : false;\r
279         \r
280         // set to parse elements marked private with @access private\r
281         $this->render->setParsePrivate((isset($_phpDocumentor_setting['parseprivate'])) ? decideOnOrOff($_phpDocumentor_setting['parseprivate']) : false);\r
282 \r
283         // set to print warnings when undocumented elements are spotted\r
284         $this->render->setUndocumentedElementWarningsMode((isset($_phpDocumentor_setting['undocumentedelements'])) ? decideOnOrOff($_phpDocumentor_setting['undocumentedelements']) : false);\r
285 \r
286         if (isset($_phpDocumentor_setting['ignoretags']))\r
287         {\r
288             $ignoretags = explode(',', $_phpDocumentor_setting['ignoretags']);\r
289             $ignoretags = array_map('trim', $ignoretags);\r
290             $tags = array();\r
291             foreach($ignoretags as $tag)\r
292             {\r
293                 if (!in_array($tag,array('@global', '@access', '@package', '@ignore', '@name', '@param', '@return', '@staticvar', '@var')))\r
294                     $tags[] = $tag;\r
295             }\r
296             $_phpDocumentor_setting['ignoretags'] = $tags;\r
297         }\r
298         \r
299         if (isset($_phpDocumentor_setting['readmeinstallchangelog']))\r
300         {\r
301             $_phpDocumentor_setting['readmeinstallchangelog'] = explode(',',str_replace(' ','',$_phpDocumentor_setting['readmeinstallchangelog']));\r
302             $rics = array();\r
303             foreach($_phpDocumentor_setting['readmeinstallchangelog'] as $ric)\r
304             {\r
305                 $rics[] = strtoupper(trim($ric));\r
306             }\r
307             $_phpDocumentor_RIC_files = $rics;\r
308         }\r
309         \r
310         if (isset($_phpDocumentor_setting['javadocdesc']) && $_phpDocumentor_setting['javadocdesc'] == 'on')\r
311         {\r
312             $this->parse->eventHandlers[PARSER_EVENT_DOCBLOCK] = 'JavaDochandleDocblock';\r
313         }\r
314         if (tokenizer_ext)\r
315         {\r
316             if (isset($_phpDocumentor_setting['sourcecode']) && $_phpDocumentor_setting['sourcecode'] == 'on')\r
317             {\r
318                 $_phpDocumentor_setting['sourcecode'] = true;\r
319             } else\r
320             {\r
321                 $_phpDocumentor_setting['sourcecode'] = false;\r
322             }\r
323         } else\r
324         {\r
325             if (isset($_phpDocumentor_setting['sourcecode']) && $_phpDocumentor_setting['sourcecode'] == 'on')\r
326             {\r
327                 addWarning(PDERROR_SOURCECODE_IGNORED);\r
328             }\r
329             $_phpDocumentor_setting['sourcecode'] = false;\r
330         }\r
331         if (isset($_phpDocumentor_setting['converterparams']))\r
332         {\r
333             $_phpDocumentor_setting['converterparams'] = explode($_phpDocumentor_setting['converterparams']);\r
334             foreach($_phpDocumentor_setting['converterparams'] as $i => $p)\r
335             {\r
336                 $_phpDocumentor_setting['converterparams'][$i] = trim($p);\r
337             }\r
338         }\r
339         if (isset($_phpDocumentor_setting['customtags']) && !empty($_phpDocumentor_setting['customtags']))\r
340         {\r
341             $c = explode(',',$_phpDocumentor_setting['customtags']);\r
342             for($i=0;$i<count($c); $i++)\r
343             {\r
344                 $GLOBALS['_phpDocumentor_tags_allowed'][] = trim($c[$i]);\r
345             }\r
346         }\r
347         if (isset($_phpDocumentor_setting['pear']))\r
348         {\r
349             if ($_phpDocumentor_setting['pear'] === 'off') $_phpDocumentor_setting['pear'] = false;\r
350             if ($_phpDocumentor_setting['pear'] === 'on') $_phpDocumentor_setting['pear'] = true;\r
351         }\r
352         if (!isset($_phpDocumentor_setting['pear'])) $_phpDocumentor_setting['pear'] = false;\r
353         // set to change the default package name from "default" to whatever you want\r
354         if (isset($_phpDocumentor_setting['defaultpackagename']))\r
355         {\r
356             $GLOBALS['phpDocumentor_DefaultPackageName'] = trim($_phpDocumentor_setting['defaultpackagename']);\r
357         }\r
358         // set to change the default category name from "default" to whatever you want\r
359         if (isset($_phpDocumentor_setting['defaultcategoryname']))\r
360         {\r
361             $GLOBALS['phpDocumentor_DefaultCategoryName'] = trim($_phpDocumentor_setting['defaultcategoryname']);\r
362         }\r
363         \r
364         // set the mode (quiet or verbose)\r
365         $this->render->setQuietMode((isset($_phpDocumentor_setting['quiet'])) ? decideOnOrOff($_phpDocumentor_setting['quiet']) : false);\r
366 \r
367         // Setup the different classes\r
368         if (isset($_phpDocumentor_setting['templatebase']))\r
369         {\r
370             $this->render->setTemplateBase(trim($_phpDocumentor_setting['templatebase']));\r
371         }\r
372         if (isset($_phpDocumentor_setting['target']) && !empty($_phpDocumentor_setting['target']))\r
373         {\r
374             $this->render->setTargetDir(trim($_phpDocumentor_setting['target']));\r
375         }\r
376         else\r
377         {\r
378             echo "a target directory must be specified\n try phpdoc -h\n";\r
379             die();\r
380         }\r
381         if (!empty($_phpDocumentor_setting['packageoutput']))\r
382         {\r
383             $this->packages = explode(",",trim($_phpDocumentor_setting['packageoutput']));\r
384             foreach($this->packages as $p => $v)\r
385             {\r
386                 $this->packages[$p] = trim($v);\r
387             }\r
388         }\r
389         if (!empty($_phpDocumentor_setting['filename'])) {\r
390             $this->files = trim($_phpDocumentor_setting['filename']);\r
391         }\r
392         if (!empty($_phpDocumentor_setting['directory'])) {\r
393             $this->dirs = trim($_phpDocumentor_setting['directory']);\r
394         }\r
395     }\r
396     \r
397     function checkIgnoreTag($tagname, $inline = false)\r
398     {\r
399         global $_phpDocumentor_setting;\r
400         $tagname = '@'.$tagname;\r
401         if (!isset($_phpDocumentor_setting['ignoretags'])) return false;\r
402         if ($inline) $tagname = '{'.$tagname.'}';\r
403         return in_array($tagname, $_phpDocumentor_setting['ignoretags']);\r
404     }\r
405 \r
406     /**\r
407      * Allow a memory_limit setting in phpDocumentor.ini to override php.ini or default memory limit\r
408      * @todo recognize "K" and "G" in memory_limit settings, rather than just "M"\r
409      */\r
410     function setMemoryLimit() {\r
411         global $_phpDocumentor_options;\r
412         $DEFAULT_MEMORY_SIZE_MINIMUM = 256;\r
413         \r
414         // PhpDoc memory_limit from phpDocumentor.ini overrides all other considerations\r
415         if (isset($_phpDocumentor_options['memory_limit'])) {\r
416             $phpdoc_ini_setting = str_replace('M', '', $_phpDocumentor_options['memory_limit']);\r
417 \r
418             // allow phpdoc.ini to DISABLE the setting via "= -1"\r
419             if ($phpdoc_ini_setting == -1)\r
420             {\r
421                 $memory_setting_to_use = $phpdoc_ini_setting;\r
422                 $max_mem_log_message = "setting disabled by phpDocumentor.ini...\n";\r
423             }\r
424             else\r
425             {\r
426                 $memory_setting_to_use = $phpdoc_ini_setting . "M";\r
427                 $max_mem_log_message = "set at " . $memory_setting_to_use . " by phpDocumentor.ini...\n";\r
428             }\r
429         } else {\r
430             $php_ini_setting = str_replace('M', '', ini_get('memory_limit'));\r
431 \r
432             // allow php.ini to DISABLE the setting via "= -1"\r
433             if ($php_ini_setting == -1)\r
434             {\r
435                 // allow it to remain disabled\r
436                 $memory_setting_to_use = $php_ini_setting;\r
437                 $max_mem_log_message = "setting disabled by php.ini...\n";\r
438             }\r
439             else\r
440             {\r
441                 // memory_limit from php.ini must be at least the default minimum\r
442                 $memory_setting_to_use = ($php_ini_setting > $DEFAULT_MEMORY_SIZE_MINIMUM) ? $php_ini_setting . "M" : $DEFAULT_MEMORY_SIZE_MINIMUM . "M";\r
443                 $max_mem_log_message = "set at " . $memory_setting_to_use . " after considering php.ini...\n";                \r
444             }\r
445         }\r
446         if (ini_set("memory_limit", $memory_setting_to_use))\r
447         {\r
448             // PHP had to have been compiled with "--enable-memory-limit" to allow setting the value explicitly\r
449             phpDocumentor_out("Maximum memory usage " . $max_mem_log_message);\r
450         }\r
451         else\r
452         {\r
453             // PHP must not have been compiled with "--enable-memory-limit", so we cannot modify it...\r
454             // no need to notify user of this unless they tried using memory_limit in their phpDocumentor.ini...\r
455             if (isset($phpdoc_ini_setting))\r
456             {\r
457                 phpDocumentor_out("Unable to alter memory_limit via your phpDocumentor.ini... perhaps PHP wasn't compiled with \"--enable-memory-limit\"?\n");\r
458             }\r
459         }\r
460     }\r
461     \r
462     function setJavadocDesc()\r
463     {\r
464            $this->parse->eventHandlers[PARSER_EVENT_DOCBLOCK] = 'JavaDochandleDocblock';\r
465     }\r
466     \r
467     function setParsePrivate($flag = true)\r
468     {\r
469         $this->render->setParsePrivate($flag);\r
470     }\r
471     \r
472     function setQuietMode($flag = true)\r
473     {\r
474         $this->render->setQuietMode($flag);\r
475     }\r
476 \r
477     function setUndocumentedElementWarnings($flag = true)\r
478     {\r
479         $this->render->setUndocumentedElementWarnings($flag);\r
480     }\r
481     \r
482     function setTargetDir($target)\r
483     {\r
484         $this->render->setTargetDir($target);\r
485     }\r
486     \r
487     function setTemplateBase($dir)\r
488     {\r
489         $this->render->setTemplateBase($dir);\r
490     }\r
491     \r
492     function setPackageOutput($po)\r
493     {\r
494         $this->packages = explode(",",$po);\r
495         array_map('trim', $this->packages);\r
496     }\r
497     \r
498     function setTitle($ti)\r
499     {\r
500         $this->render = new phpDocumentor_IntermediateParser($ti);\r
501     }\r
502     \r
503     function setFilesToParse($files)\r
504     {\r
505         $this->files = $files;\r
506     }\r
507     \r
508     function setDirectoriesToParse($dirs)\r
509     {\r
510         $this->dirs = $dirs;\r
511     }\r
512     \r
513     function parseHiddenFiles($flag = true)\r
514     {\r
515         $this->hidden = $flag;\r
516     }\r
517     \r
518     function setIgnore($ig)\r
519     {\r
520         if (strstr($ig,","))\r
521         {\r
522             $this->ignore_files = explode(",",$ig);\r
523         } else {\r
524             if (!empty($ig))\r
525             $this->ignore_files = array($ig);\r
526         }\r
527         $this->ignore_files = array_map('trim', $this->ignore_files);\r
528     }\r
529     \r
530     function createDocs($title = false)\r
531     {\r
532         $this->parse_start_time = time();\r
533         global $_phpDocumentor_setting;\r
534         if (!$this->render)\r
535         {\r
536             $this->render = new phpDocumentor_IntermediateParser($title);\r
537         }\r
538         // setup ignore  list\r
539         $this->ignore_files =array();\r
540         if(isset($_phpDocumentor_setting['ignore']))\r
541         {\r
542             $this->setIgnore($_phpDocumentor_setting['ignore']);\r
543         }\r
544         $this->parse->subscribe("*",$this->render);\r
545         // parse the directory\r
546         if (!empty($this->files))\r
547         {\r
548             $files = explode(",",$this->files);\r
549             foreach($files as $file)\r
550             {\r
551                 $file = trim($file);\r
552                 $test = $this->setup->getAllFiles($file);\r
553                 if ($test)\r
554                 {\r
555                     foreach($test as $file)\r
556                     {\r
557                         $file = trim($file);\r
558                         $dir = realpath(dirname($file));\r
559                         $dir = strtr($dir, "\\", "/");\r
560                         $dir = str_replace('//','/',$dir);\r
561                         // strip trailing directory seperator\r
562                         if (substr($dir,-1) == "/" || substr($dir,-1) == "\\")\r
563                         {\r
564                             $dir = substr($dir,0,-1);\r
565                         }\r
566                         $file = strtr(realpath($file), "\\", "/");\r
567                         $file = str_replace('//','/',$file);\r
568 \r
569                         if (!$this->setup->checkIgnore(basename($file),dirname($file),$this->ignore_files,true,$this->ignoresymlinks))\r
570                         {\r
571                             $filelist[] = str_replace('\\','/',$file);\r
572                         } else {\r
573                             phpDocumentor_out("File $file Ignored\n");\r
574                             flush();\r
575                         }\r
576                     }\r
577                 } else\r
578                 {\r
579                     $dir = dirname(realpath($file));\r
580                     $dir = strtr($dir, "\\", "/");\r
581                     $dir = str_replace('//','/',$dir);\r
582                     // strip trailing directory seperator\r
583                     if (substr($dir,-1) == "/" || substr($dir,-1) == "\\")\r
584                     {\r
585                         $dir = substr($dir,0,-1);\r
586                     }\r
587                     $base = count(explode("/",$dir));\r
588                     $file = strtr(realpath($file), "\\", "/");\r
589                     $file = str_replace('//','/',$file);\r
590                     flush();\r
591 \r
592                     if (!$this->setup->checkIgnore(basename($file),dirname($file),$this->ignore_files,true,$this->ignoresymlinks))\r
593                     {\r
594                         $filelist[] = str_replace('\\','/',$file);\r
595                     } else {\r
596                         phpDocumentor_out("File $file Ignored\n");\r
597                         flush();\r
598                     }\r
599                 }\r
600             }\r
601         }\r
602         if (!empty($this->dirs))\r
603         {\r
604             $dirs = explode(",",$this->dirs);\r
605             foreach($dirs as $dir)\r
606             {\r
607                 $olddir = $dir;\r
608                 $dir = realpath($dir);\r
609                 if (!$dir) {\r
610                     phpDocumentor_out('ERROR: "' . $olddir . '" does not exist, skipping');\r
611                     continue;\r
612                 }\r
613                 $dir = trim($dir);\r
614                 $dir = strtr($dir, "\\", "/");\r
615                 $dir = str_replace('//','/',$dir);\r
616                 // strip trailing directory seperator\r
617                 if (substr($dir,-1) == "/" || substr($dir,-1) == "\\")\r
618                 {\r
619                     $dir = substr($dir,0,-1);\r
620                 }\r
621                 $files = $this->setup->dirList($dir,$this->hidden,$this->ignoresymlinks);\r
622                 if (is_array($files))\r
623                 {\r
624                     foreach($files as $file)\r
625                     {\r
626                         $file = strtr($file, '\\', '/');\r
627                         // file's subpath, relative to $dir\r
628                         $file_subpath = str_replace('\\', '/', realpath(dirname($file)));\r
629                         $file_subpath = preg_replace('~^' . preg_quote($dir, '~') . '~', '', $file_subpath);\r
630 \r
631                         if (!$this->setup->checkIgnore(basename($file), $file_subpath, $this->ignore_files,true,$this->ignoresymlinks))\r
632                         {\r
633                             $filelist[] = $file;\r
634                         } else {\r
635                             phpDocumentor_out("File $file Ignored\n");\r
636                             flush();\r
637                         }\r
638                     }\r
639                 }\r
640             }\r
641         }\r
642         if (isset($filelist))\r
643         {\r
644             if (PHPDOCUMENTOR_WINDOWS)\r
645             {\r
646                 // case insensitive array_unique\r
647                 usort($filelist,'strnatcasecmp');\r
648                 reset($filelist);\r
649                 \r
650                 $newarray = array();\r
651                 $i = 0;\r
652                 \r
653                 $element = current($filelist);\r
654                 for ($n=0;$n<sizeof($filelist);$n++)\r
655                 {\r
656                     if (strtolower(next($filelist)) != strtolower($element))\r
657                     {\r
658                         $newarray[$i] = $element;\r
659                         $element = current($filelist);\r
660                         $i++;\r
661                     }\r
662                 }\r
663                 $filelist = $newarray; \r
664             } else $filelist = array_unique($filelist);\r
665 \r
666             $base = count(explode("/",$source_base = $this->setup->getBase($filelist)));\r
667             define("PHPDOCUMENTOR_BASE",$source_base);\r
668             list($filelist,$ric) = $this->setup->getReadmeInstallChangelog($source_base, $filelist);\r
669             phpDocumentor_out("\n\nGrabbing README/INSTALL/CHANGELOG\n");\r
670             flush();\r
671             foreach($ric as $file)\r
672             {\r
673                 phpDocumentor_out(basename($file).'...');\r
674                 flush();\r
675                 $fp = fopen($file,'r');\r
676                 $contents = fread($fp,filesize($file));\r
677                 $this->render->HandleEvent(PHPDOCUMENTOR_EVENT_README_INSTALL_CHANGELOG, array(basename($file),$contents));\r
678                 fclose($fp);\r
679             }\r
680             phpDocumentor_out("\ndone\n");\r
681             flush();\r
682             list($filelist,$tutorials) = $this->setup->getTutorials($filelist);\r
683             phpDocumentor_out("\n\nTutorial/Extended Documentation Parsing Stage\n\n");\r
684             flush();\r
685             if (count($tutorials))\r
686             {\r
687                 $tuteparser = new XMLPackagePageParser;\r
688                 $tuteparser->subscribe('*',$this->render);\r
689                 foreach($tutorials as $tutorial)\r
690                 {\r
691                     switch($tutorial['tutetype'])\r
692                     {\r
693                         case 'pkg' :\r
694                         case 'cls' :\r
695                         case 'proc' :\r
696                         switch($tutorial['tutetype'])\r
697                         {\r
698                             case 'pkg' :\r
699                                 $ptext = 'Package-level Docs ';\r
700                                 if (!empty($tutorial['subpackage']))\r
701                                 $ptext = 'Sub-Package Docs ';\r
702                             break;\r
703                             case 'cls' :\r
704                                 $ptext = 'Class-level Docs ';\r
705                             break;\r
706                             case 'proc' :\r
707                                 $ptext = 'Procedural-level Docs ';\r
708                             break;\r
709                         }\r
710                         $fp = @fopen($tutorial['path'],"r");\r
711                         if ($fp)\r
712                         {\r
713                             $ret = fread($fp,filesize($tutorial['path']));\r
714                             // fix 1151650\r
715                             if (stristr($ret, "utf-8") !== "")\r
716                             {\r
717                                 $ret = utf8_decode($ret);\r
718                             }\r
719                             fclose($fp);\r
720                             unset($fp);\r
721                             phpDocumentor_out('Parsing '.$ptext.$tutorial['path'].'...');\r
722                             flush();\r
723                             $tuteparser->parse($ret,$tutorial);\r
724                             phpDocumentor_out("done\n");\r
725                             flush();\r
726                         } else\r
727                         {\r
728                             phpDocumentor_out('Error '.$ptext.$tutorial['path'].' doesn\'t exist'."\n");\r
729                             flush();\r
730                         }\r
731                         default :\r
732                         break;\r
733                     }\r
734                 }\r
735             }\r
736             phpDocumentor_out("done\n");\r
737             flush();\r
738             phpDocumentor_out("\n\nGeneral Parsing Stage\n\n");\r
739             flush();\r
740             foreach($filelist as $file)\r
741             {\r
742                 phpDocumentor_out("Reading file $file");\r
743                 flush();\r
744                 $this->parse->parse($a = $this->setup->readPhpFile($file, $this->render->quietMode),$file,$base,$this->packages);\r
745     \r
746             }\r
747             $b = (time() - $this->parse_start_time);\r
748             phpDocumentor_out("done\n");\r
749             flush();\r
750             // render output\r
751             phpDocumentor_out("\nConverting From Abstract Parsed Data\n");\r
752             flush();\r
753             $this->render->output();\r
754             $a = (time() - $this->parse_start_time);\r
755             $c = ($a - $b);\r
756             phpDocumentor_out("\nParsing time: $b seconds\n");\r
757             phpDocumentor_out("\nConversion time: $c seconds\n");\r
758             phpDocumentor_out("\nTotal Documentation Time: $a seconds\n");\r
759             phpDocumentor_out("done\n");\r
760             flush();\r
761         } else\r
762         {\r
763             print "\nERROR: nothing parsed\n";\r
764             exit;\r
765         }\r
766     }\r
767     /**\r
768      * Parse configuration file phpDocumentor.ini\r
769      */\r
770     function parseIni()\r
771     {\r
772         phpDocumentor_out("Parsing configuration file phpDocumentor.ini...\n");\r
773         flush();\r
774         if ('@DATA-DIR@' != '@'.'DATA-DIR@')\r
775         {\r
776             $options = phpDocumentor_parse_ini_file(str_replace('\\','/', '@DATA-DIR@/PhpDocumentor') . PATH_DELIMITER . 'phpDocumentor.ini',true);\r
777             phpDocumentor_out("   (found in " . '@DATA-DIR@/PhpDocumentor' . PATH_DELIMITER . ")...\n");\r
778         } else {\r
779             $options = phpDocumentor_parse_ini_file(str_replace('\\','/',$GLOBALS['_phpDocumentor_install_dir']) . PATH_DELIMITER . 'phpDocumentor.ini',true);\r
780             phpDocumentor_out("   (found in " . $GLOBALS['_phpDocumentor_install_dir'] . PATH_DELIMITER . ")...\n");\r
781         }\r
782 \r
783         if (!$options)\r
784         {\r
785             print "ERROR: cannot open phpDocumentor.ini in directory " . $GLOBALS['_phpDocumentor_install_dir']."\n";\r
786             print "-Is phpdoc in either the path or include_path in your php.ini file?";\r
787             exit;\r
788         }\r
789         \r
790         foreach($options as $var => $values)\r
791         {\r
792             if ($var != 'DEBUG')\r
793             {\r
794 //                phpDocumentor_out("\n$var");\r
795                 if ($var != '_phpDocumentor_setting' && $var != '_phpDocumentor_options' && $var != '_phpDocumentor_install_dir' ) $values = array_values($values);\r
796 //                fancy_debug("\n$var",$values);\r
797                 $GLOBALS[$var] = $values;\r
798             }\r
799         }\r
800         phpDocumentor_out("\ndone\n");\r
801         flush();\r
802         /** Debug Constant */\r
803         if (!defined('PHPDOCUMENTOR_DEBUG')) define("PHPDOCUMENTOR_DEBUG",$options['DEBUG']['PHPDOCUMENTOR_DEBUG']);\r
804         if (!defined('PHPDOCUMENTOR_KILL_WHITESPACE')) define("PHPDOCUMENTOR_KILL_WHITESPACE",$options['DEBUG']['PHPDOCUMENTOR_KILL_WHITESPACE']);\r
805         $GLOBALS['_phpDocumentor_cvsphpfile_exts'] = $GLOBALS['_phpDocumentor_phpfile_exts'];\r
806         foreach($GLOBALS['_phpDocumentor_cvsphpfile_exts'] as $key => $val)\r
807         {\r
808             $GLOBALS['_phpDocumentor_cvsphpfile_exts'][$key] = "$val,v";\r
809         }\r
810         // none of this stuff is used anymore\r
811         if (isset($GLOBALS['_phpDocumentor_html_allowed']))\r
812         {\r
813             $___htmltemp = array_flip($GLOBALS['_phpDocumentor_html_allowed']);\r
814             $___html1 = array();\r
815             foreach($___htmltemp as $tag => $trans)\r
816             {\r
817                 $___html1['<'.$tag.'>'] = htmlentities('<'.$tag.'>');\r
818                 $___html1['</'.$tag.'>'] = htmlentities('</'.$tag.'>');\r
819             }\r
820             $GLOBALS['phpDocumentor___html'] = array_flip($___html1);\r
821         }\r
822     }\r
823     \r
824     /**\r
825      * Performs character-based validation of Output Converter Template name pieces\r
826      * @param string the name piece (just ONE of either Output, Converter, or Template piece)\r
827      * @param string any extra characters to allow beyond the default character set\r
828      * @return string|bool the clean name, or FALSE if piece is deemed invalid\r
829      * @access private\r
830      */\r
831     function cleanConverterNamePiece($name, $extra_characters_to_allow = '')\r
832     {\r
833         $name = str_replace("\\", "/", $name);\r
834         // security:  ensure no opportunity exists to use "../.." pathing in this value\r
835         $name = preg_replace('/[^a-zA-Z0-9' . $extra_characters_to_allow . '_-]/', "", $name);\r
836 \r
837         // absolutely positively do NOT allow two consecutive dots ".."\r
838         if (strpos($name, '..') > -1) $name = false;\r
839         return $name;\r
840     }\r
841 \r
842     /**\r
843      * Figures out what output converter to use\r
844      * @param string Output Converter Template name\r
845      * @access private\r
846      * @global array\r
847      * @uses cleanConverterNamePieces\r
848      * @uses phpDocumentor_out\r
849      */    \r
850     function setupConverters($output = false)\r
851     {\r
852         global $_phpDocumentor_setting;\r
853         if ($output)\r
854         {\r
855             $_phpDocumentor_setting['output'] = $output;\r
856         }\r
857         if (isset($_phpDocumentor_setting['output']) && !empty($_phpDocumentor_setting['output']))\r
858         {\r
859             $c = explode(',',$_phpDocumentor_setting['output']);\r
860             for($i=0; $i< count($c); $i++)\r
861             {\r
862                 $c[$i] = explode(':',$c[$i]);\r
863                 $a = $c[$i][0];\r
864                 if (isset($c[$i][0]))\r
865                 {\r
866                     $a = $this->cleanConverterNamePiece($c[$i][0]);\r
867                 }\r
868                 else\r
869                 {\r
870                     $a = false;\r
871                 }\r
872                 if (isset($c[$i][1]))\r
873                 {\r
874                     /*\r
875                      * must allow "/" due to options like "DocBook/peardoc2"\r
876                      */\r
877                     $b = $this->cleanConverterNamePiece($c[$i][1], '\/');\r
878                 }\r
879                 else\r
880                 {\r
881                     $b = false;\r
882                 }\r
883                 if (isset($c[$i][2]))\r
884                 {\r
885                     /*\r
886                      * must allow "." due to options like "phpdoc.de"\r
887                      * must allow "/" due to options like "DOM/default"\r
888                      */\r
889                     $d = $this->cleanConverterNamePiece($c[$i][2], '.\/');\r
890                     if (substr($d,-1) != "/")\r
891                     {\r
892                         $d .= "/";\r
893                     }\r
894                     else \r
895                     {\r
896                         $d = 'default/';\r
897                     }\r
898                 }\r
899                 if (strtoupper(trim($a)) == 'HTML' && (trim($b) == 'default'))\r
900                 {\r
901                     phpDocumentor_out("WARNING: HTMLdefaultConverter is deprecated, using HTMLframesConverter.\n");\r
902                     phpDocumentor_out("WARNING: template output is identical, HTMLframes is more flexible.\n");\r
903                     phpDocumentor_out("WARNING: please adjust your usage\n");\r
904                     flush();\r
905                     $b = 'frames'; // change default to frames.\r
906                 }\r
907                 $this->render->addConverter(strtoupper(trim($a)),trim($b),trim($d));\r
908             }\r
909         } else\r
910         {\r
911             $this->render->addConverter('HTML','frames','default/');\r
912         }\r
913         if (empty($this->render->converters)) addErrorDie(PDERROR_NO_CONVERTERS);\r
914     }\r
915 }\r
916 \r
917 /**\r
918  * Fuzzy logic to interpret the boolean args' intent\r
919  * @param string the command-line option to analyze\r
920  * @return boolean our best guess of the value's boolean intent\r
921  */\r
922 function decideOnOrOff($value_to_guess = 'NO VALUE WAS PASSED')\r
923 {\r
924     $these_probably_mean_yes = array(\r
925         '',             // "--hidden" with no value \r
926         'on',           // "--hidden on"\r
927         'y', 'yes',     // "--hidden y"\r
928         'true',         // "--hidden true"\r
929         '1'             // "--hidden 1"\r
930     );\r
931     $best_guess = false;    // default to "false", "off", "no", "take a hike"\r
932 \r
933     if (in_array(strtolower(trim($value_to_guess)), $these_probably_mean_yes))\r
934     {\r
935         $best_guess = true;\r
936     }\r
937     return $best_guess;\r
938 }\r
939 \r
940 /**\r
941  * Print parse information if quiet setting is off\r
942  */\r
943 function phpDocumentor_out($string)\r
944 {\r
945     global $_phpDocumentor_setting;\r
946     if ((isset($_phpDocumentor_setting['quiet'])) ? !decideOnOrOff($_phpDocumentor_setting['quiet']) : true)\r
947     {\r
948         print $string;\r
949     }\r
950 \r
951 }\r
952 \r
953 /**\r
954  * Crash in case of known, dangerous bug condition\r
955  * \r
956  * Checks the PHP version that is executing PhpDocumentor,\r
957  * in case a known PHP/PEAR bug condition could be triggered\r
958  * by the PhpDocumentor execution.\r
959  * @param string $php_version the PHP version that contains the bug\r
960  * @param string $php_bug_number the PHP bug number (if any)\r
961  * @param string $pear_bug_number the PEAR bug number (if any)\r
962  */\r
963 function checkForBugCondition($php_version, $php_bug_number = 'none', $pear_bug_number = 'none')\r
964 {\r
965     if (version_compare(phpversion(), $php_version) == 0)\r
966     {\r
967         addErrorDie(PDERROR_DANGEROUS_PHP_BUG_EXISTS, $php_version, $php_bug_number, $pear_bug_number);\r
968     }\r
969 }\r
970 ?>\r