forked from marcobarbosa/minima
/
menu.php
124 lines (111 loc) · 3.42 KB
/
menu.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
* @version $Id: menu.php 20196 2011-01-09 02:40:25Z ian $
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// No direct access.
defined('_JEXEC') or die;
/**
* JMenu class
*
* @package Joomla.Site
* @subpackage Application
* @since 1.5
*/
class JMenuSite extends JMenu
{
/**
* Loads the entire menu table into memory.
*
* @return array
*/
public function load()
{
$cache = JFactory::getCache('mod_menu', ''); // has to be mod_menu or this cache won't get cleaned
if (!$data = $cache->get('menu_items'.JFactory::getLanguage()->getTag())) {
// Initialise variables.
$db = JFactory::getDbo();
$app = JFactory::getApplication();
$query = $db->getQuery(true);
$query->select('m.id, m.menutype, m.title, m.alias, m.path AS route, m.link, m.type, m.level');
$query->select('m.browserNav, m.access, m.params, m.home, m.img, m.template_style_id, m.component_id, m.parent_id');
$query->select('m.language');
$query->select('e.element as component');
$query->from('#__menu AS m');
$query->leftJoin('#__extensions AS e ON m.component_id = e.extension_id');
$query->where('m.published = 1');
$query->where('m.parent_id > 0');
$query->where('m.client_id = 0');
$query->order('m.lft');
$user = JFactory::getUser();
$groups = implode(',', $user->getAuthorisedViewLevels());
$query->where('m.access IN (' . $groups . ')');
// Set the query
$db->setQuery($query);
if (!($menus = $db->loadObjectList('id'))) {
JError::raiseWarning(500, JText::sprintf('JERROR_LOADING_MENUS', $db->getErrorMsg()));
return false;
}
foreach ($menus as &$menu) {
// Get parent information.
$parent_tree = array();
if (isset($menus[$menu->parent_id])) {
$parent_tree = $menus[$menu->parent_id]->tree;
}
// Create tree.
$parent_tree[] = $menu->id;
$menu->tree = $parent_tree;
// Create the query array.
$url = str_replace('index.php?', '', $menu->link);
$url = str_replace('&','&',$url);
parse_str($url, $menu->query);
}
$cache->store($menus, 'menu_items'.JFactory::getLanguage()->getTag());
$this->_items = $menus;
} else {
$this->_items = $data;
}
}
/**
* Gets menu items by attribute
*
* @param string $attributes The field name
* @param string $values The value of the field
* @param boolean $firstonly If true, only returns the first item found
*
* @return array
*/
public function getItems($attributes, $values, $firstonly = false)
{
$attributes = (array) $attributes;
$values = (array) $values;
$app = JFactory::getApplication();
// Filter by language if not set
if ($app->isSite() && $app->getLanguageFilter() && !array_key_exists('language',$attributes)) {
$attributes[]='language';
$values[]=array(JFactory::getLanguage()->getTag(), '*');
}
return parent::getItems($attributes, $values, $firstonly);
}
/**
* Get menu item by id
*
* @param string $language The language code.
*
* @return object The item object
* @since 1.5
*/
function getDefault($language='*')
{
if (array_key_exists($language, $this->_default) && JFactory::getApplication()->getLanguageFilter()) {
return $this->_items[$this->_default[$language]];
}
else if (array_key_exists('*', $this->_default)) {
return $this->_items[$this->_default['*']];
}
else {
return 0;
}
}
}