diff --git a/common/framework/filters/filenamefilter.php b/common/framework/filters/filenamefilter.php index e0399feb8..8fc4a9027 100644 --- a/common/framework/filters/filenamefilter.php +++ b/common/framework/filters/filenamefilter.php @@ -97,7 +97,7 @@ class FilenameFilter */ public static function isDirectDownload($filename) { - if (preg_match('/\.(as[fx]|avi|flac|flv|gif|jpe?g|m4[av]|midi?|mkv|moov|mov|mp[1234]|mpe?g|ogg|png|qt|ram?|rmm?|wav|web[mp]|wm[av])$/i', $filename)) + if (preg_match('/\.(as[fx]|avi|flac|flv|gif|jpe?g|m4[av]|midi?|mkv|moov|mov|mp[1234]|mpe?g|og[gv]|png|qt|ram?|rmm?|wav|web[mp]|wm[av])$/i', $filename)) { return true; } diff --git a/common/framework/image.php b/common/framework/image.php index 9b8e5e342..e13c000b2 100644 --- a/common/framework/image.php +++ b/common/framework/image.php @@ -63,11 +63,20 @@ class Image { return false; } + $img_type = [ + IMG_GIF => 'gif', + IMG_JPG => 'jpg', + // jpeg is the same as jpg + IMG_PNG => 'png', + IMG_WEBP => 'webp', + IMG_WBMP => 'wbmp', + IMG_XPM => 'xpm', + (defined('IMG_BMP') ? IMG_BMP : 64) => 'bmp', + ]; return [ 'width' => $image_info[0], 'height' => $image_info[1], - 'type' => image_type_to_extension($image_info[2], false), - 'mime' => $image_info['mime'], + 'type' => $img_type[$image_info[2]], 'bits' => $image_info['bits'] ?? null, 'channels' => $image_info['channels'] ?? null, ]; diff --git a/common/framework/mime.php b/common/framework/mime.php index 7c033f6bb..6d5218655 100644 --- a/common/framework/mime.php +++ b/common/framework/mime.php @@ -16,7 +16,7 @@ class MIME public static function getTypeByExtension($extension) { $extension = strtolower($extension); - return array_key_exists($extension, self::$_types) ? self::$_types[$extension] : self::$_default; + return array_key_exists($extension, self::$_types) ? self::$_types[$extension][0] : self::$_default; } /** @@ -30,7 +30,7 @@ class MIME $extension = strrchr($filename, '.'); if ($extension === false) return self::$_default; $extension = strtolower(substr($extension, 1)); - return array_key_exists($extension, self::$_types) ? self::$_types[$extension] : self::$_default; + return array_key_exists($extension, self::$_types) ? self::$_types[$extension][0] : self::$_default; } /** @@ -41,9 +41,12 @@ class MIME */ public static function getExtensionByType($type) { - foreach (self::$_types as $extension => $mime) + foreach (self::$_types as $extension => $mimes) { - if (!strncasecmp($type, $mime, strlen($type))) return $extension; + foreach ($mimes as $mime) + { + if (!strncasecmp($type, $mime, strlen($type))) return $extension; + } } return false; } @@ -59,96 +62,106 @@ class MIME protected static $_types = array( // Text-based document formats. - 'html' => 'text/html', - 'htm' => 'text/html', - 'shtml' => 'text/html', - 'txt' => 'text/plain', - 'text' => 'text/plain', - 'log' => 'text/plain', - 'md' => 'text/markdown', - 'markdown' => 'text/markdown', - 'rtf' => 'text/rtf', - 'xml' => 'text/xml', - 'xsl' => 'text/xml', - 'css' => 'text/css', - 'csv' => 'text/csv', + 'html' => ['text/html'], + 'htm' => ['text/html'], + 'shtml' => ['text/html'], + 'txt' => ['text/plain'], + 'text' => ['text/plain'], + 'log' => ['text/plain'], + 'md' => ['text/markdown'], + 'markdown' => ['text/markdown'], + 'rtf' => ['text/rtf'], + 'xml' => ['text/xml'], + 'xsl' => ['text/xml'], + 'css' => ['text/css'], + 'csv' => ['text/csv'], // Binary document formats. - 'doc' => 'application/msword', - 'dot' => 'application/msword', - 'xls' => 'application/vnd.ms-excel', - 'ppt' => 'application/vnd.ms-powerpoint', - 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', - 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', - 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', - 'odt' => 'application/vnd.oasis.opendocument.text', - 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', - 'odp' => 'application/vnd.oasis.opendocument.presentation', - 'odg' => 'application/vnd.oasis.opendocument.graphics', - 'odb' => 'application/vnd.oasis.opendocument.database', - 'pdf' => 'application/pdf', + 'doc' => ['application/msword'], + 'dot' => ['application/msword'], + 'xls' => ['application/vnd.ms-excel'], + 'ppt' => ['application/vnd.ms-powerpoint'], + 'docx' => ['application/vnd.openxmlformats-officedocument.wordprocessingml.document'], + 'dotx' => ['application/vnd.openxmlformats-officedocument.wordprocessingml.document'], + 'xlsx' => ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'], + 'pptx' => ['application/vnd.openxmlformats-officedocument.presentationml.presentation'], + 'odt' => ['application/vnd.oasis.opendocument.text'], + 'ods' => ['application/vnd.oasis.opendocument.spreadsheet'], + 'odp' => ['application/vnd.oasis.opendocument.presentation'], + 'odg' => ['application/vnd.oasis.opendocument.graphics'], + 'odb' => ['application/vnd.oasis.opendocument.database'], + 'pdf' => ['application/pdf'], + 'dvi' => ['application/x-dvi'], // Images. - 'bmp' => 'image/bmp', - 'gif' => 'image/gif', - 'jpg' => 'image/jpeg', - 'jpeg' => 'image/jpeg', - 'jpe' => 'image/jpeg', - 'png' => 'image/png', - 'svg' => 'image/svg+xml', - 'tiff' => 'image/tiff', - 'tif' => 'image/tiff', - 'ico' => 'image/vnd.microsoft.icon', + 'bmp' => ['image/bmp'], + 'gif' => ['image/gif'], + 'jpg' => ['image/jpeg'], + 'jpeg' => ['image/jpeg'], + 'jpe' => ['image/jpeg'], + 'png' => ['image/png'], + 'webp' => ['image/webp'], + 'svg' => ['image/svg+xml'], + 'tiff' => ['image/tiff'], + 'tif' => ['image/tiff'], + 'ico' => ['image/x-icon'], // Audio. - 'mid' => 'audio/midi', - 'midi' => 'audio/midi', - 'mpga' => 'audio/mpeg', - 'mp2' => 'audio/mpeg', - 'mp3' => 'audio/mpeg', - 'aif' => 'audio/x-aiff', - 'aiff' => 'audio/x-aiff', - 'ra' => 'audio/x-realaudio', - 'wav' => 'audio/x-wav', - 'ogg' => 'audio/ogg', + 'mid' => ['audio/midi'], + 'midi' => ['audio/midi'], + 'mp3' => ['audio/mpeg'], + 'mpga' => ['audio/mpeg'], + 'mp2' => ['audio/mpeg'], + 'aif' => ['audio/x-aiff'], + 'aiff' => ['audio/x-aiff'], + 'ra' => ['audio/x-realaudio'], + 'wav' => ['audio/x-wav'], + 'ogg' => ['audio/ogg'], + 'm4a' => ['audio/x-m4a'], // Video. - 'avi' => 'video/x-msvideo', - 'flv' => 'video/x-flv', - 'mpeg' => 'video/mpeg', - 'mpg' => 'video/mpeg', - 'mpe' => 'video/mpeg', - 'mp4' => 'video/mpeg', - 'qt' => 'video/quicktime', - 'mov' => 'video/quicktime', - 'movie' => 'video/x-sgi-movie', - 'rv' => 'video/vnd.rn-realvideo', - 'dvi' => 'application/x-dvi', + 'avi' => ['video/x-msvideo'], + 'flv' => ['video/x-flv'], + 'mpg' => ['video/mpeg'], + 'mpeg' => ['video/mpeg'], + 'mpe' => ['video/mpeg'], + 'mp4' => ['video/mp4'], + 'webm' => ['video/webm'], + 'ogv' => ['video/ogg'], + 'mov' => ['video/quicktime'], + 'moov' => ['video/quicktime'], + 'qt' => ['video/quicktime'], + 'movie' => ['video/x-sgi-movie'], + 'rv' => ['video/vnd.rn-realvideo'], + 'mkv' => ['video/x-matroska'], + 'wmv' => ['video/x-ms-asf'], + 'wma' => ['video/x-ms-asf'], + 'asf' => ['video/x-ms-asf'], + 'm4v' => ['video/x-m4v'], // Other multimedia file formats. - 'psd' => 'application/x-photoshop', - 'swf' => 'application/x-shockwave-flash', - 'ai' => 'application/postscript', - 'eps' => 'application/postscript', - 'ps' => 'application/postscript', - 'mif' => 'application/vnd.mif', - 'xul' => 'application/vnd.mozilla.xul+xml', + 'psd' => ['application/x-photoshop'], + 'swf' => ['application/x-shockwave-flash'], + 'ai' => ['application/postscript'], + 'eps' => ['application/postscript'], + 'ps' => ['application/postscript'], + 'mif' => ['application/vnd.mif'], + 'xul' => ['application/vnd.mozilla.xul+xml'], // Source code formats. - 'phps' => 'application/x-httpd-php-source', - 'js' => 'application/x-javascript', + 'phps' => ['application/x-httpd-php-source'], + 'js' => ['application/x-javascript'], // Archives. - 'bz2' => 'application/x-bzip', - 'gz' => 'application/x-gzip', - 'tar' => 'application/x-tar', - 'tgz' => 'application/x-tar', - 'gtar' => 'application/x-gtar', - 'rar' => 'application/x-rar-compressed', - 'zip' => 'application/x-zip', + 'bz2' => ['application/x-bzip'], + 'gz' => ['application/x-gzip'], + 'tar' => ['application/x-tar'], + 'tgz' => ['application/x-tar'], + 'gtar' => ['application/x-gtar'], + 'rar' => ['application/x-rar-compressed'], + 'zip' => ['application/x-zip'], // RFC822 email message. - 'eml' => 'message/rfc822', + 'eml' => ['message/rfc822'], ); } diff --git a/common/js/plugins/jquery.fileupload/js/main.js b/common/js/plugins/jquery.fileupload/js/main.js index 6e3725823..2c2627210 100644 --- a/common/js/plugins/jquery.fileupload/js/main.js +++ b/common/js/plugins/jquery.fileupload/js/main.js @@ -154,10 +154,10 @@ if(/\.(jpe?g|png|gif|webp)$/i.test(result.source_filename)) { temp_code += '' + result.source_filename + ''; } - else if(/\.(mp3)$/i.test(result.source_filename)) { + else if(/\.(mp3|ogg|wav)$/i.test(result.source_filename)) { temp_code += '