Exemplo n.º 1
0
 /**
  * Creates a new node of this type
  * @return \ride\library\cms\node\Node
  */
 public function createNode()
 {
     $site = new SiteNode();
     if ($this->defaultTheme) {
         $site->setTheme($this->defaultTheme);
     }
     return $site;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
Exemplo n.º 4
0
 /**
  * Perform the actual publishing of a single node
  * @param \ride\library\cms\node\SiteNode $site
  * @param \ride\library\cms\node\Node $node
  * @param string $revision
  * @param \ride\library\system\file\File $publishDirectory
  * @param boolean $isRecursive Flag to see if this publishing is part of a
  * recursive publish action
  * @return null
  */
 protected function publishNode(SiteNode $site, Node $node, $revision, File $publishDirectory, $isRecursive)
 {
     // initialize needed variables
     $siteId = $site->getId();
     $nodeId = $node->getId();
     $changedNodes = array();
     try {
         $publishSite = $this->getSite($siteId, $revision);
     } catch (NodeNotFoundException $exception) {
         $publishSite = null;
     }
     // process and merge the necessairy nodes
     try {
         $oldNode = $this->getNode($siteId, $revision, $nodeId);
         // check for expired routes
         $oldRoutes = $oldNode->getRoutes();
         $newRoutes = $node->getRoutes();
         if ($oldRoutes && $oldRoutes !== $newRoutes) {
             foreach ($oldRoutes as $locale => $route) {
                 if (isset($newRoutes[$locale]) && $route === $newRoutes[$locale]) {
                     continue;
                 }
                 $this->expiredRouteModel->addExpiredRoute($siteId, $nodeId, $locale, $route, $site->getBaseUrl($locale));
             }
         }
         // check for order conflicts
         $nodeOrderIndex = $node->getOrderIndex();
         $nodeParent = $node->getParent();
         if (!$isRecursive && ($nodeOrderIndex != $oldNode->getOrderIndex() || $nodeParent != $oldNode->getParent())) {
             $orderIndex = 0;
             $parentNodes = $this->getChildren($siteId, $revision, $nodeParent, 0);
             foreach ($parentNodes as $parentNodeId => $parentNode) {
                 $orderIndex++;
                 $parentOrderIndex = $parentNode->getOrderIndex();
                 $isBefore = $parentOrderIndex < $nodeOrderIndex;
                 if ($isBefore && $parentOrderIndex == $orderIndex) {
                     continue;
                 } elseif ($nodeOrderIndex == $parentOrderIndex && $nodeId != $parentNodeId) {
                     $orderIndex++;
                     $parentNode->setOrderIndex($orderIndex);
                     $changedNodes[] = $parentNode;
                 } elseif ($nodeId == $parentNodeId) {
                     $orderIndex--;
                     continue;
                 } else {
                     $parentNode->setOrderIndex($orderIndex);
                     $changedNodes[] = $parentNode;
                 }
             }
         }
     } catch (NodeNotFoundException $exception) {
         // new node in the revision
     }
     // check for new widgets
     if ($publishSite) {
         $isPublishSiteChanged = false;
         $usedWidgets = $node->getUsedWidgets();
         $availableWidgetsSite = $site->getAvailableWidgets();
         $availableWidgetsPublishSite = $publishSite->getAvailableWidgets();
         foreach ($usedWidgets as $widgetId) {
             if (!$widgetId || isset($availableWidgetsPublishSite[$widgetId]) || !isset($availableWidgetsSite[$widgetId])) {
                 continue;
             }
             $publishSite->set(Node::PROPERTY_WIDGET . '.' . $widgetId, $availableWidgetsSite[$widgetId], true);
             $isPublishSiteChanged = true;
         }
         if ($isPublishSiteChanged) {
             $changedNodes[] = $publishSite;
         }
     }
     // write the changed nodes
     foreach ($changedNodes as $changedNode) {
         $this->writeNode($changedNode);
     }
     // write the node file to the publish directory
     $nodeFile = $this->getNodeFile($node);
     $publishFile = $publishDirectory->getChild($nodeFile->getName());
     if ($nodeFile->exists()) {
         // node has been created or updated
         $nodeFile->copy($publishFile);
         return null;
     } elseif ($publishFile->exists()) {
         // node has been deleted
         $publishFile->delete();
         return $node;
     }
 }
Exemplo n.º 5
0
 /**
  * Restores the provided trash nodes
  * @param \ride\library\cms\node\SiteNode $site Site to manipulate
  * @param array $trashNodes Array with TrashNode instances
  * @param string $destination Materialized path of the new parent
  * @return null
  */
 public function restoreTrashNodes(SiteNode $site, array $trashNodes, $destination)
 {
     $this->nodeModel->restoreTrashNodes($site->getId(), $site->getRevision(), $trashNodes, $destination);
 }