home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / PhpDocumentor / phpDocumentor / Setup.inc.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  36.9 KB  |  972 lines

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