/** * Returns new or existing Singleton instance * @return Singleton */ public static final function getInstance() { if (!isset(self::$instance)) { $c = __CLASS__; self::$instance = new $c(); } return self::$instance; }
function getUserAccessIds() { $siteHelper = de_siteof_exmenu_SiteHelper::getInstance(); if ($siteHelper->isJoomla16()) { $user = JFactory::getUser(); return $user->getAuthorisedViewLevels(); } else { // in Joomla 1.5 and below we only have a single user access id // this effectively means everything from 0 up to that id is included $id = 0; if (class_exists('JFactory')) { $user = JFactory::getUser(); if (is_object($user)) { $id = intval($user->get('aid')); } } else { if (isset($GLOBALS['my'])) { $user = $GLOBALS['my']; if (is_object($user)) { $id = intval($user->gid); } } } $result = array(); for ($currentId = 0; $currentId <= $id; $currentId++) { $result[] = $currentId; } return $result; } }
function render() { $params = $this->params; if (isset($GLOBALS['EXTENDED_MENU_OVERRIDE']) && is_array($GLOBALS['EXTENDED_MENU_OVERRIDE'])) { foreach ($GLOBALS['EXTENDED_MENU_OVERRIDE'] as $k => $v) { $params->set($k, $v); } } $this->siteHelper = de_siteof_exmenu_SiteHelper::getInstance(); $siteHelper = $this->siteHelper; $this->initDefaultParameters($params); $this->initMenuTemplate($params); $currentItemid = $siteHelper->getCurrentMenuId(); $menu_style = $params->get('menu_style', 'list_tree'); $menutype = $params->get('menutype'); $menu_source_type = $params->get('menu_source_type', 'menu'); $menu_source_value = trim($params->get('menu_source_value', '')); $menu_source_show_section = $params->get('menu_source_show_section', 'default'); $menu_source_show_category = $params->get('menu_source_show_category', 'default'); $menu_source_show_content_item = $params->get('menu_source_show_content_item', 'default'); $menu_source_order = $params->get('menu_source_order', 'ordering'); $defaultContentItemid = $params->get('default_content_itemid', ''); $maxDepth = intval($params->get('max_depth')) - 1; $minExpand = intval($params->get('expand_min')); $hideFirst = intval($params->get('hide_first')); $showParent = intval($params->get('show_parent')) == 1; $openActiveOnly = !$params->get('expand_menu'); $menuImages = $params->get('menu_images', 0); $parentMenuItem = trim($params->get('parent_item')); $currentLevelBegin = intval($params->get('current_level_begin')) == 1; $depthIndex = intval($params->get('level_begin')); $splitMenu = intval($params->get('split_menu')); $menuCount = intval($params->get('menu_count')); $queryCache = intval($params->get('query_cache')); $parseAccessKey = intval($params->get('parse_access_key')); $titleAttribute = intval($params->get('title_attribute')); $levelClass = intval($params->get('level_class')); $activeMenuClass = intval($params->get('active_menu_class')); $elementId = intval($params->get('element_id')); $callGetItemid = intval($params->get('call_getitemid', '1')) == 1; $currentItem = trim($params->get('current_item', 'smart')); $currentItemDuplicates = trim($params->get('current_item_duplicates', 'convert_active')); $accessKeys = trim($params->get('access_keys', '')); $exactAccessLevel = intval($params->get('exact_access_level', '')) == 1; if ($menuCount > 1) { $splitMenu = max(1, $splitMenu); } $view = ExtendedMenuViewFactory::getNewMenuView($menu_style); if ($view->maxDepth === 0) { // the factory limited the max depth of the view $maxDepth = 0; } if ($menu_style == 'patTemplate') { $view->patTemplateDirectory = $this->patTemplateDirectory; $view->patTemplateFile = $this->patTemplateFile; } // load the menu... $menuLoader = ExtendedMenuLoaderFactory::getNewMenuLoader($menu_source_type); $menuLoader->siteHelper = $this->siteHelper; $menuLoader->loadFirstLevelOnly = $maxDepth <= 0 && $activeMenuClass <= 0 && $queryCache <= 0 && $depthIndex == 0 && $menuCount <= 1 && $parentMenuItem == '' && !$currentLevelBegin; $menuLoader->menutype = $menutype; $menuLoader->activeMenuId = $currentItemid; $menuLoader->openActiveOnly = $openActiveOnly; $menuLoader->loadActiveOnly = $openActiveOnly && $parentMenuItem == ''; $menuLoader->maxDepth = $maxDepth; $menuLoader->minExpand = $minExpand; $menuLoader->parseAccessKey = $parseAccessKey; $menuLoader->cacheEnabled = $queryCache > 0; $menuLoader->currentItemid = $currentItemid; $menuLoader->defaultSectionItemid = $defaultContentItemid; $menuLoader->defaultCategoryItemid = $defaultContentItemid; $menuLoader->defaultContentItemid = $defaultContentItemid; $menuLoader->sectionOrder = $menu_source_order; $menuLoader->categoryOrder = $menu_source_order; $menuLoader->contentItemOrder = $menu_source_order; $menuLoader->sectionLinkEnabled = $menu_source_show_section != 'label'; $menuLoader->categoryLinkEnabled = $menu_source_show_category != 'label'; $menuLoader->contentItemLinkEnabled = $menu_source_show_content_item != 'label'; $menuLoader->sectionVisible = $menu_source_show_section != 'hide' && $menu_source_show_section != 'default'; $menuLoader->categoryVisible = $menu_source_show_category != 'hide' && $menu_source_show_category != 'default'; $menuLoader->contentItemVisible = $menu_source_show_content_item != 'hide'; $menuLoader->sectionHidden = $menu_source_show_section == 'hide'; $menuLoader->categoryHidden = $menu_source_show_category == 'hide'; $menuLoader->contentItemHidden = $menu_source_show_content_item == 'hide'; $menuLoader->smartItemidEnabled = $currentItem == 'smart'; $menuLoader->ignoreItemidEnabled = $currentItem == 'ignore_itemid'; $menuLoader->exactAccessLevel = $exactAccessLevel; $menuSourceShowExceptions = array('default', 'hide', 'label'); if (!in_array($menu_source_show_section, $menuSourceShowExceptions)) { $menuLoader->sectionLinkType = $menu_source_show_section; } if (!in_array($menu_source_show_category, $menuSourceShowExceptions)) { $menuLoader->categoryLinkType = $menu_source_show_category; } if (!in_array($menu_source_show_content_item, $menuSourceShowExceptions)) { $menuLoader->contentItemLinkType = $menu_source_show_content_item; } $menuSourceValues = $menu_source_value != '' ? explode(',', $menu_source_value) : array(); foreach (array_keys($menuSourceValues) as $key) { $menuSourceValues[$key] = trim($menuSourceValues[$key]); } $menuLoader->loadBySourceValues($menuSourceValues); switch ($currentItemDuplicates) { case 'convert_active': $menuLoader->checkCurrentItemDuplicates(TRUE); break; case 'convert_normal': $menuLoader->checkCurrentItemDuplicates(FALSE); break; } // initialize the menu view... $view->siteHelper = $this->siteHelper; $view->params = $params; $view->classSuffix = $params->get('class_suffix', $params->get('class_sfx')); $view->idSuffix = $params->get('id_suffix', $view->classSuffix); $view->imageEnabled = $menuImages != '0' && $menuImages != ''; if ($view->imageEnabled) { $view->imageAlignment = $menuImages; } $view->openActiveOnly = $openActiveOnly; $view->titleAttribute = $titleAttribute > 0; $view->mainlevelClass = $levelClass > 0; $view->sublevelClass = $levelClass > 0; $view->activeMenuClassLink = $activeMenuClass & 1; $view->activeMenuClassContainer = $activeMenuClass & 2; $view->hierarchyBasedIds = $elementId > 0; $view->callGetItemid = $callGetItemid; if ($currentLevelBegin) { $depthIndex += max(0, count($menuLoader->activeIds) - 1); } static $nullMenuNode = NULL; static $nullMenuNodeList = NULL; $isFirst = TRUE; for ($iMenu = 0; $iMenu < $menuCount; $iMenu++) { if ($splitMenu > 0) { $view->maxDepth = $splitMenu - 1; } else { $view->maxDepth = $maxDepth; } $menuNode = $nullMenuNode; if ($parentMenuItem != '') { if ('' . intval($parentMenuItem) == $parentMenuItem) { $parentMenuItem = intval($parentMenuItem); $menuNode = $menuLoader->getMenuItemById($parentMenuItem); } else { $menuNode = $menuLoader->getMenuItemByName($parentMenuItem); } if (!is_null($menuNode)) { if ($depthIndex > 0) { $tempMenuNode = $menuLoader->getMenuItemByMenuNodeAndLevel($menuNode, $depthIndex); $menuNode = $tempMenuNode; } if (is_null($menuNode)) { break; // no more menu items } $menuNodeList = $menuNode->getChildNodeList(); } else { echo 'parent menu item not found: "' . $parentMenuItem . '"'; $menuNodeList = $nullMenuNodeList; } } else { if ($depthIndex > 0) { $menuNode = $menuLoader->getMenuItemByLevel($depthIndex); if (is_null($menuNode)) { break; // no more menu items } $menuNodeList = $menuNode->getChildNodeList(); } else { $menuNodeList = $menuLoader->getMenuNodeList(); } } if ($showParent) { $view->maxDepth++; $list = array(); if (!is_null($menuNode)) { $list[] = $menuNode; } else { $rootMenuNode = $menuLoader->getRootMenuNode(); $node = $menuLoader->getEmptyMenuNode(); $node->setCaption($rootMenuNode->getCaption()); $node->addChildNodes($menuNodeList); $node->setExpanded(TRUE); $list[] = $node; } $menuNodeList = $list; } if (count($menuNodeList) == 0) { // echo 'menu list empty'; break; } $view->menuHierarchy = $menuLoader->getHierarchy($depthIndex); $view->menuLevel = $depthIndex; if ($hideFirst == 1 && $iMenu == 0) { $menuNodeList2 = $menuNodeList; array_shift($menuNodeList2); $menuNodeList = $menuNodeList2; } if ($isFirst) { $this->applyAccessKeys($menuLoader, $menuNodeList, $accessKeys); $isFirst = FALSE; } echo $view->renderAsString($menuNodeList, 0); $depthIndex += $view->maxDepth + 1; if ($showParent) { $depthIndex--; } } $menuLoader->freeAll(); }
function getContentItemOrderBy($namePrefix = '') { $orderBy = array(); switch ($this->order) { case 'ordering': $orderBy[] = $namePrefix . 'ordering'; break; case 'ordering_desc': $orderBy[] = $namePrefix . 'ordering DESC'; break; case 'time': $siteHelper = de_siteof_exmenu_SiteHelper::getInstance(); $orderBy[] = $namePrefix . 'modified'; $orderBy[] = $namePrefix . 'created'; if ($siteHelper->isJoomla16()) { $orderBy[] = $namePrefix . 'lft'; } else { $orderBy[] = $namePrefix . 'ordering'; } break; case 'time_desc': $siteHelper = de_siteof_exmenu_SiteHelper::getInstance(); $orderBy[] = $namePrefix . 'modified DESC'; $orderBy[] = $namePrefix . 'created DESC'; if ($siteHelper->isJoomla16()) { $orderBy[] = $namePrefix . 'lft'; } else { $orderBy[] = $namePrefix . 'ordering'; } break; default: $orderBy = $this->getOrderBy($this->order, $namePrefix); } return $orderBy; }