preview.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. \OC_Util::checkLoggedIn();
  9. if(!\OC_App::isEnabled('files_trashbin')){
  10. exit;
  11. }
  12. $file = array_key_exists('file', $_GET) ? (string) urldecode($_GET['file']) : '';
  13. $maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '44';
  14. $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '44';
  15. $scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true;
  16. if($file === '') {
  17. \OC_Response::setStatus(400); //400 Bad Request
  18. \OC_Log::write('core-preview', 'No file parameter was passed', \OC_Log::DEBUG);
  19. exit;
  20. }
  21. if($maxX === 0 || $maxY === 0) {
  22. \OC_Response::setStatus(400); //400 Bad Request
  23. \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG);
  24. exit;
  25. }
  26. try{
  27. $preview = new \OC\Preview(\OC_User::getUser(), 'files_trashbin/files', $file);
  28. $view = new \OC\Files\View('/'.\OC_User::getUser(). '/files_trashbin/files');
  29. if ($view->is_dir($file)) {
  30. $mimetype = 'httpd/unix-directory';
  31. } else {
  32. $mimetype = \OC_Helper::getFileNameMimeType(pathinfo($file, PATHINFO_FILENAME));
  33. }
  34. $preview->setMimetype($mimetype);
  35. $preview->setMaxX($maxX);
  36. $preview->setMaxY($maxY);
  37. $preview->setScalingUp($scalingUp);
  38. $preview->showPreview();
  39. }catch(\Exception $e) {
  40. \OC_Response::setStatus(500);
  41. \OC_Log::write('core', $e->getmessage(), \OC_Log::DEBUG);
  42. }