summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/ajax/email.php17
-rw-r--r--apps/files_sharing/ajax/getitem.php74
-rw-r--r--apps/files_sharing/ajax/getstatuses.php25
-rw-r--r--apps/files_sharing/ajax/setpermissions.php15
-rw-r--r--apps/files_sharing/ajax/share.php40
-rw-r--r--apps/files_sharing/ajax/toggleresharing.php13
-rw-r--r--apps/files_sharing/ajax/unshare.php14
-rw-r--r--apps/files_sharing/ajax/userautocomplete.php45
-rw-r--r--apps/files_sharing/appinfo/app.php24
-rw-r--r--apps/files_sharing/css/sharing.css14
-rw-r--r--apps/files_sharing/get.php6
-rw-r--r--apps/files_sharing/js/list.js54
-rw-r--r--apps/files_sharing/js/settings.js16
-rw-r--r--apps/files_sharing/js/share.js387
-rw-r--r--apps/files_sharing/l10n/.gitkeep0
-rw-r--r--apps/files_sharing/l10n/ca.php6
-rw-r--r--apps/files_sharing/l10n/cs_CZ.php6
-rw-r--r--apps/files_sharing/l10n/de.php6
-rw-r--r--apps/files_sharing/l10n/el.php6
-rw-r--r--apps/files_sharing/l10n/eo.php3
-rw-r--r--apps/files_sharing/l10n/es.php6
-rw-r--r--apps/files_sharing/l10n/et_EE.php3
-rw-r--r--apps/files_sharing/l10n/fa.php6
-rw-r--r--apps/files_sharing/l10n/fi_FI.php6
-rw-r--r--apps/files_sharing/l10n/fr.php6
-rw-r--r--apps/files_sharing/l10n/it.php6
-rw-r--r--apps/files_sharing/l10n/ja_JP.php6
-rw-r--r--apps/files_sharing/l10n/lt_LT.php6
-rw-r--r--apps/files_sharing/l10n/nb_NO.php6
-rw-r--r--apps/files_sharing/l10n/pl.php6
-rw-r--r--apps/files_sharing/l10n/sl.php6
-rw-r--r--apps/files_sharing/l10n/sv.php6
-rw-r--r--apps/files_sharing/l10n/th_TH.php6
-rw-r--r--apps/files_sharing/lib/share/file.php91
-rw-r--r--apps/files_sharing/lib/share/folder.php61
-rw-r--r--apps/files_sharing/lib/sharedstorage.php427
-rw-r--r--apps/files_sharing/lib_share.php523
-rw-r--r--apps/files_sharing/list.php37
-rw-r--r--apps/files_sharing/settings.php10
-rw-r--r--apps/files_sharing/sharedstorage.php542
-rwxr-xr-xapps/files_sharing/templates/get.php11
-rw-r--r--apps/files_sharing/templates/list.php30
-rw-r--r--apps/files_sharing/templates/settings.php8
43 files changed, 739 insertions, 1847 deletions
diff --git a/apps/files_sharing/ajax/email.php b/apps/files_sharing/ajax/email.php
deleted file mode 100644
index 2a81e6f9827..00000000000
--- a/apps/files_sharing/ajax/email.php
+++ /dev/null
@@ -1,17 +0,0 @@
-<?php
-OCP\JSON::checkLoggedIn();
-OCP\JSON::callCheck();
-OCP\JSON::checkAppEnabled('files_sharing');
-$user = OCP\USER::getUser();
-// TODO translations
-$type = (strpos($_POST['file'], '.') === false) ? 'folder' : 'file';
-$subject = $user.' shared a '.$type.' with you';
-$link = $_POST['link'];
-$text = $user.' shared the '.$type.' '.$_POST['file'].' with you. It is available for download here: '.$link;
-$fromaddress = OCP\Config::getUserValue($user, 'settings', 'email', 'sharing-noreply@'.OCP\Util::getServerHost());
-try {
- OCP\Util::sendMail($_POST['toaddress'], $_POST['toaddress'], $subject, $text, $fromaddress, $user);
- OCP\JSON::success();
-} catch (Exception $exception) {
- OCP\JSON::error(array('data' => array('message' => $exception->getMessage())));
-}
diff --git a/apps/files_sharing/ajax/getitem.php b/apps/files_sharing/ajax/getitem.php
deleted file mode 100644
index 852e5a24571..00000000000
--- a/apps/files_sharing/ajax/getitem.php
+++ /dev/null
@@ -1,74 +0,0 @@
-<?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='.str_replace('%2F', '/', str_replace('+', '%20', urlencode(substr($source, strlen($path)))));;
- }
- } else {
- // Check if uid_shared_with is a group
- $pos = strrpos($uid_shared_with, '@');
- if ($pos !== false) {
- $gid = substr($uid_shared_with, $pos + 1);
- } else {
- $gid = false;
- }
- if ($gid && OC_Group::groupExists($gid)) {
- // 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));
-
-?>
diff --git a/apps/files_sharing/ajax/getstatuses.php b/apps/files_sharing/ajax/getstatuses.php
deleted file mode 100644
index 8edcb214758..00000000000
--- a/apps/files_sharing/ajax/getstatuses.php
+++ /dev/null
@@ -1,25 +0,0 @@
-<?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 if (!isset($items[$item])) {
- $items[$item] = false;
- }
- }
-}
-
-OCP\JSON::success(array('data' => $items));
-
-?> \ No newline at end of file
diff --git a/apps/files_sharing/ajax/setpermissions.php b/apps/files_sharing/ajax/setpermissions.php
deleted file mode 100644
index 13daab738de..00000000000
--- a/apps/files_sharing/ajax/setpermissions.php
+++ /dev/null
@@ -1,15 +0,0 @@
-<?php
-require_once(OC::$APPSROOT . '/apps/files_sharing/lib_share.php');
-
-OCP\JSON::checkAppEnabled('files_sharing');
-OCP\JSON::checkLoggedIn();
-OCP\JSON::callCheck();
-
-$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();
-
-?>
diff --git a/apps/files_sharing/ajax/share.php b/apps/files_sharing/ajax/share.php
deleted file mode 100644
index fb28caf7b7e..00000000000
--- a/apps/files_sharing/ajax/share.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-require_once(OC::$APPSROOT . '/apps/files_sharing/lib_share.php');
-
-OCP\JSON::checkAppEnabled('files_sharing');
-OCP\JSON::checkLoggedIn();
-OCP\JSON::callCheck();
-
-$userDirectory = '/'.OCP\USER::getUser().'/files';
-$sources = explode(';', $_POST['sources']);
-$uid_shared_with = $_POST['uid_shared_with'];
-$permissions = $_POST['permissions'];
-foreach ($sources as $source) {
- $file = OC_FileCache::get($source);
- $path = ltrim($source, '/');
- $source = $userDirectory.$source;
- // Check if the file exists or if the file is being reshared
- if ($source && $file['encrypted'] == false && (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(array('data' => array('message' => $exception->getMessage())));
- }
- } else {
- 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')));
- }
- }
-}
-
-?>
diff --git a/apps/files_sharing/ajax/toggleresharing.php b/apps/files_sharing/ajax/toggleresharing.php
deleted file mode 100644
index ab8e82c8c3f..00000000000
--- a/apps/files_sharing/ajax/toggleresharing.php
+++ /dev/null
@@ -1,13 +0,0 @@
-<?php
-
-OCP\JSON::callCheck();
-
-OCP\JSON::checkAppEnabled('files_sharing');
-OCP\JSON::checkAdminUser();
-if ($_POST['resharing'] == true) {
- OCP\Config::setAppValue('files_sharing', 'resharing', 'yes');
-} else {
- OCP\Config::setAppValue('files_sharing', 'resharing', 'no');
-}
-
-?>
diff --git a/apps/files_sharing/ajax/unshare.php b/apps/files_sharing/ajax/unshare.php
deleted file mode 100644
index d291b719e38..00000000000
--- a/apps/files_sharing/ajax/unshare.php
+++ /dev/null
@@ -1,14 +0,0 @@
-<?php
-require_once(OC::$APPSROOT . '/apps/files_sharing/lib_share.php');
-
-OCP\JSON::checkAppEnabled('files_sharing');
-OCP\JSON::checkLoggedIn();
-OCP\JSON::callCheck();
-
-$source = '/'.OCP\USER::getUser().'/files'.$_POST['source'];
-$uid_shared_with = $_POST['uid_shared_with'];
-OC_Share::unshare($source, $uid_shared_with);
-
-OCP\JSON::success();
-
-?>
diff --git a/apps/files_sharing/ajax/userautocomplete.php b/apps/files_sharing/ajax/userautocomplete.php
deleted file mode 100644
index 23865693a1b..00000000000
--- a/apps/files_sharing/ajax/userautocomplete.php
+++ /dev/null
@@ -1,45 +0,0 @@
-<?php
-
-OCP\JSON::checkLoggedIn();
-OCP\JSON::checkAppEnabled('files_sharing');
-
-$users = array();
-$groups = array();
-$self = OCP\USER::getUser();
-$users[] = "<optgroup label='Users'>";
-$groups[] = "<optgroup label='Groups'>";
-if(OCP\Config::getAppValue('files_sharing', 'allowSharingWithEveryone', 'no') == 'yes') {
- $allGroups = OC_Group::getGroups();
- foreach($allGroups as $group) {
- $groups[] = "<option value='".$group."(group)'>".$group." (group) </option>";
- }
- $allUsers = OC_User::getUsers();
- foreach($allUsers as $user) {
- if($user != $self) {
- $users[] = "<option value='".$user."'>".$user."</option>";
- }
- }
-} else {
- $userGroups = OC_Group::getUserGroups($self);
- foreach ($userGroups as $group) {
- $groupUsers = OC_Group::usersInGroup($group);
- $userCount = 0;
- foreach ($groupUsers as $user) {
- if ($user != $self) {
- $users[] = "<option value='".$user."'>".$user."</option>";
- $userCount++;
- }
- }
- // Don't include the group if only the current user is a member of it
- if ($userCount > 0) {
- $groups[] = "<option value='".$group."(group)'>".$group." (group) </option>";
- }
- }
- $users = array_unique($users);
-}
-$users[] = "</optgroup>";
-$groups[] = "</optgroup>";
-$users = array_merge($users, $groups);
-OCP\JSON::encodedPrint($users);
-
-?>
diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php
index ea3a9da6f7a..109f86b2e87 100644
--- a/apps/files_sharing/appinfo/app.php
+++ b/apps/files_sharing/appinfo/app.php
@@ -1,19 +1,9 @@
<?php
-require_once('apps/files_sharing/sharedstorage.php');
-
-OC::$CLASSPATH['OC_Share'] = "apps/files_sharing/lib_share.php";
-OCP\App::registerAdmin('files_sharing', 'settings');
-OCP\Util::connectHook("OC_Filesystem", "post_delete", "OC_Share", "deleteItem");
-OCP\Util::connectHook("OC_Filesystem", "post_rename", "OC_Share", "renameItem");
-OCP\Util::connectHook("OC_Filesystem", "post_write", "OC_Share", "updateItem");
-OCP\Util::connectHook('OC_User', 'post_deleteUser', 'OC_Share', 'removeUser');
-OCP\Util::connectHook('OC_User', 'post_addToGroup', 'OC_Share', 'addToGroupShare');
-OCP\Util::connectHook('OC_User', 'post_removeFromGroup', 'OC_Share', 'removeFromGroupShare');
-$dir = isset($_GET['dir']) ? $_GET['dir'] : '/';
-if ($dir != '/Shared' || OCP\Config::getAppValue('files_sharing', 'resharing', 'yes') == 'yes') {
- OCP\Util::addscript("files_sharing", "share");
-}
-OCP\Util::addscript("3rdparty", "chosen/chosen.jquery.min");
-OCP\Util::addStyle( 'files_sharing', 'sharing' );
-OCP\Util::addStyle("3rdparty", "chosen/chosen");
+OC::$CLASSPATH['OC_Share_Backend_File'] = "apps/files_sharing/lib/share/file.php";
+OC::$CLASSPATH['OC_Share_Backend_Folder'] = 'apps/files_sharing/lib/share/folder.php';
+OC::$CLASSPATH['OC_Filestorage_Shared'] = "apps/files_sharing/lib/sharedstorage.php";
+OCP\Util::connectHook('OC_Filesystem', 'setup', 'OC_Filestorage_Shared', 'setup');
+OCP\Share::registerBackend('file', 'OC_Share_Backend_File');
+OCP\Share::registerBackend('folder', 'OC_Share_Backend_Folder', 'file');
+OCP\Util::addScript('files_sharing', 'share');
diff --git a/apps/files_sharing/css/sharing.css b/apps/files_sharing/css/sharing.css
deleted file mode 100644
index c4b4540e9d1..00000000000
--- a/apps/files_sharing/css/sharing.css
+++ /dev/null
@@ -1,14 +0,0 @@
-/* Copyright (c) 2011, Jan-Christoph Borchardt, http://jancborchardt.net
- This file is licensed under the Affero General Public License version 3 or later.
- See the COPYING-README file. */
-
-#dropdown { display:block; position:absolute; z-index:100; width:16em; right:0; margin-right:7em; background:#eee; padding:1em;
--moz-box-shadow:0 1px 1px #777; -webkit-box-shadow:0 1px 1px #777; box-shadow:0 1px 1px #777;
--moz-border-radius-bottomleft:1em; -webkit-border-bottom-left-radius:1em; border-bottom-left-radius:1em;
--moz-border-radius-bottomright:1em; -webkit-border-bottom-right-radius:1em; border-bottom-right-radius:1em; }
-#sharedWithList { padding:0.5em; list-style-type: none; }
-#privateLink { border-top:1px solid #ddd; padding-top:0.5em; }
-a.unshare { float:right; display:inline; margin:0 .5em; padding:.3em .3em 0 .3em !important; opacity:.5; }
-a.unshare:hover { opacity:1; }
-#share_with { width: 16em; }
-#privateLink label, .edit { font-weight:normal; }
diff --git a/apps/files_sharing/get.php b/apps/files_sharing/get.php
index e2fcb82750d..1d219719b2d 100644
--- a/apps/files_sharing/get.php
+++ b/apps/files_sharing/get.php
@@ -1,6 +1,4 @@
<?php
-$RUNTIME_NOSETUPFS=true; //don't setup the fs yet
-
// only need authentication apps
$RUNTIME_APPTYPES=array('authentication');
OC_App::loadApps($RUNTIME_APPTYPES);
@@ -61,7 +59,7 @@ if (isset($_GET['token']) && $source = OC_Share::getSource($_GET['token'])) {
$list->assign("downloadURL", OCP\Util::linkTo("", "public.php")."?service=files&token=".$token."&path=");
$list->assign("readonly", true);
$tmpl = new OCP\Template("files", "index", "user");
- $tmpl->assign("fileList", $list->fetchPage());
+ $tmpl->assign("fileList", $list->fetchPage(), false);
$tmpl->assign("breadcrumb", $breadcrumbNav->fetchPage());
$tmpl->assign("readonly", true);
$tmpl->assign("allowZipDownload", false);
@@ -77,6 +75,7 @@ if (isset($_GET['token']) && $source = OC_Share::getSource($_GET['token'])) {
header("Content-Length: " . OC_Filesystem::filesize($source));
//download the file
@ob_clean();
+ OCP\Util::emitHook('OC_Share', 'public-download', array('source'=>$source, 'token'=>$token));
OC_Filesystem::readfile($source);
}
} else {
@@ -85,4 +84,3 @@ if (isset($_GET['token']) && $source = OC_Share::getSource($_GET['token'])) {
$tmpl->printPage();
die();
}
-?>
diff --git a/apps/files_sharing/js/list.js b/apps/files_sharing/js/list.js
deleted file mode 100644
index 41eabd1f4af..00000000000
--- a/apps/files_sharing/js/list.js
+++ /dev/null
@@ -1,54 +0,0 @@
-$(document).ready(function() {
- $( "#source" ).autocomplete({
- source: "../../files/ajax/autocomplete.php",
- minLength: 1
- });
- $( "#uid_shared_with" ).autocomplete({
- source: "ajax/userautocomplete.php",
- minLength: 1
- });
- $("button.delete").live('click', function( event ) {
- event.preventDefault();
-// var row=$(this);
- var source=$(this).attr('data-source');
- var uid_shared_with=$(this).attr('data-uid_shared_with');
- var data='source='+encodeURIComponent(source)+'&uid_shared_with='+encodeURIComponent(uid_shared_with);
- $.ajax({
- type: 'GET',
- url: 'ajax/unshare.php',
- cache: false,
- data: data
-// success: function(){
-// row.remove();
-// }
- });
- });
- $('#share_item').submit(function( event ){
- event.preventDefault();
- var source=$('#source').val();
- var uid_shared_with=$('#uid_shared_with').val();
- var permissions=$('#permissions').val()||0;
- var data='source='+source+'&uid_shared_with='+uid_shared_with+'&permissions='+permissions;
- $.ajax({
- type: 'GET',
- url: 'ajax/share.php',
- cache: false,
- data: data,
-// success: function(token){
-// if(token){
-// var html="<tr class='link' id='"+token+"'>";
-// html+="<td class='path'>"+path+"</td>";
-// var expire=($('#expire').val())?$('#expire').val():'Never'
-// html+="<td class='expire'>"+expire+"</td>"
-// html+="<td class='link'><a href='get.php?token="+token+"'>"+$('#baseUrl').val()+"?token="+token+"</a></td>"
-// html+="<td><button class='delete fancybutton' data-token='"+token+"'>Delete</button></td>"
-// html+="</tr>"
-// $(html).insertBefore($('#newlink_row'));
-// $('#expire').val('');
-// $('#expire_time').val('');
-// $('#path').val('');
-// }
-// }
- });
- });
-}); \ No newline at end of file
diff --git a/apps/files_sharing/js/settings.js b/apps/files_sharing/js/settings.js
deleted file mode 100644
index c276521b7b5..00000000000
--- a/apps/files_sharing/js/settings.js
+++ /dev/null
@@ -1,16 +0,0 @@
-$(document).ready(function() {
- $('#allowResharing').bind('change', function() {
- var checked = 1;
- if (!this.checked) {
- checked = 0;
- }
- $.post(OC.filePath('files_sharing','ajax','toggleresharing.php'), 'resharing='+checked);
- });
- $('#allowSharingWithEveryone').bind('change', function() {
- var checked = 1;
- if (!this.checked) {
- checked = 0;
- }
- $.post(OC.filePath('files_sharing','ajax','togglesharewitheveryone.php'), 'allowSharingWithEveryone='+checked);
- });
-}); \ No newline at end of file
diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js
index 1ad51873540..bcfd42ce21e 100644
--- a/apps/files_sharing/js/share.js
+++ b/apps/files_sharing/js/share.js
@@ -1,375 +1,64 @@
-OC.Share={
- icons:[],
- itemUsers:[],
- itemGroups:[],
- itemPrivateLink:false,
- usersAndGroups:[],
- loadIcons:function() {
- // Cache all icons for shared files
- $.getJSON(OC.filePath('files_sharing', 'ajax', 'getstatuses.php'), function(result) {
- if (result && result.status === 'success') {
- $.each(result.data, function(item, hasPrivateLink) {
- if (hasPrivateLink) {
- OC.Share.icons[item] = OC.imagePath('core', 'actions/public');
- } else {
- OC.Share.icons[item] = OC.imagePath('core', 'actions/shared');
- }
- });
- }
- });
- },
- loadItem:function(item) {
- $.ajax({type: 'GET', url: OC.filePath('files_sharing', 'ajax', 'getitem.php'), data: { item: item }, async: false, success: function(result) {
- if (result && result.status === 'success') {
- var item = result.data;
- OC.Share.itemUsers = item.users;
- OC.Share.itemGroups = item.groups;
- OC.Share.itemPrivateLink = item.privateLink;
- }
- }});
- },
- share:function(source, uid_shared_with, permissions, callback) {
- $.post(OC.filePath('files_sharing', 'ajax', 'share.php'), { sources: source, uid_shared_with: uid_shared_with, permissions: permissions }, function(result) {
- if (result && result.status === 'success') {
- if (callback) {
- callback(result.data);
- }
- } else {
- OC.dialogs.alert(result.data.message, 'Error while sharing');
- }
- });
- },
- unshare:function(source, uid_shared_with, callback) {
- $.post(OC.filePath('files_sharing', 'ajax', 'unshare.php'), { source: source, uid_shared_with: uid_shared_with }, function(result) {
- if (result && result.status === 'success') {
- if (callback) {
- callback();
- }
- } else {
- OC.dialogs.alert('Error', 'Error while unsharing');
- }
- });
- },
- changePermissions:function(source, uid_shared_with, permissions) {
- $.post(OC.filePath('files_sharing','ajax','setpermissions.php'), { source: source, uid_shared_with: uid_shared_with, permissions: permissions }, function(result) {
- if (!result || result.status !== 'success') {
- OC.dialogs.alert('Error', 'Error while changing permissions');
- }
- });
- },
- showDropDown:function(item, appendTo) {
- OC.Share.loadItem(item);
- var html = '<div id="dropdown" class="drop" data-item="'+item+'">';
- html += '<select data-placeholder="User or Group" id="share_with" class="chzen-select">';
- html += '<option value=""></option>';
- html += '</select>';
- html += '<div id="sharedWithList">';
- html += '<ul id="userList"></ul>';
- html += '<div id="groups" style="display:none;">';
- html += '<br />';
- html += 'Groups: ';
- html += '<ul id="groupList"></ul>';
- html += '</div>';
- html += '</div>';
- html += '<div id="privateLink">';
- html += '<input type="checkbox" name="privateLinkCheckbox" id="privateLinkCheckbox" value="1" /><label for="privateLinkCheckbox">Share with private link</label>';
- html += '<br />';
- html += '<form id="emailPrivateLink">';
- html += '<input id="privateLinkText" style="display:none; width:90%;" />';
- html += '<input id="email" style="display:none; width:65%;" value="" placeholder="Email link to person" />';
- html += '<input id="emailButton" style="display:none;" type="submit" value="Send" />';
- html += '</form>';
- html += '</div>';
- $(html).appendTo(appendTo);
- if (OC.Share.usersAndGroups.length < 1) {
- $.ajax({type: 'GET', url: OC.filePath('files_sharing', 'ajax', 'userautocomplete.php'), async: false, success: function(users) {
- if (users) {
- OC.Share.usersAndGroups = users;
- $.each(users, function(index, user) {
- $(user).appendTo('#share_with');
- });
- $('#share_with').trigger('liszt:updated');
- }
- }});
- } else {
- $.each(OC.Share.usersAndGroups, function(index, user) {
- $(user).appendTo('#share_with');
- });
- $('#share_with').trigger('liszt:updated');
- }
- if (OC.Share.itemUsers) {
- $.each(OC.Share.itemUsers, function(index, user) {
- if (user.parentFolder) {
- OC.Share.addSharedWith(user.uid, user.permissions, false, user.parentFolder);
- } else {
- OC.Share.addSharedWith(user.uid, user.permissions, false, false);
- }
- });
- }
- if (OC.Share.itemGroups) {
- $.each(OC.Share.itemGroups, function(index, group) {
- if (group.parentFolder) {
- OC.Share.addSharedWith(group.gid, group.permissions, group.users, group.parentFolder);
- } else {
- OC.Share.addSharedWith(group.gid, group.permissions, group.users, false);
- }
- });
- }
- if (OC.Share.itemPrivateLink) {
- OC.Share.showPrivateLink(item, OC.Share.itemPrivateLink);
- }
- $('#dropdown').show('blind');
- $('#share_with').chosen();
- },
- hideDropDown:function(callback) {
- $('#dropdown').hide('blind', function() {
- $('#dropdown').remove();
- if (callback) {
- callback.call();
- }
- });
- },
- addSharedWith:function(uid_shared_with, permissions, isGroup, parentFolder) {
- if (parentFolder) {
- var sharedWith = '<li>Parent folder '+parentFolder+' shared with '+uid_shared_with+'</li>';
- } else {
- var checked = ((permissions > 0) ? 'checked="checked"' : 'style="display:none;"');
- var style = ((permissions == 0) ? 'style="display:none;"' : '');
- var sharedWith = '<li data-uid_shared_with="'+uid_shared_with+'">';
- sharedWith += '<a href="" class="unshare" style="display:none;"><img class="svg" alt="Unshare" src="'+OC.imagePath('core','actions/delete')+'"/></a>';
- sharedWith += uid_shared_with;
- sharedWith += '<input type="checkbox" name="permissions" id="'+uid_shared_with+'" class="permissions" '+checked+' />';
- sharedWith += '<label class="edit" for="'+uid_shared_with+'" '+style+'>can edit</label>';
- sharedWith += '</li>';
- }
- if (isGroup) {
- // Groups are added to a different list
- $('#groups').show();
- $(sharedWith).appendTo('#groupList');
- // Remove group from select form
- $('#share_with option[value="'+uid_shared_with+'(group)"]').remove();
- $('#share_with').trigger('liszt:updated');
- // Remove users in group from select form
- $.each(isGroup, function(index, user) {
- $('#share_with option[value="'+user+'"]').remove();
- $('#share_with').trigger('liszt:updated');
- });
- } else {
- $(sharedWith).appendTo('#userList');
- // Remove user from select form
- $('#share_with option[value="'+uid_shared_with+'"]').remove();
- $('#share_with').trigger('liszt:updated');
- }
-
- },
- removeSharedWith:function(uid_shared_with) {
- var option;
- if ($('#userList li[data-uid_shared_with="'+uid_shared_with+'"]').length > 0) {
- $('#userList li[data-uid_shared_with="'+uid_shared_with+'"]').remove();
- option = '<option value="'+uid_shared_with+'">'+uid_shared_with+'</option>';
- } else if ($('#groupList li[data-uid_shared_with="'+uid_shared_with+'"]').length > 0) {
- $('#groupList li[data-uid_shared_with="'+uid_shared_with+'"]').remove();
- if ($('#groupList li').length < 1) {
- $('#groups').hide();
- }
- option = '<option value="'+uid_shared_with+'(group)">'+uid_shared_with+' (group)</option>';
- }
- $(option).appendTo('#share_with');
- $('#share_with').trigger('liszt:updated');
- },
- showPrivateLink:function(item, token) {
- $('#privateLinkCheckbox').attr('checked', true);
- var link = parent.location.protocol+'//'+location.host+OC.linkTo('', 'public.php')+'?service=files&token='+token;
- if (token.indexOf('&path=') == -1) {
- link += '&file=' + encodeURIComponent(item).replace(/%2F/g, '/');
- } else {
- // Disable checkbox if inside a shared parent folder
- $('#privateLinkCheckbox').attr('disabled', 'true');
- }
- $('#privateLinkText').val(link);
- $('#privateLinkText').show('blind', function() {
- $('#privateLinkText').after('<br id="emailBreak" />');
- $('#email').show();
- $('#emailButton').show();
- });
- },
- hidePrivateLink:function() {
- $('#privateLinkText').hide('blind');
- $('#emailBreak').remove();
- $('#email').hide();
- $('#emailButton').hide();
- },
- emailPrivateLink:function() {
- var link = $('#privateLinkText').val();
- var file = link.substr(link.lastIndexOf('/') + 1).replace(/%20/g, ' ');
- var email = $('#email').val();
- if (email != '') {
- $.post(OC.filePath('files_sharing', 'ajax', 'email.php'), { toaddress: email, link: link, file: file }, function(result) {
- if (result && result.status == 'success') {
- $('#email').css('font-weight', 'bold');
- $('#email').animate({ fontWeight: 'normal' }, 2000, function() {
- $(this).val('');
- }).val('Email sent');
- } else {
- OC.dialogs.alert(result.data.message, 'Error while sharing');
- }
- });
- }
- },
- dirname:function(path) {
- return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');
- }
-}
-
$(document).ready(function() {
if (typeof FileActions !== 'undefined') {
- OC.Share.loadIcons();
- FileActions.register('all', 'Share', function(filename) {
+ OC.Share.loadIcons('file');
+ FileActions.register('all', 'Share', FileActions.PERMISSION_SHARE, function(filename) {
// Return the correct sharing icon
if (scanFiles.scanning) { return; } // workaround to prevent additional http request block scanning feedback
- var item = $('#dir').val() + '/' + filename;
- // Check if icon is in cache
- if (OC.Share.icons[item]) {
- return OC.Share.icons[item];
+ if ($('#dir').val() == '/') {
+ var item = $('#dir').val() + filename;
+ } else {
+ var item = $('#dir').val() + '/' + filename;
+ }
+ // Check if status is in cache
+ if (OC.Share.statuses[item] === true) {
+ return OC.imagePath('core', 'actions/public');
+ } else if (OC.Share.statuses[item] === false) {
+ return OC.imagePath('core', 'actions/shared');
} else {
var last = '';
var path = OC.Share.dirname(item);
// Search for possible parent folders that are shared
while (path != last) {
- if (OC.Share.icons[path]) {
- OC.Share.icons[item] = OC.Share.icons[path];
- return OC.Share.icons[item];
+ if (OC.Share.statuses[path] === true) {
+ return OC.imagePath('core', 'actions/public');
+ } else if (OC.Share.statuses[path] === false) {
+ return OC.imagePath('core', 'actions/shared');
}
last = path;
path = OC.Share.dirname(path);
}
- OC.Share.icons[item] = OC.imagePath('core', 'actions/share');
- return OC.Share.icons[item];
+ return OC.imagePath('core', 'actions/share');
}
}, function(filename) {
- var file = $('#dir').val() + '/' + filename;
- var appendTo = $('tr').filterAttr('data-file',filename).find('td.filename');
+ if ($('#dir').val() == '/') {
+ var item = $('#dir').val() + filename;
+ } else {
+ var item = $('#dir').val() + '/' + filename;
+ }
+ if ($('tr').filterAttr('data-file', filename).data('type') == 'dir') {
+ var itemType = 'folder';
+ var possiblePermissions = OC.Share.PERMISSION_CREATE | OC.Share.PERMISSION_UPDATE | OC.Share.PERMISSION_DELETE | OC.Share.PERMISSION_SHARE;
+ } else {
+ var itemType = 'file';
+ var possiblePermissions = OC.Share.PERMISSION_UPDATE | OC.Share.PERMISSION_DELETE | OC.Share.PERMISSION_SHARE;
+ }
+ var appendTo = $('tr').filterAttr('data-file', filename).find('td.filename');
// Check if drop down is already visible for a different file
- if (($('#dropdown').length > 0)) {
- if (file != $('#dropdown').data('item')) {
+ if (OC.Share.droppedDown) {
+ if (item != $('#dropdown').data('item')) {
OC.Share.hideDropDown(function () {
- $('tr').removeClass('mouseOver');
- $('tr').filterAttr('data-file',filename).addClass('mouseOver');
- OC.Share.showDropDown(file, appendTo);
+ $('tr').filterAttr('data-file', filename).addClass('mouseOver');
+ OC.Share.showDropDown(itemType, item, appendTo, true, possiblePermissions);
});
+ } else {
+ OC.Share.hideDropDown();
}
} else {
$('tr').filterAttr('data-file',filename).addClass('mouseOver');
- OC.Share.showDropDown(file, appendTo);
+ OC.Share.showDropDown(itemType, item, appendTo, true, possiblePermissions);
}
});
- };
-
- $(this).click(function(event) {
- if (!($(event.target).hasClass('drop')) && $(event.target).parents().index($('#dropdown')) == -1) {
- if ($('#dropdown').is(':visible')) {
- OC.Share.hideDropDown(function() {
- $('tr').removeClass('mouseOver');
- });
- }
- }
- });
-
- $('#sharedWithList li').live('mouseenter', function(event) {
- // Show permissions and unshare button
- $(':hidden', this).show();
- });
-
- $('#sharedWithList li').live('mouseleave', function(event) {
- // Hide permissions and unshare button
- $('a', this).hide();
- if (!$('input:[type=checkbox]', this).is(':checked')) {
- $('input:[type=checkbox]', this).hide();
- $('label', this).hide();
- }
- });
-
- $('#share_with').live('change', function() {
- var item = $('#dropdown').data('item');
- var uid_shared_with = $(this).val();
- var pos = uid_shared_with.indexOf('(group)');
- var isGroup = false;
- if (pos != -1) {
- // Remove '(group)' from uid_shared_with
- uid_shared_with = uid_shared_with.substr(0, pos);
- isGroup = true;
- }
- OC.Share.share(item, uid_shared_with, 0, function() {
- if (isGroup) {
- // Reload item because we don't know which users are in the group
- OC.Share.loadItem(item);
- var users;
- $.each(OC.Share.itemGroups, function(index, group) {
- if (group.gid == uid_shared_with) {
- users = group.users;
- }
- });
- OC.Share.addSharedWith(uid_shared_with, 0, users, false);
- } else {
- OC.Share.addSharedWith(uid_shared_with, 0, false, false);
- }
- // Change icon
- if (!OC.Share.itemPrivateLink) {
- OC.Share.icons[item] = OC.imagePath('core', 'actions/shared');
- }
- });
- });
-
- $('.unshare').live('click', function() {
- var item = $('#dropdown').data('item');
- var uid_shared_with = $(this).parent().data('uid_shared_with');
- OC.Share.unshare(item, uid_shared_with, function() {
- OC.Share.removeSharedWith(uid_shared_with);
- // Reload item to update cached users and groups for the icon check
- OC.Share.loadItem(item);
- // Change icon
- if (!OC.Share.itemPrivateLink && !OC.Share.itemUsers && !OC.Share.itemGroups) {
- OC.Share.icons[item] = OC.imagePath('core', 'actions/share');
- }
- });
- });
-
- $('.permissions').live('change', function() {
- var permissions = (this.checked) ? 1 : 0;
- OC.Share.changePermissions($('#dropdown').data('item'), $(this).parent().data('uid_shared_with'), permissions);
- });
-
- $('#privateLinkCheckbox').live('change', function() {
- var item = $('#dropdown').data('item');
- if (this.checked) {
- // Create a private link
- OC.Share.share(item, 'public', 0, function(token) {
- OC.Share.showPrivateLink(item, token);
- // Change icon
- OC.Share.icons[item] = OC.imagePath('core', 'actions/public');
- });
- } else {
- // Delete private link
- OC.Share.unshare(item, 'public', function() {
- OC.Share.hidePrivateLink();
- // Change icon
- if (OC.Share.itemUsers || OC.Share.itemGroups) {
- OC.Share.icons[item] = OC.imagePath('core', 'actions/shared');
- } else {
- OC.Share.icons[item] = OC.imagePath('core', 'actions/share');
- }
- });
- }
- });
-
- $('#privateLinkText').live('click', function() {
- $(this).focus();
- $(this).select();
- });
+ }
- $('#emailPrivateLink').live('submit', function(event) {
- event.preventDefault();
- OC.Share.emailPrivateLink();
- });
}); \ No newline at end of file
diff --git a/apps/files_sharing/l10n/.gitkeep b/apps/files_sharing/l10n/.gitkeep
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/apps/files_sharing/l10n/.gitkeep
diff --git a/apps/files_sharing/l10n/ca.php b/apps/files_sharing/l10n/ca.php
new file mode 100644
index 00000000000..6931389b9c9
--- /dev/null
+++ b/apps/files_sharing/l10n/ca.php
@@ -0,0 +1,6 @@
+<?php $TRANSLATIONS = array(
+"Size" => "Mida",
+"Modified" => "Modificat",
+"Delete all" => "Esborra-ho tot",
+"Delete" => "Elimina"
+);
diff --git a/apps/files_sharing/l10n/cs_CZ.php b/apps/files_sharing/l10n/cs_CZ.php
new file mode 100644
index 00000000000..7c5828a6136
--- /dev/null
+++ b/apps/files_sharing/l10n/cs_CZ.php
@@ -0,0 +1,6 @@
+<?php $TRANSLATIONS = array(
+"Size" => "Velikost",
+"Modified" => "Upraveno",
+"Delete all" => "Smazat vše",
+"Delete" => "Smazat"
+);
diff --git a/apps/files_sharing/l10n/de.php b/apps/files_sharing/l10n/de.php
new file mode 100644
index 00000000000..d42383b43b0
--- /dev/null
+++ b/apps/files_sharing/l10n/de.php
@@ -0,0 +1,6 @@
+<?php $TRANSLATIONS = array(
+"Size" => "Größe",
+"Modified" => "Geändert",
+"Delete all" => "Alle löschen",
+"Delete" => "Löschen"
+);
diff --git a/apps/files_sharing/l10n/el.php b/apps/files_sharing/l10n/el.php
new file mode 100644
index 00000000000..63f4c61204a
--- /dev/null
+++ b/apps/files_sharing/l10n/el.php
@@ -0,0 +1,6 @@
+<?php $TRANSLATIONS = array(
+"Size" => "Μέγεθος",
+"Modified" => "Τροποποιήθηκε",
+"Delete all" => "Διαγραφή όλων",
+"Delete" => "Διαγραφή"
+);
diff --git a/apps/files_sharing/l10n/eo.php b/apps/files_sharing/l10n/eo.php
new file mode 100644
index 00000000000..81a8dcb1525
--- /dev/null
+++ b/apps/files_sharing/l10n/eo.php
@@ -0,0 +1,3 @@
+<?php $TRANSLATIONS = array(
+"Delete" => "Forigi"
+);
diff --git a/apps/files_sharing/l10n/es.php b/apps/files_sharing/l10n/es.php
new file mode 100644
index 00000000000..85f880927d6
--- /dev/null
+++ b/apps/files_sharing/l10n/es.php
@@ -0,0 +1,6 @@
+<?php $TRANSLATIONS = array(
+"Size" => "Tamaño",
+"Modified" => "Modificado",
+"Delete all" => "Eliminar todo",
+"Delete" => "Eliminar"
+);
diff --git a/apps/files_sharing/l10n/et_EE.php b/apps/files_sharing/l10n/et_EE.php
new file mode 100644
index 00000000000..da299f4ff70
--- /dev/null
+++ b/apps/files_sharing/l10n/et_EE.php
@@ -0,0 +1,3 @@
+<?php $TRANSLATIONS = array(
+"Delete" => "Kustutamine"
+);
diff --git a/apps/files_sharing/l10n/fa.php b/apps/files_sharing/l10n/fa.php
new file mode 100644
index 00000000000..06e1862e8b3
--- /dev/null
+++ b/apps/files_sharing/l10n/fa.php
@@ -0,0 +1,6 @@
+<?php $TRANSLATIONS = array(
+"Size" => "اندازه",
+"Modified" => "تاریخ",
+"Delete all" => "حذف همه",
+"Delete" => "حذف"
+);
diff --git a/apps/files_sharing/l10n/fi_FI.php b/apps/files_sharing/l10n/fi_FI.php
new file mode 100644
index 00000000000..ca7928aeecb
--- /dev/null
+++ b/apps/files_sharing/l10n/fi_FI.php
@@ -0,0 +1,6 @@
+<?php $TRANSLATIONS = array(
+"Size" => "Koko",
+"Modified" => "Muokattu",
+"Delete all" => "Poista kaikki",
+"Delete" => "Poista"
+);
diff --git a/apps/files_sharing/l10n/fr.php b/apps/files_sharing/l10n/fr.php
new file mode 100644
index 00000000000..5a90331e422
--- /dev/null
+++ b/apps/files_sharing/l10n/fr.php
@@ -0,0 +1,6 @@
+<?php $TRANSLATIONS = array(
+"Size" => "Taille",
+"Modified" => "Modifié",
+"Delete all" => "Tout effacer",
+"Delete" => "Effacement"
+);
diff --git a/apps/files_sharing/l10n/it.php b/apps/files_sharing/l10n/it.php
new file mode 100644
index 00000000000..7f91b856783
--- /dev/null
+++ b/apps/files_sharing/l10n/it.php
@@ -0,0 +1,6 @@
+<?php $TRANSLATIONS = array(
+"Size" => "Dimensione",
+"Modified" => "Modificato",
+"Delete all" => "Elimina tutto",
+"Delete" => "Eliminazione"
+);
diff --git a/apps/files_sharing/l10n/ja_JP.php b/apps/files_sharing/l10n/ja_JP.php
new file mode 100644
index 00000000000..9fca88d0a33
--- /dev/null
+++ b/apps/files_sharing/l10n/ja_JP.php
@@ -0,0 +1,6 @@
+<?php $TRANSLATIONS = array(
+"Size" => "サイズ",
+"Modified" => "変更",
+"Delete all" => "すべて削除",
+"Delete" => "削除"
+);
diff --git a/apps/files_sharing/l10n/lt_LT.php b/apps/files_sharing/l10n/lt_LT.php
new file mode 100644
index 00000000000..d21a3c14f40
--- /dev/null
+++ b/apps/files_sharing/l10n/lt_LT.php
@@ -0,0 +1,6 @@
+<?php $TRANSLATIONS = array(
+"Size" => "Dydis",
+"Modified" => "Pakeista",
+"Delete all" => "Ištrinti viską",
+"Delete" => "Ištrinti"
+);
diff --git a/apps/files_sharing/l10n/nb_NO.php b/apps/files_sharing/l10n/nb_NO.php
new file mode 100644
index 00000000000..6102b03db74
--- /dev/null
+++ b/apps/files_sharing/l10n/nb_NO.php
@@ -0,0 +1,6 @@
+<?php $TRANSLATIONS = array(
+"Size" => "Størrelse",
+"Modified" => "Endret",
+"Delete all" => "Slett alle",
+"Delete" => "Slett"
+);
diff --git a/apps/files_sharing/l10n/pl.php b/apps/files_sharing/l10n/pl.php
new file mode 100644
index 00000000000..7f612126b93
--- /dev/null
+++ b/apps/files_sharing/l10n/pl.php
@@ -0,0 +1,6 @@
+<?php $TRANSLATIONS = array(
+"Size" => "Rozmiar",
+"Modified" => "Zmodyfikowane",
+"Delete all" => "Usuń wszystko",
+"Delete" => "Usuń"
+);
diff --git a/apps/files_sharing/l10n/sl.php b/apps/files_sharing/l10n/sl.php
new file mode 100644
index 00000000000..485ab7a85ac
--- /dev/null
+++ b/apps/files_sharing/l10n/sl.php
@@ -0,0 +1,6 @@
+<?php $TRANSLATIONS = array(
+"Size" => "Velikost",
+"Modified" => "Spremenjeno",
+"Delete all" => "Izbriši vse",
+"Delete" => "Izbris"
+);
diff --git a/apps/files_sharing/l10n/sv.php b/apps/files_sharing/l10n/sv.php
new file mode 100644
index 00000000000..5a2cda43686
--- /dev/null
+++ b/apps/files_sharing/l10n/sv.php
@@ -0,0 +1,6 @@
+<?php $TRANSLATIONS = array(
+"Size" => "Storlek",
+"Modified" => "Ändrad",
+"Delete all" => "Radera alla",
+"Delete" => "Radera"
+);
diff --git a/apps/files_sharing/l10n/th_TH.php b/apps/files_sharing/l10n/th_TH.php
new file mode 100644
index 00000000000..3f8908a91a3
--- /dev/null
+++ b/apps/files_sharing/l10n/th_TH.php
@@ -0,0 +1,6 @@
+<?php $TRANSLATIONS = array(
+"Size" => "ขนาด",
+"Modified" => "แก้ไขแล้ว",
+"Delete all" => "ลบทั้งหมด",
+"Delete" => "ลบ"
+);
diff --git a/apps/files_sharing/lib/share/file.php b/apps/files_sharing/lib/share/file.php
new file mode 100644
index 00000000000..ae6315600f8
--- /dev/null
+++ b/apps/files_sharing/lib/share/file.php
@@ -0,0 +1,91 @@
+<?php
+/**
+* ownCloud
+*
+* @author Michael Gapczynski
+* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
+
+ const FORMAT_SHARED_STORAGE = 0;
+ const FORMAT_FILE_APP = 1;
+ const FORMAT_FILE_APP_ROOT = 2;
+ const FORMAT_OPENDIR = 3;
+
+ public function isValidSource($item, $uid) {
+ if (OC_Filesystem::file_exists($item)) {
+ return true;
+ }
+ return false;
+ }
+
+ public function getFilePath($item, $uid) {
+ return $item;
+ }
+
+ public function generateTarget($item, $uid, $exclude = null) {
+ // TODO Make sure target path doesn't exist already
+ return $item;
+ }
+
+ public function formatItems($items, $format, $parameters = null) {
+ if ($format == self::FORMAT_SHARED_STORAGE) {
+ // Only 1 item should come through for this format call
+ return array('path' => $items[key($items)]['file_source'], 'permissions' => $items[key($items)]['permissions']);
+ } else if ($format == self::FORMAT_FILE_APP) {
+ $files = array();
+ foreach ($items as $item) {
+ $file = array();
+ $file['path'] = $item['file_target'];
+ $file['name'] = basename($item['file_target']);
+ $file['ctime'] = $item['ctime'];
+ $file['mtime'] = $item['mtime'];
+ $file['mimetype'] = $item['mimetype'];
+ $file['size'] = $item['size'];
+ $file['encrypted'] = $item['encrypted'];
+ $file['versioned'] = $item['versioned'];
+ $file['directory'] = $parameters['folder'];
+ $file['type'] = ($item['mimetype'] == 'httpd/unix-directory') ? 'dir' : 'file';
+ $file['permissions'] = $item['permissions'];
+ if ($file['type'] == 'file') {
+ // Remove Create permission if type is file
+ $file['permissions'] &= ~OCP\Share::PERMISSION_CREATE;
+ }
+ $files[] = $file;
+ }
+ return $files;
+ } else if ($format == self::FORMAT_FILE_APP_ROOT) {
+ $mtime = 0;
+ $size = 0;
+ foreach ($items as $item) {
+ if ($item['mtime'] > $mtime) {
+ $mtime = $item['mtime'];
+ }
+ $size += $item['size'];
+ }
+ return array(0 => array('name' => 'Shared', 'mtime' => $mtime, 'mimetype' => 'httpd/unix-directory', 'size' => $size, 'writable' => false, 'type' => 'dir', 'directory' => '', 'permissions' => OCP\Share::PERMISSION_READ));
+ } else if ($format == self::FORMAT_OPENDIR) {
+ $files = array();
+ foreach ($items as $item) {
+ $files[] = basename($item['file_target']);
+ }
+ return $files;
+ }
+ return array();
+ }
+
+} \ No newline at end of file
diff --git a/apps/files_sharing/lib/share/folder.php b/apps/files_sharing/lib/share/folder.php
new file mode 100644
index 00000000000..b6db96614fd
--- /dev/null
+++ b/apps/files_sharing/lib/share/folder.php
@@ -0,0 +1,61 @@
+<?php
+/**
+* ownCloud
+*
+* @author Michael Gapczynski
+* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+class OC_Share_Backend_Folder extends OC_Share_Backend_File {
+
+ public function formatItems($items, $format, $parameters = null) {
+ if ($format == self::FORMAT_SHARED_STORAGE) {
+ // Only 1 item should come through for this format call
+ return array('path' => $items[key($items)]['file_source'], 'permissions' => $items[key($items)]['permissions']);
+ } else if ($format == self::FORMAT_FILE_APP && isset($parameters['folder'])) {
+ // Only 1 item should come through for this format call
+ $folder = $items[key($items)];
+ if (isset($parameters['mimetype_filter'])) {
+ $mimetype_filter = $parameters['mimetype_filter'];
+ } else {
+ $mimetype_filter = '';
+ }
+ $path = $folder['file_source'].substr($parameters['folder'], 7 + strlen($folder['file_target']));
+ $files = OC_FileCache::getFolderContent($path, '', $mimetype_filter);
+ foreach ($files as &$file) {
+ $file['directory'] = $parameters['folder'];
+ $file['type'] = ($file['mimetype'] == 'httpd/unix-directory') ? 'dir' : 'file';
+ $file['permissions'] = $folder['permissions'];
+ if ($file['type'] == 'file') {
+ // Remove Create permission if type is file
+ $file['permissions'] &= ~OCP\Share::PERMISSION_CREATE;
+ }
+ }
+ return $files;
+ }
+ return array();
+ }
+
+ public function getChildren($itemSource) {
+ $files = OC_FileCache::getFolderContent($itemSource);
+ $sources = array();
+ foreach ($files as $file) {
+ $sources[] = $file['path'];
+ }
+ return $sources;
+ }
+
+} \ No newline at end of file
diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php
new file mode 100644
index 00000000000..582c9c66172
--- /dev/null
+++ b/apps/files_sharing/lib/sharedstorage.php
@@ -0,0 +1,427 @@
+<?php
+/**
+ * ownCloud
+ *
+ * @author Michael Gapczynski
+ * @copyright 2011 Michael Gapczynski mtgap@owncloud.com
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+/**
+ * Convert target path to source path and pass the function call to the correct storage provider
+ */
+class OC_Filestorage_Shared extends OC_Filestorage_Common {
+
+ private $sharedFolder;
+ private $files = array();
+
+ public function __construct($arguments) {
+ $this->sharedFolder = $arguments['sharedFolder'];
+ }
+
+ /**
+ * @brief Get the source file path and the permissions granted for a shared file
+ * @param string Shared target file path
+ * @return Returns array with the keys path and permissions or false if not found
+ */
+ private function getFile($target) {
+ $target = '/'.$target;
+ $target = rtrim($target, '/');
+ if (isset($this->files[$target])) {
+ return $this->files[$target];
+ } else {
+ $pos = strpos($target, '/', 1);
+ // Get shared folder name
+ if ($pos !== false) {
+ $folder = substr($target, 0, $pos);
+ if (isset($this->files[$folder])) {
+ $file = $this->files[$folder];
+ } else {
+ $file = OCP\Share::getItemSharedWith('folder', $folder, OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
+ }
+ if ($file) {
+ $this->files[$target]['path'] = $file['path'].substr($target, strlen($folder));
+ $this->files[$target]['permissions'] = $file['permissions'];
+ return $this->files[$target];
+ }
+ } else {
+ $file = OCP\Share::getItemSharedWith('file', $target, OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
+ if ($file) {
+ $this->files[$target] = $file;
+ return $this->files[$target];
+ }
+ }
+ OCP\Util::writeLog('files_sharing', 'File source not found for: '.$target, OCP\Util::ERROR);
+ return false;
+ }
+ }
+
+ /**
+ * @brief Get the source file path for a shared file
+ * @param string Shared target file path
+ * @return Returns source file path or false if not found
+ */
+ private function getSourcePath($target) {
+ $file = $this->getFile($target);
+ if (isset($file['path'])) {
+ return $file['path'];
+ }
+ return false;
+ }
+
+ /**
+ * @brief Get the permissions granted for a shared file
+ * @param string Shared target file path
+ * @return Returns CRUDS permissions granted or false if not found
+ */
+ private function getPermissions($target) {
+ $file = $this->getFile($target);
+ if (isset($file['permissions'])) {
+ return $file['permissions'];
+ }
+ return false;
+ }
+
+ /**
+ * @brief Get the internal path to pass to the storage filesystem call
+ * @param string Source file path
+ * @return Source file path with mount point stripped out
+ */
+ private function getInternalPath($path) {
+ $mountPoint = OC_Filesystem::getMountPoint($path);
+ $internalPath = substr($path, strlen($mountPoint));
+ return $internalPath;
+ }
+
+ public function mkdir($path) {
+ if ($path == '' || $path == '/' || !$this->isCreatable(dirname($path))) {
+ return false;
+ } else if ($source = $this->getSourcePath($path)) {
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->mkdir($this->getInternalPath($source));
+ }
+ return false;
+ }
+
+ public function rmdir($path) {
+ if (($source = $this->getSourcePath($path)) && $this->isDeletable($path)) {
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->rmdir($this->getInternalPath($source));
+ }
+ return false;
+ }
+
+ public function opendir($path) {
+ if ($path == '' || $path == '/') {
+ $files = OCP\Share::getItemsSharedWith('file', OC_Share_Backend_Folder::FORMAT_OPENDIR);
+ OC_FakeDirStream::$dirs['shared'] = $files;
+ return opendir('fakedir://shared');
+ } else if ($source = $this->getSourcePath($path)) {
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->opendir($this->getInternalPath($source));
+ }
+ return false;
+ }
+
+ public function is_dir($path) {
+ if ($path == '' || $path == '/') {
+ return true;
+ } else if ($source = $this->getSourcePath($path)) {
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->is_dir($this->getInternalPath($source));
+ }
+ return false;
+ }
+
+ public function is_file($path) {
+ if ($source = $this->getSourcePath($path)) {
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->is_file($this->getInternalPath($source));
+ }
+ return false;
+ }
+
+ public function stat($path) {
+ if ($path == '' || $path == '/') {
+ $stat['size'] = $this->filesize($path);
+ $stat['mtime'] = $this->filemtime($path);
+ $stat['ctime'] = $this->filectime($path);
+ return $stat;
+ } else if ($source = $this->getSourcePath($path)) {
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->stat($this->getInternalPath($source));
+ }
+ return false;
+ }
+
+ public function filetype($path) {
+ if ($path == '' || $path == '/') {
+ return 'dir';
+ } else if ($source = $this->getSourcePath($path)) {
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->filetype($this->getInternalPath($source));
+ }
+ return false;
+ }
+
+ public function filesize($path) {
+ if ($path == '' || $path == '/' || $this->is_dir($path)) {
+ return 0;
+ } else if ($source = $this->getSourcePath($path)) {
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->filesize($this->getInternalPath($source));
+ }
+ return false;
+ }
+
+ public function isCreatable($path) {
+ if ($path == '') {
+ return false;
+ }
+ return ($this->getPermissions($path) & OCP\Share::PERMISSION_CREATE);
+ }
+
+ public function isReadable($path) {
+ return $this->file_exists($path);
+ }
+
+ public function isUpdatable($path) {
+ if ($path == '') {
+ return false;
+ }
+ return ($this->getPermissions($path) & OCP\Share::PERMISSION_UPDATE);
+ }
+
+ public function isDeletable($path) {
+ if ($path == '') {
+ return false;
+ }
+ return ($this->getPermissions($path) & OCP\Share::PERMISSION_DELETE);
+ }
+
+ public function isSharable($path) {
+ if ($path == '') {
+ return false;
+ }
+ return ($this->getPermissions($path) & OCP\Share::PERMISSION_SHARE);
+ }
+
+ public function file_exists($path) {
+ if ($path == '' || $path == '/') {
+ return true;
+ } else if ($source = $this->getSourcePath($path)) {
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->file_exists($this->getInternalPath($source));
+ }
+ return false;
+ }
+
+ public function filectime($path) {
+ if ($path == '' || $path == '/') {
+ $ctime = 0;
+ if ($dh = $this->opendir($path)) {
+ while (($filename = readdir($dh)) !== false) {
+ $tempctime = $this->filectime($filename);
+ if ($tempctime < $ctime) {
+ $ctime = $tempctime;
+ }
+ }
+ }
+ return $ctime;
+ } else {
+ $source = $this->getSourcePath($path);
+ if ($source) {
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->filectime($this->getInternalPath($source));
+ }
+ }
+ }
+
+ public function filemtime($path) {
+ if ($path == '' || $path == '/') {
+ $mtime = 0;
+ if ($dh = $this->opendir($path)) {
+ while (($filename = readdir($dh)) !== false) {
+ $tempmtime = $this->filemtime($filename);
+ if ($tempmtime > $mtime) {
+ $mtime = $tempmtime;
+ }
+ }
+ }
+ return $mtime;
+ } else {
+ $source = $this->getSourcePath($path);
+ if ($source) {
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->filemtime($this->getInternalPath($source));
+ }
+ }
+ }
+
+ public function file_get_contents($path) {
+ $source = $this->getSourcePath($path);
+ if ($source) {
+ $info = array(
+ 'target' => $this->sharedFolder.$path,
+ 'source' => $source,
+ );
+ OCP\Util::emitHook('OC_Filestorage_Shared', 'file_get_contents', $info);
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->file_get_contents($this->getInternalPath($source));
+ }
+ }
+
+ public function file_put_contents($path, $data) {
+ if ($source = $this->getSourcePath($path)) {
+ // Check if permission is granted
+ if (($this->file_exists($path) && !$this->isUpdatable($path)) || ($this->is_dir($path) && !$this->isCreatable($path))) {
+ return false;
+ }
+ $info = array(
+ 'target' => $this->sharedFolder.$path,
+ 'source' => $source,
+ );
+ OCP\Util::emitHook('OC_Filestorage_Shared', 'file_put_contents', $info);
+ $storage = OC_Filesystem::getStorage($source);
+ $result = $storage->file_put_contents($this->getInternalPath($source), $data);
+ return $result;
+ }
+ return false;
+ }
+
+ public function unlink($path) {
+ // Delete the file if DELETE permission is granted
+ if (($source = $this->getSourcePath($path)) && $this->isDeletable($path)) {
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->unlink($this->getInternalPath($source));
+ }
+ return false;
+ }
+
+ public function rename($path1, $path2) {
+ if ($oldSource = $this->getSourcePath($path1)) {
+ $root1 = substr($path1, 0, strpos($path1, '/'));
+ $root2 = substr($path2, 0, strpos($path2, '/'));
+ // Moving/renaming is only allowed within the same shared folder
+ if ($root1 == $root2) {
+ $storage = OC_Filesystem::getStorage($oldSource);
+ $newSource = substr($oldSource, 0, strpos($oldSource, $root1)).$path2;
+ if (dirname($path1) == dirname($path2)) {
+ // Rename the file if UPDATE permission is granted
+ if ($this->isUpdatable($path1)) {
+ return $storage->rename($this->getInternalPath($oldSource), $this->getInternalPath($newSource));
+ }
+ // Move the file if DELETE and CREATE permissions are granted
+ } else if ($this->isDeletable($path1) && $this->isCreatable(dirname($path2))) {
+ return $storage->rename($this->getInternalPath($oldSource), $this->getInternalPath($newSource));
+ }
+ }
+ }
+ return false;
+ }
+
+ public function copy($path1, $path2) {
+ // Copy the file if CREATE permission is granted
+ if (($source = $this->getSourcePath($path1)) && $this->isCreatable(dirname($path2))) {
+ $source = $this->fopen($path1, 'r');
+ $target = $this->fopen($path2, 'w');
+ return OC_Helper::streamCopy($source, $target);
+ }
+ return true;
+ }
+
+ public function fopen($path, $mode) {
+ if ($source = $this->getSourcePath($path)) {
+ switch ($mode) {
+ case 'r+':
+ case 'rb+':
+ case 'w+':
+ case 'wb+':
+ case 'x+':
+ case 'xb+':
+ case 'a+':
+ case 'ab+':
+ case 'w':
+ case 'wb':
+ case 'x':
+ case 'xb':
+ case 'a':
+ case 'ab':
+ if (!$this->isUpdatable($path)) {
+ return false;
+ }
+ }
+ $info = array(
+ 'target' => $this->sharedFolder.$path,
+ 'source' => $source,
+ 'mode' => $mode,
+ );
+ OCP\Util::emitHook('OC_Filestorage_Shared', 'fopen', $info);
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->fopen($this->getInternalPath($source), $mode);
+ }
+ return false;
+ }
+
+ public function getMimeType($path) {
+ if ($path == '' || $path == '/') {
+ return 'httpd/unix-directory';
+ }
+ if ($source = $this->getSourcePath($path)) {
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->getMimeType($this->getInternalPath($source));
+ }
+ return false;
+ }
+
+ public function free_space($path) {
+ $source = $this->getSourcePath($path);
+ if ($source) {
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->free_space($this->getInternalPath($source));
+ }
+ }
+
+ public function getLocalFile($path) {
+ if ($source = $this->getSourcePath($path)) {
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->getLocalFile($this->getInternalPath($source));
+ }
+ return false;
+ }
+ public function touch($path, $mtime = null) {
+ if ($source = $this->getSourcePath($path)) {
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->touch($this->getInternalPath($source), $mtime);
+ }
+ return false;
+ }
+
+ public static function setup($options) {
+ $user_dir = $options['user_dir'];
+ OC_Filesystem::mount('OC_Filestorage_Shared', array('sharedFolder' => '/Shared'), $user_dir.'/Shared/');
+ }
+
+ /**
+ * check if a file or folder has been updated since $time
+ * @param int $time
+ * @return bool
+ */
+ public function hasUpdated($path,$time){
+ //TODO
+ return false;
+ }
+}
diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php
deleted file mode 100644
index fe312ad9ed7..00000000000
--- a/apps/files_sharing/lib_share.php
+++ /dev/null
@@ -1,523 +0,0 @@
-<?php
-/**
- * ownCloud
- *
- * @author Michael Gapczynski
- * @copyright 2011 Michael Gapczynski GapczynskiM@gmail.com
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-/**
- * This class manages shared items within the database.
- */
-class OC_Share {
-
- const WRITE = 1;
- const DELETE = 2;
- const UNSHARED = -1;
- const PUBLICLINK = "public";
-
- private $token;
-
- /**
- * Share an item, adds an entry into the database
- * @param $source The source location of the item
- * @param $uid_shared_with The user or group to share the item with
- * @param $permissions The permissions, use the constants WRITE and DELETE
- */
- public function __construct($source, $uid_shared_with, $permissions) {
- $uid_owner = OCP\USER::getUser();
- $query = OCP\DB::prepare('INSERT INTO `*PREFIX*sharing` VALUES(?,?,?,?,?)');
- // Check if this is a reshare and use the original source
- if ($result = OC_Share::getSource($source)) {
- $source = $result;
- }
- if ($uid_shared_with == self::PUBLICLINK) {
- $token = sha1("$uid_shared_with-$source");
- $query->execute(array($uid_owner, self::PUBLICLINK, $source, $token, $permissions));
- $this->token = $token;
- } else {
- if (OC_Group::groupExists($uid_shared_with)) {
- $gid = $uid_shared_with;
- $uid_shared_with = OC_Group::usersInGroup($gid);
- // Remove the owner from the list of users in the group
- $uid_shared_with = array_diff($uid_shared_with, array($uid_owner));
- } else if (OCP\User::userExists($uid_shared_with)) {
- if(OCP\Config::getAppValue('files_sharing', 'allowSharingWithEveryone', 'no') == 'yes') {
- $gid = null;
- $uid_shared_with = array($uid_shared_with);
- } else {
- $userGroups = OC_Group::getUserGroups($uid_owner);
- // Check if the user is in one of the owner's groups
- foreach ($userGroups as $group) {
- if ($inGroup = OC_Group::inGroup($uid_shared_with, $group)) {
- $gid = null;
- $uid_shared_with = array($uid_shared_with);
- break;
- }
- }
- if (!$inGroup) {
- throw new Exception("You can't share with ".$uid_shared_with);
- }
- }
- } else {
- throw new Exception($uid_shared_with." is not a user");
- }
- foreach ($uid_shared_with as $uid) {
- // Check if this item is already shared with the user
- $checkSource = OCP\DB::prepare('SELECT `source` FROM `*PREFIX*sharing` WHERE `source` = ? AND `uid_shared_with` '.self::getUsersAndGroups($uid, false));
- $resultCheckSource = $checkSource->execute(array($source))->fetchAll();
- // TODO Check if the source is inside a folder
- if (count($resultCheckSource) > 0) {
- if (!isset($gid)) {
- throw new Exception("This item is already shared with ".$uid);
- } else {
- // Skip this user if sharing with a group
- continue;
- }
- }
- // Check if the target already exists for the user, if it does append a number to the name
- $sharedFolder = '/'.$uid.'/files/Shared';
- $target = $sharedFolder."/".basename($source);
- $checkTarget = OCP\DB::prepare('SELECT `source` FROM `*PREFIX*sharing` WHERE `target` = ? AND `uid_shared_with` '.self::getUsersAndGroups($uid, false),1);
- $result = $checkTarget->execute(array($target))->fetchAll();
- if (count($result) > 0) {
- if ($pos = strrpos($target, ".")) {
- $name = substr($target, 0, $pos);
- $ext = substr($target, $pos);
- } else {
- $name = $target;
- $ext = "";
- }
- $counter = 1;
- while (count($result) > 0) {
- $target = $name."_".$counter.$ext;
- $result = $checkTarget->execute(array($target))->fetchAll();
- $counter++;
- }
- }
- // Update mtime of shared folder to invoke a file cache rescan
- $rootView=new OC_FilesystemView('/');
- if (!$rootView->is_dir($sharedFolder)) {
- if (!$rootView->is_dir('/'.$uid.'/files')) {
- OC_Util::tearDownFS();
- OC_Util::setupFS($uid);
- OC_Util::tearDownFS();
- }
- $rootView->mkdir($sharedFolder);
- }
- $rootView->touch($sharedFolder);
- if (isset($gid)) {
- $uid = $uid."@".$gid;
- }
- $query->execute(array($uid_owner, $uid, $source, $target, $permissions));
- }
- }
- }
-
- /**
- * Remove any duplicate or trailing '/' from the path
- * @return A clean path
- */
- private static function cleanPath($path) {
- $path = rtrim($path, "/");
- return preg_replace('{(/)\1+}', "/", $path);
- }
-
- /**
- * Generate a string to be used for searching for uid_shared_with that handles both users and groups
- * @param $uid (Optional) The uid to get the user groups for, a gid to get the users in a group, or if not set the current user
- * @return An IN operator as a string
- */
- private static function getUsersAndGroups($uid = null, $includePrivateLinks = true) {
- $in = " IN(";
- if (isset($uid) && OC_Group::groupExists($uid)) {
- $users = OC_Group::usersInGroup($uid);
- foreach ($users as $user) {
- // Add a comma only if the the current element isn't the last
- if ($user !== end($users)) {
- $in .= "'".$user."@".$uid."', ";
- } else {
- $in .= "'".$user."@".$uid."'";
- }
- }
- } else if (isset($uid)) {
- // TODO Check if this is necessary, only constructor needs it as IN. It would be better for other queries to just return =$uid
- $in .= "'".$uid."'";
- $groups = OC_Group::getUserGroups($uid);
- foreach ($groups as $group) {
- $in .= ", '".$uid."@".$group."'";
- }
- } else {
- $uid = OCP\USER::getUser();
- $in .= "'".$uid."'";
- $groups = OC_Group::getUserGroups($uid);
- foreach ($groups as $group) {
- $in .= ", '".$uid."@".$group."'";
- }
- }
- if ($includePrivateLinks) {
- $in .= ", '".self::PUBLICLINK."'";
- }
- $in .= ")";
- return $in;
- }
-
- private static function updateFolder($uid_shared_with) {
- if ($uid_shared_with != self::PUBLICLINK) {
- if (OC_Group::groupExists($uid_shared_with)) {
- $uid_shared_with = OC_Group::usersInGroup($uid_shared_with);
- // Remove the owner from the list of users in the group
- $uid_shared_with = array_diff($uid_shared_with, array(OCP\USER::getUser()));
- } else {
- $pos = strrpos($uid_shared_with, '@');
- if ($pos !== false && OC_Group::groupExists(substr($uid_shared_with, $pos + 1))) {
- $uid_shared_with = array(substr($uid_shared_with, 0, $pos));
- } else {
- $uid_shared_with = array($uid_shared_with);
- }
- }
- foreach ($uid_shared_with as $uid) {
- $sharedFolder = $uid.'/files/Shared';
- // Update mtime of shared folder to invoke a file cache rescan
- $rootView = new OC_FilesystemView('/');
- $rootView->touch($sharedFolder);
- }
- }
- }
-
- /**
- * Create a new entry in the database for a file inside a shared folder
- *
- * $oldTarget and $newTarget may be the same value. $oldTarget exists in case the file is being moved outside of the folder
- *
- * @param $oldTarget The current target location
- * @param $newTarget The new target location
- */
- public static function pullOutOfFolder($oldTarget, $newTarget) {
- $folders = self::getParentFolders($oldTarget);
- $source = $folders['source'].substr($oldTarget, strlen($folders['target']));
- $item = self::getItem($folders['target']);
- $query = OCP\DB::prepare('INSERT INTO `*PREFIX*sharing` VALUES(?,?,?,?,?)');
- $query->execute(array($item[0]['uid_owner'], OCP\USER::getUser(), $source, $newTarget, $item[0]['permissions']));
- }
-
- /**
- * Get the item with the specified target location
- * @param $target The target location of the item
- * @return An array with the item
- */
- public static function getItem($target) {
- $target = self::cleanPath($target);
- $query = OCP\DB::prepare('SELECT `uid_owner`, `source`, `permissions` FROM `*PREFIX*sharing` WHERE `target` = ? AND `uid_shared_with` = ?',1);
- return $query->execute(array($target, OCP\USER::getUser()))->fetchAll();
- }
-
- /**
- * Get the item with the specified source location
- * @param $source The source location of the item
- * @return An array with the users and permissions the item is shared with
- */
- public static function getMySharedItem($source) {
- $source = self::cleanPath($source);
- $query = OCP\DB::prepare('SELECT `uid_shared_with`, `permissions` FROM `*PREFIX*sharing` WHERE `source` = ? AND `uid_owner` = ?');
- $result = $query->execute(array($source, OCP\USER::getUser()))->fetchAll();
- if (count($result) > 0) {
- return $result;
- } else if ($originalSource = self::getSource($source)) {
- return $query->execute(array($originalSource, OCP\USER::getUser()))->fetchAll();
- } else {
- return false;
- }
- }
-
- /**
- * Get all items the current user is sharing
- * @return An array with all items the user is sharing
- */
- public static function getMySharedItems() {
- $query = OCP\DB::prepare('SELECT `uid_shared_with`, `source`, `permissions` FROM `*PREFIX*sharing` WHERE `uid_owner` = ?');
- return $query->execute(array(OCP\USER::getUser()))->fetchAll();
- }
-
- /**
- * Get the items within a shared folder that have their own entry for the purpose of name, location, or permissions that differ from the folder itself
- *
- * Works for both target and source folders. Can be used for getting all items shared with you e.g. pass '/MTGap/files'
- *
- * @param $folder The folder of the items to look for
- * @return An array with all items in the database that are in the folder
- */
- public static function getItemsInFolder($folder) {
- $folder = self::cleanPath($folder);
- // Append '/' in order to filter out the folder itself if not already there
- if (substr($folder, -1) !== "/") {
- $folder .= "/";
- }
- $length = strlen($folder);
- $query = OCP\DB::prepare('SELECT `uid_owner`, `source`, `target`, `permissions` FROM `*PREFIX*sharing` WHERE SUBSTR(`source`, 1, ?) = ? OR SUBSTR(`target`, 1, ?) = ? AND `uid_shared_with` '.self::getUsersAndGroups());
- return $query->execute(array($length, $folder, $length, $folder))->fetchAll();
- }
-
- /**
- * Get the source and target parent folders of the specified target location
- * @param $target The target location of the item
- * @return An array with the keys 'source' and 'target' with the values of the source and target parent folders
- */
- public static function getParentFolders($target) {
- $target = self::cleanPath($target);
- $query = OCP\DB::prepare('SELECT `source` FROM `*PREFIX*sharing` WHERE `target` = ? AND `uid_shared_with` '.self::getUsersAndGroups(),1);
- // Prevent searching for user directory e.g. '/MTGap/files'
- $userDirectory = substr($target, 0, strpos($target, "files") + 5);
- $target = dirname($target);
- $result = array();
- while ($target != "" && $target != "/" && $target != "." && $target != $userDirectory && $target != "\\") {
- // Check if the parent directory of this target location is shared
- $result = $query->execute(array($target))->fetchAll();
- if (count($result) > 0) {
- break;
- }
- $target = dirname($target);
- }
- if (count($result) > 0) {
- // Return both the source folder and the target folder
- return array("source" => $result[0]['source'], "target" => $target);
- } else {
- return false;
- }
- }
-
- /**
- * Get the source location of the item at the specified target location
- * @param $target The target location of the item
- * @return Source location or false if target location is not valid
- */
- public static function getSource($target) {
- $target = self::cleanPath($target);
- $query = OCP\DB::prepare('SELECT `source` FROM `*PREFIX*sharing` WHERE `target` = ? AND `uid_shared_with` '.self::getUsersAndGroups(),1);
- $result = $query->execute(array($target))->fetchAll();
- if (count($result) > 0) {
- return $result[0]['source'];
- } else {
- $folders = self::getParentFolders($target);
- if ($folders == true) {
- return $folders['source'].substr($target, strlen($folders['target']));
- } else {
- return false;
- }
- }
-}
-
- public static function getTarget($source) {
- $source = self::cleanPath($source);
- $query = OCP\DB::prepare('SELECT `target` FROM `*PREFIX*sharing` WHERE `source` = ? AND `uid_owner` = ',1);
- $result = $query->execute(array($source, OCP\USER::getUser()))->fetchAll();
- if (count($result) > 0) {
- return $result[0]['target'];
- } else {
- // TODO Check in folders
- return false;
- }
- }
-
- /**
- * Get the user's permissions for the item at the specified target location
- * @param $target The target location of the item
- * @return The permissions, use bitwise operators to check against the constants WRITE and DELETE
- */
- public static function getPermissions($target) {
- $target = self::cleanPath($target);
- $query = OCP\DB::prepare('SELECT `permissions` FROM `*PREFIX*sharing` WHERE `target` = ? AND `uid_shared_with` '.self::getUsersAndGroups(),1);
- $result = $query->execute(array($target))->fetchAll();
- if (count($result) > 0) {
- return $result[0]['permissions'];
- } else {
- $folders = self::getParentFolders($target);
- if ($folders == true) {
- $result = $query->execute(array($folders['target']))->fetchAll();
- if (count($result) > 0) {
- return $result[0]['permissions'];
- }
- } else {
- OCP\Util::writeLog('files_sharing',"Not existing parent folder : ".$target,OCP\Util::ERROR);
- return false;
- }
- }
- }
-
- /**
- * Get the token for a public link
- * @return The token of the public link, a sha1 hash
- */
- public function getToken() {
- return $this->token;
- }
-
- /**
- * Get the token for a public link
- * @param $source The source location of the item
- * @return The token of the public link, a sha1 hash
- */
- public static function getTokenFromSource($source) {
- $query = OCP\DB::prepare('SELECT `target` FROM `*PREFIX*sharing` WHERE `source` = ? AND `uid_shared_with` = ? AND `uid_owner` = ?',1);
- $result = $query->execute(array($source, self::PUBLICLINK, OCP\USER::getUser()))->fetchAll();
- if (count($result) > 0) {
- return $result[0]['target'];
- } else {
- return false;
- }
- }
-
- /**
- * Set the target location to a new value
- *
- * You must use the pullOutOfFolder() function to change the target location of a file inside a shared folder if the target location differs from the folder
- *
- * @param $oldTarget The current target location
- * @param $newTarget The new target location
- */
- public static function setTarget($oldTarget, $newTarget) {
- $oldTarget = self::cleanPath($oldTarget);
- $newTarget = self::cleanPath($newTarget);
- $query = OCP\DB::prepare('UPDATE `*PREFIX*sharing` SET `target` = `REPLACE(`target`, ?, ?) WHERE `uid_shared_with` '.self::getUsersAndGroups());
- $query->execute(array($oldTarget, $newTarget));
- }
-
- /**
- * Change the permissions for the specified item and user
- *
- * You must construct a new shared item to change the permissions of a file inside a shared folder if the permissions differ from the folder
- *
- * @param $source The source location of the item
- * @param $uid_shared_with The user to change the permissions for
- * @param $permissions The permissions, use the constants WRITE and DELETE
- */
- public static function setPermissions($source, $uid_shared_with, $permissions) {
- $source = self::cleanPath($source);
- $query = OCP\DB::prepare('UPDATE `*PREFIX*sharing` SET `permissions` = ? WHERE SUBSTR(`source`, 1, ?) = ? AND `uid_owner` = ? AND `uid_shared_with` '.self::getUsersAndGroups($uid_shared_with));
- $query->execute(array($permissions, strlen($source), $source, OCP\USER::getUser()));
- }
-
- /**
- * Unshare the item, removes it from all specified users
- *
- * You must use the pullOutOfFolder() function to unshare a file inside a shared folder and set $newTarget to nothing
- *
- * @param $source The source location of the item
- * @param $uid_shared_with Array of users to unshare the item from
- */
- public static function unshare($source, $uid_shared_with) {
- $source = self::cleanPath($source);
- $uid_owner = OCP\USER::getUser();
- $query = OCP\DB::prepare('DELETE FROM `*PREFIX*sharing` WHERE SUBSTR(`source`, 1, ?) = ? AND `uid_owner` = ? AND `uid_shared_with` '.self::getUsersAndGroups($uid_shared_with, false));
- $query->execute(array(strlen($source), $source, $uid_owner));
- self::updateFolder($uid_shared_with);
- }
-
- /**
- * Unshare the item from the current user, removes it only from the database and doesn't touch the source file
- *
- * You must use the pullOutOfFolder() function before you call unshareFromMySelf() and set the delete parameter to false to unshare from self a file inside a shared folder
- *
- * @param $target The target location of the item
- * @param $delete (Optional) If true delete the entry from the database, if false the permission is set to UNSHARED
- */
- public static function unshareFromMySelf($target, $delete = true) {
- $target = self::cleanPath($target);
- if ($delete) {
- $query = OCP\DB::prepare('DELETE FROM `*PREFIX*sharing` WHERE SUBSTR(`target`, 1, ?) = ? AND `uid_shared_with` '.self::getUsersAndGroups());
- $query->execute(array(strlen($target), $target));
- } else {
- $query = OCP\DB::prepare('UPDATE `*PREFIX*sharing` SET `permissions` = ? WHERE SUBSTR(`target`, 1, ?) = ? AND `uid_shared_with` '.self::getUsersAndGroups());
- $query->execute(array(self::UNSHARED, strlen($target), $target));
- }
- }
-
- /**
- * Remove the item from the database, the owner deleted the file
- * @param $arguments Array of arguments passed from OC_Hook
- */
- public static function deleteItem($arguments) {
- $source = "/".OCP\USER::getUser()."/files".self::cleanPath($arguments['path']);
- $result = self::getMySharedItem($source);
- if (is_array($result)) {
- foreach ($result as $item) {
- self::updateFolder($item['uid_shared_with']);
- }
- }
- $query = OCP\DB::prepare('DELETE FROM `*PREFIX*sharing` WHERE SUBSTR(`source`, 1, ?) = ? AND `uid_owner` = ?');
- $query->execute(array(strlen($source), $source, OCP\USER::getUser()));
- }
-
- /**
- * Rename the item in the database, the owner renamed the file
- * @param $arguments Array of arguments passed from OC_Hook
- */
- public static function renameItem($arguments) {
- $oldSource = "/".OCP\USER::getUser()."/files".self::cleanPath($arguments['oldpath']);
- $newSource = "/".OCP\USER::getUser()."/files".self::cleanPath($arguments['newpath']);
- $query = OCP\DB::prepare('UPDATE `*PREFIX*sharing` SET `source` = REPLACE(`source`, ?, ?) WHERE `uid_owner` = ?');
- $query->execute(array($oldSource, $newSource, OCP\USER::getUser()));
- }
-
- public static function updateItem($arguments) {
- $source = "/".OCP\USER::getUser()."/files".self::cleanPath($arguments['path']);
- $result = self::getMySharedItem($source);
- if (is_array($result)) {
- foreach ($result as $item) {
- self::updateFolder($item['uid_shared_with']);
- }
- }
- }
-
- public static function removeUser($arguments) {
- $query = OCP\DB::prepare('SELECT `uid_shared_with` FROM `*PREFIX*sharing` WHERE `uid_owner` = ?');
- $result = $query->execute(array($arguments['uid']))->fetchAll();
- if (is_array($result)) {
- $result = array_unique($result);
- foreach ($result as $item) {
- self::updateFolder($item['uid_shared_with']);
- }
- $query = OCP\DB::prepare('DELETE FROM `*PREFIX*sharing` WHERE `uid_owner` = ? OR `uid_shared_with` '.self::getUsersAndGroups($arguments['uid']));
- $query->execute(array($arguments['uid']));
- }
- }
-
- public static function addToGroupShare($arguments) {
- $length = -strlen($arguments['gid']) - 1;
- $query = OCP\DB::prepare('SELECT `uid_owner`, `source`, `permissions` FROM `*PREFIX*sharing` WHERE SUBSTR(`uid_shared_with`, '.$length.') = ?');
- $gid = '@'.$arguments['gid'];
- $result = $query->execute(array($gid))->fetchAll();
- if (count($result) > 0) {
- $lastSource = '';
- for ($i = 0; $i < count($result) - 1; $i++) {
- if ($result[$i]['source'] != $lastSource) {
- new OC_Share($result[$i]['source'], $arguments['gid'], $result[$i]['permissions']);
- $lastSource = $result[$i]['source'];
- }
- }
- }
- }
-
- public static function removeFromGroupShare($arguments) {
- $query = OCP\DB::prepare('DELETE FROM `*PREFIX*sharing` WHERE `uid_shared_with` = ?');
- $query->execute(array($arguments['uid'].'@'.$arguments['gid']));
- self::updateFolder($arguments['uid']);
- }
-
-}
-
-?>
diff --git a/apps/files_sharing/list.php b/apps/files_sharing/list.php
deleted file mode 100644
index 2fd24840d36..00000000000
--- a/apps/files_sharing/list.php
+++ /dev/null
@@ -1,37 +0,0 @@
-<?php
-/**
- * ownCloud
- *
- * @author Michael Gapczynski
- * @copyright 2011 Michael Gapczynski GapczynskiM@gmail.com
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-
-require_once('lib_share.php');
-
-OCP\User::checkLoggedIn();
-OCP\App::checkAppEnabled('files_sharing');
-
-OCP\App::setActiveNavigationEntry("files_sharing_list");
-
-OCP\Util::addscript("files_sharing", "list");
-
-$tmpl = new OCP\Template("files_sharing", "list", "user");
-$tmpl->assign("shared_items", OC_Share::getMySharedItems());
-$tmpl->printPage();
-
-?>
diff --git a/apps/files_sharing/settings.php b/apps/files_sharing/settings.php
deleted file mode 100644
index fcae7e0370f..00000000000
--- a/apps/files_sharing/settings.php
+++ /dev/null
@@ -1,10 +0,0 @@
-<?php
-
-OCP\User::checkAdminUser();
-OCP\Util::addscript('files_sharing', 'settings');
-$tmpl = new OCP\Template('files_sharing', 'settings');
-$tmpl->assign('allowResharing', OCP\Config::getAppValue('files_sharing', 'resharing', 'yes'));
-$tmpl->assign('allowSharingWithEveryone', OCP\Config::getAppValue('files_sharing', 'allowSharingWithEveryone', 'no'));
-return $tmpl->fetchPage();
-
-?> \ No newline at end of file
diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php
deleted file mode 100644
index a2dfe34402f..00000000000
--- a/apps/files_sharing/sharedstorage.php
+++ /dev/null
@@ -1,542 +0,0 @@
-<?php
-/**
- * ownCloud
- *
- * @author Michael Gapczynski
- * @copyright 2011 Michael Gapczynski GapczynskiM@gmail.com
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-require_once( 'lib_share.php' );
-
-/**
- * Convert target path to source path and pass the function call to the correct storage provider
- */
-class OC_Filestorage_Shared extends OC_Filestorage {
-
- private $datadir;
- private $sourcePaths = array();
-
- public function __construct($arguments) {
- $this->datadir = $arguments['datadir'];
- $this->datadir .= "/";
- }
-
- public function getInternalPath($path) {
- $mountPoint = OC_Filesystem::getMountPoint($path);
- $internalPath = substr($path, strlen($mountPoint));
- return $internalPath;
- }
-
- public function getSource($target) {
- $target = $this->datadir.$target;
- if (array_key_exists($target, $this->sourcePaths)) {
- return $this->sourcePaths[$target];
- } else {
- $source = OC_Share::getSource($target);
- $this->sourcePaths[$target] = $source;
- return $source;
- }
- }
-
- public function mkdir($path) {
- if ($path == "" || $path == "/" || !$this->is_writable($path)) {
- return false;
- } else {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->mkdir($this->getInternalPath($source));
- }
- }
- }
-
- public function rmdir($path) {
- // The folder will be removed from the database, but won't be deleted from the owner's filesystem
- OC_Share::unshareFromMySelf($this->datadir.$path);
- $this->clearFolderSizeCache($path);
- }
-
- public function opendir($path) {
- if ($path == "" || $path == "/") {
- $path = $this->datadir.$path;
- $sharedItems = OC_Share::getItemsInFolder($path);
- $files = array();
- foreach ($sharedItems as $item) {
- // If item is in the root of the shared storage provider and the item exists add it to the fakedirs
- if (dirname($item['target'])."/" == $path && $this->file_exists(basename($item['target']))) {
- $files[] = basename($item['target']);
- }
- }
- OC_FakeDirStream::$dirs['shared'.$path] = $files;
- return opendir('fakedir://shared'.$path);
- } else {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- $dh = $storage->opendir($this->getInternalPath($source));
- $modifiedItems = OC_Share::getItemsInFolder($source);
- if ($modifiedItems && $dh) {
- $sources = array();
- $targets = array();
- // Remove any duplicate or trailing '/'
- $path = preg_replace('{(/)\1+}', "/", $path);
- $targetFolder = rtrim($this->datadir.$path, "/");
- foreach ($modifiedItems as $item) {
- // If the item is in the current directory and the item exists add it to the arrays
- if (dirname($item['target']) == $targetFolder && $this->file_exists($path."/".basename($item['target']))) {
- // If the item was unshared from self, add it it to the arrays
- if ($item['permissions'] == OC_Share::UNSHARED) {
- $sources[] = basename($item['source']);
- $targets[] = "";
- } else {
- $sources[] = basename($item['source']);
- $targets[] = basename($item['target']);
- }
- }
- }
- // Don't waste time if there aren't any modified items in the current directory
- if (empty($sources)) {
- return $dh;
- } else {
- global $FAKEDIRS;
- $files = array();
- while (($filename = readdir($dh)) !== false) {
- if ($filename != "." && $filename != "..") {
- // If the file isn't in the sources array it isn't modified and can be added as is
- if (!in_array($filename, $sources)) {
- $files[] = $filename;
- // The file has a different name than the source and is added to the fakedirs
- } else {
- $target = $targets[array_search($filename, $sources)];
- // Don't add the file if it was unshared from self by the user
- if ($target != "") {
- $files[] = $target;
- }
- }
- }
- }
- $FAKEDIRS['shared'] = $files;
- return opendir('fakedir://shared');
- }
- } else {
- return $dh;
- }
- }
- }
- }
-
- public function is_dir($path) {
- if ($path == "" || $path == "/") {
- return true;
- } else {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->is_dir($this->getInternalPath($source));
- }
- }
- }
-
- public function is_file($path) {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->is_file($this->getInternalPath($source));
- }
- }
-
- // TODO fill in other components of array
- public function stat($path) {
- if ($path == "" || $path == "/") {
- $stat["size"] = $this->filesize($path);
- $stat["mtime"] = $this->filemtime($path);
- $stat["ctime"] = $this->filectime($path);
- return $stat;
- } else {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->stat($this->getInternalPath($source));
- }
- }
- }
-
- public function filetype($path) {
- if ($path == "" || $path == "/") {
- return "dir";
- } else {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->filetype($this->getInternalPath($source));
- }
- }
-
- }
-
- public function filesize($path) {
- if ($path == "" || $path == "/" || $this->is_dir($path)) {
- return $this->getFolderSize($path);
- } else {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->filesize($this->getInternalPath($source));
- }
- }
- }
-
- public function getFolderSize($path) {
- return 0; //depricated
- }
-
- private function calculateFolderSize($path) {
- if ($this->is_file($path)) {
- $path = dirname($path);
- }
- $size = 0;
- if ($dh = $this->opendir($path)) {
- while (($filename = readdir($dh)) !== false) {
- if ($filename != "." && $filename != "..") {
- $subFile = $path."/".$filename;
- if ($this->is_file($subFile)) {
- $size += $this->filesize($subFile);
- } else {
- $size += $this->getFolderSize($subFile);
- }
- }
- }
- if ($size > 0) {
- $dbpath = rtrim($this->datadir.$path, "/");
-// $query = OCP\DB::prepare("INSERT INTO `*PREFIX*foldersize` VALUES(?,?)");
-// $result = $query->execute(array($dbpath, $size));
- }
- }
- return $size;
- }
-
- private function clearFolderSizeCache($path) {
- $path = rtrim($path, "/");
- $path = preg_replace('{(/)\1+}', "/", $path);
- if ($this->is_file($path)) {
- $path = dirname($path);
- }
- $dbpath = rtrim($this->datadir.$path, "/");
-// $query = OCP\DB::prepare("DELETE FROM `*PREFIX*/*foldersize*/` WHERE `path` = ?");
-// $result = $query->execute(array($dbpath));
- if ($path != "/" && $path != "") {
- $parts = explode("/", $path);
- $part = array_pop($parts);
- if (empty($part)) {
- array_pop($parts);
- }
- $parent = implode("/", $parts);
- $this->clearFolderSizeCache($parent);
- }
- }
-
- public function is_readable($path) {
- return true;
- }
-
- public function is_writable($path) {
- if($path == "" || $path == "/"){
- return false;
- }elseif (OC_Share::getPermissions($this->datadir.$path) & OC_Share::WRITE) {
- return true;
- } else {
- return false;
- }
- }
-
- public function file_exists($path) {
- if ($path == "" || $path == "/") {
- return true;
- } else {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->file_exists($this->getInternalPath($source));
- }
- }
- }
-
- public function filectime($path) {
- if ($path == "" || $path == "/") {
- $ctime = 0;
- if ($dh = $this->opendir($path)) {
- while (($filename = readdir($dh)) !== false) {
- $tempctime = $this->filectime($filename);
- if ($tempctime < $ctime) {
- $ctime = $tempctime;
- }
- }
- }
- return $ctime;
- } else {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->filectime($this->getInternalPath($source));
- }
- }
- }
-
- public function filemtime($path) {
- if ($path == "" || $path == "/") {
- $mtime = 0;
- if ($dh = $this->opendir($path)) {
- while (($filename = readdir($dh)) !== false) {
- $tempmtime = $this->filemtime($filename);
- if ($tempmtime > $mtime) {
- $mtime = $tempmtime;
- }
- }
- }
- return $mtime;
- } else {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->filemtime($this->getInternalPath($source));
- }
- }
- }
-
- public function file_get_contents($path) {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->file_get_contents($this->getInternalPath($source));
- }
- }
-
- public function file_put_contents($path, $data) {
- if ($this->is_writable($path)) {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- $result = $storage->file_put_contents($this->getInternalPath($source), $data);
- if ($result) {
- $this->clearFolderSizeCache($path);
- }
- return $result;
- }
- }
- }
-
- public function unlink($path) {
- // The item will be removed from the database, but won't be touched on the owner's filesystem
- $target = $this->datadir.$path;
- // Check if the item is inside a shared folder
- if (OC_Share::getParentFolders($target)) {
- // If entry for item already exists
- if (OC_Share::getItem($target)) {
- OC_Share::unshareFromMySelf($target, false);
- } else {
- OC_Share::pullOutOfFolder($target, $target);
- OC_Share::unshareFromMySelf($target, false);
- }
- // Delete the database entry
- } else {
- OC_Share::unshareFromMySelf($target);
- }
- $this->clearFolderSizeCache($this->getInternalPath($target));
- return true;
- }
-
- public function rename($path1, $path2) {
- $oldTarget = $this->datadir.$path1;
- $newTarget = $this->datadir.$path2;
- // Check if the item is inside a shared folder
- if ($folders = OC_Share::getParentFolders($oldTarget)) {
- $root1 = substr($path1, 0, strpos($path1, "/"));
- $root2 = substr($path1, 0, strpos($path2, "/"));
- // Prevent items from being moved into different shared folders until versioning (cut and paste) and prevent items going into 'Shared'
- if ($root1 !== $root2) {
- return false;
- // Check if both paths have write permission
- } else if ($this->is_writable($path1) && $this->is_writable($path2)) {
- $oldSource = $this->getSource($path1);
- $newSource = $folders['source'].substr($newTarget, strlen($folders['target']));
- if ($oldSource) {
- $storage = OC_Filesystem::getStorage($oldSource);
- return $storage->rename($this->getInternalPath($oldSource), $this->getInternalPath($newSource));
- }
- // If the user doesn't have write permission, items can only be renamed and not moved
- } else if (dirname($path1) !== dirname($path2)) {
- return false;
- // The item will be renamed in the database, but won't be touched on the owner's filesystem
- } else {
- OC_Share::pullOutOfFolder($oldTarget, $newTarget);
- // If this is a folder being renamed, call setTarget in case there are any database entries inside the folder
- if (self::is_dir($path1)) {
- OC_Share::setTarget($oldTarget, $newTarget);
- }
- }
- } else {
- OC_Share::setTarget($oldTarget, $newTarget);
- }
- $this->clearFolderSizeCache($this->getInternalPath($oldTarget));
- $this->clearFolderSizeCache($this->getInternalPath($newTarget));
- return true;
- }
-
- public function copy($path1, $path2) {
- if ($path2 == "" || $path2 == "/") {
- // TODO Construct new shared item or should this not be allowed?
- } else {
- if ($this->is_writable($path2)) {
- $tmpFile = $this->toTmpFile($path1);
- $result = $this->fromTmpFile($tmpFile, $path2);
- if ($result) {
- $this->clearFolderSizeCache($path2);
- }
- return $result;
- } else {
- return false;
- }
- }
- }
-
- public function fopen($path, $mode) {
- $source = $this->getSource($path);
- if ($source) {
- switch ($mode) {
- case 'r+':
- case 'rb+':
- case 'w+':
- case 'wb+':
- case 'x+':
- case 'xb+':
- case 'a+':
- case 'ab+':
- case 'w':
- case 'wb':
- case 'x':
- case 'xb':
- case 'a':
- case 'ab':
- if (!$this->is_writable($path)) {
- return false;
- }
- }
- $storage = OC_Filesystem::getStorage($source);
- return $storage->fopen($this->getInternalPath($source), $mode);
- }
- }
-
- public function toTmpFile($path) {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->toTmpFile($this->getInternalPath($source));
- }
- }
-
- public function fromTmpFile($tmpFile, $path) {
- if ($this->is_writable($path)) {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- $result = $storage->fromTmpFile($tmpFile, $this->getInternalPath($source));
- if ($result) {
- $this->clearFolderSizeCache($path);
- }
- return $result;
- }
- } else {
- return false;
- }
- }
-
- public function getMimeType($path) {
- if ($path == "" || $path == "/") {
- return 'httpd/unix-directory';
- }
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->getMimeType($this->getInternalPath($source));
- }
- }
-
- public function hash($type, $path, $raw = false) {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->hash($type, $this->getInternalPath($source), $raw);
- }
- }
-
- public function free_space($path) {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->free_space($this->getInternalPath($source));
- }
- }
-
- public function search($query) {
- return $this->searchInDir($query);
- }
-
- private function searchInDir($query, $path = "") {
- $files = array();
- if ($dh = $this->opendir($path)) {
- while (($filename = readdir($dh)) !== false) {
- if ($filename != "." && $filename != "..") {
- if (strstr(strtolower($filename), strtolower($query))) {
- $files[] = $path."/".$filename;
- }
- if ($this->is_dir($path."/".$filename)) {
- $files = array_merge($files, $this->searchInDir($query, $path."/".$filename));
- }
- }
- }
- }
- return $files;
- }
-
- public function getLocalFile($path) {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->getLocalFile($this->getInternalPath($source));
- }
- }
- public function touch($path, $mtime=null){
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->touch($this->getInternalPath($source),$time);
- }
- }
-
- public static function setup() {
- OC_Filesystem::mount('OC_Filestorage_Shared', array('datadir' => '/'.OCP\USER::getUser().'/files/Shared'), '/'.OCP\USER::getUser().'/files/Shared/');
- }
-
-}
-
-if (OCP\USER::isLoggedIn()) {
- OC_Filestorage_Shared::setup();
-} else {
- OCP\Util::connectHook('OC_User', 'post_login', 'OC_Filestorage_Shared', 'setup');
-}
-
-?>
diff --git a/apps/files_sharing/templates/get.php b/apps/files_sharing/templates/get.php
new file mode 100755
index 00000000000..57275f07a3d
--- /dev/null
+++ b/apps/files_sharing/templates/get.php
@@ -0,0 +1,11 @@
+<table>
+ <thead>
+ <tr>
+ <th id="headerSize"><?php echo $l->t( 'Size' ); ?></th>
+ <th id="headerDate"><span id="modified"><?php echo $l->t( 'Modified' ); ?></span><span class="selectedActions"><a href="" class="delete"><?php echo $l->t('Delete all')?> <img class="svg" alt="<?php echo $l->t('Delete')?>" src="<?php echo OCP\image_path("core", "actions/delete.svg"); ?>" /></a></span></th>
+ </tr>
+ </thead>
+ <tbody id="fileList" data-readonly="<?php echo $_['readonly'];?>">
+ <?php echo($_['fileList']); ?>
+ </tbody>
+</table> \ No newline at end of file
diff --git a/apps/files_sharing/templates/list.php b/apps/files_sharing/templates/list.php
deleted file mode 100644
index d46ff818ac1..00000000000
--- a/apps/files_sharing/templates/list.php
+++ /dev/null
@@ -1,30 +0,0 @@
-<fieldset>
- <legend><?php echo $l->t('Your Shared Files');?></legend>
- <table id="itemlist">
- <thead>
- <tr>
- <th><?php echo $l->t('Item');?></th>
- <th><?php echo $l->t('Shared With');?></th>
- <th><?php echo $l->t('Permissions');?></th>
- </tr>
- </thead>
- <tbody>
- <?php foreach($_['shared_items'] as $item):?>
- <tr class="item">
- <td class="source"><?php echo substr($item['source'], strlen("/".$_SESSION['user_id']."/files/"));?></td>
- <td class="uid_shared_with"><?php echo $item['uid_shared_with'];?></td>
- <td class="permissions"><?php echo $l->t('Read'); echo($item['permissions'] & OC_SHARE::WRITE ? ", ".$l->t('Edit') : ""); echo($item['permissions'] & OC_SHARE::DELETE ? ", ".$l->t('Delete') : "");?></td>
- <td><button class="delete" data-source="<?php echo $item['source'];?>" data-uid_shared_with="<?php echo $item['uid_shared_with'];?>"><?php echo $l->t('Delete');?></button></td>
- </tr>
- <?php endforeach;?>
- <tr id="share_item_row">
- <form action="#" id="share_item">
- <td class="source"><input placeholder="Item" id="source" /></td>
- <td class="uid_shared_with"><input placeholder="Share With" id="uid_shared_with" /></td>
- <td class="permissions"><input placeholder="Permissions" id="permissions" /></td>
- <td><input type="submit" value="Share" /></td>
- </form>
- </tr>
- </tbody>
- </table>
-</fieldset>
diff --git a/apps/files_sharing/templates/settings.php b/apps/files_sharing/templates/settings.php
deleted file mode 100644
index 533a5c0c0c8..00000000000
--- a/apps/files_sharing/templates/settings.php
+++ /dev/null
@@ -1,8 +0,0 @@
-<form id="resharing">
- <fieldset class="personalblock">
- <p><input type="checkbox" name="allowResharing" id="allowResharing" value="1" <?php if ($_['allowResharing'] == 'yes') echo ' checked="checked"'; ?> /> <label for="allowResharing"><?php echo $l->t('Enable Resharing'); ?></label> <br/>
- <em><?php echo $l->t('Allow users to reshare files they don\'t own');?></em></p>
- <p><input type="checkbox" name="allowSharingWithEveryone" id="allowSharingWithEveryone" value="1" <?php if ($_['allowSharingWithEveryone'] == 'yes') echo ' checked="checked"'; ?> /> <label for="allowSharingWithEveryone"><?php echo $l->t('Enable sharing with everyone'); ?></label> <br/>
- <em><?php echo $l->t('Allow users to share files with everyone');?></em></p>
- </fieldset>
-</form> \ No newline at end of file