Blame view
sources/apps/gallery/ajax/image.php
2.22 KB
|
d1bafeea1
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
<?php
/**
* Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
OCP\JSON::checkAppEnabled('gallery');
list($token, $img) = explode('/', $_GET['file'], 2);
$linkItem = \OCP\Share::getShareByToken($token);
if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
// seems to be a valid share
$rootLinkItem = \OCP\Share::resolveReShare($linkItem);
$owner = $rootLinkItem['uid_owner'];
OCP\JSON::checkUserExists($owner);
OC_Util::tearDownFS();
OC_Util::setupFS($owner);
\OC_User::setIncognitoMode(true);
} else {
OCP\JSON::checkLoggedIn();
list($owner, $img) = explode('/', $_GET['file'], 2);
if ($owner !== OCP\User::getUser()) {
OCP\JSON::checkUserExists($owner);
OC_Util::tearDownFS();
OC_Util::setupFS($owner);
$view = new \OC\Files\View('/' . $owner . '/files');
// second part is the (duplicated) share name
list($folderId, , $img) = explode('/', $img, 3);
$shareInfo = \OCP\Share::getItemSharedWithBySource('file', $folderId);
if ($shareInfo) {
$sharedFolder = $view->getPath($folderId);
if ($sharedFolder) {
$img = $sharedFolder . '/' . $img;
} else {
\OC_Response::setStatus(404);
exit;
}
} else {
\OC_Response::setStatus(403);
exit;
}
}
}
session_write_close();
$ownerView = new \OC\Files\View('/' . $owner . '/files');
if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
// prepend path to share
$path = $ownerView->getPath($linkItem['file_source']);
$img = $path.'/'.$img;
}
$mime = $ownerView->getMimeType($img);
list($mimePart,) = explode('/', $mime);
if ($mimePart === 'image') {
$local = $ownerView->getLocalFile($img);
$rotate = false;
if (is_callable('exif_read_data')) { //don't use OCP\Image here, using OCP\Image will always cause parsing the image file
$exif = @exif_read_data($local, 'IFD0');
if (isset($exif['Orientation'])) {
$rotate = ($exif['Orientation'] > 1);
}
}
if ($rotate) {
$image = new OCP\Image($local);
$image->fixOrientation();
$image->show();
} else { //use the original file if we dont need to rotate, saves having to re-encode the image
header('Content-Type: ' . $mime);
$ownerView->readfile($img);
}
}
|