Blame view

sources/apps/gallery/ajax/image.php 1.78 KB
d1bafeea1   Kload   [fix] Upgrade to ...
1
2
3
4
5
6
7
8
9
  <?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');
6d9380f96   Cédric Dupont   Update sources OC...
10
11
  list($owner, $img) = explode('/', $_GET['file'], 2);
  $linkItem = \OCP\Share::getShareByToken($owner);
d1bafeea1   Kload   [fix] Upgrade to ...
12
13
14
  if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
  	// seems to be a valid share
  	$rootLinkItem = \OCP\Share::resolveReShare($linkItem);
6d9380f96   Cédric Dupont   Update sources OC...
15
16
17
18
  	$user = $rootLinkItem['uid_owner'];
  
  	// Setup filesystem
  	OCP\JSON::checkUserExists($user);
d1bafeea1   Kload   [fix] Upgrade to ...
19
  	OC_Util::tearDownFS();
6d9380f96   Cédric Dupont   Update sources OC...
20
21
22
23
24
  	OC_Util::setupFS($user);
  	OC_User::setIncognitoMode(true);
  
  	$fullPath = \OC\Files\Filesystem::getPath($linkItem['file_source']);
  	$img = trim($fullPath . '/' . $img);
d1bafeea1   Kload   [fix] Upgrade to ...
25
26
  } else {
  	OCP\JSON::checkLoggedIn();
6d9380f96   Cédric Dupont   Update sources OC...
27
  	$user = OCP\User::getUser();
d1bafeea1   Kload   [fix] Upgrade to ...
28
29
30
  }
  
  session_write_close();
6d9380f96   Cédric Dupont   Update sources OC...
31
  $ownerView = new \OC\Files\View('/' . $user . '/files');
d1bafeea1   Kload   [fix] Upgrade to ...
32
33
34
35
  
  $mime = $ownerView->getMimeType($img);
  list($mimePart,) = explode('/', $mime);
  if ($mimePart === 'image') {
6d9380f96   Cédric Dupont   Update sources OC...
36
37
38
39
40
41
  	$fileInfo = $ownerView->getFileInfo($img);
  	if($fileInfo['encrypted'] === true) {
  		$local = $ownerView->toTmpFile($img);
  	} else {
  		$local = $ownerView->getLocalFile($img);
  	}
d1bafeea1   Kload   [fix] Upgrade to ...
42
43
44
45
46
47
48
  	$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);
  		}
  	}
6d9380f96   Cédric Dupont   Update sources OC...
49
50
51
  	
  	OCP\Response::setContentDispositionHeader(basename($img), 'attachment');
  	
d1bafeea1   Kload   [fix] Upgrade to ...
52
53
54
55
56
57
58
59
60
  	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);
  	}
  }