home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / PDFdefaultConverter.inc < prev    next >
Encoding:
Text File  |  2004-03-24  |  36.2 KB  |  913 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.  * @package Converters
  21.  * @subpackage PDFdefault
  22.  */
  23. /**
  24.  * The Cezpdf class library
  25.  */
  26. include_once('phpDocumentor/Converters/PDF/default/class.phpdocpdf.php');
  27. /**
  28.  * PDF output converter.
  29.  * This Converter takes output from the {@link Parser} and converts it to PDF-ready output for use with {@link Cezpdf}.
  30.  * This is now beta code
  31.  *
  32.  * @package Converters
  33.  * @subpackage PDFdefault
  34.  * @author Greg Beaver <cellog@users.sourceforge.net>
  35.  * @since 1.1
  36.  * @version $Id: PDFdefaultConverter.inc,v 1.43.2.7 2003/07/29 07:28:12 CelloG Exp $
  37.  * @todo Implement links to conflicts/inheritance
  38.  */
  39. class PDFdefaultConverter extends Converter
  40. {
  41.     /**
  42.      * default PDF Converter wants elements sorted by type as well as alphabetically
  43.      * @see Converter::$sort_page_contents_by_type
  44.      * @var boolean
  45.      */
  46.     var $sort_absolutely_everything = true;
  47.     var $leftindex = array('classes' => false, 'pages' => false, 'functions' => false, 'defines' => false, 'globals' => false);
  48.     var $pagepackage_pagenums = array();
  49.     var $classpackage_pagenums = array();
  50.     /** @var string always PDF */
  51.     var $outputformat = 'PDF';
  52.     /** @var string always default */
  53.     var $name = 'default';
  54.     var $curpagepackage = false;
  55.     var $curclasspackage = false;
  56.     var $smarty_dir;
  57.     /**
  58.      * @var Cezpdf
  59.      */
  60.     var $pdf = false;
  61.     var $ric_set = array();
  62.     /**
  63.      * Source files for appendix C are stored here
  64.      *
  65.      * Format: array(array(package => packagename, code => array(highlightedsource code 1, ...)))
  66.      * @var array
  67.      */
  68.     var $_sourcecode;
  69.     /**
  70.      * @see Converter::Converter()
  71.      */
  72.     function PDFdefaultConverter(&$allp, &$packp, &$classes, &$procpages, $po, $pp, $qm, $targetDir, $templateDir, $title)
  73.     {
  74.         Converter::Converter($allp, $packp, $classes, $procpages, $po, $pp, $qm, $targetDir, $templateDir, $title);
  75.         $this->pdf =& new phpdocpdf($this, $this->getConverterDir() . PATH_DELIMITER .'templates/fonts/','letter');
  76.         $this->pdf->selectFont($this->getConverterDir() . PATH_DELIMITER .'templates/fonts/Helvetica.afm');
  77. // put a line top and bottom on all the pages
  78.         $this->pdf->ezSetMargins(50,70,50,50);
  79.         $template = &$this->newSmarty();
  80.         $this->pdf->ezText($template->fetch('footer.tpl'));
  81.         $template->assign('title',$title);
  82.         if (file_exists($this->templateDir . 'templates' . PATH_DELIMITER . 'media'. PATH_DELIMITER .'logo.jpg'))
  83.         {
  84.             $template->assign('logo',$this->templateDir . 'templates' . PATH_DELIMITER . 'media'. PATH_DELIMITER .'logo.jpg');
  85.         }
  86.         $this->pdf->ezText($template->fetch('title_page.tpl'));
  87.         unset($template);
  88.     }
  89.     
  90.     function writeSource($path, $value)
  91.     {
  92.         $templ = &$this->newSmarty();
  93.         $pathinfo = $this->proceduralpages->getPathInfo($path, $this);
  94.         $templ->assign('source',$value);
  95.         $templ->assign('package',$pathinfo['package']);
  96.         $templ->assign('subpackage',$pathinfo['subpackage']);
  97.         $templ->assign('name',$pathinfo['name']);
  98.         $templ->assign('source_loc',$pathinfo['source_loc']);
  99.         $templ->assign('docs',$pathinfo['docs']);
  100.         $templ->assign('dest', $this->getFileSourceName($path));
  101.         $this->setSourcePaths($path);
  102.         $this->_sourcecode[$pathinfo['package']][] = $templ->fetch('filesource.tpl');
  103.     }
  104.     
  105.     function postProcess($text)
  106.     {
  107.         return htmlspecialchars($text);
  108.     }
  109.     
  110.     function writeExample($title, $path, $source)
  111.     {
  112.         $templ = &$this->newSmarty();
  113.         $templ->assign('source',$source);
  114.         if (empty($title))
  115.         {
  116.             $title = 'example';
  117.             addWarning(PDERROR_EMPTY_EXAMPLE_TITLE, $path, $title);
  118.         }
  119.         $templ->assign('title',$title);
  120.         $templ->assign('file',$path);
  121.         $this->pdf->ezText($templ->fetch('examplesource.tpl'));
  122.     }
  123.     
  124.     function getExampleLink($path, $title)
  125.     {
  126.         return '';
  127.         return $this->returnLink('{$subdir}__examplesource' . PATH_DELIMITER . 'exsource_'.$path.'.html',$title);
  128.     }
  129.     
  130.     function getSourceLink($path)
  131.     {
  132. //        var_dump(htmlentities('<c:ilink:'.$this->getFileSourceName($path).'>Source Code for this file</c:ilink>'));
  133.         return '<c:ilink:'.$this->getFileSourceName($path).'>Source Code for this file</c:ilink>';
  134.     }
  135.     
  136.     function getFileSourceName($path, $anchor = '')
  137.     {
  138.         return urlencode($anchor . parent::getFileSourceName($path));
  139.     }
  140.     
  141.     /**
  142.      * Retrieve a Converter-specific anchor to a segment of a source code file
  143.      * parsed via a {@tutorial tags.filesource.pkg} tag.
  144.      * @param string full path to source file
  145.      * @param string name of anchor
  146.      * @param string link text, if this is a link
  147.      * @param boolean returns either a link or a destination based on this
  148.      *                parameter
  149.      * @return string link to an anchor, or the anchor
  150.      */
  151.     function getSourceAnchor($sourcefile,$anchor,$text = '',$link = false)
  152.     {
  153.         if ($link)
  154.         {
  155.             return '<c:ilink:' . $this->getFileSourceName($sourcefile, $anchor). '>' . $text . '</c:ilink>';
  156.         } else
  157.         {
  158.             return '</text><pdffunction:addDestination arg="'.$this->getFileSourceName($sourcefile, $anchor).'" arg="FitH" arg=$this->y /><text size="8">';
  159.         }
  160.     }
  161.     
  162.     /**
  163.      * Returns a bookmark using Cezpdf 009
  164.      *
  165.      * @param abstractLink a descendant of abstractlink should be passed, and never text
  166.      * @param string text to display in the link
  167.      */
  168.     function returnSee(&$element, $eltext = false)
  169.     {
  170.         if (!$element) return false;
  171.         if (!$eltext)
  172.         {
  173.             $eltext = '';
  174.             switch($element->type)
  175.             {
  176.                 case 'tutorial' :
  177.                 $eltext = $element->title;
  178.                 break;
  179.                 case 'method' :
  180.                 case 'var' :
  181.                 $eltext .= $element->class.'::';
  182.                 case 'page' :
  183.                 case 'define' :
  184.                 case 'class' :
  185.                 case 'function' :
  186.                 case 'global' :
  187.                 default :
  188.                 $eltext .= $element->name;
  189.                 if ($element->type == 'function' || $element->type == 'method') $eltext .= '()';
  190.                 break;
  191.             }
  192.         }
  193.         switch ($element->type)
  194.         {
  195.             case 'tutorial' :
  196.             return '<c:ilink:'.urlencode($element->type.$element->package.$element->subpackage.$element->name.$element->section).'>'.$eltext.'</c:ilink>';
  197.             case 'page' :
  198.             return '<c:ilink:'.urlencode($element->type.$element->package.$element->path).'>'.$eltext.'</c:ilink>';
  199.             case 'define' :
  200.             case 'global' :
  201.             case 'class' :
  202.             case 'function' :
  203.             return '<c:ilink:'.urlencode($element->type.$element->package.$element->name).'>'.$eltext.'</c:ilink>';
  204.             case 'method' :
  205.             case 'var' :
  206.             return '<c:ilink:'.urlencode($element->type.$element->package.$element->class.'::'.$element->name).'>'.$eltext.'</c:ilink>';
  207.         }
  208.         return $element;
  209.     }
  210.     
  211.     /**
  212.      * @param string
  213.      * @param string
  214.      * @return string <c:alink:$link>$text</c:alink>
  215.      */
  216.     function returnLink($link,$text)
  217.     {
  218.         return "<c:alink:$link>$text</c:alink>";
  219.     }
  220.     
  221.     /**
  222.      * Convert README/INSTALL/CHANGELOG file contents to output format
  223.      * @param README|INSTALL|CHANGELOG
  224.      * @param string contents of the file
  225.      */
  226.     function Convert_RIC($name, $contents)
  227.     {
  228.         $this->ric_set[$name] = $contents;
  229.     }
  230.  
  231.     function convertDocBlock(&$element)
  232.     {
  233.         if (!$element->docblock) return;
  234.         $template = &$this->newSmarty();
  235.         
  236.         $nopackage = true;
  237.         if ($element->type == 'page' || $element->type == 'class') $nopackage = false;
  238.         $tagses = $element->docblock->listTags();
  239.         $tags = array();
  240.         $names = array('staticvar' => 'Static Variable','deprec' => 'Deprecated','abstract' => 'Abstract Element','todo' => 'TODO');
  241.         if (!$nopackage)
  242.         {
  243.             $tags[] = array('keyword' => 'Package','data' => $element->docblock->package);
  244.             if (!empty($element->docblock->subpackage)) $tags[] = array('keyword' => 'Sub-Package','data' => $element->docblock->subpackage);
  245.         }
  246.         if ($element->docblock->var)
  247.         {
  248.             $a = $element->docblock->var->Convert($this);
  249.             if (!empty($a))
  250.             $tags[] = array('keyword' => 'Var', 'data' => $a);
  251.         }
  252.         if ($element->docblock->funcglobals)
  253.         foreach($element->docblock->funcglobals as $global => $val)
  254.         {
  255.             if ($a = $this->getGlobalLink($global,$element->docblock->package))
  256.             {
  257.                 $global = $a;
  258.             }
  259.             $b = Converter::getLink($val[0]);
  260.             if (is_object($b) && get_class($b) == 'classlink')
  261.             {
  262.                 $val[0] = $this->returnSee($b);
  263.             }
  264.             $tags[] = array('keyword' => 'Global Variable Used','data' => $val[0].' '.$global.': '.$val[1]->Convert($this));
  265.         }
  266.         if ($element->docblock->statics)
  267.         foreach($element->docblock->statics as $static => $val)
  268.         {
  269.             $a = $val->Convert($this);
  270.             $tags[] = array('keyword' => 'Static Variable Used','data' => $val->converted_returnType.' '.$static.': '.$a);
  271.         }
  272.         foreach($tagses as $tag)
  273.         {
  274.             if (isset($names[$tag->keyword])) $tag->keyword = $names[$tag->keyword];
  275.             $tags[] = array("keyword" => ucfirst($tag->keyword),"data" => $tag->Convert($this));
  276.         }
  277.         $utags = array();
  278.         foreach($element->docblock->unknown_tags as $keyword => $t)
  279.         {
  280.             foreach($t as $tag)
  281.             $utags[] = array('keyword' => $keyword, 'data' => $tag->Convert($this));
  282.         }
  283.         if ($element->type == 'packagepage') return;
  284.         $sdesc = $element->docblock->getSDesc($this);
  285.         $desc = $element->docblock->getDesc($this);
  286.         $template->assign('utags',$utags);
  287.         $template->assign('tags',$tags);
  288.         $template->assign('sdesc',$sdesc);
  289.         $template->assign('desc',$desc);
  290.         if (false) // $element->type != 'page')
  291.         {
  292.             if ($element->type != 'var' && $element->type != 'method')
  293.             {
  294.                 $this->pdf->addDestination(urlencode($element->type.$element->docblock->package.$element->name),'FitH',$this->pdf->y);
  295.             } else
  296.             {
  297.                 $this->pdf->addDestination(urlencode($element->type.$element->docblock->package.$element->class.'::'.$element->name),'FitH',$this->pdf->y);
  298.             }
  299.         } elseif (false)
  300.         {
  301.             $this->pdf->addDestination(urlencode('page'.$element->parent->package.$element->parent->getPath()),'FitH',$this->pdf->y);
  302.         }
  303.         $this->convertParams($element);
  304.         $this->pdf->ezText($template->fetch('docblock.tpl'));
  305.     }
  306.     
  307.     function convertParams(&$element)
  308.     {
  309.         if ($element->type != 'function' && $element->type != 'method') return;
  310.         if (count($element->docblock->params))
  311.         {
  312.             $template = &$this->newSmarty();
  313.             $params = array();
  314.             if (count($element->docblock->params))
  315.             foreach($element->docblock->params as $param => $val)
  316.             {
  317.                 $a = $val->Convert($this);
  318.                 $params[] = array("name" => $param,"type" => $val->converted_returnType,"description" => $a);
  319.             }
  320.             $template->assign('params',$params);
  321.             $this->pdf->ezText($template->fetch('params.tpl'));
  322.         }
  323.     }
  324.     
  325.     function convertGlobal(&$element)
  326.     {
  327.         $sdesc = '';
  328.         if ($element->docblock->sdesc)
  329.         {
  330.             $sdesc = $element->docblock->sdesc->Convert($this);
  331.         }
  332.         $template = &$this->newSmarty();
  333.         $template->assign('linenumber',$element->getLineNumber());
  334.         if ($this->hasSourceCode($element->getPath()))
  335.         $template->assign('slink',$this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true));
  336.         else
  337.         $template->assign('slink', false);
  338.         $template->assign('dest', urlencode($element->type.$element->docblock->package.$element->name));
  339.         $template->assign('type',$element->getDataType($this));
  340.         $template->assign('name',$element->name);
  341.         $template->assign('value',$this->getGlobalValue($element->getValue()));
  342.         $template->assign('sdesc',$sdesc);
  343.         $this->pdf->ezText($template->fetch('global.tpl'));
  344.         $this->convertDocBlock($element);
  345.     }
  346.     
  347.     function getGlobalValue($value)
  348.     {
  349.         return parent::getGlobalValue(htmlspecialchars($value));
  350.     }
  351.     
  352.     function convertMethod(&$element)
  353.     {
  354.         $sdesc = '';
  355.         if ($element->docblock->sdesc)
  356.         {
  357.             $sdesc = $element->docblock->sdesc->Convert($this);
  358.         }
  359.         $params = array();
  360.         if (count($element->docblock->params))
  361.         foreach($element->docblock->params as $param => $val)
  362.         {
  363.             $a = $val->Convert($this);
  364.             $params[$param] = array("var" => $param,"datatype" => $val->converted_returnType,"data" => $a);
  365.         }
  366.         if ($element->docblock->return)
  367.         {
  368.             if (!$element->docblock->return->returnType) $element->docblock->return->returnType = 'void';
  369.         }
  370.         $template = &$this->newSmarty();
  371.         $template->assign('class',$this->class);
  372.         $template->assign('constructor',$element->isConstructor);
  373.         $template->assign('dest', urlencode($element->type.$element->docblock->package.$element->class.'::'.$element->name));
  374.         $template->assign('linenumber',$element->getLineNumber());
  375.         if ($this->hasSourceCode($element->getPath()))
  376.         $template->assign('slink',$this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true));
  377.         else
  378.         $template->assign('slink',false);
  379.         $template->assign('return',$element->docblock->return->returnType);
  380.         $template->assign('functioncall',$element->getFunctionCall());
  381.         $template->assign('intricatefunctioncall',$element->getIntricateFunctionCall($this,$params));
  382.         $template->assign('sdesc',$sdesc);
  383.         $this->pdf->ezText($template->fetch('method.tpl'));
  384.         $this->convertDocBlock($element);
  385.     }
  386.     
  387.     function convertVar(&$element)
  388.     {
  389.         $sdesc = '';
  390.         if ($element->docblock->sdesc)
  391.         {
  392.             $sdesc = $element->docblock->sdesc->Convert($this);
  393.         }
  394.         $template = &$this->newSmarty();
  395.         $template->assign('class',$this->class);
  396.         $template->assign('linenumber',$element->getLineNumber());
  397.         if ($this->hasSourceCode($element->getPath()))
  398.         $template->assign('slink',$this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true));
  399.         else
  400.         $template->assign('slink',false);
  401.         $template->assign('type',$element->docblock->var->returnType);
  402.         $template->assign('name',$element->name);
  403.         $template->assign('dest', urlencode($element->type.$element->docblock->package.$element->class.'::'.$element->name));
  404.         $template->assign('value',$element->value);
  405.         $template->assign('sdesc',$sdesc);
  406.         $this->pdf->ezText($template->fetch('var.tpl'));
  407.         $this->convertDocBlock($element);
  408.     }
  409.     
  410.     function convertClass(&$element)
  411.     {
  412.         $template = &$this->newSmarty();
  413.         if ($this->curclasspackage != $element->docblock->package)
  414.         {
  415.             $template->assign('includeheader',true);
  416.             if (isset($this->package_pages[$element->docblock->package]))
  417.             {
  418.                 $template->assign('ppage',$this->package_pages[$element->docblock->package]);
  419.                 $template->assign('isclass',true);
  420.                 unset($this->package_pages[$element->docblock->package]);
  421.             }
  422.             $template->assign('classeslink',rawurlencode("Package ".$element->docblock->package." Classes"));
  423.         }
  424.         $sdesc = '';
  425.         if ($element->docblock->sdesc)
  426.         {
  427.             $sdesc = $element->docblock->sdesc->Convert($this);
  428.         }
  429.         $this->curclasspackage = $element->docblock->package;
  430.         $template->assign('dest', urlencode($element->type.$element->docblock->package.$element->name));
  431.         $template->assign('package',$element->docblock->package);
  432.         $template->assign('linenumber',$element->getLineNumber());
  433.         if ($this->hasSourceCode($element->getPath()))
  434.         $template->assign('slink',$this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true));
  435.         else
  436.         $template->assign('slink',false);
  437.         $template->assign('name',$element->name);
  438.         $template->assign('sdesc',$sdesc);
  439.         $this->pdf->ezText($template->fetch('class.tpl'));
  440.         $this->convertDocBlock($element);
  441.     }
  442.     
  443.     function convertInclude(&$element)
  444.     {
  445.         $template = &$this->newSmarty();
  446.         $template->assign('linenumber',$element->getLineNumber());
  447.         if ($this->hasSourceCode($element->getPath()))
  448.         $template->assign('slink',$this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true));
  449.         else
  450.         $template->assign('slink',false);
  451.         $template->assign('name',$element->name);
  452.         $template->assign('value',$this->getIncludeValue($element->getValue(), $element->getPath()));
  453.         $this->pdf->ezText($template->fetch('include.tpl'));
  454.         $this->convertDocBlock($element);
  455.     }
  456.     
  457.     function convertFunction(&$element)
  458.     {
  459.         $sdesc = '';
  460.         if ($element->docblock->sdesc)
  461.         {
  462.             $sdesc = $element->docblock->sdesc->Convert($this);
  463.         }
  464.         $params = array();
  465.         if (count($element->docblock->params))
  466.         foreach($element->docblock->params as $param => $val)
  467.         {
  468.             $a = $val->Convert($this);
  469.             $params[$param] = array("var" => $param,"datatype" => $val->converted_returnType,"data" => $a);
  470.         }
  471.         if ($element->docblock->return)
  472.         {
  473.             if (!$element->docblock->return->returnType) $element->docblock->return->returnType = 'void';
  474.         }
  475.         $template = &$this->newSmarty();
  476.         $template->assign('dest', urlencode($element->type.$element->docblock->package.$element->name));
  477.         $template->assign('linenumber',$element->getLineNumber());
  478.         if ($this->hasSourceCode($element->getPath()))
  479.         $template->assign('slink',$this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true));
  480.         else
  481.         $template->assign('slink',false);
  482.         $template->assign('return',$element->docblock->return->returnType);
  483.         $template->assign('functioncall',$element->getFunctionCall());
  484.         $template->assign('intricatefunctioncall',$element->getIntricateFunctionCall($this,$params));
  485.         $template->assign('sdesc',$sdesc);
  486.         $this->pdf->ezText($template->fetch('function.tpl'));
  487.         $this->convertDocBlock($element);
  488.     }
  489.     
  490.     function convertDefine(&$element)
  491.     {
  492.         $sdesc = '';
  493.         if ($element->docblock->sdesc)
  494.         {
  495.             $sdesc = $element->docblock->sdesc->Convert($this);
  496.         }
  497.         $template = &$this->newSmarty();
  498.         $template->assign('linenumber',$element->getLineNumber());
  499.         if ($this->hasSourceCode($element->getPath()))
  500.         $template->assign('slink',$this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true));
  501.         else
  502.         $template->assign('slink',false);
  503.         $template->assign('name',$element->name);
  504.         $template->assign('dest', urlencode($element->type.$element->docblock->package.$element->name));
  505.         $template->assign('value',$element->value);
  506.         $template->assign('sdesc',$sdesc);
  507.         $this->pdf->ezText($template->fetch('define.tpl'));
  508.         $this->convertDocBlock($element);
  509.     }
  510.     
  511.     function convertPage(&$element)
  512.     {
  513.         $template = &$this->newSmarty();
  514.         $template->assign('includeheader',false);
  515.         $sdesc = '';
  516.         if ($element->docblock->sdesc)
  517.         {
  518.             $sdesc = $element->docblock->sdesc->Convert($this);
  519.         }
  520.         if (count($element->elements) || ($sdesc) || count($element->docblock->tags))
  521.         {
  522.             if ($this->curpagepackage != $element->parent->package)
  523.             {
  524.                 $template->assign('includeheader',true);
  525.                 if (isset($this->package_pages[$element->parent->package]))
  526.                 {
  527.                     $template->assign('ppage',$this->package_pages[$element->parent->package]);
  528.                     unset($this->package_pages[$element->parent->package]);
  529.                 }
  530.             }
  531.             $this->curpagepackage = $element->parent->package;
  532.             $template->assign('dest', urlencode('page'.$element->parent->package.$element->parent->getPath()));
  533.             $template->assign('sdesc',$sdesc);
  534.             $template->assign('package',$element->parent->package);
  535.             $template->assign('name',$element->parent->file);
  536.             $this->pdf->ezText($template->fetch('page.tpl'));
  537.             $this->convertDocBlock($element);
  538.         }
  539.     }
  540.     
  541.         
  542.     /**
  543.      * Used to translate an XML DocBook tag from a tutorial by reading the
  544.      * options.ini file for the template.
  545.      * @param string tag name
  546.      * @param string any attributes Format: array(name => value)
  547.      * @param string the tag contents, if any
  548.      * @param string the tag contents, if any, unpost-processed
  549.      * @return string
  550.      */
  551.     function TranslateTag($name,$attr,$cdata,$unconvertedcdata)
  552.     {
  553.         if ($name == 'example' && @$attr['role'] == 'html')
  554.         {
  555.             $cdata = htmlspecialchars($cdata);
  556.             $unconvertedcdata = htmlspecialchars($unconvertedcdata);
  557.         }
  558.         if ($name == 'programlisting' && @$attr['role'] == 'php')
  559.         {
  560.             $unconvertedcdata = strtr($unconvertedcdata, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
  561.             $a = parent::TranslateTag($name, $attr, $cdata, $unconvertedcdata);
  562. //            var_dump(htmlspecialchars($cdata), htmlspecialchars($unconvertedcdata), htmlspecialchars($a));
  563.             return $a;
  564.         }
  565.         return parent::TranslateTag($name, $attr, $cdata, $unconvertedcdata);
  566.     }
  567.  
  568.     function getPageName(&$element)
  569.     {
  570.         if (get_class($element) == 'parserpage') return $element->getName();
  571.         return $element->parent->getName();
  572.     }
  573.  
  574.     function getTutorialId($package,$subpackage,$tutorial,$id)
  575.     {
  576.         return 'tutorial'.$package.$subpackage.$tutorial.$id;
  577.     }
  578.     
  579.     function getCData($value)
  580.     {
  581.         return str_replace(array('<c:','<C:'),array("<c:","<C:"),$value);
  582.     }
  583.     
  584.     /**
  585.      * @deprecated html package pages just don't work with PDF, use {@tutorial tutorials.pkg}
  586.      */
  587.     function convertPackagepage(&$element)
  588.     {
  589.         $x = $element->Convert($this);
  590.         $x = substr($x,strpos($x,'<body'));
  591.         $this->package_pages[$element->package] = trim(substr($x,strpos($x,'>') + 1,strpos($x,'</body>') - 6));
  592.     }
  593.     
  594.     function convertTutorial(&$element)
  595.     {
  596.         $x = $element->Convert($this, true);
  597.         $template = &$this->newSmarty();
  598.         $template->assign('package',$element->package);
  599.         $template->assign('subpackage',$element->subpackage);
  600.         $template->assign('contents',$x);
  601.         $template->assign('title',$element->getTitle($this));
  602.         $template->assign('child',$element->parent);
  603.         if (isset($element->parent->parent)) $template->assign('hasparent',$element->parent->parent);
  604.         $template->assign('element',$element);
  605.         $this->pdf->ezText($template->fetch('tutorial.tpl'));
  606.     }
  607.     
  608.     /**
  609.      * returns a template-enabled array of class trees
  610.      * 
  611.      * @param    string    $package    package to generate a class tree for
  612.      * @see $roots, getRootTree()
  613.      */
  614.     function generateFormattedClassTrees($package)
  615.     {
  616.         if (!isset($this->roots[$package])) return array();
  617.         $roots = $trees = array();
  618.         $roots = $this->roots[$package];
  619.         for($i=0;$i<count($roots);$i++)
  620.         {
  621.             $trees[] = array('class' => $roots[$i],'class_tree' => "<ul>\n".$this->getRootTree($this->getSortedClassTreeFromClass($roots[$i],$package,''),$package)."</ul>\n");
  622.         }
  623.         return $trees;
  624.     }
  625.     
  626.     /**
  627.      * return formatted class tree for the Class Trees page
  628.      *
  629.      * @param array $tree output from {@link getSortedClassTreeFromClass()}
  630.      * @see Classes::$definitechild, generateFormattedClassTrees()
  631.      * @return string
  632.      */
  633.     function getRootTree($tree,$package)
  634.     {
  635.         if (!$tree) return '';
  636.         $my_tree = '';
  637.         $cur = '#root';
  638.         $lastcur = array(false);
  639.         $kids = array();
  640.         $dopar = false;
  641.         if ($tree[$cur]['parent'])
  642.         {
  643.             $dopar = true;
  644.             if (!is_object($tree[$cur]['parent']))
  645.             {
  646. //                debug("parent ".$tree[$cur]['parent']." not found");
  647.                 $my_tree .= '<li>' . $tree[$cur]['parent'] .'<ul>';
  648.             }
  649.             else
  650.             {
  651. //                        debug("parent ".$this->returnSee($tree[$cur]['parent'], false, false)." in other package");
  652.                 $my_tree .= '<li>' . $this->returnSee($tree[$cur]['parent'], false, false);
  653.                 if ($tree[$cur]['parent']->package != $package) $my_tree .= ' <b>(Different package)</b><ul>';
  654.             }
  655.         }
  656.         do
  657.         {
  658. //            fancy_debug($cur,$lastcur,$kids);
  659.             if (count($tree[$cur]['children']))
  660.             {
  661. //                debug("$cur has children");
  662.                 if (!isset($kids[$cur]))
  663.                 {
  664. //                    debug("set $cur kids");
  665.                     $kids[$cur] = 1;
  666.                     $my_tree .= '<li>'.$this->returnSee($tree[$cur]['link'], false, false);
  667.                     $my_tree .= '<ul>'."\n";
  668.                 }
  669.                 array_push($lastcur,$cur);
  670.                 list(,$cur) = each($tree[$cur]['children']);
  671. //                var_dump('listed',$cur);
  672.                 if ($cur)
  673.                 {
  674.                     $cur = $cur['package'] . '#' . $cur['class'];
  675. //                    debug("set cur to child $cur");
  676. //                    $my_tree .= '<li>'.$this->returnSee($tree[$cur]['link'], false, false);
  677.                     continue;
  678.                 } else
  679.                 {
  680. //                    debug("end of children for $cur");
  681.                     $cur = array_pop($lastcur);
  682.                     $cur = array_pop($lastcur);
  683.                     $my_tree .= '</ul></li>'."\n";
  684.                     if ($dopar && ($cur == '#root' || !$cur)) $my_tree .= '</ul></li>';
  685.                 }
  686.             } else 
  687.             {
  688. //                debug("$cur has no children");
  689.                 $my_tree .= '<li>'.$this->returnSee($tree[$cur]['link'], false, false)."</li>";
  690.                 if ($dopar && $cur == '#root') $my_tree .= '</ul></li>';
  691.                 $cur = array_pop($lastcur);
  692.             }
  693.         } while ($cur);
  694.         return $my_tree;
  695.     }
  696.     
  697.     /**
  698.      * calls {@link Cezpdf::ezOutput()} and writes documentation.pdf to targetDir
  699.      */
  700.     function Output($title = 'Generated Documentation')
  701.     {
  702.         phpDocumentor_out("Generating PDF file..");
  703.         flush();
  704.         $template = &$this->newSmarty();
  705.         $this->pdf->ezText($template->fetch('appendix_title_page.tpl'));
  706.         $trees = array();
  707.         foreach($this->all_packages as $package => $rest)
  708.         {
  709.             if (!isset($this->pkg_elements[$package])) continue;
  710.             $a = array();
  711.             phpDocumentor_out('.');
  712.             flush();
  713.             $a['package'] = $package;
  714.             $a["trees"] = $this->generateFormattedClassTrees($package);
  715.             $trees[] = $a;
  716.         }
  717.         $template->assign('trees',$trees);
  718.         $this->pdf->ezText($template->fetch('classtree.tpl'));
  719.         phpDocumentor_out('.');
  720.         if (count($this->ric_set))
  721.         $this->pdf->ezText($template->fetch('ric_title_page.tpl'));
  722.         foreach($this->ric_set as $name => $contents)
  723.         {
  724.             $template->assign('contents',$contents);
  725.             $template->assign('name',$name);
  726.             $this->pdf->ezText($template->fetch('ric.tpl'));
  727.         }
  728.         if (count($this->_sourcecode))
  729.         {
  730.             $this->pdf->ezText($template->fetch('source_title_page.tpl'));
  731.             $template->assign('source',$this->_sourcecode);
  732.             $this->pdf->ezText($template->fetch('source_loop.tpl'));
  733.         }
  734.         flush();
  735.         if (count($this->todoList))
  736.         {
  737.             $todolist = array();
  738.             foreach($this->todoList as $package => $alltodos)
  739.             {
  740.                 foreach($alltodos as $todos)
  741.                 {
  742.                     $converted = array();
  743.                     $converted['link'] = $this->returnSee($todos[0]);
  744.                     if (!is_array($todos[1]))
  745.                     {
  746.                         $converted['todos'][] = $todos[1]->Convert($this);
  747.                     } else
  748.                     {
  749.                         foreach($todos[1] as $todo)
  750.                         {
  751.                             $converted['todos'][] = $todo->Convert($this);
  752.                         }
  753.                     }
  754.                     $todolist[$package][] = $converted;
  755.                 }
  756.             }
  757.             $template->assign('todos',$todolist);
  758.             
  759.             $this->pdf->ezText($template->fetch('todolist.tpl'));
  760.         }
  761.         if (false) {
  762.         $fp = @fopen("C:/Documents and Settings/Owner/Desktop/pdfsourceorig.txt",'w');
  763.         if ($fp)
  764.         {
  765.             $a = $this->pdf->ezOutput(true); // debug
  766.             fwrite($fp, $a, strlen($a));
  767.             fclose($fp);
  768.         }
  769.         }
  770.         $this->pdf->setupTOC();
  771.         $template->assign('contents',$this->pdf->reportContents);
  772.         $this->pdf->ezText($template->fetch('toc.tpl'));
  773.         $x = $this->pdf->ezOutput(false, $template);
  774.         phpDocumentor_out("done\n");
  775.         flush();
  776.         $this->writeFile("documentation.pdf", $x, true);
  777.     }
  778.     
  779.     function mystrnatcasecmp($a,$b)
  780.     {
  781.         return strnatcasecmp($a[0],$b[0]);
  782.     }
  783.     
  784.     
  785.     /**
  786.      * @param string name of class
  787.      * @param string package name
  788.      * @param string full path to look in (used in index generation)
  789.      * @return mixed false if not found, or an html a link to the class's documentation
  790.      * @see parent::getClassLink()
  791.      */
  792.     function getClassLink($expr,$package, $file = false,$text = false)
  793.     {
  794.         $a = Converter::getClassLink($expr,$package,$file);
  795.         if (!$a) return false;
  796.         return $this->returnSee($a, $text);
  797.     }
  798.  
  799.     /**
  800.      * @param string name of function
  801.      * @param string package name
  802.      * @param string full path to look in (used in index generation)
  803.      * @param boolean deprecated
  804.      * @return mixed false if not found, or an html a link to the function's documentation
  805.      * @see parent::getFunctionLink()
  806.      */
  807.     function getFunctionLink($expr,$package, $file = false,$text = false)
  808.     {
  809.         $a = Converter::getFunctionLink($expr,$package,$file);
  810.         if (!$a) return false;
  811.         return $this->returnSee($a, $text);
  812.     }
  813.  
  814.     /**
  815.      * @param string name of define
  816.      * @param string package name
  817.      * @param string full path to look in (used in index generation)
  818.      * @param boolean deprecated
  819.      * @return mixed false if not found, or an html a link to the define's documentation
  820.      * @see parent::getDefineLink()
  821.      */
  822.     function getDefineLink($expr,$package, $file = false,$text = false)
  823.     {
  824.         $a = Converter::getDefineLink($expr,$package,$file);
  825.         if (!$a) return false;
  826.         return $this->returnSee($a, $text);
  827.     }
  828.  
  829.     /**
  830.      * @param string name of global variable
  831.      * @param string package name
  832.      * @param string full path to look in (used in index generation)
  833.      * @param boolean deprecated
  834.      * @return mixed false if not found, or an html a link to the global variable's documentation
  835.      * @see parent::getGlobalLink()
  836.      */
  837.     function getGlobalLink($expr,$package, $file = false,$text = false)
  838.     {
  839.         $a = Converter::getGlobalLink($expr,$package,$file);
  840.         if (!$a) return false;
  841.         return $this->returnSee($a, $text);
  842.     }
  843.  
  844.     /**
  845.      * @param string name of procedural page
  846.      * @param string package name
  847.      * @param string full path to look in (used in index generation)
  848.      * @param boolean deprecated
  849.      * @return mixed false if not found, or an html a link to the procedural page's documentation
  850.      * @see parent::getPageLink()
  851.      */
  852.     function getPageLink($expr,$package, $path = false,$text = false)
  853.     {
  854.         $a = Converter::getPageLink($expr,$package,$path);
  855.         if (!$a) return false;
  856.         return $this->returnSee($a, $text);
  857.     }
  858.  
  859.     /**
  860.      * @param string name of method
  861.      * @param string class containing method
  862.      * @param string package name
  863.      * @param string full path to look in (used in index generation)
  864.      * @param boolean deprecated
  865.      * @return mixed false if not found, or an html a link to the method's documentation
  866.      * @see parent::getMethodLink()
  867.      */
  868.     function getMethodLink($expr,$class,$package, $file = false,$text = false)
  869.     {
  870.         $a = Converter::getMethodLink($expr,$class,$package,$file);
  871.         if (!$a) return false;
  872.         return $this->returnSee($a, $text);
  873.     }
  874.  
  875.     /**
  876.      * @param string name of var
  877.      * @param string class containing var
  878.      * @param string package name
  879.      * @param string full path to look in (used in index generation)
  880.      * @param boolean deprecated
  881.      * @param boolean return just the URL, or enclose it in an html a tag
  882.      * @return mixed false if not found, or an html a link to the var's documentation
  883.      * @see parent::getVarLink()
  884.      */
  885.     function getVarLink($expr,$class,$package, $file = false,$text = false)
  886.     {
  887.         $a = Converter::getVarLink($expr,$class,$package,$file);
  888.         if (!$a) return false;
  889.         return $this->returnSee($a, $text);
  890.     }
  891.  
  892.     function setTemplateDir($dir)
  893.     {
  894.         Converter::setTemplateDir($dir);
  895.         $this->smarty_dir = $this->templateDir;
  896.     }
  897.     
  898.     /** @return 1 always the same */
  899.     function getState()
  900.     {
  901.         return 1;
  902.     }
  903.     
  904.     /**
  905.      * @see parent::unmangle()
  906.      */
  907.     function unmangle($notused,$source)
  908.     {
  909. //        $source = str_replace("\n","<mybr>",$source);
  910.         return $source;
  911.     }
  912. }
  913. ?>