/**
  * Checks if this action is available for the node
  * @param \ride\library\cms\node\Node $node
  * @return boolean True if available
  */
 public function isAvailableForNode(Node $node)
 {
     if (!$node->getParent()) {
         return true;
     }
     $nodeType = $this->cms->getNodeType($node);
     return $nodeType->getFrontendCallback() ? true : false;
 }
Ejemplo n.º 2
0
 /**
  * Checks if this action is available for the node
  * @param \ride\library\cms\node\Node $node
  * @return boolean True if available
  */
 public function isAvailableForNode(Node $node)
 {
     if (!$node->getParent()) {
         return !$node->isAutoPublish();
     }
     $nodeType = $this->cms->getNodeType($node);
     $isAvailable = $nodeType->getFrontendCallback() ? true : false;
     return $isAvailable && !$node->getRootNode()->isAutoPublish();
 }
 /**
  * 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;
 }
Ejemplo n.º 4
0
 /**
  * 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;
 }
 /**
  * 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);
 }
 /**
  * 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), '/') . '/');
 }
Ejemplo n.º 8
0
 /**
  * Constructs a new site node
  * @param string $type Name of the node type
  * @return null
  */
 public function __construct($type = null)
 {
     if (!$type) {
         $type = PageNodeType::NAME;
     }
     parent::__construct($type);
     $this->defaultInherit = false;
 }
 /**
  * Get a suffix for the security inherit label based on the inherited settings
  * @param \ride\library\cms\node\Node $node
  * @param \ride\library\i18n\translator\Translator $translator
  * @return string if a publish setting is found the suffix will be " (Yes)" or " (No)"
  */
 protected function getSecurityInheritSuffix(Node $node, Translator $translator)
 {
     $security = $node->get(Node::PROPERTY_SECURITY, Node::AUTHENTICATION_STATUS_EVERYBODY, true, true);
     $suffix = ' (';
     switch ($security) {
         case Node::AUTHENTICATION_STATUS_EVERYBODY:
             $suffix .= $translator->translate('label.allow.everybody');
             break;
         case Node::AUTHENTICATION_STATUS_ANONYMOUS:
             $suffix .= $translator->translate('label.allow.anonymous');
             break;
         case Node::AUTHENTICATION_STATUS_AUTHENTICATED:
             $suffix .= $translator->translate('label.allow.authenticated');
             break;
         default:
             $suffix .= $security;
             break;
     }
     $suffix .= ')';
     return strtolower($suffix);
 }
Ejemplo n.º 10
0
 /**
  * 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;
 }
 /**
  * Gets the collapsed nodes for the provided node
  * @param \ride\library\cms\node\Node $node
  * @return array Array with the collapsed node id as key and true as value
  */
 protected function getCollapsedNodes(Node $node)
 {
     $site = $node->getRootNodeId();
     $revision = '[' . $node->getRevision() . ']';
     $nodes = array();
     $collapsedNodes = $this->cms->getCollapsedNodes();
     foreach ($collapsedNodes as $node => $flag) {
         if (strpos($node, $site) !== 0 || strpos($node, $revision) === false) {
             continue;
         }
         $node = str_replace($revision, '', $node);
         $tokens = explode(Node::PATH_SEPARATOR, $node);
         $nodes[array_pop($tokens)] = true;
     }
     return $nodes;
 }
Ejemplo n.º 12
0
 /**
  * Get a HTML representation of a Node instance
  * @param \ride\library\cms\node\Node $node
  * @return string HTML representation of the Node
  */
 protected function getHtmlFromNode(Node $node)
 {
     $properties = array();
     $parentNode = $node->getParentNode();
     while ($parentNode) {
         $parentProperties = $parentNode->getProperties();
         foreach ($parentProperties as $key => $property) {
             if ($property->getInherit() && !isset($properties[$key])) {
                 $properties[$key] = $property;
             }
         }
         $parentNode = $parentNode->getParentNode();
     }
     $nodeProperties = $node->getProperties();
     $properties = $nodeProperties + $properties;
     ksort($properties);
     $html = '';
     foreach ($properties as $key => $property) {
         $value = $property->getIniString(true);
         if ($property->getInherit()) {
             $value = substr($value, 1);
         }
         if (isset($nodeProperties[$key])) {
             $html .= '<strong>' . $value . '</strong>';
         } else {
             $html .= $value;
         }
         $html .= "<br />\n";
     }
     return $html;
 }
