From cc19df22a1c6e69ebffb23eaf6e07c6361a59aa7 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 6 Feb 2013 13:09:04 -0500 Subject: [PATCH 01/15] Remove old OC4 link compatibility --- apps/files_sharing/public.php | 46 ----------------------------------- 1 file changed, 46 deletions(-) diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php index a3e0ec192a..7159b21511 100644 --- a/apps/files_sharing/public.php +++ b/apps/files_sharing/public.php @@ -2,52 +2,6 @@ // Load other apps for file previews OC_App::loadApps(); -// Compatibility with shared-by-link items from ownCloud 4.0 -// requires old Sharing table ! -// support will be removed in OC 5.0,a -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)) { - $rootView = new \OC\Files\View(''); - $info = $rootView->getFileInfo($filepath, ''); - if (strtolower($info['mimetype']) == 'httpd/unix-directory') { - $_GET['dir'] = $filepath; - } else { - $_GET['file'] = $filepath; - } - \OCP\Util::writeLog('files_sharing', 'You have files that are shared by link originating from ownCloud 4.0.' - .' Redistribute the new links, because backwards compatibility will be removed in ownCloud 5.', - \OCP\Util::WARN); - } -} - -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\Files\Filesystem::getMountPoint($path), -7, 6) == "Shared") { - $path_parts = explode('/', $path, 5); - $user = $path_parts[1]; - $intPath = '/'.$path_parts[4]; - $query = \OC_DB::prepare('SELECT `item_source`' - .' FROM `*PREFIX*share`' - .' WHERE `uid_owner` = ?' - .' AND `file_target` = ? '); - $result = $query->execute(array($user, $intPath)); - $row = $result->fetchRow(); - $fileSource = $row['item_source']; - } else { - $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 because OC_FileCache::getPath($id, $user) already requires the user From 71affd528c74410a53ae923da9750e1dcdb83d2f Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 10 Feb 2013 00:53:58 -0500 Subject: [PATCH 02/15] Fix public links --- apps/files_sharing/public.php | 238 ++++++---------------------------- 1 file changed, 40 insertions(+), 198 deletions(-) diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php index 7159b21511..29b7b3dee7 100644 --- a/apps/files_sharing/public.php +++ b/apps/files_sharing/public.php @@ -1,21 +1,8 @@ execute(array($id)); - $row = $result->fetchRow(); - return $row; -} - - if (isset($_GET['t'])) { $token = $_GET['t']; $linkItem = OCP\Share::getShareByToken($token); @@ -24,24 +11,14 @@ if (isset($_GET['t'])) { $type = $linkItem['item_type']; $fileSource = $linkItem['file_source']; $shareOwner = $linkItem['uid_owner']; - - if (OCP\User::userExists($shareOwner) && $fileSource != -1 ) { - - $pathAndUser = getPathAndUser($linkItem['file_source']); - $fileOwner = $pathAndUser['user']; - - //if this is a reshare check the file owner also exists - if ($shareOwner != $fileOwner && ! OCP\User::userExists($fileOwner)) { - OCP\Util::writeLog('share', 'original file owner '.$fileOwner - .' does not exist for share '.$linkItem['id'], \OCP\Util::ERROR); - header('HTTP/1.0 404 Not Found'); - $tmpl = new OCP\Template('', '404', 'guest'); - $tmpl->printPage(); - exit(); - } - - //mount filesystem of file owner - OC_Util::setupFS($fileOwner); + if (OCP\User::userExists($shareOwner) && $fileSource != -1) { + OC_Util::setupFS($shareOwner); + $path = $linkItem['file_target']; + } else { + header('HTTP/1.0 404 Not Found'); + $tmpl = new OCP\Template('', '404', 'guest'); + $tmpl->printPage(); + exit(); } } } else { @@ -135,17 +112,12 @@ if ($linkItem) { } } } - $basePath = substr($pathAndUser['path'], strlen('/' . $fileOwner . '/files')); - $path = $basePath; - if (isset($_GET['path'])) { - $path .= $_GET['path']; - } - 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(); - exit(); + $basePath = $path; + if (isset($_GET['path']) && \OC\Files\Filesystem::isReadable($_GET['path'])) { + $getPath = \OC\Files\Filesystem::normalizePath($_GET['path']); + $path .= $getPath; + } else { + $getPath = ''; } $dir = dirname($path); $file = basename($path); @@ -175,12 +147,6 @@ if ($linkItem) { $tmpl->assign('dir', $dir); $tmpl->assign('filename', $file); $tmpl->assign('mimetype', \OC\Files\Filesystem::getMimeType($path)); - if (isset($_GET['path'])) { - $getPath = $_GET['path']; - } else { - $getPath = ''; - } - // $urlLinkIdentifiers= (isset($token)?'&t='.$token:'') .(isset($_GET['dir'])?'&dir='.$_GET['dir']:'') .(isset($_GET['file'])?'&file='.$_GET['file']:''); @@ -192,171 +158,37 @@ if ($linkItem) { OCP\Util::addscript('files', 'keyboardshortcuts'); $files = array(); $rootLength = strlen($basePath) + 1; - foreach (OC_Files::getDirectoryContent($path) as $i) { + foreach (\OC\Files\Filesystem::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']) : ''; + if (!empty($fileinfo['extension'])) { + $i['extension'] = '.' . $fileinfo['extension']; + } else { + $i['extension'] = ''; + } } - $i['directory'] = '/' . substr($i['directory'], $rootLength); - if ($i['directory'] == '/') { - $i['directory'] = ''; - } - $i['permissions'] = OCP\PERMISSION_READ; + $i['directory'] = $dir; $files[] = $i; } // Make breadcrumb $breadcrumb = array(); $pathtohere = ''; - - //add base breadcrumb - $breadcrumb[] = array('dir' => '/', 'name' => basename($basePath)); - - //add subdir breadcrumbs - foreach (explode('/', urldecode($getPath)) as $i) { + foreach (explode('/', $dir) as $i) { if ($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', ''); $list->assign('files', $files, false); $list->assign('disableSharing', 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', '' ); + $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); + $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); @@ -367,14 +199,24 @@ if ($linkItem) { $folder->assign('uploadMaxFilesize', 0); $folder->assign('uploadMaxHumanFilesize', 0); $folder->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true))); + $folder->assign('usedSpacePercent', 0); $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)); + $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download&path=' . urlencode($getPath)); } else { - OCP\Util::writeLog('share', 'could not resolve linkItem', \OCP\Util::DEBUG); + // 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)); + } } + $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'); From 8e3b8c7f47ab12e1612d3fa025e6b9eb7f5ffdb3 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 10 Feb 2013 19:09:58 -0500 Subject: [PATCH 03/15] Proper fix for shared links --- apps/files_sharing/lib/sharedstorage.php | 2 +- apps/files_sharing/public.php | 45 +++++++++++++----------- lib/files/filesystem.php | 4 +-- lib/util.php | 2 +- 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index ea28ca69b9..65812b7e2f 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -390,7 +390,7 @@ class Shared extends \OC\Files\Storage\Common { } public static function setup($options) { - if (\OCP\Share::getItemsSharedWith('file')) { + if (!\OCP\User::isLoggedIn() || \OCP\User::getUser() != $options['user'] || \OCP\Share::getItemsSharedWith('file')) { $user_dir = $options['user_dir']; \OC\Files\Filesystem::mount('\OC\Files\Storage\Shared', array('sharedFolder' => '/Shared'), $user_dir.'/Shared/'); } diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php index 29b7b3dee7..47e074edb8 100644 --- a/apps/files_sharing/public.php +++ b/apps/files_sharing/public.php @@ -11,14 +11,26 @@ if (isset($_GET['t'])) { $type = $linkItem['item_type']; $fileSource = $linkItem['file_source']; $shareOwner = $linkItem['uid_owner']; - if (OCP\User::userExists($shareOwner) && $fileSource != -1) { - OC_Util::setupFS($shareOwner); - $path = $linkItem['file_target']; + $fileOwner = null; + $path = null; + if (isset($linkItem['parent'])) { + $parent = $linkItem['parent']; + while (isset($parent)) { + $query = \OC_DB::prepare('SELECT `parent`, `uid_owner` FROM `*PREFIX*share` WHERE `id` = ?', 1); + $item = $query->execute(array($parent))->fetchRow(); + if (isset($item['parent'])) { + $parent = $item['parent']; + } else { + $fileOwner = $item['uid_owner']; + break; + } + } } else { - header('HTTP/1.0 404 Not Found'); - $tmpl = new OCP\Template('', '404', 'guest'); - $tmpl->printPage(); - exit(); + $fileOwner = $shareOwner; + } + if (isset($fileOwner)) { + OC_Util::setupFS($fileOwner); + $path = \OC\Files\Filesystem::getPath($linkItem['file_source']); } } } else { @@ -55,7 +67,7 @@ if (isset($_GET['t'])) { } } -if ($linkItem) { +if (isset($path)) { if (!isset($linkItem['item_type'])) { OCP\Util::writeLog('share', 'No item type set for share id: ' . $linkItem['id'], \OCP\Util::ERROR); header('HTTP/1.0 404 Not Found'); @@ -123,20 +135,12 @@ 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 - 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 { // download a single shared file + if (isset($_GET['files'])) { // download selected files + OC_Files::get($dir, $_GET['files'], $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false); + } else { OC_Files::get($dir, $file, $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false); } - + exit(); } else { OCP\Util::addStyle('files_sharing', 'public'); OCP\Util::addScript('files_sharing', 'public'); @@ -147,6 +151,7 @@ if ($linkItem) { $tmpl->assign('dir', $dir); $tmpl->assign('filename', $file); $tmpl->assign('mimetype', \OC\Files\Filesystem::getMimeType($path)); + $tmpl->assign('fileTarget', basename($linkItem['file_target'])); $urlLinkIdentifiers= (isset($token)?'&t='.$token:'') .(isset($_GET['dir'])?'&dir='.$_GET['dir']:'') .(isset($_GET['file'])?'&file='.$_GET['file']:''); diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php index 71bf3d8708..a0c3c4b9b7 100644 --- a/lib/files/filesystem.php +++ b/lib/files/filesystem.php @@ -190,14 +190,14 @@ class Filesystem { } } - static public function init($root) { + static public function init($user, $root) { if (self::$defaultInstance) { return false; } self::$defaultInstance = new View($root); //load custom mount config - self::initMountPoints(); + self::initMountPoints($user); self::$loaded = true; diff --git a/lib/util.php b/lib/util.php index a5fe4cb175..54a3f63404 100755 --- a/lib/util.php +++ b/lib/util.php @@ -51,7 +51,7 @@ class OC_Util { mkdir( $userdirectory, 0755, true ); } //jail the user into his "home" directory - \OC\Files\Filesystem::init($user_dir); + \OC\Files\Filesystem::init($user, $user_dir); $quotaProxy=new OC_FileProxy_Quota(); $fileOperationProxy = new OC_FileProxy_FileOperations(); From 0d3c58d6b6bb9a3070294de398542b6c453a6190 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 10 Feb 2013 19:13:13 -0500 Subject: [PATCH 04/15] Replace filename key with fileTarget in template --- apps/files_sharing/templates/public.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/files_sharing/templates/public.php b/apps/files_sharing/templates/public.php index 71fca09ed6..7776fd63b3 100644 --- a/apps/files_sharing/templates/public.php +++ b/apps/files_sharing/templates/public.php @@ -6,9 +6,9 @@ ownCloud
- t('%s shared the folder %s with you', array($_['displayName'], $_['filename'])) ?> + t('%s shared the folder %s with you', array($_['displayName'], $_['fileTarget'])) ?> - t('%s shared the file %s with you', array($_['displayName'], $_['filename'])) ?> + t('%s shared the file %s with you', array($_['displayName'], $_['fileTarget'])) ?> Download" />t('Download')?> @@ -26,7 +26,7 @@
  • - t('No preview available for').' '.$_['filename']; ?>
    + t('No preview available for').' '.$_['fileTarget']; ?>
    Download" />t('Download')?>
