PageRenderTime 58ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/secured/phpDocumentor/phpDocumentor/Setup.inc.php

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