home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / HTMLframesConverter.inc < prev    next >
Encoding:
Text File  |  2004-03-24  |  63.9 KB  |  1,657 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.  * HTML original framed output converter, modified to use Smarty Template.
  21.  * This Converter takes output from the {@link Parser} and converts it to HTML-ready output for use with {@link Smarty}.
  22.  *
  23.  * @package Converters
  24.  * @subpackage HTMLframes
  25.  * @see parserDocBlock, parserInclude, parserPage, parserClass, parserDefine, parserFunction, parserMethod, parserVar
  26.  * @author Greg Beaver <cellog@users.sourceforge.net>
  27.  * @since 1.0rc1
  28.  * @version $Id: HTMLframesConverter.inc,v 1.79.2.6 2003/08/20 21:04:29 mvonballmo Exp $
  29.  */
  30. /**
  31.  * HTML output converter.
  32.  * This Converter takes output from the {@link Parser} and converts it to HTML-ready output for use with {@link Smarty}.
  33.  *
  34.  * @package Converters
  35.  * @subpackage HTMLframes
  36.  * @see parserDocBlock, parserInclude, parserPage, parserClass, parserDefine, parserFunction, parserMethod, parserVar
  37.  * @author Greg Beaver <cellog@users.sourceforge.net>
  38.  * @since 1.2
  39.  * @version $Id: HTMLframesConverter.inc,v 1.79.2.6 2003/08/20 21:04:29 mvonballmo Exp $
  40.  */
  41. class HTMLframesConverter extends Converter
  42. {
  43.     /**
  44.      * Smarty Converter wants elements sorted by type as well as alphabetically
  45.      * @see Converter::$sort_page_contents_by_type
  46.      * @var boolean
  47.      */
  48.     var $sort_page_contents_by_type = true;
  49.     /** @var string */
  50.     var $outputformat = 'HTML';
  51.     /** @var string */
  52.     var $name = 'frames';
  53.     /**
  54.      * indexes of elements by package that need to be generated
  55.      * @var array
  56.      */
  57.     var $leftindex = array('classes' => true, 'pages' => true, 'functions' => true, 'defines' => false, 'globals' => false);
  58.     
  59.     /**
  60.      * output directory for the current procedural page being processed
  61.      * @var string
  62.      */
  63.     var $page_dir;
  64.     
  65.     /**
  66.      * target directory passed on the command-line.
  67.      * {@link $targetDir} is malleable, always adding package/ and package/subpackage/ subdirectories onto it.
  68.      * @var string
  69.      */
  70.     var $base_dir;
  71.     
  72.     /**
  73.      * output directory for the current class being processed
  74.      * @var string
  75.      */
  76.     var $class_dir;
  77.     
  78.     /**
  79.      * array of converted package page names.
  80.      * Used to link to the package page in the left index
  81.      * @var array Format: array(package => 1)
  82.      */
  83.     var $package_pages = array();
  84.     
  85.     /**
  86.      * controls formatting of parser informative output
  87.      * 
  88.      * Converter prints:
  89.      * "Converting /path/to/file.php... Procedural Page Elements... Classes..."
  90.      * Since HTMLdefaultConverter outputs files while converting, it needs to send a \n to start a new line.  However, if there
  91.      * is more than one class, output is messy, with multiple \n's just between class file output.  This variable prevents that
  92.      * and is purely cosmetic
  93.      * @var boolean
  94.      */
  95.     var $juststarted = false;
  96.     
  97.     /**
  98.      * contains all of the template procedural page element loop data needed for the current template
  99.      * @var array
  100.      */
  101.     var $current;
  102.     
  103.     /**
  104.      * contains all of the template class element loop data needed for the current template
  105.      * @var array
  106.      */
  107.     var $currentclass;
  108.     var $wrote = false;
  109.     var $ric_set = array();
  110.     
  111.     /**
  112.      * sets {@link $base_dir} to $targetDir
  113.      * @see Converter()
  114.      */
  115.     function HTMLframesConverter(&$allp, &$packp, &$classes, &$procpages, $po, $pp, $qm, $targetDir, $templateDir, $title)
  116.     {
  117.         Converter::Converter($allp, $packp, $classes, $procpages,$po, $pp, $qm, $targetDir, $templateDir, $title);
  118.         $this->base_dir = $targetDir;
  119.     }
  120.     
  121.     /**
  122.      * @deprecated in favor of PHP 4.3.0+ tokenizer-based source highlighting
  123.      */
  124.     function unmangle($sourcecode)
  125.     {
  126.         $sourcecode = str_replace('<code>','<pre>',$sourcecode);
  127.         $sourcecode = str_replace('</code>','</pre>',$sourcecode);
  128.         $sourcecode = str_replace('<br />',"\n",$sourcecode);
  129.         $sourcecode = str_replace(' ',' ',$sourcecode);
  130.         $sourcecode = str_replace('<','<',$sourcecode);
  131.         $sourcecode = str_replace('>','>',$sourcecode);
  132.         $sourcecode = str_replace('&','&',$sourcecode);
  133.         return $sourcecode;
  134.     }
  135.  
  136.     /**
  137.      * @param string full path to the source file
  138.      * @param string fully highlighted source code
  139.      */
  140.     function writeSource($path, $value)
  141.     {
  142.         $templ = &$this->newSmarty();
  143.         $pathinfo = $this->proceduralpages->getPathInfo($path, $this);
  144.         $templ->assign('source',$value);
  145.         $templ->assign('package',$pathinfo['package']);
  146.         $templ->assign('subpackage',$pathinfo['subpackage']);
  147.         $templ->assign('name',$pathinfo['name']);
  148.         $templ->assign('source_loc',$pathinfo['source_loc']);
  149.         $templ->assign('docs',$pathinfo['docs']);
  150.         $templ->assign("subdir",'../');
  151.         $templ->register_outputfilter('HTMLframes_outputfilter');
  152.         $this->setTargetDir($this->getFileSourcePath($this->base_dir));
  153.         phpDocumentor_out("\n");
  154.         $this->setSourcePaths($path);
  155.         $this->writefile($this->getFileSourceName($path).'.html',$templ->fetch('filesource.tpl'));
  156.     }
  157.     
  158.     function writeExample($title, $path, $source)
  159.     {
  160.         $templ = &$this->newSmarty();
  161.         $templ->assign('source',$source);
  162.         if (empty($title))
  163.         {
  164.             $title = 'example';
  165.             addWarning(PDERROR_EMPTY_EXAMPLE_TITLE, $path, $title);
  166.         }
  167.         $templ->assign('title',$title);
  168.         $templ->assign('file',$path);
  169.         $templ->assign("subdir",'../');
  170.         $templ->register_outputfilter('HTMLframes_outputfilter');
  171.         $this->setTargetDir($this->base_dir . PATH_DELIMITER . '__examplesource');
  172.         phpDocumentor_out("\n");
  173.         $this->writefile('exsource_'.$path.'.html',$templ->fetch('examplesource.tpl'));
  174.     }
  175.     
  176.     function getExampleLink($path, $title)
  177.     {
  178.         return $this->returnLink('{$subdir}__examplesource' . PATH_DELIMITER . 'exsource_'.$path.'.html',$title);
  179.     }
  180.     
  181.     function getSourceLink($path)
  182.     {
  183.         return $this->returnLink($this->getFileSourcePath('{$subdir}') .
  184.         PATH_DELIMITER . $this->getFileSourceName($path).'.html','Source Code for this file');
  185.     }
  186.     
  187.     /**
  188.      * Used to convert the <<code>> tag in a docblock
  189.      * @param string
  190.      * @param boolean
  191.      * @return string
  192.      */
  193.     function ProgramExample($example, $tutorial = false, $inlinesourceparse = null/*false*/,
  194.                             $class = null/*false*/, $linenum = null/*false*/, $filesourcepath = null/*false*/)
  195.     {
  196.         return $this->PreserveWhiteSpace(parent::ProgramExample($example, $tutorial, $inlinesourceparse, $class, $linenum, $filesourcepath));
  197.     }
  198.     
  199.     /**
  200.      * Retrieve a Converter-specific anchor to a segment of a source code file
  201.      * parsed via a {@tutorial tags.filesource.pkg} tag.
  202.      * @param string full path to source file
  203.      * @param string name of anchor
  204.      * @param string link text, if this is a link
  205.      * @param boolean returns either a link or a destination based on this
  206.      *                parameter
  207.      * @return string link to an anchor, or the anchor
  208.      */
  209.     function getSourceAnchor($sourcefile,$anchor,$text = '',$link = false)
  210.     {
  211.         if ($link)
  212.         return $this->returnLink($this->getFileSourcePath('{$subdir}') .
  213.         PATH_DELIMITER . $this->getFileSourceName($sourcefile).'.html#a'.$anchor, $text);
  214.         else
  215.         return '<a name="a'.$anchor.'"></a>';
  216.     }
  217.     
  218.     function getCurrentPageLink()
  219.     {
  220.         return $this->curname . '.html';
  221.     }
  222.  
  223.     /**
  224.      * Uses htmlspecialchars() on the input
  225.      */
  226.     function postProcess($text)
  227.     {
  228.         return htmlspecialchars($text);
  229.     }
  230.     
  231.     /**
  232.      * Use the template tutorial_toc.tpl to generate a table of contents for HTML
  233.      * @return string table of contents formatted for use in the current output format
  234.      * @param array format: array(array('tagname' => section, 'link' => returnsee link, 'id' => anchor name, 'title' => from title tag),...)
  235.      */
  236.     function formatTutorialTOC($toc)
  237.     {
  238.         $template = &$this->newSmarty();
  239.         $template->assign('toc',$toc);
  240.         return $template->fetch('tutorial_toc.tpl');
  241.     }
  242.     
  243.     function &SmartyInit(&$templ)
  244.     {
  245.         if (!isset($this->package_index))
  246.         foreach($this->all_packages as $key => $val)
  247.         {
  248.             if (isset($this->pkg_elements[$key]))
  249.             {
  250.                 if (!isset($start)) $start = $key;
  251.                 $this->package_index[] = array('link' => "li_$key.html", 'title' => $key);
  252.             }
  253.         }
  254.         $templ->assign("packageindex",$this->package_index);
  255.         $templ->assign("subdir",'');
  256.         return $templ;
  257.     }
  258.     
  259.     /**
  260.      * Writes out the template file of {@link $class_data} and unsets the template to save memory
  261.      * @see registerCurrentClass()
  262.      * @see parent::endClass()
  263.      */
  264.     function endClass()
  265.     {
  266.         $a = '../';
  267.         if (!empty($this->subpackage)) $a .= '../';
  268.         if ($this->juststarted)
  269.         {
  270.             $this->juststarted = false;
  271.             phpDocumentor_out("\n");
  272.             flush();
  273.         }
  274.         $this->setTargetDir($this->base_dir . PATH_DELIMITER . $this->class_dir);
  275.         $this->class_data->assign("subdir",$a);
  276.         $this->class_data->register_outputfilter('HTMLframes_outputfilter');
  277.         $this->writefile($this->class . '.html',$this->class_data->fetch('class.tpl'));
  278.         unset($this->class_data);
  279.     }
  280.     
  281.     /**
  282.      * Writes out the template file of {@link $page_data} and unsets the template to save memory
  283.      * @see registerCurrent()
  284.      * @see parent::endPage()
  285.      */
  286.     function endPage()
  287.     {
  288.         $this->package = $this->curpage->package;
  289.         $this->subpackage = $this->curpage->subpackage;
  290.         $a = '../';
  291.         if (!empty($this->subpackage)) $a .= '../';
  292.         $this->setTargetDir($this->base_dir . PATH_DELIMITER . $this->page_dir);
  293.         $this->page_data->assign("package",$this->package);
  294.         $this->page_data->assign("subdir",$a);
  295.         $this->page_data->register_outputfilter('HTMLframes_outputfilter');
  296.         $this->writefile($this->page . '.html',$this->page_data->fetch('page.tpl'));
  297.         unset($this->page_data);
  298.     }
  299.     
  300.     /**
  301.      * @param string
  302.      * @param string
  303.      * @return string <a href="'.$link.'">'.$text.'</a>
  304.      */
  305.     function returnLink($link,$text)
  306.     {
  307.         return '<a href="'.$link.'">'.$text.'</a>';
  308.     }
  309.     
  310.     function makeLeft()
  311.     {
  312.         foreach($this->page_elements as $package => $o1)
  313.         {
  314.             foreach($o1 as $subpackage => $links)
  315.             {
  316.                 for($i=0;$i<count($links);$i++)
  317.                 {
  318.                     $left[$package][$subpackage]['files'][] =
  319.                         array("link" => $this->getId($links[$i]), "title" => $links[$i]->name);
  320.                 }
  321.             }
  322.         }
  323.         foreach($this->class_elements as $package => $o1)
  324.         {
  325.             foreach($o1 as $subpackage => $links)
  326.             {
  327.                 for($i=0;$i<count($links);$i++)
  328.                 {
  329.                                         $class = $this->classes->getClassByPackage($links[$i]->name, $links[$i]->package);
  330.                                         if ($class && isset($class->docblock) && $class->docblock->hasaccess)
  331.                                                 $left[$package][$subpackage]['classes'][] =
  332.                                                 array("link" => $this->getId($links[$i]), 
  333.                                                             "title" => $links[$i]->name,
  334.                                                             "access" => $class->docblock->tags['access'][0]->value,
  335.                                                             "abstract" => isset ($class->docblock->tags['abstract'][0]));
  336.                                         else
  337.                                                 $left[$package][$subpackage]['classes'][] =
  338.                                                 array("link" => $this->getId($links[$i]), 
  339.                                                             "title" => $links[$i]->name,
  340.                                                             "access" => 'public',
  341.                                                             "abstract" => isset ($class->docblock->tags['abstract'][0]));
  342.                 }
  343.             }
  344.         }
  345.         foreach($this->function_elements as $package => $o1)
  346.         {
  347.             foreach($o1 as $subpackage => $links)
  348.             {
  349.                 for($i=0;$i<count($links);$i++)
  350.                 {
  351.                     $left[$package][$subpackage]['functions'][] =
  352.                         array("link" => $this->getId($links[$i]), "title" => $links[$i]->name);
  353.                 }
  354.             }
  355.         }
  356.         $ret = array();
  357.         foreach($left as $package => $r)
  358.         {
  359.             $pd = 'blank';
  360.             if (isset($this->package_pages[$package])) $pd = $package.'/package_'.$package.'.html';
  361.             if (!isset($r['']))
  362.             {
  363.                 $pt = false;
  364.                 $ptnoa = false;
  365.                 $ptt = $package;
  366.                 if ($t = $this->hasTutorial('pkg',$package,$package,''))
  367.                 {
  368.                     $pt = $t->getLink($this);
  369.                     $ptnoa = $this->getId($t->getLink($this,true));
  370.                     $ptt = $t->getTitle($this);
  371.                 }
  372.                 $tutes = array();
  373.                 foreach($this->tutorial_tree as $root => $tr)
  374.                 {
  375.                     if ($tr['tutorial']->package == $package && $tr['tutorial']->subpackage == $subpackage)
  376.                     $tutes[$tr['tutorial']->tutorial_type][] = $this->getTutorialTree($tr['tutorial']);
  377.                 }
  378.                 if (isset($this->childless_tutorials[$package][$subpackage]))
  379.                 {
  380.                     foreach($this->childless_tutorials[$package][$subpackage] as $ext => $other)
  381.                     {
  382.                         foreach($other as $tutorial)
  383.                         {
  384.                             $tutes[$tutorial->tutorial_type][] = $this->getTutorialTree($tutorial);
  385.                         }
  386.                     }
  387.                 }
  388.                 $ret[$package][] =
  389.                     array(
  390.                         'package' => $package,
  391.                         'subpackage' => '',
  392.                         'packagedoc' => $pd,
  393.                         'packagetutorial' => $pt,
  394.                         'packagetutorialnoa' => $ptnoa,
  395.                         'packagetutorialtitle' => $ptt,
  396.                         'files' => array(),
  397.                         'functions' => array(),
  398.                         'classes' => array(),
  399.                         'tutorials' => $tutes,
  400.                         );
  401.             }
  402.             foreach($r as $subpackage => $info)
  403.             {
  404.                 $my = array();
  405.                 $my['package'] = $package;
  406.                 if (isset($this->package_pages[$package]))
  407.                 $my['packagedoc'] = $pd;
  408.                 else
  409.                 $my['packagedoc'] = 'blank';
  410.                 $my['subpackage'] = $subpackage;
  411.                 if (empty($subpackage))
  412.                 {
  413.                     if ($t = $this->hasTutorial('pkg',$package,$package,$subpackage))
  414.                     {
  415.                         $my['packagetutorial'] = $t->getLink($this);
  416.                         $my['packagetutorialnoa'] = $this->getId($t->getLink($this,true));
  417.                         $my['packagetutorialtitle'] = $t->getTitle($this);
  418.                     } else
  419.                     {
  420.                         $my['packagetutorial'] = '<a href="blank.html">No Package-Level Tutorial</a>';
  421.                         $my['packagetutorialnoa'] = 'blank.html';
  422.                         $my['packagetutorialtitle'] = $package;
  423.                     }
  424.                 } else
  425.                 {
  426.                     if ($t = $this->hasTutorial('pkg',$subpackage,$package,$subpackage))
  427.                     {
  428.                         $my['subpackagetutorial'] = $this->returnSee($this->getTutorialLink($t));
  429.                         $my['subpackagetutorialnoa'] = $this->getId($t->getLink($this,true));
  430.                         $my['subpackagetutorialtitle'] = $t->getTitle($this);
  431.                     } else
  432.                     {
  433.                         $my['subpackagetutorial'] = false;
  434.                         $my['subpackagetutorialnoa'] = false;
  435.                         $my['subpackagetutorialtitle'] = $subpackage;
  436.                     }
  437.                 }
  438.                 $tutes = array();
  439.                 foreach($this->tutorial_tree as $root => $tr)
  440.                 {
  441.                     if ($tr['tutorial']->package == $package && $tr['tutorial']->subpackage == $subpackage)
  442.                     {
  443.                         $tutes[$tr['tutorial']->tutorial_type][] = $this->getTutorialTree($tr['tutorial']);
  444.                     }
  445.                 }
  446.                 $my['tutorials'] = $tutes;
  447.                 $my['files'] = $my['classes'] = $my['functions'] = array();
  448.                 if (isset($info['files']))
  449.                 $my['files'] = $info['files'];
  450.                 if (isset($info['classes']))
  451.                 $my['classes'] = $info['classes'];
  452.                 if (isset($info['functions']))
  453.                 $my['functions'] = $info['functions'];
  454.                 $ret[$package][] = $my;
  455.             }
  456.         }
  457.         return $ret;
  458.     }
  459.     
  460.     function getTutorialTree($tutorial,$k = false)
  461.     {
  462.         $ret = '';
  463.         if (is_object($tutorial)) $tree = parent::getTutorialTree($tutorial); else $tree = $tutorial;
  464. //        debug($this->vardump_tree($tree));exit;
  465.         if (!$tree)
  466.         {
  467.             $template = &$this->newSmarty();
  468.             $template->assign('subtree',false);
  469.             $template->assign('name',str_replace('.','',$tutorial->name));
  470.             $template->assign('parent',false);
  471.             $template->assign('haskids',false);
  472.             $template->assign('kids','');
  473.             $link = new tutorialLink;
  474.             $t = $tutorial;
  475.             $link->addLink('',$t->path,$t->name,$t->package,$t->subpackage,$t->getTitle($this));
  476.             $main = array('link' => $this->getId($link), 'title' => $link->title);
  477.             $template->assign('main',$main);
  478.             return $template->fetch('tutorial_tree.tpl');
  479.         }
  480.         if (isset($tree['kids']))
  481.         {
  482.             foreach($tree['kids'] as $subtree)
  483.             {
  484.                 $ret .= $this->getTutorialTree($subtree, true);
  485.             }
  486.         }
  487.         $template = &$this->newSmarty();
  488.         $template->assign('subtree',$k);
  489.         $template->assign('name',str_replace('.','',$tree['tutorial']->name));
  490.         $template->assign('parent',($k ? str_replace('.','',$tree['tutorial']->parent->name) : false));
  491.         $template->assign('haskids',strlen($ret));
  492.         $template->assign('kids',$ret);
  493.         $link = new tutorialLink;
  494.         $t = $tree['tutorial'];
  495.         $link->addLink('',$t->path,$t->name,$t->package,$t->subpackage,$t->getTitle($this));
  496.         $main = array('link' => $this->getId($link), 'title' => $link->title);
  497.         $template->assign('main',$main);
  498.         $ret = $template->fetch('tutorial_tree.tpl');
  499.                 return $ret;
  500.     }
  501.     
  502.     /**
  503.      * HTMLdefaultConverter chooses to format both package indexes and the complete index here
  504.      *
  505.      * This function formats output for the elementindex.html and pkgelementindex.html template files.  It then
  506.      * writes them to the target directory
  507.      * @see generateElementIndex(), generatePkgElementIndex()
  508.      */
  509.     function formatPkgIndex()
  510.     {
  511.         list($package_indexes,$packages,$mletters) = $this->generatePkgElementIndexes();
  512.         for($i=0;$i<count($package_indexes);$i++)
  513.         {
  514.             $template = &$this->newSmarty();
  515.             $this->package = $package_indexes[$i]['package'];
  516.             $this->subpackage = '';
  517.             $template->assign("index",$package_indexes[$i]['pindex']);
  518.             $template->assign("package",$package_indexes[$i]['package']);
  519.             $template->assign("letters",$mletters[$package_indexes[$i]['package']]);
  520.             $template->register_outputfilter('HTMLframes_outputfilter');
  521.             $this->setTargetDir($this->base_dir);
  522.             $this->writefile('elementindex_'.$package_indexes[$i]['package'].'.html',$template->fetch('pkgelementindex.tpl'));
  523.         }
  524.         phpDocumentor_out("\n");
  525.         flush();
  526.         }
  527.     
  528.     /**
  529.      * HTMLdefaultConverter uses this function to format template index.html and packages.html
  530.      *
  531.      * This function generates the package list from {@link $all_packages}, eliminating any
  532.      * packages that don't have any entries in their package index (no files at all, due to @ignore
  533.      * or other factors).  Then it uses the default package name as the first package index to display.
  534.      * It sets the right pane to be either a blank file with instructions on making package-level docs,
  535.      * or the package-level docs for the default package.
  536.      * @global string Used to set the starting package to display
  537.      */
  538.     function formatIndex()
  539.     {
  540.         global $phpDocumentor_DefaultPackageName;
  541.         list($elindex,$mletters) = $this->generateElementIndex();
  542.         $template = &$this->newSmarty();
  543.         $template->assign("index",$elindex);
  544.         $template->assign("letters",$mletters);
  545.         $template->register_outputfilter('HTMLframes_outputfilter');
  546.         phpDocumentor_out("\n");
  547.         flush();
  548.         $this->setTargetDir($this->base_dir);
  549.         $this->writefile('elementindex.html',$template->fetch('elementindex.tpl'));
  550.         usort($this->package_index,"HTMLframes_pindexcmp");
  551.         $index = &$this->newSmarty();
  552.         foreach($this->all_packages as $key => $val)
  553.         {
  554.             if (isset($this->pkg_elements[$key]))
  555.             {
  556.                 if (!isset($start)) $start = $key;
  557.                 if (!isset($this->package_pages[$key])) $this->writeNewPPage($key);
  558.             }
  559.         }
  560.         // Created index.html
  561.         if (isset($this->pkg_elements[$phpDocumentor_DefaultPackageName])) $start = $phpDocumentor_DefaultPackageName;
  562.         $this->package = $start;
  563.         $this->subpackage = '';
  564.         $index->assign("package_count",count($this->pkg_elements));
  565.         if (count($this->ric_set))
  566.         $index->assign("package_count",2);
  567.         $index->assign("date",date("r",time()));
  568.         $index->assign("title",$this->title);
  569.         $index->assign("start","li_$start.html");
  570.         $index->register_outputfilter('HTMLframes_outputfilter');
  571.         if (isset($this->tutorials[$start]['']['pkg'][$start . '.pkg']))
  572.         {
  573.             $index->assign("blank",$start.'/tutorial_'.$start.'.pkg');
  574.         } elseif (isset($this->package_pages[$start]))
  575.         {
  576.             $index->assign("blank",$start.'/package_'.$start);
  577.         }
  578.         else
  579.         {
  580.             $index->assign("blank","blank");
  581.             $blank = &$this->newSmarty();
  582.             $blank->assign('package',$phpDocumentor_DefaultPackageName);
  583.             $this->setTargetDir($this->base_dir);
  584.             $this->writefile("blank.html",$blank->fetch('blank.tpl'));
  585.         }
  586.         phpDocumentor_out("\n");
  587.         flush();
  588.         $this->setTargetDir($this->base_dir);
  589.         $this->writefile("index.html",$index->fetch('index.tpl'));
  590.  
  591.         // Create package index
  592.         $package = &$this->newSmarty();
  593.         $package->assign('ric',array());
  594.         if (isset($this->ric_set))
  595.         {
  596.             foreach($this->ric_set as $name => $u)
  597.             {
  598.                 $package->append('ric',array('file' => 'ric_'.$name.'.html','name' => $name));
  599.             }
  600.         }
  601.         $package->assign("packages",$this->package_index);
  602.         $package->register_outputfilter('HTMLframes_outputfilter');
  603.         $this->writefile("packages.html",$package->fetch('top_frame.tpl'));
  604.         unset($index);
  605.     }
  606.     
  607.     function writeNewPPage($key)
  608.     {
  609.         return;
  610.         $template = &$this->newSmarty();
  611.         $this->package = $key;
  612.         $this->subpackage = '';
  613.         $template->assign("date",date("r",time()));
  614.         $template->assign("title",$this->title);
  615.         $template->assign("package",$key);
  616.         $template->register_outputfilter('HTMLframes_outputfilter');
  617.         phpDocumentor_out("\n");
  618.         flush();
  619.         $this->setTargetDir($this->base_dir);
  620.     
  621.         $this->writefile("li_$key.html",$template->fetch('index.tpl'));
  622.         unset($template);
  623.     }
  624.     
  625.     /**
  626.      * Generate indexes for li_package.html and classtree output files
  627.      *
  628.      * This function generates the li_package.html files from the template file left.html.  It does this by
  629.      * iterating through each of the $page_elements, $class_elements and  $function_elements arrays to retrieve
  630.      * the pre-sorted {@link abstractLink} descendants needed for index generation.  Conversion of these links to
  631.      * text is done by {@link returnSee()}.  The {@link $local} parameter is set to false to ensure that paths are correct.
  632.      * 
  633.      * Then it uses {@link generateFormattedClassTrees()} to create class trees from the template file classtrees.html.  Output
  634.      * filename is classtrees_packagename.html.  This function also unsets {@link $elements} and {@link $pkg_elements} to free
  635.      * up the considerable memory these two class vars use
  636.      * @see $page_elements, $class_elements, $function_elements
  637.      */
  638.     function formatLeftIndex()
  639.     {
  640.         phpDocumentor_out("\n");
  641.         flush();
  642.         $this->setTargetDir($this->base_dir);
  643.         if (0)//!isset($this->left))
  644.         {
  645.             debug("Nothing parsed, check the command-line");
  646.             die();
  647.         }
  648.         $x = $this->makeLeft();
  649.         foreach($this->all_packages as $package => $rest)
  650.         {
  651.             if (!isset($this->pkg_elements[$package])) continue;
  652.             $template = &$this->newSmarty();
  653.             $template->assign("info",$x[$package]);
  654.             $template->assign('package',$package);
  655.             $template->assign("hastutorials",isset($this->tutorials[$package]));
  656.             $template->assign('hastodos',count($this->todoList));
  657.             $template->assign('todolink','todolist.html');
  658.             $template->assign("classtreepage","classtrees_$package");
  659.             $template->assign("elementindex","elementindex_$package");
  660.             $template->register_outputfilter('HTMLframes_outputfilter');
  661.             if (isset($this->package_pages[$package]))
  662.             {
  663.                 $template->assign("packagedoc",$package.'/package_' . $package . '.html');
  664.             } else
  665.             {
  666.                 $template->assign("packagedoc",false);
  667.             }
  668.             $this->writefile("li_$package.html",$template->fetch('left_frame.tpl'));
  669.             
  670.             // Create class tree page
  671.             $template = &$this->newSmarty();
  672.             $template->assign("classtrees",$this->generateFormattedClassTrees($package));
  673.             $template->assign("package",$package);
  674.             $template->register_outputfilter('HTMLframes_outputfilter');
  675.             $this->writefile("classtrees_$package.html",$template->fetch('classtrees.tpl'));
  676.             phpDocumentor_out("\n");
  677.             flush();
  678.         }
  679.         // free up considerable memory
  680.         unset($this->elements);
  681.         unset($this->pkg_elements);
  682.     }
  683.     
  684.     /**
  685.      * This function takes an {@link abstractLink} descendant and returns an html link
  686.      *
  687.      * @param abstractLink a descendant of abstractlink should be passed, and never text
  688.      * @param string text to display in the link
  689.      * @param boolean this parameter is not used, and is deprecated
  690.      * @param boolean determines whether the returned text is enclosed in an <a> tag
  691.      */
  692.     function returnSee(&$element, $eltext = false, $with_a = true)
  693.     {
  694.         if (!$element) return false;
  695.         if (!$with_a) return $this->getId($element, false);
  696.         if (!$eltext)
  697.         {
  698.             $eltext = '';
  699.             switch($element->type)
  700.             {
  701.                 case 'tutorial' :
  702.                 $eltext = strip_tags($element->title);
  703.                 break;
  704.                 case 'method' :
  705.                 case 'var' :
  706.                 $eltext .= $element->class.'::';
  707.                 case 'page' :
  708.                 case 'define' :
  709.                 case 'class' :
  710.                 case 'function' :
  711.                 case 'global' :
  712.                 default :
  713.                 $eltext .= $element->name;
  714.                 if ($element->type == 'function' || $element->type == 'method') $eltext .= '()';
  715.                 break;
  716.             }
  717.         }
  718.         return '<a href="'.$this->getId($element).'">'.$eltext.'</a>';
  719.     }
  720.     
  721.     function getId($element, $fullpath = true)
  722.     {
  723.         if (get_class($element) == 'parserdata')
  724.         {
  725.             $element = $this->addLink($element->parent);
  726.             $elp = $element->parent;
  727.         } elseif (is_a($element, 'parserbase'))
  728.         {
  729.             $elp = $element;
  730.             $element = $this->addLink($element);
  731.         }
  732.         $c = '';
  733.         if (!empty($element->subpackage))
  734.         {
  735.             $c = '/'.$element->subpackage;
  736.         }
  737.         $b = '{$subdir}';
  738.         switch ($element->type)
  739.         {
  740.             case 'page' :
  741.             if ($fullpath)
  742.             return $b.$element->package.$c.'/'.$element->fileAlias.'.html';
  743.             return 'top';
  744.             break;
  745.             case 'define' :
  746.             case 'global' :
  747.             case 'function' :
  748.             if ($fullpath)
  749.             return $b.$element->package.$c.'/'.$element->fileAlias.'.html#'.$element->type.$element->name;
  750.             return $element->type.$element->name;
  751.             break;
  752.             case 'class' :
  753.             if ($fullpath)
  754.             return $b.$element->package.$c.'/'.$element->name.'.html';
  755.             return 'top';
  756.             break;
  757.             case 'method' :
  758.             case 'var' :
  759.             if ($fullpath)
  760.             return $b.$element->package.$c.'/'.$element->class.'.html#'.$element->type.$element->name;
  761.             return $element->type.$element->name;
  762.             break;
  763.             case 'tutorial' :
  764.             $d = '';
  765.             if ($element->section)
  766.             {
  767.                 $d = '#'.$element->section;
  768.             }
  769.             return $b.$element->package.$c.'/tutorial_'.$element->name.'.html'.$d;
  770.         }
  771.     }
  772.     
  773.     /**
  774.      * Convert README/INSTALL/CHANGELOG file contents to output format
  775.      * @param README|INSTALL|CHANGELOG
  776.      * @param string contents of the file
  777.      */
  778.     function Convert_RIC($name, $contents)
  779.     {
  780.         $template = &$this->newSmarty();
  781.         $template->assign('contents',$contents);
  782.         $template->assign('name',$name);
  783.         $this->setTargetDir($this->base_dir);
  784.         $this->writefile('ric_'.$name . '.html',$template->fetch('ric.tpl'));
  785.         $this->ric_set[$name] = true;
  786.     }
  787.     
  788.     function ConvertTodoList()
  789.     {
  790.         $todolist = array();
  791.         foreach($this->todoList as $package => $alltodos)
  792.         {
  793.             foreach($alltodos as $todos)
  794.             {
  795.                 $converted = array();
  796.                 $converted['link'] = $this->returnSee($todos[0]);
  797.                 if (!is_array($todos[1]))
  798.                 {
  799.                     $converted['todos'][] = $todos[1]->Convert($this);
  800.                 } else
  801.                 {
  802.                     foreach($todos[1] as $todo)
  803.                     {
  804.                         $converted['todos'][] = $todo->Convert($this);
  805.                     }
  806.                 }
  807.                 $todolist[$package][] = $converted;
  808.             }
  809.         }
  810.         $templ = &$this->newSmarty();
  811.         $templ->assign('todos',$todolist);
  812.         $templ->register_outputfilter('HTMLframes_outputfilter');
  813.         $this->setTargetDir($this->base_dir);
  814.         $this->writefile('todolist.html',$templ->fetch('todolist.tpl'));
  815.     }
  816.     
  817.     /**
  818.      * Create errors.html template file output
  819.      *
  820.      * This method takes all parsing errors and warnings and spits them out ordered by file and line number.
  821.      * @global ErrorTracker We'll be using it's output facility
  822.      */
  823.     function ConvertErrorLog()
  824.     {
  825.         global $phpDocumentor_errors;
  826.         $allfiles = array();
  827.         $files = array();
  828.         $warnings = $phpDocumentor_errors->returnWarnings();
  829.         $errors = $phpDocumentor_errors->returnErrors();
  830.         $template = &$this->newSmarty();
  831.         foreach($warnings as $warning)
  832.         {
  833.             $file = '##none';
  834.             $linenum = 'Warning';
  835.             if ($warning->file)
  836.             {
  837.                 $file = $warning->file;
  838.                 $allfiles[$file] = 1;
  839.                 $linenum .= ' on line '.$warning->linenum;
  840.             }
  841.             $files[$file]['warnings'][] = array('name' => $linenum, 'listing' => $warning->data);
  842.         }
  843.         foreach($errors as $error)
  844.         {
  845.             $file = '##none';
  846.             $linenum = 'Error';
  847.             if ($error->file)
  848.             {
  849.                 $file = $error->file;
  850.                 $allfiles[$file] = 1;
  851.                 $linenum .= ' on line '.$error->linenum;
  852.             }
  853.             $files[$file]['errors'][] = array('name' => $linenum, 'listing' => $error->data);
  854.         }
  855.         $i=1;
  856.         $af = array();
  857.         foreach($allfiles as $file => $num)
  858.         {
  859.             $af[$i++] = $file;
  860.         }
  861.         $allfiles = $af;
  862.         usort($allfiles,'strnatcasecmp');
  863.         $allfiles[0] = "Post-parsing";
  864.         foreach($allfiles as $i => $a)
  865.         {
  866.             $allfiles[$i] = array('file' => $a);
  867.         }
  868.         $out = array();
  869.         foreach($files as $file => $data)
  870.         {
  871.             if ($file == '##none') $file = 'Post-parsing';
  872.             $out[$file] = $data;
  873.         }
  874.         $template->assign("files",$allfiles);
  875.         $template->assign("all",$out);
  876.         $template->assign("title","phpDocumentor Parser Errors and Warnings");
  877.         $this->setTargetDir($this->base_dir);
  878.         $this->writefile("errors.html",$template->fetch('errors.tpl'));
  879.         unset($template);
  880.         phpDocumentor_out("\n\nTo view errors and warnings, look at ".$this->base_dir. PATH_DELIMITER . "errors.html\n");
  881.         flush();
  882.     }
  883.     
  884.     function getTutorialId($package,$subpackage,$tutorial,$id)
  885.     {
  886.         return $id;
  887.     }
  888.     
  889.     function getCData($value)
  890.     {
  891.         return '<pre>'.htmlentities($value).'</pre>';
  892.     }
  893.     
  894.     /**
  895.      * Converts package page and sets its package as used in {@link $package_pages}
  896.      * @param parserPackagePage
  897.      */
  898.     function convertPackagepage(&$element)
  899.     {
  900.         phpDocumentor_out("\n");
  901.         flush();
  902.         $this->package = $element->package;
  903.         $this->subpackage = '';
  904.         $contents = $element->Convert($this);
  905.         $this->package_pages[$element->package] = str_replace('{$subdir}','../',$contents);
  906.         phpDocumentor_out("\n");
  907.         flush();
  908.         $this->setTargetDir($this->base_dir . PATH_DELIMITER . $element->package);
  909.         $this->writeFile('package_'.$element->package.'.html',str_replace('{$subdir}','../',$contents));
  910.     }
  911.     
  912.     /**
  913.      * @param parserTutorial
  914.      */
  915.     function convertTutorial(&$element)
  916.     {
  917.         phpDocumentor_out("\n");
  918.         flush();
  919.         $template = &parent::convertTutorial($element);
  920.         $a = '../';
  921.         if ($element->subpackage) $a .= '../';
  922.         $template->assign('subdir',$a);
  923.         $template->register_outputfilter('HTMLframes_outputfilter');
  924.         $contents = $template->fetch('tutorial.tpl');
  925.         $a = '';
  926.         if ($element->subpackage) $a = PATH_DELIMITER . $element->subpackage;
  927.         phpDocumentor_out("\n");
  928.         flush();
  929.         $this->setTargetDir($this->base_dir . PATH_DELIMITER . $element->package . $a);
  930.         $this->writeFile('tutorial_'.$element->name.'.html',$contents);
  931.     }
  932.     
  933.     /**
  934.      * Converts class for template output
  935.      * @see prepareDocBlock(), generateChildClassList(), generateFormattedClassTree(), getFormattedConflicts()
  936.      * @see getFormattedInheritedMethods(), getFormattedInheritedVars()
  937.      * @param parserClass
  938.      */
  939.     function convertClass(&$element)
  940.     {
  941.         parent::convertClass($element);
  942.         $this->class_dir = $element->docblock->package;
  943.         if (!empty($element->docblock->subpackage)) $this->class_dir .= PATH_DELIMITER . $element->docblock->subpackage;
  944.         $a = '../';
  945.         if ($element->docblock->subpackage != '') $a = "../$a";
  946.         
  947.         $this->class_data->assign('subdir',$a);
  948.         $this->class_data->assign("title","Docs For Class " . $element->getName());
  949.         $this->class_data->assign("page",$element->getName() . '.html');
  950.     }
  951.  
  952.     /**
  953.      * Converts class variables for template output
  954.      * @see prepareDocBlock(), getFormattedConflicts()
  955.      * @param parserDefine
  956.      */
  957.     function convertVar(&$element)
  958.     {
  959.         parent::convertVar($element, array('var_dest' => $this->getId($element,false)));
  960.     }
  961.  
  962.     /**
  963.      * Converts class methods for template output
  964.      * @see prepareDocBlock(), getFormattedConflicts()
  965.      * @param parserDefine
  966.      */
  967.     function convertMethod(&$element)
  968.     {
  969.         parent::convertMethod($element, array('method_dest' => $this->getId($element,false)));
  970.     }
  971.     
  972.     /**
  973.      * Converts function for template output
  974.      * @see prepareDocBlock(), parserFunction::getFunctionCall(), getFormattedConflicts()
  975.      * @param parserFunction
  976.      */
  977.     function convertFunction(&$element)
  978.     {
  979.         $funcloc = $this->getId($this->addLink($element));
  980.         parent::convertFunction($element,array('function_dest' => $this->getId($element,false)));
  981.     }
  982.     
  983.     /**
  984.      * Converts include elements for template output
  985.      * @see prepareDocBlock()
  986.      * @param parserInclude
  987.      */
  988.     function convertInclude(&$element)
  989.     {
  990.         parent::convertInclude($element, array('include_file'    => '_'.strtr($element->getValue(),array('"' => '', "'" => '','.' => '_'))));
  991.     }
  992.     
  993.     /**
  994.      * Converts defines for template output
  995.      * @see prepareDocBlock(), getFormattedConflicts()
  996.      * @param parserDefine
  997.      */
  998.     function convertDefine(&$element)
  999.     {
  1000.         parent::convertDefine($element, array('define_link' => $this->getId($element,false)));
  1001.     }
  1002.     
  1003.     /**
  1004.      * Converts global variables for template output
  1005.      * @param parserGlobal
  1006.      */
  1007.     function convertGlobal(&$element)
  1008.     {
  1009.         parent::convertGlobal($element, array('global_link' => $this->getId($element,false)));
  1010.     }
  1011.     
  1012.     /**
  1013.      * converts procedural pages for template output
  1014.      * @see prepareDocBlock(), getClassesOnPage()
  1015.      * @param parserData
  1016.      */
  1017.     function convertPage(&$element)
  1018.     {
  1019.         parent::convertPage($element);
  1020.         $this->juststarted = true;
  1021.         $this->page_dir = $element->parent->package;
  1022.         if (!empty($element->parent->subpackage)) $this->page_dir .= PATH_DELIMITER . $element->parent->subpackage;
  1023.         // registering stuff on the template
  1024.         $this->page_data->assign("page",$this->getPageName($element) . '.html');
  1025.         $this->page_data->assign("title","Docs for page ".$element->parent->getFile());
  1026.     }
  1027.     
  1028.     function getPageName(&$element)
  1029.     {
  1030.         if (get_class($element) == 'parserpage') return '_'.$element->getName();
  1031.         return '_'.$element->parent->getName();
  1032.     }
  1033.  
  1034.     /**
  1035.      * returns an array containing the class inheritance tree from the root object to the class
  1036.      *
  1037.      * @param parserClass    class variable
  1038.      * @return array Format: array(root,child,child,child,...,$class)
  1039.      * @uses parserClass::getParentClassTree()
  1040.      */
  1041.     
  1042.     function generateFormattedClassTree($class)
  1043.     {
  1044.         $tree = $class->getParentClassTree($this);
  1045.         $out = '';
  1046.         if (count($tree) - 1)
  1047.         {
  1048.             $result = array($class->getName());
  1049.             $parent = $tree[$class->getName()];
  1050.             $distance[] = '';
  1051.             while ($parent)
  1052.             {
  1053.                 $subpackage = $parent->docblock->subpackage;
  1054.                 $package = $parent->docblock->package;
  1055.                 $x = $parent;
  1056.                 if (is_object($parent))
  1057.                 $x = $parent->getLink($this);
  1058.                 if (!$x) $x = $parent->getName();
  1059.                 $result[] = 
  1060.                     $x;
  1061.                 $distance[] =
  1062.                     "\n%s|\n" .
  1063.                     "%s--";
  1064.                 if (is_object($parent))
  1065.                 $parent = $tree[$parent->getName()];
  1066.                 elseif (isset($tree[$parent]))
  1067.                 $parent = $tree[$parent];
  1068.             }
  1069.             $nbsp = '   ';
  1070.             for($i=count($result) - 1;$i>=0;$i--)
  1071.             {
  1072.                 $my_nbsp = '';
  1073.                 for($j=0;$j<count($result) - $i;$j++) $my_nbsp .= $nbsp;
  1074.                 $distance[$i] = sprintf($distance[$i],$my_nbsp,$my_nbsp);
  1075.             }
  1076.             return array('classes'=>array_reverse($result),'distance'=>array_reverse($distance));
  1077.         } else
  1078.         {
  1079.             return array('classes'=>$class->getName(),'distance'=>array(''));
  1080.         }
  1081.     }
  1082.     
  1083.     /** @access private */
  1084.     function sortVar($a, $b)
  1085.     {
  1086.         return strnatcasecmp($a->getName(),$b->getName());
  1087.     }
  1088.     
  1089.     /** @access private */
  1090.     function sortMethod($a, $b)
  1091.     {
  1092.         if ($a->isConstructor) return -1;
  1093.         if ($b->isConstructor) return 1;
  1094.         return strnatcasecmp($a->getName(),$b->getName());
  1095.     }
  1096.  
  1097.     /**
  1098.      * returns a template-enabled array of class trees
  1099.      * 
  1100.      * @param    string    $package    package to generate a class tree for
  1101.      * @see $roots, HTMLConverter::getRootTree()
  1102.      */
  1103.     function generateFormattedClassTrees($package)
  1104.     {
  1105.         if (!isset($this->roots[$package])) return array();
  1106.         $roots = $trees = array();
  1107.         $roots = $this->roots[$package];
  1108.         for($i=0;$i<count($roots);$i++)
  1109.         {
  1110.             $trees[] = array('class' => $roots[$i],'class_tree' => "<ul>\n".$this->getRootTree($this->getSortedClassTreeFromClass($roots[$i],$package,''),$package)."</ul>\n");
  1111.         }
  1112.         return $trees;
  1113.     }
  1114.     
  1115.     /**
  1116.      * return formatted class tree for the Class Trees page
  1117.      *
  1118.      * @param array $tree output from {@link getSortedClassTreeFromClass()}
  1119.      * @see Classes::$definitechild, generateFormattedClassTrees()
  1120.      * @return string
  1121.      */
  1122.     function getRootTree($tree,$package)
  1123.     {
  1124.         if (!$tree) return '';
  1125.         $my_tree = '';
  1126.         $cur = '#root';
  1127.         $lastcur = array(false);
  1128.         $kids = array();
  1129.         $dopar = false;
  1130.         if ($tree[$cur]['parent'])
  1131.         {
  1132.             $dopar = true;
  1133.             if (!is_object($tree[$cur]['parent']))
  1134.             {
  1135. //                debug("parent ".$tree[$cur]['parent']." not found");
  1136.                 $my_tree .= '<li>' . $tree[$cur]['parent'] .'<ul>';
  1137.             }
  1138.             else
  1139.             {
  1140. //                        debug("parent ".$this->returnSee($tree[$cur]['parent'])." in other package");
  1141.                 $my_tree .= '<li>' . $this->returnSee($tree[$cur]['parent']);
  1142.                 if ($tree[$cur]['parent']->package != $package) $my_tree .= ' <b>(Different package)</b><ul>';
  1143.             }
  1144.         }
  1145.         do
  1146.         {
  1147. //            fancy_debug($cur,$lastcur,$kids);
  1148.             if (count($tree[$cur]['children']))
  1149.             {
  1150. //                debug("$cur has children");
  1151.                 if (!isset($kids[$cur]))
  1152.                 {
  1153. //                    debug("set $cur kids");
  1154.                     $kids[$cur] = 1;
  1155.                     $my_tree .= '<li>'.$this->returnSee($tree[$cur]['link']);
  1156.                     $my_tree .= '<ul>'."\n";
  1157.                 }
  1158.                 array_push($lastcur,$cur);
  1159.                 list(,$cur) = each($tree[$cur]['children']);
  1160. //                var_dump('listed',$cur);
  1161.                 if ($cur)
  1162.                 {
  1163.                     $cur = $cur['package'] . '#' . $cur['class'];
  1164. //                    debug("set cur to child $cur");
  1165. //                    $my_tree .= '<li>'.$this->returnSee($tree[$cur]['link']);
  1166.                     continue;
  1167.                 } else
  1168.                 {
  1169. //                    debug("end of children for $cur");
  1170.                     $cur = array_pop($lastcur);
  1171.                     $cur = array_pop($lastcur);
  1172.                     $my_tree .= '</ul></li>'."\n";
  1173.                     if ($dopar && ($cur == '#root' || !$cur)) $my_tree .= '</ul></li>';
  1174.                 }
  1175.             } else 
  1176.             {
  1177. //                debug("$cur has no children");
  1178.                 $my_tree .= '<li>'.$this->returnSee($tree[$cur]['link'])."</li>";
  1179.                 if ($dopar && $cur == '#root') $my_tree .= '</ul></li>';
  1180.                 $cur = array_pop($lastcur);
  1181.             }
  1182.         } while ($cur);
  1183.         return $my_tree;
  1184.     }
  1185.         /**
  1186.          * Generate indexing information for given element
  1187.          * 
  1188.          * @param parserElement descendant of parserElement
  1189.          * @see generateElementIndex()
  1190.          * @return array
  1191.          */
  1192.         function getIndexInformation($elt)
  1193.         {
  1194.             $Result['type'] = $elt->type;
  1195.             $Result['file_name'] = $elt->file;
  1196.             $Result['path'] = $elt->getPath();
  1197.             
  1198.             if (isset($elt->docblock))
  1199.                         {
  1200.                             $Result['description'] = $elt->docblock->getSDesc($this);
  1201.                             
  1202.                             if ($elt->docblock->hasaccess)
  1203.                                 $Result['access'] = $elt->docblock->tags['access'][0]->value;
  1204.                             else
  1205.                                 $Result['access'] = 'public';
  1206.  
  1207.                             $Result['abstract'] = isset ($elt->docblock->tags['abstract'][0]);
  1208.                         }
  1209.             else
  1210.                 $Result['description'] = '';
  1211.             
  1212.             $aa = $Result['description'];
  1213.             if (!empty($aa)) $aa = "<br>    $aa";
  1214.  
  1215.             switch($elt->type)
  1216.             {
  1217.                     case 'class':
  1218.                             $Result['name'] = $elt->getName();
  1219.                             $Result['title'] = 'Class';
  1220.                             $Result['link'] = $this->getClassLink($elt->getName(),
  1221.                                                                   $elt->docblock->package,
  1222.                                                                   $elt->getPath(),
  1223.                                                                   $elt->getName());
  1224.                             $Result['listing'] = 'in file '.$elt->file.', class '.$Result['link']."$aa";
  1225.                     break;
  1226.                     case 'define':
  1227.                             $Result['name'] = $elt->getName();
  1228.                             $Result['title'] = 'Constant';
  1229.                             $Result['link'] = $this->getDefineLink($elt->getName(),
  1230.                                                                    $elt->docblock->package,
  1231.                                                                    $elt->getPath(),
  1232.                                                                    $elt->getName());
  1233.                             $Result['listing'] = 'in file '.$elt->file.', constant '.$Result['link']."$aa";
  1234.                     break;
  1235.                     case 'global':
  1236.                             $Result['name'] = $elt->getName();
  1237.                             $Result['title'] = 'Global';
  1238.                             $Result['link'] = $this->getGlobalLink($elt->getName(),
  1239.                                                                    $elt->docblock->package,
  1240.                                                                    $elt->getPath(),
  1241.                                                                    $elt->getName());
  1242.                             $Result['listing'] = 'in file '.$elt->file.', global variable '.$Result['link']."$aa";
  1243.                     break;
  1244.                     case 'function':
  1245.                             $Result['name'] = $elt->getName();
  1246.                             $Result['title'] = 'Function';
  1247.                             $Result['link'] = $this->getFunctionLink($elt->getName(),
  1248.                                                                      $elt->docblock->package,
  1249.                                                                      $elt->getPath(),
  1250.                                                                      $elt->getName().'()');
  1251.                             $Result['listing'] = 'in file '.$elt->file.', function '.$Result['link']."$aa";
  1252.                     break;
  1253.                     case 'method':
  1254.                             $Result['name'] = $elt->getName();
  1255.                             $Result['title'] = 'Method';
  1256.                             $Result['link'] = $this->getMethodLink($elt->getName(),
  1257.                                                                    $elt->class,
  1258.                                                                    $elt->docblock->package,
  1259.                                                                    $elt->getPath(),
  1260.                                                                    $elt->class.'::'.$elt->getName().'()'
  1261.                                                                              );
  1262.                                                         if ($elt->isConstructor) $Result['constructor'] = 1;
  1263.                             $Result['listing'] = 'in file '.$elt->file.', method '.$Result['link']."$aa";
  1264.                     break;
  1265.                     case 'var':
  1266.                             $Result['name'] = $elt->getName();
  1267.                             $Result['title'] = 'Variable';
  1268.                             $Result['link'] = $this->getVarLink($elt->getName(),
  1269.                                                                 $elt->class,
  1270.                                                                 $elt->docblock->package,
  1271.                                                                 $elt->getPath(),
  1272.                                                                 $elt->class.'::'.$elt->getName());
  1273.                             $Result['listing'] = 'in file '.$elt->file.', variable '.$Result['link']."$aa";
  1274.                     break;
  1275.                     case 'page':
  1276.                             $Result['name'] = $elt->getFile();
  1277.                             $Result['title'] = 'Page';
  1278.                             $Result['link'] = $this->getPageLink($elt->getFile(),
  1279.                                                                  $elt->package,
  1280.                                                                  $elt->getPath(),
  1281.                                                                  $elt->getFile());
  1282.                             $Result['listing'] = 'procedural page '.$Result['link'];
  1283.                     break;
  1284.                     case 'include':
  1285.                             $Result['name'] = $elt->getName();
  1286.                             $Result['title'] = 'Include';
  1287.                             $Result['link'] = $elt->getValue();
  1288.                             $Result['listing'] = 'include '.$Result['name'];
  1289.                     break;
  1290.             }
  1291.  
  1292.             return $Result;
  1293.         }
  1294.     /**
  1295.      * Generate alphabetical index of all elements
  1296.      *
  1297.      * @see $elements, walk()
  1298.      */
  1299.     function generateElementIndex()
  1300.     {
  1301.         $elementindex = array();
  1302.         $letters = array();
  1303.         $used = array();
  1304.         foreach($this->elements as $letter => $nutoh)
  1305.         {
  1306.             foreach($this->elements[$letter] as $i => $yuh)
  1307.             {
  1308.                 if ($this->elements[$letter][$i]->type != 'include')
  1309.                 {
  1310.                     if (!isset($used[$letter]))
  1311.                     {
  1312.                         $letters[]['letter'] = $letter;
  1313.                         $elindex['letter'] = $letter;
  1314.                         $used[$letter] = 1;
  1315.                     }
  1316.  
  1317.                     $elindex['index'][] = $this->getIndexInformation($this->elements[$letter][$i]);
  1318.                 }
  1319.             }
  1320.             if (isset($elindex['index']))
  1321.             {
  1322.                 $elementindex[] = $elindex;
  1323.             } else
  1324.             {
  1325.                 unset($letters[count($letters) - 1]);
  1326.             }
  1327.             $elindex = array();
  1328.         }
  1329.         return array($elementindex,$letters);
  1330.     }
  1331.     
  1332.     function copyMediaRecursively($media,$targetdir,$subdir = '')
  1333.     {
  1334.         foreach($media as $dir => $files)
  1335.         {
  1336.             if ($dir === '/')
  1337.             {
  1338.                 $this->copyMediaRecursively($files,$targetdir);
  1339.             } else
  1340.             {
  1341.                 if (!is_numeric($dir))
  1342.                 {
  1343.                     // create the subdir
  1344.                     phpDocumentor_out("creating $targetdir/$dir\n");
  1345.                     Converter::setTargetDir($targetdir . PATH_DELIMITER . $dir);
  1346.                     if (!empty($subdir)) $subdir .= PATH_DELIMITER;
  1347.                     $this->copyMediaRecursively($files,"$targetdir/$dir",$subdir . $dir);
  1348.                 } else
  1349.                 {
  1350.                     // copy the file
  1351.                     phpDocumentor_out("copying $targetdir/".$files['file']."\n");
  1352.                     $this->copyFile($files['file'],$subdir);
  1353.                 }
  1354.             }
  1355.         }
  1356.     }
  1357.     
  1358.     /**
  1359.      * calls the converter setTargetDir, and then copies any template images and the stylesheet if they haven't been copied
  1360.      * @see Converter::setTargetDir()
  1361.      */
  1362.     function setTargetDir($dir)
  1363.     {
  1364.         Converter::setTargetDir($dir);
  1365.         if ($this->wrote) return;
  1366.         $this->wrote = true;
  1367.         $template_images = array();
  1368.         $stylesheets = array();
  1369.         $tdir = $dir;
  1370.         $dir = $this->templateDir;
  1371.         $this->templateDir = $this->templateDir.'templates/';
  1372.         $info = new Io;
  1373.         $this->copyMediaRecursively($info->getDirTree($this->templateDir.'media',$this->templateDir),$tdir);
  1374.     }
  1375.     
  1376.     /**
  1377.      * Generate alphabetical index of all elements by package and subpackage
  1378.      *
  1379.      * @param string $package name of a package
  1380.      * @see $pkg_elements, walk(), generatePkgElementIndexes()
  1381.      */
  1382.     function generatePkgElementIndex($package)
  1383.     {
  1384. //        var_dump($this->pkg_elements[$package]);
  1385.         $elementindex = array();
  1386.         $letters = array();
  1387.         $letterind = array();
  1388.         $used = array();
  1389.         $subp = '';
  1390.         foreach($this->pkg_elements[$package] as $subpackage => $els)
  1391.         {
  1392.             if (empty($els)) continue;
  1393.             if (!empty($subpackage)) $subp = " (<b>subpackage:</b> $subpackage)"; else $subp = '';
  1394.             foreach($els as $letter => $yuh)
  1395.             {
  1396.                 foreach($els[$letter] as $i => $yuh)
  1397.                 {
  1398.                     if ($els[$letter][$i]->type != 'include')
  1399.                     {
  1400.                         if (!isset($used[$letter]))
  1401.                         {
  1402.                             $letters[]['letter'] = $letter;
  1403.                             $letterind[$letter] = count($letters) - 1;
  1404.                             $used[$letter] = 1;
  1405.                         }
  1406.                         $elindex[$letter]['letter'] = $letter;
  1407.  
  1408.                         $elindex[$letter]['index'][] = $this->getIndexInformation($els[$letter][$i]);
  1409.                     }
  1410.                 }
  1411.             }
  1412.         }
  1413.         ksort($elindex);
  1414.         usort($letters,'HTMLframes_lettersort');
  1415.         if (isset($elindex))
  1416.         {
  1417.             while(list($letter,$tempel) = each($elindex))
  1418.             {
  1419.                 if (!isset($tempel))
  1420.                 {
  1421.                     unset($letters[$letterind[$tempel['letter']]]);
  1422.                 } else
  1423.                 $elementindex[] = $tempel;
  1424.             }
  1425.         } else $letters = array();
  1426.         return array($elementindex,$letters);
  1427.     }
  1428.     
  1429.     /**
  1430.      *
  1431.      * @see generatePkgElementIndex()
  1432.      */
  1433.     function generatePkgElementIndexes()
  1434.     {
  1435.         $packages = array();
  1436.         $package_names = array();
  1437.         $pkg = array();
  1438.         $letters = array();
  1439.         foreach($this->pkg_elements as $package => $trash)
  1440.         {
  1441.             $pkgs['package'] = $package;
  1442.             $pkg['package'] = $package;
  1443.             list($pkg['pindex'],$letters[$package]) = $this->generatePkgElementIndex($package);
  1444.             if (count($pkg['pindex']))
  1445.             {
  1446.                 $packages[] = $pkg;
  1447.                 $package_names[] = $pkgs;
  1448.             }
  1449.             unset($pkgs);
  1450.             unset($pkg);
  1451.         }
  1452.         foreach($packages as $i => $package)
  1453.         {
  1454.             $pnames = array();
  1455.             for($j=0;$j<count($package_names);$j++)
  1456.             {
  1457.                 if ($package_names[$j]['package'] != $package['package']) $pnames[] = $package_names[$j];
  1458.             }
  1459.             $packages[$i]['packageindexes'] = $pnames;
  1460.         }
  1461.         return array($packages,$package_names,$letters);
  1462.     }
  1463.     
  1464.     /**
  1465.      * @param string name of class
  1466.      * @param string package name
  1467.      * @param string full path to look in (used in index generation)
  1468.      * @param boolean deprecated
  1469.      * @param boolean return just the URL, or enclose it in an html a tag
  1470.      * @return mixed false if not found, or an html a link to the class's documentation
  1471.      * @see parent::getClassLink()
  1472.      */
  1473.     function getClassLink($expr,$package, $file = false,$text = false, $with_a = true)
  1474.     {
  1475.         $a = Converter::getClassLink($expr,$package,$file);
  1476.         if (!$a) return false;
  1477.         return $this->returnSee($a, $text, $with_a);
  1478.     }
  1479.  
  1480.     /**
  1481.      * @param string name of function
  1482.      * @param string package name
  1483.      * @param string full path to look in (used in index generation)
  1484.      * @param boolean deprecated
  1485.      * @param boolean return just the URL, or enclose it in an html a tag
  1486.      * @return mixed false if not found, or an html a link to the function's documentation
  1487.      * @see parent::getFunctionLink()
  1488.      */
  1489.     function getFunctionLink($expr,$package, $file = false,$text = false)
  1490.     {
  1491.         $a = Converter::getFunctionLink($expr,$package,$file);
  1492.         if (!$a) return false;
  1493.         return $this->returnSee($a, $text);
  1494.     }
  1495.  
  1496.     /**
  1497.      * @param string name of define
  1498.      * @param string package name
  1499.      * @param string full path to look in (used in index generation)
  1500.      * @param boolean deprecated
  1501.      * @param boolean return just the URL, or enclose it in an html a tag
  1502.      * @return mixed false if not found, or an html a link to the define's documentation
  1503.      * @see parent::getDefineLink()
  1504.      */
  1505.     function getDefineLink($expr,$package, $file = false,$text = false)
  1506.     {
  1507.         $a = Converter::getDefineLink($expr,$package,$file);
  1508.         if (!$a) return false;
  1509.         return $this->returnSee($a, $text);
  1510.     }
  1511.  
  1512.     /**
  1513.      * @param string name of global variable
  1514.      * @param string package name
  1515.      * @param string full path to look in (used in index generation)
  1516.      * @param boolean deprecated
  1517.      * @param boolean return just the URL, or enclose it in an html a tag
  1518.      * @return mixed false if not found, or an html a link to the global variable's documentation
  1519.      * @see parent::getGlobalLink()
  1520.      */
  1521.     function getGlobalLink($expr,$package, $file = false,$text = false)
  1522.     {
  1523.         $a = Converter::getGlobalLink($expr,$package,$file);
  1524.         if (!$a) return false;
  1525.         return $this->returnSee($a, $text);
  1526.     }
  1527.  
  1528.     /**
  1529.      * @param string name of procedural page
  1530.      * @param string package name
  1531.      * @param string full path to look in (used in index generation)
  1532.      * @param boolean deprecated
  1533.      * @param boolean return just the URL, or enclose it in an html a tag
  1534.      * @return mixed false if not found, or an html a link to the procedural page's documentation
  1535.      * @see parent::getPageLink()
  1536.      */
  1537.     function getPageLink($expr,$package, $path = false,$text = false)
  1538.     {
  1539.         $a = Converter::getPageLink($expr,$package,$path);
  1540.         if (!$a) return false;
  1541.         return $this->returnSee($a, $text);
  1542.     }
  1543.  
  1544.     /**
  1545.      * @param string name of method
  1546.      * @param string class containing method
  1547.      * @param string package name
  1548.      * @param string full path to look in (used in index generation)
  1549.      * @param boolean deprecated
  1550.      * @param boolean return just the URL, or enclose it in an html a tag
  1551.      * @return mixed false if not found, or an html a link to the method's documentation
  1552.      * @see parent::getMethodLink()
  1553.      */
  1554.     function getMethodLink($expr,$class,$package, $file = false,$text = false)
  1555.     {
  1556.         $a = Converter::getMethodLink($expr,$class,$package,$file);
  1557.         if (!$a) return false;
  1558.         return $this->returnSee($a, $text);
  1559.     }
  1560.  
  1561.     /**
  1562.      * @param string name of var
  1563.      * @param string class containing var
  1564.      * @param string package name
  1565.      * @param string full path to look in (used in index generation)
  1566.      * @param boolean deprecated
  1567.      * @param boolean return just the URL, or enclose it in an html a tag
  1568.      * @return mixed false if not found, or an html a link to the var's documentation
  1569.      * @see parent::getVarLink()
  1570.      */
  1571.     function getVarLink($expr,$class,$package, $file = false,$text = false)
  1572.     {
  1573.         $a = Converter::getVarLink($expr,$class,$package,$file);
  1574.         if (!$a) return false;
  1575.         return $this->returnSee($a, $text);
  1576.     }
  1577.     
  1578.     /**
  1579.      * does a nat case sort on the specified second level value of the array
  1580.      *
  1581.      * @param    mixed    $a
  1582.      * @param    mixed    $b
  1583.      * @return    int
  1584.      */
  1585.     function rcNatCmp ($a, $b)
  1586.     {
  1587.         $aa = strtoupper($a[$this->rcnatcmpkey]);
  1588.         $bb = strtoupper($b[$this->rcnatcmpkey]);
  1589.         
  1590.         return strnatcasecmp($aa, $bb);
  1591.     }
  1592.     
  1593.     /**
  1594.      * does a nat case sort on the specified second level value of the array.
  1595.      * this one puts constructors first
  1596.      *
  1597.      * @param    mixed    $a
  1598.      * @param    mixed    $b
  1599.      * @return    int
  1600.      */
  1601.     function rcNatCmp1 ($a, $b)
  1602.     {
  1603.         $aa = strtoupper($a[$this->rcnatcmpkey]);
  1604.         $bb = strtoupper($b[$this->rcnatcmpkey]);
  1605.         
  1606.         if (strpos($aa,'CONSTRUCTOR') === 0)
  1607.         {
  1608.             return -1;
  1609.         }
  1610.         if (strpos($bb,'CONSTRUCTOR') === 0)
  1611.         {
  1612.             return 1;
  1613.         }
  1614.         if (strpos($aa,strtoupper($this->class)) === 0)
  1615.         {
  1616.             return -1;
  1617.         }
  1618.         if (strpos($bb,strtoupper($this->class)) === 0)
  1619.         {
  1620.             return -1;
  1621.         }
  1622.         return strnatcasecmp($aa, $bb);
  1623.     }
  1624.     
  1625.     /**
  1626.      * This function is not used by HTMLdefaultConverter, but is required by Converter
  1627.      */
  1628.     function Output()
  1629.     {
  1630.     }
  1631. }
  1632.  
  1633. /**
  1634.  * @access private
  1635.  * @global string name of the package to set as the first package
  1636.  */
  1637. function HTMLframes_pindexcmp($a, $b)
  1638. {
  1639.     global $phpDocumentor_DefaultPackageName;
  1640.     if ($a['title'] == $phpDocumentor_DefaultPackageName) return -1;
  1641.     if ($b['title'] == $phpDocumentor_DefaultPackageName) return 1;
  1642.     return strnatcasecmp($a['title'],$b['title']);
  1643. }
  1644.  
  1645. /** @access private */
  1646. function HTMLframes_lettersort($a, $b)
  1647. {
  1648.     return strnatcasecmp($a['letter'],$b['letter']);
  1649. }
  1650.  
  1651. /** @access private */
  1652. function HTMLframes_outputfilter($src, &$smarty)
  1653. {
  1654.     return str_replace('{$subdir}',$smarty->_tpl_vars['subdir'],$src);
  1655. }
  1656. ?>
  1657.