예제 #1
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 (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);
		}
	}
예제 #2
0
파일: preview.php 프로젝트: unrealbato/core
 /**
  * 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);
     }
 }
예제 #3
0
 /**
  * Returns a preview of a file
  *
  * The cache is searched first and if nothing usable was found then a preview is
  * generated by one of the providers
  *
  * @return \OCP\IImage
  */
 public function getPreview()
 {
     if (!is_null($this->preview) && $this->preview->valid()) {
         return $this->preview;
     }
     $this->preview = null;
     $fileInfo = $this->getFileInfo();
     if ($fileInfo === null || $fileInfo === false) {
         return new \OC_Image();
     }
     $fileId = $fileInfo->getId();
     $cached = $this->isCached($fileId);
     if ($cached) {
         $this->getCachedPreview($fileId, $cached);
     }
     if (is_null($this->preview)) {
         $this->generatePreview($fileId);
     }
     // We still don't have a preview, so we generate an empty object which can't be displayed
     if (is_null($this->preview)) {
         $this->preview = new \OC_Image();
     }
     return $this->preview;
 }