preview.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Georg Ehrke <georg@owncloud.com>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. * @author Vincent Petry <pvince81@owncloud.com>
  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. if(!\OC_App::isEnabled('files_trashbin')){
  30. exit;
  31. }
  32. $file = array_key_exists('file', $_GET) ? (string) $_GET['file'] : '';
  33. $maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '44';
  34. $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '44';
  35. $scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true;
  36. if($file === '') {
  37. \OC_Response::setStatus(400); //400 Bad Request
  38. \OCP\Util::writeLog('core-preview', 'No file parameter was passed', \OCP\Util::DEBUG);
  39. exit;
  40. }
  41. if($maxX === 0 || $maxY === 0) {
  42. \OC_Response::setStatus(400); //400 Bad Request
  43. \OCP\Util::writeLog('core-preview', 'x and/or y set to 0', \OCP\Util::DEBUG);
  44. exit;
  45. }
  46. try{
  47. $preview = new \OC\Preview(\OC_User::getUser(), 'files_trashbin/files', $file);
  48. $view = new \OC\Files\View('/'.\OC_User::getUser(). '/files_trashbin/files');
  49. if ($view->is_dir($file)) {
  50. $mimetype = 'httpd/unix-directory';
  51. } else {
  52. $pathInfo = pathinfo(ltrim($file, '/'));
  53. $fileName = $pathInfo['basename'];
  54. // if in root dir
  55. if ($pathInfo['dirname'] === '.') {
  56. // cut off the .d* suffix
  57. $i = strrpos($fileName, '.');
  58. if ($i !== false) {
  59. $fileName = substr($fileName, 0, $i);
  60. }
  61. }
  62. $mimetype = \OC::$server->getMimeTypeDetector()->detectPath($fileName);
  63. }
  64. $preview->setMimetype($mimetype);
  65. $preview->setMaxX($maxX);
  66. $preview->setMaxY($maxY);
  67. $preview->setScalingUp($scalingUp);
  68. $preview->showPreview();
  69. } catch (\OC\PreviewNotAvailableException $e) {
  70. \OC_Response::setStatus(404);
  71. }catch(\Exception $e) {
  72. \OC_Response::setStatus(500);
  73. \OCP\Util::writeLog('core', $e->getmessage(), \OCP\Util::DEBUG);
  74. }