Browse Source
Refactor sharing UI; bug fixes, code clean-up, and more efficient with less ajax calls
Refactor sharing UI; bug fixes, code clean-up, and more efficient with less ajax calls
9 changed files with 440 additions and 279 deletions
-
87apps/files_sharing/ajax/getitem.php
-
25apps/files_sharing/ajax/getstatuses.php
-
13apps/files_sharing/ajax/setpermissions.php
-
42apps/files_sharing/ajax/share.php
-
11apps/files_sharing/ajax/unshare.php
-
10apps/files_sharing/ajax/userautocomplete.php
-
5apps/files_sharing/css/sharing.css
-
518apps/files_sharing/js/share.js
-
8apps/files_sharing/lib_share.php
@ -1,36 +1,69 @@ |
|||
<?php |
|||
//$RUNTIME_NOAPPS = true;
|
|||
|
|||
require_once(OC::$APPSROOT . '/apps/files_sharing/lib_share.php'); |
|||
|
|||
OCP\JSON::checkAppEnabled('files_sharing'); |
|||
require_once(OC::$APPSROOT . '/apps/files_sharing/lib_share.php'); |
|||
OCP\JSON::checkLoggedIn(); |
|||
|
|||
$userDirectory = "/".OCP\USER::getUser()."/files"; |
|||
$source = $userDirectory.$_GET['source']; |
|||
$item = array(); |
|||
$userDirectory = '/'.OCP\USER::getUser().'/files'; |
|||
$source = $userDirectory.$_GET['item']; |
|||
$path = $source; |
|||
$users = array(); |
|||
if ($users = OC_Share::getMySharedItem($source)) { |
|||
for ($i = 0; $i < count($users); $i++) { |
|||
if ($users[$i]['uid_shared_with'] == OC_Share::PUBLICLINK) { |
|||
$users[$i]['token'] = OC_Share::getTokenFromSource($source); |
|||
} |
|||
} |
|||
} |
|||
$source = dirname($source); |
|||
while ($source != "" && $source != "/" && $source != "." && $source != $userDirectory) { |
|||
if ($values = OC_Share::getMySharedItem($source)) { |
|||
$values = array_values($values); |
|||
$parentUsers = array(); |
|||
for ($i = 0; $i < count($values); $i++) { |
|||
if ($values[$i]['uid_shared_with'] == OC_Share::PUBLICLINK) { |
|||
$values[$i]['token'] = OC_Share::getTokenFromSource($source)."&path=".substr($path, strlen($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); |
|||
} |
|||
} |
|||
} |
|||
$parentUsers[basename($source)."-".$i] = $values[$i]; |
|||
} |
|||
$users = array_merge($users, $parentUsers); |
|||
} |
|||
$source = dirname($source); |
|||
} |
|||
if (!empty($users)) { |
|||
OCP\JSON::encodedPrint($users); |
|||
$path = dirname($path); |
|||
} |
|||
|
|||
OCP\JSON::success(array('data' => $item)); |
|||
|
|||
?>
|
|||
@ -0,0 +1,25 @@ |
|||
<?php |
|||
require_once(OC::$APPSROOT . '/apps/files_sharing/lib_share.php'); |
|||
|
|||
OCP\JSON::checkAppEnabled('files_sharing'); |
|||
OCP\JSON::checkLoggedIn(); |
|||
|
|||
$items = array(); |
|||
$userDirectory = '/'.OCP\USER::getUser().'/files'; |
|||
$dirLength = strlen($userDirectory); |
|||
if ($rows = OC_Share::getMySharedItems()) { |
|||
for ($i = 0; $i < count($rows); $i++) { |
|||
$source = $rows[$i]['source']; |
|||
// Strip out user directory
|
|||
$item = substr($source, $dirLength); |
|||
if ($rows[$i]['uid_shared_with'] == OC_Share::PUBLICLINK) { |
|||
$items[$item] = true; |
|||
} else { |
|||
$items[$item] = false; |
|||
} |
|||
} |
|||
} |
|||
|
|||
OCP\JSON::success(array('data' => $items)); |
|||
|
|||
?>
|
|||
@ -1,13 +1,14 @@ |
|||
<?php |
|||
//$RUNTIME_NOAPPS = true;
|
|||
require_once(OC::$APPSROOT . '/apps/files_sharing/lib_share.php'); |
|||
|
|||
|
|||
OCP\JSON::checkAppEnabled('files_sharing'); |
|||
require_once(OC::$APPSROOT . '/apps/files_sharing/lib_share.php'); |
|||
OCP\JSON::checkLoggedIn(); |
|||
|
|||
$source = "/".OCP\USER::getUser()."/files".$_GET['source']; |
|||
$uid_shared_with = $_GET['uid_shared_with']; |
|||
$permissions = $_GET['permissions']; |
|||
$source = '/'.OCP\USER::getUser().'/files'.$_POST['source']; |
|||
$uid_shared_with = $_POST['uid_shared_with']; |
|||
$permissions = $_POST['permissions']; |
|||
OC_Share::setPermissions($source, $uid_shared_with, $permissions); |
|||
|
|||
OCP\JSON::success(); |
|||
|
|||
?>
|
|||
@ -1,31 +1,33 @@ |
|||
<?php |
|||
//$RUNTIME_NOAPPS = true;
|
|||
require_once(OC::$APPSROOT . '/apps/files_sharing/lib_share.php'); |
|||
|
|||
|
|||
OCP\JSON::checkAppEnabled('files_sharing'); |
|||
require_once(OC::$APPSROOT . '/apps/files_sharing/lib_share.php'); |
|||
OCP\JSON::checkLoggedIn(); |
|||
|
|||
$userDirectory = "/".OCP\USER::getUser()."/files"; |
|||
$sources = explode(";", $_POST['sources']); |
|||
$userDirectory = '/'.OCP\USER::getUser().'/files'; |
|||
$sources = explode(';', $_POST['sources']); |
|||
$uid_shared_with = $_POST['uid_shared_with']; |
|||
$permissions = $_POST['permissions']; |
|||
foreach ($sources as $source) { |
|||
// Make sure file exists and can be shared
|
|||
if ($source && OC_FILESYSTEM::file_exists($source) && OC_FILESYSTEM::is_readable($source)) { |
|||
$source = $userDirectory.$source; |
|||
// If the file doesn't exist, it may be shared with the current user
|
|||
} else if (!$source = OC_Share::getSource($userDirectory.$source)) { |
|||
OCP\Util::writeLog('files_sharing',"Shared file doesn't exists :".$source,OCP\Util::ERROR); |
|||
echo "false"; |
|||
} |
|||
try { |
|||
$shared = new OC_Share($source, $uid_shared_with, $permissions); |
|||
if ($uid_shared_with == OC_Share::PUBLICLINK) { |
|||
echo $shared->getToken(); |
|||
$path = ltrim($source, '/'); |
|||
$source = $userDirectory.$source; |
|||
// Check if the file exists or if the file is being reshared
|
|||
if ($source && (OC_FILESYSTEM::file_exists($path) && OC_FILESYSTEM::is_readable($path) || OC_Share::getSource($source))) { |
|||
try { |
|||
$shared = new OC_Share($source, $uid_shared_with, $permissions); |
|||
// If this is a private link, return the token
|
|||
if ($uid_shared_with == OC_Share::PUBLICLINK) { |
|||
OCP\JSON::success(array('data' => $shared->getToken())); |
|||
} else { |
|||
OCP\JSON::success(); |
|||
} |
|||
} catch (Exception $exception) { |
|||
OCP\Util::writeLog('files_sharing', 'Unexpected Error : '.$exception->getMessage(),OCP\Util::ERROR); |
|||
OCP\JSON::error(); |
|||
} |
|||
} catch (Exception $exception) { |
|||
OCP\Util::writeLog('files_sharing',"Unexpected Error : ".$exception->getMessage(),OCP\Util::ERROR); |
|||
echo "false"; |
|||
} else { |
|||
OCP\Util::writeLog('files_sharing', 'File does not exist or is not readable :'.$source,OCP\Util::ERROR); |
|||
OCP\JSON::error(); |
|||
} |
|||
} |
|||
|
|||
|
|||
@ -1,12 +1,13 @@ |
|||
<?php |
|||
//$RUNTIME_NOAPPS = true;
|
|||
require_once(OC::$APPSROOT . '/apps/files_sharing/lib_share.php'); |
|||
|
|||
|
|||
OCP\JSON::checkAppEnabled('files_sharing'); |
|||
require_once(OC::$APPSROOT . '/apps/files_sharing/lib_share.php'); |
|||
OCP\JSON::checkLoggedIn(); |
|||
|
|||
$source = "/".OCP\USER::getUser()."/files".$_GET['source']; |
|||
$uid_shared_with = $_GET['uid_shared_with']; |
|||
$source = '/'.OCP\USER::getUser().'/files'.$_POST['source']; |
|||
$uid_shared_with = $_POST['uid_shared_with']; |
|||
OC_Share::unshare($source, $uid_shared_with); |
|||
|
|||
OCP\JSON::success(); |
|||
|
|||
?>
|
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue