2011-07-20 21:34:16 +04:00
|
|
|
<?php
|
2012-05-05 22:56:52 +04:00
|
|
|
require_once(OC::$APPSROOT . '/apps/files_sharing/lib_share.php');
|
2011-07-20 21:34:16 +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-07-20 21:34:16 +04:00
|
|
|
|
2012-05-05 22:56:52 +04:00
|
|
|
$userDirectory = '/'.OCP\USER::getUser().'/files';
|
|
|
|
$sources = explode(';', $_POST['sources']);
|
2011-08-01 04:47:53 +04:00
|
|
|
$uid_shared_with = $_POST['uid_shared_with'];
|
|
|
|
$permissions = $_POST['permissions'];
|
2011-07-28 23:31:52 +04:00
|
|
|
foreach ($sources as $source) {
|
2012-05-15 19:29:02 +04:00
|
|
|
$file = OC_FileCache::get($source);
|
2012-05-05 22:56:52 +04:00
|
|
|
$path = ltrim($source, '/');
|
|
|
|
$source = $userDirectory.$source;
|
|
|
|
// Check if the file exists or if the file is being reshared
|
2012-05-15 19:29:02 +04:00
|
|
|
if ($source && $file['encrypted'] == false && (OC_FILESYSTEM::file_exists($path) && OC_FILESYSTEM::is_readable($path) || OC_Share::getSource($source))) {
|
2012-05-05 22:56:52 +04:00
|
|
|
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) {
|
2012-05-07 03:06:24 +04:00
|
|
|
OCP\Util::writeLog('files_sharing', 'Unexpected Error : '.$exception->getMessage(), OCP\Util::ERROR);
|
|
|
|
OCP\JSON::error(array('data' => array('message' => $exception->getMessage())));
|
2011-08-24 20:32:02 +04:00
|
|
|
}
|
2012-05-05 22:56:52 +04:00
|
|
|
} else {
|
2012-05-15 19:29:02 +04:00
|
|
|
if ($file['encrypted'] == true) {
|
|
|
|
OCP\JSON::error(array('data' => array('message' => 'Encrypted files cannot be shared')));
|
|
|
|
} else {
|
|
|
|
OCP\Util::writeLog('files_sharing', 'File does not exist or is not readable :'.$source, OCP\Util::ERROR);
|
|
|
|
OCP\JSON::error(array('data' => array('message' => 'File does not exist or is not readable')));
|
|
|
|
}
|
2011-08-24 20:32:02 +04:00
|
|
|
}
|
2011-07-28 23:31:52 +04:00
|
|
|
}
|
2011-07-20 21:34:16 +04:00
|
|
|
|
2011-10-01 01:05:10 +04:00
|
|
|
?>
|