Ejemplo n.º 13
0
 /**
  * Removes a node
  * @param \ride\library\cms\node\Node $node Node to delete
  * @param boolean $recursive Flag to see if child nodes should be deleted
  * @return
  */
 public function removeNode(Node $node, $recursive = true)
 {
     $siteId = $node->getRootNodeId();
     $revision = $node->getRevision();
     $parent = $node->getParent();
     $path = $node->getPath();
     $orderIndex = $node->getOrderIndex();
     $baseOrderIndex = $orderIndex - 1;
     $changedNodes = array();
     // remove children or move the children the the parent's path
     $numChildren = 0;
     $children = $this->getNodesByPath($siteId, $revision, $path);
     foreach ($children as $child) {
         if ($recursive) {
             $this->removeNode($child, true);
             continue;
         }
         $childParent = $child->getParent();
         if ($childParent === $path) {
             $child->setOrderIndex($baseOrderIndex + $child->getOrderIndex());
             $numChildren++;
         }
         $child->setParent(str_replace($path, $parent, $childParent));
         $changedNodes[] = $child;
     }
     if (!$recursive) {
         // fix order index for nodes after the removed node
         $siblings = $this->getChildren($node->getRootNodeId(), $node->getRevision(), $parent, 0);
         foreach ($siblings as $sibling) {
             $siblingOrderIndex = $sibling->getOrderIndex();
             if ($siblingOrderIndex <= $orderIndex) {
                 continue;
             }
             $sibling->setOrderIndex($siblingOrderIndex + $numChildren - 1);
             $changedNodes[] = $sibling;
         }
     }
     // save and remove the necessairy nodes
     foreach ($changedNodes as $changedNode) {
         $this->setNode($changedNode);
     }
     $this->deleteNode($node);
     unset($this->nodes[$siteId][$revision][$node->getId()]);
 }
 /**
  * Checks if this action is available for the node
  * @param \ride\library\cms\node\Node $node
  * @return boolean True if available
  */
 public function isAvailableForNode(Node $node)
 {
     return !$node->hasParent();
 }
Ejemplo n.º 15
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;
     }
 }
 /**
  * Validates the publication dates
  * @param \ride\library\cms\node\Node $node Node to be validated
  * @param \ride\library\validation\exception\ValidationException $exception
  * @return null
  */
 protected function validatePublicationDate(Node $node, ValidationException $exception)
 {
     $publishStart = $node->get(Node::PROPERTY_PUBLISH_START, null, false);
     $publishStop = $node->get(Node::PROPERTY_PUBLISH_STOP, null, false);
     $isPublishStartEmpty = empty($publishStart);
     $isPublishStopEmpty = empty($publishStop);
     if (!$isPublishStartEmpty) {
         $this->validateDate($publishStart, $exception, Node::PROPERTY_PUBLISH_START);
     }
     if (!$isPublishStopEmpty) {
         $this->validateDate($publishStop, $exception, Node::PROPERTY_PUBLISH_STOP);
     }
     if (!$isPublishStartEmpty && !$isPublishStopEmpty && $publishStart >= $publishStop) {
         $error = new ValidationError('error.date.publish.negative', 'Publish stop date cannot be before the publish start date');
         $exception->addErrors(Node::PROPERTY_PUBLISH_STOP, array($error));
     }
 }
Ejemplo n.º 17
0
 /**
  * Cleans up all properties in the provided node which are used one of the
  * provided widgets
  * @param \ride\library\cms\node\Node $node
  * @param array $unusedWidgetd Array with the widget instance id as key
  * @return boolean Flag to see if the node has changed
  */
 protected function clearWidgetUsage(Node $node, array $unusedWidgets)
 {
     $isChanged = false;
     $isRootNode = $node->getParent() ? false : true;
     $properties = $node->getProperties();
     foreach ($unusedWidgets as $widgetId => $null) {
         foreach ($properties as $key => $property) {
             if (strpos($key, Node::PROPERTY_WIDGET . '.' . $widgetId . '.') === 0 || $isRootNode && $key === Node::PROPERTY_WIDGET . '.' . $widgetId) {
                 $node->set($key, null);
                 $isChanged = true;
             }
         }
     }
     return $isChanged;
 }
Ejemplo n.º 18
0
 /**
  * Checks whether the node is localized
  * @param string $locale
  * @return boolean
  */
 public function isLocalized($locale)
 {
     $localizedName = $this->node->getProperty(Node::PROPERTY_NAME . '.' . $locale);
     return $localizedName ? true : false;
 }
