From 9a4ba7b78150e68cc439d39f341defa46ddfd552 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Tue, 20 Oct 2015 16:22:08 +0000 Subject: [PATCH] * Etemplate: Fix issue expose view gets opened for not supported mime-type (eg. image/pdf) --- etemplate/js/et2_widget_link.js | 2 +- etemplate/js/et2_widget_vfs.js | 2 +- etemplate/js/expose.js | 5 ++++- phpgwapi/inc/class.html.inc.php | 3 +++ phpgwapi/inc/class.mime_magic.inc.php | 18 ++++++++++++++++++ 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/etemplate/js/et2_widget_link.js b/etemplate/js/et2_widget_link.js index 1f735d81db..d62643f143 100644 --- a/etemplate/js/et2_widget_link.js +++ b/etemplate/js/et2_widget_link.js @@ -1360,7 +1360,7 @@ var et2_link_string = expose(et2_valueWidget.extend([et2_IDetachedDOM], { var base_url = egw.webserverUrl.match(/^\//,'ig')?egw(window).window.location.origin + egw.webserverUrl : egw.webserverUrl; var mediaContent = []; - if (_value && typeof _value.type !='undefined' && _value.type.match(/video\/|audio\//,'ig')) + if (_value && typeof _value.type !='undefined' && _value.type.match(/video\//,'ig')) { mediaContent = [{ title: _value.id, diff --git a/etemplate/js/et2_widget_vfs.js b/etemplate/js/et2_widget_vfs.js index 24939359f1..45988d96ce 100644 --- a/etemplate/js/et2_widget_vfs.js +++ b/etemplate/js/et2_widget_vfs.js @@ -345,7 +345,7 @@ var et2_vfsMime = expose(et2_valueWidget.extend([et2_IDetachedDOM], mediaContent[0].download_href = mediaContent[0].href + '?download'; } } - if (_value && _value.mime && _value.mime.match(/video\/|audio\//,'ig')) + if (_value && _value.mime && _value.mime.match(/video\//,'ig')) { mediaContent[0].thumbnail = this.egw().mime_icon(_value.mime, _value.path, undefined, _value.mtime); } diff --git a/etemplate/js/expose.js b/etemplate/js/expose.js index 2f5d7b599b..914042b35e 100644 --- a/etemplate/js/expose.js +++ b/etemplate/js/expose.js @@ -48,7 +48,10 @@ function expose (widget) }; // For filtering to only show things we can handle - var mime_regex = new RegExp(/(video\/)|(image\/:*(?!tif|x-xcf))|(audio\/)/); + var mime_regex = new RegExp(/(video\/(mp4|ogg|webm))|(image\/:*(?!tif|x-xcf|pdf))/); + + // IE only supports video/mp4 mime type + if (navigator.userAgent.match(/(MSIE|Trident)/)) mime_regex.compile(/(video\/mp4)|(image\/:*(?!tif|x-xcf|pdf))/); // Only one gallery var gallery = null; diff --git a/phpgwapi/inc/class.html.inc.php b/phpgwapi/inc/class.html.inc.php index 586d5fe8f5..7704c18947 100644 --- a/phpgwapi/inc/class.html.inc.php +++ b/phpgwapi/inc/class.html.inc.php @@ -1515,6 +1515,9 @@ egw_LAB.wait(function() { */ public static function safe_content_header(&$content, $path, &$mime='', &$length=0, $nocache=true, $force_download=true, $no_content_type=false) { + // change old/aliased mime-types to new one, eg. image/pdf to application/pdf + $mime = mime_magic::fix_mime_type($mime); + // mitigate risk of serving javascript or css via webdav from our domain, // which will get around same origin policy and CSP list($type, $subtype) = explode('/', strtolower($mime)); diff --git a/phpgwapi/inc/class.mime_magic.inc.php b/phpgwapi/inc/class.mime_magic.inc.php index 945d6c12c3..127f0ee645 100644 --- a/phpgwapi/inc/class.mime_magic.inc.php +++ b/phpgwapi/inc/class.mime_magic.inc.php @@ -123,6 +123,23 @@ class mime_magic return $key; } + /** + * Fix old / aliased mime-types by returning valid/default mime-type + * + * @param string $_alias + * @return string new type, of $alias, if there is no alias defined for it + */ + public static function fix_mime_type($_alias) + { + $alias = strtolower($_alias); + + if (isset(self::$mime_alias_map[$alias])) + { + return self::$mime_alias_map[$alias]; + } + return $alias; + } + /** * Uses variants of the UNIX "file" command to attempt to determine the * MIME type of an unknown file. @@ -1671,6 +1688,7 @@ class mime_magic 'application/x-javascript' => 'application/javascript', 'application/x-troff' => 'text/troff', 'application/x-egroupware-etemplate' => 'application/xml', + 'image/pdf' => 'application/pdf', ); /**