summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorMichael Gapczynski <mtgap@owncloud.com>2012-09-18 23:56:00 -0400
committerMichael Gapczynski <mtgap@owncloud.com>2012-09-18 23:56:14 -0400
commit749b5b52ca5361be76d8e6ffb5857e2b6ca60311 (patch)
tree1bebbe9694745f9fb6b54976a34d4ee142a94c2b /apps
parentb0e645fe1372f7408507abb755626eba55f47dfb (diff)
downloadnextcloud-server-749b5b52ca5361be76d8e6ffb5857e2b6ca60311.tar.gz
nextcloud-server-749b5b52ca5361be76d8e6ffb5857e2b6ca60311.zip
Show preview for public folder links
Diffstat (limited to 'apps')
-rw-r--r--apps/files_sharing/js/public.js12
-rw-r--r--apps/files_sharing/js/share.js6
-rw-r--r--apps/files_sharing/public.php104
-rwxr-xr-xapps/files_sharing/templates/public.php24
4 files changed, 122 insertions, 24 deletions
diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js
index 92b626bba18..b1b6b079db6 100644
--- a/apps/files_sharing/js/public.js
+++ b/apps/files_sharing/js/public.js
@@ -1,6 +1,10 @@
// Override download path to files_sharing/public.php
function fileDownloadPath(dir, file) {
- return $('#downloadURL').val();
+ var url = $('#downloadURL').val();
+ if (url.indexOf('&path=') != -1) {
+ url += '/'+file;
+ }
+ return url;
}
$(document).ready(function() {
@@ -17,6 +21,12 @@ $(document).ready(function() {
action($('#filename').val());
}
}
+ FileActions.register('dir', 'Open', OC.PERMISSION_READ, '', function(filename) {
+ var tr = $('tr').filterAttr('data-file', filename)
+ if (tr.length > 0) {
+ window.location = $(tr).find('a.name').attr('href');
+ }
+ });
}
}); \ No newline at end of file
diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js
index 9d0e2c90f88..a171751589a 100644
--- a/apps/files_sharing/js/share.js
+++ b/apps/files_sharing/js/share.js
@@ -39,10 +39,8 @@ $(document).ready(function() {
var tr = $('tr').filterAttr('data-file', filename);
if ($(tr).data('type') == 'dir') {
var itemType = 'folder';
- var link = false;
} else {
var itemType = 'file';
- var link = true;
}
var possiblePermissions = $(tr).data('permissions');
var appendTo = $(tr).find('td.filename');
@@ -51,14 +49,14 @@ $(document).ready(function() {
if (item != $('#dropdown').data('item')) {
OC.Share.hideDropDown(function () {
$(tr).addClass('mouseOver');
- OC.Share.showDropDown(itemType, $(tr).data('id'), appendTo, link, possiblePermissions);
+ OC.Share.showDropDown(itemType, $(tr).data('id'), appendTo, true, possiblePermissions);
});
} else {
OC.Share.hideDropDown();
}
} else {
$(tr).addClass('mouseOver');
- OC.Share.showDropDown(itemType, $(tr).data('id'), appendTo, link, possiblePermissions);
+ OC.Share.showDropDown(itemType, $(tr).data('id'), appendTo, true, possiblePermissions);
}
});
}
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
diff --git a/apps/files_sharing/templates/public.php b/apps/files_sharing/templates/public.php
index ca48a35575e..426b45b2681 100755
--- a/apps/files_sharing/templates/public.php
+++ b/apps/files_sharing/templates/public.php
@@ -6,19 +6,25 @@
<a href="<?php echo link_to('', 'index.php'); ?>" title="" id="owncloud"><img class="svg" src="<?php echo image_path('', 'logo-wide.svg'); ?>" alt="ownCloud" /></a>
<div class="header-right">
<span id="details"><?php echo $_['details']; ?></span>
- <a href="<?php echo $_['downloadURL']; ?>" id="download"><img class="svg" alt="Download" src="<?php echo OCP\image_path("core", "actions/download.svg"); ?>" /><?php echo $l->t('Download')?></a>
+ <?php if (!isset($_['folder']) || $_['allowZipDownload']): ?>
+ <a href="<?php echo $_['downloadURL']; ?>" id="download"><img class="svg" alt="Download" src="<?php echo OCP\image_path("core", "actions/download.svg"); ?>" /><?php echo $l->t('Download')?></a>
+ <?php endif; ?>
</div>
</div></header>
<div id="preview">
- <?php if (substr($_['mimetype'], 0 , strpos($_['mimetype'], '/')) == 'image'): ?>
- <img src="<?php echo $_['downloadURL']; ?>" />
+ <?php if (isset($_['folder'])): ?>
+ <?php echo $_['folder']; ?>
+ <?php else: ?>
+ <?php if (substr($_['mimetype'], 0 , strpos($_['mimetype'], '/')) == 'image'): ?>
+ <img src="<?php echo $_['downloadURL']; ?>" />
+ <?php endif; ?>
+ <ul id="noPreview">
+ <li class="error">
+ <?php echo $l->t('No preview available for').' '.$_['filename']; ?><br />
+ <a href="<?php echo $_['downloadURL']; ?>" id="download"><img class="svg" alt="Download" src="<?php echo OCP\image_path("core", "actions/download.svg"); ?>" /><?php echo $l->t('Download')?></a>
+ </li>
+ </ul>
<?php endif; ?>
- <ul id="noPreview">
- <li class="error">
- <?php echo $l->t('No preview available for').' '.$_['filename']; ?><br />
- <a href="<?php echo $_['downloadURL']; ?>" id="download"><img class="svg" alt="Download" src="<?php echo OCP\image_path("core", "actions/download.svg"); ?>" /><?php echo $l->t('Download')?></a>
- </li>
- </ul>
<div id="content"></div>
<table></table>
</div>