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 <?php
OC_APP::addSettingsPage( array( OC_APP::addSettingsPage( array( "id" => "files_sharing_administration",
"id" => "files_sharing_administration",
"order" => 10, "order" => 10,
"href" => OC_HELPER::linkTo( "files_sharing", "admin.php" ), "href" => OC_HELPER::linkTo( "files_sharing", "admin.php" ),
"name" => "Share", "name" => "Share",

View File

@ -81,9 +81,16 @@ class OC_SHARE {
* @return source path * @return source path
*/ */
public static function getSource($target) { 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 = ?"); $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ?");
$result = $query->execute(array($target, $_SESSION['user_id']))->fetchAll(); $result = $query->execute(array($parts[0], $_SESSION['user_id']))->fetchAll();
return $result[0]['source']; $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) { public function opendir($path) {
global $FAKEDIRS; if ($path == "" || $path == "/") {
$sharedItems = OC_SHARE::getItemsSharedWith(); global $FAKEDIRS;
foreach ($sharedItems as $item) { $sharedItems = OC_SHARE::getItemsSharedWith();
$files[] = $item['target']; 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) { public function is_dir($path) {
@ -144,7 +151,7 @@ class OC_FILESTORAGE_SHARED {
if ($path == "" || $path == "/") { if ($path == "" || $path == "/") {
$dbpath = $_SESSION['user_id']."/files/Share/"; $dbpath = $_SESSION['user_id']."/files/Share/";
} else { } else {
$dbpath = $path; $dbpath = substr(OC_SHARE::getSource($path), 1);
} }
$query = OC_DB::prepare("SELECT size FROM *PREFIX*foldersize WHERE path=?"); $query = OC_DB::prepare("SELECT size FROM *PREFIX*foldersize WHERE path=?");
$size = $query->execute(array($dbpath))->fetchAll(); $size = $query->execute(array($dbpath))->fetchAll();