1 <?php
2 3 4 5 6 7 8
9
10 defined('JPATH_PLATFORM') or die;
11
12 13 14 15 16
17 class extends JMenu
18 {
19 20 21 22 23 24
25 protected $app;
26
27 28 29 30 31 32
33 protected $db;
34
35 36 37 38 39 40
41 protected $language;
42
43 44 45 46 47 48 49
50 public function __construct($options = array())
51 {
52
53 $this->app = isset($options['app']) && $options['app'] instanceof JApplicationCms ? $options['app'] : JFactory::getApplication();
54 $this->db = isset($options['db']) && $options['db'] instanceof JDatabaseDriver ? $options['db'] : JFactory::getDbo();
55 $this->language = isset($options['language']) && $options['language'] instanceof JLanguage ? $options['language'] : JFactory::getLanguage();
56
57 parent::__construct($options);
58 }
59
60 61 62 63 64 65 66
67 public function load()
68 {
69
70 $db = $this->db;
71
72 $loader = function () use ($db)
73 {
74 $query = $db->getQuery(true)
75 ->select('m.id, m.menutype, m.title, m.alias, m.note, m.path AS route, m.link, m.type, m.level, m.language')
76 ->select($db->quoteName('m.browserNav') . ', m.access, m.params, m.home, m.img, m.template_style_id, m.component_id, m.parent_id')
77 ->select('e.element as component')
78 ->from('#__menu AS m')
79 ->join('LEFT', '#__extensions AS e ON m.component_id = e.extension_id')
80 ->where('m.published = 1')
81 ->where('m.parent_id > 0')
82 ->where('m.client_id = 0')
83 ->order('m.lft');
84
85
86 $db->setQuery($query);
87
88 return $db->loadObjectList('id', 'JMenuItem');
89 };
90
91 try
92 {
93
94 $cache = JFactory::getCache('com_menus', 'callback');
95
96 $this->_items = $cache->get($loader, array(), md5(get_class($this)), false);
97 }
98 catch (JCacheException $e)
99 {
100 try
101 {
102 $this->_items = $loader();
103 }
104 catch (JDatabaseExceptionExecuting $databaseException)
105 {
106 JError::raiseWarning(500, JText::sprintf('JERROR_LOADING_MENUS', $databaseException->getMessage()));
107
108 return false;
109 }
110 }
111 catch (JDatabaseExceptionExecuting $e)
112 {
113 JError::raiseWarning(500, JText::sprintf('JERROR_LOADING_MENUS', $e->getMessage()));
114
115 return false;
116 }
117
118 foreach ($this->_items as &$item)
119 {
120
121 $parent_tree = array();
122
123 if (isset($this->_items[$item->parent_id]))
124 {
125 $parent_tree = $this->_items[$item->parent_id]->tree;
126 }
127
128
129 $parent_tree[] = $item->id;
130 $item->tree = $parent_tree;
131
132
133 $url = str_replace('index.php?', '', $item->link);
134 $url = str_replace('&', '&', $url);
135
136 parse_str($url, $item->query);
137 }
138
139 return true;
140 }
141
142 143 144 145 146 147 148 149 150 151 152
153 public function getItems($attributes, $values, $firstonly = false)
154 {
155 $attributes = (array) $attributes;
156 $values = (array) $values;
157
158 if ($this->app->isClient('site'))
159 {
160
161 if (($key = array_search('language', $attributes)) === false)
162 {
163 if (JLanguageMultilang::isEnabled())
164 {
165 $attributes[] = 'language';
166 $values[] = array(JFactory::getLanguage()->getTag(), '*');
167 }
168 }
169 elseif ($values[$key] === null)
170 {
171 unset($attributes[$key], $values[$key]);
172 }
173
174
175 if (($key = array_search('access', $attributes)) === false)
176 {
177 $attributes[] = 'access';
178 $values[] = $this->user->getAuthorisedViewLevels();
179 }
180 elseif ($values[$key] === null)
181 {
182 unset($attributes[$key], $values[$key]);
183 }
184 }
185
186
187 $attributes = array_values($attributes);
188 $values = array_values($values);
189
190 return parent::getItems($attributes, $values, $firstonly);
191 }
192
193 194 195 196 197 198 199 200 201
202 public function getDefault($language = '*')
203 {
204 if (array_key_exists($language, $this->_default) && $this->app->isClient('site') && $this->app->getLanguageFilter())
205 {
206 return $this->_items[$this->_default[$language]];
207 }
208
209 if (array_key_exists('*', $this->_default))
210 {
211 return $this->_items[$this->_default['*']];
212 }
213
214 return;
215 }
216 }
217