shareinfo.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * @author Joas Schilling <nickvergessen@owncloud.com>
  4. * @author Morris Jobke <hey@morrisjobke.de>
  5. * @author Robin Appelman <icewind@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. OCP\JSON::checkAppEnabled('files_sharing');
  25. if (!isset($_GET['t'])) {
  26. \OC_Response::setStatus(400); //400 Bad Request
  27. exit;
  28. }
  29. if (OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled() === false) {
  30. \OC_Response::setStatus(404); // 404 not found
  31. exit;
  32. }
  33. $token = $_GET['t'];
  34. $password = null;
  35. if (isset($_POST['password'])) {
  36. $password = $_POST['password'];
  37. }
  38. $relativePath = null;
  39. if (isset($_GET['dir'])) {
  40. $relativePath = $_GET['dir'];
  41. }
  42. $data = \OCA\Files_Sharing\Helper::setupFromToken($token, $relativePath, $password);
  43. $linkItem = $data['linkItem'];
  44. // Load the files
  45. $path = $data['realPath'];
  46. $isWritable = $linkItem['permissions'] & (\OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_CREATE);
  47. if (!$isWritable) {
  48. \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, $storage) {
  49. return new \OCA\Files_Sharing\ReadOnlyWrapper(array('storage' => $storage));
  50. });
  51. }
  52. $rootInfo = \OC\Files\Filesystem::getFileInfo($path);
  53. $rootView = new \OC\Files\View('');
  54. /**
  55. * @param \OCP\Files\FileInfo $dir
  56. * @param \OC\Files\View $view
  57. * @return array
  58. */
  59. function getChildInfo($dir, $view) {
  60. $children = $view->getDirectoryContent($dir->getPath());
  61. $result = array();
  62. foreach ($children as $child) {
  63. $formated = \OCA\Files\Helper::formatFileInfo($child);
  64. if ($child->getType() === 'dir') {
  65. $formated['children'] = getChildInfo($child, $view);
  66. }
  67. $formated['mtime'] = $formated['mtime'] / 1000;
  68. $result[] = $formated;
  69. }
  70. return $result;
  71. }
  72. $result = \OCA\Files\Helper::formatFileInfo($rootInfo);
  73. $result['mtime'] = $result['mtime'] / 1000;
  74. if ($rootInfo->getType() === 'dir') {
  75. $result['children'] = getChildInfo($rootInfo, $rootView);
  76. }
  77. OCP\JSON::success(array('data' => $result));