Ejemplo n.º 19
0
 /**
  * Parses the widget from the provided section string
  * @param string $section String to define the widgets in a section
  * eg. [12,4,87],[43,2]
  * @return array Array with the block id as key and as value an array with the
  * widget instance id as key and the widget id as value
  */
 public function parseSectionString(Node $site, $sectionString)
 {
     $blocks = array();
     $blocksWidgetIds = explode(self::BLOCK_CLOSE . NodeProperty::LIST_SEPARATOR . self::BLOCK_OPEN, $sectionString);
     foreach ($blocksWidgetIds as $block => $blockWidgetIds) {
         $block++;
         // start from 1 instead of 0
         $blocks[$block] = array();
         $blockWidgetIds = trim($blockWidgetIds, self::BLOCK_OPEN . self::BLOCK_CLOSE . ' ');
         if (!$blockWidgetIds) {
             continue;
         }
         $widgetIds = explode(NodeProperty::LIST_SEPARATOR, $blockWidgetIds);
         foreach ($widgetIds as $widgetId) {
             $widgetId = trim($widgetId);
             $blocks[$block][$widgetId] = $site->get(self::PROPERTY_WIDGET . '.' . $widgetId);
         }
     }
     return $blocks;
 }
Ejemplo n.º 20
0
 /**
  * Creates a new node of this type
  * @return \ride\library\cms\node\Node
  */
 public function createNode()
 {
     $node = new Node($this->getName());
     $node->setDefaultInherit($this->getDefaultInherit());
     return $node;
 }
 /**
  * Gets the available locales options
  * @param \ride\library\cms\node\Node $node
  * @param \ride\library\i18n\translator\Translator $translator
  * @param array $locales
  * @return array Array with the publish code as key and the translation as
  * value
  */
 protected function getLocalesOptions(Node $node, Translator $translator, array $locales)
 {
     $options = array();
     $parentNode = $node->getParentNode();
     if ($parentNode) {
         $inheritedValue = $parentNode->get(Node::PROPERTY_LOCALES, Node::LOCALES_ALL, true, true);
         $options[self::OPTION_INHERITED] = $translator->translate('label.inherited') . ' (' . $inheritedValue . ')';
     }
     $options[Node::LOCALES_ALL] = $translator->translate('label.locales.all');
     foreach ($locales as $locale) {
         $options[$locale] = $translator->translate('language.' . $locale);
     }
     return $options;
 }
Ejemplo n.º 22
0
 /**
  * Sets a property
  * @param NodeProperty $property
  * @return null
  */
 public function setProperty(NodeProperty $property)
 {
     parent::setProperty($property);
     $key = $property->getKey();
     if (strpos($key, Node::PROPERTY_WIDGET) === 0 && strrpos($key, '.') === 6) {
         $this->widgets[substr($key, 7)] = $property->getValue();
     }
 }
Ejemplo n.º 23
0
 /**
  * Constructs a new site node
  * @return null
  */
 public function __construct()
 {
     parent::__construct(RedirectNodeType::NAME);
     $this->defaultInherit = true;
 }
Ejemplo n.º 24
0
 /**
  * Gets the node type of the provided node
  * @param \ride\library\cms\node\Node $node Node to get the type from
  * @return \ride\library\cms\node\type\NodeType
  */
 public function getNodeType(Node $node)
 {
     $nodeTypeManager = $this->nodeModel->getNodeTypeManager();
     return $nodeTypeManager->getNodeType($node->getType());
 }
 /**
  * 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);
 }
 /**
  * Gets the inherited cache options
  * @param \ride\library\cms\node\Node $parentNode
  * @param \ride\library\i18n\translator\Translator $translator
  * @param $locale
  *
  * @return string
  */
 protected function getInheritedCacheOption(Node $parentNode, Translator $translator, $locale)
 {
     $value = $parentNode->get('cache.target', null, true, true);
     $maxAge = $parentNode->getHeader($locale, 'max-age');
     $sharedMaxAge = $parentNode->getHeader($locale, 's-maxage');
     if (empty($value)) {
         return "";
     }
     $suffix = ' (';
     $suffix .= $translator->translate('label.cache.target.' . $value);
     $suffix .= in_array($value, array('inherit', 'all')) ? ', ' . $translator->translate('label.header.maxage') . ': ' . $translator->translate('label.cache.time.' . $maxAge) : null;
     $suffix .= in_array($value, array('inherit', 'intermediate', 'all')) ? ', ' . $translator->translate('label.header.smaxage') . ': ' . $translator->translate('label.cache.time.' . $sharedMaxAge) : null;
     $suffix .= ')';
     return $suffix;
 }
