You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

preview.php 2.4KB

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