From c40a47724d15f35885a6343d6251c40e60600f48 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 1 Aug 2019 15:57:05 +0900 Subject: [PATCH] Simplify allowed_filetypes input format --- .../js/plugins/jquery.fileupload/js/main.js | 4 +-- modules/file/file.admin.controller.php | 34 +++++++++++++++++-- modules/file/file.class.php | 1 + modules/file/file.controller.php | 11 ++---- modules/file/file.model.php | 20 +++++++++++ modules/file/lang/en.php | 2 +- modules/file/lang/ko.php | 2 +- modules/file/ruleset/fileModuleConfig.xml | 4 --- modules/file/ruleset/insertConfig.xml | 4 --- modules/file/tpl/file_module_config.html | 2 +- modules/file/tpl/upload_config.html | 2 +- 11 files changed, 61 insertions(+), 25 deletions(-) diff --git a/common/js/plugins/jquery.fileupload/js/main.js b/common/js/plugins/jquery.fileupload/js/main.js index 696ab7569..83b0d71ee 100644 --- a/common/js/plugins/jquery.fileupload/js/main.js +++ b/common/js/plugins/jquery.fileupload/js/main.js @@ -372,12 +372,12 @@ data.uploadTargetSrl = res.uploadTargetSrl; // @TODO 정리 - $container.find('.allowed_filetypes').text(res.allowed_filetypes); + $container.find('.allowed_filetypes').text(res.allowed_extensions.join(', ')); $container.find('.allowed_filesize').text(res.allowed_filesize); $container.find('.allowed_attach_size').text(res.allowed_attach_size); $container.find('.attached_size').text(res.attached_size); $container.find('.file_count').text(res.files.length); - if(res.allowed_filetypes === '*.*') { + if(res.allowed_extensions.length == 0) { $container.find('.allowed_filetypes_container').hide(); } else { $container.find('.allowed_filetypes_container').show(); diff --git a/modules/file/file.admin.controller.php b/modules/file/file.admin.controller.php index 981205d0c..788a7f005 100644 --- a/modules/file/file.admin.controller.php +++ b/modules/file/file.admin.controller.php @@ -65,7 +65,7 @@ class fileAdminController extends file $config = getModel('module')->getModuleConfig('file'); $config->allowed_filesize = Context::get('allowed_filesize'); $config->allowed_attach_size = Context::get('allowed_attach_size'); - $config->allowed_filetypes = str_replace(' ', '', Context::get('allowed_filetypes')); + $config->allowed_filetypes = Context::get('allowed_filetypes'); $config->max_image_width = intval(Context::get('max_image_width')) ?: ''; $config->max_image_height = intval(Context::get('max_image_height')) ?: ''; $config->max_image_size_action = Context::get('max_image_size_action') ?: ''; @@ -85,6 +85,21 @@ class fileAdminController extends file } } + // Simplify allowed_filetypes + $config->allowed_extensions = strtr(strtolower(trim($config->allowed_filetypes)), array('*.' => '', ';' => ',')); + if ($config->allowed_extensions) + { + $config->allowed_extensions = array_map('trim', explode(',', $config->allowed_filetypes)); + $config->allowed_filetypes = implode(';', array_map(function($ext) { + return '*.' . $ext; + }, $config->allowed_extensions)); + } + else + { + $config->allowed_extensions = array(); + $config->allowed_filetypes = '*.*'; + } + // Save and redirect $oModuleController = getController('module'); $output = $oModuleController->insertModuleConfig('file',$config); @@ -140,7 +155,7 @@ class fileAdminController extends file $file_config->allow_outlink_site = Context::get('allow_outlink_site'); $file_config->allowed_filesize = Context::get('allowed_filesize'); $file_config->allowed_attach_size = Context::get('allowed_attach_size'); - $file_config->allowed_filetypes = str_replace(' ', '', Context::get('allowed_filetypes')); + $file_config->allowed_filetypes = Context::get('allowed_filetypes'); if(!is_array($download_grant)) { @@ -160,6 +175,21 @@ class fileAdminController extends file } } + // Simplify allowed_filetypes + $file_config->allowed_extensions = strtr(strtolower(trim($file_config->allowed_filetypes)), array('*.' => '', ';' => ',')); + if ($file_config->allowed_extensions) + { + $file_config->allowed_extensions = array_map('trim', explode(',', $file_config->allowed_filetypes)); + $file_config->allowed_filetypes = implode(';', array_map(function($ext) { + return '*.' . $ext; + }, $file_config->allowed_extensions)); + } + else + { + $file_config->allowed_extensions = array(); + $file_config->allowed_filetypes = '*.*'; + } + $oModuleController = getController('module'); for($i=0;$iallowed_filesize = '2'; $config->allowed_attach_size = '2'; $config->allowed_filetypes = '*.*'; + $config->allowed_extensions = array(); $oModuleController->insertModuleConfig('file', $config); // Generate a directory for the file module FileHandler::makeDir('./files/attach/images'); diff --git a/modules/file/file.controller.php b/modules/file/file.controller.php index 328543fc8..316377665 100644 --- a/modules/file/file.controller.php +++ b/modules/file/file.controller.php @@ -881,16 +881,9 @@ class fileController extends file { // Check file type - if(isset($config->allowed_filetypes) && $config->allowed_filetypes !== '*.*') + if(isset($config->allowed_extensions) && count($config->allowed_extensions)) { - $filetypes = explode(';', $config->allowed_filetypes); - $ext = array(); - foreach($filetypes as $item) { - $item = explode('.', $item); - $ext[] = strtolower($item[1]); - } - - if(!in_array($extension, $ext)) + if(!in_array($extension, $config->allowed_extensions)) { throw new Rhymix\Framework\Exception('msg_not_allowed_filetype'); } diff --git a/modules/file/file.model.php b/modules/file/file.model.php index ad562ef84..6e8faf0ad 100644 --- a/modules/file/file.model.php +++ b/modules/file/file.model.php @@ -112,6 +112,7 @@ class fileModel extends file $allowed_attach_size = FileHandler::filesize($file_config->allowed_attach_size*1024*1024); $allowed_filesize = FileHandler::filesize($file_config->allowed_filesize*1024*1024); $allowed_filetypes = $file_config->allowed_filetypes; + $allowed_extensions = $file_config->allowed_extensions; $this->add("files",$files); $this->add("editor_sequence",$editor_sequence); $this->add("upload_target_srl",$upload_target_srl); @@ -121,6 +122,7 @@ class fileModel extends file $this->add('allowed_attach_size', $allowed_attach_size); $this->add('allowed_filesize', $allowed_filesize); $this->add('allowed_filetypes', $allowed_filetypes); + $this->add('allowed_extensions', $allowed_extensions); } /** @@ -188,6 +190,7 @@ class fileModel extends file $config->allowed_filesize = $file_config->allowed_filesize; $config->allowed_attach_size = $file_config->allowed_attach_size; $config->allowed_filetypes = $file_config->allowed_filetypes; + $config->allowed_extensions = $file_config->allowed_extensions; $config->inline_download_format = $file_config->inline_download_format; $config->max_image_width = $file_config->max_image_width; $config->max_image_height = $file_config->max_image_height; @@ -207,6 +210,7 @@ class fileModel extends file if(!$config->allowed_filesize) $config->allowed_filesize = $file_module_config->allowed_filesize; if(!$config->allowed_attach_size) $config->allowed_attach_size = $file_module_config->allowed_attach_size; if(!$config->allowed_filetypes) $config->allowed_filetypes = $file_module_config->allowed_filetypes; + if(!$config->allowed_extensions) $config->allowed_extensions = $file_module_config->allowed_extensions; if(!$config->allow_outlink) $config->allow_outlink = $file_module_config->allow_outlink; if(!$config->allow_outlink_site) $config->allow_outlink_site = $file_module_config->allow_outlink_site; if(!$config->allow_outlink_format) $config->allow_outlink_format = $file_module_config->allow_outlink_format; @@ -231,6 +235,22 @@ class fileModel extends file if(!$config->image_autoconv) $config->image_autoconv = array(); if(!$config->image_autoconv_quality) $config->image_autoconv_quality = 75; if(!$config->image_autorotate_quality) $config->image_autorotate_quality = 75; + + // Format allowed_filetypes + if($config->allowed_filetypes && !isset($config->allowed_extensions)) + { + $config->allowed_filetypes = trim($config->allowed_filetypes); + if($config->allowed_filetypes === '*.*') + { + $config->allowed_extensions = ''; + } + else + { + $config->allowed_extensions = array_map(function($ext) { + return strtolower(substr(strrchr(trim($ext), '.'), 1)); + }, explode(';', $config->allowed_filetypes)); + } + } return $config; } diff --git a/modules/file/lang/en.php b/modules/file/lang/en.php index 0eba73a2d..69a127067 100644 --- a/modules/file/lang/en.php +++ b/modules/file/lang/en.php @@ -42,7 +42,7 @@ $lang->about_allowed_attach_size = 'You can limit the total size of all attached $lang->about_allowed_filesize_global = 'This is the global limit on the size of each attachment.'; $lang->about_allowed_attach_size_global = 'This is the global limit on the combined size of all attachments in one document.'; $lang->about_allowed_size_limits = 'The file size will be limited to the value set in php.ini (%sB) in IE9 and below and older Android browsers.'; -$lang->about_allowed_filetypes = 'To allow an extension, use "*.[extention]". To allow multiple extensions, use ";" between each extension. ex) *.* or *.jpg;*.gif; '; +$lang->about_allowed_filetypes = 'Rhymix no longer uses the old *.* syntax. Simply list the extensions you wish to allow.
Please use a comma (,) to separate items: e.g. doc, zip, pdf'; $lang->about_max_image_size = 'You can limit the maximum width and/or height of uploaded images.
This limit does not apply to files uploaded by the administrator.'; $lang->about_image_autoconv = 'Automatically convert types of images that often cause trouble or waste disk space into other types.
This also works for WebP images that incorrectly have the JPG extension.
If enabled, this feature also applies to images uploaded by the administrator.'; $lang->about_image_autorotate = 'Automatically correct images that are rotated by mobile devices.
If enabled, this feature also applies to images uploaded by the administrator.'; diff --git a/modules/file/lang/ko.php b/modules/file/lang/ko.php index dbe2b31f0..afb7a45e1 100644 --- a/modules/file/lang/ko.php +++ b/modules/file/lang/ko.php @@ -42,7 +42,7 @@ $lang->about_allowed_attach_size = '하나의 문서에 첨부할 수 있는 최 $lang->about_allowed_filesize_global = '관리자를 포함하여 사이트 전체에 적용되는 파일 용량 제한입니다.'; $lang->about_allowed_attach_size_global = '관리자를 포함하여 사이트 전체에 적용되는 문서당 총 첨부 용량 제한입니다.'; $lang->about_allowed_size_limits = 'IE9 이하, 구버전 안드로이드 등에서는 php.ini에서 지정한 %sB로 제한됩니다.'; -$lang->about_allowed_filetypes = '"*.확장자"로 지정할 수 있고 ";" 으로 여러 개 지정이 가능합니다. 예) *.* or *.jpg;*.gif;'; +$lang->about_allowed_filetypes = '업로드를 허용할 확장자 목록입니다. 구 버전의 *.* 문법은 사용하지 않습니다.
여러 개 입력시 쉼표(,)을 이용해서 구분해 주세요. 예) doc, zip, pdf'; $lang->about_max_image_size = '이미지 파일의 가로, 세로, 또는 가로세로 크기를 모두 제한할 수 있습니다.
관리자가 업로드한 파일에는 적용되지 않습니다.'; $lang->about_image_autoconv = '종종 문제를 일으키거나 용량을 낭비하는 이미지 타입을 다른 타입으로 자동 변환합니다.
WebP 이미지에 JPG 확장자가 잘못 부여된 경우에도 변환할 수 있습니다.
관리자가 업로드한 파일에도 적용됩니다.'; $lang->about_image_autorotate = '모바일 기기 등에서 잘못 회전된 이미지를 바로잡습니다.
관리자가 업로드한 파일에도 적용됩니다.'; diff --git a/modules/file/ruleset/fileModuleConfig.xml b/modules/file/ruleset/fileModuleConfig.xml index 963180a3e..067c5c072 100644 --- a/modules/file/ruleset/fileModuleConfig.xml +++ b/modules/file/ruleset/fileModuleConfig.xml @@ -1,11 +1,7 @@ - - - - diff --git a/modules/file/ruleset/insertConfig.xml b/modules/file/ruleset/insertConfig.xml index 963180a3e..067c5c072 100644 --- a/modules/file/ruleset/insertConfig.xml +++ b/modules/file/ruleset/insertConfig.xml @@ -1,11 +1,7 @@ - - - - diff --git a/modules/file/tpl/file_module_config.html b/modules/file/tpl/file_module_config.html index b3a4e35a2..5b9100106 100644 --- a/modules/file/tpl/file_module_config.html +++ b/modules/file/tpl/file_module_config.html @@ -24,7 +24,7 @@
- +

{$lang->about_allowed_filetypes}

diff --git a/modules/file/tpl/upload_config.html b/modules/file/tpl/upload_config.html index fcb1d4d7e..b651b1300 100644 --- a/modules/file/tpl/upload_config.html +++ b/modules/file/tpl/upload_config.html @@ -84,7 +84,7 @@
- +

{$lang->about_allowed_filetypes}