| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id: menu.php 14401 2010-01-26 14:10:00Z louis $ 4 * @package Joomla.Framework 5 * @subpackage Application 6 * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved. 7 * @license GNU/GPL, see LICENSE.php 8 * Joomla! is free software. This version may have been modified pursuant 9 * to the GNU General Public License, and as distributed it includes or 10 * is derivative of works licensed under the GNU General Public License or 11 * other free or open source software licenses. 12 * See COPYRIGHT.php for copyright notices and details. 13 */ 14 15 // Check to ensure this file is within the rest of the framework 16 defined('JPATH_BASE') or die(); 17 18 /** 19 * JMenu class 20 * 21 * @package Joomla.Framework 22 * @subpackage Application 23 * @since 1.5 24 */ 25 class JMenu extends JObject 26 { 27 /** 28 * Array to hold the menu items 29 * 30 * @access private 31 * @param array 32 */ 33 var $_items = array (); 34 35 /** 36 * Identifier of the default menu item 37 * 38 * @access private 39 * @param integer 40 */ 41 var $_default = 0; 42 43 /** 44 * Identifier of the active menu item 45 * 46 * @access private 47 * @param integer 48 */ 49 var $_active = 0; 50 51 52 /** 53 * Class constructor 54 * 55 * @access public 56 * @return boolean True on success 57 */ 58 function __construct($options = array()) 59 { 60 $this->load(); //load the menu items 61 62 foreach ($this->_items as $k => $item) 63 { 64 if ($item->home) { 65 $this->_default = $item->id; 66 } 67 } 68 } 69 70 /** 71 * Returns a reference to a JMenu object 72 * 73 * This method must be invoked as: 74 * <pre> $menu = &JSite::getMenu();</pre> 75 * 76 * @access public 77 * @param string $client The name of the client 78 * @param array $options An associative array of options 79 * @return JMenu A menu object. 80 * @since 1.5 81 */ 82 function &getInstance($client, $options = array()) 83 { 84 static $instances; 85 86 if (!isset( $instances )) { 87 $instances = array(); 88 } 89 90 if (empty($instances[$client])) 91 { 92 //Load the router object 93 $info =& JApplicationHelper::getClientInfo($client, true); 94 95 $path = $info->path.DS.'includes'.DS.'menu.php'; 96 if(file_exists($path)) 97 { 98 require_once $path; 99 100 // Create a JPathway object 101 $classname = 'JMenu'.ucfirst($client); 102 $instance = new $classname($options); 103 } 104 else 105 { 106 //$error = JError::raiseError( 500, 'Unable to load menu: '.$client); 107 $error = null; //Jinx : need to fix this 108 return $error; 109 } 110 111 $instances[$client] = & $instance; 112 } 113 114 return $instances[$client]; 115 } 116 117 /** 118 * Get menu item by id 119 * 120 * @access public 121 * @param int The item id 122 * @return mixed The item object, or null if not found 123 */ 124 function &getItem($id) 125 { 126 $result = null; 127 if (isset($this->_items[$id])) { 128 $result = &$this->_items[$id]; 129 } 130 131 return $result; 132 } 133 134 /** 135 * Set the default item by id 136 * 137 * @param int The item id 138 * @access public 139 * @return True, if succesfull 140 */ 141 function setDefault($id) 142 { 143 if(isset($this->_items[$id])) { 144 $this->_default = $id; 145 return true; 146 } 147 148 return false; 149 } 150 151 /** 152 * Get menu item by id 153 * 154 * @access public 155 * 156 * @return object The item object 157 */ 158 function &getDefault() 159 { 160 $item =& $this->_items[$this->_default]; 161 return $item; 162 } 163 164 /** 165 * Set the default item by id 166 * 167 * @param int The item id 168 * @access public 169 * @return If successfull the active item, otherwise null 170 */ 171 function &setActive($id) 172 { 173 if(isset($this->_items[$id])) 174 { 175 $this->_active = $id; 176 $result = &$this->_items[$id]; 177 return $result; 178 } 179 180 $result = null; 181 return $result; 182 } 183 184 /** 185 * Get menu item by id 186 * 187 * @access public 188 * 189 * @return object The item object 190 */ 191 function &getActive() 192 { 193 if ($this->_active) { 194 $item =& $this->_items[$this->_active]; 195 return $item; 196 } 197 198 $result = null; 199 return $result; 200 } 201 202 /** 203 * Gets menu items by attribute 204 * 205 * @access public 206 * @param string The field name 207 * @param string The value of the field 208 * @param boolean If true, only returns the first item found 209 * @return array 210 */ 211 function getItems($attribute, $value, $firstonly = false) 212 { 213 $items = null; 214 215 foreach ($this->_items as $item) 216 { 217 if ( ! is_object($item) ) 218 continue; 219 220 if ($item->$attribute == $value) 221 { 222 if($firstonly) { 223 return $item; 224 } 225 226 $items[] = $item; 227 } 228 } 229 230 return $items; 231 } 232 233 /** 234 * Gets the parameter object for a certain menu item 235 * 236 * @access public 237 * @param int The item id 238 * @return object A JParameter object 239 */ 240 function &getParams($id) 241 { 242 $ini = ''; 243 if ($menu =& $this->getItem($id)) { 244 $ini = $menu->params; 245 } 246 $result = new JParameter( $ini ); 247 248 return $result; 249 } 250 251 /** 252 * Getter for the menu array 253 * 254 * @access public 255 * @return array 256 */ 257 function getMenu() { 258 return $this->_items; 259 } 260 261 /** 262 * Method to check JMenu object authorization against an access control 263 * object and optionally an access extension object 264 * 265 * @access public 266 * @param integer $id The menu id 267 * @param integer $accessid The users access identifier 268 * @return boolean True if authorized 269 */ 270 function authorize($id, $accessid = 0) 271 { 272 $menu =& $this->getItem($id); 273 return ((isset($menu->access) ? $menu->access : 0) <= $accessid); 274 } 275 276 /** 277 * Loads the menu items 278 * 279 * @abstract 280 * @access public 281 * @return array 282 */ 283 function load() 284 { 285 return array(); 286 } 287 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Mar 28 15:54:07 2012 | Cross-referenced by PHPXref 0.7.1 |