/** * Dispatches the frontend of a node * @return null */ public function indexAction(Cms $cms, CmsCacheControl $cacheControl, NodeDispatcherFactory $nodeDispatcherFactory, TemplateFacade $templateFacade, $node, $locale = null) { $cache = null; if ($cacheControl->isEnabled()) { $cache = $this->dependencyInjector->get('ride\\library\\cache\\pool\\CachePool', 'cms'); } $i18n = $this->getI18n(); $siteLocale = null; try { $site = $cms->getCurrentSite($this->request->getBaseUrl(), $siteLocale); } catch (NodeNotFoundException $exception) { // not found, try the public web controller return $this->chainWebRequest(); } if ($siteLocale && $locale && $siteLocale != $locale) { // locale inconsistency, not found, try the public web controller return $this->chainWebRequest(); } elseif ($siteLocale) { // set the locale of the site $i18n->setCurrentLocale($siteLocale); } elseif ($locale) { // set the requested locale $i18n->setCurrentLocale($locale); } else { // fallback locale $locale = $i18n->getLocale()->getCode(); } $nodeDispatcher = $nodeDispatcherFactory->createNodeDispatcher($site, $node, $this->request->getBaseScript(), $locale); if ($nodeDispatcher) { $node = $nodeDispatcher->getNode(); if ($node->isPublished() && $node->isAvailableInLocale($locale)) { $securityManager = $this->getSecurityManager(); if (!$node->isAllowed($securityManager)) { throw new UnauthorizedException(); } $nodeView = $nodeDispatcher->getView(); $nodeView->setTemplateFacade($templateFacade); $nodeView->setLayouts($cms->getLayouts()); $textParser = $this->dependencyInjector->get('ride\\library\\cms\\content\\text\\TextParser', 'chain'); $textParser->setBaseUrl($this->request->getBaseUrl()); $textParser->setSiteUrl($this->request->getBaseScript()); $templateFacade->setThemeModel($cms->getThemeModel()); $templateFacade->setDefaultTheme($nodeView->getTemplate()->getTheme()); $nodeDispatcher->dispatch($this->request, $this->response, $securityManager, $cache); if ($this->response->getStatusCode() != Response::STATUS_CODE_NOT_FOUND) { $headers = $node->getHeader($locale); foreach ($headers as $name => $value) { $this->response->setHeader($name, $value); } return; } } } // not found, try the public web controller return $this->chainWebRequest(); }
/** * Dynamic action to preview a node * @param \ride\web\cms\node\dispatcher\NodeDispatcherFactory $nodeDispatcherFactory * @param \ride\library\template\TemplateFacade $templateFacade * @param string $site Id of the site * @param string $revision Name of the revision * @param string $locale Code of the locale * @return null */ public function previewAction(NodeDispatcherFactory $nodeDispatcherFactory, TemplateFacade $templateFacade, $site, $revision, $locale) { $node = $site; if (!$this->cms->resolveNode($site, $revision, $node, null, true)) { return; } $cache = null; $i18n = $this->getI18n(); $i18n->setCurrentLocale($locale); $requestUrl = $this->request->getUrl(); $routeUrl = $this->request->getRoute()->getUrl($this->request->getBaseScript(), array('locale' => $locale, 'site' => $site->getId(), 'revision' => $revision)); $path = str_replace($routeUrl, '', $requestUrl); $node = $site->getChildByRoute($path, $locale, $this->cms->getLocales()); if (!$node) { $this->response->setStatusCode(Response::STATUS_CODE_NOT_FOUND); return; } $nodeDispatcher = $nodeDispatcherFactory->createNodeDispatcher($site, $node->getId(), $routeUrl, $locale); if (!$nodeDispatcher) { $this->response->setStatusCode(Response::STATUS_CODE_NOT_FOUND); return; } $node = $nodeDispatcher->getNode(); if (!$node->isAvailableInLocale($locale)) { $this->response->setStatusCode(Response::STATUS_CODE_NOT_FOUND); return; } if (!$node->isAllowed($this->getSecurityManager())) { throw new UnauthorizedException(); } $this->request->setBaseScript($routeUrl); if ($node->getType() == RedirectNodeType::NAME) { $url = $node->getRedirectUrl($locale); if ($url) { $this->response->setRedirect($url); return; } $node = $node->getRedirectNode($locale); if (!$node) { throw new CmsException('No redirect properties set to this node for locale "' . $locale . '".'); } $revision = $site->getRevision(); $site = $site->getId(); if (!$this->cms->resolveNode($site, $revision, $node)) { return; } $redirectUrl = $this->request->getBaseScript() . $node->getRoute($locale); $this->response->setRedirect($redirectUrl); return; } $nodeView = $nodeDispatcher->getView(); $nodeView->setLayouts($this->cms->getLayouts()); $nodeView->setTemplateFacade($templateFacade); $templateFacade->setThemeModel($this->cms->getThemeModel()); $templateFacade->setDefaultTheme($nodeView->getTemplate()->getTheme()); $textParser = $this->dependencyInjector->get('ride\\library\\cms\\content\\text\\TextParser', 'chain'); $textParser->setBaseUrl($this->request->getBaseUrl()); $textParser->setSiteUrl($routeUrl); $nodeDispatcher->dispatch($this->request, $this->response, $this->getUser(), $cache); }