'header-image.tpl' ); protected $_footer; protected $_hasLog = true; protected $_virtualMenu = array(); protected $_backgroundImageItem; protected function _init() { parent::_init(); /** * якщо сторінка не вимагає авторизації але в системі є залогінений юзер, * то треба його повторно автинтифікувати, робиться для того щоб перевірити * чи юзера не заблокували чи видалили */ if (!$this->_hasAuthentication && $this->getAuth()->hasIdentity()) { $this->authenticate(); } 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->_initBackgroundImage(); $this->_initCheckoutFooter(); $this->_initSideBlockContent(); $this->_initUserToolbar(); $this->_initSubPageTabs(); 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() { if (App_Settings_Obj::get('googleSearchEngineId')) { $item = array(); $item['tpl'] = Qs_SiteMap::getTemplate('form.tpl', 'GSResults'); $item['id'] = 'header-search-form'; $item['action'] = Qs_SiteMap::findFirst(null, array('type' => 'GSResults\\'), null, 'fullAlias'); $item['q'] = Qs_Request::getGetValue('q', ''); $this->assign('SEARCH_FORM', $item); $params = array( 'elements' => array(array('selector' => '#' . $item['id'] . '-query', 'hint' => 'Site Search')) ); $this->addScript('js/jquery.defaultHint.js', array(), 'defaultHint'); $this->addInitFunction ('$("form#' . $item['id'] . '").defaultHint', array($params)); } return $this; } protected function _initSubPageTabs() { if (($mode = $this->getOption('xTabs')) && 'subPages' == $mode) { $pages = Qs_SiteMap::find(['idParent' => $this->getOption('id')]); } elseif (($parent = Qs_SiteMap::findFirst(['id' => $this->getOption('idParent')])) && array_key_exists('xTabs', $parent) && ($mode = $parent['xTabs']) && 'subPages' == $mode ) { $pages = Qs_SiteMap::find(['idParent' => $parent['id']]); if ($parent['header']) { $this->setHeader($parent['header'] . ': ' . $this->getHeader()); } } if (!empty($pages)) { $item = [ 'subPageUrls' => Qs_Array::fetchPairs($pages, ['title', 'url']), 'tpl' => $this->getTemplate('subpages-tab.tpl') ]; $this->addItemFirst($item); } return $this; } private function addItemFirst($item) { $groupName = $this->getGroupName(); $docItem = new Qs_Doc_Item($item); $this->addItemResources($docItem); array_unshift($this->_content[$groupName], $docItem); 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); $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; }); $authData = $this->getAuthData(); $this->_prepareUserNavigation($authData, $navigation); return $navigation; } public function hasLoggedInUserAccessToPageId($pageId) { if (false === ($page = Qs_SiteMap::findFirst(['id' => $pageId]))) { $page = []; } return $this->hasUserAccessToPage($this->getAuthData(false, []), $page); } protected function hasUserAccessToPage(array $authData, array $page) { if (!array_key_exists('xAllowFor', $page) || empty($page['xAllowFor'])) { return true; } foreach ($page['xAllowFor'] as $field => $value) { if ((is_array($value) && !in_array($authData[$field], $value)) || (is_scalar($value) && $authData[$field] != $value) ) { return false; } } return true; } protected function _prepareUserNavigation(array $authData, array &$menu) { foreach ($menu as $key => $item) { if (!$this->hasUserAccessToPage($authData, $item)) { unset($menu[$key]); continue; } if (!empty($item['sub'])) { $this->_prepareUserNavigation($authData, $item['sub']); } } return $this; } 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 _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; } protected function _initBackgroundImage() { BackgroundImage::attach($this); 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; } public function addGoogleMapScript() { $config = Zend_Registry::get('config')->toArray(); $config = $config['googleMapsApi']; $this->addScript(sprintf($config['url'], $config['key'])); return $this; } }