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