. */ // $Id: xhtml.php 70 2010-05-02 07:04:23Z zyxist $ class xhtml extends standardOutput { protected $date = ''; protected $translate = null; protected $_tagVersion = array(); protected $_currentPage = null; /** * Initializes the generation, creating the index.html file with the * table of contents. * @param tfProject $project The project * @param String $path Output path */ public function init($project, $path) { $this->translate = $translate = tfTranslate::get(); $this->date = date('d.m.Y'); $this->project = $project; $this->path = $path; // Generating TOC. $code = $this->createHeader($translate->_('general','table_of_contents'), array()); $code .= '

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

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

'; $code .= $this->menuGen('', true, true); $code .= $this->createFooter(); $this->project->fs->write($this->path.'index.html', $code); } // 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); /*if($this->project->config['showNumbers']) { $code = $this->createHeader($page['FullNumber'].'. '.$page['Tags']['Title'], $nav); } else*/ { $code = $this->createHeader($page['Tags']['Title'], $nav); } $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'].'

'; } $code .= $this->menuGen($page['Id'], false, true); $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); $code .= $this->createBottomNavigator($page); $code .= $this->createFooter(); $this->project->fs->write($this->path.$page['Id'].'.html', $code); } // end generate(); /** * Closes the parsing - unused. */ public function close() { } // 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) { $translate = tfTranslate::get(); $docTitle = $this->project->config['title']; $docVersion = $this->project->config['version']; $textDocumentation = $translate->_('general', $this->project->config['projectType']); $code = << {$title} - {$docTitle}
EOF; return $code; } // end createHeader(); /** * Creates a common footer for each page. * * @return String */ public function createFooter() { $translate = tfTranslate::get(); 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 = $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']; $translate = tfTranslate::get(); $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 .= '
'.$translate->_('general','table_of_contents').'
'.($n ? $page['FullNumber'].'. ' : '').$page['Tags']['Title'].'
'; } if(!is_null($prev)) { $code .= '
'.($n ? $prev['FullNumber'].'. ' : '').$prev['Tags']['Title'].'
« '.$translate->_('navigation','prev').'
'; } if(!is_null($next)) { $code .= '
'.($n ? $next['FullNumber'].'. ' : '').$next['Tags']['Title'].'
'.$translate->_('navigation','next').' »
'; } $code .= '
'; return $code; } // end createTopNavigator(); /** * Creates the navigation below the page contents. * * @param Array &$page The page meta-info. * @return String */ public function createBottomNavigator(&$page) { $n =& $this->project->config['showNumbers']; $translate = tfTranslate::get(); $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 ? $page['FullNumber'].'. ' : '').$page['Tags']['Title'].'
'.($n ? $parent['FullNumber'].'. ' : '').$parent['Tags']['Title'].'
'; } else { $code .= '
'.($n ? $page['FullNumber'].'. ' : '').$page['Tags']['Title'].'
'.$translate->_('general','table_of_contents').'
'; } if(!is_null($prev)) { $code .= '
« '.$translate->_('navigation','prev').'
'.($n ? $prev['FullNumber'].'. ' : '').$prev['Tags']['Title'].'
'; } if(!is_null($next)) { $code .= '
'.$translate->_('navigation','next').' »
'.($n ? $next['FullNumber'].'. ' : '').$next['Tags']['Title'].'
'; } $code .= '
'; return $code; } // end createBottomNavigator(); /** * 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']; $translate = tfTranslate::get(); $code = ''; if($start) { $code .= '

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

'; } if(isset($this->project->tree[$what]) && count($this->project->tree[$what]) > 0) { $code .= ''; return $code; } return ''; } // end menuGen(); /** * Converts the page identifier to the URL. * * @param String $page The page identifier. * @return String */ public function toAddress($page) { return $page.'.html'; } // end toAddress(); /** * Creates "See also" links below the page content. * * @param Array $standard The links within the documentation * @param Array $external The external SeeAlso links * @return String */ public function _tagSeeAlso($standard, $external) { $n =& $this->project->config['showNumbers']; $translate = tfTranslate::get(); $prog = tfProgram::get(); $i = 0; $code = '

'.$this->translate->_('navigation','see_also').':

'; if($i == 0) { return ''; } return $code; } // end _tagSeeAlso(); /** * Handles "Author" tag. * * @param String $value The tag value * @return String */ public function _tagAuthor($value) { return ''.$this->translate->_('tags','author').''.$value.''; } // end _tagAuthor(); /** * Handles "Status" tag. * * @param String $value The tag value * @return String */ public function _tagStatus($value) { return ''.$this->translate->_('tags','status').''.$value.''; } // end _tagStatus(); /** * Handles "VCSKeywords" tag. * * @param String $val The value to be displayed. * @return String */ public function _tagVCSKeywords($val) { if($this->project->config['versionControlInfo']) { return ''.$this->translate->_('tags','version_control_info').''.$val.''; } return ''; } // end _tagVCSKeywords(); /** * Handles "VersionSince" tag. * * @param String $val The value to be displayed. * @return String */ public function _tagVersionSince($val) { $this->_tagVersion['since'] = $val; return ''; } // end _tagVersionSince(); /** * Handles "VersionTo" tag. * * @param String $val The value to be displayed. * @return String */ public function _tagVersionTo($val) { $this->_tagVersion['to'] = $val; return ''; } // end _tagVersionTo(); /** * Handles "FeatureInformation" tag. * * @param String $val The parsed value to be displayed. * @return String */ public function _tagFeatureInformationFrame($val) { return $val; } // end _tagImplements(); /** * Handles "Construct" tag. * * @param String $val The value to be displayed. * @return String */ public function _tagConstruct($val) { return ''.$this->translate->_('tags','construct').''.$val.''; } // end _tagConstruct(); /** * Handles "Visibility" tag. * * @param String $value The tag value * @return String */ public function _tagVisibility($value) { return ''.$this->translate->_('tags','visibility').''.$value.''; } // end _tagVisibility(); /** * Handles "Namespace" and "ENamespace" tags. * * @param String $value The tag value * @return String */ public function _tagNamespace($namespace, $enamespace) { if($namespace === null) { return ''.$this->translate->_('tags','namespace').''.$enamespace.''; } else { $pp = $this->project->getMetaInfo($namespace, false); if($pp !== null) { return ''.$this->translate->_('tags','namespace').''.$pp['Tags']['ShortTitle'].''; } else { return 'dupa'; } } } // end _tagNamespace(); /** * Handles "File" tag. * * @param String $value The tag value * @return String */ public function _tagFile($value) { return ''.$this->translate->_('tags','file').''.$value.''; } // end _tagFile(); /** * Handles "Reference" tag. * * @param String $value The tag value * @return String */ public function _tagReference($value) { return ''.$this->translate->_('tags','reference').''.$value.''; } // end _tagReference(); /** * Handles "Files" tag. * * @param String $value The tag value * @return String */ public function _tagFiles($value) { $code = ''.$this->translate->_('tags','files').''; foreach($value as $file) { $code .= ''.$file.'
'; } return $code.''; } // end _tagFiles(); /** * Handles "Returns" tag. * * @param String $value The tag value * @return String */ public function _tagReturns($value) { return ''.$this->translate->_('tags','returns').''.$value.''; } // end _tagVisibility(); /** * Handles "Type" tag. * * @param String $value The tag value * @return String */ public function _tagType($value) { return ''.$this->translate->_('tags','type').''.$value.''; } // end _tagType(); /** * Handles "Extends" and "EExtends" tags. * * @param String $extends The "Extends" list of values * @param String $eextends The "EExtends" list of values * @return String */ public function _tagExtends($extends, $eextends) { $extends = (is_null($extends) ? $eextends : $extends); $pp = $this->project->getMetaInfo($extends, false); if(!is_null($pp)) { return ''.$this->translate->_('tags','obj_extends').''.$pp['Tags']['ShortTitle'].''; } } // end _tagExtends(); /** * Handles "PartOf" and "EPartOf" tags. * * @param String $partOf The "PartOf" list of values * @param String $ePartOf The "EPartOf" list of values * @return String */ public function _tagPartOf($partOf, $ePartOf) { $partOf = (is_null($partOf) ? $ePartOf : $partOf); $pp = $this->project->getMetaInfo($partOf, false); if(!is_null($pp)) { return ''.$this->translate->_('tags','part_of').''.$pp['Tags']['ShortTitle'].''; } } // end _tagPartOf(); /** * Handles "ExtendedBy" and "EExtendedBy" tags. * * @param Array $val1 The "ExtendedBy" list of values * @param Array $val2 The "EExtendedBy" list of values * @return String */ public function _tagExtendedBy($val1, $val2) { return $this->_showLinks($val1, $val2, 'obj_extended'); } // end _tagExtendedBy(); /** * Handles "ImplementedBy" and "EImplementedBy" tags. * * @param Array $val1 The "ImplementedBy" list of values * @param Array $val2 The "EImplementedBy" list of values * @return String */ public function _tagImplementedBy($val1, $val2) { return $this->_showLinks($val1, $val2, 'obj_implemented'); } // end _tagExtendedBy(); /** * Handles "Implements" and "EImplements" tags. * * @param Array $val1 The "Implements" list of values * @param Array $val2 The "EImplements" list of values * @return String */ public function _tagImplements($val1, $val2) { return $this->_showLinks($val1, $val2, 'obj_implements'); } // end _tagImplements(); /** * Handles "Throws" and "EThrows" tags. * * @param Array $val1 The "Implements" list of values * @param Array $val2 The "EImplements" list of values * @return String */ public function _tagThrows($val1, $val2) { return $this->_showLinks($val1, $val2, 'obj_throws'); } // end _tagImplements(); /** * Handles "MultiExtends" and "EMultiExtends" tags. * * @param Array $val1 The "Implements" list of values * @param Array $val2 The "EImplements" list of values * @return String */ public function _tagMultiExtends($val1, $val2) { return $this->_showLinks($val1, $val2, 'obj_extends'); } // end _tagMultiExtends(); /** * Handles "Mixins" and "EMixins" tags. * * @param Array $val1 The "Mixins" list of values * @param Array $val2 The "EMixins" list of values * @return String */ public function _tagMixins($val1, $val2) { return $this->_showLinks($val1, $val2, 'obj_mixins'); } // end _tagMixins(); /** * Handles "Traits" and "ETraits" tags. * * @param Array $val1 The "Traits" list of values * @param Array $val2 The "ETraits" list of values * @return String */ public function _tagTraits($val1, $val2) { return $this->_showLinks($val1, $val2, 'obj_traits'); } // end _tagTraits(); /** * Handles "Arguments" tag. * * @param Array $list The argument list * @return String */ public function _tagArguments($list) { $output = tfProgram::get()->console->stderr; $typeOk = true; foreach($list as $item) { if(!isset($item['Type']) && !isset($item['EType'])) { $typeOk = false; } // Do some validation here. if(!isset($item['Desc'])) { $output->writeln('Missing Arguments:Desc tag in '.$this->_currentPage['Id']); return; } if(!isset($item['Name'])) { $output->writeln('Missing Arguments:Name tag in '.$this->_currentPage['Id']); return; } } $code = ''.$this->translate->_('tags', 'arg_list').'';//.$this->translate->_('tags', 'arg_name').''; $code .= '
'; foreach($list as $item) { $code .= '
'.$item['Name'].''; if($typeOk) { $code .= ' - '; if(isset($item['Type'])) { $pp = $this->project->getMetaInfo($item['Type'], false); if(!is_null($pp)) { $code .= ''.$pp['Tags']['ShortTitle'].''; } } elseif(isset($item['EType'])) { $code .= ''.$item['EType'].''; } $code .= ''; } $code .= '
'.$item['Desc'].'
'; } return $code.'
'; } // end _tagParameters(); /** * Handles "Package" tag. * * @param String $value The tag value * @return String */ public function _tagPackage($package, $epackage) { if($package === null) { return ''.$this->translate->_('tags','package').''.$epackage.''; } else { $pp = $this->project->getMetaInfo($extends, false); if($pp !== null) { return ''.$this->translate->_('tags','package').''.$pageDef['ShortTitle'].''; } } } // end _tagPackage(); /** * Handles "TimeComplexity" tag. * * @param String $val The value to be displayed. * @return String */ public function _tagTimeComplexity($val) { return ''.$this->translate->_('tags','time_complexity').''.$val.''; } // end _tagTimeComplexity(); /** * Handles "MemoryComplexity" tag. * * @param String $val The value to be displayed. * @return String */ public function _tagMemoryComplexity($val) { return ''.$this->translate->_('tags','memory_complexity').''.$val.''; } // end _tagMemoryComplexity(); /** * Handles "StartConditions" tag. * * @param Array $conditions The values to be displayed. * @return String */ public function _tagStartConditions($conditions) { return $this->_showList($conditions, 'start_conditions'); } // end _tagStartConditions(); /** * Handles "EndConditions" tag. * * @param Array $conditions The values to be displayed. * @return String */ public function _tagEndConditions($conditions) { return $this->_showList($conditions, 'end_conditions'); } // end _tagEndConditions(); /** * Handles "SideEffects" tag. * * @param Array $conditions The values to be displayed. * @return String */ public function _tagSideEffects($conditions) { return $this->_showList($conditions, 'side_effects'); } // end _tagSideEffects(); /** * Handles "Limitations" tag. * * @param Array $conditions The values to be displayed. * @return String */ public function _tagLimitations($conditions) { return $this->_showList($conditions, 'limitations'); } // end _tagLimitations(); /** * Handles "DataSources" tag. * * @param Array $conditions The values to be displayed. * @return String */ public function _tagDataSources($val1, $val2) { $code = ''.$this->translate->_('tags', 'datasources').'
    '; if($val1 !== null) { foreach($val1 as $item) { $pp = $this->project->getMetaInfo($item, false); if(!is_null($pp)) { $code .= '
  1. '.$pp['Tags']['ShortTitle'].'
  2. '; } } } if($val2 !== null) { foreach($val2 as $item) { $code .= '
  3. '.$item.'
  4. '; } } return $code.'
'; } // end _tagDataSources(); /** * A helper method for tags like "SideEffects". * * @param Array $val1 * @param Array $val2 * @param String $message */ protected function _showList(array $val1, $message) { $code = ''.$this->translate->_('tags',$message).''; $items = array(); if(sizeof($val1) == 1) { $code .= $val1[0]; } else { $code .= '
    '; foreach($val1 as $item) { $code .= '
  1. '.$item.'
  2. '; } $code .= '
'; } return $code.''; } // end _showList(); /** * A helper method for tags like "Implements". * * @param Array $val1 * @param Array $val2 * @param String $message */ protected function _showLinks($val1, $val2, $message) { $code = ''.$this->translate->_('tags',$message).''; $items = array(); if($val1 !== null) { foreach($val1 as $item) { $pp = $this->project->getMetaInfo($item, false); if(!is_null($pp)) { $items[] = ''.$pp['Tags']['ShortTitle'].''; } } } if($val2 !== null) { foreach($val2 as $item) { $items[] = ''.$item.''; } } return $code.implode(', ', $items).''; } // end _showLinks(); } // end xhtml;