preview.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Georg Ehrke <georg@owncloud.com>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Robin Appelman <robin@icewind.nl>
  10. * @author Thomas Müller <thomas.mueller@tmit.eu>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. \OC_Util::checkLoggedIn();
  28. \OC::$server->getSession()->close();
  29. $file = array_key_exists('file', $_GET) ? (string)$_GET['file'] : '';
  30. $maxX = array_key_exists('x', $_GET) ? (int)$_GET['x'] : '32';
  31. $maxY = array_key_exists('y', $_GET) ? (int)$_GET['y'] : '32';
  32. $scalingUp = array_key_exists('scalingup', $_GET) ? (bool)$_GET['scalingup'] : true;
  33. $keepAspect = array_key_exists('a', $_GET) ? true : false;
  34. $always = array_key_exists('forceIcon', $_GET) ? (bool)$_GET['forceIcon'] : true;
  35. $mode = array_key_exists('mode', $_GET) ? $_GET['mode'] : 'fill';
  36. if ($file === '') {
  37. //400 Bad Request
  38. \OC_Response::setStatus(400);
  39. \OCP\Util::writeLog('core-preview', 'No file parameter was passed', \OCP\Util::DEBUG);
  40. exit;
  41. }
  42. if ($maxX === 0 || $maxY === 0) {
  43. //400 Bad Request
  44. \OC_Response::setStatus(400);
  45. \OCP\Util::writeLog('core-preview', 'x and/or y set to 0', \OCP\Util::DEBUG);
  46. exit;
  47. }
  48. $info = \OC\Files\Filesystem::getFileInfo($file);
  49. if (!$info instanceof OCP\Files\FileInfo || !$always && !\OC::$server->getPreviewManager()->isAvailable($info)) {
  50. \OC_Response::setStatus(404);
  51. } else {
  52. $preview = new \OC\Preview(\OC_User::getUser(), 'files');
  53. $preview->setFile($file, $info);
  54. $preview->setMaxX($maxX);
  55. $preview->setMaxY($maxY);
  56. $preview->setScalingUp($scalingUp);
  57. $preview->setMode($mode);
  58. $preview->setKeepAspect($keepAspect);
  59. $preview->showPreview();
  60. }