exit; } $sharedFile = \OC\Files\Filesystem::normalizePath($file); } if ($linkedItem['item_type'] === 'file') { $parent = $pathInfo['parent']; $path = $view->getPath($parent); $sharedFile = $pathInfo['name']; } $path = \OC\Files\Filesystem::normalizePath($path, false); if (substr($path, 0, 1) === '/') { $path = substr($path, 1); } if ($maxX === 0 || $maxY === 0) { \OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST); \OCP\Util::writeLog('core-preview', 'x and/or y set to 0', \OCP\Util::DEBUG); exit; } $root = 'files/' . $path; try { $preview = new \OC\Preview($userId, $root); $preview->setFile($sharedFile); $preview->setMaxX($maxX); $preview->setMaxY($maxY); $preview->setScalingUp($scalingUp); $preview->setKeepAspect($keepAspect); $preview->showPreview(); } catch (\Exception $e) { \OC_Response::setStatus(\OC_Response::STATUS_INTERNAL_SERVER_ERROR); \OCP\Util::writeLog('core', $e->getmessage(), \OCP\Util::DEBUG); }
$keepAspect = array_key_exists('a', $_GET) ? true : false; $always = array_key_exists('forceIcon', $_GET) ? (bool) $_GET['forceIcon'] : true; if ($file === '') { //400 Bad Request \OC_Response::setStatus(400); \OC_Log::write('core-preview', 'No file parameter was passed', \OC_Log::DEBUG); exit; } if ($maxX === 0 || $maxY === 0) { //400 Bad Request \OC_Response::setStatus(400); \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG); exit; } try { $preview = new \OC\Preview(\OC_User::getUser(), 'files'); $info = \OC\Files\Filesystem::getFileInfo($file); if (!$always and !$preview->isAvailable($info)) { \OC_Response::setStatus(404); } else { $preview->setFile($file); $preview->setMaxX($maxX); $preview->setMaxY($maxY); $preview->setScalingUp($scalingUp); $preview->setKeepAspect($keepAspect); } $preview->showPreview(); } catch (\Exception $e) { \OC_Response::setStatus(500); \OC_Log::write('core', $e->getmessage(), \OC_Log::DEBUG); }
public function testIsCached() { $sourceFile = __DIR__ . '/../data/testimage.png'; $userId = $this->getUniqueID(); $this->createUser($userId, 'pass'); $storage = new Temporary(); $storage->mkdir('files'); $this->registerMount($userId, $storage, '/' . $userId); \OC_Util::tearDownFS(); \OC_Util::setupFS($userId); $preview = new \OC\Preview($userId, 'files'); $view = new View('/' . $userId . '/files'); $view->file_put_contents('test.png', file_get_contents($sourceFile)); $info = $view->getFileInfo('test.png'); $preview->setFile('test.png', $info); $preview->setMaxX(64); $preview->setMaxY(64); $this->assertFalse($preview->isCached($info->getId())); $preview->getPreview(); $this->assertEquals('thumbnails/' . $info->getId() . '/64-64.png', $preview->isCached($info->getId())); }
$maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '32'; $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '32'; $scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true; $keepAspect = array_key_exists('a', $_GET) ? true : false; $always = array_key_exists('forceIcon', $_GET) ? (bool) $_GET['forceIcon'] : true; $mode = array_key_exists('mode', $_GET) ? $_GET['mode'] : 'fill'; if ($file === '') { //400 Bad Request \OC_Response::setStatus(400); \OCP\Util::writeLog('core-preview', 'No file parameter was passed', \OCP\Util::DEBUG); exit; } if ($maxX === 0 || $maxY === 0) { //400 Bad Request \OC_Response::setStatus(400); \OCP\Util::writeLog('core-preview', 'x and/or y set to 0', \OCP\Util::DEBUG); exit; } $info = \OC\Files\Filesystem::getFileInfo($file); if (!$info instanceof OCP\Files\FileInfo || !$always && !\OC::$server->getPreviewManager()->isAvailable($info)) { \OC_Response::setStatus(404); } else { $preview = new \OC\Preview(\OC_User::getUser(), 'files'); $preview->setFile($file, $info); $preview->setMaxX($maxX); $preview->setMaxY($maxY); $preview->setScalingUp($scalingUp); $preview->setMode($mode); $preview->setKeepAspect($keepAspect); $preview->showPreview(); }
/** * @brief offer preview for download * * if no preview exists for this file, send icon instead * * @param string $path full path to file * @param string type type of preview requested */ public static function servePreview($path, $type) { \OCP\User::checkLoggedIn(); \OC::$server->getSession()->close(); $i = \OC\Files\Filesystem::getFileInfo($path, false); /* check for predefined cover, if found replace $path with that of cover file */ $meta = Meta::get($i['fileid']); if ($meta['cover']) { $path = pathinfo($path)['dirname'] . '/' . $meta['cover']; $i = \OC\Files\Filesystem::getFileInfo($path, false); } if (\OC::$server->getPreviewManager()->isMimeSupported($i['mimetype'])) { $preview = new \OC\Preview(\OC_User::getUser(), 'files'); $preview->setFile($path); switch ($type) { case 'cover': $preview->setMaxX(Config::getApp('cover-x', '200')); $preview->setMaxY(Config::getApp('cover-y', '200')); break; case 'thumbnail': $preview->setMaxX(Config::getApp('thumb-x', '36')); $preview->setMaxY(Config::getApp('thumb-y', '36')); break; } $preview->showPreview(); } else { // no preview, serve icon instead $scheme = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? 'https' : 'http'; header("Location: " . $scheme . "://" . $_SERVER['HTTP_HOST'] . \OC_Helper::mimetypeIcon($i->getMimeType())); /* Note: relative URL should be enough (RFC7231) but some OPDS clients * (especially those in dedicated book readers) might not support them * * header("Location: " . \OC_Helper::mimetypeIcon($i->getMimeType())); */ } }