/**
  * Gets the additional sub routes for this widget
  * @return array|null Array with a route path as key and the action method
  * as value
  */
 public function getRoutes()
 {
     $node = $this->properties->getNode();
     if ($node->getRoute($this->locale) === '/') {
         // never make the root of your site dynamic, it can mess up other resources
         return null;
     }
     $parameters = $this->getContentProperties()->getParameters();
     if ($parameters === null) {
         return null;
     }
     $route = new Route('/', array($this, 'indexAction'), null, array('head', 'get'));
     $route->setIsDynamic(true);
     return array($route);
 }
 /**
  * Chains the current request to the public web controller
  * @return null|\ride\library\mvc\Request
  */
 protected function chainWebRequest()
 {
     // not found, try the public controller
     $arguments = ltrim($this->request->getBasePath(true), '/');
     if (!$arguments) {
         $this->response->setStatusCode(Response::STATUS_CODE_NOT_FOUND);
         return;
     }
     $controller = $this->dependencyInjector->get('ride\\library\\mvc\\controller\\Controller', 'public');
     $callback = array($controller, 'indexAction');
     $route = new Route('/', $callback);
     $route->setIsDynamic(true);
     $route->setArguments(explode('/', $arguments));
     $this->request->setRoute($route);
     $this->response->setStatusCode(Response::STATUS_CODE_OK);
     return $this->request;
 }
Ejemplo 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;
 }
 /**
  * Gets the route container from a data source
  * @return \ride\library\router\RouteContainer
  */
 public function getRouteContainer()
 {
     $container = new RouteContainer();
     $nodeTypeManager = $this->nodeModel->getNodeTypeManager();
     $nodeTypes = $nodeTypeManager->getNodeTypes();
     $defaultRevision = $this->nodeModel->getDefaultRevision();
     $registeredPaths = array();
     $expiredCallback = array('ride\\web\\cms\\controller\\frontend\\ExpiredController', 'indexAction');
     $sites = $this->nodeModel->getSites();
     foreach ($sites as $siteId => $site) {
         $nodes = $this->nodeModel->getNodes($siteId, $defaultRevision);
         foreach ($this->locales as $locale) {
             $baseUrl = $site->getBaseUrl($locale);
             foreach ($nodes as $nodeId => $node) {
                 if (!$node->getParent()) {
                     continue;
                 }
                 $nodeType = $nodeTypes[$node->getType()];
                 $callback = $nodeType->getFrontendCallback();
                 if (!$callback) {
                     continue;
                 }
                 if (!$node->isAvailableInLocale($locale)) {
                     continue;
                 }
                 $path = $node->getRoute($locale);
                 $route = new Route($path, $callback, 'cms.front.' . $siteId . '.' . $nodeId . '.' . $locale);
                 $route->setIsDynamic(true);
                 $route->setPredefinedArguments(array('site' => $siteId, 'node' => $nodeId));
                 $route->setLocale($locale);
                 if ($baseUrl) {
                     $route->setBaseUrl($baseUrl);
                 }
                 $container->addRoute($route);
                 $registeredPaths[$path] = true;
             }
         }
         $expiredRoutes = $this->expiredRouteModel->getExpiredRoutes($siteId);
         foreach ($expiredRoutes as $expiredRoute) {
             $path = $expiredRoute->getPath();
             if (isset($registeredPaths[$path]) || $path == '/') {
                 continue;
             }
             $route = new Route($path, $expiredCallback);
             $route->setIsDynamic(true);
             $route->setPredefinedArguments(array('site' => $siteId, 'node' => $expiredRoute->getNode()));
             $route->setLocale($expiredRoute->getLocale());
             $baseUrl = $expiredRoute->getBaseUrl();
             if ($baseUrl) {
                 $route->setBaseUrl($baseUrl);
             }
             $container->addRoute($route);
         }
     }
     return $container;
 }