| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Joomla.Platform 4 * @subpackage HTML 5 * 6 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 7 * @license GNU General Public License version 2 or later; see LICENSE 8 */ 9 10 defined('JPATH_PLATFORM') or die; 11 12 /** 13 * Utility class working with menu select lists 14 * 15 * @package Joomla.Platform 16 * @subpackage HTML 17 * @since 11.1 18 */ 19 abstract class JHtmlMenu 20 { 21 /** 22 * Cached array of the menus. 23 * 24 * @var array 25 * @since 11.1 26 */ 27 protected static $menus = null; 28 29 /** 30 * Cached array of the menus items. 31 * 32 * @var array 33 * @since 11.1 34 */ 35 protected static $items = null; 36 37 /** 38 * Get a list of the available menus. 39 * 40 * @return string 41 * 42 * @since 11.1 43 */ 44 public static function menus() 45 { 46 if (empty(self::$menus)) 47 { 48 $db = JFactory::getDbo(); 49 $query = $db->getQuery(true); 50 $query->select('menutype AS value, title AS text'); 51 $query->from($db->quoteName('#__menu_types')); 52 $query->order('title'); 53 $db->setQuery($query); 54 self::$menus = $db->loadObjectList(); 55 } 56 57 return self::$menus; 58 } 59 60 /** 61 * Returns an array of menu items grouped by menu. 62 * 63 * @param array $config An array of configuration options. 64 * 65 * @return array 66 */ 67 public static function menuitems($config = array()) 68 { 69 if (empty(self::$items)) 70 { 71 $db = JFactory::getDbo(); 72 $query = $db->getQuery(true); 73 $query->select('menutype AS value, title AS text'); 74 $query->from($db->quoteName('#__menu_types')); 75 $query->order('title'); 76 $db->setQuery($query); 77 $menus = $db->loadObjectList(); 78 79 $query->clear(); 80 $query->select('a.id AS value, a.title AS text, a.level, a.menutype'); 81 $query->from('#__menu AS a'); 82 $query->where('a.parent_id > 0'); 83 $query->where('a.type <> ' . $db->quote('url')); 84 $query->where('a.client_id = 0'); 85 86 // Filter on the published state 87 if (isset($config['published'])) 88 { 89 if (is_numeric($config['published'])) 90 { 91 $query->where('a.published = ' . (int) $config['published']); 92 } 93 elseif ($config['published'] === '') 94 { 95 $query->where('a.published IN (0,1)'); 96 } 97 } 98 99 $query->order('a.lft'); 100 101 $db->setQuery($query); 102 $items = $db->loadObjectList(); 103 104 // Collate menu items based on menutype 105 $lookup = array(); 106 foreach ($items as &$item) 107 { 108 if (!isset($lookup[$item->menutype])) 109 { 110 $lookup[$item->menutype] = array(); 111 } 112 $lookup[$item->menutype][] = &$item; 113 114 $item->text = str_repeat('- ', $item->level) . $item->text; 115 } 116 self::$items = array(); 117 118 foreach ($menus as &$menu) 119 { 120 // Start group: 121 self::$items[] = JHtml::_('select.optgroup', $menu->text); 122 123 // Special "Add to this Menu" option: 124 self::$items[] = JHtml::_('select.option', $menu->value . '.1', JText::_('JLIB_HTML_ADD_TO_THIS_MENU')); 125 126 // Menu items: 127 if (isset($lookup[$menu->value])) 128 { 129 foreach ($lookup[$menu->value] as &$item) 130 { 131 self::$items[] = JHtml::_('select.option', $menu->value . '.' . $item->value, $item->text); 132 } 133 } 134 135 // Finish group: 136 self::$items[] = JHtml::_('select.optgroup', $menu->text); 137 } 138 } 139 140 return self::$items; 141 } 142 143 /** 144 * Displays an HTML select list of menu items. 145 * 146 * @param string $name The name of the control. 147 * @param string $selected The value of the selected option. 148 * @param string $attribs Attributes for the control. 149 * @param array $config An array of options for the control. 150 * 151 * @return string 152 */ 153 public static function menuitemlist($name, $selected = null, $attribs = null, $config = array()) 154 { 155 static $count; 156 157 $options = self::menuitems($config); 158 159 return JHtml::_( 160 'select.genericlist', $options, $name, 161 array( 162 'id' => isset($config['id']) ? $config['id'] : 'assetgroups_' . ++$count, 163 'list.attr' => (is_null($attribs) ? 'class="inputbox" size="1"' : $attribs), 164 'list.select' => (int) $selected, 165 'list.translate' => false 166 ) 167 ); 168 } 169 170 /** 171 * Build the select list for Menu Ordering 172 * 173 * @param object &$row The row object 174 * @param integer $id The id for the row. Must exist to enable menu ordering 175 * 176 * @return string 177 * 178 * @since 11.1 179 */ 180 public static function ordering(&$row, $id) 181 { 182 $db = JFactory::getDbo(); 183 $query = $db->getQuery(true); 184 185 if ($id) 186 { 187 $query->select('ordering AS value, title AS text'); 188 $query->from($db->quoteName('#__menu')); 189 $query->where($db->quoteName('menutype') . ' = ' . $db->quote($row->menutype)); 190 $query->where($db->quoteName('parent_id') . ' = ' . (int) $row->parent_id); 191 $query->where($db->quoteName('published') . ' != -2'); 192 $query->order('ordering'); 193 $order = JHtml::_('list.genericordering', $query); 194 $ordering = JHtml::_( 195 'select.genericlist', $order, 'ordering', 196 array('list.attr' => 'class="inputbox" size="1"', 'list.select' => intval($row->ordering)) 197 ); 198 } 199 else 200 { 201 $ordering = '<input type="hidden" name="ordering" value="' . $row->ordering . '" />' . JText::_('JGLOBAL_NEWITEMSLAST_DESC'); 202 } 203 204 return $ordering; 205 } 206 207 /** 208 * Build the multiple select list for Menu Links/Pages 209 * 210 * @param boolean $all True if all can be selected 211 * @param boolean $unassigned True if unassigned can be selected 212 * 213 * @return string 214 * 215 * @since 11.1 216 */ 217 public static function linkoptions($all = false, $unassigned = false) 218 { 219 $db = JFactory::getDbo(); 220 $query = $db->getQuery(true); 221 222 // get a list of the menu items 223 $query->select('m.id, m.parent_id, m.title, m.menutype'); 224 $query->from($db->quoteName('#__menu') . ' AS m'); 225 $query->where($db->quoteName('m.published') . ' = 1'); 226 $query->order('m.menutype, m.parent_id, m.ordering'); 227 $db->setQuery($query); 228 229 $mitems = $db->loadObjectList(); 230 231 // Check for a database error. 232 if ($db->getErrorNum()) 233 { 234 JError::raiseNotice(500, $db->getErrorMsg()); 235 } 236 237 if (!$mitems) 238 { 239 $mitems = array(); 240 } 241 242 $mitems_temp = $mitems; 243 244 // Establish the hierarchy of the menu 245 $children = array(); 246 // First pass - collect children 247 foreach ($mitems as $v) 248 { 249 $pt = $v->parent_id; 250 $list = @$children[$pt] ? $children[$pt] : array(); 251 array_push($list, $v); 252 $children[$pt] = $list; 253 } 254 // Second pass - get an indent list of the items 255 $list = JHtmlMenu::TreeRecurse(intval($mitems[0]->parent_id), '', array(), $children, 9999, 0, 0); 256 257 // Code that adds menu name to Display of Page(s) 258 259 $mitems = array(); 260 if ($all | $unassigned) 261 { 262 $mitems[] = JHtml::_('select.option', '<OPTGROUP>', JText::_('JOPTION_MENUS')); 263 264 if ($all) 265 { 266 $mitems[] = JHtml::_('select.option', 0, JText::_('JALL')); 267 } 268 if ($unassigned) 269 { 270 $mitems[] = JHtml::_('select.option', -1, JText::_('JOPTION_UNASSIGNED')); 271 } 272 273 $mitems[] = JHtml::_('select.option', '</OPTGROUP>'); 274 } 275 276 $lastMenuType = null; 277 $tmpMenuType = null; 278 foreach ($list as $list_a) 279 { 280 if ($list_a->menutype != $lastMenuType) 281 { 282 if ($tmpMenuType) 283 { 284 $mitems[] = JHtml::_('select.option', '</OPTGROUP>'); 285 } 286 $mitems[] = JHtml::_('select.option', '<OPTGROUP>', $list_a->menutype); 287 $lastMenuType = $list_a->menutype; 288 $tmpMenuType = $list_a->menutype; 289 } 290 291 $mitems[] = JHtml::_('select.option', $list_a->id, $list_a->title); 292 } 293 if ($lastMenuType !== null) 294 { 295 $mitems[] = JHtml::_('select.option', '</OPTGROUP>'); 296 } 297 298 return $mitems; 299 } 300 301 /** 302 * Build the list representing the menu tree 303 * 304 * @param integer $id Id of the menu item 305 * @param string $indent The indentation string 306 * @param array $list The list to process 307 * @param array &$children The children of the current item 308 * @param integer $maxlevel The maximum number of levels in the tree 309 * @param integer $level The starting level 310 * @param string $type Type of link: component, URL, alias, separator 311 * 312 * @return array 313 * 314 * @since 11.1 315 */ 316 public static function treerecurse($id, $indent, $list, &$children, $maxlevel = 9999, $level = 0, $type = 1) 317 { 318 if (@$children[$id] && $level <= $maxlevel) 319 { 320 foreach ($children[$id] as $v) 321 { 322 $id = $v->id; 323 324 if ($type) 325 { 326 $pre = '<sup>|_</sup> '; 327 $spacer = '.      '; 328 } 329 else 330 { 331 $pre = '- '; 332 $spacer = '  '; 333 } 334 335 if ($v->parent_id == 0) 336 { 337 $txt = $v->title; 338 } 339 else 340 { 341 $txt = $pre . $v->title; 342 } 343 $pt = $v->parent_id; 344 $list[$id] = $v; 345 $list[$id]->treename = "$indent$txt"; 346 $list[$id]->children = count(@$children[$id]); 347 $list = JHtmlMenu::TreeRecurse($id, $indent . $spacer, $list, $children, $maxlevel, $level + 1, $type); 348 } 349 } 350 return $list; 351 } 352 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Apr 3 11:40:28 2012 | Cross-referenced by PHPXref 0.7.1 |