home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / Converter.inc < prev    next >
Encoding:
Text File  |  2004-03-24  |  193.9 KB  |  4,745 lines

  1. <?php
  2. //
  3. // +------------------------------------------------------------------------+
  4. // | phpDocumentor                                                          |
  5. // +------------------------------------------------------------------------+
  6. // | Copyright (c) 2000-2003 Joshua Eichorn, Gregory Beaver                 |
  7. // | Email         jeichorn@phpdoc.org, cellog@phpdoc.org                   |
  8. // | Web           http://www.phpdoc.org                                    |
  9. // | Mirror        http://phpdocu.sourceforge.net/                          |
  10. // | PEAR          http://pear.php.net/package-info.php?pacid=137           |
  11. // +------------------------------------------------------------------------+
  12. // | This source file is subject to version 3.00 of the PHP License,        |
  13. // | that is available at http://www.php.net/license/3_0.txt.               |
  14. // | If you did not receive a copy of the PHP license and are unable to     |
  15. // | obtain it through the world-wide-web, please send a note to            |
  16. // | license@php.net so we can mail you a copy immediately.                 |
  17. // +------------------------------------------------------------------------+
  18. //
  19.  
  20. /**
  21.  * Base class for all output converters.
  22.  * @package Converters
  23.  * @author Greg Beaver <cellog@users.sourceforge.net>
  24.  * @since 1.0rc1
  25.  * @version $Id: pear-Converter.inc,v 1.1.2.3 2003/08/13 20:23:45 CelloG Exp $
  26.  */
  27. /**
  28.  * Smarty template files
  29.  */
  30. include_once("phpDocumentor/Smarty-2.5.0/libs/Smarty.class.php");
  31. /**
  32.  * Base class for all output converters.
  33.  *
  34.  * The Converter marks the final stage in phpDocumentor.  phpDocumentor works
  35.  * in this order:
  36.  *
  37.  * <pre>Parsing => Intermediate Parsing organization => Conversion to output</pre>
  38.  *
  39.  * A Converter takes output from the {@link phpDocumentor_IntermediateParser} and
  40.  * converts it to output.  With version 1.2, phpDocumentor includes a variety
  41.  * of output converters:
  42.  * <ul>
  43.  *  <li>{@link HTMLframesConverter}</li>
  44.  *  <li>{@link HTMLSmartyConverter}</li>
  45.  *  <li>{@link PDFdefaultConverter}</li>
  46.  *  <li>{@link CHMdefaultConverter}</li>
  47.  *  <li>{@link CSVdia2codeConverter}</li>
  48.  *  <li>{@link XMLDocBookConverter}</li>
  49.  * </ul>
  50.  * {@internal
  51.  * The converter takes output directly from {@link phpDocumentor_IntermediateParser}
  52.  * and using {@link walk()} or {@link walk_everything} (depending on the value of
  53.  * {@link $sort_absolutely_everything}) it "walks" over an array of phpDocumentor elements.}}
  54.  * 
  55.  * @package Converters
  56.  * @abstract
  57.  * @author Greg Beaver <cellog@users.sourceforge.net>
  58.  * @since 1.0rc1
  59.  * @version $Id: pear-Converter.inc,v 1.1.2.3 2003/08/13 20:23:45 CelloG Exp $
  60.  */
  61. class Converter
  62. {
  63.     /**
  64.      * output format of this converter
  65.      *
  66.      * in Child converters, this will match the first part of the -o command-line
  67.      * as in -o HTML:frames:default "HTML"
  68.      * @tutorial phpDocumentor.howto.pkg#using.command-line.output
  69.      * @var string
  70.      */
  71.     var $outputformat = 'Generic';
  72.     /**
  73.      * package name currently being converted
  74.      * @var string
  75.      */
  76.     var $package = 'default';
  77.     /**
  78.      * subpackage name currently being converted
  79.      * @var string
  80.      */
  81.     var $subpackage = '';
  82.     /**
  83.      * set to a classname if currently parsing a class, false if not
  84.      * @var string|false
  85.      */
  86.     var $class = false;
  87.     /**#@+
  88.      * @access private
  89.      */
  90.     /**
  91.      * the workhorse of linking.
  92.      *
  93.      * This array is an array of link objects of format:
  94.      * [package][subpackage][eltype][elname] = descendant of {@link abstractLink}
  95.      * eltype can be page|function|define|class|method|var
  96.      * if eltype is method or var, the array format is:
  97.      * [package][subpackage][eltype][class][elname]
  98.      * @var array
  99.      * @see functionLink, pageLink, classLink, defineLink, methodLink, varLink, globalLink
  100.      */
  101.     var $links = array();
  102.     
  103.     /**
  104.      * the workhorse of linking, with allowance for support of multiple
  105.      * elements in different files.
  106.      *
  107.      * This array is an array of link objects of format:
  108.      * [package][subpackage][eltype][file][elname] = descendant of {@link abstractLink}
  109.      * eltype can be function|define|class|method|var
  110.      * if eltype is method or var, the array format is:
  111.      * [package][subpackage][eltype][file][class][elname]
  112.      * @var array
  113.      * @see functionLink, pageLink, classLink, defineLink, methodLink, varLink, globalLink
  114.     */
  115.     var $linkswithfile = array();
  116.     /**#@-*/
  117.     /**
  118.      * set to value of -po commandline
  119.      * @tutorial phpDocumentor.howto.pkg#using.command-line.packageoutput
  120.      * @var mixed
  121.      */
  122.     var $package_output;
  123.     
  124.     /**
  125.      * name of current page being converted
  126.      * @var string
  127.      */
  128.     var $page;
  129.     
  130.     /**
  131.      * path of current page being converted
  132.      * @var string
  133.      */
  134.     var $path;
  135.     
  136.     /**
  137.      * template for the procedural page currently being processed
  138.      * @var Smarty
  139.      */
  140.     var $page_data;
  141.     
  142.     /**
  143.      * template for the class currently being processed
  144.      * @var Smarty
  145.      */
  146.     var $class_data;
  147.     
  148.     /**
  149.      * current procedural page being processed
  150.      * @var parserPage
  151.      */
  152.     var $curpage;
  153.     /**
  154.      * alphabetical index of all elements sorted by package, subpackage, page,
  155.      * and class.
  156.      * @var array Format: array(package => array(subpackage => array('page'|'class' => array(path|classname => array(element, element,...)))))
  157.      * @uses $sort_absolutely_everything if true, then $package_elements is used,
  158.      *       otherwise, the {@link ParserData::$classelements} and
  159.      *       {@link ParserData::$pageelements} variables are used
  160.      */
  161.     var $package_elements = array();
  162.     /**
  163.      * alphabetical index of all elements
  164.      *
  165.      * @var array Format: array(first letter of element name => array({@link parserElement} or {@link parserPage},...))
  166.      * @see formatIndex(), HTMLframesConverter::formatIndex()
  167.      */
  168.     var $elements = array();
  169.     /**
  170.      * alphabetized index of procedural pages by package
  171.      *
  172.      * @see $leftindex
  173.      * @var array Format: array(package => array(subpackage => array({@link pageLink} 1,{@link pageLink} 2,...)
  174.      */
  175.     var $page_elements = array();
  176.     /**
  177.      * alphabetized index of defines by package
  178.      *
  179.      * @see $leftindex
  180.      * @var array Format: array(package => array(subpackage => array({@link defineLink} 1,{@link defineLink} 2,...)
  181.      */
  182.     var $define_elements = array();
  183.     /**
  184.      * alphabetized index of classes by package
  185.      *
  186.      * @see $leftindex
  187.      * @var array Format: array(package => array(subpackage => array({@link classLink} 1,{@link classLink} 2,...)
  188.      */
  189.     var $class_elements = array();
  190.     /**
  191.      * alphabetized index of global variables by package
  192.      *
  193.      * @see $leftindex
  194.      * @var array Format: array(package => array(subpackage => array({@link globalLink} 1,{@link globalLink} 2,...)
  195.      */
  196.     var $global_elements = array();
  197.     /**
  198.      * alphabetized index of functions by package
  199.      *
  200.      * @see $leftindex
  201.      * @var array Format: array(package => array(subpackage => array({@link functionLink} 1,{@link functionLink} 2,...)
  202.      */
  203.     var $function_elements = array();
  204.     /**
  205.      * alphabetical index of all elements, indexed by package/subpackage
  206.      *
  207.      * @var array Format: array(first letter of element name => array({@link parserElement} or {@link parserPage},...))
  208.      * @see formatPkgIndex(), HTMLframesConverter::formatPkgIndex()
  209.      */
  210.     var $pkg_elements = array();
  211.     
  212.     /**
  213.      * alphabetical index of all elements on a page by package/subpackage
  214.      *
  215.      * The page itself has a link under ###main
  216.      * @var array Format: array(package => array(subpackage => array(path => array({@link abstractLink} descendant 1, ...)))
  217.      * @see formatLeftIndex()
  218.      */
  219.     var $page_contents = array();
  220.     
  221.     /**
  222.      * This determines whether the {@link $page_contents} array should be sorted by element type as well as alphabetically by name
  223.      * @see sortPageContentsByElementType()
  224.      * @var boolean
  225.      */
  226.     var $sort_page_contents_by_type = false;
  227.     /**
  228.      * This is used if the content must be passed in the order it should be read, i.e. by package, procedural then classes
  229.      *
  230.      * This fixes bug 637921, and is used by {@link PDFdefaultConverter}
  231.      */
  232.     var $sort_absolutely_everything = false;
  233.     /**
  234.      * alphabetical index of all methods and vars in a class by package/subpackage
  235.      *
  236.      * The class itself has a link under ###main
  237.      * @var array 
  238.      * Format:<pre>
  239.      * array(package =>
  240.      *       array(subpackage =>
  241.      *             array(path =>
  242.      *                   array(class => 
  243.      *                         array({@link abstractLink} descendant 1, ...
  244.      *                        )
  245.      *                  )
  246.      *            )
  247.      *      )</pre>
  248.      * @see formatLeftIndex()
  249.      */
  250.     var $class_contents = array();
  251.     /**
  252.      * controls processing of elements marked private with @access private
  253.      *
  254.      * defaults to false.  Set with command-line --parseprivate or -pp
  255.      * @var bool
  256.      */
  257.     var $parseprivate;
  258.     /**
  259.      * controls display of progress information while parsing.
  260.      *
  261.      * defaults to false.  Set to true for cron jobs or other situations where no visual output is necessary
  262.      * @var bool
  263.      */
  264.     var $quietmode;
  265.     
  266.     /**
  267.      * directory that output is sent to. -t command-line sets this.
  268.      * @tutorial phpDocumentor.howto.pkg#using.command-line.target
  269.      */
  270.     var $targetDir = '';
  271.     
  272.     /**
  273.      * Directory that the template is in, relative to phpDocumentor root directory
  274.      * @var string
  275.      */
  276.     var $templateDir = '';
  277.     
  278.     /**
  279.      * Directory that the smarty templates are in
  280.      * @var string
  281.      */
  282.     var $smarty_dir = '';
  283.     
  284.     /**
  285.      * Name of the template, from last part of -o
  286.      * @tutorial phpDocumentor.howto.pkg#using.command-line.output
  287.      * @var string
  288.      */
  289.     var $templateName = '';
  290.     
  291.     /**
  292.      * full path of the current file being converted
  293.      */
  294.     var $curfile;
  295.     
  296.     /**
  297.      * All class information, organized by path, and by package
  298.      * @var Classes
  299.      */
  300.     var $classes;
  301.     
  302.     /**
  303.      * Hierarchy of packages
  304.      *
  305.      * Every package that contains classes may have parent or child classes
  306.      * in other packages.  In other words, this code is legal:
  307.      *
  308.      * <code>
  309.      * /**
  310.      *  * @package one
  311.      *  * /
  312.      * class one {}
  313.      *
  314.      * /**
  315.      *  * @package two
  316.      *  * /
  317.      * class two extends one {}
  318.      * </code>
  319.      *
  320.      * In this case, package one is a parent of package two
  321.      * @var array
  322.      * @see phpDocumentor_IntermediateParser::$package_parents
  323.      */
  324.     var $package_parents;
  325.     
  326.     /**
  327.      * Packages associated with categories
  328.      *
  329.      * Used by the XML:DocBook/peardoc2 converter, and available to others, to
  330.      * group many packages into categories
  331.      * @see phpDocumentor_IntermediateParser::$packagecategories
  332.      * @var array
  333.      */
  334.     var $packagecategories;
  335.     
  336.     /**
  337.      * All packages encountered in parsing
  338.      * @var array
  339.      * @see phpDocumentor_IntermediateParser::$all_packages
  340.      */
  341.     var $all_packages;
  342.     
  343.     /**
  344.      * A list of files that have had source code generated
  345.      * @var array
  346.      */
  347.     var $sourcePaths = array();
  348.  
  349.     /**
  350.      * Controls which of the one-element-only indexes are generated.
  351.      *
  352.      * Generation of these indexes for large packages is time-consuming.  This is an optimization feature.  An
  353.      * example of how to use this is in {@link HTMLframesConverter::$leftindex}, and in {@link HTMLframesConverter::formatLeftIndex()}.
  354.      * These indexes are intended for use as navigational aids through documentation, but can be used for anything by converters.
  355.      * @see $class_elements, $page_elements, $function_elements, $define_elements, $global_elements
  356.      * @see formatLeftIndex()
  357.      * @var array
  358.      */
  359.     var $leftindex = array('classes' => true, 'pages' => true, 'functions' => true, 'defines' => true, 'globals' => true);
  360.     
  361.     /** @access private */
  362.     var $killclass = false;
  363.     /**
  364.      * @var string
  365.      * @see phpDocumentor_IntermediateParser::$title
  366.      */
  367.     var $title = 'Generated Documentation';
  368.     
  369.     /**
  370.      * Options for each template, parsed from the options.ini file in the template base directory
  371.      * @tutorial phpDocumentor/tutorials.pkg#conversion.ppage
  372.      * @var array
  373.      */
  374.     var $template_options;
  375.     
  376.     /**
  377.      * Tutorials and Extended Documentation parsed from a tutorials/package[/subpackage] directory
  378.      * @tutorial tutorials.pkg
  379.      * @access private
  380.      */
  381.     var $tutorials = array();
  382.     
  383.     /**
  384.      * tree-format structure of tutorials and their child tutorials, if any
  385.      * @var array
  386.      * @access private
  387.      */
  388.     var $tutorial_tree = false;
  389.     
  390.     /**
  391.      * list of tutorials that have already been processed. Used by @link _setupTutorialTree()
  392.      * @var array
  393.      * @access private
  394.      */
  395.     var $processed_tutorials;
  396.  
  397.     /**
  398.      * List of all @todo tags and a link to the element with the @todo
  399.      *
  400.      * Format: array(package => array(link to element, array(todo {@link parserTag},...)),...)
  401.      * @tutorial tags.todo.pkg
  402.      * @var array
  403.      */
  404.     var $todoList = array();
  405.     
  406.     /**
  407.      * Initialize Converter data structures
  408.      * @param array {@link $all_packages} value
  409.      * @param array {@link $package_parents} value
  410.      * @param Classes {@link $classes} value
  411.      * @param ProceduralPages {@link $proceduralpages} value
  412.      * @param array {@link $package_output} value
  413.      * @param boolean {@link $parseprivate} value
  414.      * @param boolean {@link $quietmode} value
  415.      * @param string {@link $targetDir} value
  416.      * @param string {@link $templateDir} value
  417.      * @param string (@link $title} value
  418.      */
  419.     function Converter(&$allp, &$packp, &$classes, &$procpages, $po, $pp, $qm, $targetDir, $template, $title)
  420.     {
  421.         $this->all_packages = $allp;
  422.         $this->package_parents = $packp;
  423.         $this->package = $GLOBALS['phpDocumentor_DefaultPackageName'];
  424.         $this->proceduralpages = &$procpages;
  425.         $this->package_output = $po;
  426.         if (is_array($po))
  427.         {
  428.             $a = $po[0];
  429.             $this->all_packages = array_flip($po);
  430.             $this->all_packages[$a] = 1;
  431.         }
  432.         $this->parseprivate = $pp;
  433.         $this->quietmode = $qm;
  434.         $this->classes = &$classes;
  435.         $this->roots = $classes->getRoots();
  436.         $this->title = $title;
  437.         $this->setTemplateDir($template);
  438.         $this->setTargetdir($targetDir);
  439.     }
  440.     
  441.     /**
  442.      * Called by IntermediateParser after creation
  443.      * @access private
  444.      */
  445.     function setTutorials($tutorials)
  446.     {
  447.         $this->tutorials = $tutorials;
  448.     }
  449.     
  450.     /**
  451.      * @param pkg|cls|proc the tutorial type to search for
  452.      * @param tutorial name
  453.      * @param string package name
  454.      * @param string subpackage name, if any
  455.      * @return false|parserTutorial if the tutorial exists, return it
  456.      */
  457.     function hasTutorial($type, $name, $package, $subpackage = '')
  458.     {
  459.         if (isset($this->tutorials[$package][$subpackage][$type][$name . '.' . $type]))
  460.             return $this->tutorials[$package][$subpackage][$type][$name . '.' . $type];
  461.         return false;
  462.     }
  463.     
  464.     /**
  465.      * Called by {@link walk()} while converting, when the last class element
  466.      * has been parsed.
  467.      *
  468.      * A Converter can use this method in any way it pleases. HTMLframesConverter
  469.      * uses it to complete the template for the class and to output its
  470.      * documentation
  471.      * @see HTMLframesConverter::endClass()
  472.      * @abstract
  473.      */
  474.     function endClass()
  475.     {
  476.     }
  477.     
  478.     /**
  479.     * Called by {@link walk()} while converting, when the last procedural page
  480.     * element has been parsed.
  481.     *
  482.     * A Converter can use this method in any way it pleases. HTMLframesConverter
  483.     * uses it to complete the template for the procedural page and to output its
  484.     * documentation
  485.     * @see HTMLframesConverter::endClass()
  486.     * @abstract
  487.     */
  488.     function endPage()
  489.     {
  490.     }
  491.     
  492.     /**
  493.     * Called by {@link walk()} while converting.
  494.     *
  495.     * This method is intended to be the place that {@link $pkg_elements} is
  496.     * formatted for output.
  497.     * @see HTMLframesConverter::formatPkgIndex()
  498.     * @abstract
  499.     */
  500.     function formatPkgIndex()
  501.     {
  502.     }
  503.     
  504.     /**
  505.     * Called by {@link walk()} while converting.
  506.     *
  507.     * This method is intended to be the place that {@link $elements} is
  508.     * formatted for output.
  509.     * @see HTMLframesConverter::formatIndex()
  510.     * @abstract
  511.     */
  512.     function formatIndex()
  513.     {
  514.     }
  515.     
  516.     /**
  517.     * Called by {@link walk()} while converting.
  518.     *
  519.     * This method is intended to be the place that any of
  520.     * {@link $class_elements, $function_elements, $page_elements},
  521.     * {@link $define_elements}, and {@link $global_elements} is formatted for
  522.     * output, depending on the value of {@link $leftindex}
  523.     * @see HTMLframesConverter::formatLeftIndex()
  524.     * @abstract
  525.     */
  526.     function formatLeftIndex()
  527.     {
  528.     }
  529.     
  530.     /**
  531.      * Called by {@link parserSourceInlineTag::stringConvert()} to allow
  532.      * converters to format the source code the way they'd like.
  533.      *
  534.      * default returns it unchanged (html with xhtml tags)
  535.      * @param string output from highlight_string() - use this function to
  536.      * reformat the returned data for Converter-specific output
  537.      * @return string
  538.      * @deprecated in favor of tokenizer-based highlighting.  This will be
  539.      *             removed for 2.0
  540.      */
  541.     function unmangle($sourcecode)
  542.     {
  543.         return $sourcecode;
  544.     }
  545.     
  546.  
  547.     /**
  548.      * Used to allow converters to format the source code the way they'd like.
  549.      *
  550.      * default returns it unchanged.  Mainly used by the {@link HighlightParser}
  551.      * {@internal
  552.      * The method takes information from options.ini, the template options
  553.      * file, specifically the [highlightSourceTokens] and [highlightSource]
  554.      * sections, and uses them to enclose tokens.
  555.      *
  556.      * {@source}}}
  557.      * @param integer token value from {@link PHP_MANUAL#tokenizer tokenizer constants}
  558.      * @param string contents of token
  559.      * @param boolean whether the contents are preformatted or need modification
  560.      * @return string
  561.      */
  562.     function highlightSource($token, $word, $preformatted = false)
  563.     {
  564.         if ($token !== false)
  565.         {
  566.             if (!$preformatted) $word = $this->postProcess($word);
  567.             if (isset($this->template_options['highlightSourceTokens'][token_name($token)]))
  568.             {
  569.                 return $this->template_options['highlightSourceTokens'][token_name($token)] . $word .
  570.                        $this->template_options['highlightSourceTokens']['/'.token_name($token)];
  571.             } else return $word;
  572.         } else
  573.         {
  574.             if (isset($this->template_options['highlightSource'][$word]))
  575.             {
  576.                 return $this->template_options['highlightSource'][$word] . ($preformatted ? $word : $this->postProcess($word)) .
  577.                        $this->template_options['highlightSource']['/'.$word];
  578.             } else
  579.             {
  580.                 return ($preformatted ? $word : $this->postProcess($word));
  581.             }
  582.         }
  583.     }
  584.     
  585.     /**
  586.      * Used to allow converters to format the source code of DocBlocks the way
  587.      * they'd like.
  588.      *
  589.      * default returns it unchanged.  Mainly used by the {@link HighlightParser}
  590.      * {@internal
  591.      * The method takes information from options.ini, the template options
  592.      * file, specifically the [highlightDocBlockSourceTokens] section, and uses
  593.      * it to enclose tokens.
  594.      *
  595.      * {@source}}}
  596.      * @param string name of docblock token type
  597.      * @param string contents of token
  598.      * @param boolean whether the contents are preformatted or need modification
  599.      * @return string
  600.      */
  601.     function highlightDocBlockSource($token, $word, $preformatted = false)
  602.     {
  603.         if (isset($this->template_options['highlightDocBlockSourceTokens'][$token]))
  604.         {
  605.             if (!$preformatted) $word = $this->postProcess($word);
  606.             return $this->template_options['highlightDocBlockSourceTokens'][$token] . $word .
  607.                    $this->template_options['highlightDocBlockSourceTokens']['/'.$token];
  608.         } else return ($preformatted ? $word : $this->postProcess($word));
  609.     }
  610.     
  611.     /**
  612.      * Called by {@link parserReturnTag::Convert()} to allow converters to
  613.      * change type names to desired formatting
  614.      *
  615.      * Used by {@link XMLDocBookConverter::type_adjust()} to change true and
  616.      * false to the peardoc2 values
  617.      * @param string
  618.      * @return string
  619.      */
  620.     function type_adjust($typename)
  621.     {
  622.         return $typename;
  623.     }
  624.     
  625.     /**
  626.      * Used to convert the <<code>> tag in a docblock
  627.      * @param string
  628.      * @param boolean true if this is to highlight a tutorial <programlisting>
  629.      * @return string
  630.      */
  631.     function ProgramExample($example, $tutorial = false, $inlinesourceparse = null/*false*/,
  632.                             $class = null/*false*/, $linenum = null/*false*/, $filesourcepath = null/*false*/)
  633.     {
  634.         if (tokenizer_ext)
  635.         {
  636.             $e = $example;
  637.             if (!is_array($example))
  638.             {
  639.                 $obj = new phpDocumentorTWordParser;
  640.                 $obj->setup($example);
  641.                 $e = $obj->getFileSource();
  642.                 if (!is_array($e[0][0]) || $e[0][0][0] != T_OPEN_TAG)
  643.                 {
  644.                     $example = "<?php\n".$example;
  645.                     $obj->setup($example);
  646.                     $e = $obj->getFileSource();
  647.                     unset($e[0]);
  648.                     $e = array_values($e);
  649.                 }
  650.                 unset($obj);
  651.             }
  652.             $parser = new phpDocumentor_HighlightParser;
  653.             if (!isset($inlinesourceparse))
  654.             {
  655.                 $example = $parser->parse($e, $this, true); // force php mode
  656.             } else
  657.             {
  658.                 if (isset($filesourcepath))
  659.                 {
  660.                     $example = $parser->parse($e, $this, $inlinesourceparse, $class, $linenum, $filesourcepath);
  661.                 } elseif (isset($linenum))
  662.                 {
  663.                     $example = $parser->parse($e, $this, $inlinesourceparse, $class, $linenum);
  664.                 } elseif (isset($class))
  665.                 {
  666.                     $example = $parser->parse($e, $this, $inlinesourceparse, $class);
  667.                 } else
  668.                 {
  669.                     $example = $parser->parse($e, $this, $inlinesourceparse);
  670.                 }
  671.             }
  672.         }
  673.         
  674.         if ($tutorial)
  675.         {
  676.             return $example;
  677.         }
  678.  
  679.         if (!isset($this->template_options['desctranslate'])) return $example;
  680.         if (!isset($this->template_options['desctranslate']['code'])) return $example;
  681.         $example = $this->template_options['desctranslate']['code'] . $example;
  682.         if (!isset($this->template_options['desctranslate']['/code'])) return $example;
  683.         return $example . $this->template_options['desctranslate']['/code'];
  684.     }
  685.     
  686.     /**
  687.      * Used to convert the contents of <<li>> in a docblock
  688.      * @param string
  689.      * @return string
  690.      */
  691.     function ListItem($item)
  692.     {
  693.         if (!isset($this->template_options['desctranslate'])) return $item;
  694.         if (!isset($this->template_options['desctranslate']['li'])) return $item;
  695.         $item = $this->template_options['desctranslate']['li'] . $item;
  696.         if (!isset($this->template_options['desctranslate']['/li'])) return $item;
  697.         return $item . $this->template_options['desctranslate']['/li'];
  698.     }
  699.     
  700.     /**
  701.      * Used to convert the contents of <<ol>> or <<ul>> in a docblock
  702.      * @param string
  703.      * @return string
  704.      */
  705.     function EncloseList($list,$ordered)
  706.     {
  707.         $listname = ($ordered ? 'ol' : 'ul');
  708.         if (!isset($this->template_options['desctranslate'])) return $list;
  709.         if (!isset($this->template_options['desctranslate'][$listname])) return $list;
  710.         $list = $this->template_options['desctranslate'][$listname] . $list;
  711.         if (!isset($this->template_options['desctranslate']['/'.$listname])) return $list;
  712.         return $list . $this->template_options['desctranslate']['/'.$listname];
  713.     }
  714.     
  715.     /**
  716.      * Used to convert the contents of <<pre>> in a docblock
  717.      * @param string
  718.      * @return string
  719.      */
  720.     function PreserveWhiteSpace($string)
  721.     {
  722.         if (!isset($this->template_options['desctranslate'])) return $string;
  723.         if (!isset($this->template_options['desctranslate']['pre'])) return $string;
  724.         $string = $this->template_options['desctranslate']['pre'] . $string;
  725.         if (!isset($this->template_options['desctranslate']['/pre'])) return $string;
  726.         return $string . $this->template_options['desctranslate']['/pre'];
  727.     }
  728.     
  729.     /**
  730.      * Used to enclose a paragraph in a docblock
  731.      * @param string
  732.      * @return string
  733.      */
  734.     function EncloseParagraph($para)
  735.     {
  736.         if (!isset($this->template_options['desctranslate'])) return $para;
  737.         if (!isset($this->template_options['desctranslate']['p'])) return $para;
  738.         $para = $this->template_options['desctranslate']['p'] . $para;
  739.         if (!isset($this->template_options['desctranslate']['/p'])) return $para;
  740.         return $para . $this->template_options['desctranslate']['/p'];
  741.     }
  742.     
  743.     /**
  744.      * Used to convert the contents of <<b>> in a docblock
  745.      * @param string
  746.      * @return string
  747.      */
  748.     function Bolden($para)
  749.     {
  750.         if (!isset($this->template_options['desctranslate'])) return $para;
  751.         if (!isset($this->template_options['desctranslate']['b'])) return $para;
  752.         $para = $this->template_options['desctranslate']['b'] . $para;
  753.         if (!isset($this->template_options['desctranslate']['/b'])) return $para;
  754.         return $para . $this->template_options['desctranslate']['/b'];
  755.     }
  756.     
  757.     /**
  758.      * Used to convert the contents of <<i>> in a docblock
  759.      * @param string
  760.      * @return string
  761.      */
  762.     function Italicize($para)
  763.     {
  764.         if (!isset($this->template_options['desctranslate'])) return $para;
  765.         if (!isset($this->template_options['desctranslate']['i'])) return $para;
  766.         $para = $this->template_options['desctranslate']['i'] . $para;
  767.         if (!isset($this->template_options['desctranslate']['/i'])) return $para;
  768.         return $para . $this->template_options['desctranslate']['/i'];
  769.     }
  770.     
  771.     /**
  772.      * Used to convert the contents of <<var>> in a docblock
  773.      * @param string
  774.      * @return string
  775.      */
  776.     function Varize($para)
  777.     {
  778.         if (!isset($this->template_options['desctranslate'])) return $para;
  779.         if (!isset($this->template_options['desctranslate']['var'])) return $para;
  780.         $para = $this->template_options['desctranslate']['var'] . $para;
  781.         if (!isset($this->template_options['desctranslate']['/var'])) return $para;
  782.         return $para . $this->template_options['desctranslate']['/var'];
  783.     }
  784.     
  785.     /**
  786.      * Used to convert the contents of <<kbd>> in a docblock
  787.      * @param string
  788.      * @return string
  789.      */
  790.     function Kbdize($para)
  791.     {
  792.         if (!isset($this->template_options['desctranslate'])) return $para;
  793.         if (!isset($this->template_options['desctranslate']['kbd'])) return $para;
  794.         $para = $this->template_options['desctranslate']['kbd'] . $para;
  795.         if (!isset($this->template_options['desctranslate']['/kbd'])) return $para;
  796.         return $para . $this->template_options['desctranslate']['/kbd'];
  797.     }
  798.     
  799.     /**
  800.      * Used to convert the contents of <<samp>> in a docblock
  801.      * @param string
  802.      * @return string
  803.      */
  804.     function Sampize($para)
  805.     {
  806.         if (!isset($this->template_options['desctranslate'])) return $para;
  807.         if (!isset($this->template_options['desctranslate']['samp'])) return $para;
  808.         $para = $this->template_options['desctranslate']['samp'] . $para;
  809.         if (!isset($this->template_options['desctranslate']['/samp'])) return $para;
  810.         return $para . $this->template_options['desctranslate']['/samp'];
  811.     }
  812.     
  813.     /**
  814.      * Used to convert <<br>> in a docblock
  815.      * @param string
  816.      * @return string
  817.      */
  818.     function Br($para)
  819.     {
  820.         if (!isset($this->template_options['desctranslate'])) return $para;
  821.         if (!isset($this->template_options['desctranslate']['br'])) return $para;
  822.         $para = $this->template_options['desctranslate']['br'] . $para;
  823.         return $para;
  824.     }
  825.     
  826.     /**
  827.      * This version does nothing
  828.      *
  829.      * Perform necessary post-processing of string data.  For example, the HTML
  830.      * Converters should escape < and > to become < and >
  831.      * @return string
  832.      */
  833.     function postProcess($text)
  834.     {
  835.         return $text;
  836.     }
  837.     
  838.     /**
  839.      * Creates a table of contents for a {@}toc} inline tag in a tutorial
  840.      * 
  841.      * This function should return a formatted table of contents.  By default, it
  842.      * does nothing, it is up to the converter to format the TOC
  843.      * @abstract
  844.      * @return string table of contents formatted for use in the current output format
  845.      * @param array format: array(array('tagname' => section, 'link' => returnsee link, 'id' => anchor name, 'title' => from title tag),...)
  846.      */
  847.     function formatTutorialTOC($toc)
  848.     {
  849.         return '';
  850.     }
  851.     
  852.     /**
  853.      * Write out the formatted source code for a php file
  854.      *
  855.      * This function provides the primary functionality for the
  856.      * {@tutorial tags.filesource.pkg} tag.
  857.      * @param string full path to the file
  858.      * @param string fully highlighted/linked source code of the file
  859.      * @abstract
  860.      */
  861.     function writeSource($filepath, $source)
  862.     {
  863.         debug($source);
  864.         return;
  865.     }
  866.     
  867.     /**
  868.      * Write out the formatted source code for an example php file
  869.      *
  870.      * This function provides the primary functionality for the
  871.      * {@tutorial tags.example.pkg} tag.
  872.      * @param string example title
  873.      * @param string example filename (no path)
  874.      * @param string fully highlighted/linked source code of the file
  875.      * @abstract
  876.      */
  877.     function writeExample($title, $path, $source)
  878.     {
  879.         return;
  880.     }
  881.     
  882.     /** Translate the path info into a unique file name for the highlighted
  883.      * source code.
  884.      * @param string $pathinfo
  885.      * @return string 
  886.      */
  887.     function getFileSourceName($path)
  888.     {
  889.         global $_phpDocumentor_options;
  890.         $pathinfo = $this->proceduralpages->getPathInfo($path, $this);
  891.         $pathinfo['source_loc'] = str_replace($_phpDocumentor_options['Program_Root'].'/','',$pathinfo['source_loc']);
  892.         $pathinfo['source_loc'] = str_replace('/','_',$pathinfo['source_loc']);
  893.         return "fsource_{$pathinfo['package']}_{$pathinfo['subpackage']}_{$pathinfo['source_loc']}";
  894.     }
  895.     
  896.     /** Return the fixed path to the source-code file folder.
  897.      * @param string $base Path is relative to this folder
  898.      * @return string 
  899.      */
  900.     function getFileSourcePath($base)
  901.     {
  902.         return $base . PATH_DELIMITER . '__filesource';
  903.     }
  904.     
  905.     /** Return the path to the current 
  906.      * @param string $pathinfo
  907.      * @return string 
  908.      */
  909.     function getCurrentPageURL()
  910.     {
  911.         return '{$srcdir}' . PATH_DELIMITER . $this->page_dir;
  912.     }
  913.  
  914.     /**
  915.      * @return string an output-format dependent link to phpxref-style highlighted
  916.      * source code
  917.      * @abstract
  918.      */
  919.     function getSourceLink($path)
  920.     {
  921.         return '';
  922.     }
  923.     
  924.     /**
  925.      * @return string Link to the current page being parsed.
  926.      * Should return {@link $curname} and a converter-specific extension.
  927.      * @abstract
  928.      */
  929.     function getCurrentPageLink()
  930.     {
  931.     }
  932.  
  933.     /**
  934.      * Return a line of highlighted source code with formatted line number
  935.      *
  936.      * If the $path is a full path, then an anchor to the line number will be
  937.      * added as well
  938.      * @param integer line number
  939.      * @param string highlighted source code line
  940.      * @param false|string full path to @filesource file this line is a part of,
  941.      *        if this is a single line from a complete file.
  942.      * @return string formatted source code line with line number
  943.      */
  944.     function sourceLine($linenumber, $line, $path = false)
  945.     {
  946.         if ($path)
  947.         {
  948.             return $this->getSourceAnchor($path, $linenumber) .
  949.                    $this->Br(sprintf('%-6u',$linenumber).str_replace("\n",'',$line));
  950.         } else
  951.         {
  952.             return $this->Br(sprintf('%-6u',$linenumber).str_replace("\n",'',$line));
  953.         }
  954.     }
  955.     
  956.     /**
  957.      * Determine whether an element's file has generated source code, used for
  958.      * linking to line numbers of source.
  959.      *
  960.      * Wrapper for {@link $sourcePaths} in this version
  961.      * @param string full path to the source code file
  962.      * @return boolean
  963.      */
  964.     function hasSourceCode($path)
  965.     {
  966.         return isset($this->sourcePaths[$path]);
  967.     }
  968.     
  969.     /**
  970.      * Mark a file as having had source code highlighted
  971.      * @param string full path of source file
  972.      */
  973.     function setSourcePaths($path)
  974.     {
  975.         $this->sourcePaths[$path] = true;
  976.     }
  977.     
  978.     /**
  979.      * Used to translate an XML DocBook entity like ” from a tutorial by
  980.      * reading the options.ini file for the template.
  981.      * @param string entity name
  982.      */
  983.     function TranslateEntity($name)
  984.     {
  985.         if (!isset($this->template_options['ppage']))
  986.         {
  987.             if (!$this->template_options['preservedocbooktags'])
  988.             return '';
  989.             else
  990.             return '&'.$name.';';
  991.         }
  992.         if (isset($this->template_options['ppage']['&'.$name.';']))
  993.         {
  994.             return $this->template_options['ppage']['&'.$name.';'];
  995.         } else
  996.         {
  997.             if (!$this->template_options['preservedocbooktags'])
  998.             return '';
  999.             else
  1000.             return '&'.$name.';';
  1001.         }
  1002.     }
  1003.     
  1004.     /**
  1005.      * Used to translate an XML DocBook tag from a tutorial by reading the
  1006.      * options.ini file for the template.
  1007.      * @param string tag name
  1008.      * @param string any attributes Format: array(name => value)
  1009.      * @param string the tag contents, if any
  1010.      * @param string the tag contents, if any, unpost-processed
  1011.      * @return string
  1012.      */
  1013.     function TranslateTag($name,$attr,$cdata,$unconvertedcdata)
  1014.     {
  1015.         if (!isset($this->template_options['ppage']))
  1016.         {
  1017.             if (!$this->template_options['preservedocbooktags'])
  1018.             return $cdata;
  1019.             else
  1020.             return '<'.$name.$this->AttrToString($name,$attr,true).'>'.$cdata.'</'.$name.'>'."\n";
  1021.         }
  1022.         // make sure this template transforms the tag into something
  1023.         if (isset($this->template_options['ppage'][$name]))
  1024.         {
  1025.             // test for global attribute transforms like $attr$role = class, changing
  1026.             // all role="*" attributes to class="*" in html, for example
  1027.             foreach($attr as $att => $val)
  1028.             {
  1029.                 if (isset($this->template_options['$attr$'.$att]))
  1030.                 {
  1031.                     $new = '';
  1032.                     if (!isset($this->template_options['$attr$'.$att]['close']))
  1033.                     {
  1034.                         $new .= '<'.$this->template_options['$attr$'.$att]['open'];
  1035.                         if (isset($this->template_options['$attr$'.$att]['cdata!']))
  1036.                         {
  1037.                             if (isset($this->template_options['$attr$'.$att]['separateall']))
  1038.                             $new .= $this->template_options['$attr$'.$att]['separator'];
  1039.                             else
  1040.                             $new .= ' ';
  1041.                             $new .= $this->template_options['$attr$'.$att]['$'.$att];
  1042.                             $new .= $this->template_options['$attr$'.$att]['separator'];
  1043.                             if ($this->template_options['$attr$'.$att]['quotevalues']) $val = '"'.$val.'"';
  1044.                             $new .= $val.'>';
  1045.                         } else
  1046.                         {
  1047.                             $new .= '>'.$val;
  1048.                         }
  1049.                         $new .= '</'.$this->template_options['$attr$'.$att]['open'].'>';
  1050.                     } else
  1051.                     {
  1052.                         $new .= $this->template_options['$attr$'.$att]['open'] . $val . $this->template_options['$attr$'.$att]['close'];
  1053.                     }
  1054.                     unset($attr[$att]);
  1055.                     $cdata = $new . $cdata;
  1056.                 }
  1057.             }
  1058.             
  1059.             if (!isset($this->template_options['ppage']['/'.$name]))
  1060.             {// if the close tag isn't specified, we put opening and closing tags around it, with translated attributes
  1061.                 if (isset($this->template_options['ppage'][$name.'/']))
  1062.                 $cdata = '<'.$this->template_options['ppage'][$name].$this->AttrToString($name,$attr).'/>' . $cdata;
  1063.                 else
  1064.                 $cdata = '<'.$this->template_options['ppage'][$name].$this->AttrToString($name,$attr).'>' . $cdata .
  1065.                          '</'.$this->template_options['ppage'][$name].'>';
  1066.             } else
  1067.             { // if close tag is specified, use the open and close as literal
  1068.                 if ($name == 'programlisting' && isset($attr['role']) && $attr['role'] == 'php')
  1069.                 { // highlight PHP source
  1070. //                    var_dump($unconvertedcdata, $cdata);exit;
  1071.                     $cdata = $this->ProgramExample($unconvertedcdata, true);
  1072.                 } // normal case below
  1073.                 $cdata = $this->template_options['ppage'][$name].$this->AttrToString($name,$attr). $cdata .$this->template_options['ppage']['/'.$name];
  1074.             }
  1075.             return $cdata;
  1076.         } else
  1077.         {
  1078.             if ($this->template_options['preservedocbooktags'])
  1079.             {
  1080.                 return '<'.$name.$this->AttrToString($name,$attr,true).'>' . $cdata .
  1081.                          '</'.$name.'>'."\n";
  1082.             } else
  1083.             {
  1084.                 return $cdata;
  1085.             }
  1086.         }
  1087.     }
  1088.     
  1089.     /**
  1090.      * Convert the attribute of a Tutorial docbook tag's attribute list
  1091.      * to a string based on the template options.ini
  1092.      * @param string tag name
  1093.      * @param attribute array
  1094.      * @param boolean if true, returns attrname="value"...
  1095.      * @return string
  1096.      */
  1097.     function AttrToString($tag,$attr,$unmodified = false)
  1098.     {
  1099.         $ret = '';
  1100.         if ($unmodified)
  1101.         {
  1102.             $ret = ' ';
  1103.             foreach($attr as $n => $v)
  1104.             {
  1105.                 $ret .= $n.' = "'.$v.'"';
  1106.             }
  1107.             return $ret;
  1108.         }
  1109.         // no_attr tells us to ignore all attributes
  1110.         if (isset($this->template_options['no_attr'])) return $ret;
  1111.         // tagname! tells us to ignore all attributes for this tag
  1112.         if (isset($this->template_options['ppage'][$tag.'!'])) return $ret;
  1113.         if (count($attr)) $ret = ' ';
  1114.         // pass 1, check to see if any attributes add together
  1115.         $same = array();
  1116.         foreach($attr as $n => $v)
  1117.         {
  1118.             if (isset($this->template_options['ppage'][$tag.'->'.$n]))
  1119.             {
  1120.                 $same[$this->template_options['ppage'][$tag.'->'.$n]][] = $n;
  1121.             }
  1122.         }
  1123.         foreach($attr as $n => $v)
  1124.         {
  1125.             if (isset($this->template_options['ppage'][$tag.'->'.$n]))
  1126.             {
  1127.                 if (count($same[$this->template_options['ppage'][$tag.'->'.$n]]) == 1)
  1128.                 { // only 1 attribute translated for this one
  1129.                     // this is useful for equivalent value names
  1130.                     if (isset($this->template_options['ppage'][$tag.'->'.$n.'+'.$v])) $v = $this->template_options['ppage'][$tag.'->'.$n.'+'.$v];
  1131.                 } else
  1132.                 { // more than 1 attribute combines to make the new attribute
  1133.                     $teststrtemp = array();
  1134.                     foreach($same[$this->template_options['ppage'][$tag.'->'.$n]] as $oldattr)
  1135.                     {
  1136.                         $teststrtemp[] = $oldattr.'+'.$attr[$oldattr];
  1137.                     }
  1138.                     $teststrs = array();
  1139.                     $num = count($same[$this->template_options['ppage'][$tag.'->'.$n]]);
  1140.                     for($i=0;$i<$num;$i++)
  1141.                     {
  1142.                         $started = false;
  1143.                         $a = '';
  1144.                         for($j=$i;!$started || $j != $i;$j = ($j + $i) % $num)
  1145.                         {
  1146.                             if (!empty($a)) $a .= '|';
  1147.                             $a .= $teststrtemp[$j];
  1148.                         }
  1149.                         $teststrs[$i] = $a;
  1150.                     }
  1151.                     $done = false;
  1152.                     foreach($teststrs as $test)
  1153.                     {
  1154.                         if ($done) break;
  1155.                         if (isset($this->template_options['ppage'][$tag.'->'.$test]))
  1156.                         {
  1157.                             $done = true;
  1158.                             $v = $this->template_options['ppage'][$tag.'->'.$test];
  1159.                         }
  1160.                     }
  1161.                 }
  1162.                 $ret .= $this->template_options['ppage'][$tag.'->'.$n].' = "'.$v.'"';
  1163.             } else
  1164.             {
  1165.                 if (!isset($this->template_options['ppage'][$tag.'!'.$n]))
  1166.                 {
  1167.                     if (isset($this->template_options['ppage']['$attr$'.$n]))
  1168.                     $ret .= $this->template_options['ppage']['$attr$'.$n].' = "'.$v.'"';
  1169.                     else
  1170.                     $ret .= $n.' = "'.$v.'"';
  1171.                 }
  1172.             }
  1173.         }
  1174.         return $ret;
  1175.     }
  1176.     
  1177.     /**
  1178.      * Convert the title of a Tutorial docbook tag section
  1179.      * to a string based on the template options.ini
  1180.      * @param string tag name
  1181.      * @param array
  1182.      * @param string title text
  1183.      * @param string
  1184.      * @return string
  1185.      */
  1186.     function ConvertTitle($tag,$attr,$title,$cdata)
  1187.     {
  1188.         if (!isset($this->template_options[$tag.'_title'])) return array($attr,$title.$cdata);
  1189.         if (isset($this->template_options[$tag.'_title']['tag_attr']))
  1190.         {
  1191.             $attr[$this->template_options[$tag.'_title']['tag_attr']] = urlencode($cdata);
  1192.             $cdata = '';
  1193.         } elseif(isset($this->template_options[$tag.'_title']['cdata_start']))
  1194.         {
  1195.             $cdata = $this->template_options[$tag.'_title']['open'] . $title .
  1196.                      $this->template_options[$tag.'_title']['close'] . $cdata;
  1197.         } else $cdata = $title.$cdata;
  1198.         return array($attr,$cdata);
  1199.     }
  1200.     
  1201.     /**
  1202.      * Return a converter-specific id to distinguish tutorials and their
  1203.      * sections
  1204.      *
  1205.      * Used by {@}id}
  1206.      * @return string
  1207.      */
  1208.     function getTutorialId($package,$subpackage,$tutorial,$id)
  1209.     {
  1210.         return $package.$subpackage.$tutorial.$id;
  1211.     }
  1212.     
  1213.     /**
  1214.      * Create the {@link $elements, $pkg_elements} and {@link $links} arrays
  1215.      * @access private
  1216.      * @todo version 2.0 - faulty package_output logic should be removed
  1217.      *
  1218.      *       in this version, if the parent file isn't in the package, all
  1219.      *       the procedural elements are simply shunted to another package!
  1220.      */
  1221.     function _createPkgElements(&$pages)
  1222.     {
  1223.         if (empty($this->elements))
  1224.         {
  1225.             $this->elements = array();
  1226.             $this->pkg_elements = array();
  1227.             $this->links = array();
  1228.             phpDocumentor_out('Building indexes...');
  1229.             flush();
  1230.             foreach($pages as $j => $flub)
  1231.             {
  1232.                 $this->package = $pages[$j]->parent->package;
  1233.                 $this->subpackage = $pages[$j]->parent->subpackage;
  1234.                 $this->class = false;
  1235.                 $this->curfile = $pages[$j]->parent->getFile();
  1236.                 $this->curname = $this->getPageName($pages[$j]->parent);
  1237.                 $this->curpath = $pages[$j]->parent->getPath();
  1238.                 $use = true;
  1239.                 if ($this->package_output)
  1240.                 {
  1241.                     if (in_array($this->package,$this->package_output))
  1242.                     {
  1243.                         $this->addElement($pages[$j]->parent,$pages[$j]);
  1244.                     } else
  1245.                     {
  1246.                         if (count($pages[$j]->classelements))
  1247.                         {
  1248.                             list(,$pages[$j]->parent->package) = each($this->package_output);
  1249.                             reset($this->package_output);
  1250.                             $pages[$j]->parent->subpackage = '';
  1251.                             $this->addElement($pages[$j]->parent,$pages[$j]);
  1252.                         } else
  1253.                         {
  1254.                             unset($pages[$j]);
  1255.                             continue;
  1256.                         }
  1257.                     }
  1258.                 } else
  1259.                 {
  1260.                     $this->addElement($pages[$j]->parent,$pages[$j]);
  1261.                 }
  1262.                 if ($use)
  1263.                 for($i=0; $i<count($pages[$j]->elements); $i++)
  1264.                 {
  1265.                     $pages[$j]->elements[$i]->docblock->package = $this->package;
  1266.                     $pages[$j]->elements[$i]->docblock->subpackage = $this->subpackage;
  1267.                     $this->proceduralpages->replaceElement($pages[$j]->elements[$i]);
  1268.                     $this->addElement($pages[$j]->elements[$i]);
  1269.                 }
  1270.                 for($i=0; $i<count($pages[$j]->classelements); $i++)
  1271.                 {
  1272.                     if ($this->class)
  1273.                     {
  1274.                         if ($pages[$j]->classelements[$i]->type == 'class')
  1275.                         {
  1276.                             if ($this->checkKillClass($pages[$j]->classelements[$i]->getName(),$pages[$j]->classelements[$i]->getPath())) continue;
  1277.                             $this->package = $pages[$j]->classelements[$i]->docblock->package;
  1278.                             if ($this->package_output) if (!in_array($this->package,$this->package_output)) continue;
  1279.                             $this->subpackage = $pages[$j]->classelements[$i]->docblock->subpackage;
  1280.                             $this->class = $pages[$j]->classelements[$i]->name;
  1281.                         } else
  1282.                         {
  1283.                             if ($this->killclass) continue;
  1284.                             // force all contained elements to have parent package/subpackage
  1285.                             $pages[$j]->classelements[$i]->docblock->package = $this->package;
  1286.                             $pages[$j]->classelements[$i]->docblock->subpackage = $this->subpackage;
  1287.                         }
  1288.                     }
  1289.                     if ($pages[$j]->classelements[$i]->type == 'class')
  1290.                     {
  1291.                         if ($this->checkKillClass($pages[$j]->classelements[$i]->getName(),$pages[$j]->classelements[$i]->getPath())) continue;
  1292.                         $this->package = $pages[$j]->classelements[$i]->docblock->package;
  1293.                         if ($this->package_output) if (!in_array($this->package,$this->package_output)) continue;
  1294.                         $this->subpackage = $pages[$j]->classelements[$i]->docblock->subpackage;
  1295.                         $this->class = $pages[$j]->classelements[$i]->name;
  1296.                     }
  1297.                     if (!$this->killclass) $this->addElement($pages[$j]->classelements[$i]);
  1298.                 }
  1299.             }
  1300.             phpDocumentor_out("done\n");
  1301.             flush();
  1302.         }
  1303.         $this->sortIndexes();
  1304.         $this->sortTodos();
  1305.         if ($this->sort_page_contents_by_type) $this->sortPageContentsByElementType($pages);
  1306.     }
  1307.     
  1308.     /**
  1309.      * Process the {@link $tutorials} array
  1310.      *
  1311.      * Using the tutorialname.ext.ini files, this method sets up tutorial
  1312.      * hierarchy.  There is some minimal error checking to make sure that no
  1313.      * tutorial links to itself, even two levels deep as in tute->next->tute.
  1314.      *
  1315.      * If all tests pass, it creates the hierarchy
  1316.      * @uses generateTutorialOrder()
  1317.      * @uses _setupTutorialTree()
  1318.      * @access private
  1319.      */
  1320.     function _processTutorials()
  1321.     {
  1322.         $parents = $all = array();
  1323.         foreach($this->tutorials as $package => $els)
  1324.         {
  1325.             if ($this->package_output)
  1326.             {
  1327.                 if (!in_array($package,$this->package_output))
  1328.                 {
  1329.                     unset($this->tutorials[$package]);
  1330.                     continue;
  1331.                 }
  1332.             }
  1333.             if (!isset($this->pkg_elements[$package]))
  1334.             {
  1335.                 unset($this->tutorials[$package]);
  1336.                 continue;
  1337.             }
  1338.             foreach($els as $subpackage => $els2)
  1339.             {
  1340.                 foreach($els2 as $type => $tutorials)
  1341.                 {
  1342.                     foreach($tutorials as $tutorial)
  1343.                     {
  1344.                         if ($tutorial->ini)
  1345.                         {
  1346.                             if (isset($tutorial->ini['Linked Tutorials']))
  1347.                             {
  1348.                                 foreach($tutorial->ini['Linked Tutorials'] as $child)
  1349.                                 {
  1350.                                     $sub = (empty($tutorial->subpackage) ? '' : $tutorial->subpackage . '/');
  1351.                                     $kid = $tutorial->package . '/' . $sub . $child . '.' . $tutorial->tutorial_type;
  1352.                                     // parent includes self as a linked tutorial?
  1353.                                     if ($this->returnSee($this->getTutorialLink($kid,false,false,array($tutorial->package))) == $tutorial->getLink($this))
  1354.                                     { // bad!
  1355.                                         addErrorDie(PDERROR_TUTORIAL_IS_OWN_CHILD,$tutorial->name,$tutorial->name.'.ini');
  1356.                                     }
  1357.                                 }
  1358.                                 $parents[] = $tutorial;
  1359.                             }
  1360.                         }
  1361.                         $all[$package][$subpackage][$type][] = $tutorial;
  1362.                     }
  1363.                 }
  1364.             }
  1365.         }
  1366.         // loop error-checking, use this to eliminate possibility of accidentally linking to a parent as a child
  1367.         $testlinks = array();
  1368.         foreach($parents as $parent)
  1369.         {
  1370.             $testlinks[$parent->name]['links'][] = $parent->getLink($this);
  1371.             $testlinks[$parent->name]['name'][$parent->getLink($this)] = $parent->name;
  1372.         }
  1373.         // generate the order of tutorials, and link them together
  1374.         foreach($parents as $parent)
  1375.         {
  1376.             foreach($parent->ini['Linked Tutorials'] as $child)
  1377.             {
  1378.                 $sub = (empty($parent->subpackage) ? '' : $parent->subpackage . '/');
  1379.                 $kid = $parent->package . '/' . $sub . $child . '.' . $parent->tutorial_type;
  1380.                 // child tutorials must be in the same package AND subpackage
  1381.                 // AND have the same extension as the parent, makes things clearer for both ends
  1382.                 if (in_array($this->returnSee($this->getTutorialLink($kid,false,false,array($parent->package))),$testlinks[$parent->name]['links']))
  1383.                     addErrorDie(PDERROR_TUTORIAL_IS_OWN_GRANDPA,$testlinks[$parent->name][$this->returnSee($this->getTutorialLink($kid,false,false,array($parent->package)))],$kid->name,$testlinks[$parent->name][$this->returnSee($this->getTutorialLink($kid,false,false,array($parent->package)))],$kid->name.'.ini');
  1384.                 if ($this->returnSee($this->getTutorialLink($kid,false,false,array($parent->package))) == $kid)
  1385.                 {
  1386.                     addWarning(PDERROR_CHILD_TUTORIAL_NOT_FOUND, $child . '.' . $parent->tutorial_type, $parent->name .'.ini',$parent->package, $parent->subpackage);
  1387.                 }
  1388.             }
  1389.         }
  1390.         $new = $tree = $roots = array();
  1391.                 // build a list of all 'root' tutorials (tutorials without parents).
  1392.         foreach($parents as $i => $parent)
  1393.         {
  1394.             if (! $parent->isChildOf($parents))
  1395.                             $roots[] = $parent;
  1396.         }
  1397.                 $parents = $roots;
  1398.         // add the parents and all child tutorials in order to the list of tutorials to process
  1399.         foreach($parents as $parent)
  1400.         {
  1401.             $this->generateTutorialOrder($parent,$all,$new);
  1402.         }
  1403.         if (count($all))
  1404.         {
  1405.             // add the leftover tutorials
  1406.             foreach($all as $package => $els)
  1407.             {
  1408.                 foreach($els as $subpackage => $els2)
  1409.                 {
  1410.                     foreach($els2 as $type => $tutorials)
  1411.                     {
  1412.                         foreach($tutorials as $tutorial)
  1413.                         {
  1414.                             $new[$package][$subpackage][$type][] = $tutorial;
  1415.                         }
  1416.                     }
  1417.                 }
  1418.             }
  1419.         }
  1420.         // remove the old, unprocessed tutorials, and set it up with the next code
  1421.         $this->tutorials = array();
  1422.         // reset integrity of the tutorial list
  1423.         $prev = false;
  1424.         uksort($new, 'tutorialcmp');
  1425. //        debug($this->vardump_tree($new));exit;
  1426.         foreach($new as $package => $els)
  1427.         {
  1428.             foreach($els as $subpackage => $els2)
  1429.             {
  1430.                 foreach($els2 as $type => $tutorials)
  1431.                 {
  1432.                     foreach($tutorials as $tutorial)
  1433.                     {
  1434.                         if ($prev)
  1435.                         {
  1436.                             $this->tutorials[$prevpackage][$prevsubpackage][$prevtype][$prevname]->setNext($tutorial,$this);
  1437.                             $tutorial->setPrev($prev,$this);
  1438.                         }
  1439.                         $this->tutorials[$package][$subpackage][$type][$tutorial->name] = $tutorial;
  1440.                         $prev = $tutorial->getLink($this,true);
  1441.                         $prevpackage = $package;
  1442.                         $prevsubpackage = $subpackage;
  1443.                         $prevtype = $type;
  1444.                         $prevname = $tutorial->name;
  1445.                     }
  1446.                 }
  1447.             }
  1448.         }
  1449.         $this->tutorial_tree = $this->_setupTutorialTree();
  1450.         return $new;
  1451.     }
  1452.     
  1453.     /**
  1454.     * called by {@link phpDocumentor_IntermediateParser::Convert()} to traverse
  1455.     * the array of pages and their elements, converting them to the output format
  1456.     *
  1457.     * The walk() method should be flexible enough such that it never needs
  1458.     * modification.  walk() sets up all of the indexes, and sorts everything in
  1459.     * logical alphabetical order.  It then passes each element individually to
  1460.     * {@link Convert()}, which then passes to the Convert*() methods.  A child
  1461.     * Converter need not override any of these unless special functionality must
  1462.     * be added. see {@tutorial Converters/template.vars.cls} for details.
  1463.     * {@internal
  1464.     * walk() first creates all of the indexes {@link $elements, $pkg_elements}
  1465.     * and the left indexes specified by {@link $leftindexes},
  1466.     * and then sorts them by calling {@link sortIndexes()}.
  1467.     *
  1468.     * Next, it converts all README/CHANGELOG/INSTALL-style files, using
  1469.     * {@link Convert_RIC}.
  1470.     *
  1471.     * After this, it
  1472.     * passes all package-level docs to Convert().  Then, it calls the index
  1473.     * sorting functions {@link formatPkgIndex(), formatIndex()} and
  1474.     * {@link formatLeftIndex()}.
  1475.     *
  1476.     * Finally, it converts each procedural page in alphabetical order.  This
  1477.     * stage passes elements from the physical file to Convert() in alphabetical
  1478.     * order.  First, procedural page elements {@link parserDefine, parserInclude}
  1479.     * {@link parserGlobal}, and {@link parserFunction} are passed to Convert().
  1480.     *
  1481.     * Then, class elements are passed in this order: {@link parserClass}, then
  1482.     * all of the {@link parserVar}s in the class and all of the
  1483.     * {@link parserMethod}s in the class.  Classes are in alphabetical order,
  1484.     * and both vars and methods are in alphabetical order.
  1485.     *
  1486.     * Finally, {@link ConvertErrorLog()} is called and the data walk is complete.}}
  1487.     * @param array Format: array(fullpath => {@link parserData} structure with full {@link parserData::$elements}
  1488.     *                                         and {@link parserData::$class_elements}.
  1489.     * @param array Format: array({@link parserPackagePage} 1, {@link parserPackagePage} 2,...)
  1490.     * @uses Converter::_createPkgElements() sets up {@link $elements} and
  1491.     *       {@link $pkg_elements} array, as well as {@link $links}
  1492.     */
  1493.     function walk(&$pages,&$package_pages)
  1494.     {
  1495.         if (empty($pages))
  1496.         {
  1497.             die("<b>ERROR</b>: nothing parsed");
  1498.         }
  1499.         $this->_createPkgElements($pages);
  1500.         if (count($this->ric))
  1501.         {
  1502.             phpDocumentor_out("Converting README/INSTALL/CHANGELOG contents...\n");
  1503.             flush();
  1504.             foreach($this->ric as $name => $contents)
  1505.             {
  1506.                 phpDocumentor_out("$name...");
  1507.                 flush();
  1508.                 $this->Convert_RIC($name,$contents);
  1509.             }
  1510.             phpDocumentor_out("\ndone\n");
  1511.             flush();
  1512.         }
  1513.         foreach($package_pages as $i => $perp)
  1514.         {
  1515.             if ($this->package_output)
  1516.             {
  1517.                 if (!in_array($package_pages[$i]->package,$this->package_output)) continue;
  1518.             }
  1519.             phpDocumentor_out('Converting package page for package '.$package_pages[$i]->package.'... ');
  1520.             flush();
  1521.             $this->package = $package_pages[$i]->package;
  1522.             $this->subpackage = '';
  1523.             $this->class = false;
  1524.             $this->Convert($package_pages[$i]);
  1525.             phpDocumentor_out("done\n");
  1526.             flush();
  1527.         }
  1528.         phpDocumentor_out("Converting tutorials/extended docs\n");
  1529.         flush();
  1530.         // get tutorials into the order they will display, and set next/prev links
  1531.         $new = $this->_processTutorials();
  1532.         foreach($this->tutorials as $package => $els)
  1533.         {
  1534.             foreach($els as $subpackage => $els2)
  1535.             {
  1536.                 foreach($els2 as $type => $tutorials)
  1537.                 {
  1538.                     foreach($tutorials as $tutorial)
  1539.                     {
  1540.                         switch ($type)
  1541.                         {
  1542.                             case 'pkg' :
  1543.                                 $a = '';
  1544.                                 if ($tutorial->ini)
  1545.                                 $a .= 'Top-level ';
  1546.                                 if (!empty($tutorial->subpackage))
  1547.                                 $a .= 'Sub-';
  1548.                                 $ptext = "Converting ${a}Package-level tutorial ".$tutorial->name.'...';
  1549.                             break;
  1550.                             case 'cls' :
  1551.                                 $a = '';
  1552.                                 if ($tutorial->ini)
  1553.                                 $a .= 'Top-level ';
  1554.                                 $ptext = "Converting ${a}Class-level tutorial " . $tutorial->name ." and associating...";
  1555.                                 $link = Converter::getClassLink(str_replace('.cls','',$tutorial->name), $tutorial->package);
  1556.                                 if (is_object($link))
  1557.                                 {
  1558.                                     if ($this->sort_absolutely_everything)
  1559.                                     {
  1560.                                         $addend = 'unsuccessful ';
  1561.                                         if (isset($this->package_elements[$tutorial->package][$tutorial->subpackage]['class'][$link->name]))
  1562.                                         {
  1563.                                             $this->package_elements[$tutorial->package][$tutorial->subpackage]['class'][$link->name][0]->addTutorial($tutorial,$this);
  1564.                                             $addend = 'success ';
  1565.                                         }
  1566.                                     } else
  1567.                                     {
  1568.                                         $addend = 'unsuccessful ';
  1569.                                         if (!isset($this->classes->killclass[str_replace('.cls','',$tutorial->name)]) && !isset($this->classes->killclass[str_replace('.cls','',$tutorial->name)][$tutorial->path]))
  1570.                                         {
  1571.                                             foreach($pages as $j => $inf)
  1572.                                             {
  1573.                                                 foreach($inf->classelements as $i => $class)
  1574.                                                 {
  1575.                                                     if ($class->type == 'class' && $class->name == str_replace('.cls','',$tutorial->name) && $class->path == $link->path)
  1576.                                                     {
  1577.                                                         $pages[$j]->classelements[$i]->addTutorial($tutorial,$this);
  1578.                                                         $addend = 'success ';
  1579.                                                     }
  1580.                                                 }
  1581.                                             }
  1582.                                         }
  1583.                                     }
  1584.                                     $ptext .= $addend;
  1585.                                 } else $ptext .= "unsuccessful ";
  1586.                             break;
  1587.                             case 'proc' :
  1588.                                 $a = '';
  1589.                                 if ($tutorial->ini)
  1590.                                 $a .= 'Top-level ';
  1591.                                 $ptext = "Converting ${a}Procedural-level tutorial ".$tutorial->name." and associating...";
  1592.                                 $link = Converter::getPageLink(str_replace('.proc','',$tutorial->name), $tutorial->package);
  1593.                                 if (is_object($link))
  1594.                                 {
  1595.                                     $addend = 'unsuccessful ';
  1596.                                     if ($this->sort_absolutely_everything)
  1597.                                     {
  1598.                                         if (isset($this->package_elements[$tutorial->package][$tutorial->subpackage]['page'][$link->path]))
  1599.                                         {
  1600.                                             $this->package_elements[$tutorial->package][$tutorial->subpackage]['page'][$link->path][0]->addTutorial($tutorial,$this);
  1601.                                             $addend = "success ";
  1602.                                         }
  1603.                                     } else
  1604.                                     {
  1605.                                         foreach($pages as $j => $info)
  1606.                                         {
  1607.                                             if ($j == $link->path)
  1608.                                             {
  1609.                                                 $pages[$j]->addTutorial($tutorial,$this);
  1610.                                                 $addend = "success ";
  1611.                                             }
  1612.                                         }
  1613.                                     }
  1614.                                     $ptext .= $addend;
  1615.                                 } else $ptext .= "unsuccessful ";
  1616.                             break;
  1617.                         }
  1618.                         phpDocumentor_out($ptext);
  1619.                         flush();
  1620.                         $this->package = $tutorial->package;
  1621.                         $this->subpackage = $tutorial->subpackage;
  1622.                         $this->Convert($tutorial);
  1623.                         phpDocumentor_out("done\n");
  1624.                         flush();
  1625.                     }
  1626.                 }
  1627.             }
  1628.         }
  1629.         phpDocumentor_out("Formatting Package Indexes...");
  1630.         flush();
  1631.         $this->formatPkgIndex();
  1632.         phpDocumentor_out("done\n");
  1633.         flush();
  1634.         phpDocumentor_out("Formatting Index...");
  1635.         flush();
  1636.         $this->formatIndex();
  1637.         phpDocumentor_out("done\n\n");
  1638.         flush();
  1639.         phpDocumentor_out("Formatting Left Quick Index...");
  1640.         flush();
  1641.         $this->formatLeftIndex();
  1642.         phpDocumentor_out("done\n\n");
  1643.         flush();
  1644.         if ($this->sort_absolutely_everything) return $this->walk_everything();
  1645.         foreach($pages as $j => $flub)
  1646.         {
  1647.             phpDocumentor_out('Converting '.$pages[$j]->parent->getPath());
  1648.             flush();
  1649.             $this->package = $pages[$j]->parent->package;
  1650.             $this->subpackage = $pages[$j]->parent->subpackage;
  1651.             $this->class = false;
  1652.             $this->curfile = $pages[$j]->parent->getFile();
  1653.             $this->curname = $this->getPageName($pages[$j]->parent);
  1654.             $this->curpath = $pages[$j]->parent->getPath();
  1655.             $use = true;
  1656.             if ($this->package_output)
  1657.             {
  1658.                 if (in_array($this->package,$this->package_output))
  1659.                 {
  1660.                     $this->Convert($pages[$j]);
  1661.                 } else
  1662.                 {
  1663.                     $use = false;
  1664.                 }
  1665.             } else
  1666.             {
  1667.                 $this->Convert($pages[$j]);
  1668.             }
  1669.             phpDocumentor_out(" Procedural Page Elements...");
  1670.             flush();
  1671.             if ($use)
  1672.             for($i=0; $i<count($pages[$j]->elements); $i++)
  1673.             {
  1674.                 $a = $pages[$j]->elements[$i]->docblock->getKeyword('access');
  1675.                 if ($a) $a = $a->getString();
  1676.                 if (!$this->parseprivate && ($a == 'private'))
  1677.                     continue;
  1678. //                phpDocumentor_out("    ".$pages[$j]->elements[$i]->name."\n");
  1679.                 $pages[$j]->elements[$i]->docblock->package = $this->package;
  1680.                 $pages[$j]->elements[$i]->docblock->subpackage = $this->subpackage;
  1681.                 $this->Convert($pages[$j]->elements[$i]);
  1682.             }
  1683.             phpDocumentor_out(" Classes...");
  1684.             flush();
  1685.             for($i=0; $i<count($pages[$j]->classelements); $i++)
  1686.             {
  1687.                 if ($this->class)
  1688.                 {
  1689.                     if ($pages[$j]->classelements[$i]->type == 'class')
  1690.                     {
  1691.                         if (!$this->killclass) $this->endClass();
  1692.                         $this->killclass = false;
  1693.                         if ($this->checkKillClass($pages[$j]->classelements[$i]->getName(),$pages[$j]->classelements[$i]->getPath())) continue;
  1694.                         $this->package = $pages[$j]->classelements[$i]->docblock->package;
  1695.                         if ($this->package_output) if (!in_array($this->package,$this->package_output)) continue;
  1696.                         $this->subpackage = $pages[$j]->classelements[$i]->docblock->subpackage;
  1697.                         $this->class = $pages[$j]->classelements[$i]->name;
  1698.                     } else
  1699.                     {
  1700.                         $a = $pages[$j]->classelements[$i]->docblock->getKeyword('access');
  1701.                         if ($a) $a = $a->getString();
  1702.                         if (!$this->parseprivate && ($a == 'private'))
  1703.                             continue;
  1704.                         if ($this->killclass) continue;
  1705.                         // force all contained elements to have parent package/subpackage
  1706.                         $pages[$j]->classelements[$i]->docblock->package = $this->package;
  1707.                         $pages[$j]->classelements[$i]->docblock->subpackage = $this->subpackage;
  1708.                     }
  1709.                 }
  1710.                 if ($pages[$j]->classelements[$i]->type == 'class')
  1711.                 {
  1712.                     $this->killclass = false;
  1713.                     if ($this->checkKillClass($pages[$j]->classelements[$i]->getName(),$pages[$j]->classelements[$i]->getPath())) continue;
  1714.                     $this->package = $pages[$j]->classelements[$i]->docblock->package;
  1715.                     if ($this->package_output) if (!in_array($this->package,$this->package_output)) continue;
  1716.                     $this->subpackage = $pages[$j]->classelements[$i]->docblock->subpackage;
  1717.                     $this->class = $pages[$j]->classelements[$i]->name;
  1718.                 }
  1719.                 if ($this->killclass) continue;
  1720. //                phpDocumentor_out("    ".$pages[$j]->classelements[$i]->name."\n");
  1721.                 $this->Convert($pages[$j]->classelements[$i]);
  1722.             }
  1723.             if (count($pages[$j]->classelements) && !$this->killclass) $this->endClass();
  1724.             phpDocumentor_out(" done\n");
  1725.             flush();
  1726.             $this->endPage();
  1727.         }
  1728.         phpDocumentor_out("\nConverting @todo List...");
  1729.         flush();
  1730.         if (count($this->todoList))
  1731.         {
  1732.             $this->ConvertTodoList();
  1733.         }
  1734.         phpDocumentor_out("done\n");
  1735.         flush();
  1736.         phpDocumentor_out("\nConverting Error Log...");
  1737.         flush();
  1738.         $this->ConvertErrorLog();
  1739.         phpDocumentor_out("done\n");
  1740.         flush();
  1741.     }
  1742.     
  1743.  
  1744.     /**
  1745.      * Get a tree structure representing the hierarchy of tutorials
  1746.      *
  1747.      * Returns an array in format:
  1748.      * <pre>
  1749.      * array('tutorial' => {@link parserTutorial},
  1750.      *       'kids' => array( // child tutorials
  1751.      *                   array('tutorial' => child {@link parserTutorial},
  1752.      *                         'kids' => array(...)
  1753.      *                        )
  1754.      *                      )
  1755.      *      )
  1756.      * </pre>
  1757.      * @param parserTutorial|array
  1758.      * @tutorial tutorials.pkg
  1759.      * @return array
  1760.      */
  1761.     function getTutorialTree($tutorial)
  1762.     {
  1763.         if (is_object($tutorial))
  1764.         {
  1765.                         $path = $tutorial->package . '/' . $tutorial->subpackage . '/' . $tutorial->name;
  1766.             if (isset($this->tutorial_tree[$path]))
  1767.                                 $tutorial = $this->tutorial_tree[$path];
  1768.             else
  1769.                                 return false;
  1770.         }
  1771.         $tree = array();
  1772.         if (isset($tutorial['tutorial']))
  1773.         {
  1774.             $tree['tutorial'] = $tutorial['tutorial'];
  1775.             if (isset($tutorial['child']))
  1776.             {
  1777.                 foreach($tutorial['child'] as $a => $b)
  1778.                 {
  1779.                                         $btut = $b['tutorial'];
  1780.                     $res['tutorial'] = $this->tutorials[$btut->package][$btut->subpackage][$btut->tutorial_type][$btut->name];
  1781.                     if (isset($b['child']))
  1782.                     {
  1783.                          $tempres = Converter::getTutorialTree($b);
  1784.                          $res['kids'] = $tempres['kids'];
  1785.                     }
  1786.                     $tree['kids'][] = $res;
  1787.                 }
  1788.             }
  1789.         }
  1790.         return $tree;
  1791.     }
  1792.     
  1793.     /**
  1794.      * Remove tutorials one by one from $all, and transfer them into $new in the
  1795.      * order they should be parsed
  1796.      * @param parserTutorial
  1797.      * @param array
  1798.      * @param array
  1799.      * @access private
  1800.      */
  1801.     function generateTutorialOrder($parent,&$all,&$new)
  1802.     {
  1803.         // remove from the list of tutorials to process
  1804.         foreach($all[$parent->package][$parent->subpackage][$parent->tutorial_type] as $ind => $t)
  1805.         {
  1806.             if ($t->name == $parent->name)
  1807.             unset($all[$parent->package][$parent->subpackage][$parent->tutorial_type][$ind]);
  1808.         }
  1809.         // add to the new ordered list of tutorials
  1810.         $x = &$new[$parent->package][$parent->subpackage][$parent->tutorial_type];
  1811.         if ($x[count($x) - 1]->name != $parent->name)
  1812.         { // only add if the parent isn't also a child
  1813.             $new[$parent->package][$parent->subpackage][$parent->tutorial_type][] = $parent;
  1814.             // add a new branch to the tree
  1815.         }
  1816.         // process all child tutorials, and insert them in order
  1817. //        debug("processing parent ".$parent->name);
  1818.         if ($parent->ini)
  1819.         {
  1820.             foreach($parent->ini['Linked Tutorials'] as $child)
  1821.             {
  1822.                 $sub = (empty($parent->subpackage) ? '' : $parent->subpackage . '/');
  1823.                 $kid = $parent->package . '/' . $sub . $child . '.' . $parent->tutorial_type;
  1824.                 $klink = $this->returnSee($this->getTutorialLink($kid,false,false,array($parent->package)));
  1825.                 // remove the child from the list of remaining tutorials
  1826.                 foreach($all[$parent->package][$parent->subpackage][$parent->tutorial_type] as $ind => $tute)
  1827.                 {
  1828.                     if ($tute->getLink($this) == $klink)
  1829.                     {
  1830.                         // set up parent, next and prev links
  1831.                         $tute->setParent($parent, $this);
  1832.                         // remove the child from the list of tutorials to process
  1833.                         foreach($all[$parent->package][$parent->subpackage][$parent->tutorial_type] as $ind => $t)
  1834.                         {
  1835.                             if ($t->name == $tute->name)
  1836.                             unset($all[$parent->package][$parent->subpackage][$parent->tutorial_type][$ind]);
  1837.                         }
  1838.                         // add to the new ordered list of tutorials
  1839.                         $new[$parent->package][$parent->subpackage][$parent->tutorial_type][] = $tute;
  1840.                         if ($tute->ini)
  1841.                         {
  1842.                             // add all the child's child tutorials to the list
  1843.                             $this->generateTutorialOrder($tute,$all,$new);
  1844.                         }
  1845.                     }
  1846.                 }
  1847.             }
  1848.         }
  1849.         return;
  1850.     }
  1851.     
  1852.         /** Returns the path to this tutorial as a string
  1853.          * @param parserTutorial $pkg 
  1854.          * @param parserTutorial $subpkg 
  1855.          * @param parserTutorial $namepkg 
  1856.          * @return string */
  1857.         function _tutorial_path($pkg, $subpkg = 0, $namepkg = 0)
  1858.         {
  1859.             if (! $subpkg)
  1860.                 $subpkg = $pkg;
  1861.             if (! $namepkg)
  1862.                 $namepkg = $pkg;
  1863.             return $pkg->package.'/'.$subpkg->subpackage.'/'.$namepkg->name;
  1864.         }
  1865.  
  1866.  
  1867.     /**
  1868.      * Creates a tree structure of tutorials
  1869.      *
  1870.      * Format:
  1871.      * <pre>
  1872.      * array('package/subpackage/tutorial1.ext' => 
  1873.      *          array('tutorial' => {@link parserTutorial},
  1874.      *                'child'    =>
  1875.      *                    array('package/subpackage/child1tutorial.ext' => ...,
  1876.      *                          'package/subpackage/child2tutorial.ext' => ...,
  1877.      *                          ...
  1878.      *                         )
  1879.      *       'package/subpackage/tutorial2.ext' => ...,
  1880.      *       ...
  1881.      *       )
  1882.      * </pre>
  1883.      * @return array the tutorial tree
  1884.      * @access private
  1885.      */
  1886.     function _setupTutorialTree($parent = false)
  1887.     {
  1888.                 if (! isset($this->processed_tutorials))
  1889.                         $this->processed_tutorials = array();
  1890.         $tree = array();
  1891.         if (!$parent)
  1892.         {
  1893.             foreach($this->tutorials as $package => $s)
  1894.             {
  1895.                 foreach($s as $subpackage => $t)
  1896.                 {
  1897.                     foreach($t as $type => $n)
  1898.                     {
  1899.                         foreach($n as $name => $tutorial)
  1900.                         {
  1901.                             if (!$tutorial->parent)
  1902.                             {
  1903.                                                                 $child_path = $this->_tutorial_path($tutorial,$tutorial,$tutorial);
  1904.                                                                 if (! isset($this->processed_tutorials[$child_path]))
  1905.                                                                 {
  1906.                                                                         $this->processed_tutorials[$child_path] = $tutorial;
  1907.                                                                         //debug("parent ".$tutorial->name);
  1908.                                                                         $ret = $this->_setupTutorialTree($tutorial);
  1909.                                                                         if (!count($tree)) 
  1910.                                                                             $tree = $ret; 
  1911.                                                                         else
  1912.                                                                             $tree = array_merge($tree,$ret);
  1913.                                                                 }
  1914.                             }
  1915.                         }
  1916.                     }
  1917.                 }
  1918.             }
  1919.             return $tree;
  1920.         }
  1921.                 $parent_path = $this->_tutorial_path($parent);
  1922.         $tree[$parent_path]['tutorial'] = $parent;
  1923.         // process all child tutorials, and insert them in order
  1924.         if ($parent->ini)
  1925.         {
  1926.             foreach($parent->ini['Linked Tutorials'] as $child)
  1927.             {
  1928.                 if (isset($this->tutorials[$parent->package][$parent->subpackage][$parent->tutorial_type][$child . '.' . $parent->tutorial_type]))
  1929.                                                 // remove the child from the list of remaining tutorials
  1930.                                         $tute = $this->tutorials[$parent->package][$parent->subpackage][$parent->tutorial_type][$child . '.' . $parent->tutorial_type];
  1931.                 else 
  1932.                                         $tute = false;
  1933.  
  1934.                 if ($tute)
  1935.                 {
  1936.                                         $child_path = $this->_tutorial_path($parent,$parent,$tute);
  1937.                                         if (! isset($this->processed_tutorials[$child_path]))
  1938.                                         {
  1939.                                                 $this->processed_tutorials[$child_path] = $tute;
  1940.                                                 if ($tute->name == $child . '.' . $parent->tutorial_type)
  1941.                                                 {
  1942. //                                                        echo "Adding [$child_path] to [$parent_path]<br>";
  1943.                                                         $tree[$parent_path]['child'][$this->_tutorial_path($parent,$parent,$tute)]['tutorial'] = $tute;
  1944.                                                         if ($tute->ini)
  1945.                                                         {
  1946.                                                                 // add all the child's child tutorials to the list
  1947.                                                                 if (!isset($tree[$parent_path]['child']))
  1948.                                                                         $tree[$parent_path]['child'] = $this->_setupTutorialTree($tute);
  1949.                                                                 else
  1950.                                                                         $tree[$parent_path]['child'] = array_merge($tree[$parent_path]['child'],$this->_setupTutorialTree($tute));
  1951.                                                         }
  1952.                                                 }
  1953.                                         }
  1954.                 }
  1955.             }
  1956.         }
  1957.         return $tree;
  1958.     }
  1959.     
  1960.     /**
  1961.      * Debugging function for dumping {@link $tutorial_tree}
  1962.      * @return string
  1963.      */
  1964.     function vardump_tree($tree,$indent='')
  1965.     {
  1966.         if (get_class($tree) == 'parsertutorial') return $tree->name.' extends '.($tree->parent? $tree->parent->name : 'nothing');
  1967.         $a = '';
  1968.         foreach($tree as $ind => $stuff)
  1969.         {
  1970.             $x = $this->vardump_tree($stuff,"$indent   ");
  1971.             $a .= $indent.'['.$ind." => \n   ".$indent.$x."]\n";
  1972.         }
  1973.         return substr($a,0,strlen($a) - 1);
  1974.     }
  1975.     
  1976.     /**
  1977.      * @access private
  1978.      */
  1979.     function sort_package_elements($a,$b)
  1980.     {
  1981.         if (($a->type == $b->type) && (isset($a->isConstructor) && $a->isConstructor)) return -1;
  1982.         if (($a->type == $b->type) && (isset($b->isConstructor) && $b->isConstructor)) return 1;
  1983.         if ($a->type == $b->type) return strnatcasecmp($a->name,$b->name);
  1984.         if ($a->type == 'class') return -1;
  1985.         if ($b->type == 'class') return 1;
  1986.         if ($a->type == 'var') return -1;
  1987.         if ($b->type == 'var') return 1;
  1988.         if ($a->type == 'page') return -1;
  1989.         if ($b->type == 'page') return 1;
  1990.         if ($a->type == 'include') return -1;
  1991.         if ($b->type == 'include') return 1;
  1992.         if ($a->type == 'define') return -1;
  1993.         if ($b->type == 'define') return 1;
  1994.         if ($a->type == 'global') return -1;
  1995.         if ($b->type == 'global') return 1;
  1996.         if ($a->type == 'function') return -1;
  1997.         if ($b->type == 'function') return 1;
  1998.     }
  1999.     
  2000.     /**
  2001.      * @access private
  2002.      */
  2003.     function defpackagesort($a,$b)
  2004.     {
  2005.         if ($a == $GLOBALS['phpDocumentor_DefaultPackageName']) return -1;
  2006.         if ($b == $GLOBALS['phpDocumentor_DefaultPackageName']) return 0;
  2007.         return strnatcasecmp($a,$b);
  2008.     }
  2009.  
  2010.     /**
  2011.      * @access private
  2012.      */
  2013.     function Pc_sort($a,$b)
  2014.     {
  2015.         return strnatcasecmp(key($a),key($b));
  2016.     }
  2017.     
  2018.     /**
  2019.      * walk over elements by package rather than page
  2020.      *
  2021.      * This method is designed for converters like the PDF converter that need
  2022.      * everything passed in alphabetical order by package/subpackage and by
  2023.      * procedural and then class information
  2024.      * @see PDFdefaultConverter
  2025.      * @see walk()
  2026.      */
  2027.     function walk_everything()
  2028.     {
  2029.         global $hooser;
  2030.         $hooser = false;
  2031.         uksort($this->package_elements,array($this,'defpackagesort'));
  2032.         foreach($this->package_elements as $package => $r)
  2033.         {
  2034.             if ($this->package_output)
  2035.             {
  2036.                 if (!in_array($this->package,$this->package_output))
  2037.                 {
  2038.                     unset($this->package_elements[$package]);
  2039.                     continue;
  2040.                 }
  2041.             }
  2042.             uksort($this->package_elements[$package],'strnatcasecmp');
  2043.         }
  2044.         foreach($this->package_elements as $package => $r)
  2045.         {
  2046.             foreach($this->package_elements[$package] as $subpackage => $r)
  2047.             {
  2048.                 if (isset($r['page']))
  2049.                 {
  2050.                     uksort($r['page'],'strnatcasecmp');
  2051.                     foreach($r['page'] as $page => $oo)
  2052.                     {
  2053.                         usort($this->package_elements[$package][$subpackage]['page'][$page],array($this,'sort_package_elements'));
  2054.                     }
  2055.                 }
  2056.                 if (isset($r['class']))
  2057.                 {
  2058.                     uksort($r['class'],'strnatcasecmp');
  2059.                     foreach($r['class'] as $page => $oo)
  2060.                     {
  2061.                         usort($r['class'][$page],array($this,'sort_package_elements'));
  2062.                     }
  2063.                 }
  2064.                 $this->package_elements[$package][$subpackage] = $r;
  2065.             }
  2066.         }
  2067.         foreach($this->package_elements as $package => $s)
  2068.         {
  2069.             $notyet = false;
  2070.             foreach($s as $subpackage => $r)
  2071.             {
  2072.                 $this->package = $package;
  2073.                 $this->subpackage = $subpackage;
  2074.                 if (isset($r['page']))
  2075.                 {
  2076.                     $this->class = false;
  2077.                     foreach($r['page'] as $page => $elements)
  2078.                     {
  2079.                         if (is_array($elements))
  2080.                         {
  2081.                             foreach($elements as $element)
  2082.                             {
  2083.                                 if ($element->type == 'page')
  2084.                                 {
  2085.                                     phpDocumentor_out('Converting '.$element->parent->getPath());
  2086.                                     flush();
  2087.                                     $this->curfile = $element->parent->getFile();
  2088.                                     $this->curname = $this->getPageName($element->parent);
  2089.                                     $this->curpath = $element->parent->getPath();
  2090.                                     $notyet = true;
  2091.                                 } else
  2092.                                 {
  2093.                                     // force all contained elements to have parent package/subpackage
  2094.                                     $element->docblock->package = $this->package;
  2095.                                     $element->docblock->subpackage = $this->subpackage;
  2096.                                     $a = $element->docblock->getKeyword('access');
  2097.                                     if ($a) $a = $a->getString();
  2098.                                     if (!$this->parseprivate && ($a == 'private'))
  2099.                                         continue;
  2100.                                 }
  2101.                                 if ($notyet)
  2102.                                 {
  2103.                                     phpDocumentor_out(" Procedural Page Elements...");
  2104.                                     flush();
  2105.                                     $notyet = false;
  2106.                                 }
  2107.                                 $this->Convert($element);
  2108.                             }
  2109.                         }
  2110.                         $this->endPage();
  2111.                         phpDocumentor_out("done\n");
  2112.                         flush();
  2113.                     }
  2114.                 }
  2115.                 $start_classes = true;
  2116.                 if (isset($r['class']))
  2117.                 {
  2118.                     foreach($r['class'] as $class => $elements)
  2119.                     {
  2120.                         foreach($elements as $element)
  2121.                         {
  2122.                             if ($element->type == 'class')
  2123.                             {
  2124.                                 if (!$start_classes)
  2125.                                 {
  2126.                                     if (count($elements) && !$this->killclass) $this->endClass();
  2127.                                     phpDocumentor_out("done\n");
  2128.                                     flush();
  2129.                                 }
  2130.                                 $start_classes = false;
  2131.                                 $this->class = $element->getName();
  2132.                                 $this->killclass = false;
  2133.                                 if ($this->checkKillClass($element->getName(),$element->getPath())) continue;
  2134.                                 if (!$this->killclass)
  2135.                                 {
  2136.                                     phpDocumentor_out('Converting '.$this->class."...");
  2137.                                     flush();
  2138.                                     $notyet = true;
  2139.                                 }
  2140.                             } else
  2141.                             {
  2142.                                 if ($notyet)
  2143.                                 {
  2144.                                     phpDocumentor_out("Variables/methods...\n");
  2145.                                     flush();
  2146.                                     $notyet = false;
  2147.                                 }
  2148.                                 $a = $element->docblock->getKeyword('access');
  2149.                                 if ($a) $a = $a->getString();
  2150.                                 if (!$this->parseprivate && ($a == 'private'))
  2151.                                     continue;
  2152.                                 if ($this->killclass) continue;
  2153.                                 // force all contained elements to have parent package/subpackage
  2154.                                 $element->docblock->package = $this->package;
  2155.                                 $element->docblock->subpackage = $this->subpackage;
  2156.                             }
  2157.                             if ($this->killclass) continue;
  2158.                             $this->Convert($element);
  2159.                         }
  2160.                     }
  2161.                     if (count($elements) && !$this->killclass) $this->endClass();
  2162.                     phpDocumentor_out("done\n");
  2163.                     flush();
  2164.                 } // if isset($r['class'])
  2165.             } // foreach($s
  2166.         } // foreach($this->package_elements)
  2167.         phpDocumentor_out("\nConverting @todo List...");
  2168.         flush();
  2169.         if (count($this->todoList))
  2170.         {
  2171.             $this->ConvertTodoList();
  2172.         }
  2173.         phpDocumentor_out("done\n");
  2174.         flush();
  2175.         phpDocumentor_out("\nConverting Error Log...");
  2176.         flush();
  2177.         $this->ConvertErrorLog();
  2178.         phpDocumentor_out("done\n");
  2179.         flush();
  2180.     }
  2181.     
  2182.     /**
  2183.      * Convert the phpDocumentor parsing/conversion error log
  2184.      * @abstract
  2185.      */
  2186.     function ConvertErrorLog()
  2187.     {
  2188.     }
  2189.     
  2190.     /**
  2191.      * Convert the list of all @todo tags
  2192.      * @abstract
  2193.      */
  2194.     function ConvertTodoList()
  2195.     {
  2196.     }
  2197.     
  2198.     /**
  2199.      * Sorts the @todo list - do not override or modify this function
  2200.      * @access private
  2201.      * @uses _sortTodos passed to {@link usort()} to sort the todo list
  2202.      */
  2203.     function sortTodos()
  2204.     {
  2205.         phpDocumentor_out("\nSorting @todo list...");
  2206.         flush();
  2207.         foreach($this->todoList as $package => $r)
  2208.         usort($this->todoList[$package],array($this, '_sortTodos'));
  2209.         phpDocumentor_out("done\n");
  2210.     }
  2211.     
  2212.     /** @access private */
  2213.     function _sortTodos($a, $b)
  2214.     {
  2215.         return strnatcasecmp($a[0]->name, $b[0]->name);
  2216.     }
  2217.     
  2218.     /**
  2219.      * Sorts all indexes - do not override or modify this function
  2220.      * @uses $leftindex based on the value of leftindex, sorts link arrays
  2221.      * @uses $class_elements sorts with {@link compareLink}
  2222.      * @uses $page_elements sorts with {@link compareLink}
  2223.      * @uses $define_elements sorts with {@link compareLink}
  2224.      * @uses $global_elements sorts with {@link compareLink}
  2225.      * @uses $function_elements sorts with {@link compareLink}
  2226.      * @uses $elements sorts with {@link elementCmp}
  2227.      * @uses $pkg_elements sorts with {@link elementCmp} after sorting by
  2228.      *                     package/subpackage alphabetically
  2229.      * @access private
  2230.      */
  2231.     function sortIndexes()
  2232.     {
  2233.         phpDocumentor_out("\nSorting Indexes...");
  2234.         flush();
  2235.         uksort($this->elements,'strnatcasecmp');
  2236.         if ($this->leftindex['classes'])
  2237.         {
  2238.             foreach($this->class_elements as $package => $o1)
  2239.             {
  2240.                 foreach($o1 as $subpackage => $links)
  2241.                 {
  2242.                     usort($this->class_elements[$package][$subpackage],array($this,'compareLink'));
  2243.                 }
  2244.             }
  2245.         }
  2246.         if ($this->leftindex['pages'])
  2247.         {
  2248.             foreach($this->page_elements as $package => $o1)
  2249.             {
  2250.                 uksort($this->page_elements[$package],'strnatcasecmp');
  2251.                 foreach($o1 as $subpackage => $links)
  2252.                 {
  2253.                     usort($this->page_elements[$package][$subpackage],array($this,'compareLink'));
  2254.                 }
  2255.             }
  2256.         }
  2257.         if ($this->leftindex['defines'])
  2258.         {
  2259.             foreach($this->define_elements as $package => $o1)
  2260.             {
  2261.                 uksort($this->define_elements[$package],'strnatcasecmp');
  2262.                 foreach($o1 as $subpackage => $links)
  2263.                 {
  2264.                     usort($this->define_elements[$package][$subpackage],array($this,'compareLink'));
  2265.                 }
  2266.             }
  2267.         }
  2268.         if ($this->leftindex['globals'])
  2269.         {
  2270.             foreach($this->global_elements as $package => $o1)
  2271.             {
  2272.                 uksort($this->global_elements[$package],'strnatcasecmp');
  2273.                 foreach($o1 as $subpackage => $links)
  2274.                 {
  2275.                     usort($this->global_elements[$package][$subpackage],array($this,'compareLink'));
  2276.                 }
  2277.             }
  2278.         }
  2279.         if ($this->leftindex['functions'])
  2280.         {
  2281.             foreach($this->function_elements as $package => $o1)
  2282.             {
  2283.                 uksort($this->function_elements[$package],'strnatcasecmp');
  2284.                 foreach($o1 as $subpackage => $links)
  2285.                 {
  2286.                     usort($this->function_elements[$package][$subpackage],array($this,'compareLink'));
  2287.                 }
  2288.             }
  2289.         }
  2290.         foreach($this->elements as $letter => $nothuing)
  2291.         {
  2292.             uasort($this->elements[$letter],array($this,"elementCmp"));
  2293.         }
  2294.         foreach($this->pkg_elements as $package => $els)
  2295.         {
  2296.             uksort($this->pkg_elements[$package],'strnatcasecmp');
  2297.             foreach($this->pkg_elements[$package] as $subpackage => $els)
  2298.             {
  2299.                 if (empty($els)) continue;
  2300.                 uksort($this->pkg_elements[$package][$subpackage],'strnatcasecmp');
  2301.                 foreach($els as $letter => $yuh)
  2302.                 {
  2303.                     usort($this->pkg_elements[$package][$subpackage][$letter],array($this,"elementCmp"));
  2304.                 }
  2305.             }
  2306.         }
  2307.         phpDocumentor_out("done\n");
  2308.         flush();
  2309.     }
  2310.     
  2311.     /**
  2312.      * sorts {@link $page_contents} by element type as well as alphabetically
  2313.      * @see $sort_page_contents_by_element_type
  2314.      */
  2315.     function sortPageContentsByElementType(&$pages)
  2316.     {
  2317.         foreach($this->page_contents as $package => $els)
  2318.         {
  2319.             foreach($this->page_contents[$package] as $subpackage => $els)
  2320.             {
  2321.                 if (empty($els)) continue;
  2322.                 foreach($this->page_contents[$package][$subpackage] as $path => $stuff)
  2323.                 {
  2324.                     if (!count($pages[$path]->elements)) continue;
  2325.                     usort($pages[$path]->elements,array($this,'eltypecmp'));
  2326.                     usort($this->page_contents[$package][$subpackage][$path],array($this,'eltypecmp'));
  2327.                     if (isset($this->page_contents[$package][$subpackage][$path][0]))
  2328.                     $this->page_contents[$package][$subpackage][$path]['###main'] = $this->page_contents[$package][$subpackage][$path][0];
  2329.                     unset($this->page_contents[$package][$subpackage][$path][0]);
  2330.                 }
  2331.             }
  2332.         }
  2333.     }
  2334.     
  2335.     /**
  2336.      * @access private
  2337.      * @see Converter::sortIndexes()
  2338.      */
  2339.     function compareLink($a, $b)
  2340.     {
  2341.          return strnatcasecmp($a->name,$b->name);
  2342.     }
  2343.     
  2344.     /**
  2345.      * @access private
  2346.      * @see Converter::sortPageContentsByElementType()
  2347.      */
  2348.     function eltypecmp($a, $b)
  2349.     {
  2350.         if ($a->type == 'page') return -1;
  2351.         if ($b->type == 'page') return 1;
  2352.          return strnatcasecmp($a->type.$a->name,$b->type.$b->name);
  2353.     }
  2354.     
  2355.     /**
  2356.      * does a nat case sort on the specified second level value of the array
  2357.      *
  2358.      * @param    mixed    $a
  2359.      * @param    mixed    $b
  2360.      * @return    int
  2361.      * @access private
  2362.      */
  2363.     function elementCmp ($a, $b)
  2364.     {
  2365.         return strnatcasecmp($a->getName(), $b->getName());
  2366.     }
  2367.  
  2368.     /**
  2369.      * Used to stop conversion of @ignored or private @access classes
  2370.      * @uses $killclass sets killclass based on the value of {@link Classes::$killclass}
  2371.      *       and {@link $package_output}
  2372.      * @access private
  2373.      */
  2374.     function checkKillClass($class, $path)
  2375.     {
  2376.         $this->killclass = false;
  2377.         if (isset($this->classes->killclass[$class]) && isset($this->classes->killclass[$class][$path])) $this->killclass = true;
  2378.         if ($this->package_output)
  2379.         {
  2380.             $a = $this->classes->getClass($class, $path);
  2381.             if (!in_array($a->docblock->package,$this->package_output)) $this->killclass = true;
  2382.         }
  2383.         if (PHPDOCUMENTOR_DEBUG && $this->killclass) debug("$class $path killed");
  2384.         return $this->killclass;
  2385.     }
  2386.     
  2387.     /**
  2388.      * @param abstractLink descendant of abstractLink
  2389.      * @param array|parserTag list of @todos|@todo tag
  2390.      * @access private
  2391.      */
  2392.     function addTodoLink($link, $todos)
  2393.     {
  2394.         $this->todoList[$link->package][] = array($link, $todos);
  2395.     }
  2396.     
  2397.     /**
  2398.      * Adds all elements to the {@link $elements, $pkg_elements, $links},
  2399.      * {@link $linkswithfile} and left indexes - Do not modify or override
  2400.      * @access private
  2401.      * @param parserBase any documentable element descendant of parserBase
  2402.      *                   except parserTutorial
  2403.      * @param false|parserPage only used to add a {@link parserPage} if the
  2404.      *                         $element passed is a parserPage
  2405.      * @staticvar string path of current page, used for {@link $page_contents} setup
  2406.      */
  2407.     function addElement(&$element,$pageel=false)
  2408.     {
  2409.         static $curpath = '';
  2410.         if ($this->package_output)
  2411.         {
  2412.             if (!in_array($this->package, $this->package_output)) return;
  2413.         }
  2414.         if ($pageel && get_class($pageel) == 'parserdata')
  2415.         {
  2416.             if (isset($pageel->docblock) && get_class($pageel->docblock) == 'parserdocblock')
  2417.             {
  2418.                 $a = $pageel->docblock->getKeyword('todo');
  2419.                 if ($a)
  2420.                 {
  2421.                     $this->addTodoLink($this->addLink($element),$a);
  2422.                 }
  2423.             }
  2424.         }
  2425.         if (isset($element->docblock))
  2426.         {
  2427.             $a = $element->docblock->getKeyword('access');
  2428.             if ($a) $a = $a->getString();
  2429.             if (!$this->parseprivate && ($a == 'private'))
  2430.                 return;
  2431.             $a = $element->docblock->getKeyword('todo');
  2432.             if ($a)
  2433.             {
  2434.                 $this->addTodoLink($this->addLink($element),$a);
  2435.             }
  2436.         }
  2437.         $i = 0;
  2438.         switch($element->type)
  2439.         {
  2440.             case 'page' :
  2441.                 if ($this->sort_absolutely_everything)
  2442.                 {
  2443.                     $this->package_elements[$element->package][$element->subpackage]['page'][$element->getPath()][] = $pageel;
  2444.                 }
  2445.                 $link = $this->addLink($element);
  2446.                 $curpath = $element->getPath();
  2447.                 if ($this->leftindex['pages'])
  2448.                 $this->page_elements[$element->package][$element->subpackage][] = $link;
  2449.                 $this->page_contents[$element->package][$element->subpackage][$curpath]['###main'] = $link;
  2450.             break;
  2451.             case 'class' :
  2452.                 if ($this->sort_absolutely_everything)
  2453.                 {
  2454.                     $this->package_elements[$element->docblock->package][$element->docblock->subpackage]['class'][$this->class][] = $element;
  2455.                 }
  2456.                 $link = $this->addLink($element);
  2457.                 if ($this->leftindex['classes'])
  2458.                 $this->class_elements[$element->docblock->package][$element->docblock->subpackage][] = $link;
  2459.                 $this->class_contents[$element->docblock->package][$element->docblock->subpackage][$this->class]['###main'] = $link;
  2460.             break;
  2461.             case 'include' :
  2462.                 if ($this->sort_absolutely_everything)
  2463.                 {
  2464.                     $this->package_elements[$element->docblock->package][$element->docblock->subpackage]['page'][$curpath][] = $element;
  2465.                 }
  2466.                 $link = $this->addLink($element);
  2467.             break;
  2468.             case 'define' :
  2469.                 if ($this->sort_absolutely_everything)
  2470.                 {
  2471.                     $this->package_elements[$element->docblock->package][$element->docblock->subpackage]['page'][$curpath][] = $element;
  2472.                 }
  2473.                 $link = $this->addLink($element);
  2474.                 if ($this->leftindex['defines'])
  2475.                 $this->define_elements[$element->docblock->package][$element->docblock->subpackage][] = $link;
  2476.                 $this->page_contents[$element->docblock->package][$element->docblock->subpackage][$curpath][] = $link;
  2477.             break;
  2478.             case 'global' :
  2479.                 if ($this->sort_absolutely_everything)
  2480.                 {
  2481.                     $this->package_elements[$element->docblock->package][$element->docblock->subpackage]['page'][$curpath][] = $element;
  2482.                 }
  2483.                 $link = $this->addLink($element);
  2484.                 $i++;
  2485.                 if ($this->leftindex['globals'])
  2486.                 $this->global_elements[$element->docblock->package][$element->docblock->subpackage][] = $link;
  2487.                 $this->page_contents[$element->docblock->package][$element->docblock->subpackage][$curpath][] = $link;
  2488.             break;
  2489.             case 'var' :
  2490.                 if ($this->sort_absolutely_everything)
  2491.                 {
  2492.                     $this->package_elements[$element->docblock->package][$element->docblock->subpackage]['class'][$this->class][] = $element;
  2493.                 }
  2494.                 $link = $this->addLink($element);
  2495.                 $i++;
  2496.                 $this->class_contents[$element->docblock->package][$element->docblock->subpackage][$this->class][] = $link;
  2497.             break;
  2498.             case 'method' :
  2499.                 if ($this->sort_absolutely_everything)
  2500.                 {
  2501.                     $this->package_elements[$element->docblock->package][$element->docblock->subpackage]['class'][$this->class][] = $element;
  2502.                 }
  2503.                 $link = $this->addLink($element);
  2504.                 $this->class_contents[$element->docblock->package][$element->docblock->subpackage][$this->class][] = $link;
  2505.             break;
  2506.             case 'function' :
  2507.                 if ($this->sort_absolutely_everything)
  2508.                 {
  2509.                     $this->package_elements[$element->docblock->package][$element->docblock->subpackage]['page'][$curpath][] = $element;
  2510.                 }
  2511.                 $link = $this->addLink($element);
  2512.                 if ($this->leftindex['functions'])
  2513.                 $this->function_elements[$element->docblock->package][$element->docblock->subpackage][] = $link;
  2514.                 $this->page_contents[$element->docblock->package][$element->docblock->subpackage][$curpath][] = $link;
  2515.             break;
  2516.             default :
  2517.             break;
  2518.         }
  2519.         if ($element->getType() != 'include')
  2520.         {
  2521.             if ($element->getType() == 'var' || $element->getType() == 'method')
  2522.             {
  2523.                 $this->links[$this->package][$this->subpackage][$element->getType()][$element->class][$element->getName()] = $link;
  2524.                 $this->linkswithfile[$this->package][$this->subpackage][$element->getType()][$element->getPath()][$element->class][$element->getName()] = $link;
  2525.             } else
  2526.             {
  2527.                 if ($element->type == 'page')
  2528.                 {
  2529.                     $this->links[$this->package][$this->subpackage][$element->getType()][$element->getFile()] = $link;
  2530.                     $this->linkswithfile[$this->package][$this->subpackage][$element->getType()][$element->getPath()][$element->getFile()] = $link;
  2531.                 } else
  2532.                 {
  2533.                     $this->links[$this->package][$this->subpackage][$element->getType()][$element->getName()] = $link;
  2534.                     $this->linkswithfile[$this->package][$this->subpackage][$element->getType()][$element->getPath()][$element->getName()] = $link;
  2535.                 }
  2536.             }
  2537.         }
  2538.         if ($element->type == 'page')
  2539.         {
  2540.             $this->elements[substr(strtolower($element->getFile()),$i,1)][] = $element;
  2541.             $this->pkg_elements[$this->package][$this->subpackage][substr(strtolower($element->getFile()),$i,1)][] = $element;
  2542.         } else
  2543.         {
  2544.             $this->elements[substr(strtolower($element->getName()),$i,1)][] = $element;
  2545.             $this->pkg_elements[$this->package][$this->subpackage][substr(strtolower($element->getName()),$i,1)][] = $element;
  2546.         }
  2547.     }
  2548.     
  2549.     /**
  2550.      * returns an abstract link to element.  Do not modify or override
  2551.      *
  2552.      * This method should only be called in process of Conversion, unless
  2553.      * $element is a parserPage, or $page is set to true, and $element is
  2554.      * not a parserPage
  2555.      * @return abstractLink abstractLink descendant
  2556.      * @access private
  2557.      * @param parserElement element to add a new link (descended from
  2558.      *                      {@link abstractLink})to the {@link $links} array
  2559.      * @param string classname for elements that are class-based (this may be
  2560.      *               deprecated in the future, as the classname
  2561.      *               should be contained within the element.  if $element is a
  2562.      *               page, this parameter is a package name
  2563.      * @param string subpackage name for page elements
  2564.      */
  2565.     function addLink(&$element,$page = false)
  2566.     {
  2567.         if ($page)
  2568.         {
  2569.             // create a fake parserPage to extract the fileAlias for this link
  2570.             $fakepage = new parserPage;
  2571.             $fakepage->setPath($element->getPath());
  2572.             $fakepage->setFile(basename($element->getPath()));
  2573.             $this->curname = $this->getPageName($fakepage);
  2574.         }
  2575.         switch($element->type)
  2576.         {
  2577.             case 'function':
  2578.                 $x = new functionLink;
  2579.                 $x->addLink($element->getPath(), $this->curname, $element->name, $element->docblock->package, $element->docblock->subpackage, $element->docblock->category);
  2580.                 return $x;
  2581.             break;
  2582.             case 'define':
  2583.                 $x = new defineLink;
  2584.                 $x->addLink($element->getPath(), $this->curname, $element->name, $element->docblock->package, $element->docblock->subpackage, $element->docblock->category);
  2585.                 return $x;
  2586.             break;
  2587.             case 'global':
  2588.                 $x = new globalLink;
  2589.                 $x->addLink($element->getPath(), $this->curname, $element->name, $element->docblock->package, $element->docblock->subpackage, $element->docblock->category);
  2590.                 return $x;
  2591.             break;
  2592.             case 'class':
  2593.                 $x = new classLink;
  2594.                 $x->addLink($element->getPath(), $this->curname, $element->name, $element->docblock->package, $element->docblock->subpackage, $element->docblock->category);
  2595.                 return $x;
  2596.             break;
  2597.             case 'method':
  2598.                 $x = new methodLink;
  2599.                 $x->addLink($this->class, $element->getPath(), $this->curname, $element->name, $element->docblock->package, $element->docblock->subpackage, $element->docblock->category);
  2600.                 return $x;
  2601.             break;
  2602.             case 'var':
  2603.                 $x = new varLink;
  2604.                 $x->addLink($this->class, $element->getPath(), $this->curname, $element->name, $element->docblock->package, $element->docblock->subpackage, $element->docblock->category);
  2605.                 return $x;
  2606.             break;
  2607.             case 'page':
  2608.                 $x = new pageLink;
  2609.                 $x->addLink($element->getPath(),$this->getPageName($element),$element->file,$element->package, $element->subpackage, $element->category);
  2610.                 return $x;
  2611.             break;
  2612.         }
  2613.     }
  2614.  
  2615.     /**
  2616.      * Return a tree of all classes that extend this class
  2617.      *
  2618.      * The data structure returned is designed for a non-recursive algorithm,
  2619.      * and is somewhat complex.
  2620.      * In most cases, the array returned is:
  2621.      *
  2622.      * <pre>
  2623.      * array('#root' => 
  2624.      *         array('link' => {@link classLink} to $class,
  2625.      *               'parent' => false,
  2626.      *               'children' => array(array('class' => 'childclass1',
  2627.      *                                         'package' => 'child1package'),
  2628.      *                                    array('class' => 'childclass2',
  2629.      *                                         'package' => 'child2package'),...
  2630.      *                                  )
  2631.      *               ),
  2632.      *       'child1package#childclass1' =>
  2633.      *         array('link' => {@link classLink} to childclass1,
  2634.      *               'parent' => '#root',
  2635.      *               'children' => array(array('class' => 'kidclass',
  2636.      *                                         'package' => 'kidpackage'),...
  2637.      *                                  )
  2638.      *              ),
  2639.      *       'kidpackage#kidclass' =>
  2640.      *         array('link' => {@link classLink} to kidclass,
  2641.      *               'parent' => 'child1package#childclass1',
  2642.      *               'children' => array() // no children
  2643.      *              ),
  2644.      *      ....
  2645.      *      )
  2646.      *</pre>
  2647.      *
  2648.      * To describe this format using language, every class in the tree has an
  2649.      * entry in the first level of the array.  The index for all child
  2650.      * classes that extend the root class is childpackage#childclassname.
  2651.      * Each entry in the array has 3 elements: link, parent, and children.
  2652.      * <ul>
  2653.      *  <li>link - a {@link classLink} to the current class</li>
  2654.      *  <li>parent - a {@link classLink} to the class's parent, or false (except for one special case described below)</li>
  2655.      *  <li>children - an array of arrays, each entry has a 'class' and 'package' index to the child class,
  2656.      * used to find the entry in the big array</li>
  2657.      * </ul>
  2658.      *
  2659.      * special cases are when the #root class has a parent in another package,
  2660.      * or when the #root class extends a class not found
  2661.      * by phpDocumentor.  In the first case, parent will be a
  2662.      * classLink to the parent class.  In the second, parent will be the
  2663.      * extends clause, as in:
  2664.      * <code>
  2665.      * class X extends Y
  2666.      * {
  2667.      * ...
  2668.      * }
  2669.      * </code>
  2670.      * in this case, the #root entry will be array('link' => classLink to X, 'parent' => 'Y', children => array(...))
  2671.      *
  2672.      * The fastest way to design a method to process the array returned
  2673.      * is to copy HTMLframesConverter::getRootTree() into
  2674.      * your converter and to modify the html to whatever output format you are going to use
  2675.      * @see HTMLframesConverter::getRootTree()
  2676.      * @param string class name
  2677.      * @param string
  2678.      * @param string
  2679.      * @return array Format: see docs 
  2680.      */
  2681.     function getSortedClassTreeFromClass($class,$package,$subpackage)
  2682.     {
  2683.         $my_tree = array();
  2684.         $root = $this->classes->getClassByPackage($class,$package);
  2685.         if (!$root) return false;
  2686.         $class_children = $this->classes->getDefiniteChildren($class,$root->curfile);
  2687.         if (!$class_children)
  2688.         {
  2689.             // special case: parent class is found, but is not part of this package, class has no children
  2690.             if (is_array($root->parent))
  2691.             {
  2692.                 $x = $root->getParent($this);
  2693.                 if ($x->docblock->package != $package)
  2694.                 {
  2695.                     $v = Converter::getClassLink($root->getName(),$package,$root->getPath());
  2696.                     return array('#root' => array('link' => $v,'parent' => Converter::getClassLink($x->getName(),$x->docblock->package,$x->getPath()), 'children' => array()));
  2697.                 }
  2698.             } else
  2699.             { // class has normal situation, no children
  2700.                 if (is_string($root->getParent($this)))
  2701.                 return array('#root' => array('link' => Converter::getClassLink($root->getName(),$package,$root->getPath()), 'parent' => $root->getExtends(),'children' => array()));
  2702.                 else
  2703.                 return array('#root' => array('link' => Converter::getClassLink($root->getName(),$package,$root->getPath()), 'parent' => false, 'children' => array()));
  2704.             }
  2705.         }
  2706.         // special case: parent class is found, but is not part of this package, class has children
  2707.         if (is_array($root->parent))
  2708.         {
  2709.             $x = $root->getParent($this);
  2710.             if ($x->docblock->package != $package)
  2711.             {
  2712.                 $v = Converter::getClassLink($root->getName(),$package,$root->getPath());
  2713.                 $my_tree = array('#root' => array('link' => $v, 'parent' => Converter::getClassLink($x->getName(),$x->docblock->package,$x->getPath()), 'children' => array()));
  2714.             } else
  2715.             {
  2716.             }
  2717.         } else
  2718.         $my_tree = array('#root' => array('link' => Converter::getClassLink($root->getName(),$package,$root->getPath()), 'parent' => false, 'children' => array()));
  2719.         // location of tree walker
  2720.         $cur = '#root';
  2721.         $lastcur = array(array(false,0));
  2722.         $childpos = 0;
  2723.         if (isset($class_children))
  2724.         {
  2725.             do
  2726.             {
  2727.                 if (!$class_children)
  2728.                 {
  2729.                     list($cur, $childpos) = array_pop($lastcur);
  2730.                     if (isset($my_tree[$cur]['children'][$childpos + 1]))
  2731.                     {
  2732.                         array_push($lastcur, array($cur, $childpos + 1));
  2733.                         $par = $cur;
  2734.                         $cur = $my_tree[$cur]['children'][$childpos + 1];
  2735.                         $x = $this->classes->getClassByPackage($cur['class'],$cur['package']);
  2736.                         $childpos = 0;
  2737.                         $cur = $cur['package'] . '#' . $cur['class'];
  2738.                         $my_tree[$cur]['link'] = Converter::getClassLink($x->getName(),$x->docblock->package,$x->getPath());
  2739.                         $my_tree[$cur]['parent'] = $par;
  2740.                         $my_tree[$cur]['children'] = array();
  2741.                         $class_children = $this->classes->getDefiniteChildren($x->getName(), $x->curfile);
  2742.                         continue;
  2743.                     } else
  2744.                     {
  2745.                         $class_children = false;
  2746.                         continue;
  2747.                     }
  2748.                 }
  2749.                 foreach($class_children as $chileclass => $chilefile)
  2750.                 {
  2751.                     $ch = $this->classes->getClass($chileclass,$chilefile);
  2752.                     $my_tree[$cur]['children'][] = array('class' => $ch->getName(), 'package' => $ch->docblock->package);
  2753.                 }
  2754.                 usort($my_tree[$cur]['children'],'rootcmp');
  2755.                 if (isset($my_tree[$cur]['children'][$childpos]))
  2756.                 {
  2757.                     array_push($lastcur, array($cur, $childpos));
  2758.                     $par = $cur;
  2759.                     $cur = $my_tree[$cur]['children'][$childpos];
  2760.                     $x = $this->classes->getClassByPackage($cur['class'],$cur['package']);
  2761.                     $cur = $cur['package'] . '#' . $cur['class'];
  2762.                     $my_tree[$cur]['link'] = Converter::getClassLink($x->getName(),$x->docblock->package,$x->getPath());
  2763.                     $my_tree[$cur]['parent'] = $par;
  2764.                     $my_tree[$cur]['children'] = array();
  2765.                     $childpos = 0;
  2766.                     $class_children = $this->classes->getDefiniteChildren($x->getName(), $x->curfile);
  2767.                 } else
  2768.                 {
  2769.                     list($cur, $childpos) = array_pop($lastcur);
  2770.                 }
  2771.             } while ($cur);
  2772.         }
  2773.         return $my_tree;
  2774.     }
  2775.     
  2776.     /**
  2777.      * do not override
  2778.      * @return bool true if a link to this class exists in package $package and subpackage $subpackage
  2779.      * @param string $expr class name
  2780.      * @param string $package package to search in
  2781.      * @param string $subpackage subpackage to search in
  2782.      * @access private
  2783.      */
  2784.     function isLinkedClass($expr,$package,$subpackage,$file=false)
  2785.     {
  2786.         if ($file)
  2787.         return isset($this->linkswithfile[$package][$subpackage]['class'][$file][$expr]);
  2788.         return isset($this->links[$package][$subpackage]['class'][$expr]);
  2789.     }
  2790.     
  2791.     /**
  2792.      * do not override
  2793.      * @return bool true if a link to this function exists in package $package and subpackage $subpackage
  2794.      * @param string $expr function name
  2795.      * @param string $package package to search in
  2796.      * @param string $subpackage subpackage to search in
  2797.      * @access private
  2798.      */
  2799.     function isLinkedFunction($expr,$package,$subpackage,$file=false)
  2800.     {
  2801.         if ($file)
  2802.         return isset($this->linkswithfile[$package][$subpackage]['function'][$file][$expr]);
  2803.         return isset($this->links[$package][$subpackage]['function'][$expr]);
  2804.     }
  2805.     
  2806.     /**
  2807.      * do not override
  2808.      * @return bool true if a link to this define exists in package $package and subpackage $subpackage
  2809.      * @param string $expr define name
  2810.      * @param string $package package to search in
  2811.      * @param string $subpackage subpackage to search in
  2812.      * @access private
  2813.      */
  2814.     function isLinkedDefine($expr,$package,$subpackage,$file=false)
  2815.     {
  2816.         if ($file)
  2817.         return isset($this->linkswithfile[$package][$subpackage]['define'][$file][$expr]);
  2818.         return isset($this->links[$package][$subpackage]['define'][$expr]);
  2819.     }
  2820.     
  2821.     /**
  2822.      * do not override
  2823.      * @return bool true if a link to this define exists in package $package and subpackage $subpackage
  2824.      * @param string $expr define name
  2825.      * @param string $package package to search in
  2826.      * @param string $subpackage subpackage to search in
  2827.      * @access private
  2828.      */
  2829.     function isLinkedGlobal($expr,$package,$subpackage,$file=false)
  2830.     {
  2831.         if ($file)
  2832.         return isset($this->linkswithfile[$package][$subpackage]['global'][$file][$expr]);
  2833.         return isset($this->links[$package][$subpackage]['global'][$expr]);
  2834.     }
  2835.     
  2836.     /**
  2837.      * do not override
  2838.      * @return bool true if a link to this procedural page exists in package $package and subpackage $subpackage
  2839.      * @param string $expr procedural page name
  2840.      * @param string $package package to search in
  2841.      * @param string $subpackage subpackage to search in
  2842.      * @access private
  2843.      */
  2844.     function isLinkedPage($expr,$package,$subpackage,$path=false)
  2845.     {
  2846.         if ($path)
  2847.         return isset($this->linkswithfile[$package][$subpackage]['page'][$path][$expr]);
  2848.         return isset($this->links[$package][$subpackage]['page'][$expr]);
  2849.     }
  2850.     
  2851.     /**
  2852.      * do not override
  2853.      * @return bool true if a link to this method exists in package $package, subpackage $subpackage and class $class
  2854.      * @param string $expr method name
  2855.      * @param string $class class name
  2856.      * @param string $package package to search in
  2857.      * @param string $subpackage subpackage to search in
  2858.      * @access private
  2859.      */
  2860.     function isLinkedMethod($expr,$package,$subpackage,$class,$file=false)
  2861.     {
  2862.         if ($file)
  2863.         return isset($this->linkswithfile[$package][$subpackage]['method'][$file][$class][$expr]);
  2864.         return isset($this->links[$package][$subpackage]['method'][$class][$expr]);
  2865.     }
  2866.     
  2867.     /**
  2868.      * do not override
  2869.      * @return bool true if a link to this method exists in package $package, subpackage $subpackage and class $class
  2870.      * @param string $expr method name
  2871.      * @param string $class class name
  2872.      * @param string $package package to search in
  2873.      * @param string $subpackage subpackage to search in
  2874.      * @access private
  2875.      */
  2876.     function isLinkedVar($expr,$package,$subpackage,$class,$file=false)
  2877.     {
  2878.         if ($file)
  2879.         return isset($this->linkswithfile[$package][$subpackage]['var'][$file][$class][$expr]);
  2880.         return isset($this->links[$package][$subpackage]['var'][$class][$expr]);
  2881.     }
  2882.     
  2883.     /**
  2884.      * return false or a {@link classLink} to $expr
  2885.      * @param string $expr class name
  2886.      * @param string $package package name
  2887.      * @return mixed returns a {@link classLink} or false if the element is not found in package $package
  2888.      * @see classLink
  2889.      */
  2890.     function getClassLink($expr,$package,$file=false, $text = false)
  2891.     {
  2892.         if (!isset($this->links[$package])) return false;
  2893.         foreach($this->links[$package] as $subpackage => $notused)
  2894.         {
  2895.             if ($this->isLinkedClass($expr,$package,$subpackage,$file))
  2896.             {
  2897.                 if ($file)
  2898.                 {
  2899.                     return $this->linkswithfile[$package][$subpackage]['class'][$file][$expr];
  2900.                 }
  2901.                 return $this->links[$package][$subpackage]['class'][$expr];
  2902.             }
  2903.         }
  2904.         return false;
  2905.     }
  2906.  
  2907.     /**
  2908.      * return false or a {@link functionLink} to $expr
  2909.      * @param string $expr function name
  2910.      * @param string $package package name
  2911.      * @return mixed returns a {@link functionLink} or false if the element is not found in package $package
  2912.      * @see functionLink
  2913.      */
  2914.     function getFunctionLink($expr,$package,$file=false, $text = false)
  2915.     {
  2916.         if (!isset($this->links[$package])) return false;
  2917.         foreach($this->links[$package] as $subpackage => $notused)
  2918.         {
  2919.             if ($this->isLinkedFunction($expr,$package,$subpackage,$file))
  2920.             {
  2921.                 if ($file)
  2922.                 {
  2923.                     return $this->linkswithfile[$package][$subpackage]['function'][$file][$expr];
  2924.                 }
  2925.                 return $this->links[$package][$subpackage]['function'][$expr];
  2926.             }
  2927.         }
  2928.         return false;
  2929.     }
  2930.  
  2931.     /**
  2932.      * return false or a {@link defineLink} to $expr
  2933.      * @param string $expr constant name
  2934.      * @param string $package package name
  2935.      * @return mixed returns a {@link defineLink} or false if the element is not found in package $package
  2936.      * @see defineLink
  2937.      */
  2938.     function getDefineLink($expr,$package,$file=false, $text = false)
  2939.     {
  2940.         if (!isset($this->links[$package])) return false;
  2941.         foreach($this->links[$package] as $subpackage => $notused)
  2942.         {
  2943.             if ($this->isLinkedDefine($expr,$package,$subpackage,$file))
  2944.             {
  2945.                 if ($file)
  2946.                 {
  2947.                     return $this->linkswithfile[$package][$subpackage]['define'][$file][$expr];
  2948.                 }
  2949.                 return $this->links[$package][$subpackage]['define'][$expr];
  2950.             }
  2951.         }
  2952.         return false;
  2953.     }
  2954.  
  2955.     /**
  2956.      * return false or a {@link globalLink} to $expr
  2957.      * @param string $expr global variable name (with leading $)
  2958.      * @param string $package package name
  2959.      * @return mixed returns a {@link defineLink} or false if the element is not found in package $package
  2960.      * @see defineLink
  2961.      */
  2962.     function getGlobalLink($expr,$package,$file=false, $text = false)
  2963.     {
  2964.         if (!isset($this->links[$package])) return false;
  2965.         foreach($this->links[$package] as $subpackage => $notused)
  2966.         {
  2967.             if ($this->isLinkedGlobal($expr,$package,$subpackage,$file))
  2968.             {
  2969.                 if ($file)
  2970.                 {
  2971.                     return $this->linkswithfile[$package][$subpackage]['global'][$file][$expr];
  2972.                 }
  2973.                 return $this->links[$package][$subpackage]['global'][$expr];
  2974.             }
  2975.         }
  2976.         return false;
  2977.     }
  2978.     
  2979.     /**
  2980.      * return false or a {@link pageLink} to $expr
  2981.      * @param string $expr procedural page name
  2982.      * @param string $package package name
  2983.      * @return mixed returns a {@link pageLink} or false if the element is not found in package $package
  2984.      * @see pageLink
  2985.      */
  2986.     function getPageLink($expr,$package,$path = false, $text = false, $packages = false)
  2987.     {
  2988.         if (!isset($this->links[$package])) return false;
  2989.         foreach($this->links[$package] as $subpackage => $notused)
  2990.         {
  2991.             if ($this->isLinkedPage($expr,$package,$subpackage,$path))
  2992.             {
  2993.                 if ($path)
  2994.                 {
  2995.                     return $this->linkswithfile[$package][$subpackage]['page'][$path][$expr];
  2996.                 }
  2997.                 return $this->links[$package][$subpackage]['page'][$expr];
  2998.             }
  2999.         }
  3000.         return false;
  3001.     }
  3002.  
  3003.     /**
  3004.      * return false or a {@link methodLink} to $expr in $class
  3005.      * @param string $expr method name
  3006.      * @param string $class class name
  3007.      * @param string $package package name
  3008.      * @return mixed returns a {@link methodLink} or false if the element is not found in package $package, class $class
  3009.      * @see methodLink
  3010.      */
  3011.     function getMethodLink($expr,$class,$package,$file=false, $text = false)
  3012.     {
  3013.         $expr = trim($expr);
  3014.         $class = trim($class);
  3015.         if (!isset($this->links[$package])) return false;
  3016.         foreach($this->links[$package] as $subpackage => $notused)
  3017.         {
  3018.             if ($this->isLinkedMethod($expr,$package,$subpackage,$class,$file))
  3019.             {
  3020.                 if ($file)
  3021.                 {
  3022.                     return $this->linkswithfile[$package][$subpackage]['method'][$file][$class][$expr];
  3023.                 }
  3024.                 return $this->links[$package][$subpackage]['method'][$class][$expr];
  3025.             }
  3026.         }
  3027.         return false;
  3028.     }
  3029.  
  3030.     /**
  3031.      * return false or a {@link varLink} to $expr in $class
  3032.      * @param string $expr var name
  3033.      * @param string $class class name
  3034.      * @param string $package package name
  3035.      * @return mixed returns a {@link varLink} or false if the element is not found in package $package, class $class
  3036.      * @see varLink
  3037.      */
  3038.     function getVarLink($expr,$class,$package,$file=false, $text = false)
  3039.     {
  3040.         $expr = trim($expr);
  3041.         $class = trim($class);
  3042.         if (!isset($this->links[$package])) return false;
  3043.         foreach($this->links[$package] as $subpackage => $notused)
  3044.         {
  3045.             if ($this->isLinkedVar($expr,$package,$subpackage,$class,$file))
  3046.             {
  3047.                 if ($file)
  3048.                 {
  3049.                     return $this->linkswithfile[$package][$subpackage]['var'][$file][$class][$expr];
  3050.                 }
  3051.                 return $this->links[$package][$subpackage]['var'][$class][$expr];
  3052.             }
  3053.         }
  3054.         return false;
  3055.     }
  3056.     
  3057.     /**
  3058.      * The meat of the @tutorial tag and inline {@}tutorial} tag
  3059.      *
  3060.      * Take a string and return an abstract link to the tutorial it represents.
  3061.      * Since tutorial naming literally works like the underlying filesystem, the
  3062.      * way to reference the tutorial is similar.  Tutorials are located in a
  3063.      * subdirectory of any directory parsed, which is named 'tutorials/' (we
  3064.      * try to make things simple when we can :).  They are further organized by
  3065.      * package and subpackage as:
  3066.      *
  3067.      * tutorials/package/subpackage
  3068.      *
  3069.      * and the files are named *.cls, *.pkg, or *.proc, and so a link to a tutorial
  3070.      * named file.cls can be referenced (depending on context) as any of:
  3071.      *
  3072.      * <code>
  3073.      * * @tutorial package/subpackage/file.cls
  3074.      * * @tutorial package/file.cls
  3075.      * * @tutorial file.cls
  3076.      * </code>
  3077.      *
  3078.      * The first case will only be needed if file.cls exists in both the current
  3079.      * package, in anotherpackage/file.cls and in anotherpackage/subpackage/file.cls
  3080.      * and you wish to reference the one in anotherpackage/subpackage.
  3081.      * The second case is only needed if you wish to reference file.cls in another
  3082.      * package and it is unique in that package. the third will link to the first
  3083.      * file.cls it finds using this search method:
  3084.      *
  3085.      * <ol>
  3086.      *    <li>current package/subpackage</li>
  3087.      *    <li>all other subpackages of current package</li>
  3088.      *    <li>parent package, if this package has classes that extend classes in
  3089.      *    another package</li>
  3090.      *    <li>all other packages</li>
  3091.      * </ol>
  3092.      * @return tutorialLink|string returns either a link, or the original text, if not found
  3093.      * @param string the original expression
  3094.      * @param string package to look in first
  3095.      * @param string subpackage to look in first
  3096.      * @param array array of package names to search in if not found in parent packages.
  3097.      *              This is used to limit the search, phpDocumentor automatically searches
  3098.      *              all packages
  3099.      * @since 1.2
  3100.      */
  3101.     function getTutorialLink($expr, $package = false, $subpackage = false, $packages = false)
  3102.     {
  3103.         // is $expr a comma-delimited list?
  3104.         if (strpos($expr,','))
  3105.         {
  3106.             $a = explode(',',$expr);
  3107.             $b = array();
  3108.             for($i=0;$i<count($a);$i++)
  3109.             {
  3110.                 // if so return each component with a link
  3111.                 $b[] = Converter::getTutorialLink(trim($a[$i]));
  3112.             }
  3113.             return $b;
  3114.         }
  3115.         $subsection = '';
  3116.         if (strpos($expr,'#'))
  3117.         {
  3118.             $a = explode('#',$expr);
  3119.             $org = $expr;
  3120.             $expr = $a[0];
  3121.             $subsection = $a[1];
  3122.         }
  3123.         if (strpos($expr,'/'))
  3124.         {
  3125.             $a = explode('/',$expr);
  3126.             if (count($a) == 3)
  3127.             {
  3128.                 return Converter::getTutorialLink($a[2],$a[0],$a[1],array());
  3129.             }
  3130.             if (count($a) == 2)
  3131.             {
  3132.                 return Converter::getTutorialLink($a[1],$a[0],false,array());
  3133.             }
  3134.         }
  3135.         if (!$package) $package = $this->package;
  3136.         if (!$subpackage) $subpackage = $this->subpackage;
  3137.         if (!isset($this->all_packages[$package])) return $expr;
  3138.         elseif (isset($packages[$package])) unset($packages[$package]);
  3139.         $ext = array_pop(explode('.',$expr));
  3140.         if (isset($this->tutorials[$package][$subpackage][$ext][$expr]))
  3141.         {
  3142.             $a = $this->tutorials[$package][$subpackage][$ext][$expr];
  3143.             $link = new tutorialLink;
  3144.             $link->addLink($subsection,$a->path,$a->name,$a->package,$a->subpackage,$a->getTitle($this,$subsection));
  3145.             return $link;
  3146.         }
  3147.         do
  3148.         {
  3149.             if (!is_array($packages))
  3150.             {
  3151.                 $packages = $this->all_packages;
  3152.                 if (isset($packages[$package])) unset($packages[$package]);
  3153.             }
  3154.             if (isset($this->tutorials[$package]))
  3155.             {
  3156.                 if (isset($this->tutorials[$package][$subpackage][$ext][$expr]))
  3157.                 {
  3158.                     $a = $this->tutorials[$package][$subpackage][$ext][$expr];
  3159.                     $link = new tutorialLink;
  3160.                     $link->addLink($subsection,$a->path,$a->name,$a->package,$a->subpackage,$a->getTitle($this));
  3161.                     return $link;
  3162.                 } else
  3163.                 {
  3164.                     foreach($this->tutorials[$package] as $subpackage => $stuff)
  3165.                     {
  3166.                         if (isset($stuff[$ext][$expr]))
  3167.                         {
  3168.                             $a = $stuff[$ext][$expr];
  3169.                             $link = new tutorialLink;
  3170.                             $link->addLink($subsection,$a->path,$a->name,$a->package,$a->subpackage,$a->getTitle($this));
  3171.                             return $link;
  3172.                         }
  3173.                     }
  3174.                 }
  3175.             }
  3176.             // try other packages
  3177.             // look in parent package first, if found
  3178.             if (isset($this->package_parents[$package]))
  3179.             {
  3180.                 $p1 = $package;
  3181.                 $package = $this->package_parents[$package];
  3182.             } else
  3183.             {
  3184.                 // no parent package, so start with the first one that's left
  3185.                 list($package,) = @each($packages);
  3186.             }
  3187.             if ($package)
  3188.             {
  3189.                 if (isset($packages[$package])) unset($packages[$package]);
  3190.             }
  3191.         } while (count($packages) || $package);
  3192.         addWarning(PDERROR_TUTORIAL_NOT_FOUND,$expr);
  3193.         return $expr;
  3194.     }
  3195.  
  3196.     /**
  3197.      * The meat of the @see tag and inline {@}link} tag
  3198.      *
  3199.      * $expr is a string with many allowable formats:
  3200.      * <ol>
  3201.      *  <li>proceduralpagename.ext</li>
  3202.      *  <li>constant_name</li>
  3203.      *  <li>classname::function()</li>
  3204.      *  <li>classname::$variablename</li>
  3205.      *  <li>classname</li>
  3206.      *  <li>function functionname()</li>
  3207.      *  <li>global $globalvarname</li>
  3208.      *  <li>packagename#expr where expr is any of the above</li>
  3209.      * </ol>
  3210.      *
  3211.      * New in version 1.1, you can explicitly specify a package to link to that
  3212.      * is different from the current package.  Use the # operator
  3213.      * to specify a new package, as in tests#bug-540368.php (which should appear
  3214.      * as a link like: "{@link tests#bug-540368.php}").  This
  3215.      * example links to the procedural page bug-540368.php in package
  3216.      * tests.  Also, the "function" operator is now used to specifically
  3217.      * link to a function instead of a method in the current class.
  3218.      *
  3219.      * <code>
  3220.      * class myclass
  3221.      * {
  3222.      *  // from inside the class definition, use "function conflict()" to refer to procedural function "conflict()"
  3223.      *    function conflict()
  3224.      *    {
  3225.      *    }
  3226.      * }
  3227.      * 
  3228.      * function conflict()
  3229.      * {
  3230.      * }
  3231.      * </code>
  3232.      *
  3233.      * If classname:: is not present, and the see tag is in a documentation
  3234.      * block within a class, then the function uses the classname to
  3235.      * search for $expr as a function or variable within classname, or any of its parent classes.
  3236.      * given an $expr without '$', '::' or '()' getLink first searches for
  3237.      * classes, procedural pages, constants, global variables, and then searches for
  3238.      * methods and variables within the default class, and finally for any function
  3239.      *
  3240.      * @param string $expr expression to search for a link
  3241.      * @param string $package package to start searching in
  3242.      * @param array $packages list of all packages to search in
  3243.      * @return mixed getLink returns a descendant of {@link abstractLink} if it finds a link, otherwise it returns a string
  3244.      * @see getPageLink(), getDefineLink(), getVarLink(), getFunctionLink(), getClassLink()
  3245.      * @see pageLink, functionLink, defineLink, classLink, methodLink, varLink
  3246.      */
  3247.     function &getLink($expr, $package = false, $packages = false)
  3248.     {
  3249.         // is $expr a comma-delimited list?
  3250.         if (strpos($expr,','))
  3251.         {
  3252.             $a = explode(',',$expr);
  3253.             $b = array();
  3254.             for($i=0;$i<count($a);$i++)
  3255.             {
  3256.                 // if so return each component with a link
  3257.                 $b[] = Converter::getLink(trim($a[$i]));
  3258.             }
  3259.             return $b;
  3260.         }
  3261.         if (strpos($expr,'#'))
  3262.         {
  3263.             $a = explode('#',$expr);
  3264.             if (count($a) == 2)
  3265.             { // can have exactly 1 package override, otherwise it's ignored
  3266.                 // feature 564991, link to php manual
  3267.                 if ($a[0] == 'PHP_MANUAL')
  3268.                 return 'http://www.php.net/'.$a[1];
  3269.                 return Converter::getLink($a[1],$a[0],array());
  3270.             }
  3271.         }
  3272.         return $this->_getLink($expr, $package, $packages);
  3273.     }
  3274.     
  3275.     /**
  3276.      * @access private
  3277.      */
  3278.     function &_getLink($expr, $package = false, $packages = false)
  3279.     {
  3280.         if (!$package) $package = $this->package;
  3281.         // 
  3282.         if (!isset($this->all_packages[$package])) return $expr;
  3283.         elseif (isset($packages[$package])) unset($packages[$package]);
  3284.         $links = &$this->links;
  3285.         $class = $this->class;
  3286.         if (strpos($expr,'function ') === 0)
  3287.         { // asking for a function, not a method
  3288.             if ($test = Converter::getFunctionLink(str_replace('function ','',str_replace('()','',$expr)), $package)) return $test;
  3289.             else return $expr;
  3290.         }
  3291.         if (strpos($expr,'global ') === 0)
  3292.         { // asking for a global variable
  3293.             if ($test = Converter::getGlobalLink(str_replace('global ','',$expr), $package)) return $test;
  3294.             else return $expr;
  3295.         }
  3296.         // are we in a class?
  3297.         if ($class)
  3298.         {
  3299.             // is $expr simply a word? see if it is the class
  3300.             if (trim($expr) == $class)
  3301.             {
  3302.                 if ($test = Converter::getClassLink(trim(str_replace('object ','',$expr)),$package)) return $test;
  3303.             }
  3304.             // if not, check to see if it is a method or variable of this class tree
  3305.             if (!strpos($expr,'::'))
  3306.             {
  3307.                 // if get is neither get() nor $get, assume get is a function, add () to make get()
  3308.                 if (strpos($expr,'$') !== 0 && !strpos($expr,'()')) //$get = $get.'()';
  3309.                 {
  3310.                     if ($a = $this->getLinkMethod($expr,$class,$package)) return $a;
  3311.                     if ($a = $this->getLinkVar('$'.$expr,$class,$package)) return $a;
  3312.                 }
  3313.                 if (strpos($expr,'()')) if ($a = $this->getLinkMethod($expr,$class,$package)) return $a;
  3314.                 if (is_numeric(strpos($expr,'$'))) if ($a = $this->getLinkVar($expr,$class,$package)) return $a;
  3315.             }
  3316.         }
  3317.         if ($test = Converter::getClassLink(trim(str_replace('object ','',$expr)),$package)) return $test;
  3318.         if ($test = Converter::getPageLink(trim($expr),$package)) return $test;
  3319.         if ($test = Converter::getDefineLink(trim($expr),$package)) return $test;
  3320.         if ($test = Converter::getGlobalLink(trim($expr),$package)) return $test;
  3321. //        if (strpos($expr,'.'))
  3322.         // package specified
  3323.  
  3324.         if (!is_array($packages))
  3325.         {
  3326.             $packages = $this->all_packages;
  3327.         }
  3328.         do
  3329.         {
  3330.             if (isset($packages[$package])) unset($packages[$package]);
  3331.             if ($test = Converter::getClassLink(str_replace('object ','',$expr),$package)) return $test;
  3332.             if ($test = Converter::getPageLink($expr,$package)) return $test;
  3333.             if ($test = Converter::getDefineLink($expr,$package)) return $test;
  3334.             if ($test = Converter::getGlobalLink($expr,$package)) return $test;
  3335.             // is $expr in class::method() or class::$variable format?
  3336.             if (strpos($expr,'function ') === 0)
  3337.             { // asking for a function, not a method
  3338.                 if ($test = Converter::getFunctionLink(str_replace('function','',str_replace('()','',$expr)), $package)) return $test;
  3339.                 else return $expr;
  3340.             }
  3341.             $test = $this->_getDoubleColon($expr, $package, $packages, $class, $links);
  3342.             if (!is_string($test)) return $test;
  3343.             if (strpos($test, 'parent::') === 0) return $test;
  3344.             // $expr does not have ::
  3345.             if (is_numeric(@strpos('$',$expr)))
  3346.             {
  3347.                 // default to current class, whose name is contained in $this->render->parent
  3348.                 if ($test = Converter::getVarLink($expr, $class, $package)) return $test;
  3349.             }
  3350.             // $expr is a function? (non-method)
  3351.             if (@strpos($expr,'()'))
  3352.             {
  3353.                 // otherwise, see if it is a method
  3354.                 if ($class)
  3355.                 {
  3356.                     if ($test = Converter::getMethodLink(str_replace('()','',$expr), $class, $package)) return $test;
  3357.                 }
  3358.                 // extract the function name, use it to retrieve the file that the function is in
  3359.     //            $page = $this->func_page[str_replace('function ','',str_replace('()','',$expr))];
  3360.                 // return the link
  3361.                 if ($test = Converter::getFunctionLink(str_replace('function ','',str_replace('()','',$expr)), $package)) return $test;
  3362.             }
  3363.             // $expr is just a word.  First, test to see if it is a function of the current package
  3364.             if ($test = Converter::getFunctionLink(str_replace('function ','',str_replace('()','',$expr)), $package)) return $test;
  3365.             // try other packages
  3366.             // look in parent package first, if found
  3367.             if (isset($this->package_parents[$package]) && in_array($this->package_parents[$package], $packages))
  3368.             {
  3369.                 $p1 = $package;
  3370.                 $package = $this->package_parents[$package];
  3371.                 if ($package)
  3372.                 {
  3373.                     if (isset($packages[$package])) unset($packages[$package]);
  3374.                 }
  3375.                 continue;
  3376.             }
  3377.             // no parent package, so start with the first one that's left
  3378.             $package = @array_shift(@array_keys($packages));
  3379.             if ($package && isset($packages[$package]))
  3380.             {
  3381.                 unset($packages[$package]);
  3382.             }
  3383.         } while (count($packages) || $package);
  3384.         $funcs = get_defined_functions();
  3385.         // feature 564991, link to php manual
  3386.         if (in_array(str_replace(array('(',')'),array('',''),$expr),$funcs['internal']))
  3387.         {
  3388.             return 'http://www.php.net/'.str_replace(array('(',')'),array('',''),$expr);
  3389.         }
  3390.         // no links found
  3391.         return $expr;
  3392.     }
  3393.     
  3394.     /**
  3395.      * Split up getLink to make it easier to debug
  3396.      * @access private
  3397.      */
  3398.     function _getDoubleColon(&$expr, &$package, &$packages, $class, $links)
  3399.     {
  3400.         if (@strpos($expr,'::'))
  3401.         {
  3402.             $class_method = explode('::',$expr);
  3403.             if ($class_method[0] == 'parent')
  3404.             {
  3405.                 // can only have parent in the same package as the class!  subtle bug
  3406.                 $package = $this->package;
  3407.                 $packages = array();
  3408.                 $cl = $this->classes->getClassByPackage($class,$package);
  3409.                 if (!$cl)
  3410.                 { // this is possible if an example file has parent::method()
  3411.                     return $expr;
  3412.                 }
  3413.                 $par = $cl->getParent($this);
  3414.                 $phpparent = false;
  3415.                 if (is_object($par))
  3416.                 {
  3417.                     $package = $par->docblock->package;
  3418.                     $phpparent = $par->getName();
  3419.                 } else
  3420.                 {
  3421.                     addWarning(PDERROR_CLASS_PARENT_NOT_FOUND,$class,$package,$class_method[1]);
  3422.                     return $expr;
  3423.                 }
  3424.                 if ($phpparent) $class_method[0] = $phpparent;
  3425.             }
  3426.             if (strpos($class_method[1],'()'))
  3427.             {
  3428.                 // strip everything but the function name, return a link
  3429.                 if ($test = Converter::getMethodLink(str_replace('()','',$class_method[1]), $class_method[0], $package)) return $test;
  3430.             }
  3431.             if ($test = Converter::getVarLink($class_method[1], $class_method[0], $package)) return $test;
  3432.         }
  3433.         return $expr;
  3434.     }
  3435.  
  3436.     /**
  3437.      * cycle through parent classes to retrieve a link to a method
  3438.      * do not use or override, used by getLink
  3439.      * @access private
  3440.      */
  3441.     function &getLinkMethod($expr, $class, $package)
  3442.     {
  3443.         $links = &$this->links;
  3444.         do
  3445.         {
  3446.             // is $expr in class::method() or class::$variable format?
  3447.             if (@strpos($expr,'::'))
  3448.             {
  3449.                 $class_method = explode('::',$expr);
  3450.                 if ($class_method[0] == 'parent')
  3451.                 {
  3452.                     $cl = $this->classes->getClassByPackage($class,$package);
  3453.                     $par = $cl->getParent($this);
  3454.                     $phpparent = false;
  3455.                     if (is_object($par))
  3456.                     {
  3457.                         $package = $par->docblock->package;
  3458.                         $phpparent = $par->getName();
  3459.                     } else addWarning(PDERROR_CLASSPARENT_NOTFOUND,$class,$package,$class_method[1]);
  3460.                     if ($phpparent) $class_method[0] = $phpparent;
  3461.                 } else
  3462.                 {
  3463.                     $cl = $this->classes->getClassByPackage($class,$package);
  3464.                 }
  3465.                 if (strpos($class_method[1],'()'))
  3466.                 {
  3467.                     // strip everything but the function name, return a link
  3468.                     if ($test = Converter::getMethodLink(str_replace('function ','',str_replace('()','',$class_method[1])), $class_method[0], $package)) return $test;
  3469.                 }
  3470.             }
  3471.             if ($test = Converter::getMethodLink(str_replace('()','',$expr), $class, $package)) return $test;
  3472.             $cl = $this->classes->getClassByPackage($class,$package);
  3473.             if ($cl)
  3474.             {
  3475.                 $par = $cl->getParent($this);
  3476.                 if (is_object($par))
  3477.                 {
  3478.                     $package = $par->docblock->package;
  3479.                     $class = $par->getName();
  3480.                 } else $class = $par;
  3481.             } else $class = false;
  3482.         } while ($class);
  3483.         // no links found
  3484.         return false;
  3485.     }
  3486.     
  3487.     /**
  3488.      * cycle through parent classes to retrieve a link to a var
  3489.      * do not use or override, used by getLink
  3490.      * @access private
  3491.      */
  3492.     function &getLinkVar($expr, $class, $package)
  3493.     {
  3494.         $links = &$this->links;
  3495.         do
  3496.         {
  3497.             // is $expr in class::method() or class::$variable format?
  3498.             if (@strpos($expr,'::'))
  3499.             {
  3500.                 $class_method = explode('::',$expr);
  3501.                 if ($class_method[0] == 'parent')
  3502.                 {
  3503.                     $cl = $this->classes->getClassByPackage($class,$package);
  3504.                     $phpparent = false;
  3505.                     $par = $cl->getParent($this);
  3506.                     if (is_object($par))
  3507.                     {
  3508.                         $package = $par->docblock->package;
  3509.                         $phpparent = $par->getName();
  3510.                     } else addWarning(PDERROR_CLASSPARENT_NOTFOUND,$class,$package,$class_method[1]);
  3511.                     if ($phpparent) $class_method[0] = $phpparent;
  3512.                 } else
  3513.                 {
  3514.                     $cl = $this->classes->getClassByPackage($class,$package);
  3515.                 }
  3516.                 if ($test = Converter::getVarLink($class_method[1], $class_method[0], $package)) return $test;
  3517.                 if ($test = Converter::getVarLink('$'.$class_method[1], $class_method[0], $package)) return $test;
  3518.             }
  3519.             if ($test = Converter::getVarLink($expr, $class, $package)) return $test;
  3520.             if ($test = Converter::getVarLink('$'.$expr, $class, $package)) return $test;
  3521.             $cl = $this->classes->getClassByPackage($class,$package);
  3522.             if ($cl)
  3523.             {
  3524.                 $par = $cl->getParent($this);
  3525.                 if (is_object($par))
  3526.                 {
  3527.                     $package = $par->docblock->package;
  3528.                     $class = $par->getName();
  3529.                 } else $class = $par;
  3530.             } else $class = false;
  3531.         } while ($class);
  3532.         // no links found
  3533.         return false;
  3534.     }
  3535.     
  3536.     /**
  3537.      * take URL $link and text $text and return a link in the format needed for the Converter
  3538.      * @param string URL
  3539.      * @param string text to display
  3540.      * @return string link to $link
  3541.      * @abstract
  3542.      */
  3543.     function returnLink($link,$text)
  3544.     {
  3545.     }
  3546.  
  3547.     /**
  3548.      * take {@link abstractLink} descendant and text $eltext and return a link
  3549.      * in the format needed for the Converter
  3550.      * @param abstractLink
  3551.      * @param string
  3552.      * @return string link to $element
  3553.      * @abstract
  3554.      */
  3555.     function returnSee(&$link, $eltext = false)
  3556.     {
  3557.     }
  3558.     
  3559.     /**
  3560.      * take {@link abstractLink} descendant and text $eltext and return a 
  3561.      * unique ID in the format needed for the Converter
  3562.      * @param abstractLink
  3563.      * @return string unique identifier of $element
  3564.      * @abstract
  3565.      */
  3566.     function getId(&$link)
  3567.     {
  3568.     }
  3569.     
  3570.     /**
  3571.      * Convert README/INSTALL/CHANGELOG file contents to output format
  3572.      * @param README|INSTALL|CHANGELOG
  3573.      * @param string contents of the file
  3574.      * @abstract
  3575.      */
  3576.     function Convert_RIC($name, $contents)
  3577.     {
  3578.     }
  3579.     
  3580.     /**
  3581.      * Convert all elements to output format
  3582.      *
  3583.      * This will call ConvertXxx where Xxx is {@link ucfirst}($element->type).
  3584.      * It is expected that a child converter defines a handler for every
  3585.      * element type, even if that handler does nothing.  phpDocumentor will
  3586.      * terminate with an error if a handler doesn't exist.
  3587.      * {@internal
  3588.      * Since 1.2.0 beta 3, this function has been moved from child converters
  3589.      * to the parent, because it doesn't really make sense to put it in the
  3590.      * child converter, and we can add error handling.
  3591.      *
  3592.      * {@source}}}
  3593.      * @throws {@link PDERROR_NO_CONVERT_HANDLER}
  3594.      * @param mixed {@link parserElement} descendant or {@link parserPackagePage} or {@link parserData}
  3595.      */
  3596.     function Convert(&$element)
  3597.     {
  3598.         $handler = 'convert'.ucfirst($element->type);
  3599.         if (method_exists($this,$handler))
  3600.         {
  3601.             $this->$handler($element);
  3602.         } else
  3603.         {
  3604.             addErrorDie(PDERROR_NO_CONVERTER_HANDLER,$element->type,$handler,get_class($this));
  3605.         }
  3606.     }
  3607.     /**#@+
  3608.      * Conversion Handlers
  3609.      *
  3610.      * All of the convert* handlers set up template variables for the Smarty
  3611.      * template.{@internal  In addition, the {@link newSmarty()} method is
  3612.      * called to retrieve the global Smarty template}}
  3613.      */
  3614.     /**
  3615.      * Default Tutorial Handler
  3616.      *
  3617.      * Sets up the tutorial template, and its prev/next/parent links
  3618.      * {@internal
  3619.      * Retrieves the title using {@link parserTutorial::getTitle()} and uses the
  3620.      * {@link parserTutorial::prev, parserTutorial::next, parserTutorial::parent}
  3621.      * links to set up those links.}}
  3622.      * @param parserTutorial
  3623.      */
  3624.     function &convertTutorial(&$element)
  3625.     {
  3626.         $this->package = $element->package;
  3627.         $this->subpackage = $element->subpackage;
  3628.         $x = $element->Convert($this);
  3629.         $template = &$this->newSmarty();
  3630.         $template->assign('contents',$x);
  3631.         $template->assign('title',$element->getTitle($this));
  3632.         $template->assign('nav',$element->parent || $element->prev || $element->next);
  3633.         if ($element->parent)
  3634.         {
  3635.             $template->assign('up',$this->getId($element->parent));
  3636.             $template->assign('uptitle',$element->parent->title);
  3637.         }
  3638.         if ($element->prev)
  3639.         {
  3640.             $template->assign('prev',$this->getId($element->prev));
  3641.             $template->assign('prevtitle',$element->prev->title);
  3642.         }
  3643.         if ($element->next)
  3644.         {
  3645.             $template->assign('next',$this->getId($element->next));
  3646.             $template->assign('nexttitle',$element->next->title);
  3647.         }
  3648.         return $template;
  3649.     }
  3650.     /**
  3651.      * Default Class Handler
  3652.      *
  3653.      * Sets up the class template.
  3654.      * {@internal special methods
  3655.      * {@link generateChildClassList(), generateFormattedClassTree()}, 
  3656.      * {@link getFormattedConflicts, getFormattedInheritedMethods},
  3657.      * and {@link getFormattedInheritedVars} are called to complete vital
  3658.      * template setup.}}
  3659.      */
  3660.     function convertClass(&$element)
  3661.     {
  3662.         $this->class = $element->getName();
  3663.         $this->class_data = &$this->newSmarty();
  3664.         $this->class_data->assign("class_name",$element->getName());
  3665.         $this->class_data->assign("vars",array());
  3666.         $this->class_data->assign("methods",array());
  3667.         $this->class_data->assign("package",$element->docblock->package);
  3668.         $this->class_data->assign("line_number",$element->getLineNumber());
  3669.         $this->class_data->assign("source_location",$element->getSourceLocation($this));
  3670.                 $this->class_data->assign("page_link",$this->getCurrentPageLink());
  3671.         $docblock = $this->prepareDocBlock($element, false);
  3672.         $this->class_data->assign("sdesc",$docblock['sdesc']);
  3673.         $this->class_data->assign("desc",$docblock['desc']);
  3674.         $this->class_data->assign("tags",$docblock['tags']);
  3675.         $this->class_data->assign("api_tags",$docblock['api_tags']);
  3676.         $this->class_data->assign("info_tags",$docblock['info_tags']);
  3677.         $this->class_data->assign("utags",$docblock['utags']);
  3678.         if ($this->hasSourceCode($element->getPath()))
  3679.         $this->class_data->assign("class_slink",$this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true));
  3680.  
  3681.         else
  3682.         $this->class_data->assign("class_slink",false);
  3683.         $this->class_data->assign("children", $this->generateChildClassList($element));
  3684.         $this->class_data->assign("class_tree", $this->generateFormattedClassTree($element));
  3685.         $this->class_data->assign("conflicts", $this->getFormattedConflicts($element,"classes"));
  3686.         $inherited_methods = $this->getFormattedInheritedMethods($element);
  3687.         if (!empty($inherited_methods))
  3688.         {
  3689.             $this->class_data->assign("imethods",$inherited_methods);
  3690.         } else
  3691.         {
  3692.             $this->class_data->assign("imethods",false);
  3693.         }
  3694.         $inherited_vars = $this->getFormattedInheritedVars($element);
  3695.         if (!empty($inherited_vars))
  3696.         {
  3697.             $this->class_data->assign("ivars",$inherited_vars);
  3698.         } else
  3699.         {
  3700.             $this->class_data->assign("ivars",false);
  3701.         }
  3702.     }
  3703.     
  3704.     
  3705.     /**
  3706.      * Converts method for template output
  3707.      *
  3708.      * This function must be called by a child converter with any extra
  3709.      * template variables needed in the parameter $addition
  3710.      * @param parserMethod
  3711.      */
  3712.     function convertMethod(&$element, $additions = array())
  3713.     {
  3714.         $fname = $element->getName();
  3715.         $docblock = $this->prepareDocBlock($element);
  3716.         $returntype = 'void';
  3717.         if ($element->isConstructor) $returntype = $element->class;
  3718.         if ($element->docblock->return)
  3719.         {
  3720.             $a = $element->docblock->return->Convert($this);
  3721.             $returntype = $element->docblock->return->converted_returnType;
  3722.         }
  3723.         $params = $param_i = array();
  3724.         if (count($element->docblock->params))
  3725.         foreach($element->docblock->params as $param => $val)
  3726.         {
  3727.             $a = $val->Convert($this);
  3728.             $params[] = $param_i[$param] = array("var" => $param,"datatype" => $val->converted_returnType,"data" => $a);
  3729.         }
  3730.  
  3731.                 if ($element->docblock->hasaccess)
  3732.                     $acc = $element->docblock->tags['access'][0]->value;
  3733.                 else
  3734.                     $acc = 'public';
  3735.  
  3736.  
  3737.         if ($this->hasSourceCode($element->getPath()))
  3738.         $additions["slink"] = $this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true);
  3739.         $this->class_data->append('methods',array_merge(
  3740.                                              array('sdesc' => $docblock['sdesc'],
  3741.                                                    'desc' => $docblock['desc'],
  3742.                                                    'tags' => $docblock['tags'],
  3743.                                                    'api_tags' => $docblock['api_tags'],
  3744.                                                    'info_tags' => $docblock['info_tags'],
  3745.                                                    'utags' => $docblock['utags'],
  3746.                                                    'constructor' => $element->isConstructor,
  3747.                                                                                                      'access' => $acc,
  3748.                                                    'function_name'     => $fname,
  3749.                                                    'function_return'    => $returntype,
  3750.                                                    'function_call'     => $element->getFunctionCall(),
  3751.                                                    'ifunction_call'     => $element->getIntricateFunctionCall($this, $param_i),
  3752.                                                    'descmethod'    => $this->getFormattedDescMethods($element),
  3753.                                                    'method_overrides'    => $this->getFormattedOverrides($element),
  3754.                                                    'line_number' => $element->getLineNumber(),
  3755.                                                    'id' => $this->getId($element),
  3756.                                                    'params' => $params),
  3757.                                              $additions));
  3758.     }
  3759.     
  3760.     /**
  3761.      * Converts class variables for template output.
  3762.      *
  3763.      * This function must be called by a child converter with any extra
  3764.      * template variables needed in the parameter $addition
  3765.      * @param parserVar
  3766.      */
  3767.     function convertVar(&$element, $additions = array())
  3768.     {
  3769.         $docblock = $this->prepareDocBlock($element);
  3770.         $b = 'mixed';
  3771.                 
  3772.                 if ($element->docblock->hasaccess)
  3773.                     $acc = $element->docblock->tags['access'][0]->value;
  3774.                 else
  3775.                     $acc = 'public';
  3776.  
  3777.         if ($element->docblock->var)
  3778.         {
  3779.             $b = $element->docblock->var->converted_returnType;
  3780.         }
  3781.         if ($this->hasSourceCode($element->getPath()))
  3782.         $additions["slink"] = $this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true);
  3783.         $this->class_data->append('vars',array_merge(
  3784.                                           array('sdesc' => $docblock['sdesc'],
  3785.                                                 'desc' => $docblock['desc'],
  3786.                                                 'utags' => $docblock['utags'],
  3787.                                                 'tags' => $docblock['tags'],
  3788.                                                 'api_tags' => $docblock['api_tags'],
  3789.                                                 'info_tags' => $docblock['info_tags'],
  3790.                                                 'var_name' => $element->getName(),
  3791.                                                 'var_default' => $this->postProcess($element->getValue()),
  3792.                                                 'var_type' => $b,
  3793.                                                                                                 'access' => $acc,
  3794.                                                 'line_number' => $element->getLineNumber(),
  3795.                                                                                                 'descvar'    => $this->getFormattedDescVars($element),
  3796.                                                 'var_overrides' => $this->getFormattedOverrides($element),
  3797.                                                 'id' => $this->getId($element)),
  3798.                                           $additions));
  3799.     }
  3800.  
  3801.     /**
  3802.      * Default Page Handler
  3803.      *
  3804.      * {@internal In addition to setting up the smarty template with {@link newSmarty()},
  3805.      * this class uses {@link getSourceLocation()} and {@link getClassesOnPage()}
  3806.      * to set template variables.  Also used is {@link getPageName()}, to get
  3807.      * a Converter-specific name for the page.}}
  3808.      * @param parserPage
  3809.      */
  3810.     function convertPage(&$element)
  3811.     {
  3812.         $this->page_data = &$this->newSmarty(true);
  3813.         $this->page = $this->getPageName($element->parent);
  3814.         $this->path = $element->parent->getPath();
  3815.         $this->curpage = &$element->parent;
  3816.         $this->page_data->assign("source_location",$element->parent->getSourceLocation($this));
  3817.         $this->page_data->assign("functions",array());
  3818.         $this->page_data->assign("includes",array());
  3819.         $this->page_data->assign("defines",array());
  3820.         $this->page_data->assign("globals",array());
  3821.         $this->page_data->assign("classes",$this->getClassesOnPage($element));
  3822.         $this->page_data->assign("name", $element->parent->getFile());
  3823.         if ($t = $element->getTutorial())
  3824.         {
  3825.             $this->page_data->assign("tutorial",$this->returnSee($t));
  3826.         } else
  3827.         {
  3828.             $this->page_data->assign("tutorial",false);
  3829.         }
  3830.         if ($element->docblock)
  3831.         {
  3832.             $docblock = $this->prepareDocBlock($element, false);
  3833.             $this->page_data->assign("sdesc",$docblock['sdesc']);
  3834.             $this->page_data->assign("desc",$docblock['desc']);
  3835.             $this->page_data->assign("tags",$docblock['tags']);
  3836.             $this->page_data->assign("api_tags",$docblock['api_tags']);
  3837.             $this->page_data->assign("info_tags",$docblock['info_tags']);
  3838.             $this->page_data->assign("utags",$docblock['utags']);
  3839.         }
  3840.     }
  3841.  
  3842.     /**
  3843.      * Converts global variables for template output
  3844.      *
  3845.      * This function must be called by a child converter with any extra
  3846.      * template variables needed in the parameter $addition
  3847.      * {@internal
  3848.      * In addition to using {@link prepareDocBlock()}, this method also
  3849.      * uses utility functions {@link getGlobalValue(), getFormattedConflicts()}}}
  3850.      * @param parserGlobal
  3851.      * @uses postProcess() on global_value template value, makes it displayable
  3852.      * @param array any additional template variables should be in this array
  3853.      */
  3854.     function convertGlobal(&$element, $addition = array())
  3855.     {
  3856.         $docblock = $this->prepareDocBlock($element);
  3857.         $value = $this->getGlobalValue($element->getValue());
  3858.         if ($this->hasSourceCode($element->getPath()))
  3859.         $addition["slink"] = $this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true);
  3860.         $this->page_data->append('globals',array_merge(
  3861.                                             array('sdesc' => $docblock['sdesc'],
  3862.                                                   'desc' => $docblock['desc'],
  3863.                                                   'tags' => $docblock['tags'],
  3864.                                                   'api_tags' => $docblock['api_tags'],
  3865.                                                   'info_tags' => $docblock['info_tags'],
  3866.                                                   'utags' => $docblock['utags'],
  3867.                                                   'global_name'     => $element->getName(),
  3868.                                                   'global_type' => $element->getDataType($this),
  3869.                                                   'global_value'    => $this->postProcess($value),
  3870.                                                   'line_number' => $element->getLineNumber(),
  3871.                                                   'global_conflicts'    => $this->getFormattedConflicts($element,"global variables"),
  3872.                                                   'id' => $this->getId($element)),
  3873.                                             $addition));
  3874.     }
  3875.     
  3876.     /**
  3877.      * Converts defines for template output
  3878.      *
  3879.      * This function must be called by a child converter with any extra
  3880.      * template variables needed in the parameter $addition
  3881.      * {@internal
  3882.      * In addition to using {@link prepareDocBlock()}, this method also
  3883.      * uses utility functions {@link getGlobalValue(), getFormattedConflicts()}}}
  3884.      * @param parserDefine
  3885.      * @uses postProcess() on define_value template value, makes it displayable
  3886.      * @param array any additional template variables should be in this array
  3887.      */
  3888.     function convertDefine(&$element, $addition = array())
  3889.     {
  3890.         $docblock = $this->prepareDocBlock($element);
  3891.         if ($this->hasSourceCode($element->getPath()))
  3892.         $addition["slink"] = $this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true);
  3893.         $this->page_data->append('defines',array_merge(
  3894.                                             array('sdesc' => $docblock['sdesc'],
  3895.                                                   'desc' => $docblock['desc'],
  3896.                                                   'tags' => $docblock['tags'],
  3897.                                                   'api_tags' => $docblock['api_tags'],
  3898.                                                   'info_tags' => $docblock['info_tags'],
  3899.                                                   'utags' => $docblock['utags'],
  3900.                                                   'define_name'     => $element->getName(),
  3901.                                                   'line_number' => $element->getLineNumber(),
  3902.                                                   'define_value'    => $this->postProcess($element->getValue()),
  3903.                                                   'define_conflicts'    => $this->getFormattedConflicts($element,"defines"),
  3904.                                                   'id' => $this->getId($element)),
  3905.                                             $addition));
  3906.     }
  3907.     
  3908.     
  3909.     /**
  3910.      * Converts includes for template output
  3911.      *
  3912.      * This function must be called by a child converter with any extra
  3913.      * template variables needed in the parameter $addition
  3914.      * @see prepareDocBlock()
  3915.      * @param parserInclude
  3916.      */
  3917.     function convertInclude(&$element, $addition = array())
  3918.     {
  3919.         $docblock = $this->prepareDocBlock($element);
  3920.         $per = $this->getIncludeValue($element->getValue(), $element->getPath());
  3921.  
  3922.         if ($this->hasSourceCode($element->getPath()))
  3923.         $addition["slink"] = $this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true);
  3924.         $this->page_data->append('includes',array_merge(
  3925.                                              array('sdesc' => $docblock['sdesc'],
  3926.                                                    'desc' => $docblock['desc'],
  3927.                                                    'tags' => $docblock['tags'],
  3928.                                                    'api_tags' => $docblock['api_tags'],
  3929.                                                    'info_tags' => $docblock['info_tags'],
  3930.                                                    'utags' => $docblock['utags'],
  3931.                                                    'include_name'     => $element->getName(),
  3932.                                                    'line_number' => $element->getLineNumber(),
  3933.                                                    'include_value'    => $per),
  3934.                                              $addition));
  3935.     }
  3936.     
  3937.     /**
  3938.      * Converts function for template output
  3939.      *
  3940.      * This function must be called by a child converter with any extra
  3941.      * template variables needed in the parameter $addition
  3942.      * @see prepareDocBlock()
  3943.      * @param parserFunction
  3944.      */
  3945.     function convertFunction(&$element, $addition = array())
  3946.     {
  3947.         $docblock = $this->prepareDocBlock($element);
  3948.         $fname = $element->getName();
  3949.         $params = $param_i = array();
  3950.         if (count($element->docblock->params))
  3951.         foreach($element->docblock->params as $param => $val)
  3952.         {
  3953.             $a = $val->Convert($this);
  3954.             $params[] = $param_i[$param] = array("var" => $param,"datatype" => $val->converted_returnType,"data" => $a);
  3955.         }
  3956.         $returntype = 'void';
  3957.         if ($element->docblock->return)
  3958.         {
  3959.             $a = $element->docblock->return->Convert($this);
  3960.             $returntype = $element->docblock->return->converted_returnType;
  3961.         }
  3962.  
  3963.         if ($this->hasSourceCode($element->getPath()))
  3964.         $addition["slink"] = $this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true);
  3965.         $this->page_data->append('functions',array_merge(
  3966.                                               array('sdesc' => $docblock['sdesc'],
  3967.                                                     'desc' => $docblock['desc'],
  3968.                                                     'tags' => $docblock['tags'],
  3969.                                                     'api_tags' => $docblock['api_tags'],
  3970.                                                     'info_tags' => $docblock['info_tags'],
  3971.                                                     'utags' => $docblock['utags'],
  3972.                                                     'function_name'     => $fname,
  3973.                                                     'function_return'    => $returntype,
  3974.                                                     'function_conflicts'    => $this->getFormattedConflicts($element,"functions"),
  3975.                                                     'ifunction_call'     => $element->getIntricateFunctionCall($this, $param_i),
  3976.                                                     'function_call'     => $element->getFunctionCall(),
  3977.                                                     'line_number' => $element->getLineNumber(),
  3978.                                                     'id' => $this->getId($element),
  3979.                                                     'params' => $params),
  3980.                                               $addition));
  3981.     }
  3982.     /**#@-*/
  3983.     
  3984.     /**
  3985.      * convert the element's DocBlock for output
  3986.      *
  3987.      * This function converts all tags and descriptions for output
  3988.      * @param mixed any descendant of {@link parserElement}, or {@link parserData}
  3989.      * @param array used to translate tagnames into other tags
  3990.      * @param boolean set to false for pages and classes, the only elements allowed to specify @package
  3991.      * @return array
  3992.      *
  3993.      * Format:
  3994.      * <pre>
  3995.      * array('sdesc' => DocBlock summary
  3996.      *       'desc' => DocBlock detailed description
  3997.      *       'tags' => array('keyword' => tagname, 'data' => tag description)
  3998.      *                 known tags
  3999.      *       'api_tags' => array('keyword' => tagname, 'data' => tag description)
  4000.      *                 known api documentation tags
  4001.      *       'info_tags' => array('keyword' => tagname, 'data' => tag description)
  4002.      *                 known informational tags
  4003.      *     [ 'utags' => array('keyword' => tagname, 'data' => tag description
  4004.      *                 unknown tags ]
  4005.      *     [ 'vartype' => type from @var/@return tag ]
  4006.      *     [ 'var_descrip' => description from @var/@return tag ]
  4007.      *      )
  4008.      * </pre>
  4009.      */
  4010.     function prepareDocBlock(&$element, $names = array(),$nopackage = true)
  4011.     {
  4012.         $tagses = $element->docblock->listTags();
  4013.         $tags = $ret = $api_tags = $info_tags = array();
  4014.         $api_tags_arr = array("abstract", "access", "deprecated", "example", "filesource",
  4015.                              "global", "internal", "name", "return", "see", "static",
  4016.                              "staticvar", "uses", "var");
  4017.         if (!$nopackage)
  4018.         {
  4019.             $tags[] = array('keyword' => 'package','data' => $element->docblock->package);
  4020.             if (!empty($element->docblock->subpackage)) $tags[] = array('keyword' => 'subpackage','data' => $element->docblock->subpackage);
  4021.         }
  4022.         if ($element->docblock->var)
  4023.         {
  4024.             $a = $element->docblock->var->Convert($this);
  4025.             $ret['vartype'] = $element->docblock->var->converted_returnType;
  4026.             if (!empty($a))
  4027.             {
  4028.                 $tags[] = array('keyword' => 'var', 'data' => $a);
  4029.                 $ret["var_descrip"] = $a;
  4030.             }
  4031.         }
  4032.         if ($element->docblock->return)
  4033.         {
  4034.             $a = $element->docblock->return->Convert($this);
  4035.             $ret['vartype'] = $element->docblock->return->converted_returnType;
  4036.             if (!empty($a))
  4037.             {
  4038.                 $tags[] = $api_tags[] = array('keyword' => 'return', 'data' => $a);
  4039.                 $ret["var_descrip"] = $a;
  4040.             }
  4041.         }
  4042.         if ($element->docblock->funcglobals)
  4043.         foreach($element->docblock->funcglobals as $global => $val)
  4044.         {
  4045.             if ($a = $this->getGlobalLink($global,$element->docblock->package))
  4046.             {
  4047.                 $global = $a;
  4048.             }
  4049.             $b = Converter::getLink($val[0]);
  4050.             if (is_object($b) && get_class($b) == 'classlink')
  4051.             {
  4052.                 $val[0] = $this->returnSee($b);
  4053.             }
  4054.             $tags[] = $api_tags[] = array('keyword' => 'global','data' => $val[0].' '.$global.': '.$val[1]->Convert($this));
  4055.         }
  4056.         if ($element->docblock->statics)
  4057.         foreach($element->docblock->statics as $static => $val)
  4058.         {
  4059.             $a = $val->Convert($this);
  4060.             $tags[] = $api_tags[] = array('keyword' => 'staticvar','data' => $val->converted_returnType.' '.$static.': '.$a);
  4061.         }
  4062.         foreach($tagses as $tag)
  4063.         {
  4064.             if (isset($names[$tag->keyword])) $tag->keyword = $names[$tag->keyword];
  4065.             if ($tag->keyword)
  4066.                 $tags[] = array("keyword" => $tag->keyword,"data" => $tag->Convert($this));
  4067.             if (in_array($tag->keyword, $api_tags_arr))
  4068.                 $api_tags[] = array("keyword" => $tag->keyword,"data" => $tag->Convert($this));
  4069.             else
  4070.                 $info_tags[] = array("keyword" => $tag->keyword,"data" => $tag->Convert($this));
  4071.         }
  4072.         $utags = array();
  4073.         foreach($element->docblock->unknown_tags as $keyword => $tag)
  4074.         {
  4075.             foreach($tag as $t)
  4076.             $utags[] = array('keyword' => $keyword, 'data' => $t->Convert($this));
  4077.         }
  4078.         $ret['sdesc'] = $element->docblock->getSDesc($this);
  4079.         $ret['desc'] = $element->docblock->getDesc($this);
  4080.         $ret['tags'] = $tags;
  4081.         $ret['api_tags'] = $api_tags;
  4082.         $ret['info_tags'] = $info_tags;
  4083.         $ret['utags'] = $utags;
  4084.         return $ret;
  4085.     }
  4086.     
  4087.     /**
  4088.      * gets a list of all classes declared on a procedural page represented by
  4089.      * $element, a {@link parserData} class
  4090.      * @param parserData &$element
  4091.      * @return array links to each classes documentation
  4092.      *
  4093.      * Format:
  4094.      * <pre>
  4095.      * array('name' => class name,
  4096.      *       'sdesc' => summary of the class
  4097.      *       'link' => link to the class's documentation)
  4098.      * </pre>
  4099.      */
  4100.     function getClassesOnPage(&$element)
  4101.     {
  4102.         global $_phpDocumentor_setting;
  4103.         $a = $element->getClasses($this);
  4104.         $classes = array();
  4105.         foreach($a as $package => $clas)
  4106.         {
  4107.             if (isset($_phpDocumentor_setting['packageoutput']))
  4108.             {
  4109.                 $packages = explode(',',$_phpDocumentor_setting['packageoutput']);
  4110.                 if (!in_array($package, $packages)) continue;
  4111.             }
  4112.             for($i=0; $i<count($clas); $i++)
  4113.             {
  4114.                 if ($this->parseprivate || ! ($clas[$i]->docblock && $clas[$i]->docblock->hasaccess && $clas[$i]->docblock->tags['access'][0]->value == 'private'))
  4115.                 {
  4116.                     $sdesc = '';
  4117.                     $r = array();
  4118.                     $sdesc = $clas[$i]->docblock->getSDesc($this);
  4119.                     if ($clas[$i]->docblock->hasaccess)
  4120.                     $r['access'] = $clas[$i]->docblock->tags['access'][0]->value;
  4121.                     else
  4122.                     $r['access'] = 'public';
  4123.                     $r['name'] = $clas[$i]->getName();
  4124.                     $r['sdesc'] = $sdesc;
  4125.                     $r['link'] = $this->getClassLink($clas[$i]->getName(),$package,$clas[$i]->getPath());
  4126.                     $classes[] = $r;
  4127.                 }
  4128.             }
  4129.         }
  4130.         return $classes;
  4131.     }
  4132.     
  4133.     /**
  4134.      * returns an array containing the class inheritance tree from the root
  4135.      * object to the class.
  4136.      *
  4137.      * This method must be overridden, or phpDocumentor will halt with a fatal
  4138.      * error
  4139.      * @return string Converter-specific class tree for an individual class
  4140.      * @param parserClass    class variable
  4141.      * @abstract
  4142.      */
  4143.     
  4144.     function generateFormattedClassTree($class)
  4145.     {
  4146.         addErrorDie(PDERROR_CONVERTER_OVR_GFCT,get_class($this));
  4147.     }
  4148.     
  4149.     /**
  4150.      * @param mixed {@link parserClass, parserFunction, parserDefine} or
  4151.      * {@link parserGlobal}
  4152.      * @param string type to display.  either 'class','function','define'
  4153.      *               or 'global variable'
  4154.      * @return array links to conflicting elements, or empty array
  4155.      * @uses parserClass::getConflicts()
  4156.      * @uses parserFunction::getConflicts()
  4157.      * @uses parserDefine::getConflicts()
  4158.      * @uses parserGlobal::getConflicts()
  4159.      */
  4160.     function getFormattedConflicts(&$element,$type)
  4161.     {
  4162.         $conflicts = $element->getConflicts($this);
  4163.         $r = array();
  4164.         if (!$conflicts) return false;
  4165.         foreach($conflicts as $package => $class)
  4166.         {
  4167.             $r[] = $class->getLink($this,$class->docblock->package);
  4168.         }
  4169.         if (!empty($r)) $r = array('conflicttype' => $type, 'conflicts' => $r);
  4170.         return $r;
  4171.     }
  4172.     
  4173.     /**
  4174.      * Get a list of methods in child classes that override this method
  4175.      * @return array empty array or array(array('link'=>link to method,
  4176.      * 'sdesc'=>short description of the method),...)
  4177.      * @uses parserMethod::getOverridingMethods()
  4178.      * @param parserMethod
  4179.      */
  4180.     function getFormattedDescMethods(&$element)
  4181.     {
  4182.         $meths = $element->getOverridingMethods($this);
  4183.         $r = array();
  4184.         for($i=0; $i<count($meths); $i++)
  4185.         {
  4186.             $ms = array();
  4187.             $ms['link'] = $meths[$i]->getLink($this);
  4188.             $ms['sdesc'] = $meths[$i]->docblock->getSDesc($this);
  4189.             $r[] = $ms;
  4190.         }
  4191.         return $r;
  4192.     }
  4193.     
  4194.     /**
  4195.      * Get a list of vars in child classes that override this var
  4196.      * @return array empty array or array('link'=>link to var,
  4197.      * 'sdesc'=>short description of the method
  4198.      * @uses parserVar::getOverridingVars()
  4199.      * @param parserVar
  4200.      */
  4201.     function getFormattedDescVars(&$element)
  4202.     {
  4203.         $vars = $element->getOverridingVars($this);
  4204.         $r = array();
  4205.         for($i=0; $i<count($vars); $i++)
  4206.         {
  4207.             $vs = array();
  4208.             $vs['link'] = $vars[$i]->getLink($this);
  4209.             $vs['sdesc'] = $vars[$i]->docblock->getSDesc($this);
  4210.             $r[] = $vs;
  4211.         }
  4212.         return $r;
  4213.     }
  4214.  
  4215.     /**
  4216.      * Get the method this method overrides, if any
  4217.      * @return array|false array('link'=>link to overridden method,
  4218.      * 'sdesc'=>short description
  4219.      * @see parserMethod::getOverrides()
  4220.      * @param parserMethod
  4221.      */
  4222.     function getFormattedOverrides(&$element)
  4223.     {
  4224.         $ovr = $element->getOverrides($this);
  4225.         if (!$ovr) return false;
  4226.         $sdesc = $ovr->docblock->getSDesc($this);
  4227.         return array('link' => $ovr->getLink($this),'sdesc' => $sdesc);
  4228.     }
  4229.     
  4230.     /**
  4231.      * returns a list of child classes
  4232.      *
  4233.      * @param parserClass class variable
  4234.      * @uses parserClass::getChildClassList()
  4235.      */
  4236.     
  4237.     function generateChildClassList($class)
  4238.     {
  4239.         $kids = $class->getChildClassList($this);
  4240.         $list = array();
  4241.         if (count($kids))
  4242.         {
  4243.             for($i=0; $i<count($kids); $i++)
  4244.             {
  4245.                 $lt['link'] = $kids[$i]->getLink($this);
  4246.                 $lt['sdesc'] = $kids[$i]->docblock->getSDesc($this);
  4247.                 $list[] = $lt;
  4248.             }
  4249.         } else return false;
  4250.         return $list;
  4251.     }
  4252.     
  4253.     /**
  4254.      * Return template-enabled list of inherited variables
  4255.      *
  4256.      * uses parserVar helper function getInheritedVars and generates a
  4257.      * template-enabled list using getClassLink()
  4258.      * @param parserVar $child class method
  4259.      * @see getClassLink(), parserVar::getInheritedVars()
  4260.      * @return array Format:
  4261.      * <pre>
  4262.      * array(
  4263.      *   array('parent_class' => link to parent class's documentation,
  4264.      *         'ivars' => 
  4265.      *            array(
  4266.      *              array('name' => inherited variable name,
  4267.      *                    'link' => link to inherited variable's documentation,
  4268.      *                    'default' => default value of inherited variable,
  4269.      *                    'sdesc' => summary of inherited variable),
  4270.      *              ...),
  4271.      *   ...)
  4272.      * </pre>
  4273.      */
  4274.     
  4275.     function getFormattedInheritedVars($child)
  4276.     {
  4277.         $package = $child->docblock->package;
  4278.         $subpackage = $child->docblock->subpackage;
  4279.         $ivars = $child->getInheritedVars($this);
  4280.         $results = array();
  4281.         if (!count($ivars)) return $results;
  4282.         foreach($ivars as $parent => $vars)
  4283.         {
  4284.             $file = $vars['file'];
  4285.             $vars = $vars['vars'];
  4286.             $par = $this->classes->getClass($parent,$file);
  4287.             $package = $par->docblock->package;
  4288.             usort($vars,array($this,"sortVar"));
  4289.             $result['parent_class'] = $this->getClassLink($parent,$package);
  4290.             foreach($vars as $var)
  4291.             {
  4292.                 $info = array();
  4293.                 
  4294.                                 if ($var->docblock->hasaccess)
  4295.                                     $info['access'] = $var->docblock->tags['access'][0]->value;
  4296.                                 else
  4297.                                     $info['access'] = 'public';
  4298.                                 
  4299.                                 $info['name'] = $var->getName();
  4300.                 $info['link'] = $var->getLink($this);
  4301.                 $info['default'] = $this->postProcess($var->getValue());
  4302.                 if ($var->docblock)
  4303.                 $info['sdesc'] = $var->docblock->getSDesc($this);
  4304.                 $result["ivars"][] = $info;
  4305.             }
  4306.             $results[] = $result;
  4307.             $result = array();
  4308.         }
  4309.         return $results;
  4310.     }
  4311.     
  4312.     /**
  4313.      * Return template-enabled list of inherited methods
  4314.      *
  4315.      * uses parserMethod helper function getInheritedMethods and generates a
  4316.      * template-enabled list using getClassLink()
  4317.      * @param parserMethod $child class method
  4318.      * @see getClassLink(), parserMethod::getInheritedMethods()
  4319.      * @return array Format:
  4320.      * <pre>
  4321.      * array(
  4322.      *   array('parent_class' => link to parent class's documentation,
  4323.      *         'ivars' => 
  4324.      *            array(
  4325.      *              array('name' => inherited variable name,
  4326.      *                    'link' => link to inherited variable's documentation,
  4327.      *                    'function_call' => {@link parserMethod::getIntricateFunctionCall()}
  4328.      *                                       returned array,
  4329.      *                    'sdesc' => summary of inherited variable),
  4330.      *              ...),
  4331.      *   ...)
  4332.      * </pre>
  4333.      */
  4334.  
  4335.     function getFormattedInheritedMethods($child)
  4336.     {
  4337.         $package = $child->docblock->package;
  4338.         $subpackage = $child->docblock->subpackage;
  4339.         $imethods = $child->getInheritedMethods($this);
  4340.         $results = array();
  4341.         if (!count($imethods)) return $results;
  4342.         foreach($imethods as $parent => $methods)
  4343.         {
  4344.             $file = $methods['file'];
  4345.             $methods = $methods['methods'];
  4346.             $par = $this->classes->getClass($parent,$file);
  4347.             $package = $par->docblock->package;
  4348.             usort($methods,array($this,"sortMethod"));
  4349.             $result['parent_class'] = $this->getClassLink($parent,$package);
  4350.             foreach($methods as $method)
  4351.             {
  4352.                 $info = array();
  4353.                                 
  4354.                                 if ($method->docblock->hasaccess)
  4355.                                     $info['access'] = $method->docblock->tags['access'][0]->value;
  4356.                                 else
  4357.                                     $info['access'] = 'public';
  4358.  
  4359.                                 if ($method->isConstructor) $info['constructor'] = 1;
  4360.                 $info['link'] = $method->getLink($this);
  4361.                 $info['name'] = $method->getName();
  4362.                 if ($method->docblock)
  4363.                 $info['sdesc'] = $method->docblock->getSDesc($this);
  4364.                 $params = array();
  4365.                 if (count($method->docblock->params))
  4366.                 foreach($method->docblock->params as $param => $val)
  4367.                 {
  4368.                     $a = $val->Convert($this);
  4369.                     $params[$param] = array("var" => $param,"datatype" => $val->converted_returnType,"data" => $a);
  4370.                 }
  4371.         
  4372.                 $info['function_call'] = $method->getIntricateFunctionCall($this,$params);
  4373.                 $result["imethods"][] = $info;
  4374.             }
  4375.             $results[] = $result;
  4376.             $result = array();
  4377.         }
  4378.         return $results;
  4379.     }
  4380.  
  4381.     /**
  4382.      * Return a Smarty template object to operate with
  4383.      *
  4384.      * This returns a Smarty template with pre-initialized variables for use.
  4385.      * If the method "SmartyInit()" exists, it is called.
  4386.      * @return Smarty
  4387.      */
  4388.     function &newSmarty()
  4389.     {
  4390.         $templ = new Smarty;
  4391.         $templ->template_dir = realpath($this->smarty_dir . PATH_DELIMITER . 'templates');
  4392.         $templ->compile_dir = realpath($this->smarty_dir . PATH_DELIMITER . 'templates_c');
  4393.         $templ->config_dir = realpath($this->smarty_dir . PATH_DELIMITER . 'configs');
  4394.         $templ->assign("date",date("r",time()));
  4395.         $templ->assign("maintitle",$this->title);
  4396.         $templ->assign("package",$this->package);
  4397.         $templ->assign("phpdocversion",PHPDOCUMENTOR_VER);
  4398.         $templ->assign("phpdocwebsite",PHPDOCUMENTOR_WEBSITE);
  4399.         $templ->assign("subpackage",$this->subpackage);
  4400.         if (method_exists($this,'SmartyInit')) return $this->SmartyInit($templ);
  4401.         return $templ;
  4402.     }
  4403.     
  4404.     /**
  4405.      * do all necessary output
  4406.      * @see Converter
  4407.      * @abstract
  4408.      */
  4409.     function Output($title)
  4410.     {
  4411.         phpDocumentor_out("WARNING: Generic Converter::Output was used, no output will be generated");
  4412.     }
  4413.     
  4414.     /**
  4415.      * Set the template directory with a different template base directory
  4416.      * @tutorial phpDocumentor.howto.pkg#using.command-line.templatebase
  4417.      * @param string template base directory
  4418.      * @param string template name
  4419.      */
  4420.     function setTemplateBase($base, $dir)
  4421.     {
  4422.         // remove trailing /'s from the base path, if any
  4423.         $base = str_replace('\\','/',$base);
  4424.         while ($base{strlen($base) - 1} == '/') $base = substr($base,0,strlen($base) - 1);
  4425.         $this->templateName = substr($dir,0,strlen($dir) - 1);
  4426.         $this->templateDir =  $base . "/Converters/" . $this->outputformat . "/" . $this->name . "/templates/" . $dir;
  4427.         if (!is_dir($this->templateDir))
  4428.         {
  4429.             addErrorDie(PDERROR_TEMPLATEDIR_DOESNT_EXIST, $this->templateDir);
  4430.         }
  4431.         
  4432.         $this->smarty_dir = $this->templateDir;
  4433.         if (file_exists($this->templateDir . PATH_DELIMITER . 'options.ini'))
  4434.         {
  4435.             // retrieve template options, allow array creation
  4436.             $this->template_options = phpDocumentor_parse_ini_file($this->templateDir . PATH_DELIMITER . 'options.ini',true);
  4437.         }
  4438.     }
  4439.     
  4440.     /**
  4441.      * sets the template directory based on the {@link $outputformat} and {@link $name}
  4442.      * Also sets {@link $templateName} to the $dir parameter
  4443.      * @param string subdirectory
  4444.      */
  4445.     function setTemplateDir($dir)
  4446.     {
  4447.         require_once 'PEAR/Config.php';
  4448.         $config = &PEAR_Config::singleton();
  4449.         $templateBase = str_replace('\\', '/', $config->get('data_dir')) . '/PhpDocumentor/phpDocumentor';
  4450. //        $templateBase = str_replace('\\','/',$GLOBALS['_phpDocumentor_install_dir']) . '/phpDocumentor';
  4451.         $this->setTemplateBase($templateBase, $dir);
  4452.     }
  4453.     
  4454.     /**
  4455.      * Get the absolute path to the converter's base directory
  4456.      * @return string
  4457.      */
  4458.     function getConverterDir()
  4459.     {
  4460.         return str_replace('\\', '/', "C:\xampp\php\pear\data/PhpDocumentor/phpDocumentor/Converters/") . $this->outputformat . "/" . $this->name;
  4461.         return str_replace('\\','/',$GLOBALS['_phpDocumentor_install_dir']) ."/phpDocumentor/Converters/" . $this->outputformat . "/" . $this->name;
  4462.     }
  4463.     
  4464.     /**
  4465.      * Parse a global variable's default value for class initialization.
  4466.      *
  4467.      * If a global variable's default value is "new class" as in:
  4468.      * <code>
  4469.      * $globalvar = new Parser
  4470.      * </code>
  4471.      * This method will document it not as "new Parser" but instead as
  4472.      * "new {@link Parser}".    For examples, see {@link phpdoc.inc}.
  4473.      * Many global variables are classes, and phpDocumentor links to their
  4474.      * documentation
  4475.      * @return string default global variable value with link to class if
  4476.      *                it's "new Class"
  4477.      * @param string default value of a global variable.
  4478.      */
  4479.     function getGlobalValue($value)
  4480.     {
  4481.         if (strpos($value,'new') === 0)
  4482.         {
  4483.             preg_match('/new([^(]*)(.*)/',$value,$newval);
  4484.             if (isset($newval[1]))
  4485.             {
  4486.                 $a = Converter::getLink(trim($newval[1]));
  4487.                 if (!isset($newval[2])) $newval[2] = '';
  4488.                 if ($a && get_class($a) == 'classlink') $value = 'new '.$this->returnSee($a).$newval[2];
  4489.             }
  4490.         }
  4491.         return $value;
  4492.     }
  4493.     
  4494.     /**
  4495.      * Parse an include's file to see if it is a file documented in this project
  4496.      *
  4497.      * Although not very smart yet, this method will try to look for the
  4498.      * included file file.ext:
  4499.      *
  4500.      * <code>
  4501.      * include ("file.ext");
  4502.      * </code>
  4503.      *
  4504.      * If it finds it, it will return a link to the file's documentation.  As of
  4505.      * 1.2.0rc1, phpDocumentor is smarty enough to find these cases:
  4506.      * <ul>
  4507.      *  <li>absolute path to file</li>
  4508.      *  <li>./file.ext or ../file.ext</li>
  4509.      *  <li>relpath/to/file.ext if relpath is a subdirectory of the base parse
  4510.      *      directory</li>
  4511.      * </ul>
  4512.      * For examples, see {@link Setup.inc.php} includes.
  4513.      * Every include auto-links to the documentation for the file that is included
  4514.      * @return string included file with link to docs for file, if found
  4515.      * @param string file included by include statement.
  4516.      * @param string path of file that has the include statement
  4517.      */
  4518.     function getIncludeValue($value, $ipath)
  4519.     {
  4520.         preg_match('/"([^"\']*\.[^"\']*)"/',$value,$match);
  4521.         if (!isset($match[1]))
  4522.         preg_match('/\'([^"\']*\.[^"\']*)\'/',$value,$match);
  4523.         if (isset($match[1]))
  4524.         {
  4525.             $fancy_per = $this->proceduralpages->pathMatchesParsedFile($match[1],$ipath);
  4526.             if ($fancy_per)
  4527.             {
  4528.                 $link = $this->addLink($fancy_per);
  4529.                 $value = $this->returnSee($link,$value);
  4530.             } else
  4531.             {
  4532.                 $per = Converter::getLink($match[1]);
  4533.                 if (is_object($per) && get_class($per) == 'pagelink')
  4534.                 $value = $this->returnSee($per);
  4535.             }
  4536.         }
  4537.         return $value;
  4538.     }
  4539.     
  4540.     /**
  4541.      * Recursively creates all subdirectories that don't exist in the $dir path
  4542.      * @param string $dir
  4543.      */
  4544.     function createParentDir($dir)
  4545.     {
  4546.         if (empty($dir)) return;
  4547.         $tmp = explode(SMART_PATH_DELIMITER,$dir);
  4548.         array_pop($tmp);
  4549.         $parent = implode(SMART_PATH_DELIMITER,$tmp);
  4550.         if ($parent != '' && !file_exists($parent))
  4551.         {
  4552.             $test = @mkdir($parent,0775);
  4553.             if (!$test)
  4554.             {
  4555.                 $this->createParentDir($parent);
  4556.                 $test = @mkdir($parent,0775);
  4557.                 phpDocumentor_out("Creating Parent Directory $parent\n");
  4558.             } else
  4559.             {
  4560.                 phpDocumentor_out("Creating Parent Directory $parent\n");
  4561.             }
  4562.         }
  4563.     }
  4564.  
  4565.     /**
  4566.      * Sets the output directory for generated documentation
  4567.      * @param string $dir the output directory
  4568.      */
  4569.     function setTargetDir($dir)
  4570.     {
  4571.         if (strlen($dir) > 0) 
  4572.         {
  4573.             $this->targetDir = $dir;
  4574.             // if directory does exist create it, this should have more error checking in the future
  4575.             if (!file_exists($dir))
  4576.             {
  4577.                 $tmp = str_replace(array("/","\\"),SMART_PATH_DELIMITER,$dir);
  4578.                 if (substr($tmp,-1) == SMART_PATH_DELIMITER)
  4579.                 {
  4580.                     $tmp = substr($tmp,0,(strlen($tmp)-1));
  4581.                 }
  4582.                 $this->createParentDir($tmp);
  4583.                 phpDocumentor_out("Creating Directory $dir\n");
  4584.                 mkdir($dir,0775);
  4585.             } 
  4586.              else if (!is_dir($dir))
  4587.             {
  4588.                 echo "Output path: '$dir' is not a directory\n";
  4589.                 die();
  4590.             }
  4591.         } else {
  4592.             echo "a target directory must be specified\n try phpdoc -h\n";
  4593.             die();
  4594.         }
  4595.     }
  4596.  
  4597.     /**
  4598.      * Writes a file to target dir
  4599.      * @param string
  4600.      * @param string
  4601.      * @param boolean true if the data is binary and not text
  4602.      */
  4603.     function writeFile($file,$data,$binary = false)
  4604.     {
  4605.         if (!file_exists($this->targetDir))
  4606.         {
  4607.             mkdir($this->targetDir,0775);
  4608.         }
  4609.         $string = '';
  4610.         if ($binary) $string = 'binary file ';
  4611.         phpDocumentor_out("    Writing $string".$this->targetDir . PATH_DELIMITER . $file . "\n");
  4612.         flush();
  4613.         $write = 'w';
  4614.         if ($binary) $write = 'wb';
  4615.         $fp = fopen($this->targetDir . PATH_DELIMITER . $file,$write);
  4616.         set_file_buffer( $fp, 0 );
  4617.         fwrite($fp,$data,strlen($data));
  4618.         fclose($fp);
  4619.     }
  4620.     
  4621.     /**
  4622.      * Copies a file from the template directory to the target directory
  4623.      * thanks to Robert Hoffmann for this fix
  4624.      * @param string
  4625.      */
  4626.     function copyFile($file, $subdir = '')
  4627.     {
  4628.         if (!file_exists($this->targetDir))
  4629.         {
  4630.             mkdir($this->targetDir,0775); 
  4631.         }
  4632.         copy($this->templateDir . $subdir  . PATH_DELIMITER . $file, $this->targetDir . PATH_DELIMITER . $file); 
  4633.     } 
  4634.  
  4635.     /**
  4636.      * Return parserStringWithInlineTags::Convert() cache state
  4637.      * @see parserStringWithInlineTags::Convert()
  4638.      * @abstract
  4639.      */
  4640.     function getState()
  4641.     {
  4642.         return true;
  4643.     }
  4644.  
  4645.     /**
  4646.      * Compare parserStringWithInlineTags::Convert() cache state to $state
  4647.      * @param mixed
  4648.      * @see parserStringWithInlineTags::Convert()
  4649.      * @abstract
  4650.      */
  4651.     function checkState($state)
  4652.     {
  4653.         return true;
  4654.     }
  4655.  
  4656. }
  4657.  
  4658. /**
  4659.  * @access private
  4660.  * @see Converter::getSortedClassTreeFromClass()
  4661.  */
  4662. function rootcmp($a, $b)
  4663. {
  4664.     return strnatcasecmp($a['class'],$b['class']);
  4665. }
  4666.  
  4667. /**
  4668.  * @access private
  4669.  * @global string used to make the first tutorials converted the default package tutorials
  4670.  */
  4671. function tutorialcmp($a, $b)
  4672. {
  4673.     global $phpDocumentor_DefaultPackageName;
  4674.     if ($a == $phpDocumentor_DefaultPackageName) return -1;
  4675.     if ($b == $phpDocumentor_DefaultPackageName) return 1;
  4676.     return strnatcasecmp($a, $b);
  4677. }
  4678.  
  4679. /**
  4680.  * smart htmlentities, doesn't entity the allowed tags list
  4681.  * Since version 1.1, this function uses htmlspecialchars instead of
  4682.  * htmlentities, for international support
  4683.  * This function has been replaced by functionality in {@link ParserDescCleanup.inc}
  4684.  * @param string $s
  4685.  * @return string browser-displayable page
  4686.  * @deprecated As of v1.2, No longer needed, as valid tags are parsed out of the source,
  4687.  *   and everything else is {@link Converter::postProcess()} handled
  4688.  */
  4689. function adv_htmlentities($s)
  4690. {
  4691.     return;
  4692.     global $phpDocumentor___html,$_phpDocumentor_html_allowed;
  4693.     $result = htmlspecialchars($s);
  4694.     $entities = array_flip(get_html_translation_table(HTML_SPECIALCHARS));
  4695.     $result = strtr($result,$phpDocumentor___html);
  4696.     $matches = array();
  4697.     preg_match_all('/(<img.*>)/U',$result,$matches);
  4698.     for($i=0;$i<count($matches[1]);$i++)
  4699.     {
  4700.         $result = str_replace($matches[1][$i],strtr($matches[1][$i],array_flip(get_html_translation_table(HTML_SPECIALCHARS))),$result);
  4701.     }
  4702.     preg_match_all('/(<font.*>)/U',$result,$matches);
  4703.     for($i=0;$i<count($matches[1]);$i++)
  4704.     {
  4705.         $result = str_replace($matches[1][$i],strtr($matches[1][$i],array_flip(get_html_translation_table(HTML_SPECIALCHARS))),$result);
  4706.     }
  4707.     preg_match_all('/(<ol.*>)/U',$result,$matches);
  4708.     for($i=0;$i<count($matches[1]);$i++)
  4709.     {
  4710.         $result = str_replace($matches[1][$i],strtr($matches[1][$i],array_flip(get_html_translation_table(HTML_SPECIALCHARS))),$result);
  4711.     }
  4712.     preg_match_all('/(<ul.*>)/U',$result,$matches);
  4713.     for($i=0;$i<count($matches[1]);$i++)
  4714.     {
  4715.         $result = str_replace($matches[1][$i],strtr($matches[1][$i],array_flip(get_html_translation_table(HTML_SPECIALCHARS))),$result);
  4716.     }
  4717.     preg_match_all('/(<li.*>)/U',$result,$matches);
  4718.     for($i=0;$i<count($matches[1]);$i++)
  4719.     {
  4720.         $result = str_replace($matches[1][$i],strtr($matches[1][$i],array_flip(get_html_translation_table(HTML_SPECIALCHARS))),$result);
  4721.     }
  4722.     preg_match_all('/(<a .*>)/U',$result,$matches);
  4723.     for($i=0;$i<count($matches[1]);$i++)
  4724.     {
  4725.         $result = str_replace($matches[1][$i],strtr($matches[1][$i],array_flip(get_html_translation_table(HTML_SPECIALCHARS))),$result);
  4726.     }
  4727.     return $result;
  4728. }
  4729.  
  4730. /**
  4731.  * Used solely for setting up the @uses list
  4732.  * @ignore
  4733.  */
  4734. class __dummyConverter extends Converter
  4735. {
  4736.     function setTemplateDir(){}
  4737.     function setTargetDir(){}
  4738.     function getPageName(&$element)
  4739.     {
  4740.         if (get_class($element) == 'parserpage') return '_'.$element->getName();
  4741.         return '_'.$element->parent->getName();
  4742.     }
  4743. }
  4744. ?>
  4745.