コード例 #1
0
 /**
  * Clears all the properties of the widget
  * @param string $prefix Prefix of the properties to remove
  * @return null
  */
 public function clearWidgetProperties($prefix = null)
 {
     $prefix = $this->widgetPropertyPrefix . $prefix;
     $properties = $this->node->getProperties();
     foreach ($properties as $key => $property) {
         if (strpos($key, $prefix) === 0) {
             unset($properties[$key]);
         }
     }
     $this->node->setProperties($properties);
 }
コード例 #2
0
ファイル: Node.php プロジェクト: janhenckens/ride-lib-cms
 /**
  * Gets the properties of this node
  * @param string $prefix Prefix of the properties to fetch
  * @param boolean $inherited True to look in inherited properties, false to
  * only look in this node
  * @param boolean $inheritedPropertyRequired True to only return the value
  * if the property will inherit, needed internally for recursive lookup
  * @return array Array with the property key as key and a NodeProperty
  * instance as value
  */
 public function getProperties($prefix = null, $inherited = false, $inheritedPropertyRequired = false)
 {
     $properties = array();
     foreach ($this->properties as $key => $property) {
         if ($prefix && strpos($key, $prefix) !== 0 || $inheritedPropertyRequired && !$property->getInherit()) {
             continue;
         }
         $properties[$key] = $property;
     }
     if ($inherited && $this->parentNode) {
         $properties += $this->parentNode->getProperties($prefix, true, true);
     }
     return $properties;
 }
コード例 #3
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;
 }
コード例 #4
0
 /**
  * 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);
     }
 }
コード例 #5
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;
 }
コード例 #6
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;
 }