PageRenderTime 53ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/includes/menu.php

https://github.com/joebushi/joomla
PHP | 83 lines | 49 code | 12 blank | 22 comment | 8 complexity | 427980eff14e2afac1cb910de62708e7 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  5. * @license GNU General Public License version 2 or later; see LICENSE.txt
  6. */
  7. // No direct access.
  8. defined('_JEXEC') or die;
  9. /**
  10. * JMenu class
  11. *
  12. * @package Joomla.Site
  13. * @subpackage Application
  14. * @since 1.5
  15. */
  16. class JMenuSite extends JMenu
  17. {
  18. /**
  19. * Loads the entire menu table into memory.
  20. *
  21. * @return array
  22. */
  23. public function load()
  24. {
  25. $cache = &JFactory::getCache('_system', 'output');
  26. if (!$data = $cache->get('menu_items'))
  27. {
  28. jimport('joomla.database.query');
  29. // Initialise some variables.
  30. $db = &JFactory::getDbo();
  31. $query = new JQuery;
  32. $query->select('m.id, m.menutype, m.title, m.alias, m.path AS route, m.link, m.type, m.level');
  33. $query->select('m.browserNav, m.access, m.params, m.home, m.img, m.template_style_id, m.component_id, m.parent_id');
  34. $query->select('e.element as component');
  35. $query->from('#__menu AS m');
  36. $query->leftJoin('#__extensions AS e ON m.component_id = e.extension_id');
  37. $query->where('m.published = 1');
  38. $query->where('m.parent_id > 0');
  39. $query->order('m.lft');
  40. $db->setQuery($query);
  41. if (!($menus = $db->loadObjectList('id')))
  42. {
  43. JError::raiseWarning(500, "Error loading Menus: ".$db->getErrorMsg());
  44. return false;
  45. }
  46. foreach ($menus as &$menu)
  47. {
  48. // Get parent information.
  49. $parent_tree = array();
  50. if (($parent = $menu->parent_id) && (isset($menus[$parent])) &&
  51. (is_object($menus[$parent])) && (isset($menus[$parent]->route)) && isset($menus[$parent]->tree)) {
  52. $parent_tree = $menus[$parent]->tree;
  53. }
  54. // Create tree.
  55. array_push($parent_tree, $menu->id);
  56. $menu->tree = $parent_tree;
  57. // Create the query array.
  58. $url = str_replace('index.php?', '', $menu->link);
  59. if (strpos($url, '&amp;') !== false) {
  60. $url = str_replace('&amp;','&',$url);
  61. }
  62. parse_str($url, $menu->query);
  63. }
  64. $cache->store(serialize($menus), 'menu_items');
  65. $this->_items = $menus;
  66. }
  67. else {
  68. $this->_items = unserialize($data);
  69. }
  70. }
  71. }