Example #1
0
	/**
	 * set the path of the file you want a thumbnail from
	 * @param string $file
	 * @return \OC\Preview $this
	 */
	public function setFile($file) {
		$this->file = $file;
		$this->info = null;
		if ($file !== '') {
			$this->getFileInfo();
			if($this->info !== null && $this->info !== false) {
				$this->mimeType = $this->info->getMimetype();
			}
		}
		return $this;
	}
Example #2
0
 /**
  * set the path of the file you want a thumbnail from
  * @param string $file
  * @return $this
  */
 public function setFile($file)
 {
     $this->file = $file;
     $this->info = null;
     if ($file !== '') {
         $this->getFileInfo();
         if ($this->info instanceof \OCP\Files\FileInfo) {
             $this->mimeType = $this->info->getMimetype();
         }
     }
     return $this;
 }
Example #3
0
 /**
  * Create a new file search result
  * @param FileInfo $data file data given by provider
  */
 public function __construct(FileInfo $data)
 {
     $path = $this->getRelativePath($data->getPath());
     $info = pathinfo($path);
     $this->id = $data->getId();
     $this->name = $info['basename'];
     $this->link = \OCP\Util::linkTo('files', 'index.php', array('dir' => $info['dirname'], 'file' => $info['basename']));
     $this->permissions = $data->getPermissions();
     $this->path = $path;
     $this->size = $data->getSize();
     $this->modified = $data->getMtime();
     $this->mime_type = $data->getMimetype();
 }
Example #4
0
 /**
  * Create a new file search result
  * @param FileInfo $data file data given by provider
  */
 public function __construct(FileInfo $data)
 {
     $path = $this->getRelativePath($data->getPath());
     $info = pathinfo($path);
     $this->id = $data->getId();
     $this->name = $info['basename'];
     $this->link = \OC::$server->getURLGenerator()->linkToRoute('files.view.index', ['dir' => $info['dirname'], 'scrollto' => $info['basename']]);
     $this->permissions = $data->getPermissions();
     $this->path = $path;
     $this->size = $data->getSize();
     $this->modified = $data->getMtime();
     $this->mime = $data->getMimetype();
 }
Example #5
0
 /**
  * Determine icon for a given file
  *
  * @param \OCP\Files\FileInfo $file file info
  * @return string icon URL
  */
 public static function determineIcon($file)
 {
     if ($file['type'] === 'dir') {
         $icon = \OC_Helper::mimetypeIcon('dir');
         // TODO: move this part to the client side, using mountType
         if ($file->isShared()) {
             $icon = \OC_Helper::mimetypeIcon('dir-shared');
         } elseif ($file->isMounted()) {
             $icon = \OC_Helper::mimetypeIcon('dir-external');
         }
     } else {
         $icon = \OC_Helper::mimetypeIcon($file->getMimetype());
     }
     return substr($icon, 0, -3) . 'svg';
 }
Example #6
0
 /**
  * Sends the preview, including the headers to client which requested it
  *
  * @param null|string $mimeTypeForHeaders the media type to use when sending back the reply
  *
  * @throws NotFoundException
  */
 public function showPreview($mimeTypeForHeaders = null)
 {
     // Check if file is valid
     if ($this->isFileValid() === false) {
         throw new NotFoundException('File not found.');
     }
     if ($cachedPath = $this->isCached($this->info->getId())) {
         header('Content-Type: ' . $this->info->getMimetype());
         $this->userView->readfile($cachedPath);
         return;
     }
     if (is_null($this->preview)) {
         $this->getPreview();
     }
     if ($this->preview instanceof \OCP\IImage) {
         if ($this->preview->valid()) {
             \OCP\Response::enableCaching(3600 * 24);
             // 24 hours
         } else {
             $this->getMimeIcon();
         }
         $this->preview->show($mimeTypeForHeaders);
     }
 }
 /**
  * Check if a preview can be generated for a file
  *
  * @param \OCP\Files\FileInfo $file
  * @return bool
  */
 public function isAvailable(\OCP\Files\FileInfo $file)
 {
     if (!$this->config->getSystemValue('enable_previews', true)) {
         return false;
     }
     $this->registerCoreProviders();
     if (!$this->isMimeSupported($file->getMimetype())) {
         return false;
     }
     $mount = $file->getMountPoint();
     if ($mount and !$mount->getOption('previews', true)) {
         return false;
     }
     foreach ($this->providers as $supportedMimeType => $providers) {
         if (preg_match($supportedMimeType, $file->getMimetype())) {
             foreach ($providers as $closure) {
                 $provider = $closure();
                 if (!$provider instanceof IProvider) {
                     continue;
                 }
                 /** @var $provider IProvider */
                 if ($provider->isAvailable($file)) {
                     return true;
                 }
             }
         }
     }
     return false;
 }