/** * 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); } }
/** * show preview * @return void */ public function showPreview($mimeType = null) { \OCP\Response::enableCaching(3600 * 24); // 24 hours if (is_null($this->preview)) { $this->getPreview(); } $this->preview->show($mimeType); }
public function show() { if ($this->useOriginal) { $fp = @$this->view->fopen($this->path, 'rb'); $mtime = $this->view->filemtime($this->path); $size = $this->view->filesize($this->path); $mime = $this->view->getMimetype($this->path); } else { $fp = @fopen($this->path, 'rb'); $mtime = filemtime($this->path); $size = filesize($this->path); $mime = \OC_Helper::getMimetype($this->path); } if ($fp) { \OCP\Response::enableCaching(); \OCP\Response::setLastModifiedHeader($mtime); header('Content-Length: ' . $size); header('Content-Type: ' . $mime); fpassthru($fp); } else { \OC_Response::setStatus(\OC_Response::STATUS_NOT_FOUND); } }
/** * @param null|string $mimeType * @throws NotFoundException */ public function showPreview($mimeType = null) { // Check if file is valid if ($this->isFileValid() === false) { throw new NotFoundException('File not found.'); } \OCP\Response::enableCaching(3600 * 24); // 24 hours if (is_null($this->preview)) { $this->getPreview(); } if ($this->preview instanceof \OC_Image) { $this->preview->show($mimeType); } }
/** * @brief analyses the parameter for calendar parameter and returns the objects * @param (string) $calendarid - calendarid * @param (int) $start - unixtimestamp of start * @param (int) $end - unixtimestamp of end * @return (array) $events */ public static function getrequestedEvents($calendarid, $start, $end) { $events = array(); if ($calendarid === 'shared_events') { $checkStart = $start->format('U'); $singleevents = \OCP\Share::getItemsSharedWith(self::SHAREEVENT, ShareEvent::FORMAT_EVENT); foreach ($singleevents as $singleevent) { $startCheck_dt = new \DateTime($singleevent['startdate'], new \DateTimeZone('UTC')); $checkStartSE = $startCheck_dt->format('U'); // \OCP\Util::writeLog('calendar','STARTDATE'.$checkStart.' -> '.$checkStartSE, \OCP\Util::DEBUG); if ($checkStartSE > $checkStart) { $singleevent['summary'] .= ' (' . (string) self::$l10n->t('by') . ' ' . Object::getowner($singleevent['id']) . ')'; $events[] = $singleevent; } } } else { if (is_numeric($calendarid)) { $calendar = self::getCalendar($calendarid); \OCP\Response::enableCaching(0); \OCP\Response::setETagHeader($calendar['ctag']); $events = Object::allInPeriod($calendarid, $start, $end, $calendar['userid'] !== \OCP\User::getUser()); } else { \OCP\Util::emitHook('OCA\\CalendarPlus', 'getEvents', array('calendar_id' => $calendarid, 'events' => &$events)); } } return $events; }
$song['artist'] = $collection->getArtistName($song['song_artist']); $song['album'] = $collection->getAlbumName($song['song_album']); \OCP\JSON::encodedPrint($song); } } break; case 'play': $ftype = \OC\Files\Filesystem::getMimeType($arguments['path']); if (substr($ftype, 0, 5) != 'audio' and $ftype != 'application/ogg') { echo 'Not an audio file'; exit; } $songId = $collection->getSongByPath($arguments['path']); $collection->registerPlay($songId); header('Content-Type:' . $ftype); \OCP\Response::enableCaching(3600 * 24); // 24 hour header('Accept-Ranges: bytes'); header('Content-Length: ' . \OC\Files\Filesystem::filesize($arguments['path'])); $mtime = \OC\Files\Filesystem::filemtime($arguments['path']); \OCP\Response::setLastModifiedHeader($mtime); \OC\Files\Filesystem::readfile($arguments['path']); exit; case 'find_music': $scanner = new Scanner($collection); $music = $scanner->getMusic(); \OCP\JSON::encodedPrint($music); exit; } } class ScanWatcher
/** * @brief show preview * @return void */ public function showPreview() { \OCP\Response::enableCaching(3600 * 24); // 24 hours if (is_null($this->preview)) { $this->getPreview(); } $this->preview->show('image/png'); return; }
// If preview exist check if it's newer than the file, regenate it otherwise if (file_exists($thumbPath)) { $thumbMTime = filemtime($thumbPath); $fileInfo = \OC\Files\Filesystem::getFileInfo($filePath); if ($thumbMTime < $fileInfo['mtime']) { unlink($thumbPath); } } // Check if thumbnail exist, create it otherwise if (!file_exists($thumbPath)) { $imgHandler = new \OCA\OCLife\ImageHandler(); $imgHandler->setHeight(320); $imgHandler->setWidth(320); $imgHandler->setBgColorFromValues(0, 0, 0); $imgHandler->generateImageThumbnail($viewPath, $filePath, $thumbPath); } $previewPath = is_file($thumbPath) ? $thumbPath : $placeHolderPath; } else { $previewPath = $placeHolderPath; } } // Output the preview $mtime = filemtime($previewPath); $size = filesize($previewPath); $mime = \OC_Helper::getMimetype($previewPath); \OCP\Response::enableCaching(); \OCP\Response::setLastModifiedHeader($mtime); header('Content-Length: ' . $size); header('Content-Type: ' . $mime); $fp = @fopen($previewPath, 'rb'); @fpassthru($fp);
/** * Get the thumbnail of the image * @param string $thumbImagePath */ public function getThumbnail($thumbImagePath) { $fp = @fopen($thumbImagePath, 'rb'); $mtime = filemtime($thumbImagePath); $size = filesize($thumbImagePath); $mime = \OC_Helper::getMimetype($thumbImagePath); if ($fp) { \OCP\Response::enableCaching(); \OCP\Response::setLastModifiedHeader($mtime); header('Content-Length: ' . $size); header('Content-Type: ' . $mime); fpassthru($fp); } else { \OC_Response::setStatus(\OC_Response::STATUS_NOT_FOUND); } }