summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-08-31 03:41:29 -0700
committerThomas Müller <thomas.mueller@tmit.eu>2013-08-31 03:41:29 -0700
commit92e90c8eb995c886b3e9cd77c14e3f0b25b95cd7 (patch)
treeed757086fcf6d761a615eb7bbbf24ebc06407310 /apps
parent0f5df181a3b1f88075193fca0bed88f289314c8e (diff)
parent668c4c2652ef4619a132d609461423aafaef424e (diff)
downloadnextcloud-server-92e90c8eb995c886b3e9cd77c14e3f0b25b95cd7.tar.gz
nextcloud-server-92e90c8eb995c886b3e9cd77c14e3f0b25b95cd7.zip
Merge pull request #4022 from owncloud/oc_preview
\OC\Preview
Diffstat (limited to 'apps')
-rw-r--r--apps/files/ajax/newfile.php2
-rw-r--r--apps/files/css/files.css187
-rw-r--r--apps/files/index.php2
-rw-r--r--apps/files/js/file-upload.js12
-rw-r--r--apps/files/js/filelist.js12
-rw-r--r--apps/files/js/files.js22
-rw-r--r--apps/files/templates/index.php29
-rw-r--r--apps/files/templates/part.list.php32
-rw-r--r--apps/files_sharing/ajax/publicpreview.php85
-rw-r--r--apps/files_sharing/appinfo/routes.php5
-rw-r--r--apps/files_sharing/js/public.js2
-rw-r--r--apps/files_sharing/public.php4
-rw-r--r--apps/files_sharing/templates/public.php4
-rw-r--r--apps/files_trashbin/ajax/preview.php42
-rw-r--r--apps/files_trashbin/appinfo/routes.php5
-rw-r--r--apps/files_trashbin/index.php1
-rw-r--r--apps/files_trashbin/lib/trash.php3
-rw-r--r--apps/files_trashbin/templates/part.list.php10
18 files changed, 396 insertions, 63 deletions
diff --git a/apps/files/ajax/newfile.php b/apps/files/ajax/newfile.php
index d224e79d01b..76c03c87a51 100644
--- a/apps/files/ajax/newfile.php
+++ b/apps/files/ajax/newfile.php
@@ -79,7 +79,7 @@ if($source) {
$success = false;
if (!$content) {
$templateManager = OC_Helper::getFileTemplateManager();
- $mimeType = OC_Helper::getMimeType($target);
+ $mimeType = OC_Helper::getMimetypeDetector()->detectPath($target);
$content = $templateManager->getTemplate($mimeType);
}
diff --git a/apps/files/css/files.css b/apps/files/css/files.css
index af0cb835811..498e34d70d4 100644
--- a/apps/files/css/files.css
+++ b/apps/files/css/files.css
@@ -19,10 +19,13 @@
background:#f8f8f8; border:1px solid #ddd; border-radius:10px; border-top-left-radius:0;
box-shadow:0 2px 7px rgba(170,170,170,.4);
}
-#new>ul>li { height:20px; margin:.3em; padding-left:2em; padding-bottom:0.1em;
+#new>ul>li { height:36px; margin:.3em; padding-left:3em; padding-bottom:0.1em;
background-repeat:no-repeat; cursor:pointer; }
-#new>ul>li>p { cursor:pointer; }
-#new>ul>li>form>input { padding:0.3em; margin:-0.3em; }
+#new>ul>li>p { cursor:pointer; padding-top: 7px; padding-bottom: 7px;}
+#new>ul>li>form>input {
+ padding: 5px;
+ margin: 2px 0;
+}
#trash { margin: 0 1em; z-index:1010; float: right; }
@@ -72,7 +75,7 @@
color:#888; text-shadow:#fff 0 1px 0;
}
#filestable { position: relative; top:37px; width:100%; }
-#filestable tbody tr { background-color:#fff; height:2.5em; }
+tbody tr { background-color:#fff; height:2.5em; }
tbody tr:hover, tbody tr:active {
background-color: rgb(240,240,240);
}
@@ -85,54 +88,153 @@ span.extension { text-transform:lowercase; -ms-filter:"progid:DXImageTransform.M
tr:hover span.extension { -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; filter:alpha(opacity=100); opacity:1; color:#777; }
table tr.mouseOver td { background-color:#eee; }
table th { height:2em; padding:0 .5em; color:#999; }
-table th .name { float:left; margin-left:.5em; }
+table th .name {
+ position: absolute;
+ left: 55px;
+ top: 15px;
+}
table th, table td { border-bottom:1px solid #ddd; text-align:left; font-weight:normal; }
-table td { border-bottom:1px solid #eee; font-style:normal; background-position:1em .5em; background-repeat:no-repeat; }
-table th#headerName { width:100em; /* not really sure why this works better than 100% … table styling */ }
-table th#headerSize, table td.filesize { min-width:3em; padding:0 1em; text-align:right; }
-table th#headerDate, table td.date { min-width:11em; padding:0 .1em 0 1em; text-align:left; }
+table td {
+ border-bottom: 1px solid #eee;
+ font-style: normal;
+ background-position: 8px center;
+ background-repeat: no-repeat;
+}
+table th#headerName {
+ position: relative;
+ width: 100em; /* not really sure why this works better than 100% … table styling */
+ padding: 0;
+}
+#headerName-container {
+ position: relative;
+ height: 50px;
+}
+table th#headerSize, table td.filesize {
+ min-width: 3em;
+ padding: 0 1em;
+ text-align: right;
+}
+table th#headerDate, table td.date {
+ -moz-box-sizing: border-box;
+ box-sizing: border-box;
+ position: relative;
+ min-width: 11em;
+ display: block;
+ height: 51px;
+}
/* Multiselect bar */
-#filestable.multiselect { top:63px; }
+#filestable.multiselect {
+ top: 88px;
+}
table.multiselect thead { position:fixed; top:82px; z-index:1; -moz-box-sizing: border-box; box-sizing: border-box; left: 0; padding-left: 80px; width:100%; }
+
table.multiselect thead th {
background-color: rgba(210,210,210,.7);
color: #000;
font-weight: bold;
border-bottom: 0;
}
-table.multiselect #headerName { width: 100%; }
+table.multiselect #headerName {
+ position: relative;
+ width: 100%;
+}
table td.selection, table th.selection, table td.fileaction { width:2em; text-align:center; }
-table td.filename a.name { display:block; height:1.5em; vertical-align:middle; margin-left:3em; }
+table td.filename a.name {
+ position:relative; /* Firefox needs to explicitly have this default set … */
+ -moz-box-sizing: border-box;
+ box-sizing: border-box;
+ display: block;
+ height: 50px;
+ vertical-align: middle;
+ padding: 0;
+}
table tr[data-type="dir"] td.filename a.name span.nametext {font-weight:bold; }
-table td.filename input.filename { width:100%; cursor:text; }
-table td.filename a, table td.login, table td.logout, table td.download, table td.upload, table td.create, table td.delete { padding:.2em .5em .5em 0; }
+table td.filename input.filename {
+ width: 80%;
+ font-size: 14px;
+ margin-top: 8px;
+ margin-left: 2px;
+ cursor: text;
+}
+table td.filename a, table td.login, table td.logout, table td.download, table td.upload, table td.create, table td.delete { padding:.2em .5em .5em .3em; }
table td.filename .nametext, .uploadtext, .modified { float:left; padding:.3em 0; }
+
+#modified {
+ position: absolute;
+ top: 15px;
+}
+.modified {
+ position: relative;
+ top: 11px;
+ left: 5px;
+}
+
/* TODO fix usability bug (accidental file/folder selection) */
-table td.filename .nametext { overflow:hidden; text-overflow:ellipsis; max-width:800px; }
+table td.filename .nametext {
+ position: absolute;
+ top: 16px;
+ left: 55px;
+ padding: 0;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ max-width: 800px;
+}
table td.filename .uploadtext { font-weight:normal; margin-left:.5em; }
table td.filename form { font-size:.85em; margin-left:3em; margin-right:3em; }
+
/* File checkboxes */
-#fileList tr td.filename>input[type="checkbox"]:first-child { -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; filter:alpha(opacity=0); opacity:0; float:left; margin:.7em 0 0 1em; /* bigger clickable area doesn’t work in FF width:2.8em; height:2.4em;*/ -webkit-transition:opacity 200ms; -moz-transition:opacity 200ms; -o-transition:opacity 200ms; transition:opacity 200ms; }
-#fileList tr td.filename>input[type="checkbox"]:hover:first-child { -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=80)"; filter:alpha(opacity=80); opacity:.8; }
-/* Always show checkbox when selected */
-#fileList tr td.filename>input[type="checkbox"]:checked:first-child { -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; filter:alpha(opacity=100); opacity:1; }
-#fileList tr.selected td.filename>input[type="checkbox"]:first-child { -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; filter:alpha(opacity=100); opacity:1; }
+#fileList tr td.filename>input[type="checkbox"]:first-child {
+ -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
+ filter: alpha(opacity=0);
+ opacity: 0;
+ float: left;
+ margin: 32px 0 4px 32px; /* bigger clickable area doesn’t work in FF width:2.8em; height:2.4em;*/
+}
+/* Show checkbox when hovering, checked, or selected */
+#fileList tr:hover td.filename>input[type="checkbox"]:first-child,
+#fileList tr td.filename>input[type="checkbox"]:checked:first-child,
+#fileList tr.selected td.filename>input[type="checkbox"]:first-child {
+ -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
+ filter: alpha(opacity=100);
+ opacity: 1;
+}
+/* Use label to have bigger clickable size for checkbox */
+#fileList tr td.filename>input[type="checkbox"] + label,
+#select_all + label {
+ height: 50px;
+ position: absolute;
+ width: 50px;
+ z-index: 5;
+}
+#fileList tr td.filename>input[type="checkbox"] + label {
+ left: 0;
+}
+#select_all + label {
+ top: 0;
+}
+#select_all {
+ position: absolute;
+ top: 18px;
+ left: 18px;
+}
+
#fileList tr td.filename {
position:relative; width:100%;
-webkit-transition:background-image 500ms; -moz-transition:background-image 500ms; -o-transition:background-image 500ms; transition:background-image 500ms;
}
-#select_all { float:left; margin:.4em 0.6em 0 .5em; }
+
#uploadsize-message,#delete-confirm { display:none; }
/* File actions */
.fileactions {
- position:absolute; top:.6em; right:0;
- font-size:.8em;
+ position: absolute;
+ top: 16px;
+ right: 0;
+ font-size: 11px;
}
-#fileList .name { position:relative; /* Firefox needs to explicitly have this default set … */ }
#fileList tr:hover .fileactions { /* background to distinguish when overlaying with file names */
background-color: rgba(240,240,240,0.898);
box-shadow: -5px 0 7px rgba(240,240,240,0.898);
@@ -142,15 +244,39 @@ table td.filename form { font-size:.85em; margin-left:3em; margin-right:3em; }
box-shadow: -5px 0 7px rgba(230,230,230,.9);
}
#fileList .fileactions a.action img { position:relative; top:.2em; }
-#fileList a.action { display:inline; margin:-.5em 0; padding:1em .5em 1em .5em !important; }
+
#fileList img.move2trash { display:inline; margin:-.5em 0; padding:1em .5em 1em .5em !important; float:right; }
-a.action.delete { float:right; }
+#fileList a.action.delete {
+ position: absolute;
+ right: 0;
+ top: 0;
+ margin: 0;
+ padding: 15px 14px 19px !important;
+}
a.action>img { max-height:16px; max-width:16px; vertical-align:text-bottom; }
-.selectedActions { display:none; float:right; }
-.selectedActions a { display:inline; margin:-.5em 0; padding:.5em !important; }
-.selectedActions a img { position:relative; top:.3em; }
+
+/* Actions for selected files */
+.selectedActions {
+ display: none;
+ position: absolute;
+ top: -1px;
+ right: 0;
+ padding: 15px 8px;
+}
+.selectedActions a {
+ display: inline;
+ padding: 17px 5px;
+}
+.selectedActions a img {
+ position:relative;
+ top:.3em;
+}
+
#fileList a.action {
+ display: inline;
+ margin: -.5em 0;
+ padding: 18px 8px !important;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter: alpha(opacity=0);
opacity: 0;
@@ -185,9 +311,8 @@ a.action>img { max-height:16px; max-width:16px; vertical-align:text-bottom; }
padding-bottom: 8px;
border-bottom: none;
}
-
.summary .info {
- margin-left: 3em;
+ margin-left: 55px;
}
#scanning-message{ top:40%; left:40%; position:absolute; display:none; }
diff --git a/apps/files/index.php b/apps/files/index.php
index e4d8e353858..f1e120c872c 100644
--- a/apps/files/index.php
+++ b/apps/files/index.php
@@ -74,6 +74,7 @@ foreach ($content as $i) {
}
}
$i['directory'] = $dir;
+ $i['isPreviewAvailable'] = \OCP\Preview::isMimeSupported($i['mimetype']);
$files[] = $i;
}
@@ -95,6 +96,7 @@ $list->assign('files', $files);
$list->assign('baseURL', OCP\Util::linkTo('files', 'index.php') . '?dir=');
$list->assign('downloadURL', OCP\Util::linkToRoute('download', array('file' => '/')));
$list->assign('disableSharing', false);
+$list->assign('isPublic', false);
$breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', '');
$breadcrumbNav->assign('breadcrumb', $breadcrumb);
$breadcrumbNav->assign('baseURL', OCP\Util::linkTo('files', 'index.php') . '?dir=');
diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js
index 1e6ab74fb6d..3d620c5640b 100644
--- a/apps/files/js/file-upload.js
+++ b/apps/files/js/file-upload.js
@@ -227,7 +227,7 @@ $(document).ready(function() {
$(this).data('text',text);
$(this).children('p').remove();
var form=$('<form></form>');
- var input=$('<input>');
+ var input=$('<input type="text">');
form.append(input);
$(this).append(form);
input.focus();
@@ -268,8 +268,9 @@ $(document).ready(function() {
tr.attr('data-mime',result.data.mime);
tr.attr('data-id', result.data.id);
tr.find('.filesize').text(humanFileSize(result.data.size));
- getMimeIcon(result.data.mime,function(path){
- tr.find('td.filename').attr('style','background-image:url('+path+')');
+ var path = getPathForPreview(name);
+ lazyLoadPreview(path, result.data.mime, function(previewpath){
+ tr.find('td.filename').attr('style','background-image:url('+previewpath+')');
});
} else {
OC.dialogs.alert(result.data.message, t('core', 'Error'));
@@ -330,8 +331,9 @@ $(document).ready(function() {
var tr=$('tr').filterAttr('data-file',localName);
tr.data('mime',mime).data('id',id);
tr.attr('data-id', id);
- getMimeIcon(mime,function(path){
- tr.find('td.filename').attr('style','background-image:url('+path+')');
+ var path = $('#dir').val()+'/'+localName;
+ lazyLoadPreview(path, mime, function(previewpath){
+ tr.find('td.filename').attr('style','background-image:url('+previewpath+')');
});
});
eventSource.listen('error',function(error){
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js
index e11cc70802b..05e31094502 100644
--- a/apps/files/js/filelist.js
+++ b/apps/files/js/filelist.js
@@ -15,9 +15,10 @@ var FileList={
// filename td
td = $('<td></td>').attr({
"class": "filename",
- "style": 'background-image:url('+iconurl+'); background-size: 16px;'
+ "style": 'background-image:url('+iconurl+'); background-size: 32px;'
});
- td.append('<input type="checkbox" />');
+ var rand = Math.random().toString(16).slice(2);
+ td.append('<input id="select-'+rand+'" type="checkbox" /><label for="select-'+rand+'"></label>');
var link_elem = $('<a></a>').attr({
"class": "name",
"href": linktarget
@@ -187,8 +188,9 @@ var FileList={
if (id != null) {
tr.attr('data-id', id);
}
- getMimeIcon(mime,function(path){
- tr.find('td.filename').attr('style','background-image:url('+path+')');
+ var path = getPathForPreview(name);
+ lazyLoadPreview(path, mime, function(previewpath){
+ tr.find('td.filename').attr('style','background-image:url('+previewpath+')');
});
tr.find('td.filename').draggable(dragOptions);
},
@@ -200,7 +202,7 @@ var FileList={
tr=$('tr').filterAttr('data-file',name);
tr.data('renaming',true);
td=tr.children('td.filename');
- input=$('<input class="filename"/>').val(name);
+ input=$('<input type="text" class="filename"/>').val(name);
form=$('<form></form>');
form.append(input);
td.children('a.name').hide();
diff --git a/apps/files/js/files.js b/apps/files/js/files.js
index 87311237e36..d729077ea72 100644
--- a/apps/files/js/files.js
+++ b/apps/files/js/files.js
@@ -454,8 +454,9 @@ var createDragShadow = function(event){
if (elem.type === 'dir') {
newtr.find('td.filename').attr('style','background-image:url('+OC.imagePath('core', 'filetypes/folder.png')+')');
} else {
- getMimeIcon(elem.mime,function(path){
- newtr.find('td.filename').attr('style','background-image:url('+path+')');
+ var path = getPathForPreview(elem.name);
+ lazyLoadPreview(path, elem.mime, function(previewpath){
+ newtr.find('td.filename').attr('style','background-image:url('+previewpath+')');
});
}
});
@@ -631,6 +632,23 @@ function getMimeIcon(mime, ready){
}
getMimeIcon.cache={};
+function getPathForPreview(name) {
+ var path = $('#dir').val() + '/' + name;
+ return path;
+}
+
+function lazyLoadPreview(path, mime, ready) {
+ getMimeIcon(mime,ready);
+ var x = $('#filestable').data('preview-x');
+ var y = $('#filestable').data('preview-y');
+ var previewURL = OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:x, y:y});
+ $.get(previewURL, function() {
+ previewURL = previewURL.replace('(','%28');
+ previewURL = previewURL.replace(')','%29');
+ ready(previewURL + '&reload=true');
+ });
+}
+
function getUniqueName(name){
if($('tr').filterAttr('data-file',name).length>0){
var parts=name.split('.');
diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php
index 360874103f8..2f7e0af4f28 100644
--- a/apps/files/templates/index.php
+++ b/apps/files/templates/index.php
@@ -10,7 +10,7 @@
data-type='file'><p><?php p($l->t('Text file'));?></p></li>
<li style="background-image:url('<?php p(OCP\mimetype_icon('dir')) ?>')"
data-type='folder'><p><?php p($l->t('Folder'));?></p></li>
- <li style="background-image:url('<?php p(OCP\image_path('core', 'actions/public.png')) ?>')"
+ <li style="background-image:url('<?php p(OCP\image_path('core', 'filetypes/web.svg')) ?>')"
data-type='web'><p><?php p($l->t('From link'));?></p></li>
</ul>
</div>
@@ -59,21 +59,24 @@
<div id="emptyfolder"><?php p($l->t('Nothing in here. Upload something!'))?></div>
<?php endif; ?>
-<table id="filestable" data-allow-public-upload="<?php p($_['publicUploadEnabled'])?>">
+<table id="filestable" data-allow-public-upload="<?php p($_['publicUploadEnabled'])?>" data-preview-x="36" data-preview-y="36">
<thead>
<tr>
<th id='headerName'>
- <input type="checkbox" id="select_all" />
- <span class='name'><?php p($l->t( 'Name' )); ?></span>
- <span class='selectedActions'>
- <?php if($_['allowZipDownload']) : ?>
- <a href="" class="download">
- <img class="svg" alt="Download"
- src="<?php print_unescaped(OCP\image_path("core", "actions/download.svg")); ?>" />
- <?php p($l->t('Download'))?>
- </a>
- <?php endif; ?>
- </span>
+ <div id="headerName-container">
+ <input type="checkbox" id="select_all" />
+ <label for="select_all"></label>
+ <span class="name"><?php p($l->t( 'Name' )); ?></span>
+ <span class="selectedActions">
+ <?php if($_['allowZipDownload']) : ?>
+ <a href="" class="download">
+ <img class="svg" alt="Download"
+ src="<?php print_unescaped(OCP\image_path("core", "actions/download.svg")); ?>" />
+ <?php p($l->t('Download'))?>
+ </a>
+ <?php endif; ?>
+ </span>
+ </div>
</th>
<th id="headerSize"><?php p($l->t('Size')); ?></th>
<th id="headerDate">
diff --git a/apps/files/templates/part.list.php b/apps/files/templates/part.list.php
index 3e6f619868d..4076c1bb331 100644
--- a/apps/files/templates/part.list.php
+++ b/apps/files/templates/part.list.php
@@ -1,5 +1,7 @@
<input type="hidden" id="disableSharing" data-status="<?php p($_['disableSharing']); ?>">
<?php foreach($_['files'] as $file):
+ //strlen('files/') => 6
+ $relativePath = substr($file['path'], 6);
// the bigger the file, the darker the shade of grey; megabytes*2
$simple_size_color = intval(160-$file['size']/(1024*1024)*2);
if($simple_size_color<0) $simple_size_color = 0;
@@ -13,16 +15,38 @@
data-file="<?php p($name);?>"
data-type="<?php ($file['type'] == 'dir')?p('dir'):p('file')?>"
data-mime="<?php p($file['mimetype'])?>"
- data-size='<?php p($file['size']);?>'
- data-permissions='<?php p($file['permissions']); ?>'>
+ data-size="<?php p($file['size']);?>"
+ data-permissions="<?php p($file['permissions']); ?>">
+ <?php if($file['isPreviewAvailable']): ?>
+ <td class="filename svg preview-icon"
+ <?php else: ?>
<td class="filename svg"
+ <?php endif; ?>
<?php if($file['type'] == 'dir'): ?>
style="background-image:url(<?php print_unescaped(OCP\mimetype_icon('dir')); ?>)"
<?php else: ?>
- style="background-image:url(<?php print_unescaped(OCP\mimetype_icon($file['mimetype'])); ?>)"
+ <?php if($_['isPublic']): ?>
+ <?php
+ $relativePath = substr($relativePath, strlen($_['sharingroot']));
+ ?>
+ <?php if($file['isPreviewAvailable']): ?>
+ style="background-image:url(<?php print_unescaped(OCP\publicPreview_icon($relativePath, $_['sharingtoken'])); ?>)"
+ <?php else: ?>
+ style="background-image:url(<?php print_unescaped(OCP\mimetype_icon($file['mimetype'])); ?>)"
+ <?php endif; ?>
+ <?php else: ?>
+ <?php if($file['isPreviewAvailable']): ?>
+ style="background-image:url(<?php print_unescaped(OCP\preview_icon($relativePath)); ?>)"
+ <?php else: ?>
+ style="background-image:url(<?php print_unescaped(OCP\mimetype_icon($file['mimetype'])); ?>)"
+ <?php endif; ?>
+ <?php endif; ?>
<?php endif; ?>
>
- <?php if(!isset($_['readonly']) || !$_['readonly']): ?><input type="checkbox" /><?php endif; ?>
+ <?php if(!isset($_['readonly']) || !$_['readonly']): ?>
+ <input id="select-<?php p($file['fileid']); ?>" type="checkbox" />
+ <label for="select-<?php p($file['fileid']); ?>"></label>
+ <?php endif; ?>
<?php if($file['type'] == 'dir'): ?>
<a class="name" href="<?php p(rtrim($_['baseURL'],'/').'/'.trim($directory,'/').'/'.$name); ?>" title="">
<?php else: ?>
diff --git a/apps/files_sharing/ajax/publicpreview.php b/apps/files_sharing/ajax/publicpreview.php
new file mode 100644
index 00000000000..41a1c178a48
--- /dev/null
+++ b/apps/files_sharing/ajax/publicpreview.php
@@ -0,0 +1,85 @@
+<?php
+/**
+ * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+if(!\OC_App::isEnabled('files_sharing')){
+ exit;
+}
+
+$file = array_key_exists('file', $_GET) ? (string) urldecode($_GET['file']) : '';
+$maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '36';
+$maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '36';
+$scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true;
+$token = array_key_exists('t', $_GET) ? (string) $_GET['t'] : '';
+
+if($token === ''){
+ \OC_Response::setStatus(400); //400 Bad Request
+ \OC_Log::write('core-preview', 'No token parameter was passed', \OC_Log::DEBUG);
+ exit;
+}
+
+$linkedItem = \OCP\Share::getShareByToken($token);
+if($linkedItem === false || ($linkedItem['item_type'] !== 'file' && $linkedItem['item_type'] !== 'folder')) {
+ \OC_Response::setStatus(404);
+ \OC_Log::write('core-preview', 'Passed token parameter is not valid', \OC_Log::DEBUG);
+ exit;
+}
+
+if(!isset($linkedItem['uid_owner']) || !isset($linkedItem['file_source'])) {
+ \OC_Response::setStatus(500);
+ \OC_Log::write('core-preview', 'Passed token seems to be valid, but it does not contain all necessary information . ("' . $token . '")', \OC_Log::WARN);
+ exit;
+}
+
+$userId = $linkedItem['uid_owner'];
+\OC_Util::setupFS($userId);
+
+$pathId = $linkedItem['file_source'];
+$path = \OC\Files\Filesystem::getPath($pathId);
+$pathInfo = \OC\Files\Filesystem::getFileInfo($path);
+$sharedFile = null;
+
+if($linkedItem['item_type'] === 'folder') {
+ $isvalid = \OC\Files\Filesystem::isValidPath($file);
+ if(!$isvalid) {
+ \OC_Response::setStatus(400); //400 Bad Request
+ \OC_Log::write('core-preview', 'Passed filename is not valid, might be malicious (file:"' . $file . '";ip:"' . $_SERVER['REMOTE_ADDR'] . '")', \OC_Log::WARN);
+ exit;
+ }
+ $sharedFile = \OC\Files\Filesystem::normalizePath($file);
+}
+
+if($linkedItem['item_type'] === 'file') {
+ $parent = $pathInfo['parent'];
+ $path = \OC\Files\Filesystem::getPath($parent);
+ $sharedFile = $pathInfo['name'];
+}
+
+$path = \OC\Files\Filesystem::normalizePath($path, false);
+if(substr($path, 0, 1) === '/') {
+ $path = substr($path, 1);
+}
+
+if($maxX === 0 || $maxY === 0) {
+ \OC_Response::setStatus(400); //400 Bad Request
+ \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG);
+ exit;
+}
+
+$root = 'files/' . $path;
+
+try{
+ $preview = new \OC\Preview($userId, $root);
+ $preview->setFile($sharedFile);
+ $preview->setMaxX($maxX);
+ $preview->setMaxY($maxY);
+ $preview->setScalingUp($scalingUp);
+
+ $preview->show();
+} catch (\Exception $e) {
+ \OC_Response::setStatus(500);
+ \OC_Log::write('core', $e->getmessage(), \OC_Log::DEBUG);
+} \ No newline at end of file
diff --git a/apps/files_sharing/appinfo/routes.php b/apps/files_sharing/appinfo/routes.php
new file mode 100644
index 00000000000..02815b5eb42
--- /dev/null
+++ b/apps/files_sharing/appinfo/routes.php
@@ -0,0 +1,5 @@
+<?php
+$this->create('core_ajax_public_preview', '/publicpreview.png')->action(
+function() {
+ require_once __DIR__ . '/../ajax/publicpreview.php';
+}); \ No newline at end of file
diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js
index 7ffd5e06873..357c6fdf540 100644
--- a/apps/files_sharing/js/public.js
+++ b/apps/files_sharing/js/public.js
@@ -16,7 +16,7 @@ $(document).ready(function() {
if (typeof FileActions !== 'undefined') {
var mimetype = $('#mimetype').val();
// Show file preview if previewer is available, images are already handled by the template
- if (mimetype.substr(0, mimetype.indexOf('/')) != 'image') {
+ if (mimetype.substr(0, mimetype.indexOf('/')) != 'image' && $('.publicpreview').length === 0) {
// Trigger default action if not download TODO
var action = FileActions.getDefault(mimetype, 'file', OC.PERMISSION_READ);
if (typeof action === 'undefined') {
diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php
index e9fdf6e4c95..ec6b4e815f8 100644
--- a/apps/files_sharing/public.php
+++ b/apps/files_sharing/public.php
@@ -172,6 +172,7 @@ if (isset($path)) {
} else {
$i['extension'] = '';
}
+ $i['isPreviewAvailable'] = \OCP\Preview::isMimeSupported($i['mimetype']);
}
$i['directory'] = $getPath;
$i['permissions'] = OCP\PERMISSION_READ;
@@ -194,6 +195,9 @@ if (isset($path)) {
$list->assign('baseURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&path=');
$list->assign('downloadURL',
OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download&path=');
+ $list->assign('isPublic', true);
+ $list->assign('sharingtoken', $token);
+ $list->assign('sharingroot', $basePath);
$breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', '');
$breadcrumbNav->assign('breadcrumb', $breadcrumb);
$breadcrumbNav->assign('baseURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&path=');
diff --git a/apps/files_sharing/templates/public.php b/apps/files_sharing/templates/public.php
index 746a715f3cc..c164b3ea2b7 100644
--- a/apps/files_sharing/templates/public.php
+++ b/apps/files_sharing/templates/public.php
@@ -79,6 +79,10 @@
<source src="<?php p($_['downloadURL']); ?>" type="<?php p($_['mimetype']); ?>" />
</video>
</div>
+ <?php elseif (\OC\Preview::isMimeSupported($_['mimetype'])): ?>
+ <div id="imgframe">
+ <img src="<?php p(OCP\Util::linkToRoute( 'core_ajax_public_preview', array('x' => 500, 'y' => 500, 'file' => urlencode($_['directory_path']), 't' => $_['dirToken']))); ?>" class="publicpreview"/>
+ </div>
<?php else: ?>
<ul id="noPreview">
<li class="error">
diff --git a/apps/files_trashbin/ajax/preview.php b/apps/files_trashbin/ajax/preview.php
new file mode 100644
index 00000000000..a0846b051c7
--- /dev/null
+++ b/apps/files_trashbin/ajax/preview.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+\OC_Util::checkLoggedIn();
+
+if(!\OC_App::isEnabled('files_trashbin')){
+ exit;
+}
+
+$file = array_key_exists('file', $_GET) ? (string) urldecode($_GET['file']) : '';
+$maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '44';
+$maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '44';
+$scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true;
+
+if($file === '') {
+ \OC_Response::setStatus(400); //400 Bad Request
+ \OC_Log::write('core-preview', 'No file parameter was passed', \OC_Log::DEBUG);
+ exit;
+}
+
+if($maxX === 0 || $maxY === 0) {
+ \OC_Response::setStatus(400); //400 Bad Request
+ \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG);
+ exit;
+}
+
+try{
+ $preview = new \OC\Preview(\OC_User::getUser(), 'files_trashbin/files');
+ $preview->setFile($file);
+ $preview->setMaxX($maxX);
+ $preview->setMaxY($maxY);
+ $preview->setScalingUp($scalingUp);
+
+ $preview->showPreview();
+}catch(\Exception $e) {
+ \OC_Response::setStatus(500);
+ \OC_Log::write('core', $e->getmessage(), \OC_Log::DEBUG);
+} \ No newline at end of file
diff --git a/apps/files_trashbin/appinfo/routes.php b/apps/files_trashbin/appinfo/routes.php
new file mode 100644
index 00000000000..b1c3f02741e
--- /dev/null
+++ b/apps/files_trashbin/appinfo/routes.php
@@ -0,0 +1,5 @@
+<?php
+$this->create('core_ajax_trashbin_preview', '/preview.png')->action(
+function() {
+ require_once __DIR__ . '/../ajax/preview.php';
+}); \ No newline at end of file
diff --git a/apps/files_trashbin/index.php b/apps/files_trashbin/index.php
index 27f8407db06..0baeab1de97 100644
--- a/apps/files_trashbin/index.php
+++ b/apps/files_trashbin/index.php
@@ -64,6 +64,7 @@ foreach ($result as $r) {
$i['directory'] = '';
}
$i['permissions'] = OCP\PERMISSION_READ;
+ $i['isPreviewAvailable'] = \OCP\Preview::isMimeSupported($r['mime']);
$files[] = $i;
}
diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php
index 880832f9afa..c79afdc0c2e 100644
--- a/apps/files_trashbin/lib/trash.php
+++ b/apps/files_trashbin/lib/trash.php
@@ -904,4 +904,7 @@ class Trashbin {
return true;
}
+ public static function preview_icon($path) {
+ return \OC_Helper::linkToRoute( 'core_ajax_trashbin_preview', array('x' => 36, 'y' => 36, 'file' => urlencode($path) ));
+ }
}
diff --git a/apps/files_trashbin/templates/part.list.php b/apps/files_trashbin/templates/part.list.php
index 254b08dd36a..f7cc6b01bbb 100644
--- a/apps/files_trashbin/templates/part.list.php
+++ b/apps/files_trashbin/templates/part.list.php
@@ -21,11 +21,19 @@
data-timestamp='<?php p($file['timestamp']);?>'
data-dirlisting=0
<?php endif; ?>>
+ <?php if($file['isPreviewAvailable']): ?>
+ <td class="filename svg preview-icon"
+ <?php else: ?>
<td class="filename svg"
+ <?php endif; ?>
<?php if($file['type'] === 'dir'): ?>
style="background-image:url(<?php print_unescaped(OCP\mimetype_icon('dir')); ?>)"
<?php else: ?>
- style="background-image:url(<?php print_unescaped(OCP\mimetype_icon($file['mimetype'])); ?>)"
+ <?php if($file['isPreviewAvailable']): ?>
+ style="background-image:url(<?php print_unescaped(OCA\Files_Trashbin\Trashbin::preview_icon(!$_['dirlisting'] ? ($file['name'].'.d'.$file['timestamp']) : ($file['directory'].'/'.$file['name']))); ?>)"
+ <?php else: ?>
+ style="background-image:url(<?php print_unescaped(OCP\mimetype_icon($file['mimetype'])); ?>)"
+ <?php endif; ?>
<?php endif; ?>
>
<?php if(!isset($_['readonly']) || !$_['readonly']): ?><input type="checkbox" /><?php endif; ?>