Add support for sharing folders

This commit is contained in:
Michael Gapczynski 2011-06-24 19:20:08 -04:00
parent 467778d66f
commit e91f42d249
3 changed files with 25 additions and 12 deletions

View File

@ -1,7 +1,6 @@
<?php
OC_APP::addSettingsPage( array(
"id" => "files_sharing_administration",
OC_APP::addSettingsPage( array( "id" => "files_sharing_administration",
"order" => 10,
"href" => OC_HELPER::linkTo( "files_sharing", "admin.php" ),
"name" => "Share",

View File

@ -81,9 +81,16 @@ class OC_SHARE {
* @return source path
*/
public static function getSource($target) {
// Break up the $target to get only the first part in case it is inside a folder
$parts = explode("/", $target);
$query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ?");
$result = $query->execute(array($target, $_SESSION['user_id']))->fetchAll();
return $result[0]['source'];
$result = $query->execute(array($parts[0], $_SESSION['user_id']))->fetchAll();
$source = $result[0]['source'];
// Add the $parts back in
foreach (array_slice($parts, 1) as $part) {
$source .= $part;
}
return $source;
}
/**

View File

@ -58,15 +58,22 @@ class OC_FILESTORAGE_SHARED {
}
}
// TODO add all files from db in array
public function opendir($path) {
global $FAKEDIRS;
$sharedItems = OC_SHARE::getItemsSharedWith();
foreach ($sharedItems as $item) {
$files[] = $item['target'];
if ($path == "" || $path == "/") {
global $FAKEDIRS;
$sharedItems = OC_SHARE::getItemsSharedWith();
foreach ($sharedItems as $item) {
$files[] = $item['target'];
}
$FAKEDIRS['shared'] = $files;
return opendir('fakedir://shared');
} else {
$source = OC_SHARE::getSource($path);
if ($source) {
$storage = OC_FILESYSTEM::getStorage($source);
return $storage->opendir($this->getInternalPath($source));
}
}
$FAKEDIRS['shared'] = $files;
return opendir('fakedir://shared');
}
public function is_dir($path) {
@ -144,7 +151,7 @@ class OC_FILESTORAGE_SHARED {
if ($path == "" || $path == "/") {
$dbpath = $_SESSION['user_id']."/files/Share/";
} else {
$dbpath = $path;
$dbpath = substr(OC_SHARE::getSource($path), 1);
}
$query = OC_DB::prepare("SELECT size FROM *PREFIX*foldersize WHERE path=?");
$size = $query->execute(array($dbpath))->fetchAll();