/**
  * Parses the provided variable
  * @param string $variable Full variable
  * @return mixed Value of the variable if resolved, null otherwise
  */
 public function parseVariable($variable)
 {
     $tokens = explode('.', $variable);
     $node = null;
     switch ($tokens[0]) {
         case 'year':
             if (count($tokens) !== 1) {
                 return null;
             }
             return date('Y');
         case 'node':
             if (count($tokens) < 3) {
                 return null;
             }
             try {
                 $selfNode = $this->textParser->getNode();
                 $node = $this->nodeModel->getNode($selfNode->getRootNodeId(), $selfNode->getRevision(), $tokens[1]);
             } catch (NodeNotFoundException $exception) {
                 return null;
             }
             $locale = isset($tokens[3]) ? $tokens[3] : $this->textParser->getLocale();
             $variable = $tokens[2];
             break;
         case 'page':
             if (count($tokens) < 4) {
                 return null;
             }
             try {
                 $selfNode = $this->textParser->getNode();
                 $node = $this->nodeModel->getNode($tokens[1], $selfNode->getRevision(), $tokens[2]);
             } catch (NodeNotFoundException $exception) {
                 return null;
             }
             $locale = isset($tokens[4]) ? $tokens[4] : $this->textParser->getLocale();
             $variable = $tokens[3];
             break;
         case 'site':
             if (count($tokens) < 2) {
                 return null;
             }
             $node = $this->textParser->getNode()->getRootNode();
             $locale = isset($tokens[2]) ? $tokens[2] : $this->textParser->getLocale();
             $variable = $tokens[1];
     }
     if (!$node) {
         return null;
     }
     switch ($variable) {
         case self::VARIABLE_URL:
             return $node->getUrl($locale, $this->textParser->getSiteUrl());
         case self::VARIABLE_NAME:
             return $node->getName($locale);
         case self::VARIABLE_LINK:
             return '<a href="' . $node->getUrl($locale, $this->textParser->getSiteUrl()) . '">' . $node->getName($locale) . '</a>';
     }
     return null;
 }
 /**
  * Creates a node dispatcher for the provided node
  * @param \ride\library\cms\node\SiteNode $site
  * @param string $nodeId Id of the node
  * @param string $baseUrl
  * @param string $locale
  * @return \ride\web\cms\node\dispatcher\NodeDispatcher
  */
 public function createNodeDispatcher(SiteNode $site, $nodeId, $baseUrl, $locale)
 {
     if ($this->cachePool) {
         $cacheKey = 'node.dispatcher.' . $site->getId() . '.' . $nodeId . '.' . $locale;
         $cacheItem = $this->cachePool->get($cacheKey);
         if ($cacheItem->isValid()) {
             $nodeDispatcher = $cacheItem->getValue();
             $this->processNodeDispatcher($nodeDispatcher);
             return $nodeDispatcher;
         }
     }
     try {
         $node = $this->nodeModel->getNode($site->getId(), $site->getRevision(), $nodeId);
     } catch (NodeNotFoundException $exception) {
         return null;
     }
     $theme = $this->themeModel->getTheme($node->getTheme());
     $nodeView = new NodeTemplateView($node, $theme, $locale);
     $router = new GenericRouter(new RouteContainer());
     $breadcrumbs = $this->nodeModel->getBreadcrumbsForNode($node, $baseUrl, $locale);
     $nodeDispatcher = new GenericNodeDispatcher($node, $nodeView, $router, $breadcrumbs);
     $nodeDispatcher->loadWidgets($this->widgetModel, $theme->getRegions());
     if ($this->cachePool) {
         $cacheItem->setValue($nodeDispatcher);
         $this->cachePool->set($cacheItem);
     }
     $this->processNodeDispatcher($nodeDispatcher);
     return $nodeDispatcher;
 }
 /**
  * Redirects the current node
  * @return null
  */
 public function indexAction(NodeModel $nodeModel)
 {
     $node = $this->properties->getNode();
     $url = $this->properties->getLocalizedWidgetProperty($this->locale, self::PROPERTY_URL);
     if ($url) {
         $url = $node->resolveUrl($this->locale, $this->request->getBaseScript(), $url);
     } else {
         $nodeId = $this->properties->getWidgetProperty(self::PROPERTY_NODE);
         if (!$nodeId) {
             return;
         }
         try {
             $node = $nodeModel->getNode($node->getRootNodeId(), $node->getRevision(), $nodeId);
         } catch (NodeNotFoundException $exception) {
             $this->getLog()->logException($exception);
             return;
         }
         $url = $node->getUrl($this->locale, $this->request->getBaseScript());
     }
     $this->response->setRedirect($url);
 }
 /**
  * Saves the node in the model
  * @param string $locale Locale of the structure
  * @param \ride\library\cms\node\SiteNode $site Site node
  * @param \ride\library\cms\node\NodeModel $nodeModel
  * @param array $nodeArray
  * @return \ride\library\cms\node\Node
  */
 protected function saveNode($locale, SiteNode $site, NodeModel $nodeModel, array $nodeArray, $isUniqueTree)
 {
     if (isset($nodeArray['id']) && $nodeArray['id']) {
         $node = $nodeModel->getNode($site->getId(), $site->getRevision(), $nodeArray['id']);
     } else {
         $type = $nodeArray['type'];
         if (!$type) {
             $type = PageNodeType::NAME;
         }
         $node = $nodeModel->createNode($type);
         $node->setParentNode($site);
         $node->setRevision($site->getRevision());
         if ($isUniqueTree) {
             $node->setAvailableLocales($locale);
         }
     }
     $node->setName($locale, $nodeArray['name']);
     if ($nodeArray['route'] && $nodeArray['route'] != '/nodes/' . $node->getId() . '/' . $locale) {
         $node->setRoute($locale, $nodeArray['route']);
     }
     $nodeModel->setNode($node, 'Updated structure of ' . $site->getName());
     return $node;
 }
 /**
  * Sets a text view to the response
  * @return null
  */
 public function indexAction(NodeModel $nodeModel)
 {
     $propertiesNode = $this->properties->getNode();
     $text = $this->getTextIO()->getText($this->properties, $this->locale);
     $textFormat = $this->getTextFormat($text->getFormat());
     $html = $textFormat->getHtml($text->getBody());
     $callToActions = $text->getCallToActions();
     foreach ($callToActions as $index => $callToAction) {
         $node = $callToAction->getNode();
         $url = $callToAction->getUrl();
         $suffix = $callToAction->getSuffix();
         if ($node) {
             try {
                 $node = $nodeModel->getNode($propertiesNode->getRootNodeId(), $propertiesNode->getRevision(), $node);
                 $callToAction->setUrl($node->getUrl($this->locale, $this->request->getBaseUrl()) . $callToAction->getSuffix());
             } catch (NodeNotFoundException $exception) {
                 $this->getLog()->logException($exception);
                 unset($callToActions[$index]);
             }
         } elseif ($url) {
             $callToAction->setUrl($this->properties->getNode()->resolveUrl($this->locale, $this->request->getBaseUrl(), $url));
         } elseif (!$suffix) {
             unset($callToActions[$index]);
         }
     }
     $this->setTemplateView($this->getTemplate(static::TEMPLATE_NAMESPACE . '/' . static::TEMPLATE_DEFAULT), array('text' => $text, 'title' => $text->getTitle(), 'subtitle' => $text->getSubtitle(), 'html' => $html, 'image' => $text->getImage(), 'imageAlignment' => $text->getImageAlignment(), 'callToActions' => $callToActions));
 }
Пример #6
0
 /**
  * Gets a list of frontend nodes
  * @param \ride\library\cms\node\NodeModel $nodeModel Instance of the node
  * model
  * @param boolean $includeRootNode Set to false to omit the root node
  * @return array Array with the id of node as key and the localized name of
  * the node as value
  */
 public function getNodeList(NodeModel $nodeModel, $includeRootNode = true)
 {
     $node = $this->properties->getNode();
     $rootNodeId = $node->getRootNodeId();
     $rootNode = $nodeModel->getNode($rootNodeId, $node->getRevision(), $rootNodeId, null, true);
     $nodeList = $nodeModel->getListFromNodes(array($rootNode), $this->locale, true);
     if ($includeRootNode) {
         $nodeList = array($rootNode->getId() => '/' . $rootNode->getName($this->locale)) + $nodeList;
     }
     return array('' => '---') + $nodeList;
 }