/** Get a Menu's tree * Get the complete list of menu entries where the menu is in $menutype. * If the component, that is linked to the menuentry, has a registered handler, * this function will call the handler routine and add the complete tree. * A tree with subtrees for each menuentry is returned. */ function printMenuTree(&$menu, &$cache, $extensions) { $database =& JFactory::getDBO(); if (strlen($menu->menutype) == 0) { $result = null; return $result; } $menuExluded = explode(',', $this->sitemap->exclmenus); // by mic: fill array with excluded menu IDs /* * noauth is true: - Will show links to registered content, even if the client is not logged in. - The user will need to login to see the item in full. * noauth is false: - Will show only links to content for which the logged in client has access. */ $sql = "SELECT m.id, m.name, m.parent, m.link, m.type, m.browserNav, m.menutype, m.ordering, m.params, m.componentid,m.home, c.name AS component" . "\n FROM #__menu AS m" . "\n LEFT JOIN #__components AS c ON m.type='components' AND c.id=m.componentid" . "\n WHERE m.published='1' AND m.parent=" . $menu->id . " AND m.menutype = '" . $menu->menutype . "'" . ($this->noauth ? '' : "\n AND m.access <= '" . $this->gid . "'") . "\n ORDER BY m.menutype,m.parent,m.ordering"; // Load all menuentries $database->setQuery($sql); $items = $database->loadObjectList(); if (count($items) <= 0) { //ignore empty menus $result = null; return $result; } $this->changeLevel(1); $router = JSite::getRouter(); foreach ($items as $i => $item) { // Add each menu entry to the root tree. $item->priority = @$menu->priority; $item->changefreq = @$menu->changefreq; if (in_array($item->id, $menuExluded)) { // ignore exluded menu-items continue; } if ($item->type == 'menulink') { $menu =& JSite::getMenu(); $params = new JParameter($item->params); if ($newItem = $menu->getItem($params->get('menu_item'))) { $item->type = $newItem->type; $item->id = $newItem->id; $item->parent = $newItem->parent; $item->link = $newItem->link; $item->home = $newItem->home; } } $node = new stdclass(); $node->id = $item->id; $node->uid = "itemid" . $item->id; $node->name = $item->name; // displayed name of node $node->parent = $item->parent; // id of parent node $node->browserNav = $item->browserNav; // how to open link $node->ordering = isset($item->ordering) ? $item->ordering : $i; // display-order of the menuentry $node->priority = $item->priority; $node->changefreq = $item->changefreq; $node->type = $item->type; // menuentry-type $node->menutype = $item->menutype; // menuentry-type $node->home = $item->home; // menuentry-type $node->link = isset($item->link) ? htmlspecialchars($item->link) : ''; if ($node->type == 'separator') { $node->browserNav = 3; } XmapPlugins::prepareMenuItem($node, $extensions); // Let's see if the extension wants to do somenthing with this node before it's printed if ($node->home) { $node->link = JURI::base(); } elseif (substr($item->link, 0, 9) == 'index.php' && $item->type != 'url' && $item->type != 'separator') { if (strpos($node->link, 'Itemid=') === FALSE) { $node->link = $router->getMode() == JROUTER_MODE_SEF ? 'index.php?Itemid=' . $node->id : $node->link . '&Itemid=' . $node->id; } } if ($this->printNode($node)) { if (preg_match('/option=(com_[a-z0-9_]+)/i', $item->link, $matches)) { // Set the uid of the node to the component uid after print it // so its children dont use a wrong uid # echo $node->uid = $matches[1]; } $this->printMenuTree($node, $cache, $extensions); XmapPlugins::printTree($this, $item, $cache, $extensions); // Determine the menu entry's type and call it's handler } } $this->changeLevel(-1); }
function &expandLink(&$parent,&$extensions) { $items = &JSite::getMenu(); $rows = null; if (strpos($parent->link,'-menu-') === 0 ) { $menutype = str_replace('-menu-','',$parent->link); // Get Menu Items $rows = $items->getItems('menutype', $menutype); } elseif ($parent->id) { $rows = $items->getItems('parent', $parent->id); } if ( $rows ) { $router = JSite::getRouter(); foreach ($rows as $item) { if ($item->parent == $parent->id) { $item->mid = $item->id; if ($item->type == 'menulink') { $menu = &JSite::getMenu(); $params = new JParameter($item->params); if ($newItem = $menu->getItem($params->get('menu_item'))) { $item->type = $newItem->type; $item->mid = $newItem->id; $item->parent = $newItem->parent; $item->link = $newItem->link; } } $node = new stdclass; $node->name = $item->name; $node->id = $item->id; $node->uid = 'itemid'.$item->id; $node->link = $item->link; $node->expandible = true; $node->selectable=true; // Prepare the node link XmapPlugins::prepareMenuItem($node,$extensions); if ( $item->home ) { $node->link = JURI::root(); } elseif (substr($item->link,0,9) == 'index.php' && $item->type != 'url' && $item->type != 'separator') { if ( strpos($node->link,'Itemid=') === FALSE ){ $node->link = $router->getMode() == JROUTER_MODE_SEF ? 'index.php?Itemid='.$node->id : $node->link.'&Itemid='.$node->id; } } $this->printNode($node); // Add to the internal list } } } if ($parent->id) { $option = null; if ( preg_match('#^/?index.php.*option=(com_[^&]+)#',$parent->link,$matches) ) { $option = $matches[1]; } $Itemid = JRequest::getInt('Itemid'); if (!$option && $Itemid) { $item = $items->getItem($Itemid); if ( preg_match('#^/?index.php.*option=(com_[^&]+)#',$item->link,$matches) ) { $option = $matches[1]; $parent->link = $item->link; } } if ( $option ) { if ( !empty($extensions[$option]) ) { $parent->uid = $option; $className = 'xmap_'.$option; $result = call_user_func_array(array($className, 'getTree'),array(&$this,&$parent,$extensions[$option]->getParams())); } } } return $this->_list;; }