preview.php 2.3 KB

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