2011-08-02 20:19:49 +04:00
|
|
|
<?php
|
2012-04-17 21:31:29 +04:00
|
|
|
|
2012-05-03 14:23:29 +04:00
|
|
|
OCP\JSON::checkAppEnabled('files_sharing');
|
2012-05-05 22:56:52 +04:00
|
|
|
OCP\JSON::checkLoggedIn();
|
2011-08-02 20:19:49 +04:00
|
|
|
|
2012-05-05 22:56:52 +04:00
|
|
|
$item = array();
|
|
|
|
$userDirectory = '/'.OCP\USER::getUser().'/files';
|
|
|
|
$source = $userDirectory.$_GET['item'];
|
2011-08-19 20:47:00 +04:00
|
|
|
$path = $source;
|
2012-05-05 22:56:52 +04:00
|
|
|
// 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
|
2012-05-07 19:30:36 +04:00
|
|
|
$item['privateLink'] = $token.'&path='.str_replace('%2F', '/', str_replace('+', '%20', urlencode(substr($source, strlen($path)))));;
|
2012-05-05 22:56:52 +04:00
|
|
|
}
|
|
|
|
} 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);
|
|
|
|
}
|
|
|
|
}
|
2011-08-19 20:47:00 +04:00
|
|
|
}
|
2011-08-08 23:49:16 +04:00
|
|
|
}
|
2011-08-07 23:20:57 +04:00
|
|
|
}
|
2012-05-05 22:56:52 +04:00
|
|
|
$path = dirname($path);
|
2011-08-19 20:47:00 +04:00
|
|
|
}
|
2012-05-05 22:56:52 +04:00
|
|
|
|
|
|
|
OCP\JSON::success(array('data' => $item));
|