/**
  * Loads existing resized image image from a backend
  */
 public function load()
 {
     $thumbnailMetadata = $this->backend->getWithMetadata($this->getFilePath(), array('mimetype', 'timestamp'));
     $this->timestamp = $thumbnailMetadata['timestamp'];
     $this->resizedImageSize = $thumbnailMetadata['size'];
     $this->resizedImageMimeType = $thumbnailMetadata['mimetype'];
     $this->resizedImageData = $this->backend->read($this->getFilePath());
 }
 /**
  * Deletes all thumbnails under the given path defined by the resource type,
  * path and file name.
  *
  * @param ResourceType $resourceType
  * @param string       $path
  * @param string       $fileName
  *
  * @return bool `true` if deleted successfully
  */
 public function deleteThumbnails(ResourceType $resourceType, $path, $fileName = null)
 {
     $path = Path::combine($this->getThumbnailsPath(), $resourceType->getName(), $path, $fileName);
     if ($this->thumbsBackend->has($path)) {
         return $this->thumbsBackend->deleteDir($path);
     }
     return false;
 }
 /**
  * Changes prefix for all entries given key prefix
  *
  * @param string $sourcePrefix
  * @param string $targetPrefix
  *
  * @return bool true if successful
  */
 public function changePrefix($sourcePrefix, $targetPrefix)
 {
     $sourceCachePath = $this->createCachePath($sourcePrefix, true);
     if (!$this->backend->hasDirectory($sourceCachePath)) {
         return false;
     }
     $targetCachePath = $this->createCachePath($targetPrefix, true);
     return $this->backend->rename($sourceCachePath, $targetCachePath);
 }
Beispiel #4
0
 /**
  * Adds the current folder information to the response.
  *
  * @param FilterResponseEvent $event
  */
 public function addCurrentFolderInfo(FilterResponseEvent $event)
 {
     /* @var JsonResponse $response */
     $response = $event->getResponse();
     if ($response instanceof JsonResponse) {
         $responseData = (array) $response->getData();
         $responseData = array('resourceType' => $this->getResourceTypeName(), 'currentFolder' => array('path' => $this->getClientCurrentFolder(), 'acl' => $this->getAclMask())) + $responseData;
         $baseUrl = $this->backend->getBaseUrl();
         if (null !== $baseUrl) {
             $folderUrl = Path::combine($baseUrl, Utils::encodeURLParts(Path::combine($this->resourceType->getDirectory(), $this->getClientCurrentFolder())));
             $responseData['currentFolder']['url'] = rtrim($folderUrl, '/') . '/';
         }
         $response->setData($responseData);
     }
 }
Beispiel #5
0
 /**
  * Checks if directory contains subdirectories
  *
  * @param Backend      $backend
  * @param ResourceType $resourceType
  * @param string       $clientPath
  * @param Acl          $acl
  *
  * @return bool
  */
 public function containsDirectories(Backend $backend, ResourceType $resourceType, $clientPath, Acl $acl)
 {
     $location = rtrim($this->applyPathPrefix(Path::combine($resourceType->getDirectory(), $clientPath)), '/\\') . '/';
     if (!is_dir($location) || false === ($fh = @opendir($location))) {
         return false;
     }
     $hasChildren = false;
     $resourceTypeName = $resourceType->getName();
     $clientPath = rtrim($clientPath, '/\\') . '/';
     while (false !== ($filename = readdir($fh))) {
         if ($filename == '.' || $filename == '..') {
             continue;
         }
         if (is_dir($location . $filename)) {
             if (!$acl->isAllowed($resourceTypeName, $clientPath . $filename, Permission::FOLDER_VIEW)) {
                 continue;
             }
             if ($backend->isHiddenFolder($filename)) {
                 continue;
             }
             $hasChildren = true;
             break;
         }
     }
     closedir($fh);
     return $hasChildren;
 }
Beispiel #6
0
 /**
  * Renames current file by adding number to file name.
  *
  * Renaming is done by adding number in parenthesis until file name doesn't
  * collide with any other file existing in target backend/path.
  * For example, if target backend path contains file named foo.txt
  * and current file name is foo.txt, this method will change current file
  * name to foo(1).txt.
  *
  * @param Backend $backend target backend
  * @param string  $path    target backend relative path
  *
  * @return bool true if file was renamed
  */
 public function autorename(Backend $backend = null, $path = '')
 {
     $filePath = Path::combine($path, $this->fileName);
     if (!$backend->has($filePath)) {
         return false;
     }
     $pieces = explode('.', $this->fileName);
     $basename = array_shift($pieces);
     $extension = implode('.', $pieces);
     $i = 0;
     while (true) {
         $i++;
         $this->fileName = "{$basename}({$i}).{$extension}";
         $filePath = Path::combine($path, $this->fileName);
         if (!$backend->has($filePath)) {
             break;
         }
     }
     return true;
 }