X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Ftemplate%2Fmenu%2Fclass_MenuTemplateEngine.php;h=62997fa86258deb1507480cd99bc8a86ef558af2;hb=4bf128b841cdd5180e9fb9d9eaa8b3cd3e3eed90;hp=141ba8861060ba551a93f03d7a25aa55d25d6803;hpb=1ee35e6d96c456b8e3499bd683f1647aa28bd501;p=core.git diff --git a/inc/classes/main/template/menu/class_MenuTemplateEngine.php b/inc/classes/main/template/menu/class_MenuTemplateEngine.php index 141ba886..62997fa8 100644 --- a/inc/classes/main/template/menu/class_MenuTemplateEngine.php +++ b/inc/classes/main/template/menu/class_MenuTemplateEngine.php @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.shipsimu.org * @@ -57,6 +57,44 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla 'anchor-href', ); + /** + * Variables for a menu entry + */ + private $menuEntryVariables = array( + // List entry + 'entry_id', + // Anchor + 'anchor-id', + 'anchor-text', + 'anchor-title', + 'anchor-href', + ); + + /** + * Variables for a menu block + */ + private $menuBlockVariables = array( + // Title + 'title_id', + 'title_class', + 'title_text', + // Content is taken from menuEntries + // Footer + 'footer_id', + 'footer_class', + 'footer_text', + ); + + /** + * Rendered menu entries + */ + private $menuEntries = array(); + + /** + * Rendered menu blocks + */ + private $menuBlocks = array(); + /** * Menu instance */ @@ -314,7 +352,7 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla */ private function initMenu ($templateDependency = '') { // Get web template engine - $this->setTemplateInstance(ObjectFactory::createObjectByConfiguredName('web_template_class', array($this->getApplicationInstance()))); + $this->setTemplateInstance(ObjectFactory::createObjectByConfiguredName('html_template_class', array($this->getApplicationInstance()))); // Handle the dependency template $this->handleTemplateDependency('menu', $templateDependency); @@ -652,6 +690,9 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla private function finishEntry () { // Pop the last entry $this->getStackInstance()->popNamed('current_node'); + + // Render this menu entry + $this->renderMenuEntry(); } /** @@ -662,6 +703,9 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla private function finishBlock () { // Pop the last entry $this->getStackInstance()->popNamed('current_node'); + + // Render this menu block + $this->renderMenuBlock(); } /** @@ -714,6 +758,97 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla $this->getStackInstance()->popNamed('current_node'); } + /** + * Renders this menu entry, as every block all variables got overwritten + * with data from next entry. + * + * @return void + */ + private function renderMenuEntry () { + // Prepare template engine + $templateInstance = $this->prepareTemplateInstance(); + + // Load menu entry template + $templateInstance->loadCodeTemplate('menu_entry'); + + // Copy all variables over to it + foreach ($this->menuEntryVariables as $variableName) { + // Copy variable + $variableValue = $this->readVariable($variableName); + + // Is the key 'anchor-href'? + if ($variableName == 'anchor-href') { + // Expand variable with URL then + $variableValue = '{?base_url?}/' . $variableValue; + } // END - if + + // ... into the instance + $templateInstance->assignVariable($variableName, $variableValue); + } // END - foreach + + // Compile template + variables + $templateInstance->compileTemplate(); + $templateInstance->compileVariables(); + + // Remember it here + $this->menuEntries[$this->readVariable('entry_id')] = $templateInstance->getRawTemplateData(); + } + + /** + * Renders this menu block, as next block all data is overwritten with + * next block. + * + * @return void + */ + private function renderMenuBlock () { + // Init block content + $blockContent = implode('', $this->menuEntries); + + // Prepare template engine + $templateInstance = $this->prepareTemplateInstance(); + + // Load menu entry template + $templateInstance->loadCodeTemplate('menu_block'); + + // Copy all variables over to it + foreach ($this->menuBlockVariables as $variableName) { + // Copy variable + $variableValue = $this->readVariable($variableName); + + // ... into the instance + $templateInstance->assignVariable($variableName, $variableValue); + } // END - foreach + + // Assign block content + $templateInstance->assignVariable('block_content', $blockContent); + + // Compile template + variables + $templateInstance->compileTemplate(); + $templateInstance->compileVariables(); + + // Remember it here + array_push($this->menuBlocks, $templateInstance->getRawTemplateData()); + + // Reset rendered menu entries array + $this->menuEntries = array(); + } + + /** + * "Getter" for menu content + * + * @return $menuContent Returned menu content + */ + public function getMenuContent () { + // Implode menuBlocks + $menuContent = implode('', $this->menuBlocks); + + // Clean variable + $this->menuBlocks = array(); + + // And return it + return $menuContent; + } + /** * Getter for menu cache file (FQFN) *