PageRenderTime 62ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/buildscripts/PhpDocumentor/phpDocumentor/Setup.inc.php

http://prado3.googlecode.com/
PHP | 978 lines | 795 code | 32 blank | 151 comment | 80 complexity | 49b8d2b8b5f75ea9f8d1391b42a16a3c MD5 | raw file
Possible License(s): Apache-2.0, IPL-1.0, LGPL-3.0, LGPL-2.1, BSD-3-Clause
  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 258122 2008-04-22 15:48:55Z ashnazg $
  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. /*
  193. * NOTE:
  194. * It is possible for the tokenizer extension to be loaded,
  195. * but actually be broken in the OS, and therefore not working...
  196. * the conditional below will NOT recognize this scenario.
  197. * You can separately run the {@link tokenizer_test.php} to
  198. * verify that the tokenizer library is working correctly
  199. * from the OS perspective.
  200. */
  201. if (tokenizer_ext) {
  202. phpDocumentor_out("using tokenizer Parser\n");
  203. $this->parse = new phpDocumentorTParser;
  204. } else {
  205. phpDocumentor_out("No Tokenizer support detected, so using default (slower) Parser..." . PHP_EOL);
  206. if (version_compare(phpversion(), '4.3.0', '<')) {
  207. phpDocumentor_out(" for faster parsing, recompile PHP with --enable-tokenizer." . PHP_EOL );
  208. } else {
  209. phpDocumentor_out(" for faster parsing, recompile PHP without --disable-tokenizer." . PHP_EOL );
  210. }
  211. $this->parse = new Parser;
  212. }
  213. }
  214. /**
  215. * Get phpDocumentor settings from a user configuration file
  216. * @param string user configuration file
  217. */
  218. function readConfigFile($file)
  219. {
  220. global $_phpDocumentor_setting, $_phpDocumentor_options;
  221. // security
  222. $file = str_replace(array('..','.ini','\\'),array('','','/'),$file);
  223. if (is_file($file . '.ini'))
  224. {
  225. $_phpDocumentor_setting = phpDocumentor_parse_ini_file($file.'.ini');
  226. } else
  227. {
  228. if ('@DATA-DIR@' != '@'.'DATA-DIR@')
  229. {
  230. $configdir = str_replace('\\','/', '@DATA-DIR@/PhpDocumentor') . PATH_DELIMITER . 'user' . PATH_DELIMITER;
  231. } else {
  232. $configdir = str_replace('\\','/',$GLOBALS['_phpDocumentor_install_dir']) . PATH_DELIMITER . 'user' . PATH_DELIMITER;
  233. }
  234. if (isset($_phpDocumentor_options['userdir'])) $configdir = $_phpDocumentor_options['userdir'];
  235. if (substr($configdir,-1) != '/')
  236. {
  237. $configdir .= '/';
  238. }
  239. $_phpDocumentor_setting = phpDocumentor_parse_ini_file( $configdir . $file . '.ini');
  240. if (empty($_phpDocumentor_setting['defaultpackagename']))
  241. {
  242. $_phpDocumentor_setting['defaultpackagename'] = 'default';
  243. }
  244. }
  245. // don't want a loop condition!
  246. unset($_phpDocumentor_setting['useconfig']);
  247. }
  248. /**
  249. * Get phpDocumentor settings from command-line or web interface
  250. */
  251. function readCommandLineSettings()
  252. {
  253. global $_phpDocumentor_setting,$interface,$_phpDocumentor_RIC_files;
  254. // subscribe $render class to $parse class events
  255. if (!isset($_phpDocumentor_setting['junk'])) $_phpDocumentor_setting['junk'] = '';
  256. if (!isset($_phpDocumentor_setting['title'])) $_phpDocumentor_setting['title'] = 'Generated Documentation';
  257. $temp_title = $_phpDocumentor_setting['title'];
  258. $this->render = new phpDocumentor_IntermediateParser($temp_title);
  259. if (isset($_phpDocumentor_setting['help']) || $_phpDocumentor_setting['junk'] == "-h" || $_phpDocumentor_setting['junk'] == "--help")
  260. {
  261. echo $this->setup->displayHelpMsg();
  262. die();
  263. }
  264. // set to parse hidden files
  265. $this->hidden = (isset($_phpDocumentor_setting['hidden'])) ? decideOnOrOff($_phpDocumentor_setting['hidden']) : false;
  266. // set to parse through symlinks
  267. $this->ignoresymlinks = (isset($_phpDocumentor_setting['ignoresymlinks'])) ? decideOnOrOff($_phpDocumentor_setting['ignoresymlinks']) : false;
  268. // set to parse elements marked private with @access private
  269. $this->render->setParsePrivate((isset($_phpDocumentor_setting['parseprivate'])) ? decideOnOrOff($_phpDocumentor_setting['parseprivate']) : false);
  270. // set to print warnings when undocumented elements are spotted
  271. $this->render->setUndocumentedElementWarningsMode((isset($_phpDocumentor_setting['undocumentedelements'])) ? decideOnOrOff($_phpDocumentor_setting['undocumentedelements']) : false);
  272. if (isset($_phpDocumentor_setting['ignoretags']))
  273. {
  274. $ignoretags = explode(',', $_phpDocumentor_setting['ignoretags']);
  275. $ignoretags = array_map('trim', $ignoretags);
  276. $tags = array();
  277. foreach($ignoretags as $tag)
  278. {
  279. if (!in_array($tag,array('@global', '@access', '@package', '@ignore', '@name', '@param', '@return', '@staticvar', '@var')))
  280. $tags[] = $tag;
  281. }
  282. $_phpDocumentor_setting['ignoretags'] = $tags;
  283. }
  284. if (isset($_phpDocumentor_setting['readmeinstallchangelog']))
  285. {
  286. $_phpDocumentor_setting['readmeinstallchangelog'] = explode(',',str_replace(' ','',$_phpDocumentor_setting['readmeinstallchangelog']));
  287. $rics = array();
  288. foreach($_phpDocumentor_setting['readmeinstallchangelog'] as $ric)
  289. {
  290. $rics[] = strtoupper(trim($ric));
  291. }
  292. $_phpDocumentor_RIC_files = $rics;
  293. }
  294. if (isset($_phpDocumentor_setting['javadocdesc']) && $_phpDocumentor_setting['javadocdesc'] == 'on')
  295. {
  296. $this->parse->eventHandlers[PARSER_EVENT_DOCBLOCK] = 'JavaDochandleDocblock';
  297. }
  298. if (tokenizer_ext)
  299. {
  300. if (isset($_phpDocumentor_setting['sourcecode']) && $_phpDocumentor_setting['sourcecode'] == 'on')
  301. {
  302. $_phpDocumentor_setting['sourcecode'] = true;
  303. } else
  304. {
  305. $_phpDocumentor_setting['sourcecode'] = false;
  306. }
  307. } else
  308. {
  309. if (isset($_phpDocumentor_setting['sourcecode']) && $_phpDocumentor_setting['sourcecode'] == 'on')
  310. {
  311. addWarning(PDERROR_SOURCECODE_IGNORED);
  312. }
  313. $_phpDocumentor_setting['sourcecode'] = false;
  314. }
  315. if (isset($_phpDocumentor_setting['converterparams']))
  316. {
  317. $_phpDocumentor_setting['converterparams'] = explode($_phpDocumentor_setting['converterparams']);
  318. foreach($_phpDocumentor_setting['converterparams'] as $i => $p)
  319. {
  320. $_phpDocumentor_setting['converterparams'][$i] = trim($p);
  321. }
  322. }
  323. if (isset($_phpDocumentor_setting['customtags']) && !empty($_phpDocumentor_setting['customtags']))
  324. {
  325. $c = explode(',',$_phpDocumentor_setting['customtags']);
  326. for($i=0;$i<count($c); $i++)
  327. {
  328. $GLOBALS['_phpDocumentor_tags_allowed'][] = trim($c[$i]);
  329. }
  330. }
  331. if (isset($_phpDocumentor_setting['pear']))
  332. {
  333. if ($_phpDocumentor_setting['pear'] === 'off') $_phpDocumentor_setting['pear'] = false;
  334. if ($_phpDocumentor_setting['pear'] === 'on') $_phpDocumentor_setting['pear'] = true;
  335. }
  336. if (!isset($_phpDocumentor_setting['pear'])) $_phpDocumentor_setting['pear'] = false;
  337. // set to change the default package name from "default" to whatever you want
  338. if (isset($_phpDocumentor_setting['defaultpackagename']))
  339. {
  340. $GLOBALS['phpDocumentor_DefaultPackageName'] = trim($_phpDocumentor_setting['defaultpackagename']);
  341. }
  342. // set to change the default category name from "default" to whatever you want
  343. if (isset($_phpDocumentor_setting['defaultcategoryname']))
  344. {
  345. $GLOBALS['phpDocumentor_DefaultCategoryName'] = trim($_phpDocumentor_setting['defaultcategoryname']);
  346. }
  347. // set the mode (quiet or verbose)
  348. $this->render->setQuietMode((isset($_phpDocumentor_setting['quiet'])) ? decideOnOrOff($_phpDocumentor_setting['quiet']) : false);
  349. // Setup the different classes
  350. if (isset($_phpDocumentor_setting['templatebase']))
  351. {
  352. $this->render->setTemplateBase(trim($_phpDocumentor_setting['templatebase']));
  353. }
  354. if (isset($_phpDocumentor_setting['target']) && !empty($_phpDocumentor_setting['target']))
  355. {
  356. $this->render->setTargetDir(trim($_phpDocumentor_setting['target']));
  357. }
  358. else
  359. {
  360. echo "a target directory must be specified\n try phpdoc -h\n";
  361. die();
  362. }
  363. if (!empty($_phpDocumentor_setting['packageoutput']))
  364. {
  365. $this->packages = explode(",",trim($_phpDocumentor_setting['packageoutput']));
  366. foreach($this->packages as $p => $v)
  367. {
  368. $this->packages[$p] = trim($v);
  369. }
  370. }
  371. if (!empty($_phpDocumentor_setting['filename'])) {
  372. $this->files = trim($_phpDocumentor_setting['filename']);
  373. }
  374. if (!empty($_phpDocumentor_setting['directory'])) {
  375. $this->dirs = trim($_phpDocumentor_setting['directory']);
  376. }
  377. }
  378. function checkIgnoreTag($tagname, $inline = false)
  379. {
  380. global $_phpDocumentor_setting;
  381. $tagname = '@'.$tagname;
  382. if (!isset($_phpDocumentor_setting['ignoretags'])) return false;
  383. if ($inline) $tagname = '{'.$tagname.'}';
  384. return in_array($tagname, $_phpDocumentor_setting['ignoretags']);
  385. }
  386. /**
  387. * Allow a memory_limit setting in phpDocumentor.ini to override php.ini or default memory limit
  388. * @todo recognize "K" and "G" in memory_limit settings, rather than just "M"
  389. */
  390. function setMemoryLimit() {
  391. global $_phpDocumentor_options;
  392. $DEFAULT_MEMORY_SIZE_MINIMUM = 256;
  393. // PhpDoc memory_limit from phpDocumentor.ini overrides all other considerations
  394. if (isset($_phpDocumentor_options['memory_limit'])) {
  395. $phpdoc_ini_setting = str_replace('M', '', $_phpDocumentor_options['memory_limit']);
  396. // allow phpdoc.ini to DISABLE the setting via "= -1"
  397. if ($phpdoc_ini_setting == -1)
  398. {
  399. $memory_setting_to_use = $phpdoc_ini_setting;
  400. $max_mem_log_message = "setting disabled by phpDocumentor.ini...\n";
  401. }
  402. else
  403. {
  404. $memory_setting_to_use = $phpdoc_ini_setting . "M";
  405. $max_mem_log_message = "set at " . $memory_setting_to_use . " by phpDocumentor.ini...\n";
  406. }
  407. } else {
  408. $php_ini_setting = str_replace('M', '', ini_get('memory_limit'));
  409. // allow php.ini to DISABLE the setting via "= -1"
  410. if ($php_ini_setting == -1)
  411. {
  412. // allow it to remain disabled
  413. $memory_setting_to_use = $php_ini_setting;
  414. $max_mem_log_message = "setting disabled by php.ini...\n";
  415. }
  416. else
  417. {
  418. // memory_limit from php.ini must be at least the default minimum
  419. $memory_setting_to_use = ($php_ini_setting > $DEFAULT_MEMORY_SIZE_MINIMUM) ? $php_ini_setting . "M" : $DEFAULT_MEMORY_SIZE_MINIMUM . "M";
  420. $max_mem_log_message = "set at " . $memory_setting_to_use . " after considering php.ini...\n";
  421. }
  422. }
  423. if (ini_set("memory_limit", $memory_setting_to_use))
  424. {
  425. // PHP had to have been compiled with "--enable-memory-limit" to allow setting the value explicitly
  426. phpDocumentor_out("Maximum memory usage " . $max_mem_log_message);
  427. }
  428. else
  429. {
  430. // PHP must not have been compiled with "--enable-memory-limit", so we cannot modify it...
  431. // no need to notify user of this unless they tried using memory_limit in their phpDocumentor.ini...
  432. if (isset($phpdoc_ini_setting))
  433. {
  434. phpDocumentor_out("Unable to alter memory_limit via your phpDocumentor.ini... perhaps PHP wasn't compiled with \"--enable-memory-limit\"?\n");
  435. }
  436. }
  437. }
  438. function setJavadocDesc()
  439. {
  440. $this->parse->eventHandlers[PARSER_EVENT_DOCBLOCK] = 'JavaDochandleDocblock';
  441. }
  442. function setParsePrivate($flag = true)
  443. {
  444. $this->render->setParsePrivate($flag);
  445. }
  446. function setQuietMode($flag = true)
  447. {
  448. $this->render->setQuietMode($flag);
  449. }
  450. function setUndocumentedElementWarnings($flag = true)
  451. {
  452. $this->render->setUndocumentedElementWarnings($flag);
  453. }
  454. function setTargetDir($target)
  455. {
  456. $this->render->setTargetDir($target);
  457. }
  458. function setTemplateBase($dir)
  459. {
  460. $this->render->setTemplateBase($dir);
  461. }
  462. function setPackageOutput($po)
  463. {
  464. $this->packages = explode(",",$po);
  465. array_map('trim', $this->packages);
  466. }
  467. function setTitle($ti)
  468. {
  469. $this->render = new phpDocumentor_IntermediateParser($ti);
  470. }
  471. function setFilesToParse($files)
  472. {
  473. $this->files = $files;
  474. }
  475. function setDirectoriesToParse($dirs)
  476. {
  477. $this->dirs = $dirs;
  478. }
  479. function parseHiddenFiles($flag = true)
  480. {
  481. $this->hidden = $flag;
  482. }
  483. function setIgnore($ig)
  484. {
  485. if (strstr($ig,","))
  486. {
  487. $this->ignore_files = explode(",",$ig);
  488. } else {
  489. if (!empty($ig))
  490. $this->ignore_files = array($ig);
  491. }
  492. $this->ignore_files = array_map('trim', $this->ignore_files);
  493. }
  494. function createDocs($title = false)
  495. {
  496. $this->parse_start_time = time();
  497. global $_phpDocumentor_setting;
  498. if (!$this->render)
  499. {
  500. $this->render = new phpDocumentor_IntermediateParser($title);
  501. }
  502. // setup ignore list
  503. $this->ignore_files =array();
  504. if(isset($_phpDocumentor_setting['ignore']))
  505. {
  506. $this->setIgnore($_phpDocumentor_setting['ignore']);
  507. }
  508. $this->parse->subscribe("*",$this->render);
  509. // parse the directory
  510. if (!empty($this->files))
  511. {
  512. $files = explode(",",$this->files);
  513. foreach($files as $file)
  514. {
  515. $file = trim($file);
  516. $test = $this->setup->getAllFiles($file);
  517. if ($test)
  518. {
  519. foreach($test as $file)
  520. {
  521. $file = trim($file);
  522. $dir = realpath(dirname($file));
  523. $dir = strtr($dir, "\\", "/");
  524. $dir = str_replace('//','/',$dir);
  525. // strip trailing directory seperator
  526. if (substr($dir,-1) == "/" || substr($dir,-1) == "\\")
  527. {
  528. $dir = substr($dir,0,-1);
  529. }
  530. $file = strtr(realpath($file), "\\", "/");
  531. $file = str_replace('//','/',$file);
  532. if (!$this->setup->checkIgnore(basename($file),dirname($file),$this->ignore_files,true,$this->ignoresymlinks))
  533. {
  534. $filelist[] = str_replace('\\','/',$file);
  535. } else {
  536. phpDocumentor_out("File $file Ignored\n");
  537. flush();
  538. }
  539. }
  540. } else
  541. {
  542. $dir = dirname(realpath($file));
  543. $dir = strtr($dir, "\\", "/");
  544. $dir = str_replace('//','/',$dir);
  545. // strip trailing directory seperator
  546. if (substr($dir,-1) == "/" || substr($dir,-1) == "\\")
  547. {
  548. $dir = substr($dir,0,-1);
  549. }
  550. $base = count(explode("/",$dir));
  551. $file = strtr(realpath($file), "\\", "/");
  552. $file = str_replace('//','/',$file);
  553. flush();
  554. if (!$this->setup->checkIgnore(basename($file),dirname($file),$this->ignore_files,true,$this->ignoresymlinks))
  555. {
  556. $filelist[] = str_replace('\\','/',$file);
  557. } else {
  558. phpDocumentor_out("File $file Ignored\n");
  559. flush();
  560. }
  561. }
  562. }
  563. }
  564. if (!empty($this->dirs))
  565. {
  566. $dirs = explode(",",$this->dirs);
  567. foreach($dirs as $dir)
  568. {
  569. $olddir = $dir;
  570. $dir = realpath($dir);
  571. if (!$dir) {
  572. phpDocumentor_out('ERROR: "' . $olddir . '" does not exist, skipping');
  573. continue;
  574. }
  575. $dir = trim($dir);
  576. $dir = strtr($dir, "\\", "/");
  577. $dir = str_replace('//','/',$dir);
  578. // strip trailing directory seperator
  579. if (substr($dir,-1) == "/" || substr($dir,-1) == "\\")
  580. {
  581. $dir = substr($dir,0,-1);
  582. }
  583. $files = $this->setup->dirList($dir,$this->hidden,$this->ignoresymlinks);
  584. if (is_array($files))
  585. {
  586. foreach($files as $file)
  587. {
  588. $file = strtr($file, '\\', '/');
  589. // file's subpath, relative to $dir
  590. $file_subpath = str_replace('\\', '/', realpath(dirname($file)));
  591. $file_subpath = preg_replace('[\\/]', DIRECTORY_SEPARATOR, $file_subpath);
  592. $file_subpath = preg_replace('~^' . preg_quote($dir, '~') . '~', '', $file_subpath);
  593. if (!$this->setup->checkIgnore(basename($file), $file_subpath, $this->ignore_files,true,$this->ignoresymlinks))
  594. {
  595. $filelist[] = $file;
  596. } else {
  597. phpDocumentor_out("File $file Ignored\n");
  598. flush();
  599. }
  600. }
  601. }
  602. }
  603. }
  604. if (isset($filelist))
  605. {
  606. if (PHPDOCUMENTOR_WINDOWS)
  607. {
  608. // case insensitive array_unique
  609. usort($filelist,'strnatcasecmp');
  610. reset($filelist);
  611. $newarray = array();
  612. $i = 0;
  613. $element = current($filelist);
  614. for ($n=0;$n<sizeof($filelist);$n++)
  615. {
  616. if (strtolower(next($filelist)) != strtolower($element))
  617. {
  618. $newarray[$i] = $element;
  619. $element = current($filelist);
  620. $i++;
  621. }
  622. }
  623. $filelist = $newarray;
  624. } else $filelist = array_unique($filelist);
  625. $base = count(explode("/",$source_base = $this->setup->getBase($filelist)));
  626. define("PHPDOCUMENTOR_BASE",$source_base);
  627. list($filelist,$ric) = $this->setup->getReadmeInstallChangelog($source_base, $filelist);
  628. phpDocumentor_out("\n\nGrabbing README/INSTALL/CHANGELOG\n");
  629. flush();
  630. foreach($ric as $file)
  631. {
  632. phpDocumentor_out(basename($file).'...');
  633. flush();
  634. $fp = fopen($file,'r');
  635. $contents = fread($fp,filesize($file));
  636. $this->render->HandleEvent(PHPDOCUMENTOR_EVENT_README_INSTALL_CHANGELOG, array(basename($file),$contents));
  637. fclose($fp);
  638. }
  639. phpDocumentor_out("\ndone\n");
  640. flush();
  641. list($filelist,$tutorials) = $this->setup->getTutorials($filelist);
  642. phpDocumentor_out("\n\nTutorial/Extended Documentation Parsing Stage\n\n");
  643. flush();
  644. if (count($tutorials))
  645. {
  646. $tuteparser = new XMLPackagePageParser;
  647. $tuteparser->subscribe('*',$this->render);
  648. foreach($tutorials as $tutorial)
  649. {
  650. switch($tutorial['tutetype'])
  651. {
  652. case 'pkg' :
  653. case 'cls' :
  654. case 'proc' :
  655. switch($tutorial['tutetype'])
  656. {
  657. case 'pkg' :
  658. $ptext = 'Package-level Docs ';
  659. if (!empty($tutorial['subpackage']))
  660. $ptext = 'Sub-Package Docs ';
  661. break;
  662. case 'cls' :
  663. $ptext = 'Class-level Docs ';
  664. break;
  665. case 'proc' :
  666. $ptext = 'Procedural-level Docs ';
  667. break;
  668. }
  669. $fp = @fopen($tutorial['path'],"r");
  670. if ($fp)
  671. {
  672. $ret = fread($fp,filesize($tutorial['path']));
  673. // fix 1151650
  674. if (stristr($ret, "utf-8") !== "")
  675. {
  676. $ret = utf8_decode($ret);
  677. }
  678. fclose($fp);
  679. unset($fp);
  680. phpDocumentor_out('Parsing '.$ptext.$tutorial['path'].'...');
  681. flush();
  682. $tuteparser->parse($ret,$tutorial);
  683. phpDocumentor_out("done\n");
  684. flush();
  685. } else
  686. {
  687. phpDocumentor_out('Error '.$ptext.$tutorial['path'].' doesn\'t exist'."\n");
  688. flush();
  689. }
  690. default :
  691. break;
  692. }
  693. }
  694. }
  695. phpDocumentor_out("done\n");
  696. flush();
  697. phpDocumentor_out("\n\nGeneral Parsing Stage\n\n");
  698. flush();
  699. foreach($filelist as $file)
  700. {
  701. phpDocumentor_out("Reading file $file");
  702. flush();
  703. $this->parse->parse($a = $this->setup->readPhpFile($file, $this->render->quietMode),$file,$base,$this->packages);
  704. }
  705. $b = (time() - $this->parse_start_time);
  706. phpDocumentor_out("done\n");
  707. flush();
  708. // render output
  709. phpDocumentor_out("\nConverting From Abstract Parsed Data\n");
  710. flush();
  711. $this->render->output();
  712. $a = (time() - $this->parse_start_time);
  713. $c = ($a - $b);
  714. phpDocumentor_out("\nParsing time: $b seconds\n");
  715. phpDocumentor_out("\nConversion time: $c seconds\n");
  716. phpDocumentor_out("\nTotal Documentation Time: $a seconds\n");
  717. phpDocumentor_out("done\n");
  718. flush();
  719. } else
  720. {
  721. print "\nERROR: nothing parsed\n";
  722. exit;
  723. }
  724. }
  725. /**
  726. * Parse configuration file phpDocumentor.ini
  727. */
  728. function parseIni()
  729. {
  730. phpDocumentor_out("Parsing configuration file phpDocumentor.ini...\n");
  731. flush();
  732. if ('@DATA-DIR@' != '@'.'DATA-DIR@')
  733. {
  734. $options = phpDocumentor_parse_ini_file(str_replace('\\','/', '@DATA-DIR@/PhpDocumentor') . PATH_DELIMITER . 'phpDocumentor.ini',true);
  735. phpDocumentor_out(" (found in " . '@DATA-DIR@/PhpDocumentor' . PATH_DELIMITER . ")...\n");
  736. } else {
  737. $options = phpDocumentor_parse_ini_file(str_replace('\\','/',$GLOBALS['_phpDocumentor_install_dir']) . PATH_DELIMITER . 'phpDocumentor.ini',true);
  738. phpDocumentor_out(" (found in " . $GLOBALS['_phpDocumentor_install_dir'] . PATH_DELIMITER . ")...\n");
  739. }
  740. if (!$options)
  741. {
  742. print "ERROR: cannot open phpDocumentor.ini in directory " . $GLOBALS['_phpDocumentor_install_dir']."\n";
  743. print "-Is phpdoc in either the path or include_path in your php.ini file?";
  744. exit;
  745. }
  746. foreach($options as $var => $values)
  747. {
  748. if ($var != 'DEBUG')
  749. {
  750. // phpDocumentor_out("\n$var");
  751. if ($var != '_phpDocumentor_setting' && $var != '_phpDocumentor_options' && $var != '_phpDocumentor_install_dir' ) $values = array_values($values);
  752. // fancy_debug("\n$var",$values);
  753. $GLOBALS[$var] = $values;
  754. }
  755. }
  756. phpDocumentor_out("\ndone\n");
  757. flush();
  758. /** Debug Constant */
  759. if (!defined('PHPDOCUMENTOR_DEBUG')) define("PHPDOCUMENTOR_DEBUG",$options['DEBUG']['PHPDOCUMENTOR_DEBUG']);
  760. if (!defined('PHPDOCUMENTOR_KILL_WHITESPACE')) define("PHPDOCUMENTOR_KILL_WHITESPACE",$options['DEBUG']['PHPDOCUMENTOR_KILL_WHITESPACE']);
  761. $GLOBALS['_phpDocumentor_cvsphpfile_exts'] = $GLOBALS['_phpDocumentor_phpfile_exts'];
  762. foreach($GLOBALS['_phpDocumentor_cvsphpfile_exts'] as $key => $val)
  763. {
  764. $GLOBALS['_phpDocumentor_cvsphpfile_exts'][$key] = "$val,v";
  765. }
  766. // none of this stuff is used anymore
  767. if (isset($GLOBALS['_phpDocumentor_html_allowed']))
  768. {
  769. $___htmltemp = array_flip($GLOBALS['_phpDocumentor_html_allowed']);
  770. $___html1 = array();
  771. foreach($___htmltemp as $tag => $trans)
  772. {
  773. $___html1['<'.$tag.'>'] = htmlentities('<'.$tag.'>');
  774. $___html1['</'.$tag.'>'] = htmlentities('</'.$tag.'>');
  775. }
  776. $GLOBALS['phpDocumentor___html'] = array_flip($___html1);
  777. }
  778. }
  779. /**
  780. * Performs character-based validation of Output Converter Template name pieces
  781. * @param string the name piece (just ONE of either Output, Converter, or Template piece)
  782. * @param string any extra characters to allow beyond the default character set
  783. * @return string|bool the clean name, or FALSE if piece is deemed invalid
  784. * @access private
  785. */
  786. function cleanConverterNamePiece($name, $extra_characters_to_allow = '')
  787. {
  788. $name = str_replace("\\", "/", $name);
  789. // security: ensure no opportunity exists to use "../.." pathing in this value
  790. $name = preg_replace('/[^a-zA-Z0-9' . $extra_characters_to_allow . '_-]/', "", $name);
  791. // absolutely positively do NOT allow two consecutive dots ".."
  792. if (strpos($name, '..') > -1) $name = false;
  793. return $name;
  794. }
  795. /**
  796. * Figures out what output converter to use
  797. * @param string Output Converter Template name
  798. * @access private
  799. * @global array
  800. * @uses cleanConverterNamePieces
  801. * @uses phpDocumentor_out
  802. */
  803. function setupConverters($output = false)
  804. {
  805. global $_phpDocumentor_setting;
  806. if ($output)
  807. {
  808. $_phpDocumentor_setting['output'] = $output;
  809. }
  810. if (isset($_phpDocumentor_setting['output']) && !empty($_phpDocumentor_setting['output']))
  811. {
  812. $c = explode(',',$_phpDocumentor_setting['output']);
  813. for($i=0; $i< count($c); $i++)
  814. {
  815. $c[$i] = explode(':',$c[$i]);
  816. $a = $c[$i][0];
  817. if (isset($c[$i][0]))
  818. {
  819. $a = $this->cleanConverterNamePiece($c[$i][0]);
  820. }
  821. else
  822. {
  823. $a = false;
  824. }
  825. if (isset($c[$i][1]))
  826. {
  827. /*
  828. * must allow "/" due to options like "DocBook/peardoc2"
  829. */
  830. $b = $this->cleanConverterNamePiece($c[$i][1], '\/');
  831. }
  832. else
  833. {
  834. $b = false;
  835. }
  836. if (isset($c[$i][2]))
  837. {
  838. /*
  839. * must allow "." due to options like "phpdoc.de"
  840. * must allow "/" due to options like "DOM/default"
  841. */
  842. $d = $this->cleanConverterNamePiece($c[$i][2], '.\/');
  843. if (substr($d,-1) != "/")
  844. {
  845. $d .= "/";
  846. }
  847. else
  848. {
  849. $d = 'default/';
  850. }
  851. }
  852. if (strtoupper(trim($a)) == 'HTML' && (trim($b) == 'default'))
  853. {
  854. phpDocumentor_out("WARNING: HTMLdefaultConverter is deprecated, using HTMLframesConverter.\n");
  855. phpDocumentor_out("WARNING: template output is identical, HTMLframes is more flexible.\n");
  856. phpDocumentor_out("WARNING: please adjust your usage\n");
  857. flush();
  858. $b = 'frames'; // change default to frames.
  859. }
  860. $this->render->addConverter(strtoupper(trim($a)),trim($b),trim($d));
  861. }
  862. } else
  863. {
  864. $this->render->addConverter('HTML','frames','default/');
  865. }
  866. if (empty($this->render->converters)) addErrorDie(PDERROR_NO_CONVERTERS);
  867. }
  868. }
  869. /**
  870. * Fuzzy logic to interpret the boolean args' intent
  871. * @param string the command-line option to analyze
  872. * @return boolean our best guess of the value's boolean intent
  873. */
  874. function decideOnOrOff($value_to_guess = 'NO VALUE WAS PASSED')
  875. {
  876. $these_probably_mean_yes = array(
  877. '', // "--hidden" with no value
  878. 'on', // "--hidden on"
  879. 'y', 'yes', // "--hidden y"
  880. 'true', // "--hidden true"
  881. '1' // "--hidden 1"
  882. );
  883. $best_guess = false; // default to "false", "off", "no", "take a hike"
  884. if (in_array(strtolower(trim($value_to_guess)), $these_probably_mean_yes))
  885. {
  886. $best_guess = true;
  887. }
  888. return $best_guess;
  889. }
  890. /**
  891. * Print parse information if quiet setting is off
  892. */
  893. function phpDocumentor_out($string)
  894. {
  895. global $_phpDocumentor_setting;
  896. if ((isset($_phpDocumentor_setting['quiet'])) ? !decideOnOrOff($_phpDocumentor_setting['quiet']) : true)
  897. {
  898. print $string;
  899. }
  900. }
  901. /**
  902. * Crash in case of known, dangerous bug condition
  903. *
  904. * Checks the PHP version that is executing PhpDocumentor,
  905. * in case a known PHP/PEAR bug condition could be triggered
  906. * by the PhpDocumentor execution.
  907. * @param string $php_version the PHP version that contains the bug
  908. * @param string $php_bug_number the PHP bug number (if any)
  909. * @param string $pear_bug_number the PEAR bug number (if any)
  910. */
  911. function checkForBugCondition($php_version, $php_bug_number = 'none', $pear_bug_number = 'none')
  912. {
  913. if (version_compare(phpversion(), $php_version) == 0)
  914. {
  915. addErrorDie(PDERROR_DANGEROUS_PHP_BUG_EXISTS, $php_version, $php_bug_number, $pear_bug_number);
  916. }
  917. }
  918. ?>