Ejemplo n.º 27
0
 /**
  * Gets the image of this node
  * @param string $locale Code of the locale
  * @return string|null Path to the image if set, null otherwise
  */
 public function getImage($locale)
 {
     $image = parent::getImage($locale);
     if ($image) {
         return $image;
     }
     $node = $this->getNode();
     if ($node) {
         return $node->getImage($locale);
     }
 }
 /**
  * Gets all the extra widget URL's
  * @param array $result Result to add URL's to
  * @param \ride\library\cms\node\Node $node Node to process
  * @param string $locale
  * @param string $nodeUrl
  * @return array
  */
 protected function getWidgetUrls(array $result, Node $node, $locale, $nodeUrl)
 {
     $theme = $this->cms->getTheme($node->getTheme());
     $regions = $theme->getRegions();
     foreach ($regions as $region => $null) {
         $sections = $node->getSections($region);
         foreach ($sections as $section => $layout) {
             $widgets = $node->getWidgets($region, $section);
             foreach ($widgets as $block => $widgets) {
                 foreach ($widgets as $widgetId => $widget) {
                     $widget = $this->cms->getWidget($widget);
                     if (!$widget) {
                         continue;
                     }
                     $widget = clone $widget;
                     $widget->setIdentifier($widgetId);
                     $widget->setRegion($region);
                     $widget->setSection($section);
                     $widget->setBlock($block);
                     $widget->setProperties($node->getWidgetProperties($widgetId));
                     $widget->setLocale($locale);
                     $routes = $widget->getRoutes();
                     if (!$routes) {
                         continue;
                     }
                     foreach ($routes as $route) {
                         $path = $route->getPath();
                         $pathTokens = $route->getPathTokens();
                         foreach ($pathTokens as $token) {
                             if (substr($token, 0, 1) == '%' && substr($token, -1) == '%') {
                                 $path = str_replace($token, '*', $path);
                             }
                         }
                         $result[] = $nodeUrl . $path;
                     }
                 }
             }
         }
     }
     return $result;
 }
Ejemplo n.º 29
0
 /**
  * Processes the widgets of a section to make them ready for usage
  * @param \ride\library\cms\node\Node $node Instance of the node
  * @param string $region Name of the region
  * @param string $section Name of the section
  * @param array $availableWidgets Array with the id of a widget instance as
  * key and the dependency id as value
  * @param array $widgets Array for the resulting widgets. The key will be
  * the id of the block, the value an array with the widget id as key and the
  * widget instance as value
  * @param array $inheritedWidgets Array with structure of the $widgets var
  * indicating which widgets are inherited, value in the block array is a
  * widget id and not a widget instance
  * @return null
  */
 protected function processSectionWidgets(Node $node, $locale, $region, $section, array $availableWidgets, array &$widgets, array &$inheritedWidgets)
 {
     $inheritedSectionWidgets = $node->getInheritedWidgets($region, $section);
     $sectionWidgets = $node->getWidgets($region, $section);
     foreach ($sectionWidgets as $block => $blockWidgets) {
         $widgets[$block] = array();
         $inheritedWidgets[$block] = array();
         foreach ($blockWidgets as $widgetId => $widget) {
             if (!$widget || !isset($availableWidgets[$widget])) {
                 continue;
             }
             $widget = clone $availableWidgets[$widget];
             $widget->setIdentifier($widgetId);
             $widget->setProperties($node->getWidgetProperties($widgetId));
             $widget->setLocale($locale);
             if ($widget instanceof AbstractController) {
                 $widget->setConfig($this->config);
                 $widget->setDependencyInjector($this->dependencyInjector);
             }
             $widgets[$block][$widgetId] = $widget;
             if (isset($inheritedSectionWidgets[$block][$widgetId])) {
                 $inheritedWidgets[$block][$widgetId] = $widgetId;
             }
         }
     }
 }
Ejemplo n.º 30
0
 /**
  * Checks if this action is available for the node
  * @param \ride\library\cms\node\Node $node
  * @return boolean True if available
  */
 public function isAvailableForNode(Node $node)
 {
     return !$node->getRootNode()->isAutoPublish();
 }