list.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * @author Jakob Sack <mail@jakobsack.de>
  4. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  5. * @author Lukas Reschke <lukas@owncloud.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Robin Appelman <icewind@owncloud.com>
  8. * @author Vincent Petry <pvince81@owncloud.com>
  9. *
  10. * @copyright Copyright (c) 2015, 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. OCP\JSON::checkLoggedIn();
  27. \OC::$server->getSession()->close();
  28. $l = \OC::$server->getL10N('files');
  29. // Load the files
  30. $dir = isset($_GET['dir']) ? (string)$_GET['dir'] : '';
  31. $dir = \OC\Files\Filesystem::normalizePath($dir);
  32. try {
  33. $dirInfo = \OC\Files\Filesystem::getFileInfo($dir);
  34. if (!$dirInfo || !$dirInfo->getType() === 'dir') {
  35. header("HTTP/1.0 404 Not Found");
  36. exit();
  37. }
  38. $data = array();
  39. $baseUrl = OCP\Util::linkTo('files', 'index.php') . '?dir=';
  40. $permissions = $dirInfo->getPermissions();
  41. $sortAttribute = isset($_GET['sort']) ? (string)$_GET['sort'] : 'name';
  42. $sortDirection = isset($_GET['sortdirection']) ? ($_GET['sortdirection'] === 'desc') : false;
  43. // make filelist
  44. $files = \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection);
  45. $files = \OCA\Files\Helper::populateTags($files);
  46. $data['directory'] = $dir;
  47. $data['files'] = \OCA\Files\Helper::formatFileInfos($files);
  48. $data['permissions'] = $permissions;
  49. OCP\JSON::success(array('data' => $data));
  50. } catch (\OCP\Files\StorageNotAvailableException $e) {
  51. \OCP\Util::logException('files', $e);
  52. OCP\JSON::error(array(
  53. 'data' => array(
  54. 'exception' => '\OCP\Files\StorageNotAvailableException',
  55. 'message' => $l->t('Storage not available')
  56. )
  57. ));
  58. } catch (\OCP\Files\StorageInvalidException $e) {
  59. \OCP\Util::logException('files', $e);
  60. OCP\JSON::error(array(
  61. 'data' => array(
  62. 'exception' => '\OCP\Files\StorageInvalidException',
  63. 'message' => $l->t('Storage invalid')
  64. )
  65. ));
  66. } catch (\Exception $e) {
  67. \OCP\Util::logException('files', $e);
  68. OCP\JSON::error(array(
  69. 'data' => array(
  70. 'exception' => '\Exception',
  71. 'message' => $l->t('Unknown error')
  72. )
  73. ));
  74. }