From 96ad8a15b43130d5a075c87211a5752d5094473f Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Mon, 22 Aug 2011 12:37:44 -0400 Subject: [PATCH] Register OC_Share for autoloading and cleanup hooks --- apps/files_sharing/appinfo/app.php | 6 +++-- apps/files_sharing/lib_share.php | 42 +++++++++--------------------- 2 files changed, 17 insertions(+), 31 deletions(-) diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index 771d91b93ba..c175142319f 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -1,9 +1,11 @@ "string")); +OC::$CLASSPATH['OC_Share'] = "apps/files_sharing/lib_share.php"; +OC_Hook::connect("OC_Filesystem", "post_delete", "OC_Share", "deleteItem"); +OC_Hook::connect("OC_Filesystem", "post_rename", "OC_Share", "renameItem"); +OC_Filesystem::registerStorageType("shared", "OC_Filestorage_Shared", array("datadir" => "string")); OC_Util::addScript("files_sharing", "share"); OC_Util::addScript("3rdparty", "chosen/chosen.jquery.min"); OC_Util::addStyle( 'files_sharing', 'sharing' ); diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 0c9528141ff..dd73a20051f 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -20,9 +20,6 @@ * */ -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. */ @@ -177,6 +174,7 @@ class OC_Share { $query = OC_DB::prepare("SELECT uid_shared_with, permissions FROM *PREFIX*sharing WHERE source = ? AND uid_owner = ?"); return $query->execute(array($source, OC_User::getUser()))->fetchAll(); } + /** * Get all items the current user is sharing * @return An array with all items the user is sharing @@ -185,7 +183,7 @@ class OC_Share { $query = OC_DB::prepare("SELECT uid_shared_with, source, permissions FROM *PREFIX*sharing WHERE uid_owner = ?"); return $query->execute(array(OC_User::getUser()))->fetchAll(); } - + /** * Get the items within a shared folder that have their own entry for the purpose of name, location, or permissions that differ from the folder itself * @@ -204,7 +202,7 @@ class OC_Share { $query = OC_DB::prepare("SELECT uid_owner, source, target, permissions FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? OR SUBSTR(target, 1, ?) = ? AND uid_shared_with ".self::getUsersAndGroups()); return $query->execute(array($length, $folder, $length, $folder))->fetchAll(); } - + /** * Get the source and target parent folders of the specified target location * @param $target The target location of the item @@ -301,18 +299,6 @@ 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) { - $oldSource = self::cleanPath($oldSource); - $newSource = self::cleanPath($newSource); - $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET source = REPLACE(source, ?, ?) WHERE uid_owner = ?"); - $query->execute(array($oldSource, $newSource, OC_User::getUser())); - } - /** * Set the target location to a new value * @@ -327,7 +313,7 @@ class OC_Share { $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET target = REPLACE(target, ?, ?) WHERE uid_shared_with ".self::getUsersAndGroups()); $query->execute(array($oldTarget, $newTarget)); } - + /** * Change the permissions for the specified item and user * @@ -342,7 +328,7 @@ class OC_Share { $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET permissions = ? WHERE SUBSTR(source, 1, ?) = ? AND uid_owner = ? AND uid_shared_with ".self::getUsersAndGroups($uid_shared_with)); $query->execute(array($permissions, strlen($source), $source, OC_User::getUser())); } - + /** * Unshare the item, removes it from all specified users * @@ -356,7 +342,7 @@ class OC_Share { $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? AND uid_owner = ? AND uid_shared_with ".self::getUsersAndGroups($uid_shared_with)); $query->execute(array(strlen($source), $source, OC_User::getUser())); } - + /** * Unshare the item from the current user, removes it only from the database and doesn't touch the source file * @@ -378,25 +364,23 @@ class OC_Share { /** * Remove the item from the database, the owner deleted the file - * @param $arguments Array of arguments passed from OC_HOOK + * @param $arguments Array of arguments passed from OC_Hook */ public static function deleteItem($arguments) { - $source = "/".OC_User::getUser()."/files".$arguments['path']; - $source = self::cleanPath($source); + $source = "/".OC_User::getUser()."/files".self::cleanPath($arguments['path']); $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? AND uid_owner = ?"); $query->execute(array(strlen($source), $source, OC_User::getUser())); } /** * Rename the item in the database, the owner renamed the file - * @param $arguments Array of arguments passed from OC_HOOK + * @param $arguments Array of arguments passed from OC_Hook */ public static function renameItem($arguments) { - $oldSource = "/".OC_User::getUser()."/files".$arguments['oldpath']; - $oldSource = self::cleanPath($oldSource); - $newSource = "/".OC_User::getUser()."/files".$arguments['newpath']; - $newSource = self::cleanPath($newSource); - self::setSource($oldSource, $newSource); + $oldSource = "/".OC_User::getUser()."/files".self::cleanPath($arguments['oldpath']); + $newSource = "/".OC_User::getUser()."/files".self::cleanPath($arguments['newpath']); + $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET source = REPLACE(source, ?, ?) WHERE uid_owner = ?"); + $query->execute(array($oldSource, $newSource, OC_User::getUser())); } } -- 2.39.5