summaryrefslogtreecommitdiffstats
path: root/lib/preview.php
diff options
context:
space:
mode:
authorGeorg Ehrke <georg@ownCloud.com>2013-06-10 11:01:12 +0200
committerGeorg Ehrke <georg@ownCloud.com>2013-06-10 11:01:12 +0200
commit25e8ac1c2f51e7f3f35eaec013aa1b3f8356f17b (patch)
tree1517aff19c191db14b93044d29995f76dbf98ca4 /lib/preview.php
parenta2bb0faec63029409f71c0b1ca1bf735ed30ca6f (diff)
downloadnextcloud-server-25e8ac1c2f51e7f3f35eaec013aa1b3f8356f17b.tar.gz
nextcloud-server-25e8ac1c2f51e7f3f35eaec013aa1b3f8356f17b.zip
implement previews for single shared files
Diffstat (limited to 'lib/preview.php')
-rwxr-xr-xlib/preview.php39
1 files changed, 24 insertions, 15 deletions
diff --git a/lib/preview.php b/lib/preview.php
index f9f1288cb98..904689bc4e1 100755
--- a/lib/preview.php
+++ b/lib/preview.php
@@ -557,31 +557,40 @@ class Preview {
if(array_key_exists('y', $_GET)) $maxY = (int) $_GET['y'];
if(array_key_exists('scalingup', $_GET)) $scalingup = (bool) $_GET['scalingup'];
if(array_key_exists('t', $_GET)) $token = (string) $_GET['t'];
-
+
$linkItem = \OCP\Share::getShareByToken($token);
-
+
if (is_array($linkItem) && isset($linkItem['uid_owner']) && isset($linkItem['file_source'])) {
$userid = $linkItem['uid_owner'];
\OC_Util::setupFS($userid);
+
$pathid = $linkItem['file_source'];
$path = \OC\Files\Filesystem::getPath($pathid);
- }
-
- //clean up file parameter
- $file = \OC\Files\Filesystem::normalizePath($file);
- if(!\OC\Files\Filesystem::isValidPath($file)) {
- \OC_Response::setStatus(403);
- exit;
- }
+ $pathinfo = \OC\Files\Filesystem::getFileInfo($path);
+
+ $sharedfile = null;
+ if($linkItem['item_type'] === 'folder') {
+ //clean up file parameter
+ $sharedfile = \OC\Files\Filesystem::normalizePath($file);
+ if(!\OC\Files\Filesystem::isValidPath($file)) {
+ \OC_Response::setStatus(403);
+ exit;
+ }
+ } else if($linkItem['item_type'] === 'file') {
+ $parent = $pathinfo['parent'];
+ $path = \OC\Files\Filesystem::getPath($parent);
+ $sharedfile = $pathinfo['name'];
+ }
- $path = \OC\Files\Filesystem::normalizePath($path, false);
- if(substr($path, 0, 1) == '/') {
- $path = substr($path, 1);
+ $path = \OC\Files\Filesystem::normalizePath($path, false);
+ if(substr($path, 0, 1) == '/') {
+ $path = substr($path, 1);
+ }
}
- if($userid !== null && $path !== null) {
+ if($userid !== null && $path !== null && $sharedfile !== null) {
try{
- $preview = new Preview($userid, 'files/' . $path, $file, $maxX, $maxY, $scalingup);
+ $preview = new Preview($userid, 'files/' . $path, $sharedfile, $maxX, $maxY, $scalingup);
$preview->showPreview();
}catch(\Exception $e) {
\OC_Response::setStatus(404);