Source for file PDFdefaultConverter.inc

Documentation is available at PDFdefaultConverter.inc

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

Documentation generated on Mon, 05 Dec 2011 21:23:29 -0600 by phpDocumentor 1.4.4