Exemplo n.º 1
0
 /**
  * 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();
 }
 public function contentAction(OrmManager $orm, Cms $cms, ContentService $contentService, ImageUrlGenerator $imageUrlGenerator, $model, $id, $locale)
 {
     $model = $orm->getModel($model);
     $entry = $model->getById($id);
     if (!$entry) {
         $this->response->setStatusCode(Response::STATUS_CODE_NOT_FOUND);
         return;
     }
     $site = $cms->getCurrentSite($this->request->getBaseUrl(), $locale);
     $content = $contentService->getContentForEntry($model, $entry, $site->getId(), $locale);
     if ($content->image) {
         $transformation = $this->request->getQueryParameter('transformation', 'crop');
         $options = array('width' => $this->request->getQueryParameter('width', 100), 'height' => $this->request->getQueryParameter('height', 100));
         $content->image = $imageUrlGenerator->generateUrl($content->image, $transformation, $options);
     }
     unset($content->data);
     $this->setJsonView($content);
 }
Exemplo n.º 3
0
 /**
  * Dispatches the frontend of a node
  * @return null
  */
 public function indexAction(Cms $cms, $node, $locale = null)
 {
     $siteLocale = null;
     try {
         $site = $cms->getCurrentSite($this->request->getBaseUrl(), $siteLocale);
     } catch (NodeNotFoundException $exception) {
         // not found, try the public web controller
         return $this->chainWebRequest();
     }
     $i18n = $this->getI18n();
     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();
     }
     // resolve the node
     $revision = $site->getRevision();
     $site = $site->getId();
     if (!$cms->resolveNode($site, $revision, $node)) {
         return $this->chainWebRequest();
     }
     // chain a request to the frontend callback
     $nodeType = $cms->getNodeType($node);
     $callback = $nodeType->getFrontendCallback();
     $arguments = ltrim($this->request->getBasePath(true), '/');
     $route = new Route('/', $callback);
     $route->setIsDynamic(true);
     $route->setArguments(explode('/', $arguments));
     $route->setPredefinedArguments(array('site' => $site->getId(), 'node' => $node->getId(), 'locale' => $locale));
     $this->request->setRoute($route);
     $this->response->setStatusCode(Response::STATUS_CODE_OK);
     return $this->request;
 }