preview.php 2.5 KB

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