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 += '';
}
- else if(/\.(mp3)$/i.test(result.source_filename)) {
+ else if(/\.(mp3|ogg|wav)$/i.test(result.source_filename)) {
temp_code += '';
}
- else if(/\.(mp4|webm|ogg)$/i.test(result.source_filename)) {
+ else if(/\.(mp4|webm|ogv)$/i.test(result.source_filename)) {
if(result.original_type === 'image/gif') {
temp_code += '';
} else {
@@ -326,10 +326,10 @@
if(/\.(jpe?g|png|gif|webp)$/i.test(result.source_filename)) {
temp_code += '
';
}
- else if(/\.(mp3)$/i.test(result.source_filename)) {
+ else if(/\.(mp3|ogg|wav)$/i.test(result.source_filename)) {
temp_code += '';
}
- else if(/\.(mp4|webm|ogg)$/i.test(result.source_filename)) {
+ else if(/\.(mp4|webm|ogv)$/i.test(result.source_filename)) {
if(result.original_type === 'image/gif') {
temp_code += '';
} else {
@@ -343,7 +343,7 @@
}
}
if(temp_code === '') {
- temp_code += '' + fileinfo.source_filename + "\n";
+ temp_code += '' + result.source_filename + "\n";
}
_getCkeInstance(data.editorSequence).insertHtml(temp_code, "unfiltered_html");
});
@@ -437,7 +437,7 @@
file.source_filename = file.source_filename.replace("&", "&");
if(file.thumbnail_filename) {
file.download_url = file.thumbnail_filename;
- if(/\.(mp4|webm|ogg)$/i.test(file.source_filename)) {
+ if(/\.(mp4|webm|ogv)$/i.test(file.source_filename)) {
result_image.push(template_fileimte_video(file));
} else {
result_image.push(template_fileimte_image(file));
diff --git a/modules/file/file.controller.php b/modules/file/file.controller.php
index 8f1d4e3a6..90bff8af2 100644
--- a/modules/file/file.controller.php
+++ b/modules/file/file.controller.php
@@ -884,17 +884,13 @@ class fileController extends file
$file_info['converted'] = false;
// Correct extension
- if($extension_by_type = Rhymix\Framework\MIME::getExtensionByType($file_info['type']))
+ if($file_info['extension'])
{
- $target_types = ['image', 'audio', 'video'];
- if(in_array(array_shift(explode('/', $file_info['type'])), $target_types))
+ $type_by_extension = Rhymix\Framework\MIME::getTypeByExtension($file_info['extension']);
+ if(!in_array($type_by_extension, [$file_info['type'], 'application/octet-stream']))
{
- $file_info['extension'] = $extension_by_type;
- }
- elseif($file_info['extension'])
- {
- $type_by_extension = Rhymix\Framework\MIME::getTypeByExtension($file_info['extension']);
- if(in_array(array_shift(explode('/', $type_by_extension)), $target_types))
+ $extension_by_type = Rhymix\Framework\MIME::getExtensionByType($file_info['type']);
+ if($extension_by_type && preg_match('@^(?:image|audio|video)/@m', $file_info['type'] . PHP_EOL . $type_by_extension))
{
$file_info['extension'] = $extension_by_type;
}
@@ -924,7 +920,7 @@ class fileController extends file
}
// video
- if(in_array($file_info['extension'], ['mp4', 'webm', 'ogg']))
+ if(in_array($file_info['extension'], ['mp4', 'webm', 'ogv']))
{
$file_info = $this->adjustUploadedVideo($file_info, $config);
}
@@ -1123,7 +1119,7 @@ class fileController extends file
}
// Adjust image rotation
- if ($config->image_autorotate && in_array($image_info['type'], ['jpg', 'jpeg']) && function_exists('exif_read_data'))
+ if ($config->image_autorotate && $image_info['type'] === 'jpg' && function_exists('exif_read_data'))
{
$exif = @exif_read_data($file_info['tmp_name']);
if($exif && isset($exif['Orientation']))
diff --git a/modules/file/lang/en.php b/modules/file/lang/en.php
index 601c81aa6..f2a732050 100644
--- a/modules/file/lang/en.php
+++ b/modules/file/lang/en.php
@@ -98,4 +98,5 @@ $lang->video_mp4_gif_time = 'Treat as GIF';
$lang->about_video_mp4_gif_time = 'treat silent MP4 videos with duration less than the set time as GIF images, and play with auto and loop.';
$lang->ffmpeg_path = 'FFmpeg path';
$lang->ffprobe_path = 'FFprobe path';
-$lang->msg_cannot_use_ffmpeg = 'FFmpeg and FFprobe must can be executed by PHP';
+$lang->msg_cannot_use_ffmpeg = 'FFmpeg and FFprobe must can be executed by PHP.';
+$lang->msg_cannot_use_exif = 'PHP Exif module is required.';
\ No newline at end of file
diff --git a/modules/file/lang/ko.php b/modules/file/lang/ko.php
index 1f5836dac..e92014d13 100644
--- a/modules/file/lang/ko.php
+++ b/modules/file/lang/ko.php
@@ -100,3 +100,4 @@ $lang->about_video_mp4_gif_time = '설정된 시간 이하의 길이를 가진
$lang->ffmpeg_path = 'FFmpeg 경로';
$lang->ffprobe_path = 'FFprobe 경로';
$lang->msg_cannot_use_ffmpeg = 'PHP에서 FFmpeg 및 FFprobe를 실행할 수 있어야 합니다.';
+$lang->msg_cannot_use_exif = 'PHP Exif 모듈이 필요합니다.';
diff --git a/modules/file/tpl/file_module_config.html b/modules/file/tpl/file_module_config.html
index 6b08438d6..180042f6a 100644
--- a/modules/file/tpl/file_module_config.html
+++ b/modules/file/tpl/file_module_config.html
@@ -112,6 +112,7 @@
{$lang->cmd_no}
{$lang->about_image_autorotate}
+{$lang->msg_cannot_use_exif}
{$lang->about_image_autorotate}
+{$lang->msg_cannot_use_exif}