OwnCloud.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 OCP\Files\Storage\IDisableEncryptionStorage;
  9. use Sabre\DAV\Client;
  10. /**
  11. * Nextcloud backend for external storage based on DAV backend.
  12. *
  13. * The Nextcloud URL consists of three parts:
  14. * http://%host/%context/remote.php/webdav/%root
  15. *
  16. */
  17. class OwnCloud extends \OC\Files\Storage\DAV implements IDisableEncryptionStorage {
  18. public const OC_URL_SUFFIX = 'remote.php/webdav';
  19. public function __construct($params) {
  20. // extract context path from host if specified
  21. // (owncloud install path on host)
  22. $host = $params['host'];
  23. // strip protocol
  24. if (substr($host, 0, 8) === 'https://') {
  25. $host = substr($host, 8);
  26. $params['secure'] = true;
  27. } elseif (substr($host, 0, 7) === 'http://') {
  28. $host = substr($host, 7);
  29. $params['secure'] = false;
  30. }
  31. $contextPath = '';
  32. $hostSlashPos = strpos($host, '/');
  33. if ($hostSlashPos !== false) {
  34. $contextPath = substr($host, $hostSlashPos);
  35. $host = substr($host, 0, $hostSlashPos);
  36. }
  37. if (!str_ends_with($contextPath, '/')) {
  38. $contextPath .= '/';
  39. }
  40. if (isset($params['root'])) {
  41. $root = '/' . ltrim($params['root'], '/');
  42. } else {
  43. $root = '/';
  44. }
  45. $params['host'] = $host;
  46. $params['root'] = $contextPath . self::OC_URL_SUFFIX . $root;
  47. $params['authType'] = Client::AUTH_BASIC;
  48. parent::__construct($params);
  49. }
  50. public function needsPartFile() {
  51. return false;
  52. }
  53. }