Simplify allowed_filetypes input format

This commit is contained in:
Kijin Sung 2019-08-01 15:57:05 +09:00
parent 8c242327a8
commit c40a47724d
11 changed files with 61 additions and 25 deletions

View file

@ -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();

View file

@ -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;$i<count($module_srl);$i++)
{

View file

@ -21,6 +21,7 @@ class file extends ModuleObject
$config->allowed_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');

View file

@ -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');
}

View file

@ -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;
}

View file

@ -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.<br />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.<br />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.<br />This also works for WebP images that incorrectly have the JPG extension.<br />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.<br />If enabled, this feature also applies to images uploaded by the administrator.';

View file

@ -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 = '업로드를 허용할 확장자 목록입니다. 구 버전의 *.* 문법은 사용하지 않습니다.<br />여러 개 입력시 쉼표(,)을 이용해서 구분해 주세요. 예) doc, zip, pdf';
$lang->about_max_image_size = '이미지 파일의 가로, 세로, 또는 가로세로 크기를 모두 제한할 수 있습니다.<br />관리자가 업로드한 파일에는 적용되지 않습니다.';
$lang->about_image_autoconv = '종종 문제를 일으키거나 용량을 낭비하는 이미지 타입을 다른 타입으로 자동 변환합니다.<br />WebP 이미지에 JPG 확장자가 잘못 부여된 경우에도 변환할 수 있습니다.<br />관리자가 업로드한 파일에도 적용됩니다.';
$lang->about_image_autorotate = '모바일 기기 등에서 잘못 회전된 이미지를 바로잡습니다.<br />관리자가 업로드한 파일에도 적용됩니다.';

View file

@ -1,11 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<ruleset version="1.5.0">
<customrules>
<rule name="extension" type="regex" test="/^(?:\*\.\*|(\*\.\w+;\s*)*\*\.\w+;?)$/i" />
</customrules>
<fields>
<field name="allowed_filesize" required="true" rule="float" default="2" />
<field name="allowed_attach_size" required="true" rule="float" default="2" />
<field name="allowed_filetypes" required="true" rule="extension" />
</fields>
</ruleset>

View file

@ -1,11 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<ruleset version="1.5.0">
<customrules>
<rule name="extension" type="regex" test="/^(?:\*\.\*|(\*\.\w+;\s*)*\*\.\w+;?)$/i" />
</customrules>
<fields>
<field name="allowed_filesize" required="true" rule="float" default="2" />
<field name="allowed_attach_size" required="true" rule="float" default="2" />
<field name="allowed_filetypes" required="true" rule="extension" />
</fields>
</ruleset>

View file

@ -24,7 +24,7 @@
<div class="x_control-group">
<label for="allowed_filetypes" class="x_control-label">{$lang->allowed_filetypes}</label>
<div class="x_controls">
<input type="text" name="allowed_filetypes" id="allowed_filetypes" value="{$file_config->allowed_filetypes}" />
<input type="text" name="allowed_filetypes" id="allowed_filetypes" value="{implode(', ', $file_config->allowed_extensions ?: [])}" />
<p class="x_help-block">{$lang->about_allowed_filetypes}</p>
</div>
</div>

View file

@ -84,7 +84,7 @@
<div class="x_control-group">
<label for="allowedFiletypes" class="x_control-label">{$lang->allowed_filetypes}</label>
<div class="x_controls">
<input id="allowedFiletypes" type="text" name="allowed_filetypes" value="{$config->allowed_filetypes}" />
<input id="allowedFiletypes" type="text" name="allowed_filetypes" value="{implode(', ', $config->allowed_extensions ?: [])}" />
<p class="x_help-block">{$lang->about_allowed_filetypes}</p>
</div>
</div>