Files
@ 654a62c4f366
Branch filter:
Location: hot67beta/libraries/joomla/application/menu.php
654a62c4f366
5.2 KiB
text/x-php
menubar 11 to 30 and revert
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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | <?php
/**
* @version $Id: menu.php 11299 2008-11-22 01:40:44Z ian $
* @package Joomla.Framework
* @subpackage Application
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
// Check to ensure this file is within the rest of the framework
defined('JPATH_BASE') or die();
/**
* JMenu class
*
* @package Joomla.Framework
* @subpackage Application
* @since 1.5
*/
class JMenu extends JObject
{
/**
* Array to hold the menu items
*
* @access private
* @param array
*/
var $_items = array ();
/**
* Identifier of the default menu item
*
* @access private
* @param integer
*/
var $_default = 0;
/**
* Identifier of the active menu item
*
* @access private
* @param integer
*/
var $_active = 0;
/**
* Class constructor
*
* @access public
* @return boolean True on success
*/
function __construct($options = array())
{
$this->load(); //load the menu items
foreach ($this->_items as $k => $item)
{
if ($item->home) {
$this->_default = $item->id;
}
}
}
/**
* Returns a reference to a JMenu object
*
* This method must be invoked as:
* <pre> $menu = &JSite::getMenu();</pre>
*
* @access public
* @param string $client The name of the client
* @param array $options An associative array of options
* @return JMenu A menu object.
* @since 1.5
*/
function &getInstance($client, $options = array())
{
static $instances;
if (!isset( $instances )) {
$instances = array();
}
if (empty($instances[$client]))
{
//Load the router object
$info =& JApplicationHelper::getClientInfo($client, true);
$path = $info->path.DS.'includes'.DS.'menu.php';
if(file_exists($path))
{
require_once $path;
// Create a JPathway object
$classname = 'JMenu'.ucfirst($client);
$instance = new $classname($options);
}
else
{
//$error = JError::raiseError( 500, 'Unable to load menu: '.$client);
$error = null; //Jinx : need to fix this
return $error;
}
$instances[$client] = & $instance;
}
return $instances[$client];
}
/**
* Get menu item by id
*
* @access public
* @param int The item id
* @return mixed The item object, or null if not found
*/
function &getItem($id)
{
$result = null;
if (isset($this->_items[$id])) {
$result = &$this->_items[$id];
}
return $result;
}
/**
* Set the default item by id
*
* @param int The item id
* @access public
* @return True, if succesfull
*/
function setDefault($id)
{
if(isset($this->_items[$id])) {
$this->_default = $id;
return true;
}
return false;
}
/**
* Get menu item by id
*
* @access public
*
* @return object The item object
*/
function &getDefault()
{
$item =& $this->_items[$this->_default];
return $item;
}
/**
* Set the default item by id
*
* @param int The item id
* @access public
* @return If successfull the active item, otherwise null
*/
function &setActive($id)
{
if(isset($this->_items[$id]))
{
$this->_active = $id;
$result = &$this->_items[$id];
return $result;
}
$result = null;
return $result;
}
/**
* Get menu item by id
*
* @access public
*
* @return object The item object
*/
function &getActive()
{
if ($this->_active) {
$item =& $this->_items[$this->_active];
return $item;
}
$result = null;
return $result;
}
/**
* Gets menu items by attribute
*
* @access public
* @param string The field name
* @param string The value of the field
* @param boolean If true, only returns the first item found
* @return array
*/
function getItems($attribute, $value, $firstonly = false)
{
$items = null;
foreach ($this->_items as $item)
{
if ( ! is_object($item) )
continue;
if ($item->$attribute == $value)
{
if($firstonly) {
return $item;
}
$items[] = $item;
}
}
return $items;
}
/**
* Gets the parameter object for a certain menu item
*
* @access public
* @param int The item id
* @return object A JParameter object
*/
function &getParams($id)
{
$ini = '';
if ($menu =& $this->getItem($id)) {
$ini = $menu->params;
}
$result = new JParameter( $ini );
return $result;
}
/**
* Getter for the menu array
*
* @access public
* @return array
*/
function getMenu() {
return $this->_items;
}
/**
* Method to check JMenu object authorization against an access control
* object and optionally an access extension object
*
* @access public
* @param integer $id The menu id
* @param integer $accessid The users access identifier
* @return boolean True if authorized
*/
function authorize($id, $accessid = 0)
{
$menu =& $this->getItem($id);
return ((isset($menu->access) ? $menu->access : 0) <= $accessid);
}
/**
* Loads the menu items
*
* @abstract
* @access public
* @return array
*/
function load()
{
return array();
}
}
|