Пример #1
0
 /**
  * Constructs a new theme
  * @param string $name Machine name of the theme
  * @param string $displayName Display name of the theme
  * @param array $engines Array with the engine name as key and as value
  * @param array $regions Array with the region name as key and as value
  * @param string $parent Machine name of the parent
  * @return null
  */
 public function __construct($name, $displayName, $engines, $regions, $parent = null)
 {
     $this->name = StringHelper::safeString($name);
     $this->displayName = $displayName;
     $this->engines = $engines;
     $this->regions = $regions;
     $this->parent = $parent;
 }
Пример #2
0
 /**
  * Gets a id for a new node
  * @param \ride\library\cms\node\Node $node Node in need of a id
  * @return string
  */
 protected function getNewNodeId(Node $node)
 {
     $revision = $node->getRevision();
     $nodeName = $node->getName();
     if (!$nodeName) {
         $nodeName = 'node';
     }
     $baseId = StringHelper::safeString($nodeName);
     $baseId = str_replace(array('.', '-', '_', ' '), '', $baseId);
     $id = $baseId;
     $index = 1;
     try {
         $siteId = $node->getRootNodeId();
         $this->getNodes($siteId, $revision);
         while (isset($this->nodes[$siteId][$revision][$id])) {
             $id = $baseId . $index;
             $index++;
         }
     } catch (CmsException $exception) {
         // new site node
         $this->getSites();
         while (isset($this->sites[$id])) {
             $id = $baseId . $index;
             $index++;
         }
     }
     return $id;
 }
 /**
  * Caches the response
  * @param \ride\web\WebApplication $web
  * @return null
  */
 public function cacheResponse(WebApplication $web)
 {
     if (!isset($this->cache)) {
         return;
     }
     if (!isset($this->cacheTtl)) {
         $this->cacheTtl = 0;
     }
     $request = $web->getRequest();
     $response = $web->getResponse();
     $cacheKey = 'node.response.' . StringHelper::safeString($request->getUrl());
     if ($this->log) {
         $this->log->logDebug('Caching the request', 'Ttl: ' . $this->cacheTtl . ' - ' . $cacheKey, ApplicationListener::LOG_SOURCE);
     }
     $cachedResponse = $this->cache->create($cacheKey);
     $cachedResponse->setValue($response);
     $cachedResponse->setTtl($this->cacheTtl);
     $this->cache->set($cachedResponse);
 }
Пример #4
0
 /**
  * Gets the file name for a newly uploaded file
  * @param \ride\library\orm\model\Model $model
  * @param \ride\library\orm\definition\field\ModelField $field
  * @param \ride\library\orm\entry\Entry $entry
  * @return string Name for the file without path and extension
  */
 protected function getFileName(Model $model, ModelField $field, Entry $entry)
 {
     $entryFormatter = $model->getOrmManager()->getEntryFormatter();
     $format = $model->getMeta()->getFormat(EntryFormatter::FORMAT_TITLE);
     $name = $entryFormatter->formatEntry($entry, $format);
     if ($name) {
         $name = StringHelper::safeString($name);
     } else {
         $name = StringHelper::generate();
     }
     return $name;
 }
 /**
  * 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);
     }
 }
Пример #6
0
 /**
  * Handles a file upload via a dataURI string
  * @param string $fileName Filename
  * @param string $dataUri DataURI with file content
  * @return \ride\library\system\file\File
  * @throws \ride\library\system\exception\FileSystemException
  */
 public function handleDataUri($fileName, $dataUriString)
 {
     // decode dataUri
     $uploadFile = null;
     $dataUri = null;
     try {
         $dataUri = DataUri::decode($dataUriString);
     } catch (HttpException $err) {
     }
     if ($dataUri instanceof DataUri) {
         // add extension based on claimed mime type
         $mimeType = $dataUri->getMimeType();
         $mimeExtension = $this->mimeResolver->getExtensionForMimeType($mimeType);
         if (is_string($mimeExtension)) {
             $fileName .= '.' . $mimeExtension;
         }
         // prepare file name
         $fileName = StringHelper::safeString($fileName, '_', false);
         $uploadFile = $this->getUploadDirectoryTemporary()->getChild($fileName);
         $uploadFile = $uploadFile->getCopyFile();
         $uploadFile->write($dataUri->getData());
         $uploadFile->setPermissions(0644);
     }
     return $uploadFile;
 }