summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/public.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/public.php')
-rw-r--r--apps/files_sharing/public.php104
1 files changed, 94 insertions, 10 deletions
diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php
index 010f6b9de18..bed1a19fd63 100644
--- a/apps/files_sharing/public.php
+++ b/apps/files_sharing/public.php
@@ -1,13 +1,21 @@
<?php
// Load other apps for file previews
OC_App::loadApps();
-if (isset($_GET['file'])) {
- $pos = strpos($_GET['file'], '/', 1);
- $uidOwner = substr($_GET['file'], 1, $pos - 1);
+if (isset($_GET['file']) || isset($_GET['dir'])) {
+ if (isset($_GET['dir'])) {
+ $type = 'folder';
+ $path = $_GET['dir'];
+ $baseDir = basename($path);
+ $dir = $baseDir;
+ } else {
+ $type = 'file';
+ $path = $_GET['file'];
+ }
+ $uidOwner = substr($path, 1, strpos($path, '/', 1) - 1);
if (OCP\User::userExists($uidOwner)) {
OC_Util::setupFS($uidOwner);
- $fileSource = OC_Filecache::getId($_GET['file'], '');
- if ($fileSource != -1 && ($linkItem = OCP\Share::getItemSharedWithByLink('file', $fileSource, $uidOwner))) {
+ $fileSource = OC_Filecache::getId($path, '');
+ if ($fileSource != -1 && ($linkItem = OCP\Share::getItemSharedWithByLink($type, $fileSource, $uidOwner))) {
if (isset($linkItem['share_with'])) {
// Check password
if (isset($_POST['password'])) {
@@ -35,6 +43,16 @@ if (isset($_GET['file'])) {
}
}
$path = $linkItem['path'];
+ if (isset($_GET['path'])) {
+ $path .= $_GET['path'];
+ $dir .= $_GET['path'];
+ if (!OC_Filesystem::file_exists($path)) {
+ header('HTTP/1.0 404 Not Found');
+ $tmpl = new OCP\Template('', '404', 'guest');
+ $tmpl->printPage();
+ exit();
+ }
+ }
// Download the file
if (isset($_GET['download'])) {
$mimetype = OC_Filesystem::getMimeType($path);
@@ -50,18 +68,84 @@ if (isset($_GET['file'])) {
OCP\Util::addScript('files_sharing', 'public');
OCP\Util::addScript('files', 'fileactions');
$tmpl = new OCP\Template('files_sharing', 'public', 'base');
- $tmpl->assign('details', $uidOwner.' shared the file '.basename($path).' with you');
$tmpl->assign('owner', $uidOwner);
- $tmpl->assign('name', basename($path));
// Show file list
if (OC_Filesystem::is_dir($path)) {
- // TODO
+ 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($i['directory'], $rootLength);
+ if ($i['directory'] == '/') {
+ $i['directory'] = '';
+ }
+ $i['permissions'] = OCP\Share::PERMISSION_READ;
+ $files[] = $i;
+ }
+ // Make breadcrumb
+ $breadcrumb = array();
+ $pathtohere = '';
+ foreach (explode('/', $dir) as $i) {
+ if ($i != '') {
+ if ($i != $baseDir) {
+ $pathtohere .= '/'.$i;
+ }
+ $breadcrumb[] = array('dir' => $pathtohere, 'name' => $i);
+ }
+ }
+ $list = new OCP\Template('files', 'part.list', '');
+ $list->assign('files', $files, false);
+ $list->assign('baseURL', OCP\Util::linkToPublic('files').'&dir='.$_GET['dir'].'&path=', false);
+ $list->assign('downloadURL', OCP\Util::linkToPublic('files').'&download&dir='.$_GET['dir'].'&path=', false);
+ $breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', '' );
+ $breadcrumbNav->assign('breadcrumb', $breadcrumb, false);
+ $breadcrumbNav->assign('baseURL', OCP\Util::linkToPublic('files').'&dir='.$_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('details', $uidOwner.' shared the folder '.$baseDir.' with you');
+ $tmpl->assign('dir', basename($dir));
+ $tmpl->assign('filename', basename($path));
+ $tmpl->assign('mimetype', OC_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='.$_GET['dir'].'&path='.$getPath, false);
} else {
// Show file preview if viewer is available
+ $tmpl->assign('details', $uidOwner.' shared the file '.basename($path).' with you');
$tmpl->assign('dir', dirname($path));
$tmpl->assign('filename', basename($path));
$tmpl->assign('mimetype', OC_Filesystem::getMimeType($path));
- $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files').'&file='.$_GET['file'].'&download');
+ if ($type == 'file') {
+ $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files').'&file='.$_GET['file'].'&download', false);
+ } else {
+ if (isset($_GET['path'])) {
+ $getPath = $_GET['path'];
+ } else {
+ $getPath = '';
+ }
+ $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files').'&download&dir='.$_GET['dir'].'&path='.$getPath, false);
+ }
}
$tmpl->printPage();
}
@@ -71,4 +155,4 @@ if (isset($_GET['file'])) {
}
header('HTTP/1.0 404 Not Found');
$tmpl = new OCP\Template('', '404', 'guest');
-$tmpl->printPage();
+$tmpl->printPage(); \ No newline at end of file