Ejemplo n.º 1
0
 /**
  * Adds current folder info 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) {
             $responseData['currentFolder']['url'] = Path::combine($baseUrl, Utils::encodeURLParts(Path::combine($this->resourceType->getDirectory(), $this->getClientCurrentFolder())));
         }
         $response->setData($responseData);
     }
 }
Ejemplo n.º 2
0
 /**
  * Returns a URL to a file.
  *
  * If the useProxyCommand option is set for a backend, the returned
  * URL will point to the CKFinder connector Proxy command.
  *
  * @param ResourceType $resourceType      the file resource type
  * @param string       $folderPath        the resource-type relative folder path
  * @param string       $fileName          the file name
  * @param string|null  $thumbnailFileName the thumbnail file name - if the file is a thumbnail
  *
  * @return string|null URL to a file or `null` if the backend does not support it.
  */
 public function getFileUrl(ResourceType $resourceType, $folderPath, $fileName, $thumbnailFileName = null)
 {
     if (isset($this->backendConfig['useProxyCommand'])) {
         $connectorUrl = $this->app->getConnectorUrl();
         $queryParameters = array('command' => 'Proxy', 'type' => $resourceType->getName(), 'currentFolder' => $folderPath, 'fileName' => $fileName);
         if ($thumbnailFileName) {
             $queryParameters['thumbnail'] = $thumbnailFileName;
         }
         $proxyCacheLifetime = (int) $this->ckConfig->get('cache.proxyCommand');
         if ($proxyCacheLifetime > 0) {
             $queryParameters['cache'] = $proxyCacheLifetime;
         }
         return $connectorUrl . '?' . http_build_query($queryParameters, '', '&');
     }
     $path = $thumbnailFileName ? Path::combine($resourceType->getDirectory(), $folderPath, ResizedImage::DIR, $fileName, $thumbnailFileName) : Path::combine($resourceType->getDirectory(), $folderPath, $fileName);
     if (isset($this->backendConfig['baseUrl'])) {
         return Path::combine($this->backendConfig['baseUrl'], Utils::encodeURLParts($path));
     }
     $baseAdapter = $this->getBaseAdapter();
     if (method_exists($baseAdapter, 'getFileUrl')) {
         return $baseAdapter->getFileUrl($path);
     }
     return null;
 }
Ejemplo n.º 3
0
 /**
  * @param ResourceType $resourceType resource type
  * @param string       $path         resource type relative path
  */
 public function __construct(ResourceType $resourceType, $path)
 {
     $this->resourceType = $resourceType;
     $this->path = Path::combine($resourceType->getDirectory(), $path);
 }
Ejemplo n.º 4
0
 /**
  * Returns backend-relative folder path (i.e. a path with a prepended resource type directory).
  *
  * @return string backend-relative path
  */
 public function getPath()
 {
     return Path::combine($this->resourceType->getDirectory(), $this->folder);
 }
Ejemplo n.º 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;
 }
 /**
  * @param ResourceType $sourceFileResourceType
  * @param string       $sourceFilePath
  * @param string       $sourceFileName
  * @param int          $width
  * @param int          $height
  *
  * @return ResizedImage|null
  */
 public function getResizedImageBySize(ResourceType $sourceFileResourceType, $sourceFilePath, $sourceFileName, $width, $height)
 {
     $resizedImagesPath = Path::combine($sourceFileResourceType->getDirectory(), $sourceFilePath, ResizedImage::DIR, $sourceFileName);
     $backend = $sourceFileResourceType->getBackend();
     if (!$backend->hasDirectory($resizedImagesPath)) {
         return null;
     }
     $resizedImagesFiles = array_filter($backend->listContents($resizedImagesPath), function ($v) {
         return isset($v['type']) && $v['type'] === 'file';
     });
     $thresholdPixels = $this->config->get('images.threshold.pixels');
     $thresholdPercent = (double) $this->config->get('images.threshold.percent') / 100;
     foreach ($resizedImagesFiles as $resizedImage) {
         $resizedImageSize = ResizedImage::getSizeFromFilename($resizedImage['basename']);
         $resizedImageWidth = $resizedImageSize['width'];
         $resizedImageHeight = $resizedImageSize['height'];
         if ($resizedImageWidth >= $width && ($resizedImageWidth <= $width + $thresholdPixels || $resizedImageWidth <= $width + $width * $thresholdPercent) && $resizedImageHeight >= $height && ($resizedImageHeight <= $height + $thresholdPixels || $resizedImageHeight <= $height + $height * $thresholdPercent)) {
             $resizedImage = new ResizedImage($this, $sourceFileResourceType, $sourceFilePath, $sourceFileName, $resizedImageWidth, $resizedImageHeight);
             if ($resizedImage->exists()) {
                 $resizedImage->load();
                 return $resizedImage;
             }
         }
     }
     return null;
 }
Ejemplo n.º 7
0
 /**
  * Returns a path based on resource type and resource type relative path
  *
  * @param ResourceType $resourceType resource type
  * @param string       $path         resource type relative path
  *
  * @return string path to be used with backend adapter
  */
 public function buildPath(ResourceType $resourceType, $path)
 {
     return Path::combine($resourceType->getDirectory(), $path);
 }