OwnCloud.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Files_External\Lib\Storage;
  8. use OC\Files\Storage\DAV;
  9. use OCP\Files\Storage\IDisableEncryptionStorage;
  10. use Sabre\DAV\Client;
  11. /**
  12. * Nextcloud backend for external storage based on DAV backend.
  13. *
  14. * The Nextcloud URL consists of three parts:
  15. * http://%host/%context/remote.php/webdav/%root
  16. *
  17. */
  18. class OwnCloud extends DAV implements IDisableEncryptionStorage {
  19. public const OC_URL_SUFFIX = 'remote.php/webdav';
  20. public function __construct(array $parameters) {
  21. // extract context path from host if specified
  22. // (owncloud install path on host)
  23. $host = $parameters['host'];
  24. // strip protocol
  25. if (substr($host, 0, 8) === 'https://') {
  26. $host = substr($host, 8);
  27. $parameters['secure'] = true;
  28. } elseif (substr($host, 0, 7) === 'http://') {
  29. $host = substr($host, 7);
  30. $parameters['secure'] = false;
  31. }
  32. $contextPath = '';
  33. $hostSlashPos = strpos($host, '/');
  34. if ($hostSlashPos !== false) {
  35. $contextPath = substr($host, $hostSlashPos);
  36. $host = substr($host, 0, $hostSlashPos);
  37. }
  38. if (!str_ends_with($contextPath, '/')) {
  39. $contextPath .= '/';
  40. }
  41. if (isset($parameters['root'])) {
  42. $root = '/' . ltrim($parameters['root'], '/');
  43. } else {
  44. $root = '/';
  45. }
  46. $parameters['host'] = $host;
  47. $parameters['root'] = $contextPath . self::OC_URL_SUFFIX . $root;
  48. $parameters['authType'] = Client::AUTH_BASIC;
  49. parent::__construct($parameters);
  50. }
  51. public function needsPartFile(): bool {
  52. return false;
  53. }
  54. }