setSuModeOff(); } $this->setSuModeOn(); } if ($this->getAuth()->getSuMode()) { $this->setBodyAttrib('class', 'su'); } if (App\Acl\Permission::isTribalAccount()) { $this->initTribalData(); } $this->initFirstAllowedPageUrl(); App_Sitemap_Xml_Writer::removeFiles(); return $this; } protected function initFirstAllowedPageUrl() { if (!($firstAllowedPage = App\Acl\Permission::getFirstAllowedPageUrl())) { $firstAllowedPage = Qs_SiteMap::findFirst(['handler' => 'admin'], array('type' => 'Item_'), null, 'url'); } $this->getSmarty()->assign('FIRST_ALLOWED_PAGE_URL', $firstAllowedPage); } protected function initTribalData() { $tribeData = (new App\Tribe\Obj())->setPrimaryKey(App\Acl\Permission::getAdminTribeId())->getData(); $this->getSmarty()->assign('TRIBE_INFO', $tribeData); return $this; } public function renderPageItems($items) { if (!$this->getAuth()->getSuMode()) { if (!$this->_isPageAllowed()) { $errorMsg = (App\Acl\Permission::isTribalAccount()) ? App\TribalAccount\Acl::FORBIDDEN_MSG : App_Admin_Acl::FORBIDDEN_MSG; $this->displayError($errorMsg); return $this; } } return parent::renderPageItems($items); } public function getPageAclResourceIds($pageOptions = null) { $aclResourceField = (App\Acl\Permission::isTribalAccount()) ? 'aclResourceId4TribalAccounts' : 'aclResourceId'; $aclResourceIds = ($pageOptions) ? Qs_Array::get((array) $pageOptions, $aclResourceField) : $this->getOption($aclResourceField); return array_filter(explode(';', $aclResourceIds)); } protected function _isPageAllowed() { $aliasParts = explode('/', $this->getOption('fullAlias')); $count = count($aliasParts); for ($i = 0; $i < $count; $i++) { $pageAlias = implode('/', $aliasParts); if ($page = Qs_SiteMap::getPage($pageAlias)) { $pageAclResourceIds = $this->getPageAclResourceIds($page); $hasAccess = (App\Acl\Permission::isTribalAccount()) ? \App\TribalAccount\Acl::isAccessTo($pageAclResourceIds) : App_Admin_Acl::isAccessTo($pageAclResourceIds); if (App\Acl\Permission::isResourceBlocked($pageAclResourceIds) || ($pageAclResourceIds && !$hasAccess)) { return false; } } array_pop($aliasParts); } return true; } public function setHasAuthentication($value) { return $this->setAuthentication($value); } public function setSuModeOn() { $this->getAuth()->setSuMode(); $this->setRedirectMessage('Su Mode Enabled'); $url = Qs_Request::getUrlExclude('su'); Qs_Http::redirect($url); return $this; } public function setRedirectMessage($text) { $session = new Qs_Session_Namespace(Qs_Constant::get('CURRENT_PAGE'), true); $session->message = $text; $session->setExpirationHops(1, 'message'); return $this; } public function setSuModeOff() { $this->getAuth()->setSuMode(false); $this->setRedirectMessage('Su Mode Disabled'); $url = Qs_Request::getUrlExclude('su'); Qs_Http::redirect($url); return $this; } protected function _beforeDisplay() { $this->sendNoindexHeader(); \App\BrowserCheck\View::initAlert(); parent::_beforeDisplay(); $this->_initSTSAuthLink(); $this->_initKeepSession(); return $this; } public function getMenu() { if (null === $this->_content['menu']) { $this->_content['menu'] = Qs_SiteMap::getBackendMenu(); if (false === $this->getAuth()->getSuMode()) { $this->_prepareMenu4Acl($this->_content['menu']); $this->_prepareMenuItemUrl($this->_content['menu']); } } return $this->_content['menu']; } protected function _initKeepSession() { $interval = (int) Qs_Constant::get('SESSION_REFRESH_INTERVAL'); if ($interval) { $this->addScript('js/lib/keep-session.js') ->addInlineScript( 'keepSession', '$(document).ready(function(){ keepSession = new Qs_KeepSession(); keepSession.setInterval(' . $interval . '); keepSession.setUrl("' . BASE_URL_LANGUAGE . '/admin/__keep-session"); keepSession.start(); }); '); } return $this; } protected function _initSTSAuthLink() { if (class_exists('App_Admin_StsAuth_View') && class_exists('App_Admin_StsAuth_Obj') && (null != ($alias = Qs_SiteMap::getAliasByItem('Admin_StsAuth_'))) ) { $textLink = App_Settings_Obj::get('stsAuthLink'); $stsObj = new App_Admin_StsAuth_Obj(); if ($alias && $textLink && ($stsObj->getStsLoginEnabled() == 'y')) { $this->assign('STS_AUTH_LINK', str_replace('{url}', BASE_URL_LANGUAGE . '/' . $alias, $textLink)); } } return $this; } protected function _getFooterPlaceholders() { $data = parent::_getFooterPlaceholders(); $data['widgets'] = ' '; return $data; } protected function _prepareCtrlMenu(array &$menu, array $filter) { parent::_prepareCtrlMenu($menu, $filter); if (false === $this->getAuth()->getSuMode()) { $this->_prepareMenu4Acl($menu); } return $this; } protected function _prepareMenu4Acl(array &$menu) { foreach ($menu as $key => &$item) { $aclResourceIds = $this->getPageAclResourceIds($item); $hasAccess = (App\Acl\Permission::isTribalAccount()) ? \App\TribalAccount\Acl::isAccessTo($aclResourceIds) : App_Admin_Acl::isAccessTo($aclResourceIds); if (App\Acl\Permission::isResourceBlocked($aclResourceIds) || ($aclResourceIds && !$hasAccess)) { unset($menu[$key]); } if (!empty($item['sub'])) { $this->_prepareMenu4Acl($item['sub']); } } return $this; } protected function _prepareMenuItemUrl(array &$menu) { foreach ($menu as $key => &$item) { if (!empty($item['sub'])) { $item['url'] = Qs_Array::get((array) reset($item['sub']), 'url'); } } } }