preview.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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) 2015, 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'] : '36';
  30. $maxY = array_key_exists('y', $_GET) ? (int)$_GET['y'] : '36';
  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. if ($file === '') {
  35. //400 Bad Request
  36. \OC_Response::setStatus(400);
  37. \OC_Log::write('core-preview', 'No file parameter was passed', \OC_Log::DEBUG);
  38. exit;
  39. }
  40. if ($maxX === 0 || $maxY === 0) {
  41. //400 Bad Request
  42. \OC_Response::setStatus(400);
  43. \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG);
  44. exit;
  45. }
  46. $info = \OC\Files\Filesystem::getFileInfo($file);
  47. if (!$info instanceof OCP\Files\FileInfo || !$always && !\OC::$server->getPreviewManager()->isAvailable($info)) {
  48. \OC_Response::setStatus(404);
  49. } else {
  50. $preview = new \OC\Preview(\OC_User::getUser(), 'files');
  51. $preview->setFile($file);
  52. $preview->setMaxX($maxX);
  53. $preview->setMaxY($maxY);
  54. $preview->setScalingUp($scalingUp);
  55. $preview->setKeepAspect($keepAspect);
  56. $preview->showPreview();
  57. }