/** * Page 404 * * @return string|boolean */ public function __invoke() { $language = LocalizationService::getCurrentLocalization()['language']; $page404 = false; // get a custom 404 page's url if (true === DisableSiteUtility::isAllowedViewSite() && false !== ($page404 = $this->getView()->pageUrl(self::CUSTOM_404_PAGE, [], $language, true))) { $userRole = UserIdentityService::getCurrentUserIdentity()['role']; if (false == ($pageInfo = $this->getModel()->getActivePageInfo(self::CUSTOM_404_PAGE, $userRole, $language))) { return false; } // fire the page show event PageEvent::firePageShowEvent($pageInfo['slug'], $language); // check for redirect if ($pageInfo['redirect_url']) { $response = ServiceLocatorService::getServiceLocator()->get('Response'); $response->getHeaders()->addHeaderLine('Location', $pageInfo['redirect_url']); $response->setStatusCode(Response::STATUS_CODE_301); $response->sendHeaders(); return false; } // get the page's breadcrumb $breadcrumb = $this->getModel()->getActivePageParents($pageInfo['left_key'], $pageInfo['right_key'], $userRole, $language); return $this->getView()->partial($this->getModel()->getLayoutPath() . $pageInfo['layout'], ['page' => $pageInfo, 'breadcrumb' => $breadcrumb]); } return $page404; }
/** * Index page */ public function indexAction() { $receivedPath = $this->getReceivedPath(); $pageName = end($receivedPath); // get current user's role and current site's language $userRole = $this->userIdentity()['role']; $language = $this->localization()['language']; // get a page info if (!$pageName || false == ($pageInfo = $this->getModel()->getActivePageInfo($pageName, $userRole, $language))) { return $this->createHttpNotFoundModel($this->getResponse()); } // get the page's parents $pageParents = $pageInfo['level'] > 1 ? $this->getModel()->getActivePageParents($pageInfo['left_key'], $pageInfo['right_key'], $userRole, $language, false) : [$pageInfo]; // get the page's breadcrumb if (false === ($breadcrumb = $this->getPageBreadcrumb($pageParents, $pageInfo['level'] > 1))) { return $this->createHttpNotFoundModel($this->getResponse()); } // show a disabled site message if (true !== DisableSiteUtility::isAllowedViewSite()) { $this->getResponse()->setStatusCode(Response::STATUS_CODE_503); // set the page variables $viewModel = new ViewModel(['message' => $this->applicationSetting('application_disable_site_message')]); $viewModel->setTemplate($this->getModel()->getLayoutPath() . 'layout-disabled-site'); $this->layout('layout/blank'); return $viewModel; } // fire the page show event PageEvent::firePageShowEvent($pageInfo['slug'], $language); // check for redirect if ($pageInfo['redirect_url']) { $response = $this->redirect()->toUrl($pageInfo['redirect_url']); $response->setStatusCode(Response::STATUS_CODE_301); return $response; } $request = $this->getRequest(); $widgetConnectionId = $this->params()->fromQuery('widget_connection', null); $widgetPosition = $this->params()->fromQuery('widget_position', null); PageService::setCurrentPage($pageInfo); // get only a specific widget info if ($request->isXmlHttpRequest() && null !== $widgetConnectionId && null !== $widgetPosition) { // set the page variables $viewModel = new ViewModel(['page' => $pageInfo, 'widget_connection' => $widgetConnectionId, 'widget_position' => $widgetPosition]); // set a custom page layout $viewModel->setTerminal(true)->setTemplate($this->getModel()->getLayoutPath() . 'layout-ajax'); return $viewModel; } // passing the current page info to the layout $this->layout()->setVariable('page', $pageInfo); // set the page variables $viewModel = new ViewModel(['page' => $pageInfo, 'breadcrumb' => $breadcrumb]); // set a custom page layout $viewModel->setTemplate($this->getModel()->getLayoutPath() . $pageInfo['layout']); return $viewModel; }
/** * Save widget settings * * @param array $widget * string widget_name * integer widget_id * integer page_id * integer id * @param array $settingsList * @param array $formData * @param string $currentlanguage * @return boolean|string */ public function saveWidgetSettings(array $widget, array $settingsList, array $formData, $currentlanguage) { try { $this->adapter->getDriver()->getConnection()->beginTransaction(); $widgetId = $widget['widget_id']; $pageId = $widget['page_id']; $widgetConnectionId = $widget['id']; $this->updateStructurePageEditedDate($pageId); // update primary widget settings $update = $this->update()->table('page_widget_connection')->set(['title' => !empty($formData['title']) ? $formData['title'] : null, 'layout' => !empty($formData['layout']) ? $formData['layout'] : null, 'cache_ttl' => !empty($formData['cache_ttl']) ? $formData['cache_ttl'] : 0])->where(['id' => $widgetConnectionId]); $statement = $this->prepareStatementForSqlObject($update); $statement->execute(); // update extra widget settings foreach ($settingsList as $setting) { if (array_key_exists($setting['name'], $formData)) { // remove previously value $query = $this->delete('page_widget_setting_value')->where(['setting_id' => $setting['id'], 'widget_connection' => $widgetConnectionId]); $statement = $this->prepareStatementForSqlObject($query); $statement->execute(); $value = is_array($formData[$setting['name']]) ? implode(PageWidgetSetting::SETTINGS_ARRAY_DEVIDER, $formData[$setting['name']]) : (null != $formData[$setting['name']] ? $formData[$setting['name']] : ''); $query = $this->insert('page_widget_setting_value')->values(['setting_id' => $setting['id'], 'value' => $value, 'widget_connection' => $widgetConnectionId]); $statement = $this->prepareStatementForSqlObject($query); $statement->execute(); } } // clear all widget old visibility settings $delete = $this->delete()->from('page_widget_visibility')->where(['widget_connection' => $widgetConnectionId]); $statement = $this->prepareStatementForSqlObject($delete); $result = $statement->execute(); // add new widget visibility settings if (!empty($formData['visibility_settings'])) { foreach ($formData['visibility_settings'] as $aclRoleId) { $insert = $this->insert()->into('page_widget_visibility')->values(['widget_connection' => $widgetConnectionId, 'hidden' => $aclRoleId]); $statement = $this->prepareStatementForSqlObject($insert); $statement->execute(); } } // clear caches $this->clearLanguageSensitivePageCaches(); $this->clearWidgetsSettingsCache($pageId, $currentlanguage); $dynamicCache = $this->serviceLocator->get('Application\\Cache\\Dynamic'); $widgetCacheName = CacheUtility::getCacheName($widget['widget_name'], [$widgetConnectionId]); if ($dynamicCache->hasItem($widgetCacheName)) { $dynamicCache->removeItem($widgetCacheName); } $this->adapter->getDriver()->getConnection()->commit(); } catch (Exception $e) { $this->adapter->getDriver()->getConnection()->rollback(); ApplicationErrorLogger::log($e); return $e->getMessage(); } PageEvent::fireEditWidgetSettingsEvent($widgetId, $pageId); return true; }