'header-image.tpl' ); protected $_footer; protected $_hasLog = true; protected $_hasAnalyticsScripts = true; protected $_virtualMenu = array(); protected function _init() { parent::_init(); return $this; } protected function _beforeDisplay() { \App\BrowserCheck\View::initAlert(); $list = Qs_Db_Language::getList(); if (count($list) > 1) { $this->assign('LANGUAGES', $list); } $this->_initHeaderImage(); $this->_initSideBlockContent(); $this->_initSocialLinks(); return parent::_beforeDisplay(); } protected function _log() { $logOptions = array( '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', array('itemTitle' => strip_tags($this->_getHeadPart('title')))); return $this; } protected function _initSearchForm() { $item = array(); $item['tpl'] = Qs_SiteMap::getTemplate('header-form.tpl', 'Search'); $item['id'] = 'header-search-form'; $item['action'] = Qs_SiteMap::findFirst(null, array('type' => 'Search\\'), null, 'fullAlias'); $item['query'] = Qs_Request::getGetValue('query', ''); $this->assign('SEARCH_FORM', $item); $params = array('elements' => array(array('selector' => '#' . $item['id'] . '-query', 'hint' => 'Search'))); $this->addScript('js/jquery.defaultHint.js', array(), 'defaultHint'); $this->addInitFunction ('$("form#' . $item['id'] . '").defaultHint', array($params)); return $this; } protected function _initUserToolbar() { 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() { $cartUrl = Qs_SiteMap::findFirst( array('enabled' => 'y'), array('type' => 'ECommerce_Cart_'), array('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 = array( 'selector' => $domSelector, 'url' => $cartUrl, 'hasGtm' => $this->isGtmEnabled() ); $this->addScript('js/app/ECommerce/small-cart.js'); $this->addInitFunction('App_Cart_Small.init', array($params)); } return $this; } protected function _initLoginForm() { $view = new App\User\Login\View(); $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 = array('lifetime' => 7200, 'automatic_serialization' => true); } if (null === $backend) { $backend = array('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 = array(); $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 (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 = array(); } 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 = array(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 = array( array(null, array('type' => 'ECommerce_Cart_'), array('type' => 'default')), array(null, array('type' => 'ECommerce_Checkout_'), null), array(null, array('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( array('enabled' => 'y'), array('type' => $instanceName), $virtualConfig, 'alias' ); if ($mainAlias) { $virtualItems = $view->getMenu(); if (!empty($virtualItems)) { $virtual = array($mainAlias => array('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; } }