From 609a91a9b1bbee423a6bda2420dc4010b46757f6 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 19 Feb 2014 14:47:29 +0100 Subject: [PATCH 1/5] Show svg mime icons when no preview is available --- apps/files/js/filelist.js | 10 +++++----- apps/files/js/files.js | 9 +++++++-- apps/files/lib/helper.php | 14 ++++++++------ core/ajax/preview.php | 30 +++++++++++++++++------------- 4 files changed, 37 insertions(+), 26 deletions(-) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index a855d6cbe5..b2de0161aa 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -129,7 +129,7 @@ window.FileList={ if (loading) { imgurl = OC.imagePath('core', 'loading.gif'); } else { - imgurl = OC.imagePath('core', 'filetypes/file.png'); + imgurl = OC.imagePath('core', 'filetypes/file'); } var tr = this.createRow( 'file', @@ -157,7 +157,7 @@ window.FileList={ var tr = this.createRow( 'dir', name, - OC.imagePath('core', 'filetypes/folder.png'), + OC.imagePath('core', 'filetypes/folder'), OC.linkTo('files', 'index.php')+"?dir="+ encodeURIComponent($('#dir').val()+'/'+name).replace(/%2F/g, '/'), size, lastModified, @@ -907,7 +907,7 @@ $(document).ready(function() { uploadtext.attr('currentUploads', currentUploads); var translatedText = n('files', 'Uploading %n file', 'Uploading %n files', currentUploads); if (currentUploads === 0) { - var img = OC.imagePath('core', 'filetypes/folder.png'); + var img = OC.imagePath('core', 'filetypes/folder'); data.context.find('td.filename').attr('style','background-image:url('+img+')'); uploadtext.text(translatedText); uploadtext.hide(); @@ -967,7 +967,7 @@ $(document).ready(function() { if (data.errorThrown === 'abort') { //cleanup uploading to a dir var uploadtext = $('tr .uploadtext'); - var img = OC.imagePath('core', 'filetypes/folder.png'); + var img = OC.imagePath('core', 'filetypes/folder'); uploadtext.parents('td.filename').attr('style','background-image:url('+img+')'); uploadtext.fadeOut(); uploadtext.attr('currentUploads', 0); @@ -980,7 +980,7 @@ $(document).ready(function() { if (data.errorThrown === 'abort') { //cleanup uploading to a dir var uploadtext = $('tr .uploadtext'); - var img = OC.imagePath('core', 'filetypes/folder.png'); + var img = OC.imagePath('core', 'filetypes/folder'); uploadtext.parents('td.filename').attr('style','background-image:url('+img+')'); uploadtext.fadeOut(); uploadtext.attr('currentUploads', 0); diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 1ec4c4ec7a..dab060229e 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -731,6 +731,9 @@ Files.getMimeIcon = function(mime, ready) { ready(Files.getMimeIcon.cache[mime]); } else { $.get( OC.filePath('files','ajax','mimeicon.php'), {mime: mime}, function(path) { + if(SVGSupport()){ + path = path.substr(0, path.length-4) + '.svg'; + } Files.getMimeIcon.cache[mime]=path; ready(Files.getMimeIcon.cache[mime]); }); @@ -785,8 +788,10 @@ Files.lazyLoadPreview = function(path, mime, ready, width, height, etag) { // this will make the browser cache the image var img = new Image(); img.onload = function(){ - //set preview thumbnail URL - ready(previewURL); + // if loading the preview image failed (no preview for the mimetype) then img.width will < 5 + if (img.width > 5) { + ready(previewURL); + } } img.src = previewURL; }); diff --git a/apps/files/lib/helper.php b/apps/files/lib/helper.php index ac8a2ad320..fec1297b18 100644 --- a/apps/files/lib/helper.php +++ b/apps/files/lib/helper.php @@ -36,14 +36,16 @@ class Helper } } } - return \OC_Helper::mimetypeIcon('dir'); + $icon = \OC_Helper::mimetypeIcon('dir'); + }else{ + if($file['isPreviewAvailable']) { + $pathForPreview = $file['directory'] . '/' . $file['name']; + return \OC_Helper::previewIcon($pathForPreview) . '&c=' . $file['etag']; + } + $icon = \OC_Helper::mimetypeIcon($file['mimetype']); } - if($file['isPreviewAvailable']) { - $pathForPreview = $file['directory'] . '/' . $file['name']; - return \OC_Helper::previewIcon($pathForPreview) . '&c=' . $file['etag']; - } - return \OC_Helper::mimetypeIcon($file['mimetype']); + return substr($icon, 0, -3) . 'svg'; } /** diff --git a/core/ajax/preview.php b/core/ajax/preview.php index a1267d6f5c..5c6d5ce25a 100644 --- a/core/ajax/preview.php +++ b/core/ajax/preview.php @@ -7,34 +7,38 @@ */ \OC_Util::checkLoggedIn(); -$file = array_key_exists('file', $_GET) ? (string) $_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; +$file = array_key_exists('file', $_GET) ? (string)$_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; -if($file === '') { +if ($file === '') { //400 Bad Request \OC_Response::setStatus(400); \OC_Log::write('core-preview', 'No file parameter was passed', \OC_Log::DEBUG); exit; } -if($maxX === 0 || $maxY === 0) { +if ($maxX === 0 || $maxY === 0) { //400 Bad Request \OC_Response::setStatus(400); \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG); exit; } -try{ +try { $preview = new \OC\Preview(\OC_User::getUser(), 'files'); - $preview->setFile($file); - $preview->setMaxX($maxX); - $preview->setMaxY($maxY); - $preview->setScalingUp($scalingUp); + if (!$preview->isMimeSupported(\OC\Files\Filesystem::getMimeType($file))) { + \OC_Response::setStatus(404); + } else { + $preview->setFile($file); + $preview->setMaxX($maxX); + $preview->setMaxY($maxY); + $preview->setScalingUp($scalingUp); + } $preview->show(); -}catch(\Exception $e) { +} catch (\Exception $e) { \OC_Response::setStatus(500); \OC_Log::write('core', $e->getmessage(), \OC_Log::DEBUG); -} \ No newline at end of file +} From f33d35cd073addb08c78a65b719c72eb5424434a Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 19 Feb 2014 15:08:05 +0100 Subject: [PATCH 2/5] Fix svg icons for public shares and external/shared files --- apps/files/lib/helper.php | 6 +++--- apps/files_sharing/public.php | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/files/lib/helper.php b/apps/files/lib/helper.php index fec1297b18..b9e41a352b 100644 --- a/apps/files/lib/helper.php +++ b/apps/files/lib/helper.php @@ -22,6 +22,7 @@ class Helper public static function determineIcon($file) { if($file['type'] === 'dir') { $dir = $file['directory']; + $icon = \OC_Helper::mimetypeIcon('dir'); $absPath = \OC\Files\Filesystem::getView()->getAbsolutePath($dir.'/'.$file['name']); $mount = \OC\Files\Filesystem::getMountManager()->find($absPath); if (!is_null($mount)) { @@ -29,14 +30,13 @@ class Helper if (!is_null($sid)) { $sid = explode(':', $sid); if ($sid[0] === 'shared') { - return \OC_Helper::mimetypeIcon('dir-shared'); + $icon = \OC_Helper::mimetypeIcon('dir-shared'); } if ($sid[0] !== 'local' and $sid[0] !== 'home') { - return \OC_Helper::mimetypeIcon('dir-external'); + $icon = \OC_Helper::mimetypeIcon('dir-external'); } } } - $icon = \OC_Helper::mimetypeIcon('dir'); }else{ if($file['isPreviewAvailable']) { $pathForPreview = $file['directory'] . '/' . $file['name']; diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php index e7a5f5024b..fe61dd4d5a 100644 --- a/apps/files_sharing/public.php +++ b/apps/files_sharing/public.php @@ -32,7 +32,8 @@ function determineIcon($file, $sharingRoot, $sharingToken) { if($file['isPreviewAvailable']) { return OCP\publicPreview_icon($relativePath, $sharingToken) . '&c=' . $file['etag']; } - return OCP\mimetype_icon($file['mimetype']); + $icon = OCP\mimetype_icon($file['mimetype']); + return substr($icon, 0, -3) . 'svg'; } if (isset($_GET['t'])) { From f710205ee766cb2c12cf21d28cd5295d9fff432c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 20 Feb 2014 16:56:09 +0100 Subject: [PATCH 3/5] Make unit tests expect the svg icons --- apps/files/tests/ajax_rename.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/files/tests/ajax_rename.php b/apps/files/tests/ajax_rename.php index a1a5c8983b..e53c0fb3dd 100644 --- a/apps/files/tests/ajax_rename.php +++ b/apps/files/tests/ajax_rename.php @@ -110,7 +110,9 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase { $this->assertEquals('/test', $result['data']['directory']); $this->assertEquals(18, $result['data']['size']); $this->assertEquals('httpd/unix-directory', $result['data']['mime']); - $this->assertEquals(\OC_Helper::mimetypeIcon('dir'), $result['data']['icon']); + $icon = \OC_Helper::mimetypeIcon('dir'); + $icon = substr($icon, 0, -3) . 'svg'; + $this->assertEquals($icon, $result['data']['icon']); $this->assertFalse($result['data']['isPreviewAvailable']); } @@ -165,7 +167,9 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase { $this->assertEquals(18, $result['data']['size']); $this->assertEquals('httpd/unix-directory', $result['data']['mime']); $this->assertEquals('abcdef', $result['data']['etag']); - $this->assertEquals(\OC_Helper::mimetypeIcon('dir'), $result['data']['icon']); + $icon = \OC_Helper::mimetypeIcon('dir'); + $icon = substr($icon, 0, -3) . 'svg'; + $this->assertEquals($icon, $result['data']['icon']); $this->assertFalse($result['data']['isPreviewAvailable']); } From 4715fb12c8001b8642c2e6dcef57ac216ef92c3d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 21 Feb 2014 14:06:15 +0100 Subject: [PATCH 4/5] Add url parameter to control whether previews should return 404 when the mimetype is unsupported --- apps/files/js/files.js | 1 + core/ajax/preview.php | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 8b252e69a1..1f4bd6794f 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -786,6 +786,7 @@ Files.lazyLoadPreview = function(path, mime, ready, width, height, etag) { } previewURL = previewURL.replace('(', '%28'); previewURL = previewURL.replace(')', '%29'); + previewURL += '&always=0'; // preload image to prevent delay // this will make the browser cache the image diff --git a/core/ajax/preview.php b/core/ajax/preview.php index 5c6d5ce25a..285af3a8a7 100644 --- a/core/ajax/preview.php +++ b/core/ajax/preview.php @@ -11,6 +11,7 @@ $file = array_key_exists('file', $_GET) ? (string)$_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; +$always = array_key_exists('always', $_GET) ? (bool)$_GET['always'] : true; if ($file === '') { //400 Bad Request @@ -28,7 +29,7 @@ if ($maxX === 0 || $maxY === 0) { try { $preview = new \OC\Preview(\OC_User::getUser(), 'files'); - if (!$preview->isMimeSupported(\OC\Files\Filesystem::getMimeType($file))) { + if (!$always and !$preview->isMimeSupported(\OC\Files\Filesystem::getMimeType($file))) { \OC_Response::setStatus(404); } else { $preview->setFile($file); From 7c4f81bd78b0933928056f6f59020837e1291525 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 24 Feb 2014 13:24:10 +0100 Subject: [PATCH 5/5] rename url parameter --- apps/files/js/files.js | 2 +- core/ajax/preview.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 1f4bd6794f..f454612070 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -786,7 +786,7 @@ Files.lazyLoadPreview = function(path, mime, ready, width, height, etag) { } previewURL = previewURL.replace('(', '%28'); previewURL = previewURL.replace(')', '%29'); - previewURL += '&always=0'; + previewURL += '&forceIcon=0'; // preload image to prevent delay // this will make the browser cache the image diff --git a/core/ajax/preview.php b/core/ajax/preview.php index 285af3a8a7..526719e8a1 100644 --- a/core/ajax/preview.php +++ b/core/ajax/preview.php @@ -11,7 +11,7 @@ $file = array_key_exists('file', $_GET) ? (string)$_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; -$always = array_key_exists('always', $_GET) ? (bool)$_GET['always'] : true; +$always = array_key_exists('forceIcon', $_GET) ? (bool)$_GET['forceIcon'] : true; if ($file === '') { //400 Bad Request