'header-image.tpl', ]; protected $_footer; protected $_hasLog = true; protected $_hasAnalyticsScripts = true; protected $_virtualMenu = []; 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->_initCheckoutFooter(); $this->_initSideBlockContent(); $this->_initSocialLinks(); $this->_initUserToolbar(); 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; } protected function _initSearchForm() { $item = []; $item['tpl'] = Qs_SiteMap::getTemplate('header-form.tpl', 'Search'); $item['id'] = 'header-search-form'; $item['action'] = Qs_SiteMap::findFirst(null, ['type' => 'Search\\'], null, 'fullAlias'); $item['query'] = Qs_Request::getGetValue('query', ''); $this->assign('SEARCH_FORM', $item); $params = ['elements' => [['selector' => '#' . $item['id'] . '-query', 'hint' => 'Search']]]; $this->addScript('js/jquery.defaultHint.js', [], 'defaultHint'); $this->addInitFunction('$("form#' . $item['id'] . '").defaultHint', [$params]); return $this; } protected function _initUserToolbar() { if (!class_exists('App\User\View')) { return $this; } if (!$this->getAuthIdentity()) { $this->_initLoginForm(); } else { if ($this->_hasLog) { $this->_log(); } $userMenu = $this->_getUserNavigationList(); if ($userMenu) { $this->assign('USER_MENU_ACCOUNT', array_shift($userMenu)); $this->assign('USER_MENU_SUBMENU', $userMenu); } } $this->_initShoppingCart(); $this->_initSearchForm(); $this->addScript('js/app/user-toolbar.js'); $this->addInitFunction('User_Toolbar.init'); return $this; } protected function _initShoppingCart() { if (!class_exists('App_ECommerce_Cart_Obj')) { return $this; } $cartUrl = Qs_SiteMap::findFirst( ['enabled' => 'y'], ['type' => 'ECommerce_Cart_'], ['type' => 'default'], 'url' ); if ($cartUrl) { $this->assign('CART_URL', $cartUrl); $cartObj = new App_ECommerce_Cart_Obj(); $cartObj->setPrimaryKey($cartObj->getCartId()); $this->assign('CART_ITEM_COUNT', (int) $cartObj->getItemsCount()); $domSelector = '#' . App_ECommerce_Cart_View::SHOPPING_CART_QUICK_LINK_ELEMENT_ID; $params = [ 'selector' => $domSelector, 'url' => $cartUrl, 'hasGtm' => $this->isGtmEnabled(), ]; $this->addScript('js/app/ECommerce/small-cart.js'); $this->addInitFunction('App_Cart_Small.init', [$params]); } return $this; } protected function _initLoginForm() { if (!class_exists('App\User\Login\View')) { return $this; } $view = new App\User\Login\View(); $view->setDoc($this); $form = $view->getShortLoginForm(); $form->prependId(); $form->initRender(); $this->assign('LOGIN_FORM', $form); 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 _getUserNavigationList() { $aliasArray = explode('/', Qs_SiteMap::findFirst('', 'fullAlias')); $rootAlias = array_shift($aliasArray); $menu = Qs_SiteMap::getFull(); $navigation = Qs_Array::get($menu, $rootAlias . '[sub]', []); Qs_Array::treeWalk($navigation, function (&$page) { if ($page['enabled'] == 'n' || $page['isAccountNavigation'] == 'n') { return false; } return true; }); return $navigation; } 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 _initSideBlockContent() { if (class_exists('App_SideBlock_View') && 'y' === $this->getOption('showSideBlock')) { $view = new App_SideBlock_View(); $view->setDoc($this); $view->exec(); } return $this; } 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('id'), $excludePages)) { $item = $this->_getHeaderImageItem(); $options = ['images' => $item['images']]; $this->addItem($item, 'TOP_ITEMS'); $this->addScript('js/app/doc/header-image.js'); $this->addReadyFunction('new app.HeaderImage', [$options]); } } 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; } protected function _initCheckoutFooter() { $sitemapParams = [ [null, ['type' => 'ECommerce_Cart_'], ['type' => 'default']], [null, ['type' => 'ECommerce_Checkout_'], null], [null, ['type' => 'ECommerce_Checkout_LoginBlock_'], null], ]; $currentId = $this->getOption('id'); foreach ($sitemapParams as $params) { $pages = call_user_func_array('Qs_SiteMap::find', $params); if ($pages) { $allowedIds = Qs_Array::fetchCol($pages, 'id'); if (in_array($currentId, $allowedIds)) { $this->assign('CHECKOUT_FOOTER', App_Settings_Obj::get('checkoutFooter')); break; } } } return $this; } /** * 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; } }