/** * Loads the properties of the detail widget for the provided site and locale * @param string $index The key to store the values * @param string $site Id of the site * @param string $locale Code of the current locale * @return null */ protected function parseArguments($index, $site, $locale) { $properties = new ContentProperties(); $properties->getFromWidgetProperties($this->properties, $locale); $this->reflectionHelper = $this->model->getReflectionHelper(); $this->arguments[$index] = array(ContentProperties::PROPERTY_RECURSIVE_DEPTH => $properties->getRecursiveDepth(), ContentProperties::PROPERTY_INCLUDE_UNLOCALIZED => $properties->getIncludeUnlocalized(), ContentProperties::PROPERTY_ID_FIELD => $properties->getIdField(), ContentProperties::PROPERTY_FORMAT_TITLE => $properties->getContentTitleFormat(), ContentProperties::PROPERTY_FORMAT_TEASER => $properties->getContentTeaserFormat(), ContentProperties::PROPERTY_FORMAT_IMAGE => $properties->getContentImageFormat(), ContentProperties::PROPERTY_FORMAT_DATE => $properties->getContentDateFormat(), self::PROPERTY_URL => rtrim($this->routerService->getUrl($this->baseScript, 'cms.front.' . $site . '.' . $this->node->getId() . '.' . $locale), '/') . '/'); }
/** * Gets the tree node of a node * @param \ride\library\cms\node\Node $node Node to process * @param boolean $onlyCurrentLocale Flag to see if the tree should only * rendered for the current locale * @return TreeNode */ protected function getTreeNode(Node $node, $onlyCurrentLocale) { $nodeId = $node->getId(); $nodeRevision = $node->getRevision(); $urlVars = array('site' => $this->rootNodeId, 'revision' => $nodeRevision, 'node' => $nodeId, 'locale' => $this->locale); $url = $this->web->getUrl('cms.node.default', $urlVars); $treeNode = new TreeNode($node, $this->locale, $url); // add icon state classes $nodeType = $this->cms->getNodeType($node); if ($nodeType->getFrontendCallback()) { if ($node->getRoute($this->locale) == '/') { $treeNode->setIsHomePage(true); } if (!$node->isPublished()) { $treeNode->setIsHidden(true); } } $actions = array(); foreach ($this->actions as $actionName => $action) { if (!$action->isAvailableForNode($node)) { continue; } $actionUrl = $this->web->getUrl($action->getRoute(), $urlVars); if (!$this->securityManager->isUrlAllowed($actionUrl)) { continue; } $actions[$actionName] = $actionUrl; } $actionUrl = $this->web->getUrl($nodeType->getRouteEdit(), $urlVars); if ($this->securityManager->isUrlAllowed($actionUrl)) { $actions['edit'] = $actionUrl; } $actionUrl = $this->web->getUrl($nodeType->getRouteClone(), $urlVars); if ($this->securityManager->isUrlAllowed($actionUrl)) { $actions['clone'] = $actionUrl; } $actionUrl = $this->web->getUrl($nodeType->getRouteDelete(), $urlVars); if ($this->securityManager->isUrlAllowed($actionUrl)) { $actions['delete'] = $actionUrl; } $treeNode->setActions($actions); $children = $node->getChildren(); if ($children) { foreach ($children as $childId => $child) { if (!$onlyCurrentLocale || $onlyCurrentLocale && $child->isAvailableInLocale($this->locale)) { $children[$childId] = $this->getTreeNode($child, $onlyCurrentLocale); } else { unset($children[$childId]); } } $treeNode->setChildren($children); } return $treeNode; }
/** * Constructs a new template view * @param \ride\library\template\Template $template Instance of the * template to render * @return null */ public function __construct(Node $node, Theme $theme, $locale) { $template = new GenericThemedTemplate(); $template->setResource('cms/frontend/index'); $template->setResourceId($node->getId()); $template->setTheme($theme->getName()); $template->set('app', array('cms' => array('node' => $node, 'site' => $node->getRootNodeId()), 'locale' => $locale)); parent::__construct($template); $this->cache = null; $this->cacheItem = null; $this->cachedViews = null; $this->contentView = null; }
/** * Checks if there is a orm detail widget on the provided node * @param \ride\library\cms\node\Node $node * @return boolean */ private function hasDetailForNode($node) { foreach ($this->info as $modelName => $widgets) { if (!isset($widgets['orm.detail'])) { continue; } foreach ($widgets['orm.detail'] as $id => $properties) { if (strpos($id, $node->getId() . '#') === 0) { return true; } } } return false; }
/** * Writes a the nodes into the data source * @param \ride\library\cms\node\Node $node * @return null */ public function setNode(Node $node) { $id = $node->getId(); if (!$id) { $id = $this->getNewNodeId($node); $node->setId($id); } $this->writeNode($node); if ($node->getType() == SiteNodeType::NAME) { $revision = $node->getRevision(); $node->setRevisions(array($revision => $revision)); $this->sites[$id] = $node; } if ($this->nodes === null) { $this->readNodes($node->getRootNodeId(), $node->getRevision()); } else { $this->nodes[$node->getRootNodeId()][$node->getRevision()][$id] = $node; } }
/** * Saves the node tree from the structure in text format * @param string $locale Locale of the structure * @param \ride\library\cms\node\Node $parent Parent node of the structure * @param \ride\library\cms\node\NodeModel $nodeModel Instance of the node * model * @param string $structure Node tree in text format * @return null */ public function setStructure($locale, Node $parent, NodeModel $nodeModel, $structure) { $site = $parent->getRootNode(); if ($site->isLocalizationMethodUnique()) { $isUniqueTree = true; } else { $isUniqueTree = false; } $previousNodeId = null; $previousSpaces = null; $level = 0; $levels = array(0 => $site->getId()); $order = array($site->getId() => 0); $spaces = array(); $structure = $this->parseStructure($structure); foreach ($structure as $index => $nodeArray) { $structure[$index]['node'] = $this->saveNode($locale, $site, $nodeModel, $nodeArray, $isUniqueTree); $structure[$index]['id'] = $structure[$index]['node']->getId(); if ($previousSpaces === null) { $spaces[$level] = $nodeArray['spaces']; } elseif ($nodeArray['spaces'] > $previousSpaces) { $level++; $levels[$level] = $previousNodeId; $spaces[$level] = $nodeArray['spaces']; } elseif ($nodeArray['spaces'] < $previousSpaces) { krsort($spaces); foreach ($spaces as $spaceLevel => $numSpaces) { if ($nodeArray['spaces'] >= $numSpaces) { $level = $spaceLevel; break; } } } $order[$levels[$level]]++; $order[$structure[$index]['id']] = 0; $previousNodeId = $structure[$index]['id']; $previousSpaces = $nodeArray['spaces']; } $siblings = $nodeModel->getNodesByPath($site->getId(), $site->getRevision(), $parent->getId()); foreach ($siblings as $siblingId => $sibling) { if (isset($order[$siblingId]) || $isUniqueTree && !$sibling->isAvailableInLocale($locale)) { continue; } $nodeModel->removeNode($sibling, false, null, false); } unset($order[$parent->getId()]); $nodeModel->orderNodes($site->getId(), $site->getRevision(), $parent->getId(), $order, $locale); }
/** * Dispatches the node * @param \ride\library\mvc\Request $request * @param \ride\library\mvc\Response $response * @param \ride\library\security\SecurityManager $securityManager * @param \ride\library\cache\pool\CachePool $cache * @return array Array with the region name as key and a view array as * value. The view array has the widget id as key and the dispatched * widget view as value */ public function dispatch(Request $request, Response $response, SecurityManager $securityManager, CachePool $cache = null) { $this->locale = $this->view->getLocale(); // initialize context $context = array('title' => array('site' => $this->node->getRootNode()->getName($this->locale, 'title'), 'node' => $this->node->getName($this->locale, 'title')), 'breadcrumbs' => $this->breadcrumbs, 'styles' => array(), 'scripts' => array()); // prepare and process incoming route arguments $route = $request->getRoute(); $this->routeArguments = $route->getArguments(); unset($this->routeArguments['node']); unset($this->routeArguments['locale']); if (isset($this->routeArguments['site'])) { // preview has site and revision unset($this->routeArguments['site']); unset($this->routeArguments['revision']); } $nodeRoute = $this->node->getRoute($this->locale); $nodeRouteTokens = explode('/', ltrim($nodeRoute, '/')); foreach ($nodeRouteTokens as $tokenIndex => $tokenValue) { if (isset($this->routeArguments[$tokenIndex]) && $this->routeArguments[$tokenIndex] === $tokenValue) { unset($this->routeArguments[$tokenIndex]); } } $route->setPredefinedArguments(array()); $route->setArguments(); $routeArgumentsMatched = false; // check for cache $cacheKey = null; $cacheItem = null; $cachedViews = array(); $dispatchedViews = array(); $nodeCacheTtl = false; if ($cache) { $method = $request->getMethod(); $isCacheable = $method == 'GET' || $method == 'HEAD' ? true : false; $isNoCache = $request->isNoCache(); if ($isCacheable) { $parameters = $this->routeArguments ? '-' . implode('-', $this->routeArguments) : ''; $parameters .= $request->getQueryParametersAsString(); $containsUserContent = false; $nodeCacheTtl = 0; $cacheKey = 'node.view.' . $this->node->getId() . '.' . $this->node->getRevision() . '.' . $this->locale . '.' . substr(md5($parameters), 0, 10); if ($securityManager->getUser()) { $cacheKey .= '.authenticated'; } $cacheItem = $cache->get($cacheKey); if ($cacheItem->isValid()) { $cachedViews = $cacheItem->getValue(); } else { $cachedViews = array(); } } } else { $isCacheable = false; } foreach ($this->widgets as $this->region => $sections) { $dispatchedViews[$this->region] = array(); foreach ($sections as $this->section => $blocks) { $dispatchedViews[$this->region][$this->section] = array(); foreach ($blocks as $this->block => $widgets) { $dispatchedViews[$this->region][$this->section][$this->block] = array(); foreach ($widgets as $widgetId => $widget) { if ($this->log) { $this->log->logDebug('Rendering widget ' . $widget->getName() . '#' . $widgetId . ' for region ' . $this->region, null, ApplicationListener::LOG_SOURCE); } $widgetProperties = $this->node->getWidgetProperties($widgetId); if (!$widgetProperties->isPublished()) { if ($this->log) { $this->log->logDebug('Widget ' . $widget->getName() . '#' . $widgetId . ' is not published', null, ApplicationListener::LOG_SOURCE); } continue; } elseif (!$widgetProperties->isAllowed($securityManager)) { if ($this->log) { $this->log->logDebug('Widget ' . $widget->getName() . '#' . $widgetId . ' is not allowed', null, ApplicationListener::LOG_SOURCE); } continue; } if ($isCacheable) { $widgetCacheKey = $this->region . '.' . $this->section . '.' . $this->block . '.' . $widgetId . '.'; } $isWidgetCache = $widgetProperties->isCacheEnabled() || $widgetProperties->isAutoCache() && $widget->isAutoCache(); if ($isCacheable && !$isNoCache && $isWidgetCache) { if (isset($cachedViews[$this->region][$this->section][$this->block][$widgetId])) { if ($this->log) { $this->log->logDebug('Retrieved widget ' . $widget->getName() . '#' . $widgetId . ' from cache', null, ApplicationListener::LOG_SOURCE); } $cacheView = $cachedViews[$this->region][$this->section][$this->block][$widgetId]; if ($cacheView->areRoutesMatched()) { $widgetMatchedRouteArguments = true; } $cacheContext = $cacheView->getContext(); if ($cacheContext) { foreach ($cacheContext as $key => $value) { if ($value !== null) { $context[$key] = $value; } elseif (isset($context[$key])) { unset($context[$key]); } } } if ($cacheView->isContent()) { $dispatchedViews = null; $this->view->setContentView($view, $widgetId, $this->block, $this->section, $this->region); break 4; } elseif ($cacheView->isRegion()) { $dispatchedViews[$this->region] = array($this->section => array($this->block => array($widgetId => $cacheView->getView()))); break 3; } elseif ($cacheView->isSection()) { $dispatchedViews[$this->region][$this->section] = array($this->block => array($widgetId => $cacheView->getView())); break 2; } elseif ($cacheView->isBlock()) { $dispatchedViews[$this->region][$this->section][$this->block] = array($widgetId => $cacheView->getView()); break; } else { $dispatchedViews[$this->region][$this->section][$this->block][$widgetId] = $cacheView->getView(); continue; } } } $widget->setProperties($widgetProperties); $widget->setContext($context); $widgetMatchedRouteArguments = $this->dispatchWidget($request, $response, $widgetId, $widget); if ($widgetMatchedRouteArguments) { $routeArgumentsMatched = true; } $statusCode = $response->getStatusCode(); if ($statusCode != Response::STATUS_CODE_OK && $statusCode != Response::STATUS_CODE_BAD_REQUEST && $statusCode != Response::STATUS_CODE_UNPROCESSABLE_ENTITY) { return; } $view = $response->getView(); $response->setView(null); $isContent = $widget->isContent(); $isRegion = $widget->isRegion(); $isSection = $widget->isSection(); $isBlock = $widget->isBlock(); if ($isCacheable && !$containsUserContent && $widget->containsUserContent()) { $containsUserContent = true; } $oldContext = $context; $context = $widget->getContext(); if ($isCacheable && $isWidgetCache) { $widgetContext = $this->getContextDifference($context, $oldContext); if (!$widgetContext) { // calculate node cache time based on the least widget cache time $cacheTtl = $widgetProperties->getCacheTtl(); if ($nodeCacheTtl !== false && $cacheTtl) { if ($nodeCacheTtl == 0) { $nodeCacheTtl = $cacheTtl; } else { $nodeCacheTtl = min($nodeCacheTtl, $cacheTtl); } } $widgetCachedView = new WidgetCacheData($widgetContext, $isContent, $isRegion, $isSection, $isBlock, $widgetMatchedRouteArguments); $cachedViews[$this->region][$this->section][$this->block][$widgetId] = $widgetCachedView; } } if ($isContent) { $dispatchedViews = null; $this->view->setContentView($view, $widgetId, $this->block, $this->section, $this->region); break 4; } elseif ($isRegion) { $dispatchedViews[$this->region] = array($this->section => array($this->block => array($widgetId => $view))); break 3; } elseif ($isSection) { $dispatchedViews[$this->region][$this->section] = array($this->block => array($widgetId => $view)); break 2; } elseif ($isBlock) { $dispatchedViews[$this->region][$this->section][$this->block] = array($widgetId => $view); break; } $dispatchedViews[$this->region][$this->section][$this->block][$widgetId] = $view; } if (!$dispatchedViews[$this->region][$this->section][$this->block]) { unset($dispatchedViews[$this->region][$this->section][$this->block]); } } if (!$dispatchedViews[$this->region][$this->section]) { unset($dispatchedViews[$this->region][$this->section]); } } if (!$dispatchedViews[$this->region]) { unset($dispatchedViews[$this->region]); } } if ($this->routeArguments && !$routeArgumentsMatched) { // sub route provided but never matched $response->setStatusCode(Response::STATUS_CODE_NOT_FOUND); $response->setView(null); $dispatchedViews = null; } // if ($this->eventManager && $isCacheable && $nodeCacheTtl !== false) { // if ($user && $containsUserContent) { // $isCacheable = false; // } // if ($isCacheable) { // $this->cache = $cache; // $this->cacheTtl = $nodeCacheTtl; // $this->eventManager->addEventListener(WebApplication::EVENT_POST_RESPONSE, array($this, 'cacheResponse')); // } // } $this->view->setContext($context); if (is_array($dispatchedViews)) { $this->view->setDispatchedViews($dispatchedViews); $this->view->setRegions($this->regions); if ($nodeCacheTtl !== false && $cachedViews) { $cacheItem->setValue($cachedViews); $cacheItem->setTtl($nodeCacheTtl); $this->view->setCachedViews($cache, $cacheItem); } } $response->setView($this->view); }
/** * 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; } }
/** * Clones a node * @param \ride\library\cms\node\Node $node Node to clone * @param boolean $recursive Set to true to also clone the children of the * node * @param boolean $reorder Set to false to just clone the order index * instead of adding the cloned node after the source node * @param boolean $keepOriginalName Set to true to keep the name untouched, * else a suffix like (clone) or (clone 2, 3 ...) will be added to the name * of the clone * @param boolean $cloneRoutesAndId Set to true to clone the routes of the nodes. * This will only work when copying a root node, else a validation error * will occur * @param boolean $newParent Provide a new parent for the clone, needed for * recursive cloning * @param boolean $autoPublish Set to false to skip auto publishing * @return null */ public function cloneNode(Node $node, $recursive = true, $reorder = null, $keepOriginalName = false, $cloneRoutesAndId = null, $newParent = null, $autoPublish = true) { $id = $node->getId(); $rootNodeId = $node->getRootNodeId(); $isRootNode = $id === $rootNodeId; if ($reorder === null) { if ($isRootNode) { $reorder = false; } else { $reorder = true; } } if ($cloneRoutesAndId === null) { if ($isRootNode) { $cloneRoutesAndId = true; } else { $cloneRoutesAndId = false; } } if ($newParent === null) { $this->widgetTable = array(); } $nodeType = $this->nodeTypeManager->getNodeType($node->getType()); $clone = $nodeType->createNode(); $clone->setRevision($node->getRevision()); if (!$isRootNode && $cloneRoutesAndId) { $clone->setId($node->getId()); } if ($newParent) { $clone->setParent($newParent); } else { $clone->setParent($node->getParent()); } if ($clone->getParent()) { $clone->setParentNode($this->io->getNode($clone->getRootNodeId(), $node->getRevision(), $clone->getParentNodeId())); } if ($reorder) { $clone->setOrderIndex($node->getOrderIndex() + 1); } else { $clone->setOrderIndex($node->getOrderIndex()); } $this->cloneNodeProperties($node, $clone, $keepOriginalName, $cloneRoutesAndId); if ($reorder) { // reorder the siblings to insert the clone $cloneOrderIndex = $clone->getOrderIndex(); $siblings = $this->io->getChildren($node->getRootNodeId(), $node->getRevision(), $node->getParent(), 0); foreach ($siblings as $sibling) { $siblingOrderIndex = $sibling->getOrderIndex(); if ($siblingOrderIndex < $cloneOrderIndex) { continue; } $sibling->setOrderIndex($siblingOrderIndex + 1); $this->setNode($sibling, 'Reordered ' . $sibling->getName() . ' after clone of ' . $node->getName(), false); } } $this->setNode($clone, 'Cloned ' . $node->getName(), false); if ($recursive) { // clone the children $path = $clone->getPath(); $children = $this->io->getChildren($node->getRootNodeId(), $node->getRevision(), $node->getPath(), 0); foreach ($children as $child) { $this->cloneNode($child, true, false, true, $cloneRoutesAndId, $path, false); } } if ($newParent === null) { unset($this->widgetTable); } // save the root for newly created widgets $this->setNode($clone->getRootNode(), 'Updated widgets for clone of ' . $node->getName(), false); // perform auto publishing if enabled if (!$isRootNode && $autoPublish && $node->getRootNode()->isAutoPublish()) { $this->publishNode($node); } return $clone; }
/** * Gets the breadcrumbs to the current locale * @param \ride\web\WebApplication $web * @param \ride\library\cms\node\Node $node * @param string $locale * @return array Array with the URL to the node as key and the name of the * node as value */ protected function getBreadcrumbs(WebApplication $web, Node $node, $locale) { $breadcrumbs = array(); do { $url = $web->getUrl('cms.node.default', array('site' => $node->getRootNodeId(), 'revision' => $node->getRevision(), 'locale' => $locale, 'node' => $node->getId())); $breadcrumbs[$url] = $node->getName($locale); $node = $node->getParentNode(); } while ($node); return array_reverse($breadcrumbs, true); }
/** * Gets a list of the available nodes * @param \ride\library\cms\node\Node $node Root node for the list * @param string $locale Code of the locale * @param boolean $includeRootNode Flag to see if the root node should be * included in the result * @param boolean $includeEmpty Flag to see if a empty value should be * included in the result * @param boolean $onlyFrontendNodes Flag to filter on frontend nodes * @return array Array with the node id as key and a string as value */ public function getNodeList(Node $node, $locale, $includeRootNode = false, $includeEmpty = true, $onlyFrontendNodes = true) { $rootNode = $this->nodeModel->getNode($node->getRootNodeId(), $node->getRevision(), $node->getId(), null, true); $options = $this->nodeModel->getListFromNodes(array($rootNode), $locale, $onlyFrontendNodes); if ($includeRootNode) { $options = array($rootNode->getId() => '/' . $rootNode->getName($locale)) + $options; } if ($includeEmpty) { $options = array('' => '---') + $options; } return $options; }
/** * Validates the route of the node * @param \ride\library\cms\node\Node $node Node to be validated * @param \ride\library\cms\node\NodeModel $nodeModel Model of the nodes * @param \ride\library\validation\exception\ValidationException $exception * @return null */ protected function validateRoute(Node $node, NodeModel $nodeModel, ValidationException $exception) { if (!$node->getParent()) { return; } $rootNode = $node->getRootNode(); $rootNodeId = $rootNode->getId(); $nodeId = $node->getId(); $modelNodes = $nodeModel->getNodes($rootNodeId, $node->getRevision()); $propertyPrefix = Node::PROPERTY_ROUTE . '.'; $lengthPropertyPrefix = strlen($propertyPrefix); // loop all properties $properties = $node->getProperties(); foreach ($properties as $key => $property) { if (strpos($key, $propertyPrefix) !== 0) { // we're only interested in route properties continue; } $routeLocale = substr($key, $lengthPropertyPrefix); $route = $property->getValue(); // normalize route $route = trim($route, '/'); $baseUrls[$routeLocale] = $rootNode->getBaseUrl($routeLocale); $tokens = explode('/', $route); foreach ($tokens as $index => $token) { if ($token) { $token = StringHelper::safeString($token); } if (empty($token)) { unset($tokens[$index]); } else { $tokens[$index] = $token; } } $route = '/' . implode('/', $tokens); // check for duplicate routes $errors = array(); foreach ($modelNodes as $modelNode) { $modelNodeId = $modelNode->getId(); if ($modelNodeId == $nodeId || $modelNode->getRootNodeId() != $rootNodeId || !$modelNode->hasParent() || $modelNode->getType() == ReferenceNodeType::NAME) { // same node, different site or root node or a reference node continue; } $modelNodeRoutes = $modelNode->getRoutes(); foreach ($modelNodeRoutes as $locale => $modelNodeRoute) { if (!array_key_exists($locale, $baseUrls)) { $baseUrls[$locale] = $rootNode->getBaseUrl($locale); } if ($baseUrls[$routeLocale] . $route != $baseUrls[$locale] . $modelNodeRoute) { continue; } $errors[$modelNodeId] = new ValidationError('error.route.used.node', "Route '%route%' is already used by node %node% in locale %locale%", array('route' => $route, 'node' => $modelNodeId, 'locale' => $locale)); } } foreach ($errors as $error) { $exception->addErrors(Node::PROPERTY_ROUTE, array($error)); } // update property with normalized route $property->setValue($route); } }
/** * Gets an array of a node with all it's properties * @param \ride\library\cms\node\Node $node * @return array */ protected function getArrayFromNode(Node $node) { $array = array(); $array[self::PROPERTY_TYPE] = new NodeProperty(self::PROPERTY_TYPE, $node->getType()); $array[self::PROPERTY_ID] = new NodeProperty(self::PROPERTY_ID, $node->getId()); $array[self::PROPERTY_PARENT] = new NodeProperty(self::PROPERTY_PARENT, $node->getParent()); $array[self::PROPERTY_ORDER] = new NodeProperty(self::PROPERTY_ORDER, $node->getOrderIndex()); $array += $node->getProperties(); return $array; }