Completed
Push — master ( dfe6d6...a56ec1 )
by Morris
28:57
created

OwnCloud::needsPartFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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