OwnCloud.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Robin Appelman <robin@icewind.nl>
  10. * @author Robin McCorkell <robin@mccorkell.me.uk>
  11. * @author Roeland Jago Douma <roeland@famdouma.nl>
  12. * @author Vincent Petry <vincent@nextcloud.com>
  13. *
  14. * @license AGPL-3.0
  15. *
  16. * This code is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License, version 3,
  18. * as published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License, version 3,
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>
  27. *
  28. */
  29. namespace OCA\Files_External\Lib\Storage;
  30. use OCP\Files\Storage\IDisableEncryptionStorage;
  31. use Sabre\DAV\Client;
  32. /**
  33. * Nextcloud backend for external storage based on DAV backend.
  34. *
  35. * The Nextcloud URL consists of three parts:
  36. * http://%host/%context/remote.php/webdav/%root
  37. *
  38. */
  39. class OwnCloud extends \OC\Files\Storage\DAV implements IDisableEncryptionStorage {
  40. public const OC_URL_SUFFIX = 'remote.php/webdav';
  41. public function __construct($params) {
  42. // extract context path from host if specified
  43. // (owncloud install path on host)
  44. $host = $params['host'];
  45. // strip protocol
  46. if (substr($host, 0, 8) === "https://") {
  47. $host = substr($host, 8);
  48. $params['secure'] = true;
  49. } elseif (substr($host, 0, 7) === "http://") {
  50. $host = substr($host, 7);
  51. $params['secure'] = false;
  52. }
  53. $contextPath = '';
  54. $hostSlashPos = strpos($host, '/');
  55. if ($hostSlashPos !== false) {
  56. $contextPath = substr($host, $hostSlashPos);
  57. $host = substr($host, 0, $hostSlashPos);
  58. }
  59. if (!str_ends_with($contextPath, '/')) {
  60. $contextPath .= '/';
  61. }
  62. if (isset($params['root'])) {
  63. $root = '/' . ltrim($params['root'], '/');
  64. } else {
  65. $root = '/';
  66. }
  67. $params['host'] = $host;
  68. $params['root'] = $contextPath . self::OC_URL_SUFFIX . $root;
  69. $params['authType'] = Client::AUTH_BASIC;
  70. parent::__construct($params);
  71. }
  72. public function needsPartFile() {
  73. return false;
  74. }
  75. }