preview.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 Vincent Petry <pvince81@owncloud.com>
  8. *
  9. * @copyright Copyright (c) 2015, ownCloud, Inc.
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. \OC_Util::checkLoggedIn();
  26. \OC::$server->getSession()->close();
  27. if(!\OC_App::isEnabled('files_trashbin')){
  28. exit;
  29. }
  30. $file = array_key_exists('file', $_GET) ? (string) $_GET['file'] : '';
  31. $maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '44';
  32. $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '44';
  33. $scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true;
  34. if($file === '') {
  35. \OC_Response::setStatus(400); //400 Bad Request
  36. \OC_Log::write('core-preview', 'No file parameter was passed', \OC_Log::DEBUG);
  37. exit;
  38. }
  39. if($maxX === 0 || $maxY === 0) {
  40. \OC_Response::setStatus(400); //400 Bad Request
  41. \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG);
  42. exit;
  43. }
  44. try{
  45. $preview = new \OC\Preview(\OC_User::getUser(), 'files_trashbin/files', $file);
  46. $view = new \OC\Files\View('/'.\OC_User::getUser(). '/files_trashbin/files');
  47. if ($view->is_dir($file)) {
  48. $mimetype = 'httpd/unix-directory';
  49. } else {
  50. $pathInfo = pathinfo(ltrim($file, '/'));
  51. $fileName = $pathInfo['basename'];
  52. // if in root dir
  53. if ($pathInfo['dirname'] === '.') {
  54. // cut off the .d* suffix
  55. $i = strrpos($fileName, '.');
  56. if ($i !== false) {
  57. $fileName = substr($fileName, 0, $i);
  58. }
  59. }
  60. $mimetype = \OC_Helper::getFileNameMimeType($fileName);
  61. }
  62. $preview->setMimetype($mimetype);
  63. $preview->setMaxX($maxX);
  64. $preview->setMaxY($maxY);
  65. $preview->setScalingUp($scalingUp);
  66. $preview->showPreview();
  67. }catch(\Exception $e) {
  68. \OC_Response::setStatus(500);
  69. \OC_Log::write('core', $e->getmessage(), \OC_Log::DEBUG);
  70. }