From 56df48b40f0eb69dff014ef1cc43a2ef9c095506 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 10 Feb 2013 19:14:20 -0500 Subject: [PATCH 05/15] Remove additional old compatibility code --- apps/files_sharing/public.php | 35 +---------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php index 47e074edb8..dfaf4c00a6 100644 --- a/apps/files_sharing/public.php +++ b/apps/files_sharing/public.php @@ -33,40 +33,7 @@ if (isset($_GET['t'])) { $path = \OC\Files\Filesystem::getPath($linkItem['file_source']); } } -} 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); - - 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 (isset($path)) { if (!isset($linkItem['item_type'])) { OCP\Util::writeLog('share', 'No item type set for share id: ' . $linkItem['id'], \OCP\Util::ERROR); From a6bd086867a616216fc53b81ed7d41a9cb816c2e Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 10 Feb 2013 20:01:25 -0500 Subject: [PATCH 06/15] Set permissions to read only --- apps/files_sharing/public.php | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php index dfaf4c00a6..2862ad510e 100644 --- a/apps/files_sharing/public.php +++ b/apps/files_sharing/public.php @@ -142,6 +142,7 @@ if (isset($path)) { } } $i['directory'] = $dir; + $i['permissions'] = OCP\PERMISSION_READ; $files[] = $i; } // Make breadcrumb From d7d9e2a15a4039d6fbb272a63b17ee9cbd01bf51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Mon, 11 Feb 2013 10:20:31 +0100 Subject: [PATCH 07/15] fix positioning of password label, add autofocus to password field --- apps/files_sharing/templates/authenticate.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files_sharing/templates/authenticate.php b/apps/files_sharing/templates/authenticate.php index 9695caebf1..6bce6857ac 100644 --- a/apps/files_sharing/templates/authenticate.php +++ b/apps/files_sharing/templates/authenticate.php @@ -1,8 +1,8 @@
-

+

- +

From ad360296b940c20b57da9316b079497e0c1c1256 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 11 Feb 2013 11:06:09 +0100 Subject: [PATCH 08/15] Update tests and apps to the new \OC\Files\Filesystem::init signature --- apps/files_encryption/hooks/hooks.php | 2 +- lib/filesystem.php | 4 ++-- lib/ocs/cloud.php | 2 +- tests/lib/files/cache/updater.php | 2 +- tests/lib/files/filesystem.php | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 7e4f677ce9..2731d5a92f 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -40,7 +40,7 @@ class Hooks { // Manually initialise Filesystem{} singleton with correct // fake root path, in order to avoid fatal webdav errors - \OC\Files\Filesystem::init( $params['uid'] . '/' . 'files' . '/' ); + \OC\Files\Filesystem::init( $params['uid'], $params['uid'] . '/' . 'files' . '/' ); $view = new \OC_FilesystemView( '/' ); diff --git a/lib/filesystem.php b/lib/filesystem.php index 57cca90230..e86bea6bff 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -58,8 +58,8 @@ class OC_Filesystem { /** * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem */ - static public function init($root) { - return \OC\Files\Filesystem::init($root); + static public function init($user, $root) { + return \OC\Files\Filesystem::init($user, $root); } /** diff --git a/lib/ocs/cloud.php b/lib/ocs/cloud.php index 179ed8f310..820d24a8e0 100644 --- a/lib/ocs/cloud.php +++ b/lib/ocs/cloud.php @@ -45,7 +45,7 @@ class OC_OCS_Cloud { if(OC_User::userExists($parameters['user'])) { // calculate the disc space $userDir = '/'.$parameters['user'].'/files'; - \OC\Files\Filesystem::init($useDir); + \OC\Files\Filesystem::init($parameters['user'], $userDir); $rootInfo = \OC\Files\Filesystem::getFileInfo(''); $sharedInfo = \OC\Files\Filesystem::getFileInfo('/Shared'); $used = $rootInfo['size'] - $sharedInfo['size']; diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php index b83dd0c26e..7a79f45a20 100644 --- a/tests/lib/files/cache/updater.php +++ b/tests/lib/files/cache/updater.php @@ -45,7 +45,7 @@ class Updater extends \PHPUnit_Framework_TestCase { if (!self::$user) { if (!\OC\Files\Filesystem::getView()) { self::$user = uniqid(); - \OC\Files\Filesystem::init('/' . self::$user . '/files'); + \OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files'); } else { self::$user = \OC_User::getUser(); } diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php index fd116af2d2..6ce45e6178 100644 --- a/tests/lib/files/filesystem.php +++ b/tests/lib/files/filesystem.php @@ -82,7 +82,7 @@ class Filesystem extends \PHPUnit_Framework_TestCase { $user = \OC_User::getUser(); }else{ $user=uniqid(); - \OC\Files\Filesystem::init('/'.$user.'/files'); + \OC\Files\Filesystem::init($user, '/'.$user.'/files'); } \OC_Hook::clear('OC_Filesystem'); \OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook'); From d0a005ea979f7f6ddc6ed28b8b346878ce3f41b9 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 11 Feb 2013 11:20:51 +0100 Subject: [PATCH 09/15] Sharing: fix position of file list in public link view of folder --- apps/files_sharing/css/public.css | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/files_sharing/css/public.css b/apps/files_sharing/css/public.css index 492014344f..110a0028a0 100644 --- a/apps/files_sharing/css/public.css +++ b/apps/files_sharing/css/public.css @@ -34,9 +34,8 @@ body { background:#eee; border-bottom:1px solid #f8f8f8; min-height:30em; - padding-top:2em; text-align:center; - margin:50px auto; + margin:45px auto; } #noPreview { @@ -60,6 +59,7 @@ p.info a { #imgframe { height:75%; padding-bottom:2em; + padding-top:2em; width:80%; margin:0 auto; } @@ -67,4 +67,4 @@ p.info a { #imgframe img { max-height:100%; max-width:100%; -} \ No newline at end of file +} From 762688762f0b4536087d8d6e8bd8d1c9562f00d1 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 11 Feb 2013 11:38:52 +0100 Subject: [PATCH 10/15] Share: fix downloading files from a public shared folder --- apps/files_sharing/public.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php index 2862ad510e..04dcbd680e 100644 --- a/apps/files_sharing/public.php +++ b/apps/files_sharing/public.php @@ -92,7 +92,7 @@ if (isset($path)) { } } $basePath = $path; - if (isset($_GET['path']) && \OC\Files\Filesystem::isReadable($_GET['path'])) { + if (isset($_GET['path']) && \OC\Files\Filesystem::isReadable($basePath . $_GET['path'])) { $getPath = \OC\Files\Filesystem::normalizePath($_GET['path']); $path .= $getPath; } else { From 7842b416d1c85a723368148ea9cbe6d34378af69 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 11 Feb 2013 11:44:18 +0100 Subject: [PATCH 11/15] Share: fix breadcrumbs for public shared folder --- apps/files_sharing/public.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php index 04dcbd680e..4b53609741 100644 --- a/apps/files_sharing/public.php +++ b/apps/files_sharing/public.php @@ -148,7 +148,7 @@ if (isset($path)) { // Make breadcrumb $breadcrumb = array(); $pathtohere = ''; - foreach (explode('/', $dir) as $i) { + foreach (explode('/', $getPath) as $i) { if ($i != '') { $pathtohere .= '/' . $i; $breadcrumb[] = array('dir' => $pathtohere, 'name' => $i); From bbf672f4532b6c94354256e71a324830829c1dea Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 11 Feb 2013 11:48:49 +0100 Subject: [PATCH 12/15] Share: fix nested subfolders in public shared folders --- apps/files_sharing/public.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php index 4b53609741..ac889cd2dc 100644 --- a/apps/files_sharing/public.php +++ b/apps/files_sharing/public.php @@ -115,7 +115,6 @@ if (isset($path)) { $tmpl = new OCP\Template('files_sharing', 'public', 'base'); $tmpl->assign('uidOwner', $shareOwner); $tmpl->assign('displayName', \OCP\User::getDisplayName($shareOwner)); - $tmpl->assign('dir', $dir); $tmpl->assign('filename', $file); $tmpl->assign('mimetype', \OC\Files\Filesystem::getMimeType($path)); $tmpl->assign('fileTarget', basename($linkItem['file_target'])); @@ -124,6 +123,8 @@ if (isset($path)) { .(isset($_GET['file'])?'&file='.$_GET['file']:''); // Show file list if (\OC\Files\Filesystem::is_dir($path)) { + $tmpl->assign('dir', $getPath); + OCP\Util::addStyle('files', 'files'); OCP\Util::addScript('files', 'files'); OCP\Util::addScript('files', 'filelist'); @@ -141,7 +142,7 @@ if (isset($path)) { $i['extension'] = ''; } } - $i['directory'] = $dir; + $i['directory'] = $getPath; $i['permissions'] = OCP\PERMISSION_READ; $files[] = $i; } @@ -165,7 +166,7 @@ if (isset($path)) { $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('dir', $getPath); $folder->assign('isCreatable', false); $folder->assign('permissions', 0); $folder->assign('files', $files); @@ -177,6 +178,8 @@ if (isset($path)) { $tmpl->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true))); $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download&path=' . urlencode($getPath)); } else { + $tmpl->assign('dir', $dir); + // Show file preview if viewer is available if ($type == 'file') { $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download'); From 7fa9181a2697d343fce30124792fae664c9c0510 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 11 Feb 2013 11:50:41 +0100 Subject: [PATCH 13/15] Share: fix sorting of files in public shared folder --- apps/files_sharing/public.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php index ac889cd2dc..b478ac8a4a 100644 --- a/apps/files_sharing/public.php +++ b/apps/files_sharing/public.php @@ -3,6 +3,16 @@ $RUNTIME_NOSETUPFS = true; // Load other apps for file previews OC_App::loadApps(); +function fileCmp($a, $b) { + if ($a['type'] == 'dir' and $b['type'] != 'dir') { + return -1; + } elseif ($a['type'] != 'dir' and $b['type'] == 'dir') { + return 1; + } else { + return strnatcasecmp($a['name'], $b['name']); + } +} + if (isset($_GET['t'])) { $token = $_GET['t']; $linkItem = OCP\Share::getShareByToken($token); @@ -146,6 +156,8 @@ if (isset($path)) { $i['permissions'] = OCP\PERMISSION_READ; $files[] = $i; } + usort($files, "fileCmp"); + // Make breadcrumb $breadcrumb = array(); $pathtohere = ''; From a1db280a464f3fd92b4ed19e676c4b3b013f88c8 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 11 Feb 2013 11:54:44 +0100 Subject: [PATCH 14/15] Share: fix downloading selected files from public shared folder --- apps/files_sharing/public.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php index b478ac8a4a..38d598f778 100644 --- a/apps/files_sharing/public.php +++ b/apps/files_sharing/public.php @@ -113,7 +113,7 @@ if (isset($path)) { // Download the file if (isset($_GET['download'])) { if (isset($_GET['files'])) { // download selected files - OC_Files::get($dir, $_GET['files'], $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false); + OC_Files::get($path, $_GET['files'], $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false); } else { OC_Files::get($dir, $file, $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false); } From d0d6d973a9672e2da874e79836a6cc78cd73892d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 11 Feb 2013 12:35:39 +0100 Subject: [PATCH 15/15] Share: fix table head color for public shared folders --- apps/files_sharing/css/public.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/files_sharing/css/public.css b/apps/files_sharing/css/public.css index 110a0028a0..13f42b130d 100644 --- a/apps/files_sharing/css/public.css +++ b/apps/files_sharing/css/public.css @@ -68,3 +68,7 @@ p.info a { max-height:100%; max-width:100%; } + +thead{ + background-color: white; +}