]> source.dussan.org Git - nextcloud-server.git/commitdiff
introduce util.php for file sharing which provides functionallity which is also neede...
authorBjörn Schießle <schiessle@owncloud.com>
Tue, 6 Nov 2012 13:39:30 +0000 (14:39 +0100)
committerBjörn Schießle <schiessle@owncloud.com>
Thu, 8 Nov 2012 14:18:24 +0000 (15:18 +0100)
apps/files_sharing/appinfo/app.php
apps/files_sharing/lib/util.php [new file with mode: 0644]

index 109f86b2e8752b78c9fd53270d383b61d45f4ecf..bfed4266ad40ec83ef144b685f84092d063d8532 100644 (file)
@@ -3,6 +3,7 @@
 OC::$CLASSPATH['OC_Share_Backend_File'] = "apps/files_sharing/lib/share/file.php";
 OC::$CLASSPATH['OC_Share_Backend_Folder'] = 'apps/files_sharing/lib/share/folder.php';
 OC::$CLASSPATH['OC_Filestorage_Shared'] = "apps/files_sharing/lib/sharedstorage.php";
+OC::$CLASSPATH['OC_Files_Sharing_Util'] = "apps/files_sharing/lib/util.php";
 OCP\Util::connectHook('OC_Filesystem', 'setup', 'OC_Filestorage_Shared', 'setup');
 OCP\Share::registerBackend('file', 'OC_Share_Backend_File');
 OCP\Share::registerBackend('folder', 'OC_Share_Backend_Folder', 'file');
diff --git a/apps/files_sharing/lib/util.php b/apps/files_sharing/lib/util.php
new file mode 100644 (file)
index 0000000..84cddb7
--- /dev/null
@@ -0,0 +1,79 @@
+<?php
+/**\r
+ * ownCloud\r
+ *\r
+ * @author Bjoern Schiessle\r
+ * @copyright 2012 Bjoern Schiessle schiessle@owncloud.com\r
+ *\r
+ * This library is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE\r
+ * License as published by the Free Software Foundation; either\r
+ * version 3 of the License, or any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.\r
+ *\r
+ * You should have received a copy of the GNU Affero General Public\r
+ * License along with this library.  If not, see <http://www.gnu.org/licenses/>.\r
+ *\r
+ */\r
+\r
+\r
+class OC_Files_Sharing_Util {\r
+\r
+       private static $files = array();\r
+\r
+       /**\r
+        * @brief Get the source file path and the permissions granted for a shared file\r
+        * @param string Shared target file path\r
+        * @return Returns array with the keys path and permissions or false if not found\r
+        */\r
+       private function getFile($target) {\r
+               $target = '/'.$target;\r
+               $target = rtrim($target, '/');\r
+               if (isset(self::$files[$target])) {\r
+                       return self::$files[$target];\r
+               } else {\r
+                       $pos = strpos($target, '/', 1);\r
+                       // Get shared folder name\r
+                       if ($pos !== false) {\r
+                               $folder = substr($target, 0, $pos);\r
+                               if (isset(self::$files[$folder])) {\r
+                                       $file = self::$files[$folder];\r
+                               } else {\r
+                                       $file = OCP\Share::getItemSharedWith('folder', $folder, OC_Share_Backend_File::FORMAT_SHARED_STORAGE);\r
+                               }\r
+                               if ($file) {\r
+                                       self::$files[$target]['path'] = $file['path'].substr($target, strlen($folder));\r
+                                       self::$files[$target]['permissions'] = $file['permissions'];\r
+                                       return self::$files[$target];\r
+                               }\r
+                       } else {\r
+                               $file = OCP\Share::getItemSharedWith('file', $target, OC_Share_Backend_File::FORMAT_SHARED_STORAGE);\r
+                               if ($file) {\r
+                                       self::$files[$target] = $file;\r
+                                       return self::$files[$target];\r
+                               }\r
+                       }\r
+                       OCP\Util::writeLog('files_sharing', 'File source not found for: '.$target, OCP\Util::ERROR);\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       /**\r
+        * @brief Get the source file path for a shared file\r
+        * @param string Shared target file path\r
+        * @return Returns source file path or false if not found\r
+        */\r
+       public static function getSourcePath($target) {\r
+               $file = self::getFile($target);\r
+               if (isset($file['path'])) {\r
+                       $uid = substr($file['path'], 1, strpos($file['path'], '/', 1) - 1);\r
+                       OC_Filesystem::mount('OC_Filestorage_Local', array('datadir' => OC_User::getHome($uid)), $uid);\r
+                       return $file['path'];\r
+               }\r
+               return false;\r
+       }\r
+}
\ No newline at end of file