/** 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); }
/** 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, $plugins) { global $database; 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, 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); $isJ15 = defined('_JEXEC') && defined('JPATH_COMPONENT'); 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; } $node = new stdclass(); $node->id = $item->id; $node->uid = "item" . $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 if ($isJ15 && substr($item->link, 0, 9) == 'index.php') { $node->link = 'index.php?Itemid=' . $node->id; // For Joomla 1.5 SEF compatibility } else { $node->link = isset($item->link) ? htmlspecialchars($item->link) : ''; // convert link to valid xml } $this->printNode($node); XmapPlugins::printTree($this, $item, $cache, $plugins); // Determine the menu entry's type and call it's handler $this->printMenuTree($node, $cache, $plugins); } $this->changeLevel(-1); }