sPageName = ''; $this->aVisible = array( BX_DOL_STUDIO_MT_LEFT => getParam('sys_std_show_header_left') == 'on', BX_DOL_STUDIO_MT_CENTER => getParam('sys_std_show_header_center') == 'on', BX_DOL_STUDIO_MT_RIGHT => getParam('sys_std_show_header_right') == 'on', ); $this->aSelected = array( BX_DOL_STUDIO_MT_LEFT => '', BX_DOL_STUDIO_MT_CENTER => '', BX_DOL_STUDIO_MT_RIGHT => '' ); $this->aItems = array( BX_DOL_STUDIO_MT_LEFT => '', BX_DOL_STUDIO_MT_CENTER => '', BX_DOL_STUDIO_MT_RIGHT => '' ); $this->aItems[BX_DOL_STUDIO_MT_LEFT] = BxTemplStudioFunctions::getInstance()->getLogo(); $this->aItems[BX_DOL_STUDIO_MT_CENTER] = [ 'template' => 'menu_top_center.html', 'menu_items' => [] ]; $this->aItems[BX_DOL_STUDIO_MT_CENTER]['menu_items'] = []; if(!$this->aVisible[BX_DOL_STUDIO_MT_LEFT]) $this->aItems[BX_DOL_STUDIO_MT_CENTER]['menu_items']['launcher'] = [ 'name' => 'launcher', 'icon' => 'wi-home.svg', 'link' => '{url_studio}', 'title' => '_adm_tmi_cpt_launcher' ]; //--- Get Featured $aMenuItems = array(); $oRolesUtils = BxDolStudioRolesUtils::getInstance(); $oWidgetsDb = BxDolStudioWidgetsQuery::getInstance(); // Every app in the dock carries its context menu trigger (studio/js/context_menu.js loads the menu on first use). $fContextAttrs = function($sPageName, $iWidgetId = 0) { return 'data-bx-context-menu="#bx-std-cmenu-' . $sPageName . '" data-bx-context-menu-load="' . $sPageName . ':' . (int)$iWidgetId . '"'; }; $aFeatured = $oWidgetsDb->getWidgets(array('type' => 'all_featured', 'featured' => 1)); $aFeatured = array_column($aFeatured, null, 'page_name'); foreach($aFeatured as $aItem) if(empty($aItem['type']) || $oRolesUtils->isActionAllowed('use ' . $aItem['type'])) $aMenuItems[$aItem['page_name']] = array( 'class' => 'bx-menu-item-static', 'name' => $aItem['page_name'], 'icon' => $aItem['icon'], 'link' => $aItem['url'], 'onclick' => $aItem['click'], 'title' => $aItem['caption'], 'attrs_add' => $fContextAttrs($aItem['page_name'], $aItem['id']) ); //--- Get Bookmarks $aBookmarks = $oWidgetsDb->getWidgets(array('type' => 'all_bookmarks', 'bookmark' => 1, 'profile_id' => bx_get_logged_profile_id())); foreach($aBookmarks as $aBookmark) { if(array_key_exists($aBookmark['page_name'], $aMenuItems)) continue; $aFeatured[$aBookmark['page_name']] = $aBookmark; // the module lookup below reads it like a featured row if(!empty($aBookmark['type']) && !$oRolesUtils->isActionAllowed('use ' . $aBookmark['type'])) continue; $aMenuItems[$aBookmark['page_name']] = array( 'class' => 'bx-menu-item-static', 'name' => $aBookmark['page_name'], 'icon' => $aBookmark['icon'], 'link' => $aBookmark['url'], 'onclick' => $aBookmark['click'], 'title' => $aBookmark['caption'], 'attrs_add' => $fContextAttrs($aBookmark['page_name'], $aBookmark['id']) ); } $bStatic = !empty($aMenuItems); $aMenuItems['divider'] = [ 'class' => 'bx-menu-item-divider', 'name' => 'divider', 'icon' => '', 'link' => '', 'onclick' => '', 'title' => '' ]; //--- Get History $bHistory = false; $aHistory = self::historyGetList(); if(!empty($aHistory) && is_array($aHistory)) foreach($aHistory as $sPageName => $aMenuItem) { if(array_key_exists($sPageName, $aMenuItems)) continue; $aMenuItem['class'] = 'bx-menu-item-dynamic'; $aMenuItem['attrs_add'] = $fContextAttrs($sPageName); $aMenuItems[$sPageName] = $aMenuItem; $bHistory = true; } // A disabled app is dimmed in the dock as it is in the launcher (the widget rows carry the module; history rows are looked up by page). $oModuleQuery = BxDolModuleQuery::getInstance(); $oPageQuery = BxDolStudioPageQuery::getInstance(); foreach($aMenuItems as $sPageName => &$aMenuItem) { if(in_array($sPageName, ['divider', 'launcher'])) continue; $sModule = ''; if(isset($aFeatured[$sPageName]['module'])) $sModule = $aFeatured[$sPageName]['module']; else if(($aPage = $oPageQuery->getPages(['type' => 'by_page_name_full', 'value' => $sPageName])) && !empty($aPage['wid_module'])) $sModule = $aPage['wid_module']; if(!$sModule) continue; $aModule = $oModuleQuery->getModuleByName($sModule); if(!empty($aModule) && is_array($aModule) && (int)$aModule['enabled'] == 0) $aMenuItem['class_add'] = 'bx-menu-item-disabled'; } unset($aMenuItem); // The divider only makes sense between two groups: drop it while either side is empty (e.g. right after install). if(!$bStatic || !$bHistory) unset($aMenuItems['divider']); if(!empty($aMenuItems) && is_array($aMenuItems)) { if(count($aMenuItems) > BxTemplStudioMenuTop::$iToolbarLength) $aMenuItems = array_slice($aMenuItems, 0, BxTemplStudioMenuTop::$iToolbarLength); if(array_key_last($aMenuItems) == 'divider') unset($aMenuItems['divider']); if(($sKey = 'launcher') && isset($this->aItems[BX_DOL_STUDIO_MT_CENTER]['menu_items'][$sKey])) $this->aItems[BX_DOL_STUDIO_MT_CENTER]['menu_items'] = bx_array_insert_after($aMenuItems, $this->aItems[BX_DOL_STUDIO_MT_CENTER]['menu_items'], $sKey); else $this->aItems[BX_DOL_STUDIO_MT_CENTER]['menu_items'] = $aMenuItems; } } public static function getInstance() { if (!isset($GLOBALS['bxDolClasses']['BxBaseStudioMenuTop'])) $GLOBALS['bxDolClasses']['BxBaseStudioMenuTop'] = new BxTemplStudioMenuTop(); return $GLOBALS['bxDolClasses']['BxBaseStudioMenuTop']; } public static function historyGetList() { $aHistory = BxDolSession::getInstance()->getValue(self::$sHistorySessionKey); if(empty($aHistory) || !is_array($aHistory)) return array(); if(count($aHistory) > BxTemplStudioMenuTop::$iHistoryLength) $aHistory = array_slice($aHistory, -BxTemplStudioMenuTop::$iHistoryLength); return array_reverse($aHistory); } public static function historyAdd($aPage) { $oSession = BxDolSession::getInstance(); $aHistory = $oSession->getValue(self::$sHistorySessionKey); if(!empty($aHistory) && isset($aHistory[$aPage['name']])) return; if (!is_array($aHistory)) $aHistory = []; $aHistory[$aPage['name']] = array( 'name' => $aPage['name'], 'icon' => $aPage['wid_icon'], 'link' => $aPage['wid_url'], 'onclick' => $aPage['wid_click'], 'title' => $aPage['wid_caption'] ); if(count($aHistory) > BxTemplStudioMenuTop::$iHistoryLength) $aHistory = array_slice($aHistory, -BxTemplStudioMenuTop::$iHistoryLength); $oSession->setValue(self::$sHistorySessionKey, $aHistory); } public static function historyDelete($mixedPage) { if(is_array($mixedPage)) { if(!isset($mixedPage['name'])) return; $mixedPage = $mixedPage['name']; } $oSession = BxDolSession::getInstance(); $aHistory = $oSession->getValue(self::$sHistorySessionKey); if(empty($aHistory) || !isset($aHistory[$mixedPage])) return; unset($aHistory[$mixedPage]); $oSession->setValue(self::$sHistorySessionKey, $aHistory); } public function setPageName($sName) { $this->sPageName = $sName; } public function setContent($sPosition, $mixedContent) { $this->aItems[$sPosition] = $mixedContent; } public function setSelected($sPosition, $sValue) { if(!isset($this->aItems[$sPosition]['menu_items'][$sValue])) return; $this->aItems[$sPosition]['menu_items'][$sValue]['selected'] = true; } public function setVisible($sPosition, $bValue = true) { $this->aVisible[$sPosition] = $bValue; } public function setVisibleAll($bValue = true) { $this->aVisible = array( BX_DOL_STUDIO_MT_LEFT => $bValue, BX_DOL_STUDIO_MT_CENTER => $bValue, BX_DOL_STUDIO_MT_RIGHT => $bValue ); } } /** @} */