PageRenderTime 27ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/templates/ecard/html/mod_mainmenu/default.php

http://j-ecard-28022011.googlecode.com/
PHP | 153 lines | 135 code | 11 blank | 7 comment | 53 complexity | 8568d06d163247ebca9c34a51161cbab MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. <?php
  2. defined('_JEXEC') or die('Restricted access'); // no direct access
  3. ob_start();
  4. require_once realpath(dirname(__FILE__) . str_replace('/', DIRECTORY_SEPARATOR, '/../../../../modules/mod_mainmenu/tmpl/default.php'));
  5. ob_clean();
  6. if (!defined('modMainMenuArtxExtensions'))
  7. {
  8. function modMainMenuArtXMLCallback(&$node, $args)
  9. {
  10. $options = $GLOBALS['modMainMenuArtXMLCallbackOptions'];
  11. if ($node->name() == 'li') {
  12. if (!$options['show_submenus'] && $node->level() == 1) {
  13. if ($ul = $node->getElementByPath('ul'))
  14. $node->removeChild($ul);
  15. }
  16. $liChildren = & $node->_children;
  17. if (count($liChildren) > 0) {
  18. // element ( $img?, $span ( $text ) ) )
  19. // <a href="..."> <img src="..." (align="left|right")? alt="..." />?<span><![CDATA[...]]></span></a>
  20. // <span class="separator"><img src="..." (align="left|right")? alt="..." />?<span><![CDATA[...]]></span></span>
  21. $element = & $liChildren[0];
  22. if ($element->_children[0]->name() == 'img') {
  23. $img = & $element->_children[0];
  24. $span = & $element->_children[1];
  25. $element->removeChild($img);
  26. } else {
  27. $img = null;
  28. $span = & $element->_children[0];
  29. }
  30. $element->removeChild($span);
  31. // convert separator to anchor
  32. if ($element->name() == 'span' && $element->attributes('class') == 'separator') {
  33. $element->_name = 'a';
  34. $element->addAttribute('href', '#');
  35. $element->addAttribute('onclick', 'return false;');
  36. }
  37. // add extra spans for top level items, required for design
  38. if ($element->level() == 2) {
  39. $lspan = & $element->addChild('span', array('class' => 'l'));
  40. $lspan->setData(' ');
  41. $rspan = & $element->addChild('span', array('class' => 'r'));
  42. $rspan->setData(' ');
  43. $tspan = & $element->addChild('span', array('class' => 't'));
  44. $container = & $tspan;
  45. } else {
  46. $container = & $element;
  47. }
  48. // container is always <a ...>...</a> here
  49. $text = $span->data();
  50. if ($img != null) {
  51. $align = $img->attributes('align');
  52. if ($align == 'left' || $align == '') {
  53. $container->addChild('img', array('class' => 'art-metadata-icon',
  54. 'src' => $img->attributes('src'),
  55. 'style' => 'margin-right: 5px; vertical-align: middle;',
  56. 'alt' => $img->attributes('alt')));
  57. $extraArtxSpan = & $container->addChild('artx-extra-span');
  58. $extraArtxSpan->setData($text);
  59. } else if ($align == 'right') {
  60. $extraArtxSpan = & $container->addChild('artx-extra-span');
  61. $extraArtxSpan->setData($text);
  62. $container->addChild('img', array('class' => 'art-metadata-icon',
  63. 'src' => $img->attributes('src'),
  64. 'style' => 'margin-left: 5px; vertical-align: middle;',
  65. 'alt' => $img->attributes('alt')));
  66. }
  67. } else {
  68. $container->setData($text);
  69. }
  70. }
  71. modMainMenuXMLCallback($node, $args);
  72. // this should be after modMainMenuXMLCallback, because the callback sets class='active' and id='current'
  73. if ($options['vmenu'] !== null && !$options['vmenu']['simple']) {
  74. $class = $node->attributes('class');
  75. $isActive = $class && false !== strpos(' ' . $class, ' active');
  76. if ($node->attributes('id') != 'current' && !$isActive) {
  77. if ($ul = $node->getElementByPath('ul'))
  78. $node->removeChild($ul);
  79. }
  80. }
  81. $class = $node->attributes('class');
  82. if ($class && false !== strpos(' ' . $class, ' active')) {
  83. $element->addAttribute('class', 'active');
  84. }
  85. } else {
  86. modMainMenuXMLCallback($node, $args);
  87. }
  88. }
  89. function artxMenuDecorator($content)
  90. {
  91. $result = '';
  92. ob_start();
  93. ?>
  94. <div class="art-nav">
  95. <div class="l"></div>
  96. <div class="r"></div>
  97. <?php
  98. $result .= ob_get_clean() . $content;
  99. ob_start();
  100. ?>
  101. </div>
  102. <?php
  103. $result .= ob_get_clean();
  104. return $result;
  105. }
  106. define('modMainMenuArtxExtensions', true);
  107. }
  108. if (isset($attribs['name']) && $attribs['name'] == 'user3') {
  109. $GLOBALS['modMainMenuArtXMLCallbackOptions'] = array(
  110. 'show_submenus' => $GLOBALS['artx_settings']['menu']['show_submenus'] && 1 == $params->get('showAllChildren'),
  111. 'vmenu' => null
  112. );
  113. $xml = modMainMenuHelper::getXML($params->get('menutype'), $params, 'modMainMenuArtXMLCallback');
  114. if ($xml) {
  115. $xml->addAttribute('class', 'art-menu');
  116. if ($tagId = $params->get('tag_id')) {
  117. $xml->addAttribute('id', $tagId);
  118. }
  119. $result = JFilterOutput::ampReplace($xml->toString((bool)$params->get('show_whitespace')));
  120. $result = str_replace(array('<ul/>', '<ul />', '<artx-extra-span>', '</artx-extra-span>'), '', $result);
  121. echo artxMenuDecorator($result);
  122. }
  123. unset($GLOBALS['tmp_menu_show_submenus']);
  124. } else if ($params->get('moduleclass_sfx') == 'art-vmenu') {
  125. $GLOBALS['modMainMenuArtXMLCallbackOptions'] = array(
  126. 'show_submenus' => $GLOBALS['artx_settings']['vmenu']['show_submenus'] && 1 == $params->get('showAllChildren'),
  127. 'vmenu' => array('simple' => $GLOBALS['artx_settings']['vmenu']['simple']),
  128. );
  129. $xml = modMainMenuHelper::getXML($params->get('menutype'), $params, 'modMainMenuArtXMLCallback');
  130. if ($xml) {
  131. $xml->addAttribute('class', 'art-vmenu');
  132. if ($tagId = $params->get('tag_id')) {
  133. $xml->addAttribute('id', $tagId);
  134. }
  135. $result = JFilterOutput::ampReplace($xml->toString((bool)$params->get('show_whitespace')));
  136. $result = str_replace(array('<ul/>', '<ul />', '<artx-extra-span>', '</artx-extra-span>'), '', $result);
  137. echo $result;
  138. }
  139. unset($GLOBALS['tmp_menu_show_submenus']);
  140. } else {
  141. modMainMenuHelper::render($params, 'modMainMenuXMLCallback');
  142. }