Source for file XMLDocBookpeardoc2Converter.inc

Documentation is available at XMLDocBookpeardoc2Converter.inc

  1. <?php
  2. /**
  3.  * Outputs documentation in XML DocBook format, in the version expected by
  4.  * pear.php.net's documentation team
  5.  *
  6.  * phpDocumentor :: automatic documentation generator
  7.  * 
  8.  * PHP versions 4 and 5
  9.  *
  10.  * Copyright (c) 2002-2006 Gregory Beaver
  11.  * 
  12.  * LICENSE:
  13.  * 
  14.  * This library is free software; you can redistribute it
  15.  * and/or modify it under the terms of the GNU Lesser General
  16.  * Public License as published by the Free Software Foundation;
  17.  * either version 2.1 of the License, or (at your option) any
  18.  * later version.
  19.  * 
  20.  * This library is distributed in the hope that it will be useful,
  21.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  23.  * Lesser General Public License for more details.
  24.  * 
  25.  * You should have received a copy of the GNU Lesser General Public
  26.  * License along with this library; if not, write to the Free Software
  27.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  28.  *
  29.  * @package    Converters
  30.  * @subpackage XMLDocBook
  31.  * @author     Greg Beaver <[email protected]>
  32.  * @copyright  2002-2006 Gregory Beaver
  33.  * @license    http://www.opensource.org/licenses/lgpl-license.php LGPL
  34.  * @version    CVS: $Id: XMLDocBookpeardoc2Converter.inc 234423 2007-04-24 21:32:15Z ashnazg $
  35.  * @filesource
  36.  * @link       http://www.phpdoc.org
  37.  * @link       http://pear.php.net/PhpDocumentor
  38.  * @since      1.2
  39.  */
  40. /**
  41.  * XML DocBook converter.
  42.  * This Converter takes output from the {@link Parser} and converts it to DocBook
  43.  * output for PEAR documentation.
  44.  *
  45.  * This Converter differs from the parent DocBook Converter in that it does not
  46.  * recognize the possibility of procedural pages or of functions!  All functions
  47.  * must be defined as static methods for namespace purposes.  In addition, all
  48.  * constants and global variables for a package are grouped together as per
  49.  * peardoc2 requirements.  Include statements are not documented.  If you want
  50.  * to document a normal project, don't use the peardoc2 converter, use the
  51.  * DocBook converter.
  52.  * @package Converters
  53.  * @subpackage XMLDocBook
  54.  * @author Greg Beaver <[email protected]>
  55.  * @since 1.2
  56.  * @version $Id: XMLDocBookpeardoc2Converter.inc 234423 2007-04-24 21:32:15Z ashnazg $
  57.  */
  58. {
  59.     /**
  60.      * This converter knows about the new root tree processing
  61.      * In order to fix PEAR Bug #6389
  62.      * @var boolean 
  63.      */
  64.     var $processSpecialRoots = true;
  65.     /**
  66.      * XMLDocBookConverter wants elements sorted by type as well as alphabetically
  67.      * @see Converter::$sort_page_contents_by_type
  68.      * @var boolean 
  69.      */
  70.     var $sort_page_contents_by_type = true;
  71.     /** @var string */
  72.     var $outputformat = 'XML';
  73.     /** @var string */
  74.     var $name = 'DocBook/peardoc2';
  75.     /**
  76.      * indexes of elements by package that need to be generated
  77.      * @var array 
  78.      */
  79.     var $leftindex = array('classes' => true'pages' => false'functions' => false'defines' => true'globals' => true);
  80.     /**
  81.      * whether a @see is going to be in the {@link $base_dir}, or in a package/subpackage subdirectory of $base_dir
  82.      * @var boolean 
  83.      */
  84.     var $local = true;
  85.     
  86.     /**
  87.      * name of current page being converted
  88.      * @var string 
  89.      */
  90.     var $page;
  91.     
  92.     /**
  93.      * path of current page being converted
  94.      * @var string 
  95.      */
  96.     var $path;
  97.     
  98.     /**
  99.      * name of current class being converted
  100.      * @var string 
  101.      */
  102.     var $class;
  103.     
  104.     /**
  105.      * template for the procedural page currently being processed
  106.      * @var Template 
  107.      */
  108.     var $page_data;
  109.     
  110.     /**
  111.      * output directory for the current procedural page being processed
  112.      * @var string 
  113.      */
  114.     var $page_dir;
  115.  
  116.     /**
  117.      * Constants, used for constants.tpl
  118.      * @var array 
  119.      */
  120.     var $_peardoc2_constants = false;
  121.     
  122.     /**
  123.      * Global Variables, used for globals.tpl
  124.      * @var array 
  125.      */
  126.     var $_peardoc2_globals = false;
  127.     
  128.     /**
  129.      * target directory passed on the command-line.
  130.      * {@link $targetDir} is malleable, always adding package/ and package/subpackage/ subdirectories onto it.
  131.      * @var string 
  132.      */
  133.     var $base_dir;
  134.     
  135.     /**
  136.      * output directory for the current class being processed
  137.      * @var string 
  138.      */
  139.     var $class_dir;
  140.     
  141.     /**
  142.      * template for the class currently being processed
  143.      * @var Template 
  144.      */
  145.     var $class_data;
  146.     
  147.     /**
  148.      * array of converted package page names.
  149.      * Used to link to the package page in the left index
  150.      * @var array Format: array(package => 1)
  151.      */
  152.     var $package_pages = array();
  153.     
  154.     /**
  155.      * Contents of the packagename.xml file are stored in this template variable
  156.      * @var Smarty 
  157.      */
  158.     var $packagexml;
  159.     /**
  160.      * controls formatting of parser informative output
  161.      * 
  162.      * Converter prints:
  163.      * "Converting /path/to/file.php... Procedural Page Elements... Classes..."
  164.      * Since HTMLdefaultConverter outputs files while converting, it needs to send a \n to start a new line.  However, if there
  165.      * is more than one class, output is messy, with multiple \n's just between class file output.  This variable prevents that
  166.      * and is purely cosmetic
  167.      * @var boolean 
  168.      */
  169.     var $juststarted = false;
  170.     
  171.     /**
  172.      * contains all of the template procedural page element loop data needed for the current template
  173.      * @var array 
  174.      */
  175.     var $current;
  176.     
  177.     /**
  178.      * contains all of the template class element loop data needed for the current template
  179.      * @var array 
  180.      */
  181.     var $currentclass;
  182.     
  183.     /** 
  184.      * Pass elements by package, simplifies generation of package.xml/category.xml
  185.      */
  186.     var $sort_absolutely_everything = true;
  187.     /**
  188.      * template options.  Currently only 1 recognized option usepear
  189.      *
  190.      * usepear tells the getLink() function to return a package link to PEAR and PEAR_ERROR if possible, and to link directly
  191.      * to the fully-delimited link package#class.method or package#file.method in PEAR style, if possible, even if the
  192.      * package is not parsed.  This will allow parsing of separate PEAR packages without parsing the entire thing at once!
  193.      * @var array 
  194.      */
  195.     var $template_options = array('usepear' => false);
  196.     
  197.     var $function_data = array();
  198.     var $method_data = array();
  199.     var $_write_constants_xml = array();
  200.     var $_write_globals_xml = array();
  201.     var $sourceloc = '';
  202.     /**
  203.      * peardoc2 Category
  204.      * @var string 
  205.      */
  206.     var $category;
  207.     /**
  208.      * Used to re-format output so that it's easy for translators to handle
  209.      * 
  210.      * @var XML_Beautifier|false
  211.      * @access private
  212.      */
  213.     var $_beautifier false;
  214.  
  215.     /**
  216.      * sets {@link $base_dir} to $targetDir
  217.      * @see Converter()
  218.      */
  219.     function XMLDocBookpeardoc2Converter(&$allp&$packp&$classes&$procpages$po$pp$qm$targetDir$templateDir$title)
  220.     {
  221.         if (!class_exists('XML_Beautifier')) {
  222.             @include_once 'XML/Beautifier.php';
  223.         }
  224.         Converter::Converter($allp$packp$classes$procpages,$po$pp$qm$targetDir$templateDir$title);
  225.         if (class_exists('XML_Beautifier')) {
  226.             require_once 'phpDocumentor/Converters/XML/DocBook/peardoc2/Beautifier.php';
  227.             $this->_beautifier new phpDocumentor_peardoc2_XML_Beautifier;
  228.             $this->_beautifier->setOption('indent'' ');
  229.         }
  230.         $this->base_dir = $targetDir;
  231.     }
  232.     
  233.     /**
  234.      * do that stuff in $template_options
  235.      */
  236.     function &getLink($expr$package false$packages false)
  237.     {
  238.         return Converter::getLink($expr$package$packages);
  239.     }
  240.     
  241.     function unmangle($s,$sourcecode)
  242.     {
  243.         return '<programlisting role="php"><![CDATA[
  244. '.$sourcecode.']]></programlisting>';
  245.     }
  246.  
  247.     /**
  248.      * Writes a file to target dir, beautify any .xml files first
  249.      * @param string filename
  250.      * @param string file contents
  251.      * @param boolean true if the data is binary and not text
  252.      */
  253.     function writeFile($file,$data,$binary false)
  254.     {
  255.         if ($this->_beautifier && substr($file-4== '.xml'{
  256.             $ret $this->_beautifier->formatString($data);
  257.             if (PEAR::isError($ret)) {
  258.                 addWarning(PDERROR_BEAUTIFYING_FAILED$ret->getMessage());
  259.                 $ret $data;
  260.             }
  261.             $data $ret;
  262.         }
  263.         return parent::writeFile($file$data$binary);
  264.     }
  265.     
  266.     /**
  267.      * Used to convert the {@}example} inline tag in a docblock.
  268.      * 
  269.      * By default, this just wraps ProgramExample
  270.      * @see XMLDocBookpeardoc2Converter::exampleProgramExample
  271.      * @param string 
  272.      * @param boolean true if this is to highlight a tutorial <programlisting>
  273.      * @return string 
  274.      */
  275.     function exampleProgramExample($example$tutorial false$inlinesourceparse null/*false*/,
  276.                             $class null/*false*/$linenum null/*false*/$filesourcepath null/*false*/)
  277.     {
  278.         return '<example><title>Example</title><programlisting role="php"><![CDATA[' .
  279.          $example ']]></programlisting></example>';
  280.         $this->ProgramExample($example$tutorial$inlinesourceparse$class$linenum$filesourcepath)
  281.         . '</example>';
  282.     }
  283.     
  284.     function writeExample($title$path$source)
  285.     {
  286.         $this->_save_example array($title$source);
  287.     }
  288.     
  289.     function getExampleLink($unused$title)
  290.     {
  291.         $source $this->_save_example[1];
  292.         return '<para><example><title>' $title '</title>' $source '</example></para>';
  293.     }
  294.     
  295.     function type_adjust($typename)
  296.     {
  297.         if (isset($this->template_options['typechanging'][trim($typename)]))
  298.         return $this->template_options['typechanging'][trim($typename)];
  299.         $a $this->getLink($typename);
  300.         if (is_object($a))
  301.         {
  302.             if (phpDocumentor_get_class($a== 'classlink')
  303.             return '<classname>'.$typename.'</classname>';
  304.             if (phpDocumentor_get_class($a== 'functionlink' || phpDocumentor_get_class($a== 'methodlink')
  305.             return '<function>'.$typename.'</function>';
  306.             if (phpDocumentor_get_class($a== 'definelink')
  307.             return '<constant>'.$typename.'</constant>';
  308.             if (phpDocumentor_get_class($a== 'varlink')
  309.             return '<varname>'.$typename.'</varname>';
  310.         }
  311.         return $typename;
  312.     }
  313.     
  314.     /**
  315.      * Writes out the template file of {@link $class_data} and unsets the template to save memory
  316.      * @see registerCurrentClass()
  317.      * @see parent::endClass()
  318.      * @todo move class summary into an array to be written out at the end
  319.      *        of parsing each package
  320.      */
  321.     function endClass()
  322.     {
  323.         $a '../';
  324.         if (!empty($this->subpackage)) $a .= '../';
  325.         if ($this->juststarted)
  326.         {
  327.             $this->juststarted = false;
  328.             phpDocumentor_out("\n");
  329.             flush();
  330.         }
  331.         foreach($this->method_data as $func)
  332.         {
  333.             $func[0]->assign("phpdocversion",PHPDOCUMENTOR_VER);
  334.             $func[0]->assign("phpdocwebsite",PHPDOCUMENTOR_WEBSITE);
  335.             $this->setTargetDir($this->base_dir . PATH_DELIMITER strtolower($this->categoryPATH_DELIMITER strtolower($this->class_dir . PATH_DELIMITER str_replace(array('_','.'),array('-','--'),$this->class)));
  336.             $this->writefile(strtolower($func[1)'.xml','<!-- $' "Revision$ -->\n" $func[0]->fetch('method.tpl'));
  337.         }
  338.         // code below is in packagename.xml handling, see Output()
  339. /*        $this->setTargetDir($this->base_dir . PATH_DELIMITER . strtolower($this->category) . PATH_DELIMITER . strtolower($this->class_dir));
  340.         $this->writefile(str_replace(array('_','.'),array('-','--'),strtolower($this->class)) . '.xml',$this->class_data->fetch('class.tpl'));*/
  341.         unset($this->class_data);
  342.     }
  343.     
  344.     function addSummaryToPackageXml($template_output)
  345.     {
  346.         $this->packagexml->append('ids',$template_output);
  347.     }
  348.     
  349.     /**
  350.      * @param parserClass|false$element is false if this is the end of all conversion
  351.      */
  352.     function flushPackageXml($element)
  353.     {
  354.         if (isset($this->packagexml))
  355.         {
  356.             if (!$element || $element->docblock->package != $this->package// finished with package
  357.             {
  358.                 if (isset($this->_write_constants_xml[$this->category][$this->package]&&
  359.                     $this->_write_constants_xml[$this->category][$this->package])
  360.                 {
  361.                     $this->packagexml->append('ids',
  362.                         '&package.' .
  363.                          strtolower($this->category.'.' .
  364.                          str_replace(array('_','.'),array('-','--'),$this->package).'.constants;'));
  365.                     $this->_write_constants_xml[$this->category][$this->packagefalse;
  366.                 }
  367.                 if (isset($this->_write_globals_xml[$this->category][$this->package]&&
  368.                     $this->_write_globals_xml[$this->category][$this->package])
  369.                 {
  370.                     $this->packagexml->append('ids',
  371.                             '&package.'.strtolower($this->category.'.' 
  372.                              str_replace(array('_','.'),array('-','--'),$this->package).'.globals;'));
  373.                     $this->_write_globals_xml[$this->category][$this->packagefalse;
  374.                 }
  375.                 $this->setTargetDir($this->base_dir . PATH_DELIMITER strtolower($this->category));
  376.                 $this->writefile(str_replace('_','-',strtolower($this->package)).'.xml',
  377.                     '<!-- $' "Revision$ -->\n" $this->packagexml->fetch('package.tpl'));
  378.                 $this->packagexml->clear_all_assign();
  379.                 if ($element{
  380.                     $this->packagexml->assign('package',$element->docblock->package);
  381.                     $this->packagexml->assign('ids',array());
  382.                     $this->packagexml->assign('id',$this->getId($elementtrue));
  383.                 }
  384.             }
  385.         else
  386.         {
  387.             $this->packagexml = $this->newSmarty();
  388.             $this->packagexml->assign('package',$element->docblock->package);
  389.             $this->packagexml->assign('ids',array());
  390.             $this->packagexml->assign('id',$this->getId($elementtrue));
  391.         }
  392.     }
  393.     
  394.     /**
  395.      * @param string 
  396.      * @param string 
  397.      * @return string <ulink url="'.$link.'">'.$text.'</ulink>
  398.      */
  399.     function returnLink($link,$text)
  400.     {
  401.         return '<ulink url="'.$link.'">'.$text.'</ulink>';
  402.     }
  403.     
  404.     function makeLeft()
  405.     {
  406.     }
  407.     
  408.     /**
  409.      * Does nothing
  410.      */
  411.     function formatPkgIndex()
  412.     {
  413.     }
  414.     
  415.     /**
  416.      * Does nothing
  417.      */
  418.     function formatIndex()
  419.     {
  420.     }
  421.  
  422.     /**
  423.      * Does nothing
  424.      */
  425.     function writeNewPPage($key)
  426.     {
  427.     }
  428.     
  429.     /**
  430.      * Does nothing
  431.      */
  432.     function writeSource()
  433.     {
  434.     }
  435.     
  436.     /**
  437.      * Creates package/lang/categoryname/packagename.xml for each package
  438.      */
  439.     function formatLeftIndex()
  440.     {
  441.         $this->makeLeft();
  442.     }
  443.     
  444.     /**
  445.      * This function takes an {@link abstractLink} descendant and returns an html link
  446.      *
  447.      * @param abstractLink a descendant of abstractlink should be passed, and never text
  448.      * @param string text to display in the link
  449.      * @param boolean this parameter is not used, and is deprecated
  450.      * @param boolean determines whether the returned text is enclosed in an <link> tag
  451.      */
  452.     function returnSee(&$element$eltext false$local true$with_a true)
  453.     {
  454.         if (!$elementreturn false;
  455.         if (!$eltext)
  456.         {
  457.             $eltext '';
  458.             switch($element->type)
  459.             {
  460.                 case 'tutorial' :
  461.                 $eltext $element->title;
  462.                 break;
  463.                 case 'class' :
  464.                 $eltext '<classname>'.$element->name.'</classname>';
  465.                 break;
  466.                 case 'method' :
  467.                 $eltext .= '<function>';
  468.                 case 'var' :
  469.                 if ($element->type == 'var'$eltext .= '<varname>';
  470.                 $eltext .= $element->class.'::';
  471.                 case 'page' :
  472.                 case 'define' :
  473.                 if ($element->type == 'define')
  474.                 $eltext .= '<constant>';
  475.                 case 'function' :
  476.                 if ($element->type == 'function')
  477.                 $eltext .= '<function>';
  478.                 case 'global' :
  479.                 default :
  480.                 $eltext .= $element->name;
  481.                 if ($element->type == 'function' || $element->type == 'method'$eltext .= '</function>';
  482.                 if ($element->type == 'var'$eltext .= '</varname>';
  483.                 if ($element->type == 'define'$eltext .= '</constant>';
  484.                 break;
  485.             }
  486.         elseif (!is_object($element)) {
  487.             return false;
  488.         elseif ($element->type == 'method')
  489.         {
  490.             $eltext str_replace($element->name '()'$element->name$eltext);
  491.         }
  492.  
  493.         if ($element->type == 'page' || $element->type == 'function' || $element->type == 'var')
  494.         // we ignore all procedural pages, instead, constant, function and
  495.           // global variable pages are output
  496.             return $eltext;
  497.         }
  498.         if ($element->type == 'class')
  499.         {
  500.             return '<link linkend="'.$this->getId($element).'-summary">'.$eltext.'</link>';
  501.         }
  502.         return '<link linkend="'.$this->getId($element).'">'.$eltext.'</link>';
  503.     }
  504.     
  505.     /**
  506.      * Get the id value needed to allow linking
  507.      * @param mixed descendant of parserElement or parserData/parserPage
  508.      * @param boolean true to return the id for the package page
  509.      * @see parserElement, parserData, parserPage
  510.      * @return string the id value for this element type
  511.      */
  512.     function getId(&$el$returnpackage false)
  513.     {
  514.         if (phpDocumentor_get_class($el== 'parserdata')
  515.         {
  516.             $element $this->addLink($el->parent);
  517.             $elp $el->parent;
  518.         elseif (!is_a($el,'abstractlink'))
  519.         {
  520.             $elp $el;
  521.             $element $this->addLink($el);
  522.         else $element $el;
  523.         $a '';
  524.         if (!empty($element->subpackage))
  525.         {
  526.             $a str_replace(array('_','.'),array('-','--'),$element->subpackage).'.';
  527.         }
  528.         if ($returnpackagereturn 'package.'.strtolower($element->category.'.'.str_replace(array('_','.'),array('-','--'),$element->package));
  529.         switch ($element->type)
  530.         {
  531.             case 'page' :
  532.             return 'package.'.strtolower($element->category.'.'.str_replace(array('_','.'),array('-','--'),$element->package).'.'.$a.$element->fileAlias);
  533.             break;
  534.             case 'define' :
  535.             return 'package.'.strtolower($element->category.'.'.str_replace(array('_','.'),array('-','--'),$element->package).'.constants.details.'.$element->fileAlias);
  536.             break;
  537.             case 'global' :
  538.             return 'package.'.strtolower($element->category.'.'.str_replace(array('_','.'),array('-','--'),$element->package).'.globals.details.'.$element->fileAlias);
  539.             break;
  540.             case 'class' :
  541.             return 'package.'.strtolower($element->category.'.'.str_replace(array('_','.'),array('-','--'),$element->package).'.'.$a.str_replace(array('_','.'),array('-','--'),$element->name));
  542.             break;
  543.             case 'function' :
  544.             return 'package.'.strtolower($element->category.'.'.str_replace(array('_','.'),array('-','--'),$element->package).'.'.$a.$element->fileAlias.'.'.str_replace('_','-',$element->name));
  545.             break;
  546.             case 'method' :
  547.             return 'package.'.strtolower($element->category.'.'.str_replace(array('_','.'),array('-','--'),$element->package).'.'.$a.str_replace(array('_','.'),array('-','--'),$element->class).'.'.str_replace('_','-',$element->name));
  548.             break;
  549.             case 'var' :
  550.             return 'package.'.strtolower($element->category.'.'.str_replace(array('_','.'),array('-','--'),$element->package).'.'.$a.str_replace(array('_','.'),array('-','--'),$element->class).'-summary.vars.'.str_replace(array('$','_'),array('var--','-'),$element->name));
  551.             break;
  552.             case 'tutorial' :
  553.             return 'package.'.strtolower($element->category.'.'.str_replace(array('_','.'),array('-','--'),$element->package).'.'.$a.str_replace(array('_','.'),array('-','--'),$element->name)).'-tutorial';
  554.             break;
  555.         }
  556.     }
  557.  
  558.     /**
  559.      * Create errors.html template file output
  560.      *
  561.      * This method takes all parsing errors and warnings and spits them out ordered by file and line number.
  562.      * @global ErrorTracker We'll be using it's output facility
  563.      */
  564.     function ConvertErrorLog()
  565.     {
  566.         global $phpDocumentor_errors;
  567.         $allfiles array();
  568.         $files array();
  569.         $warnings $phpDocumentor_errors->returnWarnings();
  570.         $errors $phpDocumentor_errors->returnErrors();
  571.         $template &$this->newSmarty();
  572.         foreach($warnings as $warning)
  573.         {
  574.             $file '##none';
  575.             $linenum 'Warning';
  576.             if ($warning->file)
  577.             {
  578.                 $file $warning->file;
  579.                 $allfiles[$file1;
  580.                 $linenum .= ' on line '.$warning->linenum;
  581.             }
  582.             $files[$file]['warnings'][array('name' => $linenum'listing' => $warning->data);
  583.         }
  584.         foreach($errors as $error)
  585.         {
  586.             $file '##none';
  587.             $linenum 'Error';
  588.             if ($error->file)
  589.             {
  590.                 $file $error->file;
  591.                 $allfiles[$file1;
  592.                 $linenum .= ' on line '.$error->linenum;
  593.             }
  594.             $files[$file]['errors'][array('name' => $linenum'listing' => $error->data);
  595.         }
  596.         $i=1;
  597.         $af array();
  598.         foreach($allfiles as $file => $num)
  599.         {
  600.             $af[$i++$file;
  601.         }
  602.         $allfiles $af;
  603.         usort($allfiles,'strnatcasecmp');
  604.         $allfiles[0"Post-parsing";
  605.         foreach($allfiles as $i => $a)
  606.         {
  607.             $allfiles[$iarray('file' => $a);
  608.         }
  609.         $out array();
  610.         foreach($files as $file => $data)
  611.         {
  612.             if ($file == '##none'$file 'Post-parsing';
  613.             $out[$file$data;
  614.         }
  615.         $template->assign("files",$allfiles);
  616.         $template->assign("all",$out);
  617.         $template->assign("title","phpDocumentor Parser Errors and Warnings");
  618.         $this->setTargetDir($this->base_dir);
  619.         $this->writefile("errors.html",$template->fetch('errors.tpl'));
  620.         unset($template);
  621.         phpDocumentor_out("\n\nTo view errors and warnings, look at ".$this->base_dirPATH_DELIMITER "errors.html\n");
  622.         flush();
  623.     }
  624.     
  625.     function postProcess($text)
  626.     {
  627.         return str_replace("'"'&apos;'htmlentities($text));
  628.     }
  629.  
  630.     function prepareDocBlock(&$element$nopackage true)
  631.     {
  632.         $a new parserStringWithInlineTags;
  633.         $a->add('no exceptions thrown');
  634.         if (!$element->docblock->getKeyword('throws')) $element->docblock->addKeyword('throws',$a);
  635.         $tags parent::prepareDocBlock($element,
  636.                 array('staticvar' => 'note','deprec' => 'deprecated',
  637.                       'abstract' => 'abstract','TODO' => 'note''link' => 'see',
  638.                       'uses' => 'see''usedby' => 'see''tutorial' => 'see',
  639.                       'return' => 'returns''access' => false)$nopackage);
  640.         $ret array();
  641.         foreach($tags['tags'as $tag)
  642.         {
  643.             if ($tag['keyword'== 'return')
  644.             {
  645.                 // hack because stupid Converter isn't doing its job
  646.                 $tag['keyword''returns';
  647.             }
  648.             $ret[$tag['keyword']][$tag;
  649.         }
  650.         $tags['tags'$ret;
  651.         $tags['sdesc'$this->wordwrap($tags['sdesc']);
  652.         return $tags;
  653.     }
  654.     
  655.     function getTutorialId($package,$subpackage,$tutorial,$id,$category)
  656.     {
  657.         $subpackage (empty($subpackage'' '.'.$subpackage);
  658.         $id (empty($id'' '.'.$id);
  659.         return 'package.'.strtolower($category.'.'.$package.$subpackage.str_replace(array('_','.'),array('-','--'),$tutorial).$id);
  660.     }
  661.     
  662.     
  663.     /**
  664.      * Retrieve a Converter-specific anchor to a segment of a source code file
  665.      * parsed via a {@tutorial tags.filesource.pkg} tag.
  666.      *
  667.      * NOTE: unused
  668.      * @param string full path to source file
  669.      * @param string name of anchor
  670.      * @param string link text, if this is a link
  671.      * @param boolean returns either a link or a destination based on this
  672.      *                 parameter
  673.      * @return string link to an anchor, or the anchor
  674.      */
  675.     function getSourceAnchor($sourcefile,$anchor,$text '',$link false)
  676.     {
  677.         return '';
  678.     }
  679.     
  680.     function Br($input)
  681.     {
  682.         return "$input\n";
  683.     }
  684.  
  685.     function getCData($value)
  686.     {
  687.         return '<![CDATA['.$value.']]>';
  688.     }
  689.     
  690.     function ProgramExample($listing$tutorial false$inlinesourceparse null/*false*/,
  691.                             $class null/*false*/$linenum null/*false*/$filesourcepath null/*false*/$origsource null)
  692.     {
  693.         if ($origsource !== null{
  694.             $listing $origsource;
  695.         }
  696.         if (!tokenizer_ext)
  697.         {
  698.             $listing $this->getCData($listing);
  699.         }
  700.         return '<programlisting role="php">' $this->getCData($listing'</programlisting>';
  701.     }
  702.     
  703.     /**
  704.      * Does nothing - use tutorials for DocBook
  705.      * @param parserPackagePage 
  706.      */
  707.     function convertPackagePage(&$element)
  708.     {
  709.     }
  710.     
  711.     /**
  712.      * Convert tutorials for output
  713.      * @param parserTutorial 
  714.      */
  715.     function convertTutorial(&$element)
  716.     {
  717.         $template &parent::convertTutorial($element);
  718.         phpDocumentor_out("\n");
  719.         flush();
  720.         $x $element->Convert($this,false);
  721.         if ($element->ini)
  722.         // add child tutorial list to the tutorial through a slight hack :)
  723.             $subtutorials '';
  724.             $b '';
  725.             if (!empty($element->subpackage)) $b '.'.$element->subpackage;
  726.             foreach($element->ini['Linked Tutorials'as $child)
  727.             {
  728.                 $subtutorials .= '      &'.$element->category.'.'.$element->package.$b.'.'.str_replace(array('_','.'),array('-','--'),$child).'-'.$element->tutorial_type."-tutorial;\n";
  729.             }
  730.             $x str_replace('</refsect1></refentry>','</refsect1>
  731.     <refsect1>
  732.      <title>Related Docs</title>
  733.      <para>
  734. '.$subtutorials.
  735. '     </para>
  736.     </refsect1></refentry>',$x);
  737.         }
  738.         $template->assign('contents',$x);
  739.         $contents $template->fetch('tutorial.tpl');
  740.         $a '';
  741.         if ($element->subpackage$a PATH_DELIMITER $element->subpackage;
  742.         phpDocumentor_out("\n");
  743.         flush();
  744.         $this->setTargetDir($this->base_dir . PATH_DELIMITER str_replace(array('_','.'),array('-','--'),strtolower($element->category))
  745.           . PATH_DELIMITER strtolower(str_replace(array('_','.'),array('-','--'),$element->package$a));
  746.         $this->writeFile(str_replace(array('_','.'),array('-','--'),strtolower($element->name)).'-tutorial.xml',
  747.             '<!-- $' "Revision$ -->\n" $contents);
  748.     }
  749.     
  750.     /**
  751.      * Does nothing in this converter
  752.      * @param parserVar 
  753.      */
  754.     function convertVar(&$element)
  755.     {
  756.         return;
  757.         $docblock $this->prepareDocBlock($element);
  758.         $b 'mixed';
  759.         if ($element->docblock->var)
  760.         {
  761.             $b $element->docblock->var->converted_returnType;
  762.         }
  763. //        var_dump($this->getFormattedOverrides($element));
  764.         if (isset($this->template_options['separatepage']&& $this->template_options['separatepage'])
  765.         $this->class_summary->append('vars',array('sdesc' => $docblock['sdesc'],
  766.                                                'desc' => $docblock['desc'],
  767.                                                'tags' => $docblock['tags'],
  768.                                                'var_name' => $this->type_adjust($element->getName()),
  769.                                                'var_default' => htmlspecialchars($element->getValue()),
  770.                                                'var_type' => $b,
  771.                                                'var_overrides' => $this->getFormattedOverrides($element),
  772.                                                'line_number' => $element->getLineNumber(),
  773.                                                'id' => $this->getId($element)));
  774.         else
  775.         $this->class_data->append('vars',array('sdesc' => $docblock['sdesc'],
  776.                                                'desc' => $docblock['desc'],
  777.                                                'tags' => $docblock['tags'],
  778.                                                'var_name' => $this->type_adjust($element->getName()),
  779.                                                'var_default' => htmlspecialchars($element->getValue()),
  780.                                                'var_type' => $b,
  781.                                                'var_overrides' => $this->getFormattedOverrides($element),
  782.                                                'line_number' => $element->getLineNumber(),
  783.                                                'id' => $this->getId($element)));
  784.     }
  785.     
  786.     /**
  787.      * Converts class for template output
  788.      * @param parserClass 
  789.      * @uses flushPackageXml() creates packagename.xml file when all classes in
  790.      *        a package have been converted
  791.      */
  792.     function convertClass(&$element)
  793.     {
  794.         $this->flushPackageXml($element);
  795.         parent::convertClass($element);
  796.         $docblock $this->prepareDocBlock($element);
  797.         $this->method_data = array();
  798.         $this->class_dir = str_replace(array('_','.'),array('-','--'),$element->docblock->package);
  799.         $this->package = $element->docblock->package;
  800.         $this->category = strtolower($element->docblock->category);
  801.         if (!empty($element->docblock->subpackage)) $this->class_dir .= PATH_DELIMITER $element->docblock->subpackage;
  802.         $docblock $this->prepareDocBlock($element,false);
  803.         $this->class_data->assign("sdesc",$docblock['sdesc']);
  804.         $this->class_data->assign("desc",$docblock['desc']);
  805.         $this->class_data->assign("tags",$docblock['tags']);
  806.  
  807.         $this->class_data->assign("source_location",$element->getSourceLocation($this,$this->template_options['usepear']));
  808.         $this->class_data->assign("id",$this->getId($element));
  809.         $this->class_data->assign("method_ids",array());
  810.         $this->left[$this->package][array('link' => $this->getId($element).'-summary');
  811.         if ($t $element->getTutorial())
  812.         {
  813.             $this->class_data->append("method_ids",$this->getId($t));
  814.         }
  815.  
  816.         if (isset($this->template_options['separatepage']&& $this->template_options['separatepage'])
  817.         {
  818.             $this->class_summary &$this->newSmarty(true);
  819.             if ($t $element->getTutorial())
  820.             {
  821.                 $this->class_summary->assign("tutorial",$this->returnSee($t));
  822.             }
  823.  
  824.             $this->class_summary->assign("class_name",$this->type_adjust($element->getName()));
  825.             $this->class_summary->assign("sdesc",$docblock['sdesc']);
  826.             $this->class_summary->assign("desc",$docblock['desc']);
  827.             $this->class_summary->assign("tags",$docblock['tags']);
  828.             $this->class_summary->assign("vars",array());
  829.             $this->class_summary->assign("methods",array());
  830.             $this->class_summary->assign("package",$element->docblock->package);
  831.  
  832.             $this->class_summary->assign("children"$this->generateChildClassList($element));
  833.             $this->class_summary->assign("class_tree"$this->generateFormattedClassTree($element));
  834.             $this->class_summary->assign("conflicts"$this->getFormattedConflicts($element,"classes"));
  835.         
  836.             $this->class_summary->assign("source_location",$element->getSourceLocation($this,$this->template_options['usepear']));
  837.             $this->class_summary->assign("id",$this->getId($element).'-summary');
  838.             $this->class_data->append("method_ids",$this->getId($element).'.'.strtolower(str_replace('_','-',$element->getName())).'-summary');
  839.             $inherited_methods $this->getFormattedInheritedMethods($element);
  840.             if (!empty($inherited_methods))
  841.             {
  842.                 $this->class_summary->assign("imethods",$inherited_methods);
  843.             }
  844.             $inherited_vars $this->getFormattedInheritedVars($element);
  845.             // variables are irrelevant in peardoc2
  846.             if (false)//!empty($inherited_vars))
  847.             {
  848.                 $this->class_summary->assign("ivars",$inherited_vars);
  849.             }
  850.             $this->addSummaryToPackageXml($this->class_summary->fetch('class_summary.tpl'));
  851.         }
  852.         $this->sourceloc = $element->getSourceLocation($this,$this->template_options['usepear']);
  853.     }
  854.     
  855.     /**
  856.      * Converts method for template output
  857.      * @see prepareDocBlock(), parserMethod::getFunctionCall(), getFormattedDescMethods(), getFormattedOverrides()
  858.      * @param parserMethod 
  859.      */
  860.     function convertMethod(&$element)
  861.     {
  862.         $docblock $this->prepareDocBlock($element);
  863.         $returntype 'void';
  864.         if ($element->docblock->return)
  865.         {
  866.             $a $element->docblock->return->Convert($this);
  867.             $returntype $element->docblock->return->converted_returnType;
  868.             if ($returntype != $element->docblock->return->returnType)
  869.             {
  870.                 $returntype "<replaceable>$returntype</replaceable>";
  871.             }
  872.         }
  873.         $params array();
  874.         if (count($element->docblock->params))
  875.         foreach($element->docblock->params as $param => $val)
  876.         {
  877.             $a $val->Convert($this);
  878.             $b explode(' ',$a);
  879.             $c '';
  880.             foreach($b as $blah{
  881.                 if (!empty($c)) {
  882.                     $c .= ' ';
  883.                 }
  884.                 $c .= str_replace(array('true''false''null')array('&true;''&false;''&null;')$blah);
  885.             }
  886.             $params[$paramarray("var" => $param,"datatype" => str_replace(array('true''false''null')array('&true;''&false;''&null;')
  887.                 $val->returnType)"cdatatype" => $val->converted_returnType,"data" => $this->wordwrap($c));
  888.         }
  889.  
  890.         $call $element->getIntricateFunctionCall($this$params);
  891.         if (isset($call['params']))
  892.         {
  893.             foreach($call['params'as $i => $param)
  894.             {
  895.                 if (!is_string($call['params'][$i]['default']))
  896.                 {
  897.                     continue;
  898.                 }
  899.                 $call['params'][$i]['default'str_replace(array('true''false''null')array('&true;''&false;''&null;')$param['default']);
  900.             }
  901.         }
  902.         $this->packagexml->append('ids','&'.$this->getId($element).';');
  903.         $this->class_data->append('method_ids',$this->getId($element));
  904.         $this->class_summary->append('methods',array('id' => $this->getId($element),
  905.                                                   'sdesc' => $docblock['sdesc'],
  906.                                                   'desc' => $docblock['desc'],
  907.                                                   'tags' => $docblock['tags'],
  908.                                                   'is_constructor' => $element->isConstructor,
  909.                                                   'function_name' => $element->getName(),
  910.                                                   'function_return' => $returntype,
  911.                                                   'function_call' => $call,
  912.                                                   'descmethod' => $this->getFormattedDescMethods($element),
  913.                                                   'method_overrides' => $this->getFormattedOverrides($element),
  914.                                                   'line_number' => $element->getLineNumber(),
  915.                                                   'params' => $params));
  916.         $this->method_data[$i count($this->method_data1][0&$this->newSmarty(true);
  917.         $this->method_data[$i][1str_replace(array('_','.'),array('-','--'),$element->getName());
  918.         $this->method_data[$i][0]->assign('class',$this->class);
  919.         $this->method_data[$i][0]->assign('source_location',$this->returnSee($this->getLink(basename($this->curpage->getFile())),$this->sourceloc));
  920.         $this->method_data[$i][0]->assign('sdesc',$docblock['sdesc']);
  921.         $this->method_data[$i][0]->assign('desc',$docblock['desc']);
  922.         $this->method_data[$i][0]->assign('tags',$docblock['tags']);
  923.         $this->method_data[$i][0]->assign('function_name',$element->getName());
  924.         $this->method_data[$i][0]->assign('function_return',$returntype);
  925.         $this->method_data[$i][0]->assign('function_call',$call);
  926.         $this->method_data[$i][0]->assign('descmethod',$this->getFormattedDescMethods($element));
  927.         $this->method_data[$i][0]->assign('method_overrides',$this->getFormattedOverrides($element));
  928.         $this->method_data[$i][0]->assign('params',$params);
  929.         $this->method_data[$i][0]->assign('id',$this->getId($element));
  930.     }
  931.     
  932.     /**
  933.      * Converts function for template output - does nothing in peardoc2!
  934.      * @param parserFunction 
  935.      */
  936.     function convertFunction(&$element)
  937.     {
  938. /*        parent::convertFunction($element);
  939.         $docblock = $this->prepareDocBlock($element);
  940.         $fname = $element->getName();
  941.         $params = array();
  942.         if (count($element->docblock->params))
  943.         foreach($element->docblock->params as $param => $val)
  944.         {
  945.             $a = $val->Convert($this);
  946.             $params[$param] = array("var" => $param,"datatype" => $val->converted_returnType,"data" => $a);
  947.         }
  948.         $returntype = 'void';
  949.         if ($element->docblock->return)
  950.         {
  951.             $a = $element->docblock->return->Convert($this);
  952.             $returntype = $element->docblock->return->converted_returnType;
  953.         }
  954.  
  955.         $this->page_data->append("function_ids",$this->getId($element));
  956.         $this->page_summary->append("function_ids",$this->getId($element));
  957.         $this->page_summary->append('functions',array('id' => $this->getId($element),
  958.                                                    'sdesc' => $docblock['sdesc'],
  959.                                                    'desc' => $docblock['desc'],
  960.                                                    'tags' => $docblock['tags'],
  961.                                                    'function_name' => $element->getName(),
  962.                                                    'line_number' => $element->getLineNumber(),
  963.                                                    'function_return' => $returntype,
  964.                                                    'function_call' => $element->getIntricateFunctionCall($this,$params),
  965.                                                    'function_conflicts' => $this->getFormattedConflicts($element,'functions'),
  966.                                                    'params' => $params));
  967.         $this->function_data[$i = count($this->function_data) - 1][0] = $this->newSmarty(true);
  968.         $this->function_data[$i][1] = $element->getName();
  969.         $this->function_data[$i][0]->assign('sdesc',$docblock['sdesc']);
  970.         $this->function_data[$i][0]->assign('desc',$docblock['desc']);
  971.         $this->function_data[$i][0]->assign('tags',$docblock['tags']);
  972.         $this->function_data[$i][0]->assign('function_name',$fname);
  973.         $this->function_data[$i][0]->assign('line_number',$element->getLineNumber());
  974.         $this->function_data[$i][0]->assign('function_return',$returntype);
  975.         $this->function_data[$i][0]->assign('function_call',$element->getIntricateFunctionCall($this,$params));
  976.         $this->function_data[$i][0]->assign('function_conflicts',$this->getFormattedConflicts($element,"functions"));
  977.         $this->function_data[$i][0]->assign('params',$params);
  978.         $this->function_data[$i][0]->assign('source_location',$this->returnSee($this->getLink(basename($this->curpage->getFile())),$this->sourceloc));
  979.         $this->function_data[$i][0]->assign('id',$this->getId($element));*/
  980.     }
  981.     
  982.     /**
  983.      * Converts include elements for template output
  984.      *
  985.      * Completely ignored by this converter
  986.      * @param parserInclude 
  987.      */
  988.     function convertInclude(&$element)
  989.     {
  990. /*        parent::convertInclude($element, array('include_file'    => '-'.strtr($element->getValue(),array('"' => '', "'" => '','.' => '-'))));
  991.         $docblock = $this->prepareDocBlock($element);
  992.         $per = $this->getIncludeValue($element->getValue(), $element->getPath());
  993.         $this->page_summary->append('includes',array('sdesc' => $docblock['sdesc'],
  994.                                                    'desc' => $docblock['desc'],
  995.                                                   'tags' => $docblock['tags'],
  996.                                                   'utags' => $docblock['utags'],
  997.                                                   'include_name'     => $element->getName(),
  998.                                                   'include_value'    => $per,
  999.                                                   'line_number' => $element->getLineNumber(),
  1000.                                                   'include_file'    => '-'.strtr($element->getValue(),array('"' => '', "'" => '','.' => '-'))));*/
  1001.     }
  1002.     
  1003.     /**
  1004.      * Converts defines for template output
  1005.      * @see prepareDocBlock(), getFormattedConflicts()
  1006.      * @param parserDefine 
  1007.      */
  1008.     function convertDefine(&$element)
  1009.     {
  1010.         $docblock $this->prepareDocBlock($element);
  1011.         $this->_appendDefines(array('sdesc' => $docblock['sdesc'],
  1012.                                    'desc' => $docblock['desc'],
  1013.                                    'tags' => $docblock['tags'],
  1014.                                    'name'     => $this->postProcess($element->getName()),
  1015.                                    'value'    => $this->postProcess($element->getValue()),
  1016.                                    'conflicts'    => $this->getFormattedConflicts($element,"defines"),
  1017.                                    'line_number' => $element->getLineNumber(),
  1018.                                    'id' => $this->getId($element)));
  1019.     }
  1020.     
  1021.     /**
  1022.      * Append the constant information to the Smarty information
  1023.      *
  1024.      * Uses category, package, and current file to organize constants defined
  1025.      * in a package for the constants.xml output file
  1026.      * @param array 
  1027.      * @uses $_peardoc2_constants appends $define to them
  1028.      * @access private
  1029.      */
  1030.     function _appendDefines($define)
  1031.     {
  1032.         if (!isset($this->_peardoc2_constants[$this->category][$this->package][$this->sourceloc]))
  1033.         {
  1034.             $this->_peardoc2_constants[$this->category][$this->package][$this->sourceloc]['name'
  1035.                 $this->sourceloc;
  1036.             $this->_peardoc2_constants[$this->category][$this->package][$this->sourceloc]['page'=
  1037.                 $this->page;
  1038.         }
  1039.         $this->_write_constants_xml[$this->category][$this->packagetrue;
  1040.         $this->_peardoc2_constants[$this->category][$this->package][$this->sourceloc]['defines'][$define;
  1041.     }
  1042.     
  1043.     /**
  1044.      * Converts global variables for template output
  1045.      * @param parserGlobal 
  1046.      * @see prepareDocBlock(), getFormattedConflicts()
  1047.      */
  1048.     function convertGlobal(&$element)
  1049.     {
  1050.         $docblock $this->prepareDocBlock($element);
  1051.         $value $this->getGlobalValue($element->getValue());
  1052.         if ($value == $element->getValue())
  1053.         {
  1054.             $value $this->ProgramExample($value);
  1055.         else
  1056.         {
  1057.             $value $this->getGlobalValue('<![CDATA[' .$element->getValue(']]>');
  1058.         }
  1059.         $this->_appendGlobals(array('sdesc' => $docblock['sdesc'],
  1060.                                    'desc' => $docblock['desc'],
  1061.                                    'tags' => $docblock['tags'],
  1062.                                    'name'     => $this->postProcess($element->getName()),
  1063.                                    'link'    => $element->getName(),
  1064.                                    'value'    => $value,
  1065.                                    'type' => $element->getDataType($this),
  1066.                                    'line_number' => $element->getLineNumber(),
  1067.                                    'conflicts'    => $this->getFormattedConflicts($element,"global variables"),
  1068.                                    'id' => $this->getId($element)));
  1069.     }
  1070.     
  1071.     /**
  1072.      * Append the global variable information to the Smarty information
  1073.      *
  1074.      * Uses category, package, and current file to organize globals defined
  1075.      * in a package for the globals.xml output file
  1076.      * @param array 
  1077.      * @uses $_peardoc2_globals appends $global to them
  1078.      * @access private
  1079.      */
  1080.     function _appendGlobals($global)
  1081.     {
  1082.         if (!isset($this->_peardoc2_globals[$this->category][$this->package][$this->sourceloc]))
  1083.         {
  1084.             $this->_peardoc2_globals[$this->category][$this->package][$this->sourceloc]['name'
  1085.                 $this->sourceloc;
  1086.             $this->_peardoc2_globals[$this->category][$this->package][$this->sourceloc]['page'=
  1087.                 $this->page;
  1088.         }
  1089.         $this->_write_globals_xml[$this->category][$this->packagetrue;
  1090.         $this->_peardoc2_globals[$this->category][$this->package][$this->sourceloc]['globals'][$global;
  1091.     }
  1092.     
  1093.     /**
  1094.      * converts procedural pages for template output
  1095.      * @see prepareDocBlock(), getClassesOnPage()
  1096.      * @param parserData 
  1097.      */
  1098.     function convertPage(&$element)
  1099.     {
  1100.         parent::convertPage($element);
  1101.         $this->juststarted = true;
  1102.         $this->page_dir = $element->parent->package;
  1103.         $this->page = $this->getPageName($element->parent);
  1104.         $this->category = strtolower($element->parent->category);
  1105.         $this->sourceloc = $element->parent->getSourceLocation($this,true);
  1106.         if (!empty($element->parent->subpackage)) $this->page_dir .= PATH_DELIMITER $element->parent->subpackage;
  1107.         // registering stuff on the template
  1108.     }
  1109.     
  1110.     function getPageName(&$element)
  1111.     {
  1112.         return str_replace(array('/','_','.'),array('-','-','---'),$element->getSourceLocation($this,true));
  1113.     }
  1114.  
  1115.     /**
  1116.      * returns an array containing the class inheritance tree from the root object to the class
  1117.      *
  1118.      * @param parserClass    class variable
  1119.      * @return array Format: array(root,child,child,child,...,$class)
  1120.      * @uses parserClass::getParentClassTree()
  1121.      */
  1122.     
  1123.     function generateFormattedClassTree($class)
  1124.     {
  1125.         $tree $class->getParentClassTree($this);
  1126.         $out '';
  1127.         if (count($tree1)
  1128.         {
  1129.             $result array($class->getName());
  1130.             $parent $tree[$class->getName()];
  1131.             while ($parent)
  1132.             {
  1133.                 if (is_string($parent)) {
  1134.                     $result[$parent;
  1135.                     break;
  1136.                 }
  1137.                 $subpackage $parent->docblock->subpackage;
  1138.                 $package $parent->docblock->package;
  1139.                 $x $parent;
  1140.                 if (is_object($parent))
  1141.                 $x $parent->getLink($this);
  1142.                 if (!$x$x $parent->getName();
  1143.                 $result[
  1144.                     $x;
  1145.                 if (is_object($parent))
  1146.                 $parent $tree[$parent->getName()];
  1147.                 elseif (isset($tree[$parent]))
  1148.                 $parent $tree[$parent];
  1149.             }
  1150.             return array_reverse($result);
  1151.         else
  1152.         {
  1153.             return array($class->getName());
  1154.         }
  1155.     }
  1156.     
  1157.     /**
  1158.      * returns a list of child classes
  1159.      *
  1160.      * @param parserClass class variable
  1161.      * @uses parserClass::getChildClassList()
  1162.      */
  1163.     
  1164.     function generateChildClassList($class)
  1165.     {
  1166.         $kids $class->getChildClassList($this);
  1167.         $list array();
  1168.         if (count($kids))
  1169.         {
  1170.             for($i=0$i<count($kids)$i++)
  1171.             {
  1172.                 $lt['link''<link linkend="'.$this->getId($kids[$i]'-summary">'$kids[$i]->getName().'</link>';
  1173.                 $lt['sdesc'$kids[$i]->docblock->getSDesc($this);
  1174.                 $list[$lt;
  1175.             }
  1176.         else return false;
  1177.         return $list;
  1178.     }
  1179.  
  1180.     /** @access private */
  1181.     function sortVar($a$b)
  1182.     {
  1183.         return strnatcasecmp($a->getName(),$b->getName());
  1184.     }
  1185.     
  1186.     /** @access private */
  1187.     function sortMethod($a$b)
  1188.     {
  1189.         if ($a->isConstructorreturn -1;
  1190.         if ($b->isConstructorreturn 1;
  1191.         return strnatcasecmp($a->getName(),$b->getName());
  1192.     }
  1193.  
  1194.     /**
  1195.      * returns a template-enabled array of class trees
  1196.      * 
  1197.      * @param    string    $package    package to generate a class tree for
  1198.      * @see $roots, HTMLConverter::getRootTree()
  1199.      */
  1200.     function generateFormattedClassTrees($package)
  1201.     {
  1202.         if (!isset($this->roots['normal'][$package]&&
  1203.               !isset($this->roots['special'][$package])) {
  1204.             return array();
  1205.         }
  1206.         $trees array();
  1207.         if (isset($this->roots['normal'][$package])) {
  1208.             $roots $this->roots['normal'][$package];
  1209.             for($i=0;$i<count($roots);$i++)
  1210.             {
  1211.                 $root $this->classes->getClassByPackage($roots[$i]$package);
  1212.                 if ($root && $root->isInterface()) {
  1213.                     continue;
  1214.                 }
  1215.                 $trees[array('class' => $roots[$i],'class_tree' => "<ul>\n".$this->getRootTree($this->getSortedClassTreeFromClass($roots[$i],$package,''),$package)."</ul>\n");
  1216.             }
  1217.         }
  1218.         if (isset($this->roots['special'][$package])) {
  1219.             $roots $this->roots['special'][$package];
  1220.             foreach ($roots as $parent => $classes{
  1221.                 $thistree '';
  1222.                 foreach ($classes as $classinfo{
  1223.                     $root $this->classes->getClassByPackage($classinfo$package);
  1224.                     if ($root && $root->isInterface()) {
  1225.                         continue;
  1226.                     }
  1227.                     $thistree .=
  1228.                         $this->getRootTree(
  1229.                             $this->getSortedClassTreeFromClass(
  1230.                                 $classinfo,
  1231.                                 $package,
  1232.                                 ''),
  1233.                             $package,
  1234.                             true);
  1235.                 }
  1236.                 if (!$thistree{
  1237.                     continue;
  1238.                 }
  1239.                 $trees[array(
  1240.                     'class' => $parent,
  1241.                     'class_tree' => "<ul>\n" $thistree "</ul>\n"
  1242.                 );
  1243.             }
  1244.         }
  1245.         return $trees;
  1246.     }
  1247.  
  1248.     /**
  1249.      * returns a template-enabled array of interface inheritance trees
  1250.      * 
  1251.      * @param    string    $package    package to generate a class tree for
  1252.      * @see $roots, HTMLConverter::getRootTree()
  1253.      */
  1254.     function generateFormattedInterfaceTrees($package)
  1255.     {
  1256.         if (!isset($this->roots['normal'][$package]&&
  1257.               !isset($this->roots['special'][$package])) {
  1258.             return array();
  1259.         }
  1260.         $trees array();
  1261.         if (isset($this->roots['normal'][$package])) {
  1262.             $roots $this->roots['normal'][$package];
  1263.             for($i=0;$i<count($roots);$i++)
  1264.             {
  1265.                 $root $this->classes->getClassByPackage($roots[$i]$package);
  1266.                 if ($root && !$root->isInterface()) {
  1267.                     continue;
  1268.                 }
  1269.                 $trees[array('class' => $roots[$i],'class_tree' => "<ul>\n".$this->getRootTree($this->getSortedClassTreeFromClass($roots[$i],$package,''),$package)."</ul>\n");
  1270.             }
  1271.         }
  1272.         if (isset($this->roots['special'][$package])) {
  1273.             $roots $this->roots['special'][$package];
  1274.             foreach ($roots as $parent => $classes{
  1275.                 $thistree '';
  1276.                 foreach ($classes as $classinfo{
  1277.                     $root $this->classes->getClassByPackage($classinfo$package);
  1278.                     if ($root && !$root->isInterface()) {
  1279.                         continue;
  1280.                     }
  1281.                     $thistree .=
  1282.                         $this->getRootTree(
  1283.                             $this->getSortedClassTreeFromClass(
  1284.                                 $classinfo,
  1285.                                 $package,
  1286.                                 ''),
  1287.                             $package,
  1288.                             true);
  1289.                 }
  1290.                 if (!$thistree{
  1291.                     continue;
  1292.                 }
  1293.                 $trees[array(
  1294.                     'class' => $parent,
  1295.                     'class_tree' => "<ul>\n" $thistree "</ul>\n"
  1296.                 );
  1297.             }
  1298.         }
  1299.         return $trees;
  1300.     }
  1301.     
  1302.     /**
  1303.      * return formatted class tree for the Class Trees page
  1304.      *
  1305.      * @param array $tree output from {@link getSortedClassTreeFromClass()}
  1306.      * @param string $package  package
  1307.      * @param boolean $nounknownparent if true, an object's parent will not be checked
  1308.      * @see Classes::$definitechild, generateFormattedClassTrees()
  1309.      * @return string 
  1310.      */
  1311.     function getRootTree($tree$package$noparent false)
  1312.     {
  1313.         if (!$treereturn '';
  1314.         $my_tree '';
  1315.         $cur '#root';
  1316.         $lastcur array(false);
  1317.         $kids array();
  1318.         $dopar false;
  1319.         if (!$noparent && $tree[$cur]['parent'])
  1320.         {
  1321.             $dopar true;
  1322.             if (!is_object($tree[$cur]['parent']))
  1323.             {
  1324. //                debug("parent ".$tree[$cur]['parent']." not found");
  1325.                 $my_tree .= '<listitem>' $tree[$cur]['parent'.'<itemizedlist>';
  1326.             }
  1327.             else
  1328.             {
  1329. //                        debug("parent ".$this->returnSee($tree[$cur]['parent'], false, false)." in other package");
  1330.                 $my_tree .= '<listitem>' $this->returnSee($tree[$cur]['parent']falsefalse);
  1331.                 if ($tree[$cur]['parent']->package != $package$my_tree .= ' <emphasis>(Different package)</emphasis><itemizedlist>';
  1332.             }
  1333.         }
  1334.         do
  1335.         {
  1336. //            fancy_debug($cur,$lastcur,$kids);
  1337.             if (count($tree[$cur]['children']))
  1338.             {
  1339. //                debug("$cur has children");
  1340.                 if (!isset($kids[$cur]))
  1341.                 {
  1342. //                    debug("set $cur kids");
  1343.                     $kids[$cur1;
  1344.                     $my_tree .= '<listitem>'.$this->returnSee($tree[$cur]['link']falsefalse);
  1345.                     $my_tree .= '<itemizedlist>'."\n";
  1346.                 }
  1347.                 array_push($lastcur,$cur);
  1348.                 list(,$cureach($tree[$cur]['children']);
  1349. //                var_dump('listed',$cur);
  1350.                 if ($cur)
  1351.                 {
  1352.                     $cur $cur['package''#' $cur['class'];
  1353. //                    debug("set cur to child $cur");
  1354. //                    $my_tree .= '<li>'.$this->returnSee($tree[$cur]['link'], false, false);
  1355.                     continue;
  1356.                 else
  1357.                 {
  1358. //                    debug("end of children for $cur");
  1359.                     $cur array_pop($lastcur);
  1360.                     $cur array_pop($lastcur);
  1361.                     $my_tree .= '</itemizedlist></listitem>'."\n";
  1362.                     if ($dopar && ($cur == '#root' || !$cur)) $my_tree .= '</itemizedlist></listitem>';
  1363.                 }
  1364.             else 
  1365.             {
  1366. //                debug("$cur has no children");
  1367.                 $my_tree .= '<listitem>'.$this->returnSee($tree[$cur]['link']falsefalse)."</listitem>";
  1368.                 if ($dopar && $cur == '#root'$my_tree .= '</itemizedlist></listitem>';
  1369.                 $cur array_pop($lastcur);
  1370.             }
  1371.         while ($cur);
  1372.         return $my_tree;
  1373.     }
  1374.     /**
  1375.      * does nothing
  1376.      */
  1377.     function generateElementIndex()
  1378.     {
  1379.     }
  1380.     
  1381.     function setTemplateDir($dir)
  1382.     {
  1383.         Converter::setTemplateDir($dir);
  1384.         $this->smarty_dir = $this->templateDir;
  1385.     }
  1386.     
  1387.     /**
  1388.      * Generate alphabetical index of all elements by package and subpackage
  1389.      *
  1390.      * @param string $package name of a package
  1391.      * @see $pkg_elements, walk(), generatePkgElementIndexes()
  1392.      */
  1393.     function generatePkgElementIndex($package)
  1394.     {
  1395.     }
  1396.     
  1397.     /**
  1398.      *
  1399.      * @see generatePkgElementIndex()
  1400.      */
  1401.     function generatePkgElementIndexes()
  1402.     {
  1403.     }
  1404.     
  1405.     /**
  1406.      * @param string name of class
  1407.      * @param string package name
  1408.      * @param string full path to look in (used in index generation)
  1409.      * @param boolean deprecated
  1410.      * @param boolean return just the URL, or enclose it in an html a tag
  1411.      * @return mixed false if not found, or an html a link to the class's documentation
  1412.      * @see parent::getClassLink()
  1413.      */
  1414.     function getClassLink($expr,$package$file false,$text false$local true$with_a true)
  1415.     {
  1416.         $a Converter::getClassLink($expr,$package,$file);
  1417.         if (!$areturn false;
  1418.         return $this->returnSee($a$text$local$with_a);
  1419.     }
  1420.  
  1421.     /**
  1422.      * @param string name of function
  1423.      * @param string package name
  1424.      * @param string full path to look in (used in index generation)
  1425.      * @param boolean deprecated
  1426.      * @param boolean return just the URL, or enclose it in an html a tag
  1427.      * @return mixed false if not found, or an html a link to the function's documentation
  1428.      * @see parent::getFunctionLink()
  1429.      */
  1430.     function getFunctionLink($expr,$package$file false,$text false$local true)
  1431.     {
  1432.         $a Converter::getFunctionLink($expr,$package,$file);
  1433.         if (!$areturn false;
  1434.         return $this->returnSee($a$text$local);
  1435.     }
  1436.  
  1437.     /**
  1438.      * @param string name of define
  1439.      * @param string package name
  1440.      * @param string full path to look in (used in index generation)
  1441.      * @param boolean deprecated
  1442.      * @param boolean return just the URL, or enclose it in an html a tag
  1443.      * @return mixed false if not found, or an html a link to the define's documentation
  1444.      * @see parent::getDefineLink()
  1445.      */
  1446.     function getDefineLink($expr,$package$file false,$text false$local true)
  1447.     {
  1448.         $a Converter::getDefineLink($expr,$package,$file);
  1449.         if (!$areturn false;
  1450.         return $this->returnSee($a$text$local);
  1451.     }
  1452.  
  1453.     /**
  1454.      * @param string name of global variable
  1455.      * @param string package name
  1456.      * @param string full path to look in (used in index generation)
  1457.      * @param boolean deprecated
  1458.      * @param boolean return just the URL, or enclose it in an html a tag
  1459.      * @return mixed false if not found, or an html a link to the global variable's documentation
  1460.      * @see parent::getGlobalLink()
  1461.      */
  1462.     function getGlobalLink($expr,$package$file false,$text false$local true)
  1463.     {
  1464.         $a Converter::getGlobalLink($expr,$package,$file);
  1465.         if (!$areturn false;
  1466.         return $this->returnSee($a$text$local);
  1467.     }
  1468.  
  1469.     /**
  1470.      * @param string name of procedural page
  1471.      * @param string package name
  1472.      * @param string full path to look in (used in index generation)
  1473.      * @param boolean deprecated
  1474.      * @param boolean return just the URL, or enclose it in an html a tag
  1475.      * @return mixed false if not found, or an html a link to the procedural page's documentation
  1476.      * @see parent::getPageLink()
  1477.      */
  1478.     function getPageLink($expr,$package$path false,$text false$local true)
  1479.     {
  1480.         $a Converter::getPageLink($expr,$package,$path);
  1481.         if (!$areturn false;
  1482.         return $this->returnSee($a$text$local);
  1483.     }
  1484.  
  1485.     /**
  1486.      * @param string name of method
  1487.      * @param string class containing method
  1488.      * @param string package name
  1489.      * @param string full path to look in (used in index generation)
  1490.      * @param boolean deprecated
  1491.      * @param boolean return just the URL, or enclose it in an html a tag
  1492.      * @return mixed false if not found, or an html a link to the method's documentation
  1493.      * @see parent::getMethodLink()
  1494.      */
  1495.     function getMethodLink($expr,$class,$package$file false,$text false$local true)
  1496.     {
  1497.         $a Converter::getMethodLink($expr,$class,$package,$file);
  1498.         if (!$areturn false;
  1499.         return $this->returnSee($a$text$local);
  1500.     }
  1501.  
  1502.     /**
  1503.      * @param string name of var
  1504.      * @param string class containing var
  1505.      * @param string package name
  1506.      * @param string full path to look in (used in index generation)
  1507.      * @param boolean deprecated
  1508.      * @param boolean return just the URL, or enclose it in an html a tag
  1509.      * @return mixed false if not found, or an html a link to the var's documentation
  1510.      * @see parent::getVarLink()
  1511.      */
  1512.     function getVarLink($expr,$class,$package$file false,$text false$local true)
  1513.     {
  1514.         $a Converter::getVarLink($expr,$class,$package,$file);
  1515.         if (!$areturn false;
  1516.         return $this->returnSee($a$text$local);
  1517.     }
  1518.     
  1519.     /**
  1520.      * does a nat case sort on the specified second level value of the array
  1521.      *
  1522.      * @param    mixed    $a 
  1523.      * @param    mixed    $b 
  1524.      * @return    int 
  1525.      */
  1526.     function rcNatCmp ($a$b)
  1527.     {
  1528.         $aa strtoupper($a[$this->rcnatcmpkey]);
  1529.         $bb strtoupper($b[$this->rcnatcmpkey]);
  1530.         
  1531.         return strnatcasecmp($aa$bb);
  1532.     }
  1533.     
  1534.     /**
  1535.      * does a nat case sort on the specified second level value of the array.
  1536.      * this one puts constructors first
  1537.      *
  1538.      * @param    mixed    $a 
  1539.      * @param    mixed    $b 
  1540.      * @return    int 
  1541.      */
  1542.     function rcNatCmp1 ($a$b)
  1543.     {
  1544.         $aa strtoupper($a[$this->rcnatcmpkey]);
  1545.         $bb strtoupper($b[$this->rcnatcmpkey]);
  1546.         
  1547.         if (strpos($aa,'CONSTRUCTOR'=== 0)
  1548.         {
  1549.             return -1;
  1550.         }
  1551.         if (strpos($bb,'CONSTRUCTOR'=== 0)
  1552.         {
  1553.             return 1;
  1554.         }
  1555.         if (strpos($aa,strtoupper($this->class)) === 0)
  1556.         {
  1557.             return -1;
  1558.         }
  1559.         if (strpos($bb,strtoupper($this->class)) === 0)
  1560.         {
  1561.             return -1;
  1562.         }
  1563.         return strnatcasecmp($aa$bb);
  1564.     }
  1565.     
  1566.     function wordwrap($string)
  1567.     {
  1568.         return wordwrap($string);
  1569.     }
  1570.     
  1571.     /**
  1572.      * Generate the constants.xml, packagename.xml, and globals.xml files
  1573.      */
  1574.     function Output()
  1575.     {
  1576.         $this->flushPackageXml(false);
  1577.         $templ &$this->newSmarty();
  1578.         $categories array();
  1579.         $packages array_flip($this->all_packages);
  1580.         foreach($this->packagecategories as $package => $category)
  1581.         {
  1582.             $categories[$category]['package.'.$category.'.'.str_replace('_','-',strtolower($package ))1;
  1583.             if (isset($packages[$package])) unset($packages[$package]);
  1584.         }
  1585.         $category $GLOBALS['phpDocumentor_DefaultCategoryName'];
  1586.         foreach($packages as $package)
  1587.         {
  1588.             $categories[$category]['package.'.$category.'.'.str_replace('_','-',strtolower($package ))1;
  1589.         }
  1590.         foreach($categories as $category => $ids)
  1591.         {
  1592.             $templ->assign('id','package.'.$category);
  1593.             $templ->assign('ids',array());
  1594.             $templ->assign('category',$category);
  1595.             $this->setTargetDir($this->base_dir);
  1596.             if (file_exists($this->base_dir . PATH_DELIMITER strtolower($category '.xml'))
  1597.             {
  1598.                 $contents @file($this->base_dir . PATH_DELIMITER strtolower($category '.xml');
  1599.                 if (is_array($contents))
  1600.                 {
  1601.                     $found false;
  1602.                     foreach($contents as $i => $line)
  1603.                     {
  1604.                         $line trim($line);
  1605.                         if (strlen($line&& $line{0== '&')
  1606.                         {
  1607.                             $found $i;
  1608.                             if (in_array(str_replace(array ('&'';')array ('''')trim($line ))array_keys($ids )))
  1609.                             {
  1610.                                 unset($ids[str_replace(array('&'';')array('''')trim($line))]);
  1611.                             }
  1612.                         }
  1613.                         if ($found !== false && (!strlen($line|| $line{0!= '&'))
  1614.                         {
  1615.                             break;
  1616.                         }
  1617.                     }
  1618.                     $newids array();
  1619.                     foreach($ids as $id => $unll)
  1620.                     {
  1621.                         $newids[' &' $id ";\n";
  1622.                     }
  1623.                     $newcontents array_merge(array_slice($contents0$i)$newids);
  1624.                     $newcontents array_merge($newcontentsarray_slice($contents$i));
  1625.                 }
  1626.                 $categorycontents implode($newcontents'');
  1627.             else
  1628.             {
  1629.                 foreach($ids as $id => $unll)
  1630.                 {
  1631.                     if (!in_array($id$templ->_tpl_vars['ids']))
  1632.                     {
  1633.                         $templ->append('ids',$id);
  1634.                     }
  1635.                 }
  1636.                 $categorycontents '<!-- $' "Revision$ -->\n" $templ->fetch('category.tpl');
  1637.             }
  1638.             $this->writefile(strtolower($category'.xml',
  1639.                 $categorycontents);
  1640.             phpDocumentor_out("\n");
  1641.             flush();
  1642.         }
  1643.         $my &$this->newSmarty();
  1644.         if ($this->_peardoc2_constants)
  1645.         {
  1646.             foreach($this->_peardoc2_constants as $category => $r)
  1647.             {
  1648.                 foreach($r as $package => $s)
  1649.                 {
  1650.                     $my->assign('id','package.'.strtolower($category.'.'.str_replace('_','-',strtolower($package ))).'.constants');
  1651.                     $my->assign('package',$package);
  1652.                     $defines array();
  1653.                     foreach($s as $file => $t)
  1654.                     {
  1655.                         $arr array();
  1656.                         $arr['name'$file;
  1657.                         $arr['page'strtolower($t['page']);
  1658.                         $arr['defines'$t['defines'];
  1659.                         $defines[$arr;
  1660.                     }
  1661.                     $my->assign('defines',$defines);
  1662.                     $this->setTargetDir($this->base_dir . PATH_DELIMITER $category
  1663.                        . PATH_DELIMITER strtolower(str_replace('_','-',strtolower($package ))));
  1664.                     $this->writefile('constants.xml',
  1665.                         '<!-- $' "Revision$ -->\n" $my->fetch('constants.tpl'));
  1666.                     $my->clear_all_assign();
  1667.                 }
  1668.             }
  1669.             $this->_peardoc2_constants = false;
  1670.         }
  1671.         if ($this->_peardoc2_globals)
  1672.         {
  1673.             foreach($this->_peardoc2_globals as $category => $r)
  1674.             {
  1675.                 foreach($r as $package => $s)
  1676.                 {
  1677.                     $my->assign('id','package.'.strtolower($category.'.'.str_replace('_','-',strtolower($package ))).'.globals');
  1678.                     $my->assign('package',$package);
  1679.                     $defines array();
  1680.                     foreach($s as $file => $t)
  1681.                     {
  1682.                         $arr array();
  1683.                         $arr['name'$file;
  1684.                         $arr['page'strtolower($t['page']);
  1685.                         $arr['globals'$t['globals'];
  1686.                         $defines[$arr;
  1687.                     }
  1688.                     $my->assign('globals',$defines);
  1689.                     $this->setTargetDir($this->base_dir . PATH_DELIMITER $category
  1690.                        . PATH_DELIMITER strtolower(str_replace('_','-',strtolower($package ))));
  1691.                     $this->writefile('globals.xml',
  1692.                         '<!-- $' "Revision$ -->\n" $my->fetch('globals.tpl'));
  1693.                     $my->clear_all_assign();
  1694.                 }
  1695.             }
  1696.             $this->_peardoc2_globals = false;
  1697.         }
  1698.     }
  1699. }
  1700. ?>

Documentation generated on Mon, 05 Dec 2011 21:35:10 -0600 by phpDocumentor 1.4.4