From 8603b0973f994be5fb3e585817c220b22e6d2c24 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sat, 11 Jun 2011 16:14:24 -0400 Subject: [PATCH 001/122] Initial setup of sharing app --- .gitignore | 1 + apps/files_sharing/admin.php | 38 ++++++++++ apps/files_sharing/appinfo/app.php | 10 +++ apps/files_sharing/appinfo/database.xml | 41 ++++++++++ apps/files_sharing/appinfo/info.xml | 10 +++ apps/files_sharing/lib_share.php | 99 +++++++++++++++++++++++++ apps/files_sharing/sharedstorage.php | 28 +++++++ apps/files_sharing/templates/admin.php | 29 ++++++++ 8 files changed, 256 insertions(+) create mode 100644 apps/files_sharing/admin.php create mode 100644 apps/files_sharing/appinfo/app.php create mode 100644 apps/files_sharing/appinfo/database.xml create mode 100644 apps/files_sharing/appinfo/info.xml create mode 100644 apps/files_sharing/lib_share.php create mode 100644 apps/files_sharing/sharedstorage.php create mode 100644 apps/files_sharing/templates/admin.php diff --git a/.gitignore b/.gitignore index 9cfb7a5861..fd29bd8c1d 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ CVS/* RCS/* .kdev *.kdev4 +.project \ No newline at end of file diff --git a/apps/files_sharing/admin.php b/apps/files_sharing/admin.php new file mode 100644 index 0000000000..8d668c8329 --- /dev/null +++ b/apps/files_sharing/admin.php @@ -0,0 +1,38 @@ +. + * + */ + +require_once('../../lib/base.php'); +require_once( 'lib_share.php' ); +require( 'template.php' ); + +if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){ + header( "Location: ".OC_HELPER::linkTo( "index.php" )); + exit(); +} + +OC_APP::setActiveNavigationEntry( "files_sharing_administration" ); + +$tmpl = new OC_TEMPLATE( "files_sharing", "admin", "admin" ); +$tmpl->assign( 'shared_items', OC_SHARE::getSharedItems()); +$tmpl->printPage(); + +?> \ No newline at end of file diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php new file mode 100644 index 0000000000..359e26b16f --- /dev/null +++ b/apps/files_sharing/appinfo/app.php @@ -0,0 +1,10 @@ + "files_sharing_administration", + "order" => 10, + "href" => OC_HELPER::linkTo( "files_sharing", "admin.php" ), + "name" => "Share", + "icon" => OC_HELPER::imagePath( "files_sharing", "share.png" ))); + +?> \ No newline at end of file diff --git a/apps/files_sharing/appinfo/database.xml b/apps/files_sharing/appinfo/database.xml new file mode 100644 index 0000000000..fa56dbe803 --- /dev/null +++ b/apps/files_sharing/appinfo/database.xml @@ -0,0 +1,41 @@ + + + *dbname* + true + false + latin1 + + *dbprefix*sharing + + + item + text + true + 128 + + + uid_owner + text + + true + 64 + + + uid_shared_with + text + + + true + 64 + + + permissions + text + + + true + 3 + + +
+
diff --git a/apps/files_sharing/appinfo/info.xml b/apps/files_sharing/appinfo/info.xml new file mode 100644 index 0000000000..2fbb3300f6 --- /dev/null +++ b/apps/files_sharing/appinfo/info.xml @@ -0,0 +1,10 @@ + + + files_sharing + Share Files + File sharing between users + 0.1 + AGPL + Michael Gapczynski + 2 + \ No newline at end of file diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php new file mode 100644 index 0000000000..c53059b2ec --- /dev/null +++ b/apps/files_sharing/lib_share.php @@ -0,0 +1,99 @@ +. + * + */ + +/** + * This class manages shared items within the database. + */ +class OC_SHARE { + + /** + * TODO notify user a file is being shared with them? + * Share an item, adds an entry into the database + * @param string $item + * @param user item shared with $uid_shared_with + */ + public function __construct($item, $public = false, $uid_shared_with) { + if ($item && OC_FILESYSTEM::file_exists($item) && OC_FILESYSTEM::is_readable($item)) { + $uid_owner = $_SESSION['user_id']; + if ($public) { + // TODO create token for public file + $token = sha1("$uid_owner-$item"); + } else { + $query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?)"); + foreach ($uid_shared_with as $uid) { + $query->execute(array($uid_owner, $uid, $item)); + } + } + } + } + + /** + * TODO complete lib_permissions + * Change the permissions of the specified item + * @param permissions $permissions + */ + public static function setPermissions($item, $uid_shared_with, $permissions) { + $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET permissions = ? WHERE item = ? AND uid_shared_with = ? AND uid_owner = ?"); + $query->execute(array($permissions, $item, $uid_shared_with, $_SESSION['user_id'])); + } + + /** + * Get the permissions for the specified item + * @param unknown_type $item + */ + public static function getPermissions($item, $uid_shared_with) { + $query = OC_DB::prepare("SELECT permissions FROM *PREFIX*sharing WHERE item = ? AND uid_shared_with = ? AND uid_owner = ? "); + return $query->execute(array($item, $uid_shared_with, $_SESSION['user_id']))->fetchAll(); + } + + /** + * Unshare the item, removes it from all users specified + * @param array $uid_shared_with + */ + public static function unshare($item, $uid_shared_with) { + $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE item = ? AND uid_shared_with = ? AND uid_owner = ?"); + foreach ($uid_shared_with as $uid) { + $query->execute(array($item, $uid, $_SESSION['user_id']))->fetchAll(); + } + } + + /** + * Get all items the user is sharing + * @return array + */ + public static function getSharedItems() { + $query = OC_DB::prepare("SELECT * FROM *PREFIX*sharing WHERE uid_owner = ?"); + return $query->execute(array($_SESSION['user_id']))->fetchAll(); + } + + /** + * Get all items shared with the user + * @return array + */ + public static function getItemsSharedWith() { + $query = OC_DB::prepare("SELECT * FROM *PREFIX*sharing WHERE uid_shared_with = ?"); + return $query->execute(array($_SESSION['user_id']))->fetchAll(); + } + +} + +?> diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php new file mode 100644 index 0000000000..25824f2779 --- /dev/null +++ b/apps/files_sharing/sharedstorage.php @@ -0,0 +1,28 @@ +. + * + */ + +class OC_FILESTORAGE_SHARE { + + +} + +?> \ No newline at end of file diff --git a/apps/files_sharing/templates/admin.php b/apps/files_sharing/templates/admin.php new file mode 100644 index 0000000000..764aee00b4 --- /dev/null +++ b/apps/files_sharing/templates/admin.php @@ -0,0 +1,29 @@ + + + + + + + + + + + + '> + + + + + + + + + + + + + + + +
ItemShared With
+ \ No newline at end of file From bf66563cda15acbe8f5b12be76fb5ba387a6798c Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Thu, 16 Jun 2011 14:40:21 -0400 Subject: [PATCH 002/122] First version of shared storage provider - not functional --- apps/files_sharing/admin.php | 2 +- apps/files_sharing/lib_share.php | 12 +- apps/files_sharing/sharedstorage.php | 267 ++++++++++++++++++++++++- apps/files_sharing/templates/admin.php | 15 +- lib/base.php | 4 + lib/filesystem.php | 2 +- 6 files changed, 291 insertions(+), 11 deletions(-) diff --git a/apps/files_sharing/admin.php b/apps/files_sharing/admin.php index 8d668c8329..0bb45731b2 100644 --- a/apps/files_sharing/admin.php +++ b/apps/files_sharing/admin.php @@ -24,7 +24,7 @@ require_once('../../lib/base.php'); require_once( 'lib_share.php' ); require( 'template.php' ); -if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){ +if (!OC_USER::isLoggedIn()){ header( "Location: ".OC_HELPER::linkTo( "index.php" )); exit(); } diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index c53059b2ec..6a3b36b420 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -72,10 +72,20 @@ class OC_SHARE { public static function unshare($item, $uid_shared_with) { $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE item = ? AND uid_shared_with = ? AND uid_owner = ?"); foreach ($uid_shared_with as $uid) { - $query->execute(array($item, $uid, $_SESSION['user_id']))->fetchAll(); + $query->execute(array($item, $uid, $_SESSION['user_id'])); } } + /** + * Get the source location of the target item + * @return source path + */ + public static function getSource($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']; + } + /** * Get all items the user is sharing * @return array diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 25824f2779..cd797e9d0a 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -20,8 +20,273 @@ * */ -class OC_FILESTORAGE_SHARE { +require_once( 'lib_share.php' ); + +OC_FILESYSTEM::registerStorageType('shared','OC_FILESTORAGE_SHARED',array('datadir'=>'string')); + +/** + * Convert target path to source path and pass the function call to the correct storage provider + */ +class OC_FILESTORAGE_SHARED { + // TODO uh... I don't know what to do here + public function __construct($parameters) { + + } + + // TODO OC_SHARE::getPermissions() + public function mkdir($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->mkdir(OC_FILESYSTEM::getInternalPath($source)); + } + } + + // TODO OC_SHARE::getPermissions() + public function rmdir($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->is_file(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function opendir($path) { + //$source = OC_SHARE::getSource($path); + //if ($source) { + //$storage = OC_FILESYSTEM::getStorage($source); + //return $storage->opendir(OC_FILESYSTEM::getInternalPath($source)); + //} + global $FAKEDIRS; + $FAKEDIRS['shared'] = array(0 => 'test.txt'); + return opendir('fakedir://shared'); + } + + public function is_dir($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->is_dir(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function is_file($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->is_file(OC_FILESYSTEM::getInternalPath($source)); + } + } + public function stat($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->stat(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function filetype($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->filetype(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function filesize($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->filesize(OC_FILESYSTEM::getInternalPath($source)); + } + } + + // TODO OC_SHARE::getPermissions() + public function is_readable($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->is_readable(OC_FILESYSTEM::getInternalPath($source)); + } + } + + // TODO OC_SHARE::getPermissions() + public function is_writeable($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->is_writeable(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function file_exists($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->file_exists(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function readfile($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->readfile(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function filectime($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->filectime(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function filemtime($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->filemtime(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function fileatime($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->fileatime(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function file_get_contents($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->file_get_contents(OC_FILESYSTEM::getInternalPath($source)); + } + } + + // TODO OC_SHARE::getPermissions() + public function file_put_contents($path, $data) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->file_put_contents(OC_FILESYSTEM::getInternalPath($source), $data); + } + } + + public function unlink($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->unlink(OC_FILESYSTEM::getInternalPath($source)); + } + } + + // TODO OC_SHARE::getPermissions() + // TODO Update shared item location + public function rename($path1, $path2) { + $source = OC_SHARE::getSource($path1); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->rename(OC_FILESYSTEM::getInternalPath($source), $path2); + } + } + + public function copy($path1, $path2) { + $source = OC_SHARE::getSource($path1); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->copy(OC_FILESYSTEM::getInternalPath($source), $path2); + } + } + + public function fopen($path, $mode) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->fopen(OC_FILESYSTEM::getInternalPath($source), $mode); + } + } + + public function toTmpFile($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->toTmpFile(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function fromTmpFile($tmpPath, $path) { + $source = OC_SHARE::getSource($tmpPath); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->fromTmpFile(OC_FILESYSTEM::getInternalPath($source), $path); + } + } + + public function fromUploadedFile($tmpPath, $path) { + $source = OC_SHARE::getSource($tmpPath); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->fromUploadedFile(OC_FILESYSTEM::getInternalPath($source), $path); + } + } + + public function getMimeType($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->getMimeType(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function delTree($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->delTree(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function find($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->find(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function getTree($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->getTree(OC_FILESYSTEM::getInternalPath($source)); + } + } + + public function hash($type, $path, $raw) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->hash($type, OC_FILESYSTEM::getInternalPath($source), $raw); + } + } + + public function free_space($path) { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->free_space(OC_FILESYSTEM::getInternalPath($source)); + } + } + + // TODO query all shared files? + public function search($query) { + + } } diff --git a/apps/files_sharing/templates/admin.php b/apps/files_sharing/templates/admin.php index 764aee00b4..827b64143c 100644 --- a/apps/files_sharing/templates/admin.php +++ b/apps/files_sharing/templates/admin.php @@ -2,25 +2,26 @@ - - - + + + '> - + - + - - + + + diff --git a/lib/base.php b/lib/base.php index c18ecd570d..199653e25e 100644 --- a/lib/base.php +++ b/lib/base.php @@ -80,6 +80,7 @@ require_once('appconfig.php'); require_once('files.php'); require_once('filesystem.php'); require_once('filestorage.php'); +require_once('apps/files_sharing/sharedstorage.php'); require_once('log.php'); require_once('user.php'); require_once('group.php'); @@ -157,6 +158,9 @@ class OC_UTIL { // } OC_FILESYSTEM::mount($rootStorage,'/'); + $sharedStorage = OC_FILESYSTEM::createStorage('shared',array('datadir'=>$CONFIG_DATADIRECTORY)); + OC_FILESYSTEM::mount($sharedStorage,'MTGap/files/Test/'); + $CONFIG_DATADIRECTORY = "$CONFIG_DATADIRECTORY_ROOT/$user/$root"; if( !is_dir( $CONFIG_DATADIRECTORY )){ mkdir( $CONFIG_DATADIRECTORY, 0755, true ); diff --git a/lib/filesystem.php b/lib/filesystem.php index 2b5c3a56b6..897efaa140 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -155,7 +155,7 @@ class OC_FILESYSTEM{ * @param string path * @return OC_FILESTORAGE */ - static private function getStorage($path){ + static public function getStorage($path){ $mountpoint=self::getMountPoint($path); if($mountpoint){ return self::$storages[$mountpoint]; From fe4a213e1b39c90920fcf770ab0a82b73b1a9c09 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Thu, 16 Jun 2011 14:59:54 -0400 Subject: [PATCH 003/122] Fixed mistakes pointed out by icewind --- apps/files_sharing/lib_share.php | 2 +- apps/files_sharing/sharedstorage.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 6a3b36b420..b739656acf 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -31,7 +31,7 @@ class OC_SHARE { * @param string $item * @param user item shared with $uid_shared_with */ - public function __construct($item, $public = false, $uid_shared_with) { + public function __construct($item, $uid_shared_with, $public = false) { if ($item && OC_FILESYSTEM::file_exists($item) && OC_FILESYSTEM::is_readable($item)) { $uid_owner = $_SESSION['user_id']; if ($public) { diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index cd797e9d0a..ac7654970e 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -48,7 +48,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->is_file(OC_FILESYSTEM::getInternalPath($source)); + return $storage->rmdir(OC_FILESYSTEM::getInternalPath($source)); } } From e6621b9c783f7605b0b2f99051e205c30240ea98 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Thu, 16 Jun 2011 15:54:25 -0400 Subject: [PATCH 004/122] Added source and target to database fields --- apps/files_sharing/appinfo/database.xml | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/apps/files_sharing/appinfo/database.xml b/apps/files_sharing/appinfo/database.xml index fa56dbe803..bb80484bd6 100644 --- a/apps/files_sharing/appinfo/database.xml +++ b/apps/files_sharing/appinfo/database.xml @@ -13,26 +13,33 @@ true 128 + + source + text + true + 128 + + + target + text + true + 128 + uid_owner text - true 64 uid_shared_with text - - true 64 permissions text - - true 3 From 69b5e01be1fe33eb4ea13cc80846a74afe696ff3 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sat, 18 Jun 2011 13:29:16 -0400 Subject: [PATCH 005/122] OC_FILESTOAGE_SHARED updates + its own getInternalPath() --- apps/files_sharing/sharedstorage.php | 187 ++++++++++++++++++--------- 1 file changed, 123 insertions(+), 64 deletions(-) diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index ac7654970e..158d6006a4 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -34,12 +34,18 @@ class OC_FILESTORAGE_SHARED { } + public function getInternalPath($path) { + $mountPoint = OC_FILESYSTEM::getMountPoint($path); + $internalPath = substr($path,strlen($mountPoint)); + return $internalPath; + } + // TODO OC_SHARE::getPermissions() public function mkdir($path) { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->mkdir(OC_FILESYSTEM::getInternalPath($source)); + return $storage->mkdir(getInternalPath($source)); } } @@ -48,26 +54,25 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->rmdir(OC_FILESYSTEM::getInternalPath($source)); + return $storage->rmdir(getInternalPath($source)); } } public function opendir($path) { - //$source = OC_SHARE::getSource($path); - //if ($source) { - //$storage = OC_FILESYSTEM::getStorage($source); - //return $storage->opendir(OC_FILESYSTEM::getInternalPath($source)); - //} global $FAKEDIRS; $FAKEDIRS['shared'] = array(0 => 'test.txt'); return opendir('fakedir://shared'); } public function is_dir($path) { - $source = OC_SHARE::getSource($path); - if ($source) { - $storage = OC_FILESYSTEM::getStorage($source); - return $storage->is_dir(OC_FILESYSTEM::getInternalPath($source)); + if ($path == "" || $path == "/") { + return true; + } else { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->is_dir(getInternalPath($source)); + } } } @@ -75,56 +80,95 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->is_file(OC_FILESYSTEM::getInternalPath($source)); + return $storage->is_file(getInternalPath($source)); } } public function stat($path) { - $source = OC_SHARE::getSource($path); - if ($source) { - $storage = OC_FILESYSTEM::getStorage($source); - return $storage->stat(OC_FILESYSTEM::getInternalPath($source)); + if ($path == "" || $path == "/") { + $stat["dev"] = ""; + $stat["ino"] = ""; + $stat["mode"] = ""; + $stat["nlink"] = ""; + $stat["uid"] = ""; + $stat["gid"] = ""; + $stat["rdev"] = ""; + $stat["size"] = filesize($path); + $stat["atime"] = fileatime($path); + $stat["mtime"] = filemtime($path); + $stat["ctime"] = filectime($path); + $stat["blksize"] = ""; + $stat["blocks"] = ""; + return $stat; + } else { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->stat(getInternalPath($source)); + } } } public function filetype($path) { - $source = OC_SHARE::getSource($path); - if ($source) { - $storage = OC_FILESYSTEM::getStorage($source); - return $storage->filetype(OC_FILESYSTEM::getInternalPath($source)); + if ($path == "" || $path == "/") { + return "dir"; + } else { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->filetype(getInternalPath($source)); + } } + } + // TODO Get size of shared directory public function filesize($path) { - $source = OC_SHARE::getSource($path); - if ($source) { - $storage = OC_FILESYSTEM::getStorage($source); - return $storage->filesize(OC_FILESYSTEM::getInternalPath($source)); + if ($path == "" || $path == "/") { + return 10000; + } else { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->filesize(getInternalPath($source)); + } } } // TODO OC_SHARE::getPermissions() public function is_readable($path) { - $source = OC_SHARE::getSource($path); - if ($source) { - $storage = OC_FILESYSTEM::getStorage($source); - return $storage->is_readable(OC_FILESYSTEM::getInternalPath($source)); + if ($path == "" || $path == "/") { + return true; + } else { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->is_readable(getInternalPath($source)); + } } } // TODO OC_SHARE::getPermissions() public function is_writeable($path) { - $source = OC_SHARE::getSource($path); - if ($source) { - $storage = OC_FILESYSTEM::getStorage($source); - return $storage->is_writeable(OC_FILESYSTEM::getInternalPath($source)); + if ($path == "" || $path == "/") { + return true; + } else { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->is_writeable(getInternalPath($source)); + } } } public function file_exists($path) { - $source = OC_SHARE::getSource($path); - if ($source) { - $storage = OC_FILESYSTEM::getStorage($source); - return $storage->file_exists(OC_FILESYSTEM::getInternalPath($source)); + if ($path == "" || $path == "/") { + return true; + } else { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->file_exists(getInternalPath($source)); + } } } @@ -132,31 +176,46 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->readfile(OC_FILESYSTEM::getInternalPath($source)); + return $storage->readfile(getInternalPath($source)); } } + // TODO Get ctime of last file public function filectime($path) { - $source = OC_SHARE::getSource($path); - if ($source) { - $storage = OC_FILESYSTEM::getStorage($source); - return $storage->filectime(OC_FILESYSTEM::getInternalPath($source)); + if ($path == "" || $path == "/") { + return 10000003232; + } else { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->filectime(getInternalPath($source)); + } } } + // TODO Get mtime of last file public function filemtime($path) { - $source = OC_SHARE::getSource($path); - if ($source) { - $storage = OC_FILESYSTEM::getStorage($source); - return $storage->filemtime(OC_FILESYSTEM::getInternalPath($source)); + if ($path == "" || $path == "/") { + return 10000003232; + } else { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->filemtime(getInternalPath($source)); + } } } + // TODO Get atime of last file public function fileatime($path) { - $source = OC_SHARE::getSource($path); - if ($source) { - $storage = OC_FILESYSTEM::getStorage($source); - return $storage->fileatime(OC_FILESYSTEM::getInternalPath($source)); + if ($path == "" || $path == "/") { + return 10000003232; + } else { + $source = OC_SHARE::getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->fileatime(getInternalPath($source)); + } } } @@ -164,7 +223,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->file_get_contents(OC_FILESYSTEM::getInternalPath($source)); + return $storage->file_get_contents(getInternalPath($source)); } } @@ -173,7 +232,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->file_put_contents(OC_FILESYSTEM::getInternalPath($source), $data); + return $storage->file_put_contents(getInternalPath($source), $data); } } @@ -181,7 +240,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->unlink(OC_FILESYSTEM::getInternalPath($source)); + return $storage->unlink(getInternalPath($source)); } } @@ -191,7 +250,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path1); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->rename(OC_FILESYSTEM::getInternalPath($source), $path2); + return $storage->rename(getInternalPath($source), $path2); } } @@ -199,7 +258,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path1); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->copy(OC_FILESYSTEM::getInternalPath($source), $path2); + return $storage->copy(getInternalPath($source), $path2); } } @@ -207,7 +266,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->fopen(OC_FILESYSTEM::getInternalPath($source), $mode); + return $storage->fopen(getInternalPath($source), $mode); } } @@ -215,7 +274,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->toTmpFile(OC_FILESYSTEM::getInternalPath($source)); + return $storage->toTmpFile(getInternalPath($source)); } } @@ -223,7 +282,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($tmpPath); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->fromTmpFile(OC_FILESYSTEM::getInternalPath($source), $path); + return $storage->fromTmpFile(getInternalPath($source), $path); } } @@ -231,7 +290,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($tmpPath); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->fromUploadedFile(OC_FILESYSTEM::getInternalPath($source), $path); + return $storage->fromUploadedFile(getInternalPath($source), $path); } } @@ -239,7 +298,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->getMimeType(OC_FILESYSTEM::getInternalPath($source)); + return $storage->getMimeType(getInternalPath($source)); } } @@ -247,7 +306,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->delTree(OC_FILESYSTEM::getInternalPath($source)); + return $storage->delTree(getInternalPath($source)); } } @@ -255,7 +314,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->find(OC_FILESYSTEM::getInternalPath($source)); + return $storage->find(getInternalPath($source)); } } @@ -263,7 +322,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->getTree(OC_FILESYSTEM::getInternalPath($source)); + return $storage->getTree(getInternalPath($source)); } } @@ -271,7 +330,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->hash($type, OC_FILESYSTEM::getInternalPath($source), $raw); + return $storage->hash($type, getInternalPath($source), $raw); } } @@ -279,7 +338,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->free_space(OC_FILESYSTEM::getInternalPath($source)); + return $storage->free_space(getInternalPath($source)); } } From 4e7d1c376f0ad85a32e285e512eb05e05219854e Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sat, 18 Jun 2011 13:49:52 -0400 Subject: [PATCH 006/122] OC_FILESTOAGE_SHARED now works with hard coded values for files --- apps/files_sharing/sharedstorage.php | 62 ++++++++++++++-------------- lib/filesystem.php | 2 +- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 158d6006a4..bf6116c9eb 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -34,7 +34,7 @@ class OC_FILESTORAGE_SHARED { } - public function getInternalPath($path) { + public static function getInternalPath($path) { $mountPoint = OC_FILESYSTEM::getMountPoint($path); $internalPath = substr($path,strlen($mountPoint)); return $internalPath; @@ -45,7 +45,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->mkdir(getInternalPath($source)); + return $storage->mkdir(self::getInternalPath($source)); } } @@ -54,7 +54,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->rmdir(getInternalPath($source)); + return $storage->rmdir(self::getInternalPath($source)); } } @@ -71,7 +71,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->is_dir(getInternalPath($source)); + return $storage->is_dir(self::getInternalPath($source)); } } } @@ -80,7 +80,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->is_file(getInternalPath($source)); + return $storage->is_file(self::getInternalPath($source)); } } public function stat($path) { @@ -103,19 +103,19 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->stat(getInternalPath($source)); + return $storage->stat(self::getInternalPath($source)); } } } public function filetype($path) { if ($path == "" || $path == "/") { - return "dir"; + return "httpd/unix-directory"; } else { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->filetype(getInternalPath($source)); + return $storage->filetype(self::getInternalPath($source)); } } @@ -129,7 +129,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->filesize(getInternalPath($source)); + return $storage->filesize(self::getInternalPath($source)); } } } @@ -142,7 +142,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->is_readable(getInternalPath($source)); + return $storage->is_readable(self::getInternalPath($source)); } } } @@ -155,7 +155,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->is_writeable(getInternalPath($source)); + return $storage->is_writeable(self::getInternalPath($source)); } } } @@ -167,7 +167,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->file_exists(getInternalPath($source)); + return $storage->file_exists(self::getInternalPath($source)); } } } @@ -176,7 +176,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->readfile(getInternalPath($source)); + return $storage->readfile(self::getInternalPath($source)); } } @@ -188,7 +188,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->filectime(getInternalPath($source)); + return $storage->filectime(self::getInternalPath($source)); } } } @@ -201,7 +201,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->filemtime(getInternalPath($source)); + return $storage->filemtime(self::getInternalPath($source)); } } } @@ -214,7 +214,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->fileatime(getInternalPath($source)); + return $storage->fileatime(self::getInternalPath($source)); } } } @@ -223,7 +223,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->file_get_contents(getInternalPath($source)); + return $storage->file_get_contents(self::getInternalPath($source)); } } @@ -232,7 +232,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->file_put_contents(getInternalPath($source), $data); + return $storage->file_put_contents(self::getInternalPath($source), $data); } } @@ -240,7 +240,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->unlink(getInternalPath($source)); + return $storage->unlink(self::getInternalPath($source)); } } @@ -250,7 +250,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path1); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->rename(getInternalPath($source), $path2); + return $storage->rename(self::getInternalPath($source), $path2); } } @@ -258,7 +258,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path1); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->copy(getInternalPath($source), $path2); + return $storage->copy(self::getInternalPath($source), $path2); } } @@ -266,7 +266,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->fopen(getInternalPath($source), $mode); + return $storage->fopen(self::getInternalPath($source), $mode); } } @@ -274,7 +274,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->toTmpFile(getInternalPath($source)); + return $storage->toTmpFile(self::getInternalPath($source)); } } @@ -282,7 +282,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($tmpPath); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->fromTmpFile(getInternalPath($source), $path); + return $storage->fromTmpFile(self::getInternalPath($source), $path); } } @@ -290,7 +290,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($tmpPath); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->fromUploadedFile(getInternalPath($source), $path); + return $storage->fromUploadedFile(self::getInternalPath($source), $path); } } @@ -298,7 +298,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->getMimeType(getInternalPath($source)); + return $storage->getMimeType(self::getInternalPath($source)); } } @@ -306,7 +306,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->delTree(getInternalPath($source)); + return $storage->delTree(self::getInternalPath($source)); } } @@ -314,7 +314,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->find(getInternalPath($source)); + return $storage->find(self::getInternalPath($source)); } } @@ -322,7 +322,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->getTree(getInternalPath($source)); + return $storage->getTree(self::getInternalPath($source)); } } @@ -330,7 +330,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->hash($type, getInternalPath($source), $raw); + return $storage->hash($type, self::getInternalPath($source), $raw); } } @@ -338,7 +338,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->free_space(getInternalPath($source)); + return $storage->free_space(self::getInternalPath($source)); } } diff --git a/lib/filesystem.php b/lib/filesystem.php index 897efaa140..a13363f832 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -169,7 +169,7 @@ class OC_FILESYSTEM{ * @param string path * @return string */ - static private function getMountPoint($path){ + static public function getMountPoint($path){ if(!$path){ $path='/'; } From 18e776fa2f9c3d304e06e492c5b5e6059add9bd8 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 22 Jun 2011 11:40:09 -0400 Subject: [PATCH 007/122] Changed mount point to 'Share', fixed is_dir() --- apps/files_sharing/sharedstorage.php | 12 ++++++++++-- lib/base.php | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index bf6116c9eb..4bb2ceb7c0 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -58,9 +58,14 @@ class OC_FILESTORAGE_SHARED { } } + // TODO add all files from db in array public function opendir($path) { global $FAKEDIRS; - $FAKEDIRS['shared'] = array(0 => 'test.txt'); + $sharedItems = OC_SHARE::getItemsSharedWith(); + foreach ($sharedItems as $item) { + $files[] = $item['target']; + } + $FAKEDIRS['shared'] = $files; return opendir('fakedir://shared'); } @@ -83,6 +88,8 @@ class OC_FILESTORAGE_SHARED { return $storage->is_file(self::getInternalPath($source)); } } + + // TODO fill in other components of array public function stat($path) { if ($path == "" || $path == "/") { $stat["dev"] = ""; @@ -110,7 +117,7 @@ class OC_FILESTORAGE_SHARED { public function filetype($path) { if ($path == "" || $path == "/") { - return "httpd/unix-directory"; + return "dir"; } else { $source = OC_SHARE::getSource($path); if ($source) { @@ -123,6 +130,7 @@ class OC_FILESTORAGE_SHARED { // TODO Get size of shared directory public function filesize($path) { + echo "filesize"; if ($path == "" || $path == "/") { return 10000; } else { diff --git a/lib/base.php b/lib/base.php index 199653e25e..04f8f5c9fa 100644 --- a/lib/base.php +++ b/lib/base.php @@ -158,8 +158,9 @@ class OC_UTIL { // } OC_FILESYSTEM::mount($rootStorage,'/'); + // TODO add this storage provider in a proper way $sharedStorage = OC_FILESYSTEM::createStorage('shared',array('datadir'=>$CONFIG_DATADIRECTORY)); - OC_FILESYSTEM::mount($sharedStorage,'MTGap/files/Test/'); + OC_FILESYSTEM::mount($sharedStorage,'MTGap/files/Share/'); $CONFIG_DATADIRECTORY = "$CONFIG_DATADIRECTORY_ROOT/$user/$root"; if( !is_dir( $CONFIG_DATADIRECTORY )){ From ac0d41418e9639ca2d6d8c71ce499b108708b6af Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 22 Jun 2011 17:55:07 -0400 Subject: [PATCH 008/122] Correct calculation for shared folder size --- apps/files_sharing/sharedstorage.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 4bb2ceb7c0..5b2ccbd473 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -128,11 +128,14 @@ class OC_FILESTORAGE_SHARED { } - // TODO Get size of shared directory public function filesize($path) { - echo "filesize"; if ($path == "" || $path == "/") { - return 10000; + $size = 0; + $dir = OC_FILESTORAGE_SHARED::opendir($path); + while (($filename = readdir($dir)) != false) { + $size += OC_FILESTORAGE_SHARED::filesize($filename); + } + return $size; } else { $source = OC_SHARE::getSource($path); if ($source) { From 098fc5ef95c60e5e9ff5e049d80d8dc82aef5e8a Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 22 Jun 2011 18:16:41 -0400 Subject: [PATCH 009/122] Fixed stat(), file?time()'s now grab most recent time from shared files --- apps/files_sharing/sharedstorage.php | 38 +++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 5b2ccbd473..a66066aeb9 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -99,10 +99,10 @@ class OC_FILESTORAGE_SHARED { $stat["uid"] = ""; $stat["gid"] = ""; $stat["rdev"] = ""; - $stat["size"] = filesize($path); - $stat["atime"] = fileatime($path); - $stat["mtime"] = filemtime($path); - $stat["ctime"] = filectime($path); + $stat["size"] = OC_FILESTORAGE_SHARED::filesize($path); + $stat["atime"] = OC_FILESTORAGE_SHARED::fileatime($path); + $stat["mtime"] = OC_FILESTORAGE_SHARED::filemtime($path); + $stat["ctime"] = OC_FILESTORAGE_SHARED::filectime($path); $stat["blksize"] = ""; $stat["blocks"] = ""; return $stat; @@ -194,7 +194,15 @@ class OC_FILESTORAGE_SHARED { // TODO Get ctime of last file public function filectime($path) { if ($path == "" || $path == "/") { - return 10000003232; + $ctime = 0; + $dir = OC_FILESTORAGE_SHARED::opendir($path); + while (($filename = readdir($dir)) != false) { + $tempctime = OC_FILESTORAGE_SHARED::filectime($filename); + if ($tempctime > $ctime) { + $ctime = $tempctime; + } + } + return $ctime; } else { $source = OC_SHARE::getSource($path); if ($source) { @@ -207,7 +215,15 @@ class OC_FILESTORAGE_SHARED { // TODO Get mtime of last file public function filemtime($path) { if ($path == "" || $path == "/") { - return 10000003232; + $mtime = 0; + $dir = OC_FILESTORAGE_SHARED::opendir($path); + while (($filename = readdir($dir)) != false) { + $tempmtime = OC_FILESTORAGE_SHARED::filemtime($filename); + if ($tempmtime > $mtime) { + $mtime = $tempmtime; + } + } + return $mtime; } else { $source = OC_SHARE::getSource($path); if ($source) { @@ -220,7 +236,15 @@ class OC_FILESTORAGE_SHARED { // TODO Get atime of last file public function fileatime($path) { if ($path == "" || $path == "/") { - return 10000003232; + $atime = 0; + $dir = OC_FILESTORAGE_SHARED::opendir($path); + while (($filename = readdir($dir)) != false) { + $tempatime = OC_FILESTORAGE_SHARED::fileatime($filename); + if ($tempatime > $atime) { + $atime = $tempatime; + } + } + return $atime; } else { $source = OC_SHARE::getSource($path); if ($source) { From 3f5fde50c1ab4f403b7ec78005db843e2c971952 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 22 Jun 2011 18:22:48 -0400 Subject: [PATCH 010/122] Forgot to remove TODOs for file?time()s --- apps/files_sharing/sharedstorage.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index a66066aeb9..feb5d0057d 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -191,7 +191,6 @@ class OC_FILESTORAGE_SHARED { } } - // TODO Get ctime of last file public function filectime($path) { if ($path == "" || $path == "/") { $ctime = 0; @@ -212,7 +211,6 @@ class OC_FILESTORAGE_SHARED { } } - // TODO Get mtime of last file public function filemtime($path) { if ($path == "" || $path == "/") { $mtime = 0; @@ -233,7 +231,6 @@ class OC_FILESTORAGE_SHARED { } } - // TODO Get atime of last file public function fileatime($path) { if ($path == "" || $path == "/") { $atime = 0; From e3ea84d048809318a90f3cb16341e67093090a0a Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 22 Jun 2011 19:17:31 -0400 Subject: [PATCH 011/122] Changed ctime for the shared folder to the earliest ctime --- apps/files_sharing/sharedstorage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index feb5d0057d..269ede7422 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -197,7 +197,7 @@ class OC_FILESTORAGE_SHARED { $dir = OC_FILESTORAGE_SHARED::opendir($path); while (($filename = readdir($dir)) != false) { $tempctime = OC_FILESTORAGE_SHARED::filectime($filename); - if ($tempctime > $ctime) { + if ($tempctime < $ctime) { $ctime = $tempctime; } } From 87097db4eb5a3b4985223d4b34b7970f904ae5bb Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 22 Jun 2011 19:47:57 -0400 Subject: [PATCH 012/122] Changed self:: and OC_FILESTORAGE_SHARED to -> --- apps/files_sharing/sharedstorage.php | 84 ++++++++++++++-------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 269ede7422..808a05f921 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -34,7 +34,7 @@ class OC_FILESTORAGE_SHARED { } - public static function getInternalPath($path) { + public function getInternalPath($path) { $mountPoint = OC_FILESYSTEM::getMountPoint($path); $internalPath = substr($path,strlen($mountPoint)); return $internalPath; @@ -45,7 +45,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->mkdir(self::getInternalPath($source)); + return $storage->mkdir($this->getInternalPath($source)); } } @@ -54,7 +54,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->rmdir(self::getInternalPath($source)); + return $storage->rmdir($this->getInternalPath($source)); } } @@ -76,7 +76,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->is_dir(self::getInternalPath($source)); + return $storage->is_dir($this->getInternalPath($source)); } } } @@ -85,7 +85,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->is_file(self::getInternalPath($source)); + return $storage->is_file($this->getInternalPath($source)); } } @@ -99,10 +99,10 @@ class OC_FILESTORAGE_SHARED { $stat["uid"] = ""; $stat["gid"] = ""; $stat["rdev"] = ""; - $stat["size"] = OC_FILESTORAGE_SHARED::filesize($path); - $stat["atime"] = OC_FILESTORAGE_SHARED::fileatime($path); - $stat["mtime"] = OC_FILESTORAGE_SHARED::filemtime($path); - $stat["ctime"] = OC_FILESTORAGE_SHARED::filectime($path); + $stat["size"] = $this->filesize($path); + $stat["atime"] = $this->fileatime($path); + $stat["mtime"] = $this->filemtime($path); + $stat["ctime"] = $this->filectime($path); $stat["blksize"] = ""; $stat["blocks"] = ""; return $stat; @@ -110,7 +110,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->stat(self::getInternalPath($source)); + return $storage->stat($this->getInternalPath($source)); } } } @@ -122,7 +122,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->filetype(self::getInternalPath($source)); + return $storage->filetype($this->getInternalPath($source)); } } @@ -131,16 +131,16 @@ class OC_FILESTORAGE_SHARED { public function filesize($path) { if ($path == "" || $path == "/") { $size = 0; - $dir = OC_FILESTORAGE_SHARED::opendir($path); + $dir = $this->opendir($path); while (($filename = readdir($dir)) != false) { - $size += OC_FILESTORAGE_SHARED::filesize($filename); + $size += $this->filesize($filename); } return $size; } else { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->filesize(self::getInternalPath($source)); + return $storage->filesize($this->getInternalPath($source)); } } } @@ -153,7 +153,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->is_readable(self::getInternalPath($source)); + return $storage->is_readable($this->getInternalPath($source)); } } } @@ -166,7 +166,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->is_writeable(self::getInternalPath($source)); + return $storage->is_writeable($this->getInternalPath($source)); } } } @@ -178,7 +178,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->file_exists(self::getInternalPath($source)); + return $storage->file_exists($this->getInternalPath($source)); } } } @@ -187,16 +187,16 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->readfile(self::getInternalPath($source)); + return $storage->readfile($this->getInternalPath($source)); } } public function filectime($path) { if ($path == "" || $path == "/") { $ctime = 0; - $dir = OC_FILESTORAGE_SHARED::opendir($path); + $dir = $this->opendir($path); while (($filename = readdir($dir)) != false) { - $tempctime = OC_FILESTORAGE_SHARED::filectime($filename); + $tempctime = $this->filectime($filename); if ($tempctime < $ctime) { $ctime = $tempctime; } @@ -206,7 +206,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->filectime(self::getInternalPath($source)); + return $storage->filectime($this->getInternalPath($source)); } } } @@ -214,9 +214,9 @@ class OC_FILESTORAGE_SHARED { public function filemtime($path) { if ($path == "" || $path == "/") { $mtime = 0; - $dir = OC_FILESTORAGE_SHARED::opendir($path); + $dir = $this->opendir($path); while (($filename = readdir($dir)) != false) { - $tempmtime = OC_FILESTORAGE_SHARED::filemtime($filename); + $tempmtime = $this->filemtime($filename); if ($tempmtime > $mtime) { $mtime = $tempmtime; } @@ -226,7 +226,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->filemtime(self::getInternalPath($source)); + return $storage->filemtime($this->getInternalPath($source)); } } } @@ -234,9 +234,9 @@ class OC_FILESTORAGE_SHARED { public function fileatime($path) { if ($path == "" || $path == "/") { $atime = 0; - $dir = OC_FILESTORAGE_SHARED::opendir($path); + $dir = $this->opendir($path); while (($filename = readdir($dir)) != false) { - $tempatime = OC_FILESTORAGE_SHARED::fileatime($filename); + $tempatime = $this->fileatime($filename); if ($tempatime > $atime) { $atime = $tempatime; } @@ -246,7 +246,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->fileatime(self::getInternalPath($source)); + return $storage->fileatime($this->getInternalPath($source)); } } } @@ -255,7 +255,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->file_get_contents(self::getInternalPath($source)); + return $storage->file_get_contents($this->getInternalPath($source)); } } @@ -264,7 +264,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->file_put_contents(self::getInternalPath($source), $data); + return $storage->file_put_contents($this->getInternalPath($source), $data); } } @@ -272,7 +272,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->unlink(self::getInternalPath($source)); + return $storage->unlink($this->getInternalPath($source)); } } @@ -282,7 +282,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path1); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->rename(self::getInternalPath($source), $path2); + return $storage->rename($this->getInternalPath($source), $path2); } } @@ -290,7 +290,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path1); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->copy(self::getInternalPath($source), $path2); + return $storage->copy($this->getInternalPath($source), $path2); } } @@ -298,7 +298,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->fopen(self::getInternalPath($source), $mode); + return $storage->fopen($this->getInternalPath($source), $mode); } } @@ -306,7 +306,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->toTmpFile(self::getInternalPath($source)); + return $storage->toTmpFile($this->getInternalPath($source)); } } @@ -314,7 +314,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($tmpPath); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->fromTmpFile(self::getInternalPath($source), $path); + return $storage->fromTmpFile($this->getInternalPath($source), $path); } } @@ -322,7 +322,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($tmpPath); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->fromUploadedFile(self::getInternalPath($source), $path); + return $storage->fromUploadedFile($this->getInternalPath($source), $path); } } @@ -330,7 +330,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->getMimeType(self::getInternalPath($source)); + return $storage->getMimeType($this->getInternalPath($source)); } } @@ -338,7 +338,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->delTree(self::getInternalPath($source)); + return $storage->delTree($this->getInternalPath($source)); } } @@ -346,7 +346,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->find(self::getInternalPath($source)); + return $storage->find($this->getInternalPath($source)); } } @@ -354,7 +354,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->getTree(self::getInternalPath($source)); + return $storage->getTree($this->getInternalPath($source)); } } @@ -362,7 +362,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->hash($type, self::getInternalPath($source), $raw); + return $storage->hash($type, $this->getInternalPath($source), $raw); } } @@ -370,7 +370,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->free_space(self::getInternalPath($source)); + return $storage->free_space($this->getInternalPath($source)); } } From 8cbee2841604b614fe87d2e671ed15836f169a6e Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 22 Jun 2011 21:05:31 -0400 Subject: [PATCH 013/122] Better implementation of filesize for shared directory, now storing in oc_foldersize --- apps/files_sharing/sharedstorage.php | 47 +++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 808a05f921..a4d0b2354b 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -129,13 +129,8 @@ class OC_FILESTORAGE_SHARED { } public function filesize($path) { - if ($path == "" || $path == "/") { - $size = 0; - $dir = $this->opendir($path); - while (($filename = readdir($dir)) != false) { - $size += $this->filesize($filename); - } - return $size; + if ($path == "" || $path == "/" || $this->is_dir($path)) { + return $this->getFolderSize($path); } else { $source = OC_SHARE::getSource($path); if ($source) { @@ -145,6 +140,44 @@ class OC_FILESTORAGE_SHARED { } } + public function getFolderSize($path) { + if ($path == "" || $path == "/") { + $dbpath = $_SESSION['user_id']."/files/Share/"; + } else { + $dbpath = $path; + } + $query = OC_DB::prepare("SELECT size FROM *PREFIX*foldersize WHERE path=?"); + $size = $query->execute(array($dbpath))->fetchAll(); + if (count($size) > 0) { + return $size[0]['size']; + } else { + return $this->calculateFolderSize($path); + } + } + + public function calculateFolderSize($path) { + $size = 0; + if ($dh = $this->opendir($path)) { + while (($filename = readdir($dh)) != false) { + if ($this->is_file($filename)){ + $size += $this->filesize($filename); + } else { + $size += $this->getFolderSize($filename); + } + } + if ($size > 0) { + if ($path == "" || $path == "/") { + $dbpath = $_SESSION['user_id']."/files/Share/"; + } else { + $dbpath = $path; + } + $query = OC_DB::prepare("INSERT INTO *PREFIX*foldersize VALUES(?,?)"); + $result = $query->execute(array($dbpath, $size)); + } + } + return $size; + } + // TODO OC_SHARE::getPermissions() public function is_readable($path) { if ($path == "" || $path == "/") { From e91f42d249fde59ca841ebfe0c5fe10adbeb4a07 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Fri, 24 Jun 2011 19:20:08 -0400 Subject: [PATCH 014/122] Add support for sharing folders --- apps/files_sharing/appinfo/app.php | 3 +-- apps/files_sharing/lib_share.php | 11 +++++++++-- apps/files_sharing/sharedstorage.php | 23 +++++++++++++++-------- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index 359e26b16f..a559026c5b 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -1,7 +1,6 @@ "files_sharing_administration", +OC_APP::addSettingsPage( array( "id" => "files_sharing_administration", "order" => 10, "href" => OC_HELPER::linkTo( "files_sharing", "admin.php" ), "name" => "Share", diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index b739656acf..a37f7da8ca 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -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; } /** diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index a4d0b2354b..4e0089b2c0 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -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(); From c8781b1caf2e32fafa18878758d221bce382cd8b Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Fri, 24 Jun 2011 19:38:39 -0400 Subject: [PATCH 015/122] Add error handling for getSource() --- apps/files_sharing/lib_share.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index a37f7da8ca..1bf1ea8242 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -85,12 +85,16 @@ class OC_SHARE { $parts = explode("/", $target); $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ?"); $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; + if (count($result) > 0) { + $source = $result[0]['source']; + // Add the $parts back in + foreach (array_slice($parts, 1) as $part) { + $source .= $part; + } + return $source; + } else { + return false; } - return $source; } /** From 78293ea244e68cc0ebbebb4d8ccadc85fe9c0daa Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Fri, 24 Jun 2011 19:52:35 -0400 Subject: [PATCH 016/122] Better implementation of getting shared folder size by using the source path --- apps/files_sharing/sharedstorage.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 4e0089b2c0..b434331b9e 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -151,7 +151,8 @@ class OC_FILESTORAGE_SHARED { if ($path == "" || $path == "/") { $dbpath = $_SESSION['user_id']."/files/Share/"; } else { - $dbpath = substr(OC_SHARE::getSource($path), 1); + $source = OC_SHARE::getSource($path); + $dbpath = $this->getInternalPath($source); } $query = OC_DB::prepare("SELECT size FROM *PREFIX*foldersize WHERE path=?"); $size = $query->execute(array($dbpath))->fetchAll(); @@ -166,7 +167,7 @@ class OC_FILESTORAGE_SHARED { $size = 0; if ($dh = $this->opendir($path)) { while (($filename = readdir($dh)) != false) { - if ($this->is_file($filename)){ + if ($this->is_file($filename)) { $size += $this->filesize($filename); } else { $size += $this->getFolderSize($filename); From 12c168b6dd277e656e9806179f1519840b0fe605 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sat, 25 Jun 2011 22:00:52 -0400 Subject: [PATCH 017/122] Add function setTarget(), implement recursion in getSource() for folders --- apps/files_sharing/lib_share.php | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 1bf1ea8242..6bb36615b1 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -78,25 +78,36 @@ class OC_SHARE { /** * Get the source location of the target item + * @param $target * @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($parts[0], $_SESSION['user_id']))->fetchAll(); + $result = $query->execute(array($target, $_SESSION['user_id']))->fetchAll(); if (count($result) > 0) { - $source = $result[0]['source']; - // Add the $parts back in - foreach (array_slice($parts, 1) as $part) { - $source .= $part; - } - return $source; + return $result[0]['source']; } else { - return false; + // Check if the directory above this target is shared + $parentDir = substr($target, 0, strrpos($target, "/")); + if ($parentDir) { + $result = OC_SHARE::getSource($parentDir); + return $result.substr($target, strrpos($target, "/")); + } else { + return false; + } } } + /** + * Set the target location to a new value + * @param $oldTarget The current target location + * @param $newTarget The new target location + */ + public static function setTarget($oldTarget, $newTarget) { + $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET target = ? WHERE target = ? AND uid_shared_with = ?"); + $query->execute(array($newTarget, $oldTarget, $_SESSION['user_id'])); + } + /** * Get all items the user is sharing * @return array From fe178310f3a229ef1a61fcb9187cca92b82e2cdd Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 26 Jun 2011 19:21:24 -0400 Subject: [PATCH 018/122] Use php functions dirname() and basename() instead of manipulating strings in getSource() --- apps/files_sharing/lib_share.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 6bb36615b1..e64fed6f64 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -88,10 +88,10 @@ class OC_SHARE { return $result[0]['source']; } else { // Check if the directory above this target is shared - $parentDir = substr($target, 0, strrpos($target, "/")); + $parentDir = dirname($target); if ($parentDir) { $result = OC_SHARE::getSource($parentDir); - return $result.substr($target, strrpos($target, "/")); + return $result."/".basename($target); } else { return false; } From a402c8ffe1c951ec8630eec791fdc2f1bfe9c3d0 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Mon, 27 Jun 2011 11:47:36 -0400 Subject: [PATCH 019/122] Implement caching for source paths in OC_FILESTORAGE_SHARED --- apps/files_sharing/sharedstorage.php | 101 +++++++++++++++++---------- 1 file changed, 63 insertions(+), 38 deletions(-) diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index b434331b9e..f7f156c760 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -29,6 +29,8 @@ OC_FILESYSTEM::registerStorageType('shared','OC_FILESTORAGE_SHARED',array('datad */ class OC_FILESTORAGE_SHARED { + private $sourcePaths = array(); + // TODO uh... I don't know what to do here public function __construct($parameters) { @@ -36,13 +38,24 @@ class OC_FILESTORAGE_SHARED { public function getInternalPath($path) { $mountPoint = OC_FILESYSTEM::getMountPoint($path); - $internalPath = substr($path,strlen($mountPoint)); + $internalPath = substr($path, strlen($mountPoint)); return $internalPath; } + public function getSource($target) { + print_r($this->sourcePaths); + if (array_key_exists($target, $this->sourcePaths)) { + return $this->sourcePaths[$target]; + } else { + $source = OC_SHARE::getSource($target); + $this->sourcePaths[$target] = $source; + return $source; + } + } + // TODO OC_SHARE::getPermissions() public function mkdir($path) { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->mkdir($this->getInternalPath($source)); @@ -51,7 +64,7 @@ class OC_FILESTORAGE_SHARED { // TODO OC_SHARE::getPermissions() public function rmdir($path) { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->rmdir($this->getInternalPath($source)); @@ -68,7 +81,7 @@ class OC_FILESTORAGE_SHARED { $FAKEDIRS['shared'] = $files; return opendir('fakedir://shared'); } else { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->opendir($this->getInternalPath($source)); @@ -80,7 +93,7 @@ class OC_FILESTORAGE_SHARED { if ($path == "" || $path == "/") { return true; } else { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->is_dir($this->getInternalPath($source)); @@ -89,7 +102,7 @@ class OC_FILESTORAGE_SHARED { } public function is_file($path) { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->is_file($this->getInternalPath($source)); @@ -114,7 +127,7 @@ class OC_FILESTORAGE_SHARED { $stat["blocks"] = ""; return $stat; } else { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->stat($this->getInternalPath($source)); @@ -126,7 +139,7 @@ class OC_FILESTORAGE_SHARED { if ($path == "" || $path == "/") { return "dir"; } else { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->filetype($this->getInternalPath($source)); @@ -139,7 +152,7 @@ class OC_FILESTORAGE_SHARED { if ($path == "" || $path == "/" || $this->is_dir($path)) { return $this->getFolderSize($path); } else { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->filesize($this->getInternalPath($source)); @@ -148,10 +161,11 @@ class OC_FILESTORAGE_SHARED { } public function getFolderSize($path) { + return 10000; if ($path == "" || $path == "/") { $dbpath = $_SESSION['user_id']."/files/Share/"; } else { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); $dbpath = $this->getInternalPath($source); } $query = OC_DB::prepare("SELECT size FROM *PREFIX*foldersize WHERE path=?"); @@ -164,20 +178,31 @@ class OC_FILESTORAGE_SHARED { } public function calculateFolderSize($path) { + if ($this->is_file($path)) { + $path = dirname($path); + } + $path = str_replace("//", "/", $path); + if ($this->is_dir($path) && substr($path, -1) != "/") { + $path .= "/"; + } $size = 0; if ($dh = $this->opendir($path)) { - while (($filename = readdir($dh)) != false) { - if ($this->is_file($filename)) { - $size += $this->filesize($filename); - } else { - $size += $this->getFolderSize($filename); + 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) { if ($path == "" || $path == "/") { $dbpath = $_SESSION['user_id']."/files/Share/"; } else { - $dbpath = $path; + $source = $this->getSource($path); + $dbpath = $this->getInternalPath($source); } $query = OC_DB::prepare("INSERT INTO *PREFIX*foldersize VALUES(?,?)"); $result = $query->execute(array($dbpath, $size)); @@ -191,7 +216,7 @@ class OC_FILESTORAGE_SHARED { if ($path == "" || $path == "/") { return true; } else { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->is_readable($this->getInternalPath($source)); @@ -204,7 +229,7 @@ class OC_FILESTORAGE_SHARED { if ($path == "" || $path == "/") { return true; } else { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->is_writeable($this->getInternalPath($source)); @@ -216,7 +241,7 @@ class OC_FILESTORAGE_SHARED { if ($path == "" || $path == "/") { return true; } else { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->file_exists($this->getInternalPath($source)); @@ -225,7 +250,7 @@ class OC_FILESTORAGE_SHARED { } public function readfile($path) { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->readfile($this->getInternalPath($source)); @@ -244,7 +269,7 @@ class OC_FILESTORAGE_SHARED { } return $ctime; } else { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->filectime($this->getInternalPath($source)); @@ -264,7 +289,7 @@ class OC_FILESTORAGE_SHARED { } return $mtime; } else { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->filemtime($this->getInternalPath($source)); @@ -284,7 +309,7 @@ class OC_FILESTORAGE_SHARED { } return $atime; } else { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->fileatime($this->getInternalPath($source)); @@ -293,7 +318,7 @@ class OC_FILESTORAGE_SHARED { } public function file_get_contents($path) { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->file_get_contents($this->getInternalPath($source)); @@ -302,7 +327,7 @@ class OC_FILESTORAGE_SHARED { // TODO OC_SHARE::getPermissions() public function file_put_contents($path, $data) { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->file_put_contents($this->getInternalPath($source), $data); @@ -310,7 +335,7 @@ class OC_FILESTORAGE_SHARED { } public function unlink($path) { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->unlink($this->getInternalPath($source)); @@ -320,7 +345,7 @@ class OC_FILESTORAGE_SHARED { // TODO OC_SHARE::getPermissions() // TODO Update shared item location public function rename($path1, $path2) { - $source = OC_SHARE::getSource($path1); + $source = $this->getSource($path1); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->rename($this->getInternalPath($source), $path2); @@ -328,7 +353,7 @@ class OC_FILESTORAGE_SHARED { } public function copy($path1, $path2) { - $source = OC_SHARE::getSource($path1); + $source = $this->getSource($path1); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->copy($this->getInternalPath($source), $path2); @@ -336,7 +361,7 @@ class OC_FILESTORAGE_SHARED { } public function fopen($path, $mode) { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->fopen($this->getInternalPath($source), $mode); @@ -344,7 +369,7 @@ class OC_FILESTORAGE_SHARED { } public function toTmpFile($path) { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->toTmpFile($this->getInternalPath($source)); @@ -352,7 +377,7 @@ class OC_FILESTORAGE_SHARED { } public function fromTmpFile($tmpPath, $path) { - $source = OC_SHARE::getSource($tmpPath); + $source = $this->getSource($tmpPath); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->fromTmpFile($this->getInternalPath($source), $path); @@ -360,7 +385,7 @@ class OC_FILESTORAGE_SHARED { } public function fromUploadedFile($tmpPath, $path) { - $source = OC_SHARE::getSource($tmpPath); + $source = $this->getSource($tmpPath); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->fromUploadedFile($this->getInternalPath($source), $path); @@ -368,7 +393,7 @@ class OC_FILESTORAGE_SHARED { } public function getMimeType($path) { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->getMimeType($this->getInternalPath($source)); @@ -376,7 +401,7 @@ class OC_FILESTORAGE_SHARED { } public function delTree($path) { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->delTree($this->getInternalPath($source)); @@ -384,7 +409,7 @@ class OC_FILESTORAGE_SHARED { } public function find($path) { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->find($this->getInternalPath($source)); @@ -392,7 +417,7 @@ class OC_FILESTORAGE_SHARED { } public function getTree($path) { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->getTree($this->getInternalPath($source)); @@ -400,7 +425,7 @@ class OC_FILESTORAGE_SHARED { } public function hash($type, $path, $raw) { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->hash($type, $this->getInternalPath($source), $raw); @@ -408,7 +433,7 @@ class OC_FILESTORAGE_SHARED { } public function free_space($path) { - $source = OC_SHARE::getSource($path); + $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->free_space($this->getInternalPath($source)); From 053edde780204ac40839b39b2d2ee0514830fabc Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Mon, 27 Jun 2011 12:53:10 -0400 Subject: [PATCH 020/122] Improvements to caching for shared folders --- apps/files_sharing/sharedstorage.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index f7f156c760..e17685a09e 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -43,13 +43,22 @@ class OC_FILESTORAGE_SHARED { } public function getSource($target) { - print_r($this->sourcePaths); - if (array_key_exists($target, $this->sourcePaths)) { + if ($target == "") { + return false; + } elseif (array_key_exists($target, $this->sourcePaths)) { return $this->sourcePaths[$target]; } else { - $source = OC_SHARE::getSource($target); - $this->sourcePaths[$target] = $source; - return $source; + $parentDir = dirname($target); + if ($parentDir != ".") { + $source = $this->getSource($parentDir); + return $source."/".basename($target); + } else { + $source = OC_SHARE::getSource($target); + if ($source) { + $this->sourcePaths[$target] = $source; + } + return $source; + } } } From b03083b881ed48681b3977ec069a596f72af4573 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Mon, 27 Jun 2011 18:14:04 -0400 Subject: [PATCH 021/122] Fix check for parentDir and fix the return for a nonexistent target in the database --- apps/files_sharing/lib_share.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index e64fed6f64..a2fb5161d9 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -87,11 +87,15 @@ class OC_SHARE { if (count($result) > 0) { return $result[0]['source']; } else { - // Check if the directory above this target is shared + // Check if the parent directory of this target is shared $parentDir = dirname($target); - if ($parentDir) { + if ($parentDir != ".") { $result = OC_SHARE::getSource($parentDir); - return $result."/".basename($target); + if ($result) { + return $result."/".basename($target); + } else { + return false; + } } else { return false; } From e24e2d0e16a360753cc0430f2ba75f903c669b14 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 3 Jul 2011 11:43:49 -0400 Subject: [PATCH 022/122] Append LIMIT 1 to getSource queries to improve performance --- apps/files_sharing/lib_share.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index a2fb5161d9..b03720b753 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -82,7 +82,7 @@ class OC_SHARE { * @return source path */ public static function getSource($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 = ? LIMIT 1"); $result = $query->execute(array($target, $_SESSION['user_id']))->fetchAll(); if (count($result) > 0) { return $result[0]['source']; From 607f1a2738911ace1026c6bc14aa28481a898897 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Mon, 4 Jul 2011 16:45:19 -0400 Subject: [PATCH 023/122] Fix conflicts with master in lib/base.php --- lib/base.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/base.php b/lib/base.php index e821d78fd8..4250274c7c 100644 --- a/lib/base.php +++ b/lib/base.php @@ -84,12 +84,9 @@ require_once('appconfig.php'); require_once('files.php'); require_once('filesystem.php'); require_once('filestorage.php'); -<<<<<<< HEAD require_once('apps/files_sharing/sharedstorage.php'); -======= require_once('l10n.php'); require_once('preferences.php'); ->>>>>>> master require_once('log.php'); require_once('user.php'); require_once('group.php'); From 9deab8302f4c41daed3db6f3b470480b2710c502 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Tue, 5 Jul 2011 11:56:02 -0400 Subject: [PATCH 024/122] Fix bugs in getSource() and implement new target path standard --- apps/files_sharing/lib_share.php | 4 +++- apps/files_sharing/sharedstorage.php | 19 +++++-------------- lib/filesystem.php | 10 ++++++++++ 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index b03720b753..77b0bc4a70 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -82,6 +82,8 @@ class OC_SHARE { * @return source path */ public static function getSource($target) { + // Remove any trailing '/' + $target = rtrim($target, "/"); $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1"); $result = $query->execute(array($target, $_SESSION['user_id']))->fetchAll(); if (count($result) > 0) { @@ -89,7 +91,7 @@ class OC_SHARE { } else { // Check if the parent directory of this target is shared $parentDir = dirname($target); - if ($parentDir != ".") { + if ($parentDir != "" && $parentDir != "/" && $parentDir != ".") { $result = OC_SHARE::getSource($parentDir); if ($result) { return $result."/".basename($target); diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index e17685a09e..0303cce79f 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -43,22 +43,13 @@ class OC_FILESTORAGE_SHARED { } public function getSource($target) { - if ($target == "") { - return false; - } elseif (array_key_exists($target, $this->sourcePaths)) { + $target = OC_FILESYSTEM::getStorageMountPoint($this).$target; + if (array_key_exists($target, $this->sourcePaths)) { return $this->sourcePaths[$target]; } else { - $parentDir = dirname($target); - if ($parentDir != ".") { - $source = $this->getSource($parentDir); - return $source."/".basename($target); - } else { - $source = OC_SHARE::getSource($target); - if ($source) { - $this->sourcePaths[$target] = $source; - } - return $source; - } + $source = OC_SHARE::getSource($target); + $this->sourcePaths[$target] = $source; + return $source; } } diff --git a/lib/filesystem.php b/lib/filesystem.php index 4116cb9316..c7e2070fa0 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -214,6 +214,16 @@ class OC_FILESYSTEM{ } return $foundMountPoint; } + + /** + * get the mountpoint of the storage object + * @param OC_FILESTORAGE storage + * @return string + */ + static public function getStorageMountPoint($storage){ + return array_search($storage, self::$storages); + } + /** * return the path to a local version of the file * we need this because we can't know if a file is stored local or not from outside the filestorage and for some purposes a local file is needed From cf33995892d269921b0a941d3df887c011d7c93a Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 6 Jul 2011 12:12:29 -0400 Subject: [PATCH 025/122] Refactor OC_SHARE to allow for renaming and write permissions --- apps/files_sharing/lib_share.php | 117 ++++++++++++++++++++------- apps/files_sharing/sharedstorage.php | 31 ++----- 2 files changed, 96 insertions(+), 52 deletions(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 77b0bc4a70..cc471f278d 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -31,38 +31,60 @@ class OC_SHARE { * @param string $item * @param user item shared with $uid_shared_with */ - public function __construct($item, $uid_shared_with, $public = false) { - if ($item && OC_FILESYSTEM::file_exists($item) && OC_FILESYSTEM::is_readable($item)) { + public function __construct($source, $uid_shared_with, $permissions, $public = false) { + if ($source && OC_FILESYSTEM::file_exists($source) && OC_FILESYSTEM::is_readable($source)) { $uid_owner = $_SESSION['user_id']; if ($public) { // TODO create token for public file $token = sha1("$uid_owner-$item"); } else { - $query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?)"); + $query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)"); + $sourceLocalPath = substr($source, strlen("/".$uid_owner."/files/"));; foreach ($uid_shared_with as $uid) { - $query->execute(array($uid_owner, $uid, $item)); + // TODO check to see if target already exists in database + $target = "/".$uid."/files/Share/".$sourceLocalPath; + $query->execute(array($uid_owner, $uid, $source, $target, $permissions)); } } } } /** - * TODO complete lib_permissions - * Change the permissions of the specified item - * @param permissions $permissions + * Change is writeable for the specified item and user + * @param $source + * @param $uid_shared_with + * @param $is_writeable */ - public static function setPermissions($item, $uid_shared_with, $permissions) { - $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET permissions = ? WHERE item = ? AND uid_shared_with = ? AND uid_owner = ?"); - $query->execute(array($permissions, $item, $uid_shared_with, $_SESSION['user_id'])); + public static function setIsWriteable($source, $uid_shared_with, $is_writeable) { + $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET is_writeable = ? WHERE source COLLATE latin1_bin LIKE ? AND uid_shared_with = ? AND uid_owner = ?"); + $query->execute(array($is_writeable, $source."%", $uid_shared_with, $_SESSION['user_id'])); + if (mysql_affected_rows() == 0) { + // A new entry is added to the database when a file within a shared folder is set new a value for is_writeable, but not the entire folder + $query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)"); + $target = "/".$uid_shared_with."/files/"; + $query->execute(array($_SESSION['user_id'], $uid_shared_with, $source, $target, $is_writeable)); + } } /** - * Get the permissions for the specified item - * @param unknown_type $item + * Check if the specified item is writeable for the user + * @param $target + * @return true or false */ - public static function getPermissions($item, $uid_shared_with) { - $query = OC_DB::prepare("SELECT permissions FROM *PREFIX*sharing WHERE item = ? AND uid_shared_with = ? AND uid_owner = ? "); - return $query->execute(array($item, $uid_shared_with, $_SESSION['user_id']))->fetchAll(); + public static function isWriteable($target) { + $query = OC_DB::prepare("SELECT is_writeable FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ?"); + $result = $query->execute(array($target, $_SESSION['user_id']))->fetchAll(); + if (count($result) > 0) { + return $result[0]['is_writeable']; + } else { + $folders = OC_SHARE::getParentFolders($target, false); + $result = $query->execute(array($folders['target'], $_SESSION['user_id']))->fetchAll(); + if (count($result) > 0) { + return $result[0]['is_writeable']; + } else { + return false; + } + } } /** @@ -76,6 +98,16 @@ class OC_SHARE { } } + /** + * Set the source location to a new value + * @param $oldSource The current source location + * @param $newTarget The new source location + */ + public static function setSource($oldSource, $newSource) { + $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET source = REPLACE(source, ?, ?) WHERE uid_owner = ?"); + $query->execute(array($oldSource, $newSource, $_SESSION['user_id'])); + } + /** * Get the source location of the target item * @param $target @@ -89,19 +121,42 @@ class OC_SHARE { if (count($result) > 0) { return $result[0]['source']; } else { - // Check if the parent directory of this target is shared - $parentDir = dirname($target); - if ($parentDir != "" && $parentDir != "/" && $parentDir != ".") { - $result = OC_SHARE::getSource($parentDir); - if ($result) { - return $result."/".basename($target); - } else { - return false; - } + $folders = OC_SHARE::getParentFolders($target, false); + return $folders['source'].substr($target, strlen($folders['target'])); + } + } + + public static function getParentFolders($path, $isSource = true) { + // Remove any trailing '/' + $path = rtrim($path, "/"); + if ($isSource) { + $query = OC_DB::prepare("SELECT target FROM *PREFIX*sharing WHERE source = ? AND uid_shared_with = ? LIMIT 1"); + } else { + $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1"); + } + // TODO Prevent searching for user directory e.g. '/MTGap/files' + while ($path != "" && $path != "/" && $path != ".") { + $result = $query->execute(array($path, $_SESSION['user_id']))->fetchAll(); + if (count($result) > 0) { + break; } else { - return false; + // Check if the parent directory of this target is shared + $path = dirname($path); } } + if (count($result) > 0) { + if ($isSource) { + $sourceFolder = $path; + $targetFolder = $result[0]['target']; + } else { + $sourceFolder = $result[0]['source']; + $targetFolder = $path; + } + // Return both the source folder and the target folder + return array("source" => $sourceFolder, "target" => $targetFolder); + } else { + return false; + } } /** @@ -110,8 +165,16 @@ class OC_SHARE { * @param $newTarget The new target location */ public static function setTarget($oldTarget, $newTarget) { - $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET target = ? WHERE target = ? AND uid_shared_with = ?"); - $query->execute(array($newTarget, $oldTarget, $_SESSION['user_id'])); + $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET target = REPLACE(target, ?, ?) WHERE uid_shared_with = ?"); + $query->execute(array($oldTarget, $newTarget, $_SESSION['user_id'])); + if (mysql_affected_rows() == 0) { + // A new entry is added to the database when a file within a shared folder is renamed or is moved outside the original target folder + $query = OC_DB::prepare("SELECT uid_owner, is_writeable FROM *PREFIX*sharing WHERE source = ? AND uid_shared_with = ? LIMIT 1"); + $folders = OC_SHARE::getParentFolders($oldTarget, false); + $result = $query->execute(array($folders['source'], $_SESSION['user_id'])); + $query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)"); + $query->execute(array($result[0]['uid_owner'], $_SESSION['user_id'], $folders['source'].substr($oldTarget, strlen($folders['target'])), $newTarget, $result[0]['is_writeable'])); + } } /** diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 0303cce79f..3d1a5c8391 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -71,6 +71,7 @@ class OC_FILESTORAGE_SHARED { } } + // TODO Change files within shared folders that are renamed public function opendir($path) { if ($path == "" || $path == "/") { global $FAKEDIRS; @@ -161,7 +162,6 @@ class OC_FILESTORAGE_SHARED { } public function getFolderSize($path) { - return 10000; if ($path == "" || $path == "/") { $dbpath = $_SESSION['user_id']."/files/Share/"; } else { @@ -210,30 +210,16 @@ class OC_FILESTORAGE_SHARED { } return $size; } - - // TODO OC_SHARE::getPermissions() + public function is_readable($path) { - if ($path == "" || $path == "/") { - return true; - } else { - $source = $this->getSource($path); - if ($source) { - $storage = OC_FILESYSTEM::getStorage($source); - return $storage->is_readable($this->getInternalPath($source)); - } - } + return true; } - // TODO OC_SHARE::getPermissions() public function is_writeable($path) { if ($path == "" || $path == "/") { return true; } else { - $source = $this->getSource($path); - if ($source) { - $storage = OC_FILESYSTEM::getStorage($source); - return $storage->is_writeable($this->getInternalPath($source)); - } + return OC_SHARE::isWriteable($path); } } @@ -334,6 +320,7 @@ class OC_FILESTORAGE_SHARED { } } + // TODO OC_SHARE::getPermissions() public function unlink($path) { $source = $this->getSource($path); if ($source) { @@ -342,14 +329,8 @@ class OC_FILESTORAGE_SHARED { } } - // TODO OC_SHARE::getPermissions() - // TODO Update shared item location public function rename($path1, $path2) { - $source = $this->getSource($path1); - if ($source) { - $storage = OC_FILESYSTEM::getStorage($source); - return $storage->rename($this->getInternalPath($source), $path2); - } + OC_SHARE::setTarget($path1, $path2); } public function copy($path1, $path2) { From 732ad7f6c13d26f566d181ed0adbc7857a228ee6 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 6 Jul 2011 15:17:03 -0400 Subject: [PATCH 026/122] Add support for renaming, moving, and deleting shared files --- apps/files_sharing/lib_share.php | 23 ++++++++++++++++------- apps/files_sharing/sharedstorage.php | 15 +++++++-------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index cc471f278d..53f3fb3c90 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -53,7 +53,7 @@ class OC_SHARE { * Change is writeable for the specified item and user * @param $source * @param $uid_shared_with - * @param $is_writeable + * @param $is_writeable */ public static function setIsWriteable($source, $uid_shared_with, $is_writeable) { $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET is_writeable = ? WHERE source COLLATE latin1_bin LIKE ? AND uid_shared_with = ? AND uid_owner = ?"); @@ -68,7 +68,7 @@ class OC_SHARE { /** * Check if the specified item is writeable for the user - * @param $target + * @param $target * @return true or false */ public static function isWriteable($target) { @@ -82,7 +82,7 @@ class OC_SHARE { if (count($result) > 0) { return $result[0]['is_writeable']; } else { - return false; + return false; } } } @@ -91,17 +91,26 @@ class OC_SHARE { * Unshare the item, removes it from all users specified * @param array $uid_shared_with */ - public static function unshare($item, $uid_shared_with) { - $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE item = ? AND uid_shared_with = ? AND uid_owner = ?"); + public static function unshare($source, $uid_shared_with) { + $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE source = ? AND uid_shared_with = ? AND uid_owner = ?"); foreach ($uid_shared_with as $uid) { - $query->execute(array($item, $uid, $_SESSION['user_id'])); + $query->execute(array($source, $uid, $_SESSION['user_id'])); } } + /** + * Unshare the item from the current user - used when the user deletes the item + * @param $target + */ + public static function unshareFromSelf($target) { + $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE target COLLATE latin1_bin LIKE ? AND uid_shared_with = ?"); + $query->execute(array($target, $_SESSION['user_id'])); + } + /** * Set the source location to a new value * @param $oldSource The current source location - * @param $newTarget The new source location + * @param $newTarget The new source location */ public static function setSource($oldSource, $newSource) { $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET source = REPLACE(source, ?, ?) WHERE uid_owner = ?"); diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 3d1a5c8391..1f651a1b10 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -27,7 +27,7 @@ OC_FILESYSTEM::registerStorageType('shared','OC_FILESTORAGE_SHARED',array('datad /** * Convert target path to source path and pass the function call to the correct storage provider */ -class OC_FILESTORAGE_SHARED { +class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { private $sourcePaths = array(); @@ -320,17 +320,16 @@ class OC_FILESTORAGE_SHARED { } } - // TODO OC_SHARE::getPermissions() public function unlink($path) { - $source = $this->getSource($path); - if ($source) { - $storage = OC_FILESYSTEM::getStorage($source); - return $storage->unlink($this->getInternalPath($source)); - } + // The file will be removed from the database, but won't be deleted from the owner's filesystem + $target = OC_FILESYSTEM::getStorageMountPoint($this).$path; + OC_SHARE::unshareFromSelf($target); } public function rename($path1, $path2) { - OC_SHARE::setTarget($path1, $path2); + $oldTarget = OC_FILESYSTEM::getStorageMountPoint($this).$path1; + $newTarget = OC_FILESYSTEM::getStorageMountPoint($this).$path2; + OC_SHARE::setTarget($oldTarget, $newTarget); } public function copy($path1, $path2) { From 2908145b94699380e295414c4104861715b50853 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 6 Jul 2011 15:28:50 -0400 Subject: [PATCH 027/122] Fix bug in is_writeable(), was passing the wrong path --- apps/files_sharing/sharedstorage.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 1f651a1b10..a3f6bebb0f 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -219,7 +219,8 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { if ($path == "" || $path == "/") { return true; } else { - return OC_SHARE::isWriteable($path); + $target = OC_FILESYSTEM::getStorageMountPoint($this).$path; + return OC_SHARE::isWriteable($target); } } From 2212b5b5d74012ca3b6b1d1eefba2a00c2ec9218 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 6 Jul 2011 20:16:29 -0400 Subject: [PATCH 028/122] Add wildcard to database query in unshareFromSelf() --- apps/files_sharing/lib_share.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 53f3fb3c90..2b3eb0e735 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -104,7 +104,7 @@ class OC_SHARE { */ public static function unshareFromSelf($target) { $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE target COLLATE latin1_bin LIKE ? AND uid_shared_with = ?"); - $query->execute(array($target, $_SESSION['user_id'])); + $query->execute(array($target."%", $_SESSION['user_id'])); } /** From 58e8312b1c9dbfd5af39ccf737463d9a3dd3f801 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Thu, 7 Jul 2011 18:25:34 -0400 Subject: [PATCH 029/122] Fix setIsWriteable() and setTarget() --- apps/files_sharing/lib_share.php | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 2b3eb0e735..e1501257fb 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -56,12 +56,16 @@ class OC_SHARE { * @param $is_writeable */ public static function setIsWriteable($source, $uid_shared_with, $is_writeable) { - $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET is_writeable = ? WHERE source COLLATE latin1_bin LIKE ? AND uid_shared_with = ? AND uid_owner = ?"); - $query->execute(array($is_writeable, $source."%", $uid_shared_with, $_SESSION['user_id'])); - if (mysql_affected_rows() == 0) { + $query = OC_DB::prepare("SELECT is_writeable FROM *PREFIX*sharing WHERE source = ? AND uid_shared_with = ? LIMIT 1"); + $result = $query->execute(array($source, $uid_shared_with))->fetchAll(); + if (count($result) > 0) { + $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET is_writeable = ? WHERE source COLLATE latin1_bin LIKE ? AND uid_shared_with = ? AND uid_owner = ?"); + $query->execute(array($is_writeable, $source."%", $uid_shared_with, $_SESSION['user_id'])); + } else { // A new entry is added to the database when a file within a shared folder is set new a value for is_writeable, but not the entire folder $query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)"); - $target = "/".$uid_shared_with."/files/"; + $folders = OC_SHARE::getParentFolders($source); + $target = $folders['target'].substr($source, strlen($folders['source'])); $query->execute(array($_SESSION['user_id'], $uid_shared_with, $source, $target, $is_writeable)); } } @@ -72,11 +76,12 @@ class OC_SHARE { * @return true or false */ public static function isWriteable($target) { - $query = OC_DB::prepare("SELECT is_writeable FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ?"); + $query = OC_DB::prepare("SELECT is_writeable FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1"); $result = $query->execute(array($target, $_SESSION['user_id']))->fetchAll(); if (count($result) > 0) { return $result[0]['is_writeable']; } else { + // Check if the folder is writeable $folders = OC_SHARE::getParentFolders($target, false); $result = $query->execute(array($folders['target'], $_SESSION['user_id']))->fetchAll(); if (count($result) > 0) { @@ -174,15 +179,19 @@ class OC_SHARE { * @param $newTarget The new target location */ public static function setTarget($oldTarget, $newTarget) { - $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET target = REPLACE(target, ?, ?) WHERE uid_shared_with = ?"); - $query->execute(array($oldTarget, $newTarget, $_SESSION['user_id'])); - if (mysql_affected_rows() == 0) { + $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1"); + $result = $query->execute(array($oldTarget, $_SESSION['user_id']))->fetchAll(); + if (count($result) > 0) { + $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET target = REPLACE(target, ?, ?) WHERE uid_shared_with = ?"); + $query->execute(array($oldTarget, $newTarget, $_SESSION['user_id'])); + } else { // A new entry is added to the database when a file within a shared folder is renamed or is moved outside the original target folder $query = OC_DB::prepare("SELECT uid_owner, is_writeable FROM *PREFIX*sharing WHERE source = ? AND uid_shared_with = ? LIMIT 1"); $folders = OC_SHARE::getParentFolders($oldTarget, false); $result = $query->execute(array($folders['source'], $_SESSION['user_id'])); $query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)"); - $query->execute(array($result[0]['uid_owner'], $_SESSION['user_id'], $folders['source'].substr($oldTarget, strlen($folders['target'])), $newTarget, $result[0]['is_writeable'])); + $source = $folders['source'].substr($oldTarget, strlen($folders['target'])); + $query->execute(array($result[0]['uid_owner'], $_SESSION['user_id'], $source, $newTarget, $result[0]['is_writeable'])); } } From b7c45ba240f4a51fa9fae786c4c4f7d05920a839 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Thu, 7 Jul 2011 19:22:23 -0400 Subject: [PATCH 030/122] mkdir() now checks isWriteable() to see if it has permission, rmdir unshares the folder from the user --- apps/files_sharing/sharedstorage.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index a3f6bebb0f..5f343331cd 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -53,22 +53,24 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { } } - // TODO OC_SHARE::getPermissions() public function mkdir($path) { - $source = $this->getSource($path); - if ($source) { - $storage = OC_FILESYSTEM::getStorage($source); - return $storage->mkdir($this->getInternalPath($source)); + if ($path == "" || $path == "/") { + return false; + } else { + $source = $this->getSource($path); + if ($source) { + if (OC_SHARE::isWriteable($path)) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->mkdir($this->getInternalPath($source)); + } + } } } - // TODO OC_SHARE::getPermissions() public function rmdir($path) { - $source = $this->getSource($path); - if ($source) { - $storage = OC_FILESYSTEM::getStorage($source); - return $storage->rmdir($this->getInternalPath($source)); - } + // The folder will be removed from the database, but won't be deleted from the owner's filesystem + $target = OC_FILESYSTEM::getStorageMountPoint($this).$path; + OC_SHARE::unshareFromSelf($target); } // TODO Change files within shared folders that are renamed From 35d6051e9df9e3bc0f82e0be45658d5e093234b4 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Thu, 7 Jul 2011 19:26:25 -0400 Subject: [PATCH 031/122] Fix bug in mkdir(), was passing the wrong path --- apps/files_sharing/sharedstorage.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 5f343331cd..992ccc8e59 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -59,7 +59,8 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { } else { $source = $this->getSource($path); if ($source) { - if (OC_SHARE::isWriteable($path)) { + $target = OC_FILESYSTEM::getStorageMountPoint($this).$path; + if (OC_SHARE::isWriteable($target)) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->mkdir($this->getInternalPath($source)); } From d91d2178b8677c30b2ef4b841977ecff4bd97728 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Fri, 8 Jul 2011 14:58:35 -0400 Subject: [PATCH 032/122] Fix unshare() to remove database entries of files within a shared folder --- apps/files_sharing/lib_share.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index e1501257fb..795004606e 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -97,7 +97,7 @@ class OC_SHARE { * @param array $uid_shared_with */ public static function unshare($source, $uid_shared_with) { - $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE source = ? AND uid_shared_with = ? AND uid_owner = ?"); + $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE source COLLATE latin1_bin LIKE ? AND uid_shared_with = ? AND uid_owner = ?"); foreach ($uid_shared_with as $uid) { $query->execute(array($source, $uid, $_SESSION['user_id'])); } From f1cac0039636ff4c82f97d94527c2e3d1d47d9fb Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Fri, 8 Jul 2011 15:03:05 -0400 Subject: [PATCH 033/122] Add wildcard to source for database query in unshare() --- apps/files_sharing/lib_share.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 795004606e..50013aa711 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -99,7 +99,7 @@ class OC_SHARE { public static function unshare($source, $uid_shared_with) { $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE source COLLATE latin1_bin LIKE ? AND uid_shared_with = ? AND uid_owner = ?"); foreach ($uid_shared_with as $uid) { - $query->execute(array($source, $uid, $_SESSION['user_id'])); + $query->execute(array($source."%", $uid, $_SESSION['user_id'])); } } From 73bab46758552a965450354d6407e328ab82d7f9 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Fri, 8 Jul 2011 15:23:41 -0400 Subject: [PATCH 034/122] Prevent searching for user directory in getParentFolders() --- apps/files_sharing/lib_share.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 50013aa711..72a8a39e57 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -148,8 +148,9 @@ class OC_SHARE { } else { $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1"); } - // TODO Prevent searching for user directory e.g. '/MTGap/files' - while ($path != "" && $path != "/" && $path != ".") { + // Prevent searching for user directory e.g. '/MTGap/files' + $userDirectory = substr($path, 0, strpos($path, "files") + 5); + while ($path != "" && $path != "/" && $path != "." && $path != $userDirectory) { $result = $query->execute(array($path, $_SESSION['user_id']))->fetchAll(); if (count($result) > 0) { break; From 010920ad08352b33107ebe131a1263d1cb10d2e1 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Fri, 8 Jul 2011 18:21:20 -0400 Subject: [PATCH 035/122] Add support for files inside of shared folders having different names than the source file --- apps/files_sharing/lib_share.php | 12 ++++++++++++ apps/files_sharing/sharedstorage.php | 24 ++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 72a8a39e57..7fab7e2cce 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -173,6 +173,18 @@ class OC_SHARE { return false; } } + + /** + * Get the files within a shared folder that have their own entry for the purpose of name, location, or permissions that differ from the folder itself + * @param $sourceFolder The source folder of the files to look for + * @return array An array of the files if any + */ + public static function getSharedFilesIn($sourceFolder) { + // Append '/' in order to filter out the folder itself + $sourceFolder = $sourceFolder."/"; + $query = OC_DB::prepare("SELECT source, target FROM *PREFIX*sharing WHERE source COLLATE latin1_bin LIKE ? AND uid_shared_with = ?"); + return $query->execute(array($sourceFolder."%", $_SESSION['user_id']))->fetchAll(); + } /** * Set the target location to a new value diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 992ccc8e59..3b678178c3 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -74,7 +74,6 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { OC_SHARE::unshareFromSelf($target); } - // TODO Change files within shared folders that are renamed public function opendir($path) { if ($path == "" || $path == "/") { global $FAKEDIRS; @@ -88,7 +87,28 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->opendir($this->getInternalPath($source)); + $dh = $storage->opendir($this->getInternalPath($source)); + $modifiedItems = OC_SHARE::getSharedFilesIn($source); + if ($modifiedItems && $dh) { + global $FAKEDIRS; + $sources = array(); + $targets = array(); + foreach ($modifiedItems as $item) { + $sources[] = basename($item['source']); + $targets[] = basename($item['target']); + } + while (($filename = readdir($dh)) !== false) { + if (!in_array($filename, $sources)) { + $files[] = $filename; + } else { + $files[] = $targets[array_search($filename, $sources)]; + } + } + $FAKEDIRS['shared'] = $files; + return opendir('fakedir://shared'); + } else { + return $dh; + } } } } From 163c490c92c714e327eab7344a41aa4f19d8083f Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 10 Jul 2011 14:41:27 -0400 Subject: [PATCH 036/122] Remove duplicate '/' from target when searching for source --- apps/files_sharing/lib_share.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 7fab7e2cce..494f48db41 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -128,8 +128,9 @@ class OC_SHARE { * @return source path */ public static function getSource($target) { - // Remove any trailing '/' + // Remove any duplicate or trailing '/' $target = rtrim($target, "/"); + $target = preg_replace('{(/)\1+}', "/", $target); $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1"); $result = $query->execute(array($target, $_SESSION['user_id']))->fetchAll(); if (count($result) > 0) { @@ -141,8 +142,9 @@ class OC_SHARE { } public static function getParentFolders($path, $isSource = true) { - // Remove any trailing '/' + // Remove any duplicate or trailing '/' $path = rtrim($path, "/"); + $path = preg_replace('{(/)\1+}', "/", $path); if ($isSource) { $query = OC_DB::prepare("SELECT target FROM *PREFIX*sharing WHERE source = ? AND uid_shared_with = ? LIMIT 1"); } else { From 6b303ee64b5c1b1e338c9bbf1b895d33b140985d Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Tue, 12 Jul 2011 13:10:29 -0400 Subject: [PATCH 037/122] Fix bug in opendir() and remove getStorageMountPoint(), now using datadir argument instead --- apps/files_sharing/sharedstorage.php | 28 ++++++++++++---------------- lib/base.php | 2 +- lib/filesystem.php | 9 --------- 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 3b678178c3..b0770cbfdb 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -29,11 +29,11 @@ OC_FILESYSTEM::registerStorageType('shared','OC_FILESTORAGE_SHARED',array('datad */ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { + private $datadir; private $sourcePaths = array(); - // TODO uh... I don't know what to do here - public function __construct($parameters) { - + public function __construct($arguments) { + $this->datadir = $arguments['datadir']; } public function getInternalPath($path) { @@ -43,7 +43,7 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { } public function getSource($target) { - $target = OC_FILESYSTEM::getStorageMountPoint($this).$target; + $target = $this->datadir.$target; if (array_key_exists($target, $this->sourcePaths)) { return $this->sourcePaths[$target]; } else { @@ -59,8 +59,7 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { } else { $source = $this->getSource($path); if ($source) { - $target = OC_FILESYSTEM::getStorageMountPoint($this).$path; - if (OC_SHARE::isWriteable($target)) { + if (OC_SHARE::isWriteable($this->datadir.$path)) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->mkdir($this->getInternalPath($source)); } @@ -70,16 +69,17 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { public function rmdir($path) { // The folder will be removed from the database, but won't be deleted from the owner's filesystem - $target = OC_FILESYSTEM::getStorageMountPoint($this).$path; - OC_SHARE::unshareFromSelf($target); + OC_SHARE::unshareFromSelf($this->datadir.$path); } + // TODO Make sure new target is still in the current directory public function opendir($path) { if ($path == "" || $path == "/") { global $FAKEDIRS; $sharedItems = OC_SHARE::getItemsSharedWith(); foreach ($sharedItems as $item) { - $files[] = $item['target']; + // TODO Implement a better fix + $files[] = substr($item['target'], strpos($item['target'], "Share") + 5); } $FAKEDIRS['shared'] = $files; return opendir('fakedir://shared'); @@ -242,8 +242,7 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { if ($path == "" || $path == "/") { return true; } else { - $target = OC_FILESYSTEM::getStorageMountPoint($this).$path; - return OC_SHARE::isWriteable($target); + return OC_SHARE::isWriteable($this->datadir.$path); } } @@ -346,14 +345,11 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { public function unlink($path) { // The file will be removed from the database, but won't be deleted from the owner's filesystem - $target = OC_FILESYSTEM::getStorageMountPoint($this).$path; - OC_SHARE::unshareFromSelf($target); + OC_SHARE::unshareFromSelf($this->datadir.$path); } public function rename($path1, $path2) { - $oldTarget = OC_FILESYSTEM::getStorageMountPoint($this).$path1; - $newTarget = OC_FILESYSTEM::getStorageMountPoint($this).$path2; - OC_SHARE::setTarget($oldTarget, $newTarget); + OC_SHARE::setTarget($this->datadir.$path1, $this->datadir.$path2); } public function copy($path1, $path2) { diff --git a/lib/base.php b/lib/base.php index 4250274c7c..d369b392a4 100644 --- a/lib/base.php +++ b/lib/base.php @@ -166,7 +166,7 @@ class OC_UTIL { OC_FILESYSTEM::mount($rootStorage,'/'); // TODO add this storage provider in a proper way - $sharedStorage = OC_FILESYSTEM::createStorage('shared',array('datadir'=>$CONFIG_DATADIRECTORY)); + $sharedStorage = OC_FILESYSTEM::createStorage('shared',array('datadir'=>'/MTGap/files/Share/')); OC_FILESYSTEM::mount($sharedStorage,'MTGap/files/Share/'); $CONFIG_DATADIRECTORY = "$CONFIG_DATADIRECTORY_ROOT/$user/$root"; diff --git a/lib/filesystem.php b/lib/filesystem.php index c7e2070fa0..1f96e139ab 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -215,15 +215,6 @@ class OC_FILESYSTEM{ return $foundMountPoint; } - /** - * get the mountpoint of the storage object - * @param OC_FILESTORAGE storage - * @return string - */ - static public function getStorageMountPoint($storage){ - return array_search($storage, self::$storages); - } - /** * return the path to a local version of the file * we need this because we can't know if a file is stored local or not from outside the filestorage and for some purposes a local file is needed From b2b7d99302ebbcf7db5288476ef982f9871e3864 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Tue, 12 Jul 2011 18:22:59 -0400 Subject: [PATCH 038/122] Add checks in opendir() to prevent including the current directory or parent --- apps/files_sharing/sharedstorage.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index b0770cbfdb..a547560659 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -98,10 +98,12 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { $targets[] = basename($item['target']); } while (($filename = readdir($dh)) !== false) { - if (!in_array($filename, $sources)) { - $files[] = $filename; - } else { - $files[] = $targets[array_search($filename, $sources)]; + if ($filename != "." && $filename != "..") { + if (!in_array($filename, $sources)) { + $files[] = $filename; + } else { + $files[] = $targets[array_search($filename, $sources)]; + } } } $FAKEDIRS['shared'] = $files; From d393ccfe2c30d6ffa7de20aee6c52ae0e36efaa0 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Tue, 12 Jul 2011 20:18:08 -0400 Subject: [PATCH 039/122] Fix bug in getSource(), return false if target isn't in database --- apps/files_sharing/lib_share.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 494f48db41..804379f830 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -137,7 +137,11 @@ class OC_SHARE { return $result[0]['source']; } else { $folders = OC_SHARE::getParentFolders($target, false); - return $folders['source'].substr($target, strlen($folders['target'])); + if ($folders == false) { + return false; + } else { + return $folders['source'].substr($target, strlen($folders['target'])); + } } } From 5896e4875550a30d09c3fd54dc1daaec7c68165d Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 13 Jul 2011 13:30:22 -0400 Subject: [PATCH 040/122] Add missing argument for fromTmpFile() inside of rename() --- lib/filesystem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/filesystem.php b/lib/filesystem.php index 3bb0239e9f..2c26667bbe 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -384,7 +384,7 @@ class OC_FILESYSTEM{ } }elseif($storage1=self::getStorage($path1) and $storage2=self::getStorage($path2)){ $tmpFile=$storage1->toTmpFile(self::getInternalPath($path1)); - $result=$storage2->fromTmpFile(self::getInternalPath($path2)); + $result=$storage2->fromTmpFile($tmpFile,self::getInternalPath($path2)); $storage1->unlink(self::getInternalPath($path1)); } OC_HOOK::emit( 'OC_FILESYSTEM', 'post_rename', array( 'oldpath' => $path1, 'newpath'=>$path2)); From 24e24f1b6535091a862575b613bf152c9eabfde2 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 13 Jul 2011 15:27:16 -0400 Subject: [PATCH 041/122] Add support for copying files between shared folders, add check to fromTmpFile() to confirm path is writeable --- apps/files_sharing/sharedstorage.php | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index a547560659..13054d21c5 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -355,10 +355,15 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { } public function copy($path1, $path2) { - $source = $this->getSource($path1); - if ($source) { - $storage = OC_FILESYSTEM::getStorage($source); - return $storage->copy($this->getInternalPath($source), $path2); + if ($path2 == "" || $path2 == "/") { + // TODO Construct new shared item or should this not be allowed? + } else { + if ($this->is_writeable($path)) { + $tmpFile = $this->toTmpFile($path1); + return $this->fromTmpFile($tmpFile, $path2); + } else { + return false; + } } } @@ -378,11 +383,15 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { } } - public function fromTmpFile($tmpPath, $path) { - $source = $this->getSource($tmpPath); - if ($source) { - $storage = OC_FILESYSTEM::getStorage($source); - return $storage->fromTmpFile($this->getInternalPath($source), $path); + public function fromTmpFile($tmpFile, $path) { + if ($this->is_writeable($path)) { + $source = $this->getSource($path); + if ($source) { + $storage = OC_FILESYSTEM::getStorage($source); + return $storage->fromTmpFile($tmpFile, $this->getInternalPath($source)); + } + } else { + return false; } } From 2fb14816136f9d54375215174f33109c027e00d2 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Thu, 14 Jul 2011 12:40:12 -0400 Subject: [PATCH 042/122] Bug fix for setTarget() - append fetchAll() to query --- apps/files_sharing/lib_share.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 804379f830..b529f7e694 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -207,7 +207,7 @@ class OC_SHARE { // A new entry is added to the database when a file within a shared folder is renamed or is moved outside the original target folder $query = OC_DB::prepare("SELECT uid_owner, is_writeable FROM *PREFIX*sharing WHERE source = ? AND uid_shared_with = ? LIMIT 1"); $folders = OC_SHARE::getParentFolders($oldTarget, false); - $result = $query->execute(array($folders['source'], $_SESSION['user_id'])); + $result = $query->execute(array($folders['source'], $_SESSION['user_id']))->fetchAll(); $query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)"); $source = $folders['source'].substr($oldTarget, strlen($folders['target'])); $query->execute(array($result[0]['uid_owner'], $_SESSION['user_id'], $source, $newTarget, $result[0]['is_writeable'])); From 7920e706eabbcce20a8e7f53fa4f6edb524302b5 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Thu, 14 Jul 2011 19:24:48 -0400 Subject: [PATCH 043/122] Refactoring of OC_SHARE, added more documentation for functions --- apps/files_sharing/lib_share.php | 271 +++++++++++++-------------- apps/files_sharing/sharedstorage.php | 14 +- 2 files changed, 141 insertions(+), 144 deletions(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index b529f7e694..5af862c984 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -50,30 +50,97 @@ class OC_SHARE { } /** - * Change is writeable for the specified item and user - * @param $source - * @param $uid_shared_with - * @param $is_writeable - */ - public static function setIsWriteable($source, $uid_shared_with, $is_writeable) { - $query = OC_DB::prepare("SELECT is_writeable FROM *PREFIX*sharing WHERE source = ? AND uid_shared_with = ? LIMIT 1"); - $result = $query->execute(array($source, $uid_shared_with))->fetchAll(); - if (count($result) > 0) { - $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET is_writeable = ? WHERE source COLLATE latin1_bin LIKE ? AND uid_shared_with = ? AND uid_owner = ?"); - $query->execute(array($is_writeable, $source."%", $uid_shared_with, $_SESSION['user_id'])); - } else { - // A new entry is added to the database when a file within a shared folder is set new a value for is_writeable, but not the entire folder - $query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)"); - $folders = OC_SHARE::getParentFolders($source); - $target = $folders['target'].substr($source, strlen($folders['source'])); - $query->execute(array($_SESSION['user_id'], $uid_shared_with, $source, $target, $is_writeable)); - } + * 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) { + $query = OC_DB::prepare("SELECT uid_owner, source, is_writeable FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1"); + return $query->execute(array($target, $_SESSION['user_id']))->fetchAll(); } /** - * Check if the specified item is writeable for the user - * @param $target - * @return true or false + * Get all items the current user is sharing + * @return An array with all items the user is sharing + */ + public static function getMySharedItems() { + $query = OC_DB::prepare("SELECT uid_shared_with, source, is_writeable FROM *PREFIX*sharing WHERE uid_owner = ?"); + return $query->execute(array($_SESSION['user_id']))->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 + * + * Also can be used for getting all item shared with you e.g. pass '/MTGap/files' + * + * @param $targetFolder The target folder of the items to look for + * @return An array with all items in the database that are in the target folder + */ + public static function getItemsInFolder($targetFolder) { + // Append '/' in order to filter out the folder itself if not already there + if (substr($targetFolder, -1) !== "/") { + $targetFolder .= "/"; + } + $query = OC_DB::prepare("SELECT uid_owner, source, target FROM *PREFIX*sharing WHERE target COLLATE latin1_bin LIKE ? AND uid_shared_with = ?"); + return $query->execute(array($targetFolder."%", $_SESSION['user_id']))->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) { + // Remove any duplicate or trailing '/' + $target = rtrim($target, "/"); + $target = preg_replace('{(/)\1+}', "/", $target); + $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1"); + // Prevent searching for user directory e.g. '/MTGap/files' + $userDirectory = substr($target, 0, strpos($target, "files") + 5); + while ($target != "" && $target != "/" && $target != "." && $target != $userDirectory) { + $result = $query->execute(array($target, $_SESSION['user_id']))->fetchAll(); + if (count($result) > 0) { + break; + } else { + // Check if the parent directory of this target location is shared + $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) { + // Remove any duplicate or trailing '/' + $target = rtrim($target, "/"); + $target = preg_replace('{(/)\1+}', "/", $target); + $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1"); + $result = $query->execute(array($target, $_SESSION['user_id']))->fetchAll(); + if (count($result) > 0) { + return $result[0]['source']; + } else { + $folders = self::getParentFolders($target); + if ($folders == false) { + return false; + } else { + return $folders['source'].substr($target, strlen($folders['target'])); + } + } + } + + /** + * Check if the user has write permission for the item at the specified target location + * @param $target The target location of the item + * @return True if the user has write permission or false if read only */ public static function isWriteable($target) { $query = OC_DB::prepare("SELECT is_writeable FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1"); @@ -82,7 +149,7 @@ class OC_SHARE { return $result[0]['is_writeable']; } else { // Check if the folder is writeable - $folders = OC_SHARE::getParentFolders($target, false); + $folders = OC_SHARE::getParentFolders($target); $result = $query->execute(array($folders['target'], $_SESSION['user_id']))->fetchAll(); if (count($result) > 0) { return $result[0]['is_writeable']; @@ -91,27 +158,7 @@ class OC_SHARE { } } } - - /** - * Unshare the item, removes it from all users specified - * @param array $uid_shared_with - */ - public static function unshare($source, $uid_shared_with) { - $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE source COLLATE latin1_bin LIKE ? AND uid_shared_with = ? AND uid_owner = ?"); - foreach ($uid_shared_with as $uid) { - $query->execute(array($source."%", $uid, $_SESSION['user_id'])); - } - } - - /** - * Unshare the item from the current user - used when the user deletes the item - * @param $target - */ - public static function unshareFromSelf($target) { - $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE target COLLATE latin1_bin LIKE ? AND uid_shared_with = ?"); - $query->execute(array($target."%", $_SESSION['user_id'])); - } - + /** * Set the source location to a new value * @param $oldSource The current source location @@ -122,116 +169,62 @@ class OC_SHARE { $query->execute(array($oldSource, $newSource, $_SESSION['user_id'])); } - /** - * Get the source location of the target item - * @param $target - * @return source path - */ - public static function getSource($target) { - // Remove any duplicate or trailing '/' - $target = rtrim($target, "/"); - $target = preg_replace('{(/)\1+}', "/", $target); - $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1"); - $result = $query->execute(array($target, $_SESSION['user_id']))->fetchAll(); - if (count($result) > 0) { - return $result[0]['source']; - } else { - $folders = OC_SHARE::getParentFolders($target, false); - if ($folders == false) { - return false; - } else { - return $folders['source'].substr($target, strlen($folders['target'])); - } - } - } - - public static function getParentFolders($path, $isSource = true) { - // Remove any duplicate or trailing '/' - $path = rtrim($path, "/"); - $path = preg_replace('{(/)\1+}', "/", $path); - if ($isSource) { - $query = OC_DB::prepare("SELECT target FROM *PREFIX*sharing WHERE source = ? AND uid_shared_with = ? LIMIT 1"); - } else { - $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1"); - } - // Prevent searching for user directory e.g. '/MTGap/files' - $userDirectory = substr($path, 0, strpos($path, "files") + 5); - while ($path != "" && $path != "/" && $path != "." && $path != $userDirectory) { - $result = $query->execute(array($path, $_SESSION['user_id']))->fetchAll(); - if (count($result) > 0) { - break; - } else { - // Check if the parent directory of this target is shared - $path = dirname($path); - } - } - if (count($result) > 0) { - if ($isSource) { - $sourceFolder = $path; - $targetFolder = $result[0]['target']; - } else { - $sourceFolder = $result[0]['source']; - $targetFolder = $path; - } - // Return both the source folder and the target folder - return array("source" => $sourceFolder, "target" => $targetFolder); - } else { - return false; - } - } - - /** - * Get the files within a shared folder that have their own entry for the purpose of name, location, or permissions that differ from the folder itself - * @param $sourceFolder The source folder of the files to look for - * @return array An array of the files if any - */ - public static function getSharedFilesIn($sourceFolder) { - // Append '/' in order to filter out the folder itself - $sourceFolder = $sourceFolder."/"; - $query = OC_DB::prepare("SELECT source, target FROM *PREFIX*sharing WHERE source COLLATE latin1_bin LIKE ? AND uid_shared_with = ?"); - return $query->execute(array($sourceFolder."%", $_SESSION['user_id']))->fetchAll(); - } - /** * Set the target location to a new value + * + * You must construct a new shared item 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) { - $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1"); - $result = $query->execute(array($oldTarget, $_SESSION['user_id']))->fetchAll(); - if (count($result) > 0) { - $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET target = REPLACE(target, ?, ?) WHERE uid_shared_with = ?"); - $query->execute(array($oldTarget, $newTarget, $_SESSION['user_id'])); - } else { - // A new entry is added to the database when a file within a shared folder is renamed or is moved outside the original target folder - $query = OC_DB::prepare("SELECT uid_owner, is_writeable FROM *PREFIX*sharing WHERE source = ? AND uid_shared_with = ? LIMIT 1"); - $folders = OC_SHARE::getParentFolders($oldTarget, false); - $result = $query->execute(array($folders['source'], $_SESSION['user_id']))->fetchAll(); - $query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)"); - $source = $folders['source'].substr($oldTarget, strlen($folders['target'])); - $query->execute(array($result[0]['uid_owner'], $_SESSION['user_id'], $source, $newTarget, $result[0]['is_writeable'])); + $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET target = REPLACE(target, ?, ?) WHERE uid_shared_with = ?"); + $query->execute(array($oldTarget, $newTarget, $_SESSION['user_id'])); + } + + /** + * Change write permission for the specified item and user + * + * You must construct a new shared item to change the write permission of a file inside a shared folder if the write permission differs from the folder + * + * @param $source The source location of the item + * @param $uid_shared_with Array of users to change the write permission for + * @param $is_writeable True if the user has write permission or false if read only + */ + public static function setIsWriteable($source, $uid_shared_with, $is_writeable) { + $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET is_writeable = ? WHERE source COLLATE latin1_bin LIKE ? AND uid_shared_with = ? AND uid_owner = ?"); + foreach ($uid_shared_with as $uid) { + $query->execute(array($is_writeable, $source."%", $uid_shared_with, $_SESSION['user_id'])); } } /** - * Get all items the user is sharing - * @return array - */ - public static function getSharedItems() { - $query = OC_DB::prepare("SELECT * FROM *PREFIX*sharing WHERE uid_owner = ?"); - return $query->execute(array($_SESSION['user_id']))->fetchAll(); + * Unshare the item, removes it from all specified users + * + * You must construct a new shared item to unshare a file inside a shared folder and set target 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) { + $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE source COLLATE latin1_bin LIKE ? AND uid_shared_with = ? AND uid_owner = ?"); + foreach ($uid_shared_with as $uid) { + $query->execute(array($source."%", $uid, $_SESSION['user_id'])); + } } /** - * Get all items shared with the user - * @return array - */ - public static function getItemsSharedWith() { - $query = OC_DB::prepare("SELECT * FROM *PREFIX*sharing WHERE uid_shared_with = ?"); - return $query->execute(array($_SESSION['user_id']))->fetchAll(); + * Unshare the item from the current user, removes it only from the database and doesn't touch the source file + * + * You must construct a new shared item to unshare a file inside a shared folder and set target to nothing + * + * @param $target The target location of the item + */ + public static function unshareFromMySelf($target) { + $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE target COLLATE latin1_bin LIKE ? AND uid_shared_with = ?"); + $query->execute(array($target."%", $_SESSION['user_id'])); } - + } ?> diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 13054d21c5..f09b11f798 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -69,14 +69,14 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { public function rmdir($path) { // The folder will be removed from the database, but won't be deleted from the owner's filesystem - OC_SHARE::unshareFromSelf($this->datadir.$path); + OC_SHARE::unshareFromMySelf($this->datadir.$path); } // TODO Make sure new target is still in the current directory public function opendir($path) { if ($path == "" || $path == "/") { global $FAKEDIRS; - $sharedItems = OC_SHARE::getItemsSharedWith(); + $sharedItems = OC_SHARE::getItemsInFolder($this->datadir.$path); foreach ($sharedItems as $item) { // TODO Implement a better fix $files[] = substr($item['target'], strpos($item['target'], "Share") + 5); @@ -88,7 +88,7 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { if ($source) { $storage = OC_FILESYSTEM::getStorage($source); $dh = $storage->opendir($this->getInternalPath($source)); - $modifiedItems = OC_SHARE::getSharedFilesIn($source); + $modifiedItems = OC_SHARE::getItemsInFolder($this->datadir.$path); if ($modifiedItems && $dh) { global $FAKEDIRS; $sources = array(); @@ -347,11 +347,15 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { public function unlink($path) { // The file will be removed from the database, but won't be deleted from the owner's filesystem - OC_SHARE::unshareFromSelf($this->datadir.$path); + OC_SHARE::unshareFromMySelf($this->datadir.$path); } public function rename($path1, $path2) { - OC_SHARE::setTarget($this->datadir.$path1, $this->datadir.$path2); + if (dirname($path1) == dirname($path2)) { + OC_SHARE::setTarget($this->datadir.$path1, $this->datadir.$path2); + } else { + // TODO Construct new shared item + } } public function copy($path1, $path2) { From 8ed0223bd6ef767656758e03a9745e06582014e6 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Thu, 14 Jul 2011 21:04:09 -0400 Subject: [PATCH 044/122] Add pullOutOfFolder() function for use by unlink() and rename() --- apps/files_sharing/lib_share.php | 27 +++++++++++++++++++++------ apps/files_sharing/sharedstorage.php | 16 ++++++++++++---- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 5af862c984..416cfa1953 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -49,6 +49,22 @@ class OC_SHARE { } } + /** + * 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($target, strlen($folders['target'])); + $item = self::getItem($folders['target']); + $query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)"); + $query->execute(array($item[0]['uid_owner'], $_SESSION['user_id'], $source, $newTarget, $item[0]['is_writeable'])); + } + /** * Get the item with the specified target location * @param $target The target location of the item @@ -98,12 +114,11 @@ class OC_SHARE { // Prevent searching for user directory e.g. '/MTGap/files' $userDirectory = substr($target, 0, strpos($target, "files") + 5); while ($target != "" && $target != "/" && $target != "." && $target != $userDirectory) { + // Check if the parent directory of this target location is shared + $target = dirname($target); $result = $query->execute(array($target, $_SESSION['user_id']))->fetchAll(); if (count($result) > 0) { break; - } else { - // Check if the parent directory of this target location is shared - $target = dirname($target); } } if (count($result) > 0) { @@ -172,7 +187,7 @@ class OC_SHARE { /** * Set the target location to a new value * - * You must construct a new shared item to change the target location of a file inside a shared folder if the target location differs from the folder + * 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 @@ -201,7 +216,7 @@ class OC_SHARE { /** * Unshare the item, removes it from all specified users * - * You must construct a new shared item to unshare a file inside a shared folder and set target to nothing + * 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 @@ -216,7 +231,7 @@ class OC_SHARE { /** * Unshare the item from the current user, removes it only from the database and doesn't touch the source file * - * You must construct a new shared item to unshare a file inside a shared folder and set target to nothing + * You must use the pullOutOfFolder() function to unshare a file inside a shared folder and set $newTarget to nothing * * @param $target The target location of the item */ diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index f09b11f798..c7201f5216 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -346,15 +346,23 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { } public function unlink($path) { - // The file will be removed from the database, but won't be deleted from the owner's filesystem - OC_SHARE::unshareFromMySelf($this->datadir.$path); + // The file will be removed from the database, but won't be touched on the owner's filesystem + $target = $this->datadir.$path; + if (OC_SHARE::getItem($target)) { + OC_SHARE::unshareFromMySelf($target); + } else { + OC_SHARE::pullOutOfFolder($target, ""); + } } public function rename($path1, $path2) { + // The file will be renamed in the database, but won't be touched on the owner's filesystem + $oldTarget = $this->datadir.$path1; + $newTarget = $this->datadir.$path2; if (dirname($path1) == dirname($path2)) { - OC_SHARE::setTarget($this->datadir.$path1, $this->datadir.$path2); + OC_SHARE::setTarget($oldTarget, $newTarget); } else { - // TODO Construct new shared item + OC_SHARE::pullOutOfFolder($oldTarget, $newTarget); } } From 8ad4a44171e5e0d9a2f61c16a0f0db0ce2452108 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sat, 16 Jul 2011 13:06:59 -0400 Subject: [PATCH 045/122] Fix bugs in unlink(), rename(), pullOutOfFolders(), and getItemsInFolder() --- apps/files_sharing/lib_share.php | 4 +++- apps/files_sharing/sharedstorage.php | 14 ++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 416cfa1953..75a76ffb78 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -59,7 +59,7 @@ class OC_SHARE { */ public static function pullOutOfFolder($oldTarget, $newTarget) { $folders = self::getParentFolders($oldTarget); - $source = $folders['source'].substr($target, strlen($folders['target'])); + $source = $folders['source'].substr($oldTarget, strlen($folders['target'])); $item = self::getItem($folders['target']); $query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)"); $query->execute(array($item[0]['uid_owner'], $_SESSION['user_id'], $source, $newTarget, $item[0]['is_writeable'])); @@ -97,6 +97,8 @@ class OC_SHARE { if (substr($targetFolder, -1) !== "/") { $targetFolder .= "/"; } + // Remove any duplicate '/' + $targetFolder = preg_replace('{(/)\1+}', "/", $targetFolder); $query = OC_DB::prepare("SELECT uid_owner, source, target FROM *PREFIX*sharing WHERE target COLLATE latin1_bin LIKE ? AND uid_shared_with = ?"); return $query->execute(array($targetFolder."%", $_SESSION['user_id']))->fetchAll(); } diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index c7201f5216..c8f311a954 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -348,10 +348,16 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { public function unlink($path) { // The file will be removed from the database, but won't be touched on the owner's filesystem $target = $this->datadir.$path; - if (OC_SHARE::getItem($target)) { - OC_SHARE::unshareFromMySelf($target); + // If file is inside a shared folder + if (OC_SHARE::getParentFolders($target)) { + // If entry for file already exists + if (OC_SHARE::getItem($target)) { + OC_SHARE::setTarget($target, "/"); + } else { + OC_SHARE::pullOutOfFolder($target, "/"); + } } else { - OC_SHARE::pullOutOfFolder($target, ""); + OC_SHARE::unshareFromMySelf($target); } } @@ -359,7 +365,7 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { // The file will be renamed in the database, but won't be touched on the owner's filesystem $oldTarget = $this->datadir.$path1; $newTarget = $this->datadir.$path2; - if (dirname($path1) == dirname($path2)) { + if (OC_SHARE::getItem($oldTarget)) { OC_SHARE::setTarget($oldTarget, $newTarget); } else { OC_SHARE::pullOutOfFolder($oldTarget, $newTarget); From dbcb35655e844e85de0134f06803087f45b7799b Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sat, 16 Jul 2011 14:24:59 -0400 Subject: [PATCH 046/122] Fix bugs in opendir() and add extra checks to ensure functionality in all cases --- apps/files_sharing/sharedstorage.php | 49 ++++++++++++++++++---------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index c8f311a954..7184f0624a 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -72,14 +72,16 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { OC_SHARE::unshareFromMySelf($this->datadir.$path); } - // TODO Make sure new target is still in the current directory public function opendir($path) { if ($path == "" || $path == "/") { global $FAKEDIRS; - $sharedItems = OC_SHARE::getItemsInFolder($this->datadir.$path); + $path = $this->datadir.$path; + $sharedItems = OC_SHARE::getItemsInFolder($path); foreach ($sharedItems as $item) { - // TODO Implement a better fix - $files[] = substr($item['target'], strpos($item['target'], "Share") + 5); + // If item is in the root of the shared storage provider add it to the fakedirs + if (dirname($item['target'])."/" == $path) { + $files[] = basename($item['target']); + } } $FAKEDIRS['shared'] = $files; return opendir('fakedir://shared'); @@ -88,26 +90,39 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { if ($source) { $storage = OC_FILESYSTEM::getStorage($source); $dh = $storage->opendir($this->getInternalPath($source)); - $modifiedItems = OC_SHARE::getItemsInFolder($this->datadir.$path); + // Remove any duplicate or trailing '/' + $path = rtrim($this->datadir.$path, "/"); + $path = preg_replace('{(/)\1+}', "/", $path); + $modifiedItems = OC_SHARE::getItemsInFolder($path); if ($modifiedItems && $dh) { global $FAKEDIRS; $sources = array(); $targets = array(); foreach ($modifiedItems as $item) { - $sources[] = basename($item['source']); - $targets[] = basename($item['target']); - } - while (($filename = readdir($dh)) !== false) { - if ($filename != "." && $filename != "..") { - if (!in_array($filename, $sources)) { - $files[] = $filename; - } else { - $files[] = $targets[array_search($filename, $sources)]; - } + // If item is in current directory, add it to the arrays + if (dirname($item['target']) == $path) { + $sources[] = basename($item['source']); + $targets[] = basename($item['target']); } } - $FAKEDIRS['shared'] = $files; - return opendir('fakedir://shared'); + // Don't waste time if there aren't any modified items in the current directory + if (empty($sources)) { + return $dh; + } else { + 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 { + $files[] = $targets[array_search($filename, $sources)]; + } + } + } + $FAKEDIRS['shared'] = $files; + return opendir('fakedir://shared'); + } } else { return $dh; } From 5aaacf32418e1842bdaa1def131ea0733b724034 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sat, 16 Jul 2011 14:29:22 -0400 Subject: [PATCH 047/122] Fix bug in rename() so files in a folder that is in a shared folder also get their targets updated --- apps/files_sharing/sharedstorage.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 7184f0624a..af9233b0b7 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -384,6 +384,9 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { OC_SHARE::setTarget($oldTarget, $newTarget); } else { OC_SHARE::pullOutOfFolder($oldTarget, $newTarget); + if (self::is_dir($path1)) { + OC_SHARE::setTarget($oldTarget, $newTarget); + } } } From f3f8a96c6d7acc5e97653a6fdbd6148a4af6bfdc Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sat, 16 Jul 2011 14:58:12 -0400 Subject: [PATCH 048/122] Add return true to unlink() and rename(), a return is expected by OC_FILESYSTEM --- apps/files_sharing/sharedstorage.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index af9233b0b7..175a58d159 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -374,6 +374,7 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { } else { OC_SHARE::unshareFromMySelf($target); } + return true; } public function rename($path1, $path2) { @@ -388,6 +389,7 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { OC_SHARE::setTarget($oldTarget, $newTarget); } } + return true; } public function copy($path1, $path2) { From 1a6718c979a083c5b26c10a5468fed990103338a Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sat, 16 Jul 2011 15:15:18 -0400 Subject: [PATCH 049/122] Add extra check for opendir() so it only adds the file to fakedirs if it has a different name than the source --- apps/files_sharing/sharedstorage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 175a58d159..b27d91de96 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -99,8 +99,8 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { $sources = array(); $targets = array(); foreach ($modifiedItems as $item) { - // If item is in current directory, add it to the arrays - if (dirname($item['target']) == $path) { + // If the item is in the current directory and has a different name than the source, add it to the arrays + if (dirname($item['target']) == $path && basename($item['source']) != basename($item['target'])) { $sources[] = basename($item['source']); $targets[] = basename($item['target']); } From 61837428ba59d1c5cc4730dda7d7a12c5bbb25f8 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Mon, 18 Jul 2011 16:36:34 -0400 Subject: [PATCH 050/122] Add post_delete and post_rename hooks and fix the constructor --- apps/files_sharing/appinfo/app.php | 2 ++ apps/files_sharing/lib_share.php | 41 +++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index a559026c5b..3b4b16e484 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -1,5 +1,7 @@ "files_sharing_administration", "order" => 10, "href" => OC_HELPER::linkTo( "files_sharing", "admin.php" ), diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 75a76ffb78..83e5486ddf 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -20,6 +20,9 @@ * */ +OC_HOOK::connect("OC_FILESYSTEM","post_delete", "OC_SHARE", "deleteItem"); +OC_HOOK::connect("OC_FILESYSTEM","post_rename", "OC_SHARE", "renameItem"); + /** * This class manages shared items within the database. */ @@ -39,10 +42,19 @@ class OC_SHARE { $token = sha1("$uid_owner-$item"); } else { $query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)"); - $sourceLocalPath = substr($source, strlen("/".$uid_owner."/files/"));; foreach ($uid_shared_with as $uid) { - // TODO check to see if target already exists in database - $target = "/".$uid."/files/Share/".$sourceLocalPath; + $target = "/".$uid."/files/Share".$source; + $check = OC_DB::prepare("SELECT COUNT(target) FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ?"); + $result = $check->execute(array($target, $uid))->fetchAll(); + $counter = 1; + while (count($result > 0)) { + if ($pos = strrpos($target, ".")) { + $target = substr($target, 0, $pos)."_".$counter.substr($target, $pos); + } else { + $target .= $counter; + } + $result = $check->execute(array($target, $uid))->fetchAll(); + } $query->execute(array($uid_owner, $uid, $source, $target, $permissions)); } } @@ -87,7 +99,7 @@ class OC_SHARE { /** * 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 * - * Also can be used for getting all item shared with you e.g. pass '/MTGap/files' + * Also can be used for getting all items shared with you e.g. pass '/MTGap/files' * * @param $targetFolder The target folder of the items to look for * @return An array with all items in the database that are in the target folder @@ -242,6 +254,27 @@ class OC_SHARE { $query->execute(array($target."%", $_SESSION['user_id'])); } + /** + * 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 = "/".$_SESSION['user_id']."/files".$arguments['path']; + $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE source COLLATE latin1_bin LIKE ? AND uid_owner = ?"); + $query->execute(array($source."%", $_SESSION['user_id'])); + } + + /** + * 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 = "/".$_SESSION['user_id']."/files".$arguments['oldpath']; + $newSource = "/".$_SESSION['user_id']."/files".$arguments['newpath']; + $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET source = REPLACE(source, ?, ?) WHERE uid_owner = ?"); + $query->execute(array($oldSource, $newSource, $_SESSION['user_id'])); + } + } ?> From 029b21bf5464e52af159920cfb00dcedeb189e3b Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 20 Jul 2011 13:34:16 -0400 Subject: [PATCH 051/122] First implementation of sharing user interface --- apps/files_sharing/admin.php | 2 +- apps/files_sharing/ajax/share.php | 12 +++++++ apps/files_sharing/ajax/unshare.php | 12 +++++++ apps/files_sharing/appinfo/app.php | 4 +-- apps/files_sharing/js/list.js | 50 ++++++++++++++++++++++++++ apps/files_sharing/lib_share.php | 26 +++++++------- apps/files_sharing/list.php | 40 +++++++++++++++++++++ apps/files_sharing/templates/admin.php | 30 ---------------- apps/files_sharing/templates/list.php | 32 +++++++++++++++++ 9 files changed, 163 insertions(+), 45 deletions(-) create mode 100644 apps/files_sharing/ajax/share.php create mode 100644 apps/files_sharing/ajax/unshare.php create mode 100644 apps/files_sharing/js/list.js create mode 100644 apps/files_sharing/list.php delete mode 100644 apps/files_sharing/templates/admin.php create mode 100644 apps/files_sharing/templates/list.php diff --git a/apps/files_sharing/admin.php b/apps/files_sharing/admin.php index 0bb45731b2..9a583800ae 100644 --- a/apps/files_sharing/admin.php +++ b/apps/files_sharing/admin.php @@ -32,7 +32,7 @@ if (!OC_USER::isLoggedIn()){ OC_APP::setActiveNavigationEntry( "files_sharing_administration" ); $tmpl = new OC_TEMPLATE( "files_sharing", "admin", "admin" ); -$tmpl->assign( 'shared_items', OC_SHARE::getSharedItems()); +$tmpl->assign( 'shared_items', OC_SHARE::getMySharedItems()); $tmpl->printPage(); ?> \ No newline at end of file diff --git a/apps/files_sharing/ajax/share.php b/apps/files_sharing/ajax/share.php new file mode 100644 index 0000000000..7007d26f8b --- /dev/null +++ b/apps/files_sharing/ajax/share.php @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/apps/files_sharing/ajax/unshare.php b/apps/files_sharing/ajax/unshare.php new file mode 100644 index 0000000000..3207a972c9 --- /dev/null +++ b/apps/files_sharing/ajax/unshare.php @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index 3b4b16e484..b73f7d52e6 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -2,9 +2,9 @@ require_once('apps/files_sharing/lib_share.php'); -OC_APP::addSettingsPage( array( "id" => "files_sharing_administration", +OC_APP::addNavigationEntry( array( "id" => "files_sharing_list", "order" => 10, - "href" => OC_HELPER::linkTo( "files_sharing", "admin.php" ), + "href" => OC_HELPER::linkTo( "files_sharing", "list.php" ), "name" => "Share", "icon" => OC_HELPER::imagePath( "files_sharing", "share.png" ))); diff --git a/apps/files_sharing/js/list.js b/apps/files_sharing/js/list.js new file mode 100644 index 0000000000..5e91d57410 --- /dev/null +++ b/apps/files_sharing/js/list.js @@ -0,0 +1,50 @@ +$(document).ready(function() { + $( "#source" ).autocomplete({ + source: "../../files/ajax/autocomplete.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=""; +// html+=""; +// var expire=($('#expire').val())?$('#expire').val():'Never' +// html+="" +// html+="" +// html+="" +// html+="" +// $(html).insertBefore($('#newlink_row')); +// $('#expire').val(''); +// $('#expire_time').val(''); +// $('#path').val(''); +// } +// } + }); + }); +}); \ No newline at end of file diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 83e5486ddf..5b685ea390 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -36,6 +36,7 @@ class OC_SHARE { */ public function __construct($source, $uid_shared_with, $permissions, $public = false) { if ($source && OC_FILESYSTEM::file_exists($source) && OC_FILESYSTEM::is_readable($source)) { + $source = "/".$_SESSION['user_id']."/files".$source; $uid_owner = $_SESSION['user_id']; if ($public) { // TODO create token for public file @@ -43,18 +44,19 @@ class OC_SHARE { } else { $query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)"); foreach ($uid_shared_with as $uid) { - $target = "/".$uid."/files/Share".$source; - $check = OC_DB::prepare("SELECT COUNT(target) FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ?"); - $result = $check->execute(array($target, $uid))->fetchAll(); - $counter = 1; - while (count($result > 0)) { - if ($pos = strrpos($target, ".")) { - $target = substr($target, 0, $pos)."_".$counter.substr($target, $pos); - } else { - $target .= $counter; - } - $result = $check->execute(array($target, $uid))->fetchAll(); - } + $target = "/".$uid."/files/Share/".basename($source); + // TODO Fix check if target already exists +// $check = OC_DB::prepare("SELECT target FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ?"); +// $result = $check->execute(array($target, $uid))->fetchAll(); +// $counter = 1; +// while (count($result > 0)) { +// if ($pos = strrpos($target, ".")) { +// $target = substr($target, 0, $pos)."_".$counter.substr($target, $pos); +// } else { +// $target .= $counter; +// } +// $result = $check->execute(array($target, $uid))->fetchAll(); +// } $query->execute(array($uid_owner, $uid, $source, $target, $permissions)); } } diff --git a/apps/files_sharing/list.php b/apps/files_sharing/list.php new file mode 100644 index 0000000000..6c27899369 --- /dev/null +++ b/apps/files_sharing/list.php @@ -0,0 +1,40 @@ +. + * + */ + +require_once('../../lib/base.php'); +require_once('lib_share.php'); +require('template.php'); + +if (!OC_USER::isLoggedIn()){ + header( "Location: ".OC_HELPER::linkTo( "index.php" )); + exit(); +} + +OC_APP::setActiveNavigationEntry("files_sharing_list"); + +OC_UTIL::addScript("files_sharing", "list"); + +$tmpl = new OC_TEMPLATE("files_sharing", "list", "user"); +$tmpl->assign("shared_items", OC_SHARE::getMySharedItems()); +$tmpl->printPage(); + +?> \ No newline at end of file diff --git a/apps/files_sharing/templates/admin.php b/apps/files_sharing/templates/admin.php deleted file mode 100644 index 827b64143c..0000000000 --- a/apps/files_sharing/templates/admin.php +++ /dev/null @@ -1,30 +0,0 @@ - -
ItemShared WithItemShared WithPermissions
- - - - - - - - - - '> - - - - - - - - - - - - - - - - -
ItemShared WithPermissions
- \ No newline at end of file diff --git a/apps/files_sharing/templates/list.php b/apps/files_sharing/templates/list.php new file mode 100644 index 0000000000..244cd9992c --- /dev/null +++ b/apps/files_sharing/templates/list.php @@ -0,0 +1,32 @@ +
+ Your Shared Files + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ItemShared WithPermissions
+ +
From c9082d5b0d1fa8be7c916208a661388a108c6919 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 20 Jul 2011 14:16:20 -0400 Subject: [PATCH 052/122] Append number to name if target file already exists --- apps/files_sharing/ajax/unshare.php | 1 - apps/files_sharing/lib_share.php | 29 +++++++++++++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/apps/files_sharing/ajax/unshare.php b/apps/files_sharing/ajax/unshare.php index 3207a972c9..d70cf44c3e 100644 --- a/apps/files_sharing/ajax/unshare.php +++ b/apps/files_sharing/ajax/unshare.php @@ -6,7 +6,6 @@ require_once('../lib_share.php'); $source = $_GET['source']; $uid_shared_with = array($_GET['uid_shared_with']); -error_log("deleteitem called".$source.$uid_shared_with); OC_SHARE::unshare($source, $uid_shared_with); ?> \ No newline at end of file diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 5b685ea390..848c44788a 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -45,18 +45,23 @@ class OC_SHARE { $query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)"); foreach ($uid_shared_with as $uid) { $target = "/".$uid."/files/Share/".basename($source); - // TODO Fix check if target already exists -// $check = OC_DB::prepare("SELECT target FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ?"); -// $result = $check->execute(array($target, $uid))->fetchAll(); -// $counter = 1; -// while (count($result > 0)) { -// if ($pos = strrpos($target, ".")) { -// $target = substr($target, 0, $pos)."_".$counter.substr($target, $pos); -// } else { -// $target .= $counter; -// } -// $result = $check->execute(array($target, $uid))->fetchAll(); -// } + $check = OC_DB::prepare("SELECT target FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ?"); + $result = $check->execute(array($target, $uid))->fetchAll(); + if (count($result) > 0) { + if ($pos = strrpos($target, ".")) { + $name = substr($target, 0, $pos); + $ext = substr($target, $pos); + } else { + $name = $target; + } + $counter = 1; + while (count($result) > 0) { + $newTarget = $name."_".$counter.isset($ext); + $result = $check->execute(array($newTarget, $uid))->fetchAll(); + $counter++; + } + $target = $newTarget; + } $query->execute(array($uid_owner, $uid, $source, $target, $permissions)); } } From 1cfa911ce38a22788fae73e0770156263fdc03e5 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 20 Jul 2011 14:42:48 -0400 Subject: [PATCH 053/122] Update database.xml to current database fields, remove hard coded MTGap when mounting shared storage provider --- .../appinfo/.database.xml.kate-swp | Bin 0 -> 34 bytes apps/files_sharing/appinfo/database.xml | 26 +++++++----------- lib/base.php | 4 +-- 3 files changed, 12 insertions(+), 18 deletions(-) create mode 100644 apps/files_sharing/appinfo/.database.xml.kate-swp diff --git a/apps/files_sharing/appinfo/.database.xml.kate-swp b/apps/files_sharing/appinfo/.database.xml.kate-swp new file mode 100644 index 0000000000000000000000000000000000000000..f2127b00c76b8bd8d4d04cf340cdc6aa023a544f GIT binary patch literal 34 pcmZQzV36@nEJ;-eE>A2_aLdd|RnS!kOD!tS%+FIW)H4Wn1pu6)36}r> literal 0 HcmV?d00001 diff --git a/apps/files_sharing/appinfo/database.xml b/apps/files_sharing/appinfo/database.xml index bb80484bd6..3378b6b09e 100644 --- a/apps/files_sharing/appinfo/database.xml +++ b/apps/files_sharing/appinfo/database.xml @@ -8,10 +8,16 @@ *dbprefix*sharing - item + uid_owner text true - 128 + 64 + + + uid_shared_with + text + true + 64 source @@ -26,22 +32,10 @@ 128 - uid_owner - text - true - 64 - - - uid_shared_with - text - true - 64 - - permissions - text + integer true - 3 + 1 diff --git a/lib/base.php b/lib/base.php index d369b392a4..9218861ed5 100644 --- a/lib/base.php +++ b/lib/base.php @@ -166,8 +166,8 @@ class OC_UTIL { OC_FILESYSTEM::mount($rootStorage,'/'); // TODO add this storage provider in a proper way - $sharedStorage = OC_FILESYSTEM::createStorage('shared',array('datadir'=>'/MTGap/files/Share/')); - OC_FILESYSTEM::mount($sharedStorage,'MTGap/files/Share/'); + $sharedStorage = OC_FILESYSTEM::createStorage('shared',array('datadir'=>'/'.$_SESSION['user_id'].'/files/Share/')); + OC_FILESYSTEM::mount($sharedStorage,'/'.$_SESSION['user_id'].'/files/Share/'); $CONFIG_DATADIRECTORY = "$CONFIG_DATADIRECTORY_ROOT/$user/$root"; if( !is_dir( $CONFIG_DATADIRECTORY )){ From 22f84150454aa456307f0495adfa4cad07d962ce Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 20 Jul 2011 14:46:01 -0400 Subject: [PATCH 054/122] Remove accidental kate swap file --- apps/files_sharing/appinfo/.database.xml.kate-swp | Bin 34 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 apps/files_sharing/appinfo/.database.xml.kate-swp diff --git a/apps/files_sharing/appinfo/.database.xml.kate-swp b/apps/files_sharing/appinfo/.database.xml.kate-swp deleted file mode 100644 index f2127b00c76b8bd8d4d04cf340cdc6aa023a544f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 34 pcmZQzV36@nEJ;-eE>A2_aLdd|RnS!kOD!tS%+FIW)H4Wn1pu6)36}r> From 3e6037659e222f584e8165a5a5c860ef88991f71 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 20 Jul 2011 15:42:49 -0400 Subject: [PATCH 055/122] Change permissions to is_writeable --- apps/files_sharing/appinfo/database.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_sharing/appinfo/database.xml b/apps/files_sharing/appinfo/database.xml index 3378b6b09e..7ddaca21ae 100644 --- a/apps/files_sharing/appinfo/database.xml +++ b/apps/files_sharing/appinfo/database.xml @@ -32,7 +32,7 @@ 128 - permissions + is_writeable integer true 1 From fcda3a338c1a2cc08337dcc594a3f67bc4e8d879 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 20 Jul 2011 16:41:39 -0400 Subject: [PATCH 056/122] Fix bug in constructor for appending numbers to already existing targets --- apps/files_sharing/lib_share.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 848c44788a..ae730a21a5 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -47,16 +47,18 @@ class OC_SHARE { $target = "/".$uid."/files/Share/".basename($source); $check = OC_DB::prepare("SELECT target FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ?"); $result = $check->execute(array($target, $uid))->fetchAll(); + // Check if target already exists for the user, if it does append a number to the name 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) { - $newTarget = $name."_".$counter.isset($ext); + $newTarget = $name."_".$counter.$ext; $result = $check->execute(array($newTarget, $uid))->fetchAll(); $counter++; } From 6af4c465b8810926561406d38c1ba6bba69edf83 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 20 Jul 2011 16:52:01 -0400 Subject: [PATCH 057/122] Change all occurences of ['user_id'] to OC_USER::getUser() --- apps/files_sharing/lib_share.php | 40 ++++++++++++++-------------- apps/files_sharing/sharedstorage.php | 4 +-- lib/base.php | 4 +-- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index ae730a21a5..0cb2dea72c 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -36,8 +36,8 @@ class OC_SHARE { */ public function __construct($source, $uid_shared_with, $permissions, $public = false) { if ($source && OC_FILESYSTEM::file_exists($source) && OC_FILESYSTEM::is_readable($source)) { - $source = "/".$_SESSION['user_id']."/files".$source; - $uid_owner = $_SESSION['user_id']; + $source = "/".OC_USER::getUser()."/files".$source; + $uid_owner = OC_USER::getUser(); if ($public) { // TODO create token for public file $token = sha1("$uid_owner-$item"); @@ -83,7 +83,7 @@ class OC_SHARE { $source = $folders['source'].substr($oldTarget, strlen($folders['target'])); $item = self::getItem($folders['target']); $query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)"); - $query->execute(array($item[0]['uid_owner'], $_SESSION['user_id'], $source, $newTarget, $item[0]['is_writeable'])); + $query->execute(array($item[0]['uid_owner'], OC_USER::getUser(), $source, $newTarget, $item[0]['is_writeable'])); } /** @@ -93,7 +93,7 @@ class OC_SHARE { */ public static function getItem($target) { $query = OC_DB::prepare("SELECT uid_owner, source, is_writeable FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1"); - return $query->execute(array($target, $_SESSION['user_id']))->fetchAll(); + return $query->execute(array($target, OC_USER::getUser()))->fetchAll(); } /** @@ -102,7 +102,7 @@ class OC_SHARE { */ public static function getMySharedItems() { $query = OC_DB::prepare("SELECT uid_shared_with, source, is_writeable FROM *PREFIX*sharing WHERE uid_owner = ?"); - return $query->execute(array($_SESSION['user_id']))->fetchAll(); + return $query->execute(array(OC_USER::getUser()))->fetchAll(); } /** @@ -121,7 +121,7 @@ class OC_SHARE { // Remove any duplicate '/' $targetFolder = preg_replace('{(/)\1+}', "/", $targetFolder); $query = OC_DB::prepare("SELECT uid_owner, source, target FROM *PREFIX*sharing WHERE target COLLATE latin1_bin LIKE ? AND uid_shared_with = ?"); - return $query->execute(array($targetFolder."%", $_SESSION['user_id']))->fetchAll(); + return $query->execute(array($targetFolder."%", OC_USER::getUser()))->fetchAll(); } /** @@ -139,7 +139,7 @@ class OC_SHARE { while ($target != "" && $target != "/" && $target != "." && $target != $userDirectory) { // Check if the parent directory of this target location is shared $target = dirname($target); - $result = $query->execute(array($target, $_SESSION['user_id']))->fetchAll(); + $result = $query->execute(array($target, OC_USER::getUser()))->fetchAll(); if (count($result) > 0) { break; } @@ -162,7 +162,7 @@ class OC_SHARE { $target = rtrim($target, "/"); $target = preg_replace('{(/)\1+}', "/", $target); $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1"); - $result = $query->execute(array($target, $_SESSION['user_id']))->fetchAll(); + $result = $query->execute(array($target, OC_USER::getUser()))->fetchAll(); if (count($result) > 0) { return $result[0]['source']; } else { @@ -182,13 +182,13 @@ class OC_SHARE { */ public static function isWriteable($target) { $query = OC_DB::prepare("SELECT is_writeable FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1"); - $result = $query->execute(array($target, $_SESSION['user_id']))->fetchAll(); + $result = $query->execute(array($target, OC_USER::getUser()))->fetchAll(); if (count($result) > 0) { return $result[0]['is_writeable']; } else { // Check if the folder is writeable $folders = OC_SHARE::getParentFolders($target); - $result = $query->execute(array($folders['target'], $_SESSION['user_id']))->fetchAll(); + $result = $query->execute(array($folders['target'], OC_USER::getUser()))->fetchAll(); if (count($result) > 0) { return $result[0]['is_writeable']; } else { @@ -204,7 +204,7 @@ class OC_SHARE { */ public static function setSource($oldSource, $newSource) { $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET source = REPLACE(source, ?, ?) WHERE uid_owner = ?"); - $query->execute(array($oldSource, $newSource, $_SESSION['user_id'])); + $query->execute(array($oldSource, $newSource, OC_USER::getUser())); } /** @@ -217,7 +217,7 @@ class OC_SHARE { */ public static function setTarget($oldTarget, $newTarget) { $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET target = REPLACE(target, ?, ?) WHERE uid_shared_with = ?"); - $query->execute(array($oldTarget, $newTarget, $_SESSION['user_id'])); + $query->execute(array($oldTarget, $newTarget, OC_USER::getUser())); } /** @@ -232,7 +232,7 @@ class OC_SHARE { public static function setIsWriteable($source, $uid_shared_with, $is_writeable) { $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET is_writeable = ? WHERE source COLLATE latin1_bin LIKE ? AND uid_shared_with = ? AND uid_owner = ?"); foreach ($uid_shared_with as $uid) { - $query->execute(array($is_writeable, $source."%", $uid_shared_with, $_SESSION['user_id'])); + $query->execute(array($is_writeable, $source."%", $uid_shared_with, OC_USER::getUser())); } } @@ -247,7 +247,7 @@ class OC_SHARE { public static function unshare($source, $uid_shared_with) { $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE source COLLATE latin1_bin LIKE ? AND uid_shared_with = ? AND uid_owner = ?"); foreach ($uid_shared_with as $uid) { - $query->execute(array($source."%", $uid, $_SESSION['user_id'])); + $query->execute(array($source."%", $uid, OC_USER::getUser())); } } @@ -260,7 +260,7 @@ class OC_SHARE { */ public static function unshareFromMySelf($target) { $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE target COLLATE latin1_bin LIKE ? AND uid_shared_with = ?"); - $query->execute(array($target."%", $_SESSION['user_id'])); + $query->execute(array($target."%", OC_USER::getUser())); } /** @@ -268,9 +268,9 @@ class OC_SHARE { * @param $arguments Array of arguments passed from OC_HOOK */ public static function deleteItem($arguments) { - $source = "/".$_SESSION['user_id']."/files".$arguments['path']; + $source = "/".OC_USER::getUser()."/files".$arguments['path']; $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE source COLLATE latin1_bin LIKE ? AND uid_owner = ?"); - $query->execute(array($source."%", $_SESSION['user_id'])); + $query->execute(array($source."%", OC_USER::getUser())); } /** @@ -278,10 +278,10 @@ class OC_SHARE { * @param $arguments Array of arguments passed from OC_HOOK */ public static function renameItem($arguments) { - $oldSource = "/".$_SESSION['user_id']."/files".$arguments['oldpath']; - $newSource = "/".$_SESSION['user_id']."/files".$arguments['newpath']; + $oldSource = "/".OC_USER::getUser()."/files".$arguments['oldpath']; + $newSource = "/".OC_USER::getUser()."/files".$arguments['newpath']; $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET source = REPLACE(source, ?, ?) WHERE uid_owner = ?"); - $query->execute(array($oldSource, $newSource, $_SESSION['user_id'])); + $query->execute(array($oldSource, $newSource, OC_USER::getUser())); } } diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index b27d91de96..5fc2cc67b7 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -203,7 +203,7 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { public function getFolderSize($path) { if ($path == "" || $path == "/") { - $dbpath = $_SESSION['user_id']."/files/Share/"; + $dbpath = OC_USER::getUser()."/files/Share/"; } else { $source = $this->getSource($path); $dbpath = $this->getInternalPath($source); @@ -239,7 +239,7 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { } if ($size > 0) { if ($path == "" || $path == "/") { - $dbpath = $_SESSION['user_id']."/files/Share/"; + $dbpath = OC_USER::getUser()."/files/Share/"; } else { $source = $this->getSource($path); $dbpath = $this->getInternalPath($source); diff --git a/lib/base.php b/lib/base.php index 9218861ed5..de0df40fc3 100644 --- a/lib/base.php +++ b/lib/base.php @@ -166,8 +166,8 @@ class OC_UTIL { OC_FILESYSTEM::mount($rootStorage,'/'); // TODO add this storage provider in a proper way - $sharedStorage = OC_FILESYSTEM::createStorage('shared',array('datadir'=>'/'.$_SESSION['user_id'].'/files/Share/')); - OC_FILESYSTEM::mount($sharedStorage,'/'.$_SESSION['user_id'].'/files/Share/'); + $sharedStorage = OC_FILESYSTEM::createStorage('shared',array('datadir'=>'/'.OC_USER::getUser().'/files/Share/')); + OC_FILESYSTEM::mount($sharedStorage,'/'.OC_USER::getUser().'/files/Share/'); $CONFIG_DATADIRECTORY = "$CONFIG_DATADIRECTORY_ROOT/$user/$root"; if( !is_dir( $CONFIG_DATADIRECTORY )){ From 4abefde29047b6fe42240966ed4697f57cf733c0 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 20 Jul 2011 16:54:06 -0400 Subject: [PATCH 058/122] Remove admin page, administration is not needed at this time for sharing --- apps/files_sharing/admin.php | 38 ------------------------------------ 1 file changed, 38 deletions(-) delete mode 100644 apps/files_sharing/admin.php diff --git a/apps/files_sharing/admin.php b/apps/files_sharing/admin.php deleted file mode 100644 index 9a583800ae..0000000000 --- a/apps/files_sharing/admin.php +++ /dev/null @@ -1,38 +0,0 @@ -. - * - */ - -require_once('../../lib/base.php'); -require_once( 'lib_share.php' ); -require( 'template.php' ); - -if (!OC_USER::isLoggedIn()){ - header( "Location: ".OC_HELPER::linkTo( "index.php" )); - exit(); -} - -OC_APP::setActiveNavigationEntry( "files_sharing_administration" ); - -$tmpl = new OC_TEMPLATE( "files_sharing", "admin", "admin" ); -$tmpl->assign( 'shared_items', OC_SHARE::getMySharedItems()); -$tmpl->printPage(); - -?> \ No newline at end of file From 302527c2d654f87d064e4dd0a5cb0609e9aedec5 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Thu, 21 Jul 2011 14:53:51 -0400 Subject: [PATCH 059/122] Remove shared items check, it prevents sharing items if there aren't already any. --- apps/files_sharing/templates/list.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/files_sharing/templates/list.php b/apps/files_sharing/templates/list.php index 244cd9992c..73ffff1ab6 100644 --- a/apps/files_sharing/templates/list.php +++ b/apps/files_sharing/templates/list.php @@ -1,6 +1,5 @@
Your Shared Files - @@ -28,5 +27,4 @@
-
From e6e673d7c0b5cf9476aa394d35e24ca65d07d24a Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Fri, 22 Jul 2011 20:41:16 -0400 Subject: [PATCH 060/122] Use SUBSTR instead of LIKE in queries, should now work with SQLite --- apps/files_sharing/lib_share.php | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 0cb2dea72c..43821fc719 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -120,8 +120,8 @@ class OC_SHARE { } // Remove any duplicate '/' $targetFolder = preg_replace('{(/)\1+}', "/", $targetFolder); - $query = OC_DB::prepare("SELECT uid_owner, source, target FROM *PREFIX*sharing WHERE target COLLATE latin1_bin LIKE ? AND uid_shared_with = ?"); - return $query->execute(array($targetFolder."%", OC_USER::getUser()))->fetchAll(); + $query = OC_DB::prepare("SELECT uid_owner, source, target FROM *PREFIX*sharing WHERE SUBSTR(target, 1, ?) = ? AND uid_shared_with = ?"); + return $query->execute(array(strlen($targetFolder), $targetFolder, OC_USER::getUser()))->fetchAll(); } /** @@ -133,13 +133,13 @@ class OC_SHARE { // Remove any duplicate or trailing '/' $target = rtrim($target, "/"); $target = preg_replace('{(/)\1+}', "/", $target); - $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1"); + $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE SUBSTR(target, 1, ?) = ? AND uid_shared_with = ? LIMIT 1"); // Prevent searching for user directory e.g. '/MTGap/files' $userDirectory = substr($target, 0, strpos($target, "files") + 5); while ($target != "" && $target != "/" && $target != "." && $target != $userDirectory) { // Check if the parent directory of this target location is shared $target = dirname($target); - $result = $query->execute(array($target, OC_USER::getUser()))->fetchAll(); + $result = $query->execute(array(strlen($target), $target, OC_USER::getUser()))->fetchAll(); if (count($result) > 0) { break; } @@ -230,9 +230,9 @@ class OC_SHARE { * @param $is_writeable True if the user has write permission or false if read only */ public static function setIsWriteable($source, $uid_shared_with, $is_writeable) { - $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET is_writeable = ? WHERE source COLLATE latin1_bin LIKE ? AND uid_shared_with = ? AND uid_owner = ?"); + $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET is_writeable = ? WHERE SUBSTR(source, 1, ?) = ? AND uid_shared_with = ? AND uid_owner = ?"); foreach ($uid_shared_with as $uid) { - $query->execute(array($is_writeable, $source."%", $uid_shared_with, OC_USER::getUser())); + $query->execute(array($is_writeable, strlen($source), $source, $uid_shared_with, OC_USER::getUser())); } } @@ -245,9 +245,9 @@ class OC_SHARE { * @param $uid_shared_with Array of users to unshare the item from */ public static function unshare($source, $uid_shared_with) { - $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE source COLLATE latin1_bin LIKE ? AND uid_shared_with = ? AND uid_owner = ?"); + $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE source SUBSTR(source, 1, ?) = ? AND uid_shared_with = ? AND uid_owner = ?"); foreach ($uid_shared_with as $uid) { - $query->execute(array($source."%", $uid, OC_USER::getUser())); + $query->execute(array(strlen($source), $source, $uid, OC_USER::getUser())); } } @@ -259,8 +259,8 @@ class OC_SHARE { * @param $target The target location of the item */ public static function unshareFromMySelf($target) { - $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE target COLLATE latin1_bin LIKE ? AND uid_shared_with = ?"); - $query->execute(array($target."%", OC_USER::getUser())); + $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE SUBSTR(target, 1, ?) = ? AND uid_shared_with = ?"); + $query->execute(array(strlen($target), $target, OC_USER::getUser())); } /** @@ -269,8 +269,8 @@ class OC_SHARE { */ public static function deleteItem($arguments) { $source = "/".OC_USER::getUser()."/files".$arguments['path']; - $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE source COLLATE latin1_bin LIKE ? AND uid_owner = ?"); - $query->execute(array($source."%", OC_USER::getUser())); + $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? AND uid_owner = ?"); + $query->execute(array(strlen($source), $source, OC_USER::getUser())); } /** @@ -280,8 +280,7 @@ class OC_SHARE { public static function renameItem($arguments) { $oldSource = "/".OC_USER::getUser()."/files".$arguments['oldpath']; $newSource = "/".OC_USER::getUser()."/files".$arguments['newpath']; - $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET source = REPLACE(source, ?, ?) WHERE uid_owner = ?"); - $query->execute(array($oldSource, $newSource, OC_USER::getUser())); + self::setSource($oldSource, $newSource); } } From 4993fb46654749646bc156bde350e3af4bf6879d Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sat, 23 Jul 2011 14:41:01 -0400 Subject: [PATCH 061/122] Filter out files you unshare from yourself in opendir() --- apps/files_sharing/lib_share.php | 23 ++++++++++++----------- apps/files_sharing/sharedstorage.php | 12 ++++++++++-- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 43821fc719..6e43e203b2 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -108,20 +108,21 @@ class OC_SHARE { /** * 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 * - * Also can be used for getting all items shared with you e.g. pass '/MTGap/files' + * Works for both target and source folders. Can be used for getting all items shared with you e.g. pass '/MTGap/files' * - * @param $targetFolder The target folder of the items to look for - * @return An array with all items in the database that are in the target folder + * @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($targetFolder) { + public static function getItemsInFolder($folder) { // Append '/' in order to filter out the folder itself if not already there - if (substr($targetFolder, -1) !== "/") { - $targetFolder .= "/"; + if (substr($folder, -1) !== "/") { + $folder .= "/"; } // Remove any duplicate '/' - $targetFolder = preg_replace('{(/)\1+}', "/", $targetFolder); - $query = OC_DB::prepare("SELECT uid_owner, source, target FROM *PREFIX*sharing WHERE SUBSTR(target, 1, ?) = ? AND uid_shared_with = ?"); - return $query->execute(array(strlen($targetFolder), $targetFolder, OC_USER::getUser()))->fetchAll(); + $folder = preg_replace('{(/)\1+}', "/", $folder); + $length = strlen($folder); + $query = OC_DB::prepare("SELECT uid_owner, source, target FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? OR SUBSTR(target, 1, ?) = ? AND uid_shared_with = ?"); + return $query->execute(array($length, $folder, $length, $folder, OC_USER::getUser()))->fetchAll(); } /** @@ -133,13 +134,13 @@ class OC_SHARE { // Remove any duplicate or trailing '/' $target = rtrim($target, "/"); $target = preg_replace('{(/)\1+}', "/", $target); - $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE SUBSTR(target, 1, ?) = ? AND uid_shared_with = ? LIMIT 1"); + $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1"); // Prevent searching for user directory e.g. '/MTGap/files' $userDirectory = substr($target, 0, strpos($target, "files") + 5); while ($target != "" && $target != "/" && $target != "." && $target != $userDirectory) { // Check if the parent directory of this target location is shared $target = dirname($target); - $result = $query->execute(array(strlen($target), $target, OC_USER::getUser()))->fetchAll(); + $result = $query->execute(array($target, OC_USER::getUser()))->fetchAll(); if (count($result) > 0) { break; } diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 5fc2cc67b7..c26423594f 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -93,7 +93,7 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { // Remove any duplicate or trailing '/' $path = rtrim($this->datadir.$path, "/"); $path = preg_replace('{(/)\1+}', "/", $path); - $modifiedItems = OC_SHARE::getItemsInFolder($path); + $modifiedItems = OC_SHARE::getItemsInFolder($source); if ($modifiedItems && $dh) { global $FAKEDIRS; $sources = array(); @@ -103,6 +103,10 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { if (dirname($item['target']) == $path && basename($item['source']) != basename($item['target'])) { $sources[] = basename($item['source']); $targets[] = basename($item['target']); + // If the item was unshared from self, add it it to the arrays + } elseif ($item['target'] == "/") { + $sources[] = basename($item['source']); + $targets[] = ""; } } // Don't waste time if there aren't any modified items in the current directory @@ -116,7 +120,11 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { $files[] = $filename; // The file has a different name than the source and is added to the fakedirs } else { - $files[] = $targets[array_search($filename, $sources)]; + $target = $targets[array_search($filename, $sources)]; + // Don't add the file if it was unshared from self by the user + if ($target != "") { + $files[] = $target; + } } } } From 17b5bcb24f15d5b22185a48a3f7854e713b47747 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 24 Jul 2011 14:38:01 -0400 Subject: [PATCH 062/122] Bug fixes for unshare() and opendir(), thanks darkh --- apps/files_sharing/lib_share.php | 2 +- apps/files_sharing/sharedstorage.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 6e43e203b2..44babc73a7 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -246,7 +246,7 @@ class OC_SHARE { * @param $uid_shared_with Array of users to unshare the item from */ public static function unshare($source, $uid_shared_with) { - $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE source SUBSTR(source, 1, ?) = ? AND uid_shared_with = ? AND uid_owner = ?"); + $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? AND uid_shared_with = ? AND uid_owner = ?"); foreach ($uid_shared_with as $uid) { $query->execute(array(strlen($source), $source, $uid, OC_USER::getUser())); } diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index c26423594f..8efccbc769 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -77,6 +77,9 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { global $FAKEDIRS; $path = $this->datadir.$path; $sharedItems = OC_SHARE::getItemsInFolder($path); + if (empty($sharedItems)) { + return false; + } foreach ($sharedItems as $item) { // If item is in the root of the shared storage provider add it to the fakedirs if (dirname($item['target'])."/" == $path) { From 4282a42b3f0be65bb22f12ed297602043c3ecbbb Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 24 Jul 2011 15:47:37 -0400 Subject: [PATCH 063/122] Add support for user autocomplete --- apps/files_sharing/ajax/userautocomplete.php | 23 ++++++++++++++++++++ apps/files_sharing/js/list.js | 4 ++++ 2 files changed, 27 insertions(+) create mode 100644 apps/files_sharing/ajax/userautocomplete.php diff --git a/apps/files_sharing/ajax/userautocomplete.php b/apps/files_sharing/ajax/userautocomplete.php new file mode 100644 index 0000000000..b6285aba9b --- /dev/null +++ b/apps/files_sharing/ajax/userautocomplete.php @@ -0,0 +1,23 @@ + "error", "data" => array( "message" => "Authentication error" ))); + exit(); +} +$query = $_GET['term']; +$length = strlen($query); +$query = strtolower($query); +$users = array(); +$ocusers = OC_USER::getUsers(); +$self = OC_USER::getUser(); +foreach ($ocusers as $user) { + if ($user != $self && substr(strtolower($user), 0, $length) == $query) { + $users[] = (object)array('id' => $user, 'label' => $user, 'name' => $user); + } +} +echo json_encode($users); + +?> diff --git a/apps/files_sharing/js/list.js b/apps/files_sharing/js/list.js index 5e91d57410..41eabd1f4a 100644 --- a/apps/files_sharing/js/list.js +++ b/apps/files_sharing/js/list.js @@ -3,6 +3,10 @@ $(document).ready(function() { 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); From 5148eb9121e3d19211629ea29ac3ebf70b111ef6 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 24 Jul 2011 16:07:39 -0400 Subject: [PATCH 064/122] Include groups in user autocomplete --- apps/files_sharing/ajax/userautocomplete.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/files_sharing/ajax/userautocomplete.php b/apps/files_sharing/ajax/userautocomplete.php index b6285aba9b..6e1469ae34 100644 --- a/apps/files_sharing/ajax/userautocomplete.php +++ b/apps/files_sharing/ajax/userautocomplete.php @@ -3,8 +3,8 @@ $RUNTIME_NOAPPS = true; require_once('../../../lib/base.php'); -if( !OC_USER::isLoggedIn()){ - echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" ))); +if (!OC_USER::isLoggedIn()) { + echo json_encode(array("status" => "error", "data" => array("message" => "Authentication error"))); exit(); } $query = $_GET['term']; @@ -13,11 +13,17 @@ $query = strtolower($query); $users = array(); $ocusers = OC_USER::getUsers(); $self = OC_USER::getUser(); +$groups = OC_GROUP::getUserGroups($self); foreach ($ocusers as $user) { if ($user != $self && substr(strtolower($user), 0, $length) == $query) { $users[] = (object)array('id' => $user, 'label' => $user, 'name' => $user); } } +foreach ($groups as $group) { + if (substr(strtolower($group), 0, $length) == $query) { + $users[] = (object)array('id' => $group, 'label' => $group, 'name' => $group); + } +} echo json_encode($users); ?> From 1ec0b6ecc151f9701a0a8c4873c6b06ff3586136 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Tue, 26 Jul 2011 21:27:40 -0400 Subject: [PATCH 065/122] jQuery dialog for sharing files from within file browser - Not functional yet --- apps/files_sharing/appinfo/app.php | 2 + apps/files_sharing/js/share.js | 84 ++++++++++++++++++++++++++++++ files/templates/index.php | 2 +- 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 apps/files_sharing/js/share.js diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index b73f7d52e6..879bd1ea0e 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -2,6 +2,8 @@ require_once('apps/files_sharing/lib_share.php'); +OC_UTIL::addScript("files_sharing", "share"); + OC_APP::addNavigationEntry( array( "id" => "files_sharing_list", "order" => 10, "href" => OC_HELPER::linkTo( "files_sharing", "list.php" ), diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js new file mode 100644 index 0000000000..84449406ab --- /dev/null +++ b/apps/files_sharing/js/share.js @@ -0,0 +1,84 @@ +$(document).ready(function() { + $('.share').click(function(event) { + event.preventDefault(); + // TODO Replace with getSelectedFiles() from files.js + var files = ''; + $('td.selection input:checkbox:checked').parent().parent().each(function(i, element) { + files += ', ' + $(element).attr('data-file'); + }); + files = files.substr(1); + var html = "
"; + html += ""; + html += ""; + html += "
"; + html += "
"; + html += ""; + html += ""; + html += "
"; + html += "Advanced"; + html += "
"; + html += ""; + html += "
"; + html += ""; + html += "
"; + html += ""; + html += "
"; + $(html).dialog(); + }); + $("input[name=share_type]").live('change', function() { + $('#private').toggle(); + $('#public').toggle(); + }); + $('.uid_shared_with').live('keyup', function() { + $(this).autocomplete({ + source: "../apps/files_sharing/ajax/userautocomplete.php", + minLength: 1 + }); + }); + $('button.add-uid_shared_with').live('click', function(event) { + event.preventDefault(); + // TODO Make sure previous textbox has a valid user or group name + var html = "
"; + html += ""; + html += ""; + $(html).insertAfter('.add-uid_shared_with'); + $(this).html(" -  "); + $(this).removeClass("add-uid_shared_with fancybutton"); + $(this).addClass("remove-uid_shared_with fancybutton"); + }); + $('button.remove-uid_shared_with').live('click', function(event) { + event.preventDefault(); + alert("remove"); + // TODO Remove corresponding row + }); + $('#toggle-private-advanced').live('click', function(event) { + event.preventDefault(); + $('#private-advanced').toggle(); + }); + $('button.submit').live('click', function(event) { + event.preventDefault(); + if ($("input[name=share_type]:checked").val() == 'public') { + // TODO Construct public link + } else { + // TODO Construct shared item + // TODO Check all inputs are valid +// var source; +// var uid_shared_with; +// var permissions; +// var data = 'source='+source+'&uid_shared_with='+uid_shared_with+'&permissions='+permissions; +// $.ajax({ +// type: 'GET', +// url: 'ajax/share.php', +// cache: false, +// data: data +// }); + } + }); +}); \ No newline at end of file diff --git a/files/templates/index.php b/files/templates/index.php index efc9290063..f540ef4748 100644 --- a/files/templates/index.php +++ b/files/templates/index.php @@ -15,7 +15,7 @@ t( 'Download' ); ?> - + t( 'Delete' ); ?>
From 64b5332f3331544721fc38232bb05a6a35231763 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 27 Jul 2011 19:25:33 -0400 Subject: [PATCH 066/122] Make file sharing dialog work - only works for one file/folder and user --- apps/files_sharing/js/share.js | 43 ++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js index 84449406ab..e5977c30a9 100644 --- a/apps/files_sharing/js/share.js +++ b/apps/files_sharing/js/share.js @@ -1,13 +1,7 @@ $(document).ready(function() { $('.share').click(function(event) { event.preventDefault(); - // TODO Replace with getSelectedFiles() from files.js - var files = ''; - $('td.selection input:checkbox:checked').parent().parent().each(function(i, element) { - files += ', ' + $(element).attr('data-file'); - }); - files = files.substr(1); - var html = "
"; + var html = "
"; html += ""; html += ""; html += "
"; @@ -18,7 +12,7 @@ $(document).ready(function() { html += "Advanced"; html += "
"; html += ""; html += ""; html += "
"; html += ""; html += "
"; - $(html).dialog(); + $(html).dialog({ + close: function(event, ui) { + $(this).remove(); + } + }); }); $("input[name=share_type]").live('change', function() { $('#private').toggle(); @@ -62,23 +61,27 @@ $(document).ready(function() { event.preventDefault(); $('#private-advanced').toggle(); }); + $('#expire').datepicker({ + dateFormat:'MM d, yy', + altField: "#expire_time", + altFormat: "yy-mm-dd" + }); $('button.submit').live('click', function(event) { event.preventDefault(); if ($("input[name=share_type]:checked").val() == 'public') { // TODO Construct public link } else { - // TODO Construct shared item // TODO Check all inputs are valid -// var source; -// var uid_shared_with; -// var permissions; -// var data = 'source='+source+'&uid_shared_with='+uid_shared_with+'&permissions='+permissions; -// $.ajax({ -// type: 'GET', -// url: 'ajax/share.php', -// cache: false, -// data: data -// }); + var source = $('#dir').val()+"/"+getSelectedFiles('name'); + var uid_shared_with = $('.uid_shared_with').val(); + var permissions = 0; + var data = 'source='+source+'&uid_shared_with='+uid_shared_with+'&permissions='+permissions; + $.ajax({ + type: 'GET', + url: '../apps/files_sharing/ajax/share.php', + cache: false, + data: data + }); } }); }); \ No newline at end of file From d36850f0f2b507b566e57de3befb3fb8e2dd5c5a Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 27 Jul 2011 19:52:10 -0400 Subject: [PATCH 067/122] Close sharing dialog box on share success --- apps/files_sharing/js/share.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js index e5977c30a9..c77c2aa77d 100644 --- a/apps/files_sharing/js/share.js +++ b/apps/files_sharing/js/share.js @@ -1,7 +1,7 @@ $(document).ready(function() { $('.share').click(function(event) { event.preventDefault(); - var html = "
"; + var html = "
"; html += ""; html += ""; html += "
"; @@ -80,7 +80,10 @@ $(document).ready(function() { type: 'GET', url: '../apps/files_sharing/ajax/share.php', cache: false, - data: data + data: data, + success: function() { + $('#dialog').dialog('close'); + } }); } }); From 31a067b5a39ee9132054d9e5338ad6d745136a3b Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Thu, 28 Jul 2011 15:31:52 -0400 Subject: [PATCH 068/122] Add support for sharing multiple files from share dialog, move loops outside of OC_SHARE --- apps/files_sharing/ajax/share.php | 10 ++++-- apps/files_sharing/ajax/unshare.php | 2 +- apps/files_sharing/js/share.js | 11 +++++-- apps/files_sharing/lib_share.php | 48 +++++++++++++---------------- 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/apps/files_sharing/ajax/share.php b/apps/files_sharing/ajax/share.php index 7007d26f8b..b2c3a47795 100644 --- a/apps/files_sharing/ajax/share.php +++ b/apps/files_sharing/ajax/share.php @@ -4,9 +4,13 @@ $RUNTIME_NOAPPS = true; require_once('../../../lib/base.php'); require_once('../lib_share.php'); -$source = $_GET['source']; -$uid_shared_with = array($_GET['uid_shared_with']); +$sources = $_GET['sources']; +$uid_shared_with = $_GET['uid_shared_with']; $permissions = $_GET['permissions']; -new OC_SHARE($source, $uid_shared_with, $permissions); +foreach ($sources as $source) { + foreach ($uid_shared_with as $uid) { + new OC_SHARE($source, $uid, $permissions); + } +} ?> \ No newline at end of file diff --git a/apps/files_sharing/ajax/unshare.php b/apps/files_sharing/ajax/unshare.php index d70cf44c3e..4d83d33225 100644 --- a/apps/files_sharing/ajax/unshare.php +++ b/apps/files_sharing/ajax/unshare.php @@ -5,7 +5,7 @@ require_once('../../../lib/base.php'); require_once('../lib_share.php'); $source = $_GET['source']; -$uid_shared_with = array($_GET['uid_shared_with']); +$uid_shared_with = $_GET['uid_shared_with']; OC_SHARE::unshare($source, $uid_shared_with); ?> \ No newline at end of file diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js index c77c2aa77d..32926c6811 100644 --- a/apps/files_sharing/js/share.js +++ b/apps/files_sharing/js/share.js @@ -11,7 +11,7 @@ $(document).ready(function() { html += "
"; html += "Advanced"; html += "
"; - html += "