/**\r
* @brief \r
*/\r
- public static function postShared( $params ) {\r
- \r
+ public static function postShared($params) {\r
+\r
// NOTE: $params has keys:\r
// [itemType] => file\r
// itemSource -> int, filecache file ID\r
// [fileSource] => 13\r
// [fileTarget] => /test8\r
// [id] => 10\r
- // [token] => \r
- \r
+ // [token] =>\r
// TODO: Should other kinds of item be encrypted too?\r
- if ( $params['itemType'] === 'file' ) {\r
- \r
- $view = new \OC_FilesystemView( '/' );\r
+ if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {\r
+\r
+ $view = new \OC_FilesystemView('/');\r
$session = new Session($view);\r
$userId = \OCP\User::getUser();\r
- $util = new Util( $view, $userId );\r
- $path = $util->fileIdToPath( $params['itemSource'] );\r
+ $util = new Util($view, $userId);\r
+ $path = $util->fileIdToPath($params['itemSource']);\r
\r
$sharingEnabled = \OCP\Share::isEnabled();\r
- $usersSharing = $util->getSharingUsersArray( $sharingEnabled, $path);\r
- \r
- // Recursively expand path to include subfiles\r
- $allPaths = $util->getPaths( $path );\r
- \r
- $failed = array();\r
- \r
- // Loop through all subfiles\r
- foreach ( $allPaths as $path ) {\r
- \r
+\r
+ if ($params['itemType'] === 'folder') {\r
+ //list($owner, $ownerPath) = $util->getUidAndFilename($filePath);\r
+ $allFiles = $util->getAllFiles($path);\r
+ } else {\r
+ $allFiles = array($path);\r
+ }\r
+\r
+ foreach ($allFiles as $path) {\r
+ $usersSharing = $util->getSharingUsersArray($sharingEnabled, $path);\r
+\r
+ $failed = array();\r
+\r
// Attempt to set shareKey\r
- if ( ! $util->setSharedFileKeyfiles( $session, $usersSharing, $path ) ) {\r
- \r
+ if (!$util->setSharedFileKeyfiles($session, $usersSharing, $path)) {\r
+\r
$failed[] = $path;\r
- \r
}\r
- \r
}\r
- \r
+\r
// If no attempts to set keyfiles failed\r
- if ( empty( $failed ) ) {\r
- \r
+ if (empty($failed)) {\r
+\r
return true;\r
- \r
} else {\r
- \r
+\r
return false;\r
- \r
}\r
- \r
}\r
- \r
}\r
\r
/**\r
}
+ /**
+ *@ brief geo recursively through a dir and collect all files and sub files.
+ * @param type $dir relative to the users files folder
+ * @return array with list of files relative to the users files folder
+ */
+ public function getAllFiles($dir) {
+ $result = array();
+ $path = $this->view->getLocalFile();
+ $content = $this->view->getDirectoryContent("/".$this->userFilesDir.'/'.$this->filesFolderName.$dir);
+
+ foreach ($content as $c) {
+ if ($c['type'] === "dir" ) {
+ $result = array_merge($result, $this->getAllFiles(substr($c['path'],5)));
+ } else {
+ $result[] = substr($c['path'], 5);
+ }
+ }
+ return $result;
+ }
+
}