summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/appinfo/app.php9
-rw-r--r--apps/files_sharing/appinfo/info.xml2
-rw-r--r--apps/files_sharing/appinfo/update.php10
-rw-r--r--apps/files_sharing/lib/cache.php258
-rw-r--r--apps/files_sharing/lib/permissions.php85
-rw-r--r--apps/files_sharing/lib/share/file.php75
-rw-r--r--apps/files_sharing/lib/share/folder.php43
-rw-r--r--apps/files_sharing/lib/sharedstorage.php268
-rw-r--r--apps/files_sharing/lib/watcher.php51
-rw-r--r--apps/files_sharing/public.php254
10 files changed, 782 insertions, 273 deletions
diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php
index 0104d0d017f..d3e05cc62d8 100644
--- a/apps/files_sharing/appinfo/app.php
+++ b/apps/files_sharing/appinfo/app.php
@@ -2,8 +2,11 @@
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";
-OCP\Util::connectHook('OC_Filesystem', 'setup', 'OC_Filestorage_Shared', 'setup');
+OC::$CLASSPATH['OC\Files\Storage\Shared'] = "apps/files_sharing/lib/sharedstorage.php";
+OC::$CLASSPATH['OC\Files\Cache\Shared_Cache'] = 'apps/files_sharing/lib/cache.php';
+OC::$CLASSPATH['OC\Files\Cache\Shared_Permissions'] = 'apps/files_sharing/lib/permissions.php';
+OC::$CLASSPATH['OC\Files\Cache\Shared_Watcher'] = 'apps/files_sharing/lib/watcher.php';
+OCP\Util::connectHook('OC_Filesystem', 'setup', '\OC\Files\Storage\Shared', 'setup');
OCP\Share::registerBackend('file', 'OC_Share_Backend_File');
OCP\Share::registerBackend('folder', 'OC_Share_Backend_Folder', 'file');
-OCP\Util::addScript('files_sharing', 'share'); \ No newline at end of file
+OCP\Util::addScript('files_sharing', 'share');
diff --git a/apps/files_sharing/appinfo/info.xml b/apps/files_sharing/appinfo/info.xml
index a44d0338bb6..1f24a4dde83 100644
--- a/apps/files_sharing/appinfo/info.xml
+++ b/apps/files_sharing/appinfo/info.xml
@@ -5,7 +5,7 @@
<description>File sharing between users</description>
<licence>AGPL</licence>
<author>Michael Gapczynski</author>
- <require>4.9</require>
+ <require>4.91</require>
<shipped>true</shipped>
<default_enable/>
<types>
diff --git a/apps/files_sharing/appinfo/update.php b/apps/files_sharing/appinfo/update.php
index e998626f4a4..1d22b32b503 100644
--- a/apps/files_sharing/appinfo/update.php
+++ b/apps/files_sharing/appinfo/update.php
@@ -9,10 +9,12 @@ if (version_compare($installedVersion, '0.3', '<')) {
OC_User::useBackend(new OC_User_Database());
OC_Group::useBackend(new OC_Group_Database());
OC_App::loadApps(array('authentication'));
+ $rootView = new \OC\Files\View('');
while ($row = $result->fetchRow()) {
- $itemSource = OC_FileCache::getId($row['source'], '');
+ $meta = $rootView->getFileInfo($$row['source']);
+ $itemSource = $meta['fileid'];
if ($itemSource != -1) {
- $file = OC_FileCache::get($row['source'], '');
+ $file = $meta;
if ($file['mimetype'] == 'httpd/unix-directory') {
$itemType = 'folder';
} else {
@@ -68,6 +70,6 @@ if (version_compare($installedVersion, '0.3.3', '<')) {
OC_App::loadApps(array('authentication'));
$users = OC_User::getUsers();
foreach ($users as $user) {
- OC_FileCache::delete('Shared', '/'.$user.'/files/');
+// OC_FileCache::delete('Shared', '/'.$user.'/files/');
}
-} \ No newline at end of file
+}
diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php
new file mode 100644
index 00000000000..9655e447875
--- /dev/null
+++ b/apps/files_sharing/lib/cache.php
@@ -0,0 +1,258 @@
+<?php
+/**
+ * ownCloud
+ *
+ * @author Michael Gapczynski
+ * @copyright 2012 Michael Gapczynski mtgap@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
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace OC\Files\Cache;
+
+/**
+ * Metadata cache for shared files
+ *
+ * don't use this class directly if you need to get metadata, use \OC\Files\Filesystem::getFileInfo instead
+ */
+class Shared_Cache extends Cache {
+
+ private $files = array();
+
+ public function __construct($storage) {
+
+ }
+
+ /**
+ * @brief Get the source cache of a shared file or folder
+ * @param string $target Shared target file path
+ * @return \OC\Files\Cache\Cache
+ */
+ private function getSourceCache($target) {
+ $source = \OC_Share_Backend_File::getSource($target);
+ if (isset($source['path'])) {
+ $source['path'] = '/' . $source['uid_owner'] . '/' . $source['path'];
+ \OC\Files\Filesystem::initMountPoints($source['uid_owner']);
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source['path']);
+ if ($storage) {
+ $this->files[$target] = $internalPath;
+ $cache = $storage->getCache();
+ $this->storageId = $storage->getId();
+ $this->numericId = $cache->getNumericStorageId();
+ return $cache;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * get the stored metadata of a file or folder
+ *
+ * @param string/int $file
+ * @return array
+ */
+ public function get($file) {
+ if ($file == '') {
+ return \OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_File::FORMAT_FILE_APP_ROOT);
+ } else if (is_string($file)) {
+ if ($cache = $this->getSourceCache($file)) {
+ return $cache->get($this->files[$file]);
+ }
+ } else {
+ $query = \OC_DB::prepare(
+ 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`
+ FROM `*PREFIX*filecache` WHERE `fileid` = ?');
+ $result = $query->execute(array($file));
+ $data = $result->fetchRow();
+ $data['fileid'] = (int)$data['fileid'];
+ $data['size'] = (int)$data['size'];
+ $data['mtime'] = (int)$data['mtime'];
+ $data['encrypted'] = (bool)$data['encrypted'];
+ $data['mimetype'] = $this->getMimetype($data['mimetype']);
+ $data['mimepart'] = $this->getMimetype($data['mimepart']);
+ return $data;
+ }
+ return false;
+ }
+
+ /**
+ * get the metadata of all files stored in $folder
+ *
+ * @param string $folder
+ * @return array
+ */
+ public function getFolderContents($folder) {
+ if ($folder == '') {
+ $files = \OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_File::FORMAT_GET_FOLDER_CONTENTS);
+ foreach ($files as &$file) {
+ $file['mimetype'] = $this->getMimetype($file['mimetype']);
+ $file['mimepart'] = $this->getMimetype($file['mimepart']);
+ }
+ return $files;
+ } else {
+ if ($cache = $this->getSourceCache($folder)) {
+ return $cache->getFolderContents($this->files[$folder]);
+ }
+ }
+ return false;
+ }
+
+ /**
+ * store meta data for a file or folder
+ *
+ * @param string $file
+ * @param array $data
+ *
+ * @return int file id
+ */
+ public function put($file, array $data) {
+ if ($cache = $this->getSourceCache($file)) {
+ return $cache->put($this->files[$file], $data);
+ }
+ return false;
+ }
+
+ /**
+ * get the file id for a file
+ *
+ * @param string $file
+ * @return int
+ */
+ public function getId($file) {
+ if ($cache = $this->getSourceCache($file)) {
+ return $cache->getId($this->files[$file]);
+ }
+ return -1;
+ }
+
+ /**
+ * check if a file is available in the cache
+ *
+ * @param string $file
+ * @return bool
+ */
+ public function inCache($file) {
+ if ($file == '') {
+ return true;
+ }
+ return parent::inCache($file);
+ }
+
+ /**
+ * remove a file or folder from the cache
+ *
+ * @param string $file
+ */
+ public function remove($file) {
+ if ($cache = $this->getSourceCache($file)) {
+ $cache->remove($this->files[$file]);
+ }
+ }
+
+ /**
+ * Move a file or folder in the cache
+ *
+ * @param string $source
+ * @param string $target
+ */
+ public function move($source, $target) {
+ if ($cache = $this->getSourceCache($source)) {
+ $targetPath = \OC_Share_Backend_File::getSourcePath(dirname($target));
+ if ($targetPath) {
+ $targetPath .= '/' . basename($target);
+ $cache->move($this->files[$source], $targetPath);
+ }
+
+ }
+ }
+
+ /**
+ * remove all entries for files that are stored on the storage from the cache
+ */
+ public function clear() {
+ // Not a valid action for Shared Cache
+ }
+
+ /**
+ * @param string $file
+ *
+ * @return int, Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE
+ */
+ public function getStatus($file) {
+ if ($file == '') {
+ return self::COMPLETE;
+ }
+ if ($cache = $this->getSourceCache($file)) {
+ return $cache->getStatus($this->files[$file]);
+ }
+ return self::NOT_FOUND;
+ }
+
+ /**
+ * search for files matching $pattern
+ *
+ * @param string $pattern
+ * @return array of file data
+ */
+ public function search($pattern) {
+ // TODO
+ }
+
+ /**
+ * search for files by mimetype
+ *
+ * @param string $part1
+ * @param string $part2
+ * @return array
+ */
+ public function searchByMime($mimetype) {
+ if (strpos($mimetype, '/')) {
+ $where = '`mimetype` = ?';
+ } else {
+ $where = '`mimepart` = ?';
+ }
+ $mimetype = $this->getMimetypeId($mimetype);
+ $ids = $this->getAll();
+ $placeholders = join(',', array_fill(0, count($ids), '?'));
+ $query = \OC_DB::prepare('
+ SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`
+ FROM `*PREFIX*filecache` WHERE ' . $where . ' AND `fileid` IN (' . $placeholders . ')'
+ );
+ $result = $query->execute(array_merge(array($mimetype), $ids));
+ return $result->fetchAll();
+ }
+
+ /**
+ * get the size of a folder and set it in the cache
+ *
+ * @param string $path
+ * @return int
+ */
+ public function calculateFolderSize($path) {
+ if ($cache = $this->getSourceCache($path)) {
+ return $cache->calculateFolderSize($this->files[$path]);
+ }
+ return 0;
+ }
+
+ /**
+ * get all file ids on the files on the storage
+ *
+ * @return int[]
+ */
+ public function getAll() {
+ return \OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_File::FORMAT_GET_ALL);
+ }
+
+}
diff --git a/apps/files_sharing/lib/permissions.php b/apps/files_sharing/lib/permissions.php
new file mode 100644
index 00000000000..2b068ff9350
--- /dev/null
+++ b/apps/files_sharing/lib/permissions.php
@@ -0,0 +1,85 @@
+<?php
+/**
+* ownCloud
+*
+* @author Michael Gapczynski
+* @copyright 2012 Michael Gapczynski mtgap@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
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*/
+namespace OC\Files\Cache;
+
+class Shared_Permissions extends Permissions {
+
+ /**
+ * get the permissions for a single file
+ *
+ * @param int $fileId
+ * @param string $user
+ * @return int (-1 if file no permissions set)
+ */
+ public function get($fileId, $user) {
+ if ($fileId == -1) {
+ return \OCP\PERMISSION_READ;
+ }
+ $source = \OCP\Share::getItemSharedWithBySource('file', $fileId, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE, null, true);
+ if ($source) {
+ return $source['permissions'];
+ } else {
+ return -1;
+ }
+ }
+
+ /**
+ * set the permissions of a file
+ *
+ * @param int $fileId
+ * @param string $user
+ * @param int $permissions
+ */
+ public function set($fileId, $user, $permissions) {
+ // Not a valid action for Shared Permissions
+ }
+
+ /**
+ * get the permissions of multiply files
+ *
+ * @param int[] $fileIds
+ * @param string $user
+ * @return int[]
+ */
+ public function getMultiple($fileIds, $user) {
+ if (count($fileIds) === 0) {
+ return array();
+ }
+ foreach ($fileIds as $fileId) {
+ $filePermissions[$fileId] = self::get($fileId, $user);
+ }
+ return $filePermissions;
+ }
+
+ /**
+ * remove the permissions for a file
+ *
+ * @param int $fileId
+ * @param string $user
+ */
+ public function remove($fileId, $user) {
+ // Not a valid action for Shared Permissions
+ }
+
+ public function removeMultiple($fileIds, $user) {
+ // Not a valid action for Shared Permissions
+ }
+}
diff --git a/apps/files_sharing/lib/share/file.php b/apps/files_sharing/lib/share/file.php
index ac585236831..6d3c55a008f 100644
--- a/apps/files_sharing/lib/share/file.php
+++ b/apps/files_sharing/lib/share/file.php
@@ -22,16 +22,18 @@
class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
const FORMAT_SHARED_STORAGE = 0;
- const FORMAT_FILE_APP = 1;
+ const FORMAT_GET_FOLDER_CONTENTS = 1;
const FORMAT_FILE_APP_ROOT = 2;
const FORMAT_OPENDIR = 3;
+ const FORMAT_GET_ALL = 4;
private $path;
public function isValidSource($itemSource, $uidOwner) {
- $path = OC_FileCache::getPath($itemSource, $uidOwner);
- if ($path) {
- $this->path = $path;
+ $query = \OC_DB::prepare('SELECT `name` FROM `*PREFIX*filecache` WHERE `fileid` = ?');
+ $result = $query->execute(array($itemSource));
+ if ($row = $result->fetchRow()) {
+ $this->path = $row['name'];
return true;
}
return false;
@@ -70,37 +72,21 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
public function formatItems($items, $format, $parameters = null) {
if ($format == self::FORMAT_SHARED_STORAGE) {
// Only 1 item should come through for this format call
- return array('path' => $items[key($items)]['path'], 'permissions' => $items[key($items)]['permissions']);
- } else if ($format == self::FORMAT_FILE_APP) {
- if (isset($parameters['mimetype_filter']) && $parameters['mimetype_filter']) {
- $mimetype_filter = $parameters['mimetype_filter'];
- }
+ return array('path' => $items[key($items)]['path'], 'permissions' => $items[key($items)]['permissions'], 'uid_owner' => $items[key($items)]['uid_owner']);
+ } else if ($format == self::FORMAT_GET_FOLDER_CONTENTS) {
$files = array();
foreach ($items as $item) {
- if (isset($mimetype_filter)
- && strpos($item['mimetype'], $mimetype_filter) !== 0
- && $item['mimetype'] != 'httpd/unix-directory') {
- continue;
- }
$file = array();
- $file['id'] = $item['file_source'];
+ $file['fileid'] = $item['file_source'];
+ $file['storage'] = $item['storage'];
$file['path'] = $item['file_target'];
+ $file['parent'] = $item['file_parent'];
$file['name'] = basename($item['file_target']);
- $file['ctime'] = $item['ctime'];
- $file['mtime'] = $item['mtime'];
$file['mimetype'] = $item['mimetype'];
+ $file['mimepart'] = $item['mimepart'];
$file['size'] = $item['size'];
+ $file['mtime'] = $item['mtime'];
$file['encrypted'] = $item['encrypted'];
- $file['versioned'] = $item['versioned'];
- $file['directory'] = $parameters['folder'];
- $file['type'] = ($item['mimetype'] == 'httpd/unix-directory') ? 'dir' : 'file';
- $file['permissions'] = $item['permissions'];
- if ($file['type'] == 'file') {
- // Remove Create permission if type is file
- $file['permissions'] &= ~OCP\PERMISSION_CREATE;
- }
- // NOTE: Temporary fix to allow unsharing of files in root of Shared directory
- $file['permissions'] |= OCP\PERMISSION_DELETE;
$files[] = $file;
}
return $files;
@@ -111,17 +97,48 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
if ($item['mtime'] > $mtime) {
$mtime = $item['mtime'];
}
- $size += $item['size'];
+ $size += (int)$item['size'];
}
- return array(0 => array('id' => -1, 'name' => 'Shared', 'mtime' => $mtime, 'mimetype' => 'httpd/unix-directory', 'size' => $size, 'writable' => false, 'type' => 'dir', 'directory' => '', 'permissions' => OCP\PERMISSION_READ));
+ return array('fileid' => -1, 'name' => 'Shared', 'mtime' => $mtime, 'mimetype' => 'httpd/unix-directory', 'size' => $size);
} else if ($format == self::FORMAT_OPENDIR) {
$files = array();
foreach ($items as $item) {
$files[] = basename($item['file_target']);
}
return $files;
+ } else if ($format == self::FORMAT_GET_ALL) {
+ $ids = array();
+ foreach ($items as $item) {
+ $ids[] = $item['file_source'];
+ }
+ return $ids;
}
return array();
}
+ public static function getSource($target) {
+ if ($target == '') {
+ return false;
+ }
+ $target = '/'.$target;
+ $target = rtrim($target, '/');
+ $pos = strpos($target, '/', 1);
+ // Get shared folder name
+ if ($pos !== false) {
+ $folder = substr($target, 0, $pos);
+ $source = \OCP\Share::getItemSharedWith('folder', $folder, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
+ if ($source) {
+ $source['path'] = $source['path'].substr($target, strlen($folder));
+ return $source;
+ }
+ } else {
+ $source = \OCP\Share::getItemSharedWith('file', $target, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
+ if ($source) {
+ return $source;
+ }
+ }
+ \OCP\Util::writeLog('files_sharing', 'File source not found for: '.$target, \OCP\Util::ERROR);
+ return false;
+ }
+
}
diff --git a/apps/files_sharing/lib/share/folder.php b/apps/files_sharing/lib/share/folder.php
index d414fcf10fc..11c8c6b1e80 100644
--- a/apps/files_sharing/lib/share/folder.php
+++ b/apps/files_sharing/lib/share/folder.php
@@ -21,47 +21,26 @@
class OC_Share_Backend_Folder extends OC_Share_Backend_File implements OCP\Share_Backend_Collection {
- public function formatItems($items, $format, $parameters = null) {
- if ($format == self::FORMAT_SHARED_STORAGE) {
- // Only 1 item should come through for this format call
- return array('path' => $items[key($items)]['path'], 'permissions' => $items[key($items)]['permissions']);
- } else if ($format == self::FORMAT_FILE_APP && isset($parameters['folder'])) {
- // Only 1 item should come through for this format call
- $folder = $items[key($items)];
- if (isset($parameters['mimetype_filter'])) {
- $mimetype_filter = $parameters['mimetype_filter'];
- } else {
- $mimetype_filter = '';
- }
- $path = $folder['path'].substr($parameters['folder'], 7 + strlen($folder['file_target']));
- $files = OC_FileCache::getFolderContent($path, '', $mimetype_filter);
- foreach ($files as &$file) {
- $file['directory'] = $parameters['folder'];
- $file['type'] = ($file['mimetype'] == 'httpd/unix-directory') ? 'dir' : 'file';
- $file['permissions'] = $folder['permissions'];
- if ($file['type'] == 'file') {
- // Remove Create permission if type is file
- $file['permissions'] &= ~OCP\PERMISSION_CREATE;
- }
- }
- return $files;
- }
- return array();
- }
-
public function getChildren($itemSource) {
$children = array();
$parents = array($itemSource);
+ $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?');
+ $result = $query->execute(array('httpd/unix-directory'));
+ if ($row = $result->fetchRow()) {
+ $mimetype = $row['id'];
+ } else {
+ $mimetype = -1;
+ }
while (!empty($parents)) {
$parents = "'".implode("','", $parents)."'";
- $query = OC_DB::prepare('SELECT `id`, `name`, `mimetype` FROM `*PREFIX*fscache` WHERE `parent` IN ('.$parents.')');
+ $query = OC_DB::prepare('SELECT `fileid`, `name`, `mimetype` FROM `*PREFIX*filecache` WHERE `parent` IN ('.$parents.')');
$result = $query->execute();
$parents = array();
while ($file = $result->fetchRow()) {
- $children[] = array('source' => $file['id'], 'file_path' => $file['name']);
+ $children[] = array('source' => $file['fileid'], 'file_path' => $file['name']);
// If a child folder is found look inside it
- if ($file['mimetype'] == 'httpd/unix-directory') {
- $parents[] = $file['id'];
+ if ($file['mimetype'] == $mimetype) {
+ $parents[] = $file['fileid'];
}
}
}
diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php
index 50db9166fe7..ea28ca69b93 100644
--- a/apps/files_sharing/lib/sharedstorage.php
+++ b/apps/files_sharing/lib/sharedstorage.php
@@ -20,10 +20,12 @@
*
*/
+namespace OC\Files\Storage;
+
/**
* Convert target path to source path and pass the function call to the correct storage provider
*/
-class OC_Filestorage_Shared extends OC_Filestorage_Common {
+class Shared extends \OC\Files\Storage\Common {
private $sharedFolder;
private $files = array();
@@ -32,54 +34,36 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
$this->sharedFolder = $arguments['sharedFolder'];
}
+ public function getId(){
+ return 'shared::' . $this->sharedFolder;
+ }
+
/**
- * @brief Get the source file path and the permissions granted for a shared file
+ * @brief Get the source file path, permissions, and owner for a shared file
* @param string Shared target file path
- * @return Returns array with the keys path and permissions or false if not found
+ * @return Returns array with the keys path, permissions, and owner or false if not found
*/
private function getFile($target) {
- $target = '/'.$target;
- $target = rtrim($target, '/');
- if (isset($this->files[$target])) {
- return $this->files[$target];
- } else {
- $pos = strpos($target, '/', 1);
- // Get shared folder name
- if ($pos !== false) {
- $folder = substr($target, 0, $pos);
- if (isset($this->files[$folder])) {
- $file = $this->files[$folder];
- } else {
- $file = OCP\Share::getItemSharedWith('folder', $folder, OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
- }
- if ($file) {
- $this->files[$target]['path'] = $file['path'].substr($target, strlen($folder));
- $this->files[$target]['permissions'] = $file['permissions'];
- return $this->files[$target];
- }
- } else {
- $file = OCP\Share::getItemSharedWith('file', $target, OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
- if ($file) {
- $this->files[$target] = $file;
- return $this->files[$target];
- }
+ if (!isset($this->files[$target])) {
+ $source = \OC_Share_Backend_File::getSource($target);
+ if ($source) {
+ $source['path'] = '/'.$source['uid_owner'].'/'.$source['path'];
}
- OCP\Util::writeLog('files_sharing', 'File source not found for: '.$target, OCP\Util::ERROR);
- return false;
+ $this->files[$target] = $source;
}
+ return $this->files[$target];
}
/**
* @brief Get the source file path for a shared file
* @param string Shared target file path
- * @return Returns source file path or false if not found
+ * @return string source file path or false if not found
*/
private function getSourcePath($target) {
- $file = $this->getFile($target);
- if (isset($file['path'])) {
- $uid = substr($file['path'], 1, strpos($file['path'], '/', 1) - 1);
- OC_Filesystem::mount('OC_Filestorage_Local', array('datadir' => OC_User::getHome($uid)), $uid);
- return $file['path'];
+ $source = $this->getFile($target);
+ if ($source) {
+ \OC\Files\Filesystem::initMountPoints($source['uid_owner']);
+ return $source['path'];
}
return false;
}
@@ -87,61 +71,42 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
/**
* @brief Get the permissions granted for a shared file
* @param string Shared target file path
- * @return Returns CRUDS permissions granted or false if not found
+ * @return int CRUDS permissions granted or false if not found
*/
- private function getPermissions($target) {
- $file = $this->getFile($target);
- if (isset($file['permissions'])) {
- return $file['permissions'];
+ public function getPermissions($target) {
+ $source = $this->getFile($target);
+ if ($source) {
+ return $source['permissions'];
}
return false;
}
- /**
- * @brief Get the internal path to pass to the storage filesystem call
- * @param string Source file path
- * @return Source file path with mount point stripped out
- */
- private function getInternalPath($path) {
- $mountPoint = OC_Filesystem::getMountPoint($path);
- $internalPath = substr($path, strlen($mountPoint));
- return $internalPath;
- }
-
- public function getOwner($target) {
- $shared_item = OCP\Share::getItemSharedWith('folder', $target, OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
- if ($shared_item) {
- return $shared_item[0]["uid_owner"];
- }
- return null;
- }
-
public function mkdir($path) {
if ($path == '' || $path == '/' || !$this->isCreatable(dirname($path))) {
return false;
} else if ($source = $this->getSourcePath($path)) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->mkdir($this->getInternalPath($source));
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
+ return $storage->mkdir($internalPath);
}
return false;
}
public function rmdir($path) {
if (($source = $this->getSourcePath($path)) && $this->isDeletable($path)) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->rmdir($this->getInternalPath($source));
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
+ return $storage->rmdir($internalPath);
}
return false;
}
public function opendir($path) {
if ($path == '' || $path == '/') {
- $files = OCP\Share::getItemsSharedWith('file', OC_Share_Backend_Folder::FORMAT_OPENDIR);
- OC_FakeDirStream::$dirs['shared'] = $files;
+ $files = \OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_Folder::FORMAT_OPENDIR);
+ \OC\Files\Stream\Dir::register('shared', $files);
return opendir('fakedir://shared');
} else if ($source = $this->getSourcePath($path)) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->opendir($this->getInternalPath($source));
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
+ return $storage->opendir($internalPath);
}
return false;
}
@@ -150,16 +115,16 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
if ($path == '' || $path == '/') {
return true;
} else if ($source = $this->getSourcePath($path)) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->is_dir($this->getInternalPath($source));
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
+ return $storage->is_dir($internalPath);
}
return false;
}
public function is_file($path) {
if ($source = $this->getSourcePath($path)) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->is_file($this->getInternalPath($source));
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
+ return $storage->is_file($internalPath);
}
return false;
}
@@ -168,11 +133,10 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
if ($path == '' || $path == '/') {
$stat['size'] = $this->filesize($path);
$stat['mtime'] = $this->filemtime($path);
- $stat['ctime'] = $this->filectime($path);
return $stat;
} else if ($source = $this->getSourcePath($path)) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->stat($this->getInternalPath($source));
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
+ return $storage->stat($internalPath);
}
return false;
}
@@ -181,8 +145,8 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
if ($path == '' || $path == '/') {
return 'dir';
} else if ($source = $this->getSourcePath($path)) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->filetype($this->getInternalPath($source));
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
+ return $storage->filetype($internalPath);
}
return false;
}
@@ -191,8 +155,8 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
if ($path == '' || $path == '/' || $this->is_dir($path)) {
return 0;
} else if ($source = $this->getSourcePath($path)) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->filesize($this->getInternalPath($source));
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
+ return $storage->filesize($internalPath);
}
return false;
}
@@ -201,7 +165,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
if ($path == '') {
return false;
}
- return ($this->getPermissions($path) & OCP\PERMISSION_CREATE);
+ return ($this->getPermissions($path) & \OCP\PERMISSION_CREATE);
}
public function isReadable($path) {
@@ -212,54 +176,33 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
if ($path == '') {
return false;
}
- return ($this->getPermissions($path) & OCP\PERMISSION_UPDATE);
+ return ($this->getPermissions($path) & \OCP\PERMISSION_UPDATE);
}
public function isDeletable($path) {
if ($path == '') {
return true;
}
- return ($this->getPermissions($path) & OCP\PERMISSION_DELETE);
+ return ($this->getPermissions($path) & \OCP\PERMISSION_DELETE);
}
public function isSharable($path) {
if ($path == '') {
return false;
}
- return ($this->getPermissions($path) & OCP\PERMISSION_SHARE);
+ return ($this->getPermissions($path) & \OCP\PERMISSION_SHARE);
}
public function file_exists($path) {
if ($path == '' || $path == '/') {
return true;
} else if ($source = $this->getSourcePath($path)) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->file_exists($this->getInternalPath($source));
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
+ return $storage->file_exists($internalPath);
}
return false;
}
- public function filectime($path) {
- if ($path == '' || $path == '/') {
- $ctime = 0;
- if ($dh = $this->opendir($path)) {
- while (($filename = readdir($dh)) !== false) {
- $tempctime = $this->filectime($filename);
- if ($tempctime < $ctime) {
- $ctime = $tempctime;
- }
- }
- }
- return $ctime;
- } else {
- $source = $this->getSourcePath($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->filectime($this->getInternalPath($source));
- }
- }
- }
-
public function filemtime($path) {
if ($path == '' || $path == '/') {
$mtime = 0;
@@ -275,8 +218,8 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
} else {
$source = $this->getSourcePath($path);
if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->filemtime($this->getInternalPath($source));
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
+ return $storage->filemtime($internalPath);
}
}
}
@@ -288,9 +231,9 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
'target' => $this->sharedFolder.$path,
'source' => $source,
);
- OCP\Util::emitHook('OC_Filestorage_Shared', 'file_get_contents', $info);
- $storage = OC_Filesystem::getStorage($source);
- return $storage->file_get_contents($this->getInternalPath($source));
+ \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info);
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
+ return $storage->file_get_contents($internalPath);
}
}
@@ -304,9 +247,9 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
'target' => $this->sharedFolder.$path,
'source' => $source,
);
- OCP\Util::emitHook('OC_Filestorage_Shared', 'file_put_contents', $info);
- $storage = OC_Filesystem::getStorage($source);
- $result = $storage->file_put_contents($this->getInternalPath($source), $data);
+ \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info);
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
+ $result = $storage->file_put_contents($internalPath, $data);
return $result;
}
return false;
@@ -316,8 +259,8 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
// Delete the file if DELETE permission is granted
if ($source = $this->getSourcePath($path)) {
if ($this->isDeletable($path)) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->unlink($this->getInternalPath($source));
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
+ return $storage->unlink($internalPath);
} else if (dirname($path) == '/' || dirname($path) == '.') {
// Unshare the file from the user if in the root of the Shared folder
if ($this->is_dir($path)) {
@@ -325,7 +268,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
} else {
$itemType = 'file';
}
- return OCP\Share::unshareFromSelf($itemType, $path);
+ return \OCP\Share::unshareFromSelf($itemType, $path);
}
}
return false;
@@ -340,8 +283,9 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
if (dirname($path1) == dirname($path2)) {
// Rename the file if UPDATE permission is granted
if ($this->isUpdatable($path1)) {
- $storage = OC_Filesystem::getStorage($oldSource);
- return $storage->rename($this->getInternalPath($oldSource), $this->getInternalPath($newSource));
+ list($storage, $oldInternalPath) = \OC\Files\Filesystem::resolvePath($oldSource);
+ list( , $newInternalPath) = \OC\Files\Filesystem::resolvePath($newSource);
+ return $storage->rename($oldInternalPath, $newInternalPath);
}
} else {
// Move the file if DELETE and CREATE permissions are granted
@@ -355,8 +299,9 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
return $this->unlink($path1);
}
} else {
- $storage = OC_Filesystem::getStorage($oldSource);
- return $storage->rename($this->getInternalPath($oldSource), $this->getInternalPath($newSource));
+ list($storage, $oldInternalPath) = \OC\Files\Filesystem::resolvePath($oldSource);
+ list( , $newInternalPath) = \OC\Files\Filesystem::resolvePath($newSource);
+ return $storage->rename($oldInternalPath, $newInternalPath);
}
}
}
@@ -369,7 +314,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
if ($this->isCreatable(dirname($path2))) {
$source = $this->fopen($path1, 'r');
$target = $this->fopen($path2, 'w');
- return OC_Helper::streamCopy($source, $target);
+ return \OC_Helper::streamCopy($source, $target);
}
return false;
}
@@ -400,9 +345,9 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
'source' => $source,
'mode' => $mode,
);
- OCP\Util::emitHook('OC_Filestorage_Shared', 'fopen', $info);
- $storage = OC_Filesystem::getStorage($source);
- return $storage->fopen($this->getInternalPath($source), $mode);
+ \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info);
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
+ return $storage->fopen($internalPath, $mode);
}
return false;
}
@@ -412,47 +357,88 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
return 'httpd/unix-directory';
}
if ($source = $this->getSourcePath($path)) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->getMimeType($this->getInternalPath($source));
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
+ return $storage->getMimeType($internalPath);
}
return false;
}
public function free_space($path) {
+ if ($path == '') {
+ return -1;
+ }
$source = $this->getSourcePath($path);
if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->free_space($this->getInternalPath($source));
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
+ return $storage->free_space($internalPath);
}
}
public function getLocalFile($path) {
if ($source = $this->getSourcePath($path)) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->getLocalFile($this->getInternalPath($source));
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
+ return $storage->getLocalFile($internalPath);
}
return false;
}
public function touch($path, $mtime = null) {
if ($source = $this->getSourcePath($path)) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->touch($this->getInternalPath($source), $mtime);
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
+ return $storage->touch($internalPath, $mtime);
}
return false;
}
public static function setup($options) {
- $user_dir = $options['user_dir'];
- OC_Filesystem::mount('OC_Filestorage_Shared', array('sharedFolder' => '/Shared'), $user_dir.'/Shared/');
+ if (\OCP\Share::getItemsSharedWith('file')) {
+ $user_dir = $options['user_dir'];
+ \OC\Files\Filesystem::mount('\OC\Files\Storage\Shared', array('sharedFolder' => '/Shared'), $user_dir.'/Shared/');
+ }
}
- /**
- * check if a file or folder has been updated since $time
- * @param int $time
- * @return bool
- */
public function hasUpdated($path, $time) {
- //TODO
+ if ($path == '') {
+ return false;
+ }
+ return $this->filemtime($path) > $time;
+ }
+
+ public function getCache($path = '') {
+ return new \OC\Files\Cache\Shared_Cache($this);
+ }
+
+ public function getScanner($path = '') {
+ return new \OC\Files\Cache\Scanner($this);
+ }
+
+ public function getPermissionsCache($path = '') {
+ return new \OC\Files\Cache\Shared_Permissions($this);
+ }
+
+ public function getWatcher($path = '') {
+ return new \OC\Files\Cache\Shared_Watcher($this);
+ }
+
+ public function getOwner($path) {
+ if ($path == '') {
+ return false;
+ }
+ $source = $this->getFile($path);
+ if ($source) {
+ return $source['uid_owner'];
+ }
return false;
}
+
+ public function getETag($path) {
+ if ($path == '') {
+ return parent::getETag($path);
+ }
+ if ($source = $this->getSourcePath($path)) {
+ list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
+ return $storage->getETag($internalPath);
+ }
+ return null;
+ }
+
}
diff --git a/apps/files_sharing/lib/watcher.php b/apps/files_sharing/lib/watcher.php
new file mode 100644
index 00000000000..e67d1ee9086
--- /dev/null
+++ b/apps/files_sharing/lib/watcher.php
@@ -0,0 +1,51 @@
+<?php
+/**
+* ownCloud
+*
+* @author Michael Gapczynski
+* @copyright 2012 Michael Gapczynski mtgap@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
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+namespace OC\Files\Cache;
+
+/**
+ * check the storage backends for updates and change the cache accordingly
+ */
+class Shared_Watcher extends Watcher {
+
+ /**
+ * check $path for updates
+ *
+ * @param string $path
+ */
+ public function checkUpdate($path) {
+ if ($path != '') {
+ parent::checkUpdate($path);
+ }
+ }
+
+ /**
+ * remove deleted files in $path from the cache
+ *
+ * @param string $path
+ */
+ public function cleanFolder($path) {
+ if ($path != '') {
+ parent::cleanFolder($path);
+ }
+ }
+
+} \ No newline at end of file
diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php
index 5672c78dc33..9cf45e56fb9 100644
--- a/apps/files_sharing/public.php
+++ b/apps/files_sharing/public.php
@@ -9,9 +9,10 @@ if (isset($_GET['token'])) {
unset($_GET['file']);
$qry = \OC_DB::prepare('SELECT `source` FROM `*PREFIX*sharing` WHERE `target` = ?', 1);
$filepath = $qry->execute(array($_GET['token']))->fetchOne();
- if(isset($filepath)) {
- $info = OC_FileCache_Cached::get($filepath, '');
- if(strtolower($info['mimetype']) == 'httpd/unix-directory') {
+ if (isset($filepath)) {
+ $rootView = new \OC\Files\View('');
+ $info = $rootView->getFileInfo($filepath, '');
+ if (strtolower($info['mimetype']) == 'httpd/unix-directory') {
$_GET['dir'] = $filepath;
} else {
$_GET['file'] = $filepath;
@@ -25,7 +26,7 @@ if (isset($_GET['token'])) {
function getID($path) {
// use the share table from the db to find the item source if the file was reshared because shared files
//are not stored in the file cache.
- if (substr(OC_Filesystem::getMountPoint($path), -7, 6) == "Shared") {
+ if (substr(\OC\Files\Filesystem::getMountPoint($path), -7, 6) == "Shared") {
$path_parts = explode('/', $path, 5);
$user = $path_parts[1];
$intPath = '/'.$path_parts[4];
@@ -37,16 +38,19 @@ function getID($path) {
$row = $result->fetchRow();
$fileSource = $row['item_source'];
} else {
- $fileSource = OC_Filecache::getId($path, '');
+ $rootView = new \OC\Files\View('');
+ $meta = $rootView->getFileInfo($path);
+ $fileSource = $meta['fileid'];
}
return $fileSource;
}
+
// Enf of backward compatibility
/**
* lookup file path and owner by fetching it from the fscache
- * needed becaus OC_FileCache::getPath($id, $user) already requires the user
+ * needed because OC_FileCache::getPath($id, $user) already requires the user
* @param int $id
* @return array
*/
@@ -86,41 +90,43 @@ if (isset($_GET['t'])) {
OC_Util::setupFS($fileOwner);
}
}
-} else if (isset($_GET['file']) || isset($_GET['dir'])) {
- OCP\Util::writeLog('share', 'Missing token, trying fallback file/dir links', \OCP\Util::DEBUG);
- if (isset($_GET['dir'])) {
- $type = 'folder';
- $path = $_GET['dir'];
- if(strlen($path)>1 and substr($path, -1, 1)==='/') {
- $path=substr($path, 0, -1);
- }
- $baseDir = $path;
- $dir = $baseDir;
- } else {
- $type = 'file';
- $path = $_GET['file'];
- if(strlen($path)>1 and substr($path, -1, 1)==='/') {
- $path=substr($path, 0, -1);
+} else {
+ if (isset($_GET['file']) || isset($_GET['dir'])) {
+ OCP\Util::writeLog('share', 'Missing token, trying fallback file/dir links', \OCP\Util::DEBUG);
+ if (isset($_GET['dir'])) {
+ $type = 'folder';
+ $path = $_GET['dir'];
+ if (strlen($path) > 1 and substr($path, -1, 1) === '/') {
+ $path = substr($path, 0, -1);
+ }
+ $baseDir = $path;
+ $dir = $baseDir;
+ } else {
+ $type = 'file';
+ $path = $_GET['file'];
+ if (strlen($path) > 1 and substr($path, -1, 1) === '/') {
+ $path = substr($path, 0, -1);
+ }
}
- }
- $shareOwner = substr($path, 1, strpos($path, '/', 1) - 1);
+ $shareOwner = substr($path, 1, strpos($path, '/', 1) - 1);
- if (OCP\User::userExists($shareOwner)) {
- OC_Util::setupFS($shareOwner);
- $fileSource = getId($path);
- if ($fileSource != -1 ) {
- $linkItem = OCP\Share::getItemSharedWithByLink($type, $fileSource, $shareOwner);
- $pathAndUser['path'] = $path;
- $path_parts = explode('/', $path, 5);
- $pathAndUser['user'] = $path_parts[1];
- $fileOwner = $path_parts[1];
+ if (OCP\User::userExists($shareOwner)) {
+ OC_Util::setupFS($shareOwner);
+ $fileSource = getId($path);
+ if ($fileSource != -1) {
+ $linkItem = OCP\Share::getItemSharedWithByLink($type, $fileSource, $shareOwner);
+ $pathAndUser['path'] = $path;
+ $path_parts = explode('/', $path, 5);
+ $pathAndUser['user'] = $path_parts[1];
+ $fileOwner = $path_parts[1];
+ }
}
}
}
if ($linkItem) {
if (!isset($linkItem['item_type'])) {
- OCP\Util::writeLog('share', 'No item type set for share id: '.$linkItem['id'], \OCP\Util::ERROR);
+ OCP\Util::writeLog('share', 'No item type set for share id: ' . $linkItem['id'], \OCP\Util::ERROR);
header('HTTP/1.0 404 Not Found');
$tmpl = new OCP\Template('', '404', 'guest');
$tmpl->printPage();
@@ -128,11 +134,13 @@ if ($linkItem) {
}
if (isset($linkItem['share_with'])) {
// Authenticate share_with
- $url = OCP\Util::linkToPublic('files').'&t='.$token;
+ $url = OCP\Util::linkToPublic('files') . '&t=' . $token;
if (isset($_GET['file'])) {
- $url .= '&file='.urlencode($_GET['file']);
- } else if (isset($_GET['dir'])) {
- $url .= '&dir='.urlencode($_GET['dir']);
+ $url .= '&file=' . urlencode($_GET['file']);
+ } else {
+ if (isset($_GET['dir'])) {
+ $url .= '&dir=' . urlencode($_GET['dir']);
+ }
}
if (isset($_POST['password'])) {
$password = $_POST['password'];
@@ -173,13 +181,13 @@ if ($linkItem) {
}
}
}
- $basePath = substr($pathAndUser['path'], strlen('/'.$fileOwner.'/files'));
+ $basePath = substr($pathAndUser['path'], strlen('/' . $fileOwner . '/files'));
$path = $basePath;
if (isset($_GET['path'])) {
$path .= $_GET['path'];
}
- if (!$path || !OC_Filesystem::isValidPath($path) || !OC_Filesystem::file_exists($path)) {
- OCP\Util::writeLog('share', 'Invalid path '.$path.' for share id '.$linkItem['id'], \OCP\Util::ERROR);
+ if (!$path || !\OC\Files\Filesystem::isValidPath($path) || !\OC\Files\Filesystem::file_exists($path)) {
+ OCP\Util::writeLog('share', 'Invalid path ' . $path . ' for share id ' . $linkItem['id'], \OCP\Util::ERROR);
header('HTTP/1.0 404 Not Found');
$tmpl = new OCP\Template('', '404', 'guest');
$tmpl->printPage();
@@ -189,13 +197,15 @@ if ($linkItem) {
$file = basename($path);
// Download the file
if (isset($_GET['download'])) {
- if (isset($_GET['path']) && $_GET['path'] !== '' ) {
- if ( isset($_GET['files']) ) { // download selected files
+ if (isset($_GET['path']) && $_GET['path'] !== '') {
+ if (isset($_GET['files'])) { // download selected files
OC_Files::get($path, $_GET['files'], $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false);
- } else if (isset($_GET['path']) && $_GET['path'] != '' ) { // download a file from a shared directory
- OC_Files::get($dir, $file, $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false);
- } else { // download the whole shared directory
- OC_Files::get($dir, $file, $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false);
+ } else {
+ if (isset($_GET['path']) && $_GET['path'] != '') { // download a file from a shared directory
+ OC_Files::get($dir, $file, $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false);
+ } else { // download the whole shared directory
+ OC_Files::get($dir, $file, $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false);
+ }
}
} else { // download a single shared file
OC_Files::get($dir, $file, $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false);
@@ -210,7 +220,7 @@ if ($linkItem) {
$tmpl->assign('displayName', \OCP\User::getDisplayName($shareOwner));
$tmpl->assign('dir', $dir);
$tmpl->assign('filename', $file);
- $tmpl->assign('mimetype', OC_Filesystem::getMimeType($path));
+ $tmpl->assign('mimetype', \OC\Files\Filesystem::getMimeType($path));
if (isset($_GET['path'])) {
$getPath = $_GET['path'];
} else {
@@ -221,7 +231,7 @@ if ($linkItem) {
.(isset($_GET['dir'])?'&dir='.$_GET['dir']:'')
.(isset($_GET['file'])?'&file='.$_GET['file']:'');
// Show file list
- if (OC_Filesystem::is_dir($path)) {
+ if (\OC\Files\Filesystem::is_dir($path)) {
OCP\Util::addStyle('files', 'files');
OCP\Util::addScript('files', 'files');
OCP\Util::addScript('files', 'filelist');
@@ -232,9 +242,9 @@ if ($linkItem) {
if ($i['type'] == 'file') {
$fileinfo = pathinfo($i['name']);
$i['basename'] = $fileinfo['filename'];
- $i['extension'] = isset($fileinfo['extension']) ? ('.'.$fileinfo['extension']) : '';
+ $i['extension'] = isset($fileinfo['extension']) ? ('.' . $fileinfo['extension']) : '';
}
- $i['directory'] = '/'.substr($i['directory'], $rootLength);
+ $i['directory'] = '/' . substr($i['directory'], $rootLength);
if ($i['directory'] == '/') {
$i['directory'] = '';
}
@@ -251,9 +261,137 @@ if ($linkItem) {
//add subdir breadcrumbs
foreach (explode('/', urldecode($getPath)) as $i) {
if ($i != '') {
- $pathtohere .= '/'.$i;
+ $pathtohere .= '/' . $i;
$breadcrumb[] = array('dir' => $pathtohere, 'name' => $i);
+ $path = $linkItem['path'];
+ if (isset($_GET['path'])) {
+ $path .= $_GET['path'];
+ $dir .= $_GET['path'];
+ if (!\OC\Files\Filesystem::file_exists($path)) {
+ header('HTTP/1.0 404 Not Found');
+ $tmpl = new OCP\Template('', '404', 'guest');
+ $tmpl->printPage();
+ exit();
+ }
+ }
+
+ $list = new OCP\Template('files', 'part.list', '');
+ $list->assign('files', $files, false);
+ $list->assign('publicListView', true);
+ $list->assign('baseURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&path=', false);
+ $list->assign('downloadURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download&path=', false);
+ $breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', '');
+ $breadcrumbNav->assign('breadcrumb', $breadcrumb, false);
+ $breadcrumbNav->assign('baseURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&path=', false);
+ $folder = new OCP\Template('files', 'index', '');
+ $folder->assign('fileList', $list->fetchPage(), false);
+ $folder->assign('breadcrumb', $breadcrumbNav->fetchPage(), false);
+ $folder->assign('isCreatable', false);
+ $folder->assign('permissions', 0);
+ $folder->assign('files', $files);
+ $folder->assign('uploadMaxFilesize', 0);
+ $folder->assign('uploadMaxHumanFilesize', 0);
+ $folder->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));
+ $tmpl->assign('folder', $folder->fetchPage(), false);
+ $tmpl->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));
+ $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download&path=' . urlencode($getPath));
+ } else {
+ // Show file preview if viewer is available
+ if ($type == 'file') {
+ $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download');
+ } else {
+ OCP\Util::addStyle('files_sharing', 'public');
+ OCP\Util::addScript('files_sharing', 'public');
+ OCP\Util::addScript('files', 'fileactions');
+ $tmpl = new OCP\Template('files_sharing', 'public', 'base');
+ $tmpl->assign('owner', $uidOwner);
+ // Show file list
+ if (\OC\Files\Filesystem::is_dir($path)) {
+ OCP\Util::addStyle('files', 'files');
+ OCP\Util::addScript('files', 'files');
+ OCP\Util::addScript('files', 'filelist');
+ $files = array();
+ $rootLength = strlen($baseDir) + 1;
+ foreach (OC_Files::getDirectoryContent($path) as $i) {
+ $i['date'] = OCP\Util::formatDate($i['mtime']);
+ if ($i['type'] == 'file') {
+ $fileinfo = pathinfo($i['name']);
+ $i['basename'] = $fileinfo['filename'];
+ $i['extension'] = isset($fileinfo['extension']) ? ('.' . $fileinfo['extension']) : '';
+ }
+ $i['directory'] = '/' . substr('/' . $uidOwner . '/files' . $i['directory'], $rootLength);
+ if ($i['directory'] == '/') {
+ $i['directory'] = '';
+ }
+ $i['permissions'] = OCP\PERMISSION_READ;
+ $files[] = $i;
+ }
+ // Make breadcrumb
+ $breadcrumb = array();
+ $pathtohere = '';
+ $count = 1;
+ foreach (explode('/', $dir) as $i) {
+ if ($i != '') {
+ if ($i != $baseDir) {
+ $pathtohere .= '/' . $i;
+ }
+ if (strlen($pathtohere) < strlen($_GET['dir'])) {
+ continue;
+ }
+ $breadcrumb[] = array('dir' => str_replace($_GET['dir'], "", $pathtohere, $count), 'name' => $i);
+ }
+ }
+ $list = new OCP\Template('files', 'part.list', '');
+ $list->assign('files', $files, false);
+ $list->assign('publicListView', true);
+ $list->assign('baseURL', OCP\Util::linkToPublic('files') . '&dir=' . urlencode($_GET['dir']) . '&path=', false);
+ $list->assign('downloadURL', OCP\Util::linkToPublic('files') . '&download&dir=' . urlencode($_GET['dir']) . '&path=', false);
+ $breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', '');
+ $breadcrumbNav->assign('breadcrumb', $breadcrumb, false);
+ $breadcrumbNav->assign('baseURL', OCP\Util::linkToPublic('files') . '&dir=' . urlencode($_GET['dir']) . '&path=', false);
+ $folder = new OCP\Template('files', 'index', '');
+ $folder->assign('fileList', $list->fetchPage(), false);
+ $folder->assign('breadcrumb', $breadcrumbNav->fetchPage(), false);
+ $folder->assign('dir', basename($dir));
+ $folder->assign('isCreatable', false);
+ $folder->assign('permissions', 0);
+ $folder->assign('files', $files);
+ $folder->assign('uploadMaxFilesize', 0);
+ $folder->assign('uploadMaxHumanFilesize', 0);
+ $folder->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));
+ $tmpl->assign('folder', $folder->fetchPage(), false);
+ $tmpl->assign('uidOwner', $uidOwner);
+ $tmpl->assign('dir', basename($dir));
+ $tmpl->assign('filename', basename($path));
+ $tmpl->assign('mimetype', \OC\Files\Filesystem::getMimeType($path));
+ $tmpl->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));
+ if (isset($_GET['path'])) {
+ $getPath = $_GET['path'];
+ } else {
+ $getPath = '';
+ }
+ $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files') . '&download&dir=' . urlencode($_GET['dir']) . '&path=' . urlencode($getPath), false);
+ } else {
+ // Show file preview if viewer is available
+ $tmpl->assign('uidOwner', $uidOwner);
+ $tmpl->assign('dir', dirname($path));
+ $tmpl->assign('filename', basename($path));
+ $tmpl->assign('mimetype', \OC\Files\Filesystem::getMimeType($path));
+ if ($type == 'file') {
+ $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files') . '&file=' . urlencode($_GET['file']) . '&download', false);
+ } else {
+ if (isset($_GET['path'])) {
+ $getPath = $_GET['path'];
+ } else {
+ $getPath = '';
+ }
+ $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files') . '&download&dir=' . urlencode($_GET['dir']) . '&path=' . urlencode($getPath), false);
+ }
+ }
+ $tmpl->printPage();
+ }
}
+ $tmpl->printPage();
}
$list = new OCP\Template('files', 'part.list', '');
@@ -279,21 +417,11 @@ if ($linkItem) {
$tmpl->assign('downloadURL', OCP\Util::linkToPublic('files')
.$urlLinkIdentifiers.'&download&path='.urlencode($getPath));
} else {
- // Show file preview if viewer is available
- if ($type == 'file') {
- $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files')
- .$urlLinkIdentifiers.'&download');
- } else {
- $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files')
- .$urlLinkIdentifiers.'&download&path='.urlencode($getPath));
- }
+ OCP\Util::writeLog('share', 'could not resolve linkItem', \OCP\Util::DEBUG);
}
- $tmpl->printPage();
}
- exit();
-} else {
- OCP\Util::writeLog('share', 'could not resolve linkItem', \OCP\Util::DEBUG);
}
header('HTTP/1.0 404 Not Found');
$tmpl = new OCP\Template('', '404', 'guest');
$tmpl->printPage();
+