Merge pull request #7285 from owncloud/mimeicons-svg
Show svg mime icons when no preview is available
This commit is contained in:
commit
5fb1374b0f
|
@ -145,7 +145,7 @@ window.FileList={
|
||||||
if (loading) {
|
if (loading) {
|
||||||
imgurl = OC.imagePath('core', 'loading.gif');
|
imgurl = OC.imagePath('core', 'loading.gif');
|
||||||
} else {
|
} else {
|
||||||
imgurl = OC.imagePath('core', 'filetypes/file.png');
|
imgurl = OC.imagePath('core', 'filetypes/file');
|
||||||
}
|
}
|
||||||
var tr = this.createRow(
|
var tr = this.createRow(
|
||||||
'file',
|
'file',
|
||||||
|
@ -173,7 +173,7 @@ window.FileList={
|
||||||
var tr = this.createRow(
|
var tr = this.createRow(
|
||||||
'dir',
|
'dir',
|
||||||
name,
|
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, '/'),
|
OC.linkTo('files', 'index.php')+"?dir="+ encodeURIComponent($('#dir').val()+'/'+name).replace(/%2F/g, '/'),
|
||||||
size,
|
size,
|
||||||
lastModified,
|
lastModified,
|
||||||
|
@ -969,7 +969,7 @@ $(document).ready(function() {
|
||||||
uploadtext.attr('currentUploads', currentUploads);
|
uploadtext.attr('currentUploads', currentUploads);
|
||||||
var translatedText = n('files', 'Uploading %n file', 'Uploading %n files', currentUploads);
|
var translatedText = n('files', 'Uploading %n file', 'Uploading %n files', currentUploads);
|
||||||
if (currentUploads === 0) {
|
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+')');
|
data.context.find('td.filename').attr('style','background-image:url('+img+')');
|
||||||
uploadtext.text(translatedText);
|
uploadtext.text(translatedText);
|
||||||
uploadtext.hide();
|
uploadtext.hide();
|
||||||
|
@ -1029,7 +1029,7 @@ $(document).ready(function() {
|
||||||
if (data.errorThrown === 'abort') {
|
if (data.errorThrown === 'abort') {
|
||||||
//cleanup uploading to a dir
|
//cleanup uploading to a dir
|
||||||
var uploadtext = $('tr .uploadtext');
|
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.parents('td.filename').attr('style','background-image:url('+img+')');
|
||||||
uploadtext.fadeOut();
|
uploadtext.fadeOut();
|
||||||
uploadtext.attr('currentUploads', 0);
|
uploadtext.attr('currentUploads', 0);
|
||||||
|
@ -1042,7 +1042,7 @@ $(document).ready(function() {
|
||||||
if (data.errorThrown === 'abort') {
|
if (data.errorThrown === 'abort') {
|
||||||
//cleanup uploading to a dir
|
//cleanup uploading to a dir
|
||||||
var uploadtext = $('tr .uploadtext');
|
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.parents('td.filename').attr('style','background-image:url('+img+')');
|
||||||
uploadtext.fadeOut();
|
uploadtext.fadeOut();
|
||||||
uploadtext.attr('currentUploads', 0);
|
uploadtext.attr('currentUploads', 0);
|
||||||
|
|
|
@ -734,6 +734,9 @@ Files.getMimeIcon = function(mime, ready) {
|
||||||
ready(Files.getMimeIcon.cache[mime]);
|
ready(Files.getMimeIcon.cache[mime]);
|
||||||
} else {
|
} else {
|
||||||
$.get( OC.filePath('files','ajax','mimeicon.php'), {mime: mime}, function(path) {
|
$.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;
|
Files.getMimeIcon.cache[mime]=path;
|
||||||
ready(Files.getMimeIcon.cache[mime]);
|
ready(Files.getMimeIcon.cache[mime]);
|
||||||
});
|
});
|
||||||
|
@ -783,14 +786,17 @@ Files.lazyLoadPreview = function(path, mime, ready, width, height, etag) {
|
||||||
}
|
}
|
||||||
previewURL = previewURL.replace('(', '%28');
|
previewURL = previewURL.replace('(', '%28');
|
||||||
previewURL = previewURL.replace(')', '%29');
|
previewURL = previewURL.replace(')', '%29');
|
||||||
|
previewURL += '&forceIcon=0';
|
||||||
|
|
||||||
// preload image to prevent delay
|
// preload image to prevent delay
|
||||||
// this will make the browser cache the image
|
// this will make the browser cache the image
|
||||||
var img = new Image();
|
var img = new Image();
|
||||||
img.onload = function(){
|
img.onload = function(){
|
||||||
//set preview thumbnail URL
|
// if loading the preview image failed (no preview for the mimetype) then img.width will < 5
|
||||||
|
if (img.width > 5) {
|
||||||
ready(previewURL);
|
ready(previewURL);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
img.src = previewURL;
|
img.src = previewURL;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,6 +22,7 @@ class Helper
|
||||||
public static function determineIcon($file) {
|
public static function determineIcon($file) {
|
||||||
if($file['type'] === 'dir') {
|
if($file['type'] === 'dir') {
|
||||||
$dir = $file['directory'];
|
$dir = $file['directory'];
|
||||||
|
$icon = \OC_Helper::mimetypeIcon('dir');
|
||||||
$absPath = \OC\Files\Filesystem::getView()->getAbsolutePath($dir.'/'.$file['name']);
|
$absPath = \OC\Files\Filesystem::getView()->getAbsolutePath($dir.'/'.$file['name']);
|
||||||
$mount = \OC\Files\Filesystem::getMountManager()->find($absPath);
|
$mount = \OC\Files\Filesystem::getMountManager()->find($absPath);
|
||||||
if (!is_null($mount)) {
|
if (!is_null($mount)) {
|
||||||
|
@ -29,21 +30,22 @@ class Helper
|
||||||
if (!is_null($sid)) {
|
if (!is_null($sid)) {
|
||||||
$sid = explode(':', $sid);
|
$sid = explode(':', $sid);
|
||||||
if ($sid[0] === 'shared') {
|
if ($sid[0] === 'shared') {
|
||||||
return \OC_Helper::mimetypeIcon('dir-shared');
|
$icon = \OC_Helper::mimetypeIcon('dir-shared');
|
||||||
}
|
}
|
||||||
if ($sid[0] !== 'local' and $sid[0] !== 'home') {
|
if ($sid[0] !== 'local' and $sid[0] !== 'home') {
|
||||||
return \OC_Helper::mimetypeIcon('dir-external');
|
$icon = \OC_Helper::mimetypeIcon('dir-external');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return \OC_Helper::mimetypeIcon('dir');
|
}else{
|
||||||
}
|
|
||||||
|
|
||||||
if($file['isPreviewAvailable']) {
|
if($file['isPreviewAvailable']) {
|
||||||
$pathForPreview = $file['directory'] . '/' . $file['name'];
|
$pathForPreview = $file['directory'] . '/' . $file['name'];
|
||||||
return \OC_Helper::previewIcon($pathForPreview) . '&c=' . $file['etag'];
|
return \OC_Helper::previewIcon($pathForPreview) . '&c=' . $file['etag'];
|
||||||
}
|
}
|
||||||
return \OC_Helper::mimetypeIcon($file['mimetype']);
|
$icon = \OC_Helper::mimetypeIcon($file['mimetype']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return substr($icon, 0, -3) . 'svg';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -110,7 +110,9 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase {
|
||||||
$this->assertEquals('/test', $result['data']['directory']);
|
$this->assertEquals('/test', $result['data']['directory']);
|
||||||
$this->assertEquals(18, $result['data']['size']);
|
$this->assertEquals(18, $result['data']['size']);
|
||||||
$this->assertEquals('httpd/unix-directory', $result['data']['mime']);
|
$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']);
|
$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(18, $result['data']['size']);
|
||||||
$this->assertEquals('httpd/unix-directory', $result['data']['mime']);
|
$this->assertEquals('httpd/unix-directory', $result['data']['mime']);
|
||||||
$this->assertEquals('abcdef', $result['data']['etag']);
|
$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']);
|
$this->assertFalse($result['data']['isPreviewAvailable']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,8 @@ function determineIcon($file, $sharingRoot, $sharingToken) {
|
||||||
if($file['isPreviewAvailable']) {
|
if($file['isPreviewAvailable']) {
|
||||||
return OCP\publicPreview_icon($relativePath, $sharingToken) . '&c=' . $file['etag'];
|
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'])) {
|
if (isset($_GET['t'])) {
|
||||||
|
|
|
@ -11,6 +11,7 @@ $file = array_key_exists('file', $_GET) ? (string) $_GET['file'] : '';
|
||||||
$maxX = array_key_exists('x', $_GET) ? (int)$_GET['x'] : '36';
|
$maxX = array_key_exists('x', $_GET) ? (int)$_GET['x'] : '36';
|
||||||
$maxY = array_key_exists('y', $_GET) ? (int)$_GET['y'] : '36';
|
$maxY = array_key_exists('y', $_GET) ? (int)$_GET['y'] : '36';
|
||||||
$scalingUp = array_key_exists('scalingup', $_GET) ? (bool)$_GET['scalingup'] : true;
|
$scalingUp = array_key_exists('scalingup', $_GET) ? (bool)$_GET['scalingup'] : true;
|
||||||
|
$always = array_key_exists('forceIcon', $_GET) ? (bool)$_GET['forceIcon'] : true;
|
||||||
|
|
||||||
if ($file === '') {
|
if ($file === '') {
|
||||||
//400 Bad Request
|
//400 Bad Request
|
||||||
|
@ -28,10 +29,14 @@ if($maxX === 0 || $maxY === 0) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$preview = new \OC\Preview(\OC_User::getUser(), 'files');
|
$preview = new \OC\Preview(\OC_User::getUser(), 'files');
|
||||||
|
if (!$always and !$preview->isMimeSupported(\OC\Files\Filesystem::getMimeType($file))) {
|
||||||
|
\OC_Response::setStatus(404);
|
||||||
|
} else {
|
||||||
$preview->setFile($file);
|
$preview->setFile($file);
|
||||||
$preview->setMaxX($maxX);
|
$preview->setMaxX($maxX);
|
||||||
$preview->setMaxY($maxY);
|
$preview->setMaxY($maxY);
|
||||||
$preview->setScalingUp($scalingUp);
|
$preview->setScalingUp($scalingUp);
|
||||||
|
}
|
||||||
|
|
||||||
$preview->show();
|
$preview->show();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|
Loading…
Reference in New Issue