Source for file HTMLSmartyConverter.inc
Documentation is available at HTMLSmartyConverter.inc
* HTML output converter for Smarty Template.
* This Converter takes output from the {@link Parser} and converts it to HTML-ready output for use with {@link Smarty}.
* phpDocumentor :: automatic documentation generator
* Copyright (c) 2000-2006 Joshua Eichorn, Gregory Beaver
* This library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* @author Joshua Eichorn <jeichorn@phpdoc.org>
* @author Greg Beaver <cellog@php.net>
* @copyright 2000-2006 Joshua Eichorn, Gregory Beaver
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version CVS: $Id: HTMLSmartyConverter.inc,v 1.15 2007/04/19 20:20:57 ashnazg Exp $
* @link http://www.phpdoc.org
* @link http://pear.php.net/PhpDocumentor
* @see parserDocBlock, parserInclude, parserPage, parserClass
* @see parserDefine, parserFunction, parserMethod, parserVar
* This Converter takes output from the {@link Parser} and converts it to HTML-ready output for use with {@link Smarty}.
* @see parserDocBlock, parserInclude, parserPage, parserClass, parserDefine, parserFunction, parserMethod, parserVar
* @author Greg Beaver <cellog@php.net>
* @version $Revision: 1.15 $
* This converter knows about the new root tree processing
* In order to fix PEAR Bug #6389
* Smarty Converter wants elements sorted by type as well as alphabetically
* @see Converter::$sort_page_contents_by_type
* indexes of elements by package that need to be generated
var $leftindex = array('classes' => true, 'pages' => true, 'functions' => true, 'defines' => false, 'globals' => false);
* output directory for the current procedural page being processed
* target directory passed on the command-line.
* {@link $targetDir} is malleable, always adding package/ and package/subpackage/ subdirectories onto it.
* output directory for the current class being processed
* array of converted package page names.
* Used to link to the package page in the left index
* @var array Format: array(package => 1)
* controls formatting of parser informative output
* "Converting /path/to/file.php... Procedural Page Elements... Classes..."
* Since HTMLdefaultConverter outputs files while converting, it needs to send a \n to start a new line. However, if there
* is more than one class, output is messy, with multiple \n's just between class file output. This variable prevents that
* contains all of the template procedural page element loop data needed for the current template
* contains all of the template class element loop data needed for the current template
* sets {@link $base_dir} to $targetDir
var $_classleft_cache = false;
var $_classcontents_cache = false;
var $_pagecontents_cache = false;
var $_pageleft_cache = false;
var $_done_package_index = false;
var $_wrote_tdir = false;
var $ric_contents = array();
function HTMLSmartyConverter(&$allp, &$packp, &$classes, &$procpages, $po, $pp, $qm, $targetDir, $templateDir, $title)
Converter::Converter($allp, $packp, $classes, $procpages,$po, $pp, $qm, $targetDir, $templateDir, $title);
$pathinfo = $this->proceduralpages->getPathInfo($path, $this);
$templ->assign('source',$value);
$templ->assign('package',$pathinfo['package']);
$templ->assign('subpackage',$pathinfo['subpackage']);
$templ->assign('name',$pathinfo['name']);
$templ->assign('source_loc',$pathinfo['source_loc']);
$templ->assign('docs',$pathinfo['docs']);
$templ->assign("subdir",'../');
$templ->register_outputfilter('HTMLSmarty_outputfilter');
$this->writefile($this->getFileSourceName($path). '.html',$templ->fetch('filesource.tpl'));
$templ->assign('source',$source);
$templ->assign('title',$title);
$templ->assign('file',$path);
$templ->assign("subdir",'../');
$templ->register_outputfilter('HTMLSmarty_outputfilter');
$this->writefile('exsource_'. $path. '.html',$templ->fetch('examplesource.tpl'));
* Retrieve a Converter-specific anchor to a segment of a source code file
* parsed via a {@tutorial tags.filesource.pkg} tag.
* @param string full path to source file
* @param string name of anchor
* @param string link text, if this is a link
* @param boolean returns either a link or a destination based on this
* @return string link to an anchor, or the anchor
return '<a name="a'. $anchor. '"></a>';
* Return a line of highlighted source code with formatted line number
* If the $path is a full path, then an anchor to the line number will be
* @param integer line number
* @param string highlighted source code line
* @param false|stringfull path to @filesource file this line is a part of,
* if this is a single line from a complete file.
* @return string formatted source code line with line number
function sourceLine($linenumber, $line, $path = false)
return '<li><div class="src-line">' . $this->getSourceAnchor($path, $linenumber) .
return '<li><div class="src-line">' . str_replace("\n",'',$line) . "$extra</div></li>\n";
* Used to convert the <<code>> tag in a docblock
function ProgramExample($example, $tutorial = false, $inlinesourceparse = null/*false*/,
$class = null/*false*/, $linenum = null/*false*/, $filesourcepath = null/*false*/)
$example = '<ol>' . parent::ProgramExample($example, $tutorial, $inlinesourceparse, $class, $linenum, $filesourcepath)
return $this->curname . '.html';
$sourcecode = str_replace('<br />',"<br>",$sourcecode);
$sourcecode = str_replace('<code>','<pre>',$sourcecode);
$sourcecode = str_replace('</code>','</pre>',$sourcecode);
* Uses htmlspecialchars() on the input
return str_replace(array(' ',"\t"), array(' ', ' '),
* Use the template tutorial_toc.tpl to generate a table of contents for HTML
* @return string table of contents formatted for use in the current output format
* @param array format: array(array('tagname' => section, 'link' => returnsee link, 'id' => anchor name, 'title' => from title tag),...)
$template->assign('toc',$toc);
return $template->fetch('tutorial_toc.tpl');
$templ->assign("ric",$this->ric_set);
$templ->assign("packageindex",$this->package_index);
$templ->assign('todolink','todolist.html');
$templ->assign("subdir",'');
* Writes out the template file of {@link $class_data} and unsets the template to save memory
* @see registerCurrentClass()
* @see parent::endClass()
$this->class_data->assign("compiledclassindex",$classleft['class']);
$this->class_data->assign("compiledinterfaceindex",$classleft['interface']);
$this->class_data->assign("packageindex",$this->package_index);
$this->class_data->register_outputfilter('HTMLSmarty_outputfilter');
$this->writefile($this->class . '.html',$this->class_data->fetch('class.tpl'));
if (isset ($cache[$this->package])) return $cache[$this->package];
if (!isset ($this->tutorials[$package])) return false;
foreach($this->tutorials[$package] as $subpackage => $blah)
$subpackages[] = $subpackage;
foreach($subpackages as $subpackage)
if (isset ($this->tutorial_tree) && is_array($this->tutorial_tree))
foreach($this->tutorial_tree as $root => $tr)
if ($tr['tutorial']->package == $package && $tr['tutorial']->subpackage == $subpackage)
$tutes[$tr['tutorial']->tutorial_type][] = $this->getTutorialTree($tr['tutorial']);
$template->assign('subtree',false);
$template->assign('parent',false);
$template->assign('haskids',false);
$template->assign('kids','');
$main = array('link' => $this->getId($link), 'title' => $link->title);
$template->assign('main',$main);
return $template->fetch('tutorial_tree.tpl');
if (isset ($tree['kids']))
foreach($tree['kids'] as $subtree)
$template->assign('subtree',$k);
$template->assign('parent',($k ? str_replace('.','',$tree['tutorial']->parent->name) : false));
$template->assign('haskids',strlen($ret));
$template->assign('kids',$ret);
$main = array('link' => $this->getId($link) |