Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * 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;
 }