mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-07 02:31:40 +09:00
파일이나 확장자가 이미지, 오디오, 동영상이며, MIME 타입이 전혀 다른 경우에만 확장자를 고치도록 수정
direct가 아닌 첨부파일 본문 삽입시의 오류 수정 이미지, 오디오, 동영상 MIME 타입을 mime_content_type()의 반환값으로 수정
This commit is contained in:
parent
ac9141b4f2
commit
6db830c4c4
9 changed files with 122 additions and 100 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -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'],
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -154,10 +154,10 @@
|
|||
if(/\.(jpe?g|png|gif|webp)$/i.test(result.source_filename)) {
|
||||
temp_code += '<img src="' + result.download_url + '" alt="' + result.source_filename + '" editor_component="image_link" data-file-srl="' + result.file_srl + '" />';
|
||||
}
|
||||
else if(/\.(mp3)$/i.test(result.source_filename)) {
|
||||
else if(/\.(mp3|ogg|wav)$/i.test(result.source_filename)) {
|
||||
temp_code += '<audio src="' + result.download_url + '" controls data-file-srl="' + result.file_srl + '" />';
|
||||
}
|
||||
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 += '<video src="' + result.download_url + '" autoplay loop muted data-file-srl="' + result.file_srl + '" />';
|
||||
} else {
|
||||
|
|
@ -326,10 +326,10 @@
|
|||
if(/\.(jpe?g|png|gif|webp)$/i.test(result.source_filename)) {
|
||||
temp_code += '<img src="' + result.download_url + '" alt="' + result.source_filename + '" editor_component="image_link" data-file-srl="' + result.file_srl + '" />';
|
||||
}
|
||||
else if(/\.(mp3)$/i.test(result.source_filename)) {
|
||||
else if(/\.(mp3|ogg|wav)$/i.test(result.source_filename)) {
|
||||
temp_code += '<audio src="' + result.download_url + '" controls data-file-srl="' + result.file_srl + '" />';
|
||||
}
|
||||
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 += '<video src="' + result.download_url + '" autoplay loop muted data-file-srl="' + result.file_srl + '" />';
|
||||
} else {
|
||||
|
|
@ -343,7 +343,7 @@
|
|||
}
|
||||
}
|
||||
if(temp_code === '') {
|
||||
temp_code += '<a href="' + fileinfo.download_url + '" data-file-srl="' + fileinfo.file_srl + '">' + fileinfo.source_filename + "</a>\n";
|
||||
temp_code += '<a href="' + result.download_url + '" data-file-srl="' + result.file_srl + '">' + result.source_filename + "</a>\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));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue