Completed
Push — stable8.2 ( ec0a29...f5c39b )
by
unknown
18:21
created

shareinfo.php ➔ getChildInfo()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12
Metric Value
cc 3
eloc 10
nc 3
nop 2
dl 0
loc 13
ccs 0
cts 12
cp 0
crap 12
rs 9.4285
1
<?php
2
/**
3
 * @author Joas Schilling <[email protected]>
4
 * @author Morris Jobke <[email protected]>
5
 * @author Robin Appelman <[email protected]>
6
 * @author Vincent Petry <[email protected]>
7
 *
8
 * @copyright Copyright (c) 2015, ownCloud, Inc.
9
 * @license AGPL-3.0
10
 *
11
 * This code is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License, version 3,
13
 * as published by the Free Software Foundation.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License, version 3,
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
22
 *
23
 */
24
25
OCP\JSON::checkAppEnabled('files_sharing');
26
27
if (!isset($_GET['t'])) {
28
	\OC_Response::setStatus(400); //400 Bad Request
29
	exit;
30
}
31
32
if (OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled() === false) {
33
	\OC_Response::setStatus(404); // 404 not found
34
	exit;
35
}
36
37
$token = $_GET['t'];
38
39
$password = null;
40
if (isset($_POST['password'])) {
41
	$password = $_POST['password'];
42
}
43
44
$relativePath = null;
45
if (isset($_GET['dir'])) {
46
	$relativePath = $_GET['dir'];
47
}
48
49
$data = \OCA\Files_Sharing\Helper::setupFromToken($token, $relativePath, $password);
50
51
$linkItem = $data['linkItem'];
52
// Load the files
53
$path = $data['realPath'];
54
55
$isWritable = $linkItem['permissions'] & (\OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_CREATE);
56 View Code Duplication
if (!$isWritable) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
57
	\OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, $storage) {
58
		return new \OC\Files\Storage\Wrapper\PermissionsMask(array('storage' => $storage, 'mask' => \OCP\Constants::PERMISSION_READ + \OCP\Constants::PERMISSION_SHARE));
59
	});
60
}
61
62
$rootInfo = \OC\Files\Filesystem::getFileInfo($path);
63
$rootView = new \OC\Files\View('');
64
65
/**
66
 * @param \OCP\Files\FileInfo $dir
67
 * @param \OC\Files\View $view
68
 * @return array
69
 */
70
function getChildInfo($dir, $view) {
71
	$children = $view->getDirectoryContent($dir->getPath());
72
	$result = array();
73
	foreach ($children as $child) {
74
		$formated = \OCA\Files\Helper::formatFileInfo($child);
75
		if ($child->getType() === 'dir') {
76
			$formated['children'] = getChildInfo($child, $view);
77
		}
78
		$formated['mtime'] = $formated['mtime'] / 1000;
79
		$result[] = $formated;
80
	}
81
	return $result;
82
}
83
84
$result = \OCA\Files\Helper::formatFileInfo($rootInfo);
85
$result['mtime'] = $result['mtime'] / 1000;
86
if ($rootInfo->getType() === 'dir') {
87
	$result['children'] = getChildInfo($rootInfo, $rootView);
88
}
89
90
OCP\JSON::success(array('data' => $result));
91