/**
* A Menu template engine class
*
- * @author Roland Haeder <webmaster@ship-simu.org>
+ * @author Roland Haeder <webmaster@shipsimu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 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.ship-simu.org
+ * @link http://www.shipsimu.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
'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
*/
$templateInstance->setMenuInstance($menuInstance);
// Init a variable stacker
- $stackerInstance = ObjectFactory::createObjectByConfiguredName('menu_stacker_class');
+ $stackInstance = ObjectFactory::createObjectByConfiguredName('menu_stacker_class');
// Set it
- $templateInstance->setStackerInstance($stackerInstance);
+ $templateInstance->setStackInstance($stackInstance);
// Return the prepared instance
return $templateInstance;
* @return void
* @throws XmlNodeMismatchException If current main node mismatches the closing one
*/
- public function endElement ($resource, $nodeName) {
+ public function finishElement ($resource, $nodeName) {
// Make all lower-case
$nodeName = strtolower($nodeName);
// Is this string empty?
if (empty($characters)) {
// Then skip it silently
- return false;
+ return;
} // END - if
// Assign the found characters to variable and use the last entry from
// stack as the name
- parent::assignVariable($this->getStackerInstance()->getNamed('current_node'), $characters);
+ parent::assignVariable($this->getStackInstance()->getNamed('current_node'), $characters);
}
/**
*/
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);
// Push the node name on the stacker
- $this->getStackerInstance()->pushNamed('current_node', 'menu');
+ $this->getStackInstance()->pushNamed('current_node', 'menu');
}
/**
*/
private function startEntryList () {
// Push the node name on the stacker
- $this->getStackerInstance()->pushNamed('current_node', 'entry-list');
+ $this->getStackInstance()->pushNamed('current_node', 'entry-list');
}
/**
*/
private function startBlockHeader () {
// Push the node name on the stacker
- $this->getStackerInstance()->pushNamed('current_node', 'block-header');
+ $this->getStackInstance()->pushNamed('current_node', 'block-header');
}
/**
*/
private function startBlockFooter () {
// Push the node name on the stacker
- $this->getStackerInstance()->pushNamed('current_node', 'block-footer');
+ $this->getStackInstance()->pushNamed('current_node', 'block-footer');
}
/**
*/
private function startBlockList () {
// Push the node name on the stacker
- $this->getStackerInstance()->pushNamed('current_node', 'block-list');
+ $this->getStackInstance()->pushNamed('current_node', 'block-list');
}
/**
*/
private function startBlock () {
// Push the node name on the stacker
- $this->getStackerInstance()->pushNamed('current_node', 'block');
+ $this->getStackInstance()->pushNamed('current_node', 'block');
}
/**
*/
private function startTitle () {
// Push the node name on the stacker
- $this->getStackerInstance()->pushNamed('current_node', 'title');
+ $this->getStackInstance()->pushNamed('current_node', 'title');
}
/**
*/
private function startTitleId () {
// Push the node name on the stacker
- $this->getStackerInstance()->pushNamed('current_node', 'title-id');
+ $this->getStackInstance()->pushNamed('current_node', 'title-id');
}
/**
*/
private function startTitleClass () {
// Push the node name on the stacker
- $this->getStackerInstance()->pushNamed('current_node', 'title-class');
+ $this->getStackInstance()->pushNamed('current_node', 'title-class');
}
/**
*/
private function startTitleText () {
// Push the node name on the stacker
- $this->getStackerInstance()->pushNamed('current_node', 'title-text');
+ $this->getStackInstance()->pushNamed('current_node', 'title-text');
}
/**
*/
private function startEntry () {
// Push the node name on the stacker
- $this->getStackerInstance()->pushNamed('current_node', 'entry');
+ $this->getStackInstance()->pushNamed('current_node', 'entry');
}
/**
*/
private function startEntryId () {
// Push the node name on the stacker
- $this->getStackerInstance()->pushNamed('current_node', 'entry-id');
+ $this->getStackInstance()->pushNamed('current_node', 'entry-id');
}
/**
*/
private function startAnchor () {
// Push the node name on the stacker
- $this->getStackerInstance()->pushNamed('current_node', 'anchor');
+ $this->getStackInstance()->pushNamed('current_node', 'anchor');
}
/**
*/
private function startAnchorId () {
// Push the node name on the stacker
- $this->getStackerInstance()->pushNamed('current_node', 'anchor-id');
+ $this->getStackInstance()->pushNamed('current_node', 'anchor-id');
}
/**
*/
private function startAnchorText () {
// Push the node name on the stacker
- $this->getStackerInstance()->pushNamed('current_node', 'anchor-text');
+ $this->getStackInstance()->pushNamed('current_node', 'anchor-text');
}
/**
*/
private function startAnchorTitle () {
// Push the node name on the stacker
- $this->getStackerInstance()->pushNamed('current_node', 'anchor-title');
+ $this->getStackInstance()->pushNamed('current_node', 'anchor-title');
}
/**
*/
private function startAnchorHref () {
// Push the node name on the stacker
- $this->getStackerInstance()->pushNamed('current_node', 'anchor-href');
+ $this->getStackInstance()->pushNamed('current_node', 'anchor-href');
}
/**
*/
private function startFooterId () {
// Push the node name on the stacker
- $this->getStackerInstance()->pushNamed('current_node', 'footer-id');
+ $this->getStackInstance()->pushNamed('current_node', 'footer-id');
}
/**
*/
private function startFooterClass () {
// Push the node name on the stacker
- $this->getStackerInstance()->pushNamed('current_node', 'footer-class');
+ $this->getStackInstance()->pushNamed('current_node', 'footer-class');
}
/**
*/
private function startFooterText () {
// Push the node name on the stacker
- $this->getStackerInstance()->pushNamed('current_node', 'footer-text');
+ $this->getStackInstance()->pushNamed('current_node', 'footer-text');
}
/**
*/
private function finishTitle () {
// Pop the last entry
- $this->getStackerInstance()->popNamed('current_node');
+ $this->getStackInstance()->popNamed('current_node');
}
/**
*/
private function finishTitleId () {
// Pop the last entry
- $this->getStackerInstance()->popNamed('current_node');
+ $this->getStackInstance()->popNamed('current_node');
}
/**
*/
private function finishTitleClass () {
// Pop the last entry
- $this->getStackerInstance()->popNamed('current_node');
+ $this->getStackInstance()->popNamed('current_node');
}
/**
*/
private function finishTitleText () {
// Pop the last entry
- $this->getStackerInstance()->popNamed('current_node');
+ $this->getStackInstance()->popNamed('current_node');
}
/**
*/
private function finishFooterText () {
// Pop the last entry
- $this->getStackerInstance()->popNamed('current_node');
+ $this->getStackInstance()->popNamed('current_node');
}
/**
*/
private function finishFooterClass () {
// Pop the last entry
- $this->getStackerInstance()->popNamed('current_node');
+ $this->getStackInstance()->popNamed('current_node');
}
/**
*/
private function finishFooterId () {
// Pop the last entry
- $this->getStackerInstance()->popNamed('current_node');
+ $this->getStackInstance()->popNamed('current_node');
}
/**
*/
private function finishAnchorHref () {
// Pop the last entry
- $this->getStackerInstance()->popNamed('current_node');
+ $this->getStackInstance()->popNamed('current_node');
}
/**
*/
private function finishAnchorTitle () {
// Pop the last entry
- $this->getStackerInstance()->popNamed('current_node');
+ $this->getStackInstance()->popNamed('current_node');
}
/**
*/
private function finishAnchorText () {
// Pop the last entry
- $this->getStackerInstance()->popNamed('current_node');
+ $this->getStackInstance()->popNamed('current_node');
}
/**
*/
private function finishAnchorId () {
// Pop the last entry
- $this->getStackerInstance()->popNamed('current_node');
+ $this->getStackInstance()->popNamed('current_node');
}
/**
*/
private function finishAnchor () {
// Pop the last entry
- $this->getStackerInstance()->popNamed('current_node');
+ $this->getStackInstance()->popNamed('current_node');
}
/**
*/
private function finishEntryId () {
// Pop the last entry
- $this->getStackerInstance()->popNamed('current_node');
+ $this->getStackInstance()->popNamed('current_node');
}
/**
*/
private function finishEntry () {
// Pop the last entry
- $this->getStackerInstance()->popNamed('current_node');
+ $this->getStackInstance()->popNamed('current_node');
+
+ // Render this menu entry
+ $this->renderMenuEntry();
}
/**
*/
private function finishBlock () {
// Pop the last entry
- $this->getStackerInstance()->popNamed('current_node');
+ $this->getStackInstance()->popNamed('current_node');
+
+ // Render this menu block
+ $this->renderMenuBlock();
}
/**
*/
private function finishBlockList () {
// Pop the last entry
- $this->getStackerInstance()->popNamed('current_node');
+ $this->getStackInstance()->popNamed('current_node');
}
/**
*/
private function finishEntryList () {
// Pop the last entry
- $this->getStackerInstance()->popNamed('current_node');
+ $this->getStackInstance()->popNamed('current_node');
}
/**
*/
private function finishBlockHeader () {
// Pop the last entry
- $this->getStackerInstance()->popNamed('current_node');
+ $this->getStackInstance()->popNamed('current_node');
}
/**
*/
private function finishBlockFooter () {
// Pop the last entry
- $this->getStackerInstance()->popNamed('current_node');
+ $this->getStackInstance()->popNamed('current_node');
}
/**
*/
private function finishMenu () {
// Pop the last entry
- $this->getStackerInstance()->popNamed('current_node');
+ $this->getStackInstance()->popNamed('current_node');
+ }
+
+ /**
+ * Renders this menu entry, as every block all variables got overwritten
+ * with data from next entry.
+ *
+ * @todo 'anchor_href' may needs expanding with full URL
+ * @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);
+
+ // ... 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();
}
/**
*/
public function getMenuCacheFqfn () {
// Get the FQFN ready
- $fqfn = sprintf("%s%s%s/%s.%s",
+ $fqfn = sprintf('%s%s%s/%s.%s',
$this->getConfigInstance()->getConfigEntry('base_path'),
$this->getGenericBasePath(),
'menus/_cache',