'header-image.tpl' ); protected $_footer; protected $_hasLog = true; protected $_hasAnalyticsScripts = true; protected $_virtualMenu = array(); protected function _init() { parent::_init(); /** * якщо сторінка не вимагає авторизації але в системі є залогінений юзер, * то треба його повторно автинтифікувати, робиться для того щоб перевірити * чи юзера не заблокували чи видалили */ if (!$this->isPagePreviewMode() && !$this->_hasAuthentication && $this->hasAuth() && $this->getAuth()->hasIdentity() ) { $this->authenticate(); } return $this; } protected function _beforeDisplay() { $this->_init3rdPartyWidgets(); \App\BrowserCheck\View::initAlert(); \App\Cms\Preview\View::initAlert(); $list = Qs_Language::getList(); if (count($list) > 1) { $this->assign('LANGUAGES', $list); } $this->_initHeaderImage(); $this->_initSocialLinks(); return parent::_beforeDisplay(); } protected function _init3rdPartyWidgets() { $placement = App_Settings_Obj::get('widgetCodePlacement'); $html = App_Settings_Obj::get('widgetCodeHtml'); $html = trim($html); if (empty($placement) || empty($html)) { return $this; } $this->setWidgets([$placement => $html]); return $this; } protected function _log() { if ($this->_hasLog && Qs_ViewController_Log::getEnabled()) { $logOptions = [ 'role' => $this->getAuth()->getRole(), 'roleId' => $this->getAuthData('id'), 'sessionId' => Zend_Session::getId(), 'ip' => $_SERVER['REMOTE_ADDR'], 'controller' => 'App_Cms_View', 'config' => Qs_Application::getConfig('Doc'), ]; if ($this->_options['id']) { $logOptions['objectId'] = $this->_options['id']; } $log = new Qs_ViewController_Log($logOptions); $log->write('view', ['itemTitle' => strip_tags($this->_getHeadPart('title'))]); } return $this; } public function getCacheObj($frontend = null, $backend = null) { if (null === $frontend) { $frontend = ['lifetime' => 7200, 'automatic_serialization' => true]; } if (null === $backend) { $backend = ['cache_dir' => BASE_PATH . '/tmp/cache']; } return Zend_Cache::factory('Core', 'File', $frontend, $backend); } protected function _initFooter() { $footerMenu = false; if (Qs_Application::getConfig('Doc')->hasFooterMenu) { $siteMap = $this->getFooter(); if (!empty($siteMap)) { $footerMenu = []; $footerMenu['tpl'] = $this->getTemplate('footer-menu.tpl'); $footerMenu['simpleFooterMenu'] = Qs_Application::getConfig('Doc')->simpleFooterMenu; $footerMenu['siteMap'] = $siteMap; $footerMenu = new Qs_Doc_Item($footerMenu); } } $this->assign('FOOTER_MENU', $footerMenu); return parent::_initFooter(); } public function getMenu() { if (null === $this->_content['menu']) { $menu = Qs_SiteMap::getMenu(); if ($this->_virtualMenu) { $menu = Qs_Array::mergeRecursive($menu, $this->_virtualMenu); } if (Qs_Device::isTouchscreen()) { Qs_SiteMap::prepareMobileMenu($menu); } $this->_content['menu'] = $menu; } return $this->_content['menu']; } /** * Return footer menu items * * @return array */ public function getFooter() { if (null === $this->_footer) { $this->_footer = Qs_SiteMap::getFooter(); } return $this->_footer; } protected function _initSocialLinks() { if (class_exists('App_SocialLink_View') && Qs_Application::getConfig('SocialLink')->get('enabled')) { $linksView = new App_SocialLink_View(); $this->assign('SOCIAL_LINKS', $linksView->getItem()); } return $this; } protected function _initHeaderImage() { if ($this->getCmsConfig()->get('hasHeaderImage')) { $excludePages = App_Cms_Obj::getImageHeaderExcludePageIds(); if (!in_array($this->getOption('idPage'), $excludePages)) { $item = $this->_getHeaderImageItem(); $this->addItem($item, 'TOP_ITEMS'); $this->addScript('js/app/doc/header-image.js'); $this->addReadyFunction('new app.HeaderImage', array($item)); } } return $this; } public function getCmsConfig() { return Qs_Application::getConfig('cms'); } protected function _getHeaderImageItem() { $item = $this->_headerImageItem; if (!is_array($item)) { $item = []; } if (!isset($item['tpl'])) { $item['tpl'] = $this->getTemplate($item['templateName']); } $image = $this->_getHeaderImage(); if (!$image) { $image = 'images/default-header.jpg'; } $config = $this->getCmsConfig(); $item['config'] = $config->toArray(); $screenWidth = 0; $screenWidthList = [320, 560, 767, 960, 1920]; foreach ($screenWidthList as $width) { $height= round($width * $config->headerImageHeight / $config->headerImageWidth); $screenImage = Qs_ImageFs::get($image, $width, $height, $config->headerImageResizeMethod); $item['images'][$screenWidth] = BASE_URL . '/' . $screenImage; $screenWidth = $width; } return $this->_headerImageItem = $item; } public function addHeaderImageItemOptions(array $options) { $this->_headerImageItem = array_merge($this->_headerImageItem, $options); return $this; } public function setHeaderImageItem($field = null, $value = null) { if (is_array($field)) { $this->_headerImageItem = $field; } else { Qs_Array::set($this->_headerImageItem, $field, $value); } return $this; } protected function _getHeaderImage($idPage = null) { if (null == $idPage) { $image = $this->getOption('headerImage'); $idParent = $this->getOption('idParent'); } else { $meta = App_Cms_Obj::getInstance()->getMeta($idPage); $image = $meta['headerImage']; $idParent = $meta['idParent']; } if (empty($image) && !empty($idParent)) { $image = $this->_getHeaderImage($idParent); } return $image; } /** * Set virtual items for main menu * * @param array $items * @return App_Doc_SIte */ public function setVirtualMenu($items) { if (!empty($items)) { foreach ($items as $key => $instanceName) { $virtualConfig = null; if (is_array($instanceName)) { $virtualConfig = $instanceName; $instanceName = $key; } $viewInstanceName = 'App_' . $instanceName . 'View'; if (class_exists($viewInstanceName)) { /** @var $view Qs_ViewController */ $view = new $viewInstanceName(); $view->setDoc($this); if (method_exists($view, 'getMenu')) { $mainAlias = Qs_SiteMap::find( ['enabled' => 'y'], ['type' => $instanceName], $virtualConfig, 'alias' ); if ($mainAlias) { $virtualItems = $view->getMenu(); if (!empty($virtualItems)) { $virtual = [$mainAlias => ['sub' => $virtualItems]]; $this->_virtualMenu = Qs_Array::mergeRecursive($this->_virtualMenu, $virtual); } } } else { Qs_Debug::log('Method getMenu not exist in ' . $viewInstanceName . ' class for virtual menu'); } } else { Qs_Debug::log('Class ' . $viewInstanceName . ' not exist for virtual menu'); } } $this->_content['menu'] = null; } return $this; } }