PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/tmp/busines13_bundle_installer/mod_roknavmenu/lib/providers/RokMenuProviderJoomla.php

https://bitbucket.org/izubizarreta/https-bitbucket.org-bityvip
PHP | 158 lines | 119 code | 22 blank | 17 comment | 41 complexity | 740f733b3a8a69fac46c0d85cb49ad37 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.0, JSON, GPL-2.0, BSD-3-Clause, LGPL-2.1, MIT
  1. <?php
  2. /**
  3. * @version 1.13 July 2, 2012
  4. * @author RocketTheme http://www.rockettheme.com
  5. * @copyright Copyright (C) 2007 - 2012 RocketTheme, LLC
  6. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
  7. */
  8. require_once(dirname(__FILE__) . '/JoomlaRokMenuNode.php');
  9. if (!class_exists('RokMenuProviderJoomla')) {
  10. class RokMenuProviderJoomla extends AbstractRokMenuProvider {
  11. protected function getMenuItems() {
  12. //Cache this basd on access level
  13. $conf =& JFactory::getConfig();
  14. if ($conf->getValue('config.caching') && $this->args["module_cache"]) {
  15. $user =& JFactory::getUser();
  16. $cache =& JFactory::getCache('mod_roknavmenu');
  17. $cache->setCaching(true);
  18. $args = array($this->args);
  19. $checksum = md5(implode(',',$this->args));
  20. $menuitems = $cache->get(array($this, 'getFullMenuItems'), $args, 'mod_roknavmenu-'.$user->get('aid', 0).'-'.$checksum);
  21. }
  22. else {
  23. $menuitems = $this->getFullMenuItems($this->args);
  24. }
  25. $jmenu = JSite::getMenu();
  26. $active = $jmenu->getActive();
  27. if (is_object($active)){
  28. if (array_key_exists($active->id, $menuitems)){
  29. $this->current_node = $active->id;
  30. }
  31. }
  32. $this->populateActiveBranch($menuitems);
  33. return $menuitems;
  34. }
  35. public function getFullMenuItems($args){
  36. $menu = JSite::getMenu();
  37. // Get Menu Items
  38. $rows = $menu->getItems('menutype', $args['menutype']);
  39. $outputNodes = array();
  40. if(is_array($rows) && count($rows) > 0){
  41. foreach ($rows as $item) {
  42. //Create the new Node
  43. $node = new JoomlaRokMenuNode();
  44. $node->setId($item->id);
  45. $node->setParent($item->parent);
  46. $node->setTitle(addslashes(htmlspecialchars($item->name, ENT_QUOTES, 'UTF-8')));
  47. $node->setParams($item->params);
  48. $node->setLink($item->link);
  49. // Menu Link is a special type that is a link to another item
  50. if ($item->type == 'menulink' && $newItem = $menu->getItem($item->query['Itemid'])) {
  51. $node->setAlias(true);
  52. $node->setLink($newItem->link);
  53. }
  54. // Get the icon image associated with the item
  55. $iParams = (is_object($item->params)) ? $item->params : new JRegisry($item->params);
  56. if ($args['menu_images'] && $iParams->get('menu_image') && $iParams->get('menu_image') != -1) {
  57. $node->setImage(JURI::base(true) . '/images/stories/' . $iParams->get('menu_image'));
  58. if ($args['menu_images_link']) {
  59. $node->setLink(null);
  60. }
  61. }
  62. switch ($item->type)
  63. {
  64. case 'separator':
  65. $node->setType('separator');
  66. break;
  67. case 'url':
  68. if ((strpos($node->getLink(), 'index.php?') === 0) && (strpos($node->getLink(), 'Itemid=') === false)) {
  69. $node->setLink($node->getLink() . '&amp;Itemid=' . $node->getId());
  70. }
  71. $node->setType('menuitem');
  72. break;
  73. default :
  74. $router = JSite::getRouter();
  75. if ($node->isAlias() && $newItem){
  76. $menu_id = $item->query['Itemid'];
  77. }
  78. else {
  79. $menu_id = $node->getId();
  80. }
  81. $link = ($router->getMode() == JROUTER_MODE_SEF)? 'index.php?Itemid=' . $menu_id : $node->getLink() . '&Itemid=' . $menu_id;
  82. $node->setLink($link);
  83. $node->setType('menuitem');
  84. break;
  85. }
  86. if ($node->getLink() != null) {
  87. // set the target based on menu item options
  88. switch ($item->browserNav)
  89. {
  90. case 1:
  91. $node->setTarget('_blank');
  92. break;
  93. case 2:
  94. //$node->setLink(str_replace('index.php', 'index2.php', $node->getLink()));
  95. //$node->setTarget('newnotool');
  96. $value = addslashes(htmlspecialchars("window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes');return false;", ENT_QUOTES, 'UTF-8'));
  97. $node->addLinkAttrib('onclick', $value);
  98. break;
  99. default:
  100. //$node->setTarget('current');
  101. break;
  102. }
  103. // Get the final URL
  104. if ($item->home == 1) { // Set Home Links to the Base
  105. $node->setLink(JURI::base());
  106. }
  107. if ($item->type != 'separator' && $item->type != 'url') {
  108. $iSecure = $iParams->get('secure', 0);
  109. if (array_key_exists('url_type',$args) && $args['url_type'] == 'full') {
  110. $url = JRoute::_($node->getLink(), true, $iSecure);
  111. $base = (!preg_match("/^http/", $node->getLink())) ? rtrim(JURI::base(false).'/') : '';
  112. $routed = $base . $url;
  113. $secure = RokNavMenuTree::_getSecureUrl($routed, $iSecure);
  114. $node->setLink($secure);
  115. } else {
  116. $node->setLink(JRoute::_($node->getLink(), true, $iSecure));
  117. }
  118. }
  119. else if ($item->type == 'url') {
  120. $node->setLink(str_replace('&', '&amp;', $node->getLink()));
  121. }
  122. }
  123. $node->addListItemClass("item" . $node->getId());
  124. $node->setAccess($item->access);
  125. $node->addSpanClass($node->getType());
  126. $user =& JFactory::getUser();
  127. if (($node->getAccess() <= $user->get('aid', 0))||((isset($args['check_access_level'][0]) && $args['check_access_level'][0]==1))){
  128. // Add node to output list
  129. $outputNodes[$node->getId()] = $node;
  130. }
  131. }
  132. return $outputNodes;
  133. }
  134. }
  135. }
  136. }