Show preview for public folder links

This commit is contained in:
Michael Gapczynski 2012-09-18 23:56:00 -04:00
parent b0e645fe13
commit 749b5b52ca
4 changed files with 122 additions and 24 deletions

View File

@ -1,6 +1,10 @@
// Override download path to files_sharing/public.php // Override download path to files_sharing/public.php
function fileDownloadPath(dir, file) { function fileDownloadPath(dir, file) {
return $('#downloadURL').val(); var url = $('#downloadURL').val();
if (url.indexOf('&path=') != -1) {
url += '/'+file;
}
return url;
} }
$(document).ready(function() { $(document).ready(function() {
@ -17,6 +21,12 @@ $(document).ready(function() {
action($('#filename').val()); 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');
}
});
} }
}); });

View File

@ -39,10 +39,8 @@ $(document).ready(function() {
var tr = $('tr').filterAttr('data-file', filename); var tr = $('tr').filterAttr('data-file', filename);
if ($(tr).data('type') == 'dir') { if ($(tr).data('type') == 'dir') {
var itemType = 'folder'; var itemType = 'folder';
var link = false;
} else { } else {
var itemType = 'file'; var itemType = 'file';
var link = true;
} }
var possiblePermissions = $(tr).data('permissions'); var possiblePermissions = $(tr).data('permissions');
var appendTo = $(tr).find('td.filename'); var appendTo = $(tr).find('td.filename');
@ -51,14 +49,14 @@ $(document).ready(function() {
if (item != $('#dropdown').data('item')) { if (item != $('#dropdown').data('item')) {
OC.Share.hideDropDown(function () { OC.Share.hideDropDown(function () {
$(tr).addClass('mouseOver'); $(tr).addClass('mouseOver');
OC.Share.showDropDown(itemType, $(tr).data('id'), appendTo, link, possiblePermissions); OC.Share.showDropDown(itemType, $(tr).data('id'), appendTo, true, possiblePermissions);
}); });
} else { } else {
OC.Share.hideDropDown(); OC.Share.hideDropDown();
} }
} else { } else {
$(tr).addClass('mouseOver'); $(tr).addClass('mouseOver');
OC.Share.showDropDown(itemType, $(tr).data('id'), appendTo, link, possiblePermissions); OC.Share.showDropDown(itemType, $(tr).data('id'), appendTo, true, possiblePermissions);
} }
}); });
} }

View File

@ -1,13 +1,21 @@
<?php <?php
// Load other apps for file previews // Load other apps for file previews
OC_App::loadApps(); OC_App::loadApps();
if (isset($_GET['file'])) { if (isset($_GET['file']) || isset($_GET['dir'])) {
$pos = strpos($_GET['file'], '/', 1); if (isset($_GET['dir'])) {
$uidOwner = substr($_GET['file'], 1, $pos - 1); $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)) { if (OCP\User::userExists($uidOwner)) {
OC_Util::setupFS($uidOwner); OC_Util::setupFS($uidOwner);
$fileSource = OC_Filecache::getId($_GET['file'], ''); $fileSource = OC_Filecache::getId($path, '');
if ($fileSource != -1 && ($linkItem = OCP\Share::getItemSharedWithByLink('file', $fileSource, $uidOwner))) { if ($fileSource != -1 && ($linkItem = OCP\Share::getItemSharedWithByLink($type, $fileSource, $uidOwner))) {
if (isset($linkItem['share_with'])) { if (isset($linkItem['share_with'])) {
// Check password // Check password
if (isset($_POST['password'])) { if (isset($_POST['password'])) {
@ -35,6 +43,16 @@ if (isset($_GET['file'])) {
} }
} }
$path = $linkItem['path']; $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 // Download the file
if (isset($_GET['download'])) { if (isset($_GET['download'])) {
$mimetype = OC_Filesystem::getMimeType($path); $mimetype = OC_Filesystem::getMimeType($path);
@ -50,18 +68,84 @@ if (isset($_GET['file'])) {
OCP\Util::addScript('files_sharing', 'public'); OCP\Util::addScript('files_sharing', 'public');
OCP\Util::addScript('files', 'fileactions'); OCP\Util::addScript('files', 'fileactions');
$tmpl = new OCP\Template('files_sharing', 'public', 'base'); $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('owner', $uidOwner);
$tmpl->assign('name', basename($path));
// Show file list // Show file list
if (OC_Filesystem::is_dir($path)) { 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 { } else {
// Show file preview if viewer is available // 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('dir', dirname($path));
$tmpl->assign('filename', basename($path)); $tmpl->assign('filename', basename($path));
$tmpl->assign('mimetype', OC_Filesystem::getMimeType($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(); $tmpl->printPage();
} }

View File

@ -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> <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"> <div class="header-right">
<span id="details"><?php echo $_['details']; ?></span> <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>
</div></header> </div></header>
<div id="preview"> <div id="preview">
<?php if (substr($_['mimetype'], 0 , strpos($_['mimetype'], '/')) == 'image'): ?> <?php if (isset($_['folder'])): ?>
<img src="<?php echo $_['downloadURL']; ?>" /> <?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; ?> <?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> <div id="content"></div>
<table></table> <table></table>
</div> </div>