1
0

fileshome.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * @author Thomas Müller <thomas.mueller@tmit.eu>
  4. *
  5. * @copyright Copyright (c) 2016, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace OCA\DAV\Files;
  22. use OCA\DAV\Connector\Sabre\Directory;
  23. use Sabre\DAV\Exception\Forbidden;
  24. use Sabre\DAV\ICollection;
  25. use Sabre\DAV\SimpleCollection;
  26. use Sabre\HTTP\URLUtil;
  27. class FilesHome implements ICollection {
  28. /**
  29. * FilesHome constructor.
  30. *
  31. * @param array $principalInfo
  32. */
  33. public function __construct($principalInfo) {
  34. $this->principalInfo = $principalInfo;
  35. }
  36. function createFile($name, $data = null) {
  37. return $this->impl()->createFile($name, $data);
  38. }
  39. function createDirectory($name) {
  40. $this->impl()->createDirectory($name);
  41. }
  42. function getChild($name) {
  43. return $this->impl()->getChild($name);
  44. }
  45. function getChildren() {
  46. return $this->impl()->getChildren();
  47. }
  48. function childExists($name) {
  49. return $this->impl()->childExists($name);
  50. }
  51. function delete() {
  52. $this->impl()->delete();
  53. }
  54. function getName() {
  55. list(,$name) = URLUtil::splitPath($this->principalInfo['uri']);
  56. return $name;
  57. }
  58. function setName($name) {
  59. throw new Forbidden('Permission denied to rename this folder');
  60. }
  61. /**
  62. * Returns the last modification time, as a unix timestamp
  63. *
  64. * @return int
  65. */
  66. function getLastModified() {
  67. return $this->impl()->getLastModified();
  68. }
  69. /**
  70. * @return Directory
  71. */
  72. private function impl() {
  73. //
  74. // TODO: we need to mount filesystem of the give user
  75. //
  76. $user = \OC::$server->getUserSession()->getUser();
  77. if ($this->getName() !== $user->getUID()) {
  78. return new SimpleCollection($this->getName());
  79. }
  80. $view = \OC\Files\Filesystem::getView();
  81. $rootInfo = $view->getFileInfo('');
  82. $impl = new Directory($view, $rootInfo);
  83. return $impl;
  84. }
  85. }