_initAction(); if ('view' == $this->_action) { foreach (array_keys($list) as $idx) { if ('HtmlBlock_' == $list[$idx]['type']) { unset($list[$idx]); break; } } } return $this; } public function exec() { $this->_initAction(); if (null === $this->_action) { $this->_doc->display404(); } return parent::exec(); } protected function _initAction() { if (null === $this->_action) { $params = $this->getRestParams(); if (empty($params)) { $alias = $this->_getFirstAlbumAlias(); if ($alias) { \Qs_Http::redirect($alias); } else { $this->_action = 'empty'; } } else if (1 == count($params) && $this->_getDataObj()->setPrimaryKeyByAlias($params[0])->getData()) { $this->_action = 'view'; } } return $this; } protected function _doEmpty() { $item = [ 'tpl' => $this->getTemplate('empty.tpl'), ]; $this->_addItem($item); return $this; } protected function _doView() { $item = array(); $item['data'] = $this->_getDataObj()->getData(); if (!empty($item['data']) && $item['data']['enabled'] != 'n') { $albumOrientation = $this->_getDataObj()->getData('albumOrientation'); $frontendImageConfig = $this->getConfig('frontendImage')->toArray(); if (isset($frontendImageConfig[$albumOrientation])) { $frontendImageConfig = $frontendImageConfig[$albumOrientation]; } else { $frontendImageConfig = reset($frontendImageConfig); } FormMetaTrait::updateMetaTitle($item['data'], 'title'); Qs_Navigation::append(array('title' => $item['data']['title'], 'url' => $this->url())); $this->_doc->setHeader($item['data']['title']); $item['list'] = $this->_getDataObj()->getAlbumItems(); $this->_prepareImages($item['list']); $item['config'] = $this->getPhotoConfig()->toArray(); $item['image'] = $frontendImageConfig; $item['tpl'] = $this->getTemplate('view.tpl'); $this->_addItem($item); $this->_doc->addStyleSheet('css/thirdpart/fancybox/jquery.fancybox.css'); $this->_doc->addScript('js/fancybox/jquery.fancybox.js', array(), 'fancybox'); $this->_doc->addScript('js/jquery.cj-swipe.js'); $this->_doc->addScript('js/app/gallery.js'); $galleryOptions = array('title' => $item['data']['title']); $this->_doc->addInitFunction('App_Gallery.init', array($galleryOptions)); $this->_postView(); } else { $this->_doc->display404(); } return $this; } protected function _prepareImages(array &$images) { $imageConfig = $this->getPhotoConfig('image'); foreach ($images as &$image) { $source = Qs_ImageFs::WEB_PATH . '/' . $image['image']; $destination = Qs_ImageFs::getIconName( $source, $imageConfig->width, $imageConfig->height, $imageConfig->method ); $destination = Qs_ImageFs::THUMBNAIL_PATH . '/' . $destination; if (!file_exists($destination)) { $destination = Qs_ImageFs::resize( $source, array( 'width' => $imageConfig->width, 'height' => $imageConfig->height, 'force' => false, 'method' => $imageConfig->method, 'sizeCheck' => true ) ); } $realWidth = $realHeight = 0; if ($destination) { $fileInfo = Qs_ImageFs::getInfo($destination); $realWidth = $fileInfo['width']; $realHeight = $fileInfo['height'];; } $image['realWidth'] = $realWidth; $image['realHeight'] = $realHeight; } return $this; } protected function _getFirstAlbumAlias() { return $this->_findFirstAlbumAlias($this->getMenu()); } protected function _findFirstAlbumAlias($menu) { $result = false; if (!empty($menu)) { foreach ($menu as $subMenu) { if ($subMenu['imagesCount'] > 0) { return $subMenu['fullAlias']; } if ($result = $this->_findFirstAlbumAlias($subMenu['sub'])) { return $result; }; } } return $result; } public function getMenu() { $menu = (new \App_ECommerce_Product_Category_Obj())->getCategoryTree(); $fullAlias = \Qs_SiteMap::find(array('enabled' => 'y'), array('type' => 'Gallery\\'), null, 'fullAlias'); $this->_prepareMenu($menu, $fullAlias); return $menu; } protected function _prepareMenu(array &$menu, $fullAlias, $onlyFirstAlias = false) { if (!empty($menu)) { foreach ($menu as $key => &$subMenu) { $subMenu['items'] = array('type' => substr(get_class($this), 0, -4)); $subMenu['menuTitle'] = htmlspecialchars($subMenu['menuTitle']); $subMenu['fullAlias'] = $fullAlias . '/' . $subMenu['alias']; $subMenu['url'] = BASE_URL . '/' . $fullAlias . '/' . $subMenu['alias']; if ($subMenu['imagesCount'] == 0 && $subMenu['subcategoriesImagesCount'] > 0) { $subMenu['url'] = null; } elseif ($subMenu['imagesCount'] == 0 && $subMenu['subcategoriesImagesCount'] == 0) { unset($menu[$key]); continue; } elseif ($subMenu['subcategoriesImagesCount'] == 0) { $subMenu['sub'] = null; continue; } $this->_prepareMenu($subMenu['sub'], $fullAlias, $onlyFirstAlias); } } return $this; } public function getPhotoConfig($field = null, $default = null) { if (null === $this->_photoConfig) { $this->_photoConfig = Qs_Config::get($this->_photoConfigName, Qs_Config::APP_TYPE); } if (null === $field) { return $this->_photoConfig; } return $this->_photoConfig->get($field, $default); } protected function _getBackUrl($sessionName = CURRENT_PAGE_FINAL) { $session = new Qs_Session_Namespace($sessionName); if (isset($session->backUrl)) { return $session->backUrl; } return BASE_URL_LANGUAGE . '/' . CURRENT_PAGE_FINAL; } }