Welcome to mirror list, hosted at ThFree Co, Russian Federation.

getitem.php « ajax « files_sharing « apps - github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6eed0408238c2b95b9cda84bed0d0000f291cf4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
require_once(OC::$APPSROOT . '/apps/files_sharing/lib_share.php');
 
OCP\JSON::checkAppEnabled('files_sharing');
OCP\JSON::checkLoggedIn();

$item = array();
$userDirectory = '/'.OCP\USER::getUser().'/files';
$source = $userDirectory.$_GET['item'];
$path = $source;
// Search for item and shared parent folders
while ($path != $userDirectory) {
	if ($rows = OC_Share::getMySharedItem($path)) {
		for ($i = 0; $i < count($rows); $i++) {
			$uid_shared_with = $rows[$i]['uid_shared_with'];
			if ($uid_shared_with == OC_Share::PUBLICLINK && !isset($item['privateLink'])) {
				$token = OC_Share::getTokenFromSource($path);
				if ($path == $source) {
					$item['privateLink'] = $token;
				} else {
					// If in parent folder, include a path parameter to get direct access to file
					$item['privateLink'] = $token.'&path='.substr($source, strlen($path));
				}
			} else {
				// Check if uid_shared_with is a group
				if (($pos = strpos($uid_shared_with, '@')) !== false) {
					$gid = substr($uid_shared_with, $pos + 1);
					// Include users in the group so the users can be removed from the list of people to share with
					if ($path == $source) {
						$group = array(array('gid' => $gid, 'permissions' => $rows[$i]['permissions'], 'users' => OC_Group::usersInGroup($gid), 'parentFolder' => false));
					} else {
						$group = array(array('gid' => $gid, 'permissions' => $rows[$i]['permissions'], 'users' => OC_Group::usersInGroup($gid), 'parentFolder' => basename($path)));
					}
					if (!isset($item['groups'])) {
						$item['groups'] = $group;
					} else if (is_array($item['groups'])) {
						$gidExists = false;
						$currentGroups = $item['groups'];
						// Check if the group is already included
						foreach ($currentGroups as $g) {
							if ($g['gid'] == $gid) {
								$gidExists = true;
							}
						}
						if (!$gidExists) {
							$item['groups'] = array_merge($item['groups'], $group);
						}
					}
				} else {
					if ($path == $source) {
						$user = array(array('uid' => $uid_shared_with, 'permissions' => $rows[$i]['permissions'], 'parentFolder' => false));
					} else {
						$user = array(array('uid' => $uid_shared_with, 'permissions' => $rows[$i]['permissions'], 'parentFolder' => basename($path)));
					}
					if (!isset($item['users'])) {
						$item['users'] = $user;
					} else if (is_array($item['users'])) {
						$item['users'] = array_merge($item['users'], $user);
					}
				}
			}
		}
	}
	$path = dirname($path);
}

OCP\JSON::success(array('data' => $item));

?>