Example #1
0
 /**
  * @param string $owner
  * @param int $fileId
  * @param string $filePath
  * @return array
  */
 protected function getPreview($owner, $fileId, $filePath)
 {
     $info = $this->infoCache->getInfoById($owner, $fileId, $filePath);
     if (!$info['exists'] || $info['view'] !== '') {
         return $this->getPreviewFromPath($filePath, $info);
     }
     $preview = ['link' => $this->getPreviewLink($info['path'], $info['is_dir'], $info['view']), 'source' => '', 'isMimeTypeIcon' => true];
     // show a preview image if the file still exists
     if ($info['is_dir']) {
         $preview['source'] = $this->getPreviewPathFromMimeType('dir');
     } else {
         $this->view->chroot('/' . $owner . '/files');
         $fileInfo = $this->view->getFileInfo($info['path']);
         if (!$fileInfo instanceof FileInfo) {
             $pathPreview = $this->getPreviewFromPath($filePath, $info);
             $preview['source'] = $pathPreview['source'];
         } else {
             if ($this->preview->isAvailable($fileInfo)) {
                 $preview['isMimeTypeIcon'] = false;
                 $preview['source'] = $this->urlGenerator->linkToRoute('core_ajax_preview', ['file' => $info['path'], 'c' => $this->view->getETag($info['path']), 'x' => 150, 'y' => 150]);
             } else {
                 $preview['source'] = $this->getPreviewPathFromMimeType($fileInfo->getMimetype());
             }
         }
     }
     return $preview;
 }
 /**
  * @param string $owner
  * @param int $fileId
  * @param string $filePath
  * @return array
  */
 protected function getPreview($owner, $fileId, $filePath)
 {
     $this->view->chroot('/' . $owner . '/files');
     $path = $this->view->getPath($fileId);
     if ($path === null || $path === '' || !$this->view->file_exists($path)) {
         return $this->getPreviewFromPath($filePath);
     }
     $is_dir = $this->view->is_dir($path);
     $preview = ['link' => $this->getPreviewLink($path, $is_dir), 'source' => '', 'isMimeTypeIcon' => true];
     // show a preview image if the file still exists
     if ($is_dir) {
         $preview['source'] = $this->getPreviewPathFromMimeType('dir');
     } else {
         $fileInfo = $this->view->getFileInfo($path);
         if ($this->preview->isAvailable($fileInfo)) {
             $preview['isMimeTypeIcon'] = false;
             $preview['source'] = $this->urlGenerator->linkToRoute('core_ajax_preview', ['file' => $path, 'c' => $this->view->getETag($path), 'x' => 150, 'y' => 150]);
         } else {
             $preview['source'] = $this->getPreviewPathFromMimeType($fileInfo->getMimetype());
         }
     }
     return $preview;
 }
Example #3
0
 /**
  * get the ETag for a file or folder
  *
  * @param string $path
  * @return string
  */
 public static function getETag($path)
 {
     return self::$defaultInstance->getETag($path);
 }