diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2014-04-02 12:04:51 +0200 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2014-04-23 12:54:24 +0200 |
commit | a27db9e4cadb9b5ee26f7b17d3a5997b07639489 (patch) | |
tree | f1f312d96caf3bac49b22ef76fa3decd71a4f8d7 /apps/files_sharing/lib/sharedstorage.php | |
parent | cfc52ccc3d3e7e233912adc58bdc95618d941a30 (diff) | |
download | nextcloud-server-a27db9e4cadb9b5ee26f7b17d3a5997b07639489.tar.gz nextcloud-server-a27db9e4cadb9b5ee26f7b17d3a5997b07639489.zip |
first steps to remove the shared folder:
- mount shares to the root folder instead of "Shared/"
- navigate in shared folder and sub-folders
- show previews
- show correct file permissions
- download/edit files
Diffstat (limited to 'apps/files_sharing/lib/sharedstorage.php')
-rw-r--r-- | apps/files_sharing/lib/sharedstorage.php | 60 |
1 files changed, 42 insertions, 18 deletions
diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index b922654e5ec..25a05a0d1f2 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -2,8 +2,9 @@ /** * ownCloud * - * @author Michael Gapczynski - * @copyright 2011 Michael Gapczynski mtgap@owncloud.com + * @author Bjoern Schiessle, Michael Gapczynski + * @copyright 2011 Michael Gapczynski <mtgap@owncloud.com> + * 2014 Bjoern Schiessle <schiessle@owncloud.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE @@ -27,15 +28,17 @@ namespace OC\Files\Storage; */ class Shared extends \OC\Files\Storage\Common { - private $sharedFolder; + private $mountPoint; // mount point relative to data/user/files + private $type; // can be "file" or "folder" private $files = array(); public function __construct($arguments) { - $this->sharedFolder = $arguments['sharedFolder']; + $this->mountPoint = $arguments['shareTarget']; + $this->type = $arguments['shareType']; } public function getId() { - return 'shared::' . $this->sharedFolder; + return 'shared::' . $this->mountPoint; } /** @@ -48,14 +51,14 @@ class Shared extends \OC\Files\Storage\Common { if (!isset($this->files[$target])) { // Check for partial files if (pathinfo($target, PATHINFO_EXTENSION) === 'part') { - $source = \OC_Share_Backend_File::getSource(substr($target, 0, -5)); + $source = \OC_Share_Backend_File::getSource(substr($target, 0, -5), $this->getMountPoint(), $this->getShareType()); if ($source) { $source['path'] .= '.part'; // All partial files have delete permission $source['permissions'] |= \OCP\PERMISSION_DELETE; } } else { - $source = \OC_Share_Backend_File::getSource($target); + $source = \OC_Share_Backend_File::getSource($target, $this->getMountPoint(), $this->getShareType()); } $this->files[$target] = $source; } @@ -119,8 +122,8 @@ class Shared extends \OC\Files\Storage\Common { public function opendir($path) { if ($path == '' || $path == '/') { $files = \OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_Folder::FORMAT_OPENDIR); - \OC\Files\Stream\Dir::register('shared', $files); - return opendir('fakedir://shared'); + \OC\Files\Stream\Dir::register($this->mountPoint, $files); + return opendir('fakedir://' . $this->mountPoint); } else if ($source = $this->getSourcePath($path)) { list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source); return $storage->opendir($internalPath); @@ -180,7 +183,7 @@ class Shared extends \OC\Files\Storage\Common { public function isCreatable($path) { if ($path == '') { - return false; + return ($this->getPermissions($this->getMountPoint()) & \OCP\PERMISSION_CREATE); } return ($this->getPermissions($path) & \OCP\PERMISSION_CREATE); } @@ -246,7 +249,7 @@ class Shared extends \OC\Files\Storage\Common { $source = $this->getSourcePath($path); if ($source) { $info = array( - 'target' => $this->sharedFolder . $path, + 'target' => $this->mountPoint . $path, 'source' => $source, ); \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info); @@ -264,7 +267,7 @@ class Shared extends \OC\Files\Storage\Common { return false; } $info = array( - 'target' => $this->sharedFolder . $path, + 'target' => $this->mountPoint . $path, 'source' => $source, ); \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info); @@ -343,7 +346,7 @@ class Shared extends \OC\Files\Storage\Common { } } $info = array( - 'target' => $this->sharedFolder . $path, + 'target' => $this->mountPoint . $path, 'source' => $source, 'mode' => $mode, ); @@ -393,16 +396,37 @@ class Shared extends \OC\Files\Storage\Common { } public static function setup($options) { + $shares = \OCP\Share::getItemsSharedWith('file'); if (!\OCP\User::isLoggedIn() || \OCP\User::getUser() != $options['user'] - || \OCP\Share::getItemsSharedWith('file') + || $shares ) { - $user_dir = $options['user_dir']; - \OC\Files\Filesystem::mount('\OC\Files\Storage\Shared', - array('sharedFolder' => '/Shared'), - $user_dir . '/Shared/'); + foreach ($shares as $share) { + \OC\Files\Filesystem::mount('\OC\Files\Storage\Shared', + array( + 'shareTarget' => $share['file_target'], + 'shareType' => $share['item_type'], + ), + $options['user_dir'] . '/' . $share['file_target']); + } } } + /** + * @brief return mount point of share, relative to data/user/files + * @return string + */ + public function getMountPoint() { + return ltrim($this->mountPoint, '/'); + } + + /** + * @brief return share type, can be "file" or "folder" + * @return string + */ + public function getShareType() { + return $this->type; + } + public function hasUpdated($path, $time) { if ($path == '') { return false; |