. */ // $Id: xhtml_single.php 68 2010-01-16 11:11:50Z extremo $ require_once('xhtml.php'); class xhtml_single extends xhtml { protected $pageOrder = array(); protected $pageContent = array(); /** * Initializes the generation. * * @param tfProject $project The project * @param String $path Output path */ public function init($project, $path) { $this->translate = tfTranslate::get(); $this->date = date('d.m.Y'); $this->project = $project; $this->path = $path; } // end init(); /** * Generates a single page and saves it on the disk. * * @param Array $page The page meta-info. */ public function generate($page) { tfTags::setTagList($page['Tags']); $nav = array(); $this->_currentPage = $page; $nav[$page['Id']] = $page['Tags']['ShortTitle']; $parent = $page['_Parent']; do { $parent = $this->project->getMetaInfo($parent, false); if(!is_null($parent)) { $nav[$parent['Id']] = $parent['Tags']['ShortTitle']; $parent = $parent['_Parent']; } } while(!is_null($parent)); $nav = array_reverse($nav, true); $code = $this->createTopNavigator($page); $subtitle = ''; if(isset($page['Tags']['Appendix']) && $page['Tags']['Appendix']) { $subtitle = $this->translate->_('tags', 'appendix').' '; if(!$this->project->config['showNumbers']) { $subtitle = trim($subtitle).': '; } } if($this->project->config['showNumbers']) { $code .= '

'.$subtitle.$page['FullNumber'].'. '.$page['Tags']['Title'].'

'; } else { $code .= '

'.$subtitle.$page['Tags']['Title'].'

'; } $this->_tagVersion = array(); $reference = tfTags::orderProcessTag('General', 'Author', $this). tfTags::orderProcessTag('Status', 'Status', $this). tfTags::orderProcessTags('Programming', $this). tfTags::orderProcessTags('Behaviour', $this). tfTags::orderProcessTags('VersionControl', $this); if(sizeof($this->_tagVersion) > 0) { $reference .= ''.$this->translate->_('tags','versions').''; if(isset($this->_tagVersion['since'])) { $reference .= $this->translate->_('general', 'period_since').' '.$this->_tagVersion['since'].''; } if(isset($this->_tagVersion['to'])) { $reference .= ' '.$this->translate->_('general', 'period_to').' '.$this->_tagVersion['to'].''; } $reference .= ''.PHP_EOL; } if($reference != '') { $code .= '
'.$reference.'

'; } $code .= tfTags::orderProcessTag('General', 'FeatureInformationFrame', $this); $code .= $page['Content']; $code .= tfTags::orderProcessTag('Navigation', 'SeeAlso', $this); $this->pageContent[$page['Id']] = $code; } // end generate(); /** * Finalizes the generation and saves the results to the hard disk. */ public function close() { $code = $this->createHeader('', array()); $code .= '

'.$this->project->config['title'].' '.$this->project->config['version'].'

'; $code .= '
'; $code .= ''; $code .= ''; $code .= ''; $code .= '
Copyright © '.$this->project->config['copyright'].'
'.$this->translate->_('general','doc_license',$this->project->config['license']).'
'.$this->translate->_('general','generated_in',$this->date).'

'; $code .= '

'.$this->translate->_('general','table_of_contents').'

'; $code .= $this->menuGen('', true); foreach($this->pageOrder as $id) { $code .= $this->pageContent[$id]; } $code .= $this->createFooter(); $this->project->fs->write($this->path.'index.html', $code); } // end close(); /** * Internal method that generates a common header for all the pages * and returns the source code. * * @param String $title The page title. * @param Array $nav The navigation list. * @return String */ public function createHeader($title, Array $nav) { $docTitle = $this->project->config['title']; $docVersion = $this->project->config['version']; $textDocumentation = $this->translate->_('general',$this->project->config['projectType']); $code = << {$docTitle}
EOF; return $code; } // end createHeader(); /** * Creates a common footer for each page. * * @return String */ public function createFooter() { if(strlen($this->project->config['copyrightLink']) > 0) { $copyright = ''.$this->project->config['copyright'].''; } else { $copyright = $this->project->config['copyright']; } if(strlen($this->project->config['licenseLink']) > 0) { $license = ''.$this->project->config['license'].''; } else { $license = $this->project->config['license']; } $textLicense = $this->translate->_('general','doc_license',$license); $version = tfMain::VERSION; $code = <<
EOF; return $code; } // end createFooter(); /** * Creates the navigation above the page contents. * * @param Array &$page The page meta-info. * @return String */ public function createTopNavigator(&$page) { $n =& $this->project->config['showNumbers']; $id = 'toc:'.str_replace('.', '_', $page['Id']); $parent = $this->project->getMetaInfo($page['_Parent'], false); $prev = $this->project->getMetaInfo($page['_Previous'], false); $next = $this->project->getMetaInfo($page['_Next'], false); $code = '
'; if(!is_null($parent)) { $code .= '
'.($n ? $parent['FullNumber'].'. ' : '').$parent['Tags']['Title'].'
'.($n ? $page['FullNumber'].'. ' : '').$page['Tags']['Title'].'
'; } else { $code .= '
'.$this->translate->_('general', 'table_of_contents').'
'.($n ? $page['FullNumber'].'. ' : '').$page['Tags']['Title'].'
'; } if(!is_null($prev)) { $code .= '
'.($n ? $prev['FullNumber'].'. ' : '').$prev['Tags']['Title'].'
« '.$this->translate->_('navigation','prev').'
'; } if(!is_null($next)) { $code .= '
'.($n ? $next['FullNumber'].'. ' : '').$next['Tags']['Title'].'
'.$this->translate->_('navigation','next').' »
'; } $code .= '
'; return $code; } // end createTopNavigator(); /** * Converts the page identifier to the URL. * * @param String $page The page identifier. * @return String */ public function toAddress($page) { $page = str_replace('.', '_', $page); return '#toc:'.$page; } // end toAddress(); /** * Generates a menu. * * @param String $what The root page. * @param Boolean $recursive Do we need a recursive tree? * @param Boolean $start Do we include the "Table of contents" text? * @return String */ public function menuGen($what, $recursive = true, $start = false) { $n =& $this->project->config['showNumbers']; if(isset($this->project->tree[$what]) && count($this->project->tree[$what]) > 0) { $code = ''; return $code; } return ''; } // end menuGen(); }