list.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Vincent Petry
  6. * @copyright 2014 Vincent Petry <pvince81@owncloud.com>
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. OCP\JSON::checkAppEnabled('files_sharing');
  23. if(!isset($_GET['t'])){
  24. \OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST);
  25. \OC_Log::write('core-preview', 'No token parameter was passed', \OC_Log::DEBUG);
  26. exit;
  27. }
  28. $token = $_GET['t'];
  29. $password = null;
  30. if (isset($_POST['password'])) {
  31. $password = $_POST['password'];
  32. }
  33. $relativePath = null;
  34. if (isset($_GET['dir'])) {
  35. $relativePath = $_GET['dir'];
  36. }
  37. $sortAttribute = isset( $_GET['sort'] ) ? $_GET['sort'] : 'name';
  38. $sortDirection = isset( $_GET['sortdirection'] ) ? ($_GET['sortdirection'] === 'desc') : false;
  39. $data = \OCA\Files_Sharing\Helper::setupFromToken($token, $relativePath, $password);
  40. $linkItem = $data['linkItem'];
  41. // Load the files
  42. $dir = $data['realPath'];
  43. $dir = \OC\Files\Filesystem::normalizePath($dir);
  44. if (!\OC\Files\Filesystem::is_dir($dir . '/')) {
  45. \OC_Response::setStatus(\OC_Response::STATUS_NOT_FOUND);
  46. \OCP\JSON::error(array('success' => false));
  47. exit();
  48. }
  49. $data = array();
  50. // make filelist
  51. $files = \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection);
  52. $formattedFiles = array();
  53. foreach ($files as $file) {
  54. $entry = \OCA\Files\Helper::formatFileInfo($file);
  55. unset($entry['directory']); // for now
  56. $entry['permissions'] = \OCP\Constants::PERMISSION_READ;
  57. $formattedFiles[] = $entry;
  58. }
  59. $data['directory'] = $relativePath;
  60. $data['files'] = $formattedFiles;
  61. $data['dirToken'] = $linkItem['token'];
  62. $permissions = $linkItem['permissions'];
  63. // if globally disabled
  64. if (\OC::$server->getAppConfig()->getValue('core', 'shareapi_allow_public_upload', 'yes') === 'no') {
  65. // only allow reading
  66. $permissions = \OCP\Constants::PERMISSION_READ;
  67. }
  68. $data['permissions'] = $permissions;
  69. OCP\JSON::success(array('data' => $data));