--- /dev/null
+<?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