PageRenderTime 52ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/mod_roknavmenu/lib/providers/RokMenuProviderJoomla16.php

https://bitbucket.org/izubizarreta/https-bitbucket.org-bityvip
PHP | 240 lines | 184 code | 27 blank | 29 comment | 50 complexity | f87477eea9fdd7b29f03480fb00e0e63 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('RokMenuProviderJoomla16'))
  10. {
  11. class RokMenuProviderJoomla16 extends AbstractRokMenuProvider
  12. {
  13. const ROOT_ID = 1;
  14. protected function getMenuItems()
  15. {
  16. //Cache this basd on access level
  17. $conf =& JFactory::getConfig();
  18. if ($conf->getValue('config.caching') && $this->args["module_cache"])
  19. {
  20. $user =& JFactory::getUser();
  21. $cache =& JFactory::getCache('mod_roknavmenu');
  22. $cache->setCaching(true);
  23. $args = array($this->args);
  24. $checksum = md5(implode(',', $this->args));
  25. $menuitems = $cache->get(array($this, 'getFullMenuItems'), $args, 'mod_roknavmenu-' . $user->get('aid', 0) . '-' . $checksum);
  26. }
  27. else
  28. {
  29. $menuitems = $this->getFullMenuItems($this->args);
  30. }
  31. /* Set the active to the current run since its not saved with the cache */
  32. $jmenu = JSite::getMenu();
  33. $active = $jmenu->getActive();
  34. if (is_object($active))
  35. {
  36. if (array_key_exists($active->id, $menuitems))
  37. {
  38. $this->current_node = $active->id;
  39. }
  40. }
  41. $this->populateActiveBranch($menuitems);
  42. return $menuitems;
  43. }
  44. public function getFullMenuItems($args)
  45. {
  46. $menu = JSite::getMenu();
  47. // Get Menu Items
  48. $rows = $menu->getItems('menutype', $args['menutype']);
  49. $outputNodes = array();
  50. if (is_array($rows) && count($rows) > 0)
  51. {
  52. foreach ($rows as $item)
  53. {
  54. //Create the new Node
  55. $node = new JoomlaRokMenuNode();
  56. $node->setId($item->id);
  57. $node->setParent($item->parent_id);
  58. $node->setTitle(addslashes(htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8')));
  59. $node->setParams($item->params);
  60. $node->setLink($item->link);
  61. // Menu Link is a special type that is a link to another item
  62. if ($item->type == 'alias' && $newItem = $menu->getItem($item->params->get('aliasoptions')))
  63. {
  64. $node->setAlias(true);
  65. $node->setLink($newItem->link);
  66. }
  67. // Get the icon image associated with the item
  68. $iParams = (is_object($item->params)) ? $item->params : new JRegisry($item->params);
  69. if ($args['menu_images'] && $iParams->get('menu_image') && $iParams->get('menu_image') != -1)
  70. {
  71. $node->setImage(JURI::base(true) . '/images/stories/' . $iParams->get('menu_image'));
  72. if ($args['menu_images_link'])
  73. {
  74. $node->setLink(null);
  75. }
  76. }
  77. switch ($item->type)
  78. {
  79. case 'separator':
  80. $node->setType('separator');
  81. break;
  82. case 'url':
  83. if ((strpos($node->getLink(), 'index.php?') === 0) && (strpos($node->getLink(), 'Itemid=') === false))
  84. {
  85. $node->setLink($node->getLink() . '&amp;Itemid=' . $node->getId());
  86. } elseif (!empty($item->link) && ($item->link != null)){
  87. $node->setLink($item->link);
  88. }
  89. $node->setType('menuitem');
  90. break;
  91. default :
  92. $router = JSite::getRouter();
  93. if ($node->isAlias() && $newItem)
  94. {
  95. $menu_id = $item->params->get('aliasoptions');
  96. $node->setMenuId($menu_id);
  97. //for aliased items formatter.php doesn't cover
  98. if ($node->getMenuId() == $this->current_node) {
  99. //taken back out because it caused all the aliased menu items on RT demos to highlight
  100. //$node->addListItemClass('active');
  101. //$node->setCssId('current');
  102. }
  103. }
  104. else
  105. {
  106. $menu_id = $node->getId();
  107. $node->setMenuId($menu_id);
  108. }
  109. $link = ($router->getMode() == JROUTER_MODE_SEF) ? 'index.php?Itemid=' . $menu_id : $node->getLink() . '&Itemid=' . $menu_id;
  110. $node->setLink($link);
  111. $node->setType('menuitem');
  112. break;
  113. }
  114. if ($node->getLink() != null)
  115. {
  116. // set the target based on menu item options
  117. switch ($item->browserNav)
  118. {
  119. case 1:
  120. $node->setTarget('_blank');
  121. break;
  122. case 2:
  123. //$node->setLink(str_replace('index.php', 'index2.php', $node->getLink()));
  124. //$node->setTarget('newnotool');
  125. $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'));
  126. $node->addLinkAttrib('onclick', $value);
  127. break;
  128. default:
  129. //$node->setTarget('current');
  130. break;
  131. }
  132. // Get the final URL
  133. if ($item->home == 1)
  134. { // Set Home Links to the Base
  135. //removed because it breaks SEF extensions
  136. //$node->setLink(JRoute::_(JURI::base()));
  137. }
  138. if ($item->type != 'separator' && $item->type != 'url')
  139. {
  140. $iSecure = $iParams->get('secure', 0);
  141. if (array_key_exists('url_type', $args) && $args['url_type'] == 'full')
  142. {
  143. $url = JRoute::_($node->getLink(), true, $iSecure);
  144. $base = (!preg_match("/^http/", $node->getLink())) ? rtrim(JURI::base(false) . '/') : '';
  145. $routed = $base . $url;
  146. $secure = RokNavMenuTree::_getSecureUrl($routed, $iSecure);
  147. $node->setLink($secure);
  148. } else
  149. {
  150. $node->setLink(JRoute::_($node->getLink(), true, $iSecure));
  151. }
  152. }
  153. else if ($item->type == 'url')
  154. {
  155. $node->setLink(str_replace('&', '&amp;', $node->getLink()));
  156. }
  157. }
  158. $node->addListItemClass("item" . $node->getId());
  159. $node->setAccess($item->access);
  160. $node->addSpanClass($node->getType());
  161. $outputNodes[$node->getId()] = $node;
  162. }
  163. }
  164. return $outputNodes;
  165. }
  166. /**
  167. * @param $nodeList
  168. * @return void
  169. */
  170. protected function populateActiveBranch($nodeList)
  171. {
  172. // setup children array to find parents and children
  173. $children = array();
  174. $list = array();
  175. foreach ($nodeList as $node)
  176. {
  177. $thisref = &$children[$node->getId()];
  178. $thisref['parent_id'] = $node->getParent();
  179. if ($node->getParent() == 1)
  180. {
  181. $list[$node->getId()] = &$thisref;
  182. } else
  183. {
  184. $children[$node->getParent()]['children'][] = $node->getId();
  185. }
  186. }
  187. // Find active branch
  188. if ($this->current_node != 1)
  189. {
  190. if (array_key_exists($this->current_node, $nodeList))
  191. {
  192. $parent_id = $children[$this->current_node]['parent_id'];
  193. while ($parent_id && $parent_id != 1)
  194. {
  195. $this->active_branch[$parent_id] = $nodeList[$parent_id];
  196. $parent_id = $children[$parent_id]['parent_id'];
  197. }
  198. $this->active_branch = array_reverse($this->active_branch, true);
  199. $this->active_branch[$this->current_node] = $nodeList[$this->current_node];
  200. }
  201. }
  202. }
  203. public function getMenuTree()
  204. {
  205. if (null == $this->menu)
  206. {
  207. $this->menu = new RokMenuNodeTree(self::ROOT_ID);
  208. $this->populateMenuTree();
  209. }
  210. return $this->menu;
  211. }
  212. }
  213. }