function getInput() { $db =& JFactory::getDBO(); $version = new JVersion(); $odering = ", m.ordering"; if ($version->RELEASE >= '3.0') { $odering = ""; } $query = 'SELECT m.id, m.parent_id, m.title, m.menutype' . ' FROM #__menu AS m' . ' WHERE m.published = 1' . ' ORDER BY m.menutype, m.parent_id ' . $odering; $db->setQuery($query); $mitems = $db->loadObjectList(); $mitems_temp = $mitems; $children = array(); foreach ($mitems as $v) { $id = $v->id; $pt = $v->parent_id; $list = @$children[$pt] ? $children[$pt] : array(); array_push($list, $v); $children[$pt] = $list; } $list = JHTMLMenu::TreeRecurse(intval($mitems[0]->parent_id), '', array(), $children, 9999, 0, 0); $mitems_spacer = $mitems_temp[0]->menutype; $mitems = array(); if (@$all | @$unassigned) { $mitems[] = JHTML::_('select.option', '<OPTGROUP>', JText::_('Menus')); if ($all) { $mitems[] = JHTML::_('select.option', 0, JText::_('All')); } if ($unassigned) { $mitems[] = JHTML::_('select.option', -1, JText::_('Unassigned')); } $mitems[] = JHTML::_('select.option', '</OPTGROUP>'); } $lastMenuType = null; $tmpMenuType = null; foreach ($list as $list_a) { if ($list_a->menutype != $lastMenuType) { if ($tmpMenuType) { $mitems[] = JHTML::_('select.option', '</OPTGROUP>'); } $mitems[] = JHTML::_('select.option', '<OPTGROUP>', $list_a->title); $lastMenuType = $list_a->menutype; $tmpMenuType = $list_a->menutype; } $mitems[] = JHTML::_('select.option', $list_a->id, $list_a->treename); } if ($lastMenuType !== null) { $mitems[] = JHTML::_('select.option', '</OPTGROUP>'); } $result = JHTML::_('select.genericlist', $mitems, $this->name . '[]', 'class="inputbox" size="15" multiple="multiple"', 'value', 'text', $this->value); return $result; }
function treerecurse($id, $indent, $list, &$children, $maxlevel = 9999, $level = 0, $type = 1) { if (@$children[$id] && $level <= $maxlevel) { foreach ($children[$id] as $v) { $id = $v->id; if ($type) { $pre = '<sup>|_</sup> '; $spacer = '. '; } else { $pre = '- '; $spacer = ' '; } if ($v->parent == 0) { $txt = $v->name; } else { $txt = $pre . $v->name; } $pt = $v->parent; $list[$id] = $v; $list[$id]->treename = "{$indent}{$txt}"; $list[$id]->children = count(@$children[$id]); $list = JHTMLMenu::TreeRecurse($id, $indent . $spacer, $list, $children, $maxlevel, $level + 1, $type); } } return $list; }