Blame view
sources/apps/files_sharing/ajax/publicpreview.php
3.09 KB
|
31b7f2792
|
1 2 3 4 5 6 7 |
<?php /** * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ |
|
6d9380f96
|
8 9 |
OCP\JSON::checkAppEnabled('files_sharing');
|
|
31b7f2792
|
10 11 |
\OC_User::setIncognitoMode(true); |
|
6d9380f96
|
12 |
$file = array_key_exists('file', $_GET) ? (string) $_GET['file'] : '';
|
|
31b7f2792
|
13 14 15 16 |
$maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '36';
$maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '36';
$scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true;
$token = array_key_exists('t', $_GET) ? (string) $_GET['t'] : '';
|
|
6d9380f96
|
17 |
$keepAspect = array_key_exists('a', $_GET) ? true : false;
|
|
31b7f2792
|
18 19 |
if($token === ''){
|
|
6d9380f96
|
20 |
\OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST); |
|
31b7f2792
|
21 22 23 24 25 26 |
\OC_Log::write('core-preview', 'No token parameter was passed', \OC_Log::DEBUG);
exit;
}
$linkedItem = \OCP\Share::getShareByToken($token);
if($linkedItem === false || ($linkedItem['item_type'] !== 'file' && $linkedItem['item_type'] !== 'folder')) {
|
|
6d9380f96
|
27 |
\OC_Response::setStatus(\OC_Response::STATUS_NOT_FOUND); |
|
31b7f2792
|
28 29 30 31 32 |
\OC_Log::write('core-preview', 'Passed token parameter is not valid', \OC_Log::DEBUG);
exit;
}
if(!isset($linkedItem['uid_owner']) || !isset($linkedItem['file_source'])) {
|
|
6d9380f96
|
33 |
\OC_Response::setStatus(\OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
31b7f2792
|
34 35 36 |
\OC_Log::write('core-preview', 'Passed token seems to be valid, but it does not contain all necessary information . ("' . $token . '")', \OC_Log::WARN);
exit;
}
|
|
a293d369c
|
37 38 39 40 |
$rootLinkItem = OCP\Share::resolveReShare($linkedItem); $userId = $rootLinkItem['uid_owner']; OCP\JSON::checkUserExists($rootLinkItem['uid_owner']); |
|
31b7f2792
|
41 42 43 44 45 46 47 48 49 50 |
\OC_Util::setupFS($userId);
\OC\Files\Filesystem::initMountPoints($userId);
$view = new \OC\Files\View('/' . $userId . '/files');
$pathId = $linkedItem['file_source'];
$path = $view->getPath($pathId);
$pathInfo = $view->getFileInfo($path);
$sharedFile = null;
if($linkedItem['item_type'] === 'folder') {
|
|
6d9380f96
|
51 52 53 |
$isValid = \OC\Files\Filesystem::isValidPath($file);
if(!$isValid) {
\OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST);
|
|
31b7f2792
|
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
\OC_Log::write('core-preview', 'Passed filename is not valid, might be malicious (file:"' . $file . '";ip:"' . $_SERVER['REMOTE_ADDR'] . '")', \OC_Log::WARN);
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) {
|
|
6d9380f96
|
72 |
\OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST); |
|
31b7f2792
|
73 74 75 76 77 78 79 80 81 82 83 84 |
\OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG);
exit;
}
$root = 'files/' . $path;
try{
$preview = new \OC\Preview($userId, $root);
$preview->setFile($sharedFile);
$preview->setMaxX($maxX);
$preview->setMaxY($maxY);
$preview->setScalingUp($scalingUp);
|
|
6d9380f96
|
85 |
$preview->setKeepAspect($keepAspect); |
|
31b7f2792
|
86 |
|
|
6d9380f96
|
87 |
$preview->showPreview(); |
|
31b7f2792
|
88 |
} catch (\Exception $e) {
|
|
6d9380f96
|
89 |
\OC_Response::setStatus(\OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
31b7f2792
|
90 |
\OC_Log::write('core', $e->getmessage(), \OC_Log::DEBUG);
|
|
a293d369c
|
91 |
} |