From 690803f3fc5358d21380cfe24685d4ae5a0c8a17 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 1 Aug 2019 00:20:40 +0900 Subject: [PATCH 01/18] Separate upload config screen from download config screen --- modules/file/conf/module.xml | 2 ++ modules/file/file.admin.controller.php | 40 ++++++++++++++++----- modules/file/file.admin.view.php | 18 +++++++++- modules/file/lang/en.php | 1 + modules/file/lang/ko.php | 1 + modules/file/tpl/adminConfig.html | 33 ----------------- modules/file/tpl/download_config.html | 49 ++++++++++++++++++++++++++ modules/file/tpl/header.html | 3 ++ 8 files changed, 105 insertions(+), 42 deletions(-) create mode 100644 modules/file/tpl/download_config.html diff --git a/modules/file/conf/module.xml b/modules/file/conf/module.xml index e43dbd322..2b4e0a3ea 100644 --- a/modules/file/conf/module.xml +++ b/modules/file/conf/module.xml @@ -15,10 +15,12 @@ + + diff --git a/modules/file/file.admin.controller.php b/modules/file/file.admin.controller.php index 46ba168a4..f8ad5c586 100644 --- a/modules/file/file.admin.controller.php +++ b/modules/file/file.admin.controller.php @@ -55,21 +55,18 @@ class fileAdminController extends file } /** - * Add file information + * Save upload configuration * * @return Object */ function procFileAdminInsertConfig() { - // Get configurations (using module model object) - $config = new stdClass(); + // Update configuration + $oFileModel = getModel('file'); + $config = $oFileModel->getFileConfig(); $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->allow_outlink = Context::get('allow_outlink'); - $config->allow_outlink_format = Context::get('allow_outlink_format'); - $config->allow_outlink_site = Context::get('allow_outlink_site'); - $config->inline_download_format = array_map('utf8_trim', Context::get('inline_download_format')); // Check maximum file size if (PHP_INT_SIZE < 8) @@ -80,7 +77,7 @@ class fileAdminController extends file } } - // Create module Controller object + // Save and redirect $oModuleController = getController('module'); $output = $oModuleController->insertModuleConfig('file',$config); @@ -88,6 +85,33 @@ class fileAdminController extends file return $this->setRedirectUrl($returnUrl, $output); } + /** + * Save download configuration + * + * @return Object + */ + function procFileAdminInsertDownloadConfig() + { + // Update configuration + $oFileModel = getModel('file'); + $config = $oFileModel->getFileConfig(); + $config->allow_outlink = Context::get('allow_outlink'); + $config->allow_outlink_format = Context::get('allow_outlink_format'); + $config->allow_outlink_site = Context::get('allow_outlink_site'); + $config->inline_download_format = array_map('utf8_trim', Context::get('inline_download_format')); + + // Save and redirect + $oModuleController = getController('module'); + $output = $oModuleController->insertModuleConfig('file',$config); + if(!$output->toBool()) + { + return $output; + } + + $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispFileAdminDownloadConfig'); + return $this->setRedirectUrl($returnUrl, $output); + } + /** * Add file information for each module * diff --git a/modules/file/file.admin.view.php b/modules/file/file.admin.view.php index 8ae9804b0..a9723ac7a 100644 --- a/modules/file/file.admin.view.php +++ b/modules/file/file.admin.view.php @@ -210,7 +210,7 @@ class fileAdminView extends file } /** - * Set attachment information (for administrator) + * Upload config screen * * @return Object */ @@ -224,6 +224,22 @@ class fileAdminView extends file $this->setTemplatePath($this->module_path.'tpl'); $this->setTemplateFile('adminConfig'); } + + /** + * Download config screen + * + * @return Object + */ + function dispFileAdminDownloadConfig() + { + $oFileModel = getModel('file'); + $config = $oFileModel->getFileConfig(); + Context::set('config',$config); + + // Set a template file + $this->setTemplatePath($this->module_path.'tpl'); + $this->setTemplateFile('download_config'); + } } /* End of file file.admin.view.php */ /* Location: ./modules/file/file.admin.view.php */ diff --git a/modules/file/lang/en.php b/modules/file/lang/en.php index 870a012fb..5bba633c1 100644 --- a/modules/file/lang/en.php +++ b/modules/file/lang/en.php @@ -3,6 +3,7 @@ $lang->file = 'File'; $lang->file_management = 'File Management'; $lang->file_upload = 'File Upload'; $lang->file_upload_config = 'File Upload Settings'; +$lang->file_download_config = 'File Download Settings'; $lang->file_name = 'File Name'; $lang->file_size = 'File Size'; $lang->download_count = 'Number of Downloads'; diff --git a/modules/file/lang/ko.php b/modules/file/lang/ko.php index bc271cbe2..cf3db1364 100644 --- a/modules/file/lang/ko.php +++ b/modules/file/lang/ko.php @@ -3,6 +3,7 @@ $lang->file = '파일'; $lang->file_management = '파일 관리'; $lang->file_upload = '파일 업로드'; $lang->file_upload_config = '파일 업로드 설정'; +$lang->file_download_config = '파일 다운로드 설정'; $lang->file_name = '파일 이름'; $lang->file_size = '파일 크기'; $lang->download_count = '다운로드 받은 수'; diff --git a/modules/file/tpl/adminConfig.html b/modules/file/tpl/adminConfig.html index 57f8047d3..0d8d52d04 100644 --- a/modules/file/tpl/adminConfig.html +++ b/modules/file/tpl/adminConfig.html @@ -8,39 +8,6 @@ -
- -
- - -

{$lang->about_allow_outlink}

-
-
-
- -
- -

{$lang->about_allow_outlink_format}

-
-
-
- -
- -

{$lang->about_allow_outlink_site}

-
-
-
- -
- - - - - -

{$lang->about_inline_download_format}

-
-
diff --git a/modules/file/tpl/download_config.html b/modules/file/tpl/download_config.html new file mode 100644 index 000000000..16493d05e --- /dev/null +++ b/modules/file/tpl/download_config.html @@ -0,0 +1,49 @@ + + +
+

{$XE_VALIDATOR_MESSAGE}

+
+ +
+ + + +
+ +
+ + +

{$lang->about_allow_outlink}

+
+
+
+ +
+ +

{$lang->about_allow_outlink_format}

+
+
+
+ +
+ +

{$lang->about_allow_outlink_site}

+
+
+
+ +
+ + + + + +

{$lang->about_inline_download_format}

+
+
+
+
+ +
+
+
diff --git a/modules/file/tpl/header.html b/modules/file/tpl/header.html index e2060cb46..bb2a3ed4c 100644 --- a/modules/file/tpl/header.html +++ b/modules/file/tpl/header.html @@ -10,4 +10,7 @@
  • {$lang->file_upload_config}
  • +
  • + {$lang->file_download_config} +
  • From d9118289fbb85e99a87a4cb4544d6d4a2301591a Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 1 Aug 2019 00:22:15 +0900 Subject: [PATCH 02/18] Fix confusing label --- modules/file/lang/ko.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/file/lang/ko.php b/modules/file/lang/ko.php index cf3db1364..87bbf7276 100644 --- a/modules/file/lang/ko.php +++ b/modules/file/lang/ko.php @@ -12,8 +12,8 @@ $lang->is_valid = '유효'; $lang->is_stand_by = '대기'; $lang->file_list = '첨부 파일 목록'; $lang->allow_outlink = '다운로드 링크 외부 접근 허용'; -$lang->allow_outlink_site = '다운로드 링크 허용 사이트'; -$lang->allow_outlink_format = '다운로드 링크 허용 확장자'; +$lang->allow_outlink_site = '외부 접근 허용 사이트'; +$lang->allow_outlink_format = '외부 접근 허용 확장자'; $lang->allowed_filesize = '파일 크기 제한'; $lang->allowed_attach_size = '문서 첨부 제한'; $lang->allowed_filetypes = '허용 확장자'; From 280bdeb470df66c97a0622710a6f2f0ae113a9b7 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 1 Aug 2019 01:14:13 +0900 Subject: [PATCH 03/18] Rename dispFileAdminConfig to dispFileAdminUploadConfig --- modules/file/conf/module.xml | 4 ++-- modules/file/file.admin.controller.php | 4 ++-- modules/file/file.admin.view.php | 4 ++-- modules/file/tpl/header.html | 4 ++-- modules/file/tpl/{adminConfig.html => upload_config.html} | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) rename modules/file/tpl/{adminConfig.html => upload_config.html} (91%) diff --git a/modules/file/conf/module.xml b/modules/file/conf/module.xml index 2b4e0a3ea..fec31a6d2 100644 --- a/modules/file/conf/module.xml +++ b/modules/file/conf/module.xml @@ -14,12 +14,12 @@ - + - + diff --git a/modules/file/file.admin.controller.php b/modules/file/file.admin.controller.php index f8ad5c586..410e7393b 100644 --- a/modules/file/file.admin.controller.php +++ b/modules/file/file.admin.controller.php @@ -59,7 +59,7 @@ class fileAdminController extends file * * @return Object */ - function procFileAdminInsertConfig() + function procFileAdminInsertUploadConfig() { // Update configuration $oFileModel = getModel('file'); @@ -81,7 +81,7 @@ class fileAdminController extends file $oModuleController = getController('module'); $output = $oModuleController->insertModuleConfig('file',$config); - $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispFileAdminConfig'); + $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispFileAdminUploadConfig'); return $this->setRedirectUrl($returnUrl, $output); } diff --git a/modules/file/file.admin.view.php b/modules/file/file.admin.view.php index a9723ac7a..b1a571c41 100644 --- a/modules/file/file.admin.view.php +++ b/modules/file/file.admin.view.php @@ -214,7 +214,7 @@ class fileAdminView extends file * * @return Object */ - function dispFileAdminConfig() + function dispFileAdminUploadConfig() { $oFileModel = getModel('file'); $config = $oFileModel->getFileConfig(); @@ -222,7 +222,7 @@ class fileAdminView extends file // Set a template file $this->setTemplatePath($this->module_path.'tpl'); - $this->setTemplateFile('adminConfig'); + $this->setTemplateFile('upload_config'); } /** diff --git a/modules/file/tpl/header.html b/modules/file/tpl/header.html index bb2a3ed4c..d11c3416f 100644 --- a/modules/file/tpl/header.html +++ b/modules/file/tpl/header.html @@ -7,8 +7,8 @@
  • {$lang->file_list}
  • -
  • - {$lang->file_upload_config} +
  • + {$lang->file_upload_config}
  • {$lang->file_download_config} diff --git a/modules/file/tpl/adminConfig.html b/modules/file/tpl/upload_config.html similarity index 91% rename from modules/file/tpl/adminConfig.html rename to modules/file/tpl/upload_config.html index 0d8d52d04..b1589d449 100644 --- a/modules/file/tpl/adminConfig.html +++ b/modules/file/tpl/upload_config.html @@ -1,13 +1,13 @@ -
    +

    {$XE_VALIDATOR_MESSAGE}

    - - + +
    From c95f84adb83d93610f1b443be90e83b16374a4bb Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 1 Aug 2019 01:56:51 +0900 Subject: [PATCH 04/18] Implement maximum image size constraint --- modules/file/file.admin.controller.php | 9 +- modules/file/file.controller.php | 132 +++++++++++++++++-------- modules/file/file.model.php | 8 ++ modules/file/lang/en.php | 8 ++ modules/file/lang/ko.php | 10 +- modules/file/tpl/upload_config.html | 13 +++ 6 files changed, 135 insertions(+), 45 deletions(-) diff --git a/modules/file/file.admin.controller.php b/modules/file/file.admin.controller.php index 410e7393b..6775f990a 100644 --- a/modules/file/file.admin.controller.php +++ b/modules/file/file.admin.controller.php @@ -62,11 +62,13 @@ class fileAdminController extends file function procFileAdminInsertUploadConfig() { // Update configuration - $oFileModel = getModel('file'); - $config = $oFileModel->getFileConfig(); + $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->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') ?: ''; // Check maximum file size if (PHP_INT_SIZE < 8) @@ -93,8 +95,7 @@ class fileAdminController extends file function procFileAdminInsertDownloadConfig() { // Update configuration - $oFileModel = getModel('file'); - $config = $oFileModel->getFileConfig(); + $config = getModel('module')->getModuleConfig('file'); $config->allow_outlink = Context::get('allow_outlink'); $config->allow_outlink_format = Context::get('allow_outlink_format'); $config->allow_outlink_site = Context::get('allow_outlink_site'); diff --git a/modules/file/file.controller.php b/modules/file/file.controller.php index 392511f92..d59a4ff9e 100644 --- a/modules/file/file.controller.php +++ b/modules/file/file.controller.php @@ -861,48 +861,100 @@ class fileController extends file $file_info['name'] = base64_decode(strtr($match[1], ':', '/')); } - if(!$manual_insert) - { - // Get the file configurations - $logged_info = Context::get('logged_info'); - if($logged_info->is_admin != 'Y') - { - $oFileModel = getModel('file'); - $config = $oFileModel->getFileConfig($module_srl); - - // check file type - if(isset($config->allowed_filetypes) && $config->allowed_filetypes !== '*.*') - { - $filetypes = explode(';', $config->allowed_filetypes); - $ext = array(); - foreach($filetypes as $item) { - $item = explode('.', $item); - $ext[] = strtolower($item[1]); - } - $uploaded_ext = explode('.', $file_info['name']); - $uploaded_ext = strtolower(array_pop($uploaded_ext)); - - if(!in_array($uploaded_ext, $ext)) - { - throw new Rhymix\Framework\Exception('msg_not_allowed_filetype'); - } - } - - $allowed_filesize = $config->allowed_filesize * 1024 * 1024; - $allowed_attach_size = $config->allowed_attach_size * 1024 * 1024; - // An error appears if file size exceeds a limit - if($allowed_filesize < filesize($file_info['tmp_name'])) throw new Rhymix\Framework\Exception('msg_exceeds_limit_size'); - // Get total file size of all attachements (from DB) - $size_args = new stdClass; - $size_args->upload_target_srl = $upload_target_srl; - $output = executeQuery('file.getAttachedFileSize', $size_args); - $attached_size = (int)$output->data->attached_size + filesize($file_info['tmp_name']); - if($attached_size > $allowed_attach_size) throw new Rhymix\Framework\Exception('msg_exceeds_limit_size'); - } - } - // Sanitize filename $file_info['name'] = Rhymix\Framework\Filters\FilenameFilter::clean($file_info['name']); + + // Get extension + $extension = explode('.', $file_info['name']) ?: array(''); + $extension = strtolower(array_pop($extension)); + + // Check file type, size, and other attributes + if(!$manual_insert && !$this->user->isAdmin()) + { + // Get file module configuration + $oFileModel = getModel('file'); + $config = $oFileModel->getFileConfig($module_srl); + + // Check file type + if(isset($config->allowed_filetypes) && $config->allowed_filetypes !== '*.*') + { + $filetypes = explode(';', $config->allowed_filetypes); + $ext = array(); + foreach($filetypes as $item) { + $item = explode('.', $item); + $ext[] = strtolower($item[1]); + } + + if(!in_array($extension, $ext)) + { + throw new Rhymix\Framework\Exception('msg_not_allowed_filetype'); + } + } + + // Check file size + $allowed_filesize = $config->allowed_filesize * 1024 * 1024; + $allowed_attach_size = $config->allowed_attach_size * 1024 * 1024; + if($allowed_filesize < filesize($file_info['tmp_name'])) + { + throw new Rhymix\Framework\Exception('msg_exceeds_limit_size'); + } + + // Get total size of all attachements + $size_args = new stdClass; + $size_args->upload_target_srl = $upload_target_srl; + $output = executeQuery('file.getAttachedFileSize', $size_args); + $attached_size = (int)$output->data->attached_size + filesize($file_info['tmp_name']); + if($attached_size > $allowed_attach_size) + { + throw new Rhymix\Framework\Exception('msg_exceeds_limit_size'); + } + + // Check image dimensions + if($config->max_image_size_action && ($config->max_image_width || $config->max_image_height)) + { + if(in_array($extension, array('gif', 'jpg', 'png', 'webp', 'bmp'))) + { + if ($image_info = @getimagesize($file_info['tmp_name'])) + { + $image_width = $image_info[0]; + $image_height = $image_info[1]; + $exceeded = false; + if ($config->max_image_width > 0 && $image_width > $config->max_image_width) + { + $exceeded = true; + } + elseif ($config->max_image_height > 0 && $image_height > $config->max_image_height) + { + $exceeded = true; + } + + if ($exceeded) + { + if ($config->max_image_size_action === 'block') + { + if ($config->max_image_width && $config->max_image_height) + { + $message = sprintf(lang('msg_exceeds_max_image_size'), $config->max_image_width, $config->max_image_height); + } + elseif ($config->max_image_width) + { + $message = sprintf(lang('msg_exceeds_max_image_width'), $config->max_image_width); + } + else + { + $message = sprintf(lang('msg_exceeds_max_image_height'), $config->max_image_height); + } + throw new Rhymix\Framework\Exception($message); + } + else + { + // TODO + } + } + } + } + } + } // Get file_srl $file_srl = getNextSequence(); diff --git a/modules/file/file.model.php b/modules/file/file.model.php index f3b48d35f..25e85fed7 100644 --- a/modules/file/file.model.php +++ b/modules/file/file.model.php @@ -189,11 +189,15 @@ class fileModel extends file $config->allowed_attach_size = $file_config->allowed_attach_size; $config->allowed_filetypes = $file_config->allowed_filetypes; $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; + $config->max_image_size_action = $file_config->max_image_size_action; $config->download_grant = $file_config->download_grant; $config->allow_outlink = $file_config->allow_outlink; $config->allow_outlink_site = $file_config->allow_outlink_site; $config->allow_outlink_format = $file_config->allow_outlink_format; } + // Property for all files comes first than each property 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; @@ -202,6 +206,10 @@ class fileModel extends file 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; if(!$config->download_grant) $config->download_grant = $file_module_config->download_grant; + if(!$config->max_image_width) $config->max_image_width = $file_module_config->max_image_width; + if(!$config->max_image_height) $config->max_image_height = $file_module_config->max_image_height; + if(!$config->max_image_size_action) $config->max_image_size_action = $file_module_config->max_image_size_action; + // Default setting if not exists if(!$config->allowed_filesize) $config->allowed_filesize = '2'; if(!$config->allowed_attach_size) $config->allowed_attach_size = '3'; diff --git a/modules/file/lang/en.php b/modules/file/lang/en.php index 5bba633c1..59ca07299 100644 --- a/modules/file/lang/en.php +++ b/modules/file/lang/en.php @@ -17,6 +17,10 @@ $lang->allow_outlink_format = 'Allowed Formats'; $lang->allowed_filesize = 'Maximum File Size'; $lang->allowed_attach_size = 'Maximum Attachments'; $lang->allowed_filetypes = 'Allowed extentsions'; +$lang->max_image_size = 'Maximum Image Size'; +$lang->max_image_size_action_nothing = 'If exceeded, do nothing'; +$lang->max_image_size_action_block = 'If exceeded, block upload'; +$lang->max_image_size_action_resize = 'If exceeded, resize automatically'; $lang->inline_download_format = 'Open in current window'; $lang->inline_download_image = 'Image'; $lang->inline_download_audio = 'Audio'; @@ -34,6 +38,7 @@ $lang->about_allowed_filesize_global = 'This is the global limit on the size of $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_max_image_size = 'You can limit the maximum width and height of uploaded images.'; $lang->cmd_delete_checked_file = 'Delete Selected Item(s)'; $lang->cmd_move_to_document = 'Move to Document'; $lang->cmd_download = 'Download'; @@ -41,6 +46,9 @@ $lang->msg_not_permitted_download = 'You do not have a permission to download.'; $lang->msg_file_cart_is_null = 'Please select a file(s) to delete.'; $lang->msg_checked_file_is_deleted = '%d attachment(s) was(were) deleted.'; $lang->msg_exceeds_limit_size = 'This file exceeds the attachment limit.'; +$lang->msg_exceeds_max_image_size = 'This image is too large. Images must be no larger than %dx%dpx.'; +$lang->msg_exceeds_max_image_width = 'This image is too large. The maximum permitted width is %dpx.'; +$lang->msg_exceeds_max_image_height = 'This image is too large. The maximum permitted height is %dpx.'; $lang->msg_file_not_found = 'Could not find requested file.'; $lang->msg_file_key_expired = 'This download link is expired. Please initiate the download again.'; $lang->file_search_target_list['filename'] = 'File Name'; diff --git a/modules/file/lang/ko.php b/modules/file/lang/ko.php index 87bbf7276..cc17f19b7 100644 --- a/modules/file/lang/ko.php +++ b/modules/file/lang/ko.php @@ -14,9 +14,13 @@ $lang->file_list = '첨부 파일 목록'; $lang->allow_outlink = '다운로드 링크 외부 접근 허용'; $lang->allow_outlink_site = '외부 접근 허용 사이트'; $lang->allow_outlink_format = '외부 접근 허용 확장자'; -$lang->allowed_filesize = '파일 크기 제한'; +$lang->allowed_filesize = '파일 용량 제한'; $lang->allowed_attach_size = '문서 첨부 제한'; $lang->allowed_filetypes = '허용 확장자'; +$lang->max_image_size = '이미지 크기 제한'; +$lang->max_image_size_action_nothing = '초과시 아무 것도 하지 않음'; +$lang->max_image_size_action_block = '초과시 업로드 금지'; +$lang->max_image_size_action_resize = '초과시 자동 크기 조정'; $lang->inline_download_format = '다운로드시 현재 창 사용'; $lang->inline_download_image = '이미지'; $lang->inline_download_audio = '오디오'; @@ -34,6 +38,7 @@ $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_max_image_size = '이미지 파일의 가로세로 크기를 제한할 수 있습니다.'; $lang->cmd_delete_checked_file = '선택항목 삭제'; $lang->cmd_move_to_document = '문서로 이동'; $lang->cmd_download = '다운로드'; @@ -42,6 +47,9 @@ $lang->msg_file_cart_is_null = '삭제할 파일을 선택해주세요.'; $lang->msg_checked_file_is_deleted = '%d개의 첨부 파일이 삭제되었습니다.'; $lang->msg_exceeds_limit_size = '허용된 용량을 초과하여 첨부가 되지 않았습니다.'; $lang->msg_not_allowed_filetype = '업로드할 수 없는 파일 형식입니다.'; +$lang->msg_exceeds_max_image_size = '이미지가 너무 큽니다. %dx%dpx 이하의 이미지만 허용됩니다.'; +$lang->msg_exceeds_max_image_width = '이미지가 너무 큽니다. 폭 %dpx 이하의 이미지만 허용됩니다.'; +$lang->msg_exceeds_max_image_height = '이미지가 너무 큽니다. 높이 %dpx 이하의 이미지만 허용됩니다.'; $lang->msg_file_not_found = '요청한 파일을 찾을 수 없습니다.'; $lang->msg_file_key_expired = '다운로드 링크의 유효기간이 지났습니다. 다시 다운로드하여 주시기 바랍니다.'; $lang->file_search_target_list['filename'] = '파일 이름'; diff --git a/modules/file/tpl/upload_config.html b/modules/file/tpl/upload_config.html index b1589d449..52bd3ff47 100644 --- a/modules/file/tpl/upload_config.html +++ b/modules/file/tpl/upload_config.html @@ -22,6 +22,19 @@

    {$lang->about_allowed_attach_size_global}
    {sprintf($lang->about_allowed_size_limits, ini_get('upload_max_filesize'))}

    +
    + +
    + × + px   + +

    {$lang->about_max_image_size}

    +
    +
    From 1e5eedf3e026e8acc997604b1f044c07e4691b32 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 1 Aug 2019 02:13:25 +0900 Subject: [PATCH 05/18] Implement automatically resizing images that are too large --- modules/file/file.controller.php | 64 +++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/modules/file/file.controller.php b/modules/file/file.controller.php index d59a4ff9e..fade0277e 100644 --- a/modules/file/file.controller.php +++ b/modules/file/file.controller.php @@ -863,6 +863,7 @@ class fileController extends file // Sanitize filename $file_info['name'] = Rhymix\Framework\Filters\FilenameFilter::clean($file_info['name']); + $file_info['resized'] = false; // Get extension $extension = explode('.', $file_info['name']) ?: array(''); @@ -890,29 +891,11 @@ class fileController extends file throw new Rhymix\Framework\Exception('msg_not_allowed_filetype'); } } - - // Check file size - $allowed_filesize = $config->allowed_filesize * 1024 * 1024; - $allowed_attach_size = $config->allowed_attach_size * 1024 * 1024; - if($allowed_filesize < filesize($file_info['tmp_name'])) - { - throw new Rhymix\Framework\Exception('msg_exceeds_limit_size'); - } - - // Get total size of all attachements - $size_args = new stdClass; - $size_args->upload_target_srl = $upload_target_srl; - $output = executeQuery('file.getAttachedFileSize', $size_args); - $attached_size = (int)$output->data->attached_size + filesize($file_info['tmp_name']); - if($attached_size > $allowed_attach_size) - { - throw new Rhymix\Framework\Exception('msg_exceeds_limit_size'); - } // Check image dimensions if($config->max_image_size_action && ($config->max_image_width || $config->max_image_height)) { - if(in_array($extension, array('gif', 'jpg', 'png', 'webp', 'bmp'))) + if(in_array($extension, array('gif', 'jpg', 'jpeg', 'png', 'webp', 'bmp'))) { if ($image_info = @getimagesize($file_info['tmp_name'])) { @@ -948,12 +931,49 @@ class fileController extends file } else { - // TODO + $resize_width = $image_width; + $resize_height = $image_height; + if ($config->max_image_width > 0 && $image_width > $config->max_image_width) + { + $resize_width = $config->max_image_width; + $resize_height = $image_height * ($config->max_image_width / $image_width); + } + if ($config->max_image_height > 0 && $resize_height > $config->max_image_height) + { + $resize_width = $resize_width * ($config->max_image_height / $resize_height); + $resize_height = $config->max_image_height; + } + $target_type = ($extension === 'webp' || $extension === 'bmp') ? 'jpg' : $extension; + $resize_result = FileHandler::createImageFile($file_info['tmp_name'], $file_info['tmp_name'] . '.resized', intval($resize_width), intval($resize_height), $target_type); + if ($resize_result) + { + $file_info['tmp_name'] = $file_info['tmp_name'] . '.resized'; + $file_info['size'] = filesize($file_info['tmp_name']); + $file_info['resized'] = true; + } } } } } } + + // Check file size + $file_size = filesize($file_info['tmp_name']); + $allowed_filesize = $config->allowed_filesize * 1024 * 1024; + $allowed_attach_size = $config->allowed_attach_size * 1024 * 1024; + if($allowed_filesize < $file_size) + { + throw new Rhymix\Framework\Exception('msg_exceeds_limit_size'); + } + + // Get total size of all attachements + $size_args = new stdClass; + $size_args->upload_target_srl = $upload_target_srl; + $output = executeQuery('file.getAttachedFileSize', $size_args); + if($allowed_attach_size < intval($output->data->attached_size) + $file_size) + { + throw new Rhymix\Framework\Exception('msg_exceeds_limit_size'); + } } // Get file_srl @@ -992,7 +1012,7 @@ class fileController extends file } // Move the file - if($manual_insert) + if($manual_insert && !$file_info['resized']) { @copy($file_info['tmp_name'], $filename); if(!file_exists($filename)) @@ -1004,7 +1024,7 @@ class fileController extends file } } } - elseif(starts_with(RX_BASEDIR . 'files/attach/chunks/', $file_info['tmp_name'])) + elseif(starts_with(RX_BASEDIR . 'files/attach/chunks/', $file_info['tmp_name']) || $file_info['resized']) { if (!Rhymix\Framework\Storage::move($file_info['tmp_name'], $filename)) { From 62eb21abbb15ae5aa13ff465dd77e1ca72e350ae Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 1 Aug 2019 02:21:04 +0900 Subject: [PATCH 06/18] Separate image check into its own method and clean up --- modules/file/file.controller.php | 141 ++++++++++++++++++------------- 1 file changed, 80 insertions(+), 61 deletions(-) diff --git a/modules/file/file.controller.php b/modules/file/file.controller.php index fade0277e..d88a6fdd7 100644 --- a/modules/file/file.controller.php +++ b/modules/file/file.controller.php @@ -893,68 +893,9 @@ class fileController extends file } // Check image dimensions - if($config->max_image_size_action && ($config->max_image_width || $config->max_image_height)) + if(in_array($extension, array('gif', 'jpg', 'jpeg', 'png', 'webp', 'bmp'))) { - if(in_array($extension, array('gif', 'jpg', 'jpeg', 'png', 'webp', 'bmp'))) - { - if ($image_info = @getimagesize($file_info['tmp_name'])) - { - $image_width = $image_info[0]; - $image_height = $image_info[1]; - $exceeded = false; - if ($config->max_image_width > 0 && $image_width > $config->max_image_width) - { - $exceeded = true; - } - elseif ($config->max_image_height > 0 && $image_height > $config->max_image_height) - { - $exceeded = true; - } - - if ($exceeded) - { - if ($config->max_image_size_action === 'block') - { - if ($config->max_image_width && $config->max_image_height) - { - $message = sprintf(lang('msg_exceeds_max_image_size'), $config->max_image_width, $config->max_image_height); - } - elseif ($config->max_image_width) - { - $message = sprintf(lang('msg_exceeds_max_image_width'), $config->max_image_width); - } - else - { - $message = sprintf(lang('msg_exceeds_max_image_height'), $config->max_image_height); - } - throw new Rhymix\Framework\Exception($message); - } - else - { - $resize_width = $image_width; - $resize_height = $image_height; - if ($config->max_image_width > 0 && $image_width > $config->max_image_width) - { - $resize_width = $config->max_image_width; - $resize_height = $image_height * ($config->max_image_width / $image_width); - } - if ($config->max_image_height > 0 && $resize_height > $config->max_image_height) - { - $resize_width = $resize_width * ($config->max_image_height / $resize_height); - $resize_height = $config->max_image_height; - } - $target_type = ($extension === 'webp' || $extension === 'bmp') ? 'jpg' : $extension; - $resize_result = FileHandler::createImageFile($file_info['tmp_name'], $file_info['tmp_name'] . '.resized', intval($resize_width), intval($resize_height), $target_type); - if ($resize_result) - { - $file_info['tmp_name'] = $file_info['tmp_name'] . '.resized'; - $file_info['size'] = filesize($file_info['tmp_name']); - $file_info['resized'] = true; - } - } - } - } - } + $file_info = $this->checkUploadedImage($file_info, $config); } // Check file size @@ -1081,6 +1022,84 @@ class fileController extends file return $output; } + /** + * Check uploaded image + */ + public function checkUploadedImage($file_info, $config) + { + // Get image information + $image_info = @getimagesize($file_info['tmp_name']); + if (!$image_info) + { + return $file_info; + } + + // Check image size + if($config->max_image_size_action && ($config->max_image_width || $config->max_image_height)) + { + $image_width = $image_info[0]; + $image_height = $image_info[1]; + $exceeded = false; + if ($config->max_image_width > 0 && $image_width > $config->max_image_width) + { + $exceeded = true; + } + elseif ($config->max_image_height > 0 && $image_height > $config->max_image_height) + { + $exceeded = true; + } + + if ($exceeded) + { + // Block upload + if ($config->max_image_size_action === 'block') + { + if ($config->max_image_width && $config->max_image_height) + { + $message = sprintf(lang('msg_exceeds_max_image_size'), $config->max_image_width, $config->max_image_height); + } + elseif ($config->max_image_width) + { + $message = sprintf(lang('msg_exceeds_max_image_width'), $config->max_image_width); + } + else + { + $message = sprintf(lang('msg_exceeds_max_image_height'), $config->max_image_height); + } + + throw new Rhymix\Framework\Exception($message); + } + + // Resize automatically + else + { + $resize_width = $image_width; + $resize_height = $image_height; + if ($config->max_image_width > 0 && $image_width > $config->max_image_width) + { + $resize_width = $config->max_image_width; + $resize_height = $image_height * ($config->max_image_width / $image_width); + } + if ($config->max_image_height > 0 && $resize_height > $config->max_image_height) + { + $resize_width = $resize_width * ($config->max_image_height / $resize_height); + $resize_height = $config->max_image_height; + } + $target_type = ($extension === 'webp' || $extension === 'bmp') ? 'jpg' : $extension; + $resize_result = FileHandler::createImageFile($file_info['tmp_name'], $file_info['tmp_name'] . '.resized', intval($resize_width), intval($resize_height), $target_type); + if ($resize_result) + { + $file_info['tmp_name'] = $file_info['tmp_name'] . '.resized'; + $file_info['size'] = filesize($file_info['tmp_name']); + $file_info['resized'] = true; + } + } + } + } + + return $file_info; + } + /** * Delete the attachment * From bf93afd7e5624edafb01fbe5ddbbc1d29243657d Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 1 Aug 2019 03:13:58 +0900 Subject: [PATCH 07/18] Support converting BMP and WEBP images to JPG --- classes/file/FileHandler.class.php | 32 +++++++++++++++- modules/file/file.admin.controller.php | 2 + modules/file/file.controller.php | 51 +++++++++++++++++++------- modules/file/file.model.php | 3 ++ modules/file/lang/en.php | 4 ++ modules/file/lang/ko.php | 4 ++ modules/file/tpl/upload_config.html | 16 +++++++- 7 files changed, 95 insertions(+), 17 deletions(-) diff --git a/classes/file/FileHandler.class.php b/classes/file/FileHandler.class.php index e7ebb42d0..e82938635 100644 --- a/classes/file/FileHandler.class.php +++ b/classes/file/FileHandler.class.php @@ -527,6 +527,12 @@ class FileHandler case '6' : $type = 'bmp'; break; + case '8' : + $type = 'wbmp'; + break; + case '18' : + $type = 'webp'; + break; default : return; } @@ -603,13 +609,24 @@ class FileHandler $source = @imagecreatefrompng($source_file); } break; - case 'wbmp' : case 'bmp' : + if(function_exists('imagecreatefrombmp')) + { + $source = @imagecreatefrombmp($source_file); + } + break; + case 'wbmp' : if(function_exists('imagecreatefromwbmp')) { $source = @imagecreatefromwbmp($source_file); } break; + case 'webp' : + if(function_exists('imagecreatefromwebp')) + { + $source = @imagecreatefromwebp($source_file); + } + break; } if(!$source) @@ -665,13 +682,24 @@ class FileHandler $output = imagepng($thumb, $target_file, 9); } break; - case 'wbmp' : case 'bmp' : + if(function_exists('imagebmp')) + { + $output = imagebmp($thumb, $target_file, 100); + } + break; + case 'wbmp' : if(function_exists('imagewbmp')) { $output = imagewbmp($thumb, $target_file, 100); } break; + case 'webp' : + if(function_exists('imagewebp')) + { + $output = imagewebp($thumb, $target_file, 100); + } + break; } imagedestroy($thumb); diff --git a/modules/file/file.admin.controller.php b/modules/file/file.admin.controller.php index 6775f990a..8e2fbe3ee 100644 --- a/modules/file/file.admin.controller.php +++ b/modules/file/file.admin.controller.php @@ -69,6 +69,8 @@ class fileAdminController extends file $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') ?: ''; + $config->image_autoconv['bmp2jpg'] = Context::get('image_autoconv_bmp2jpg') === 'Y' ? true : false; + $config->image_autoconv['webp2jpg'] = Context::get('image_autoconv_webp2jpg') === 'Y' ? true : false; // Check maximum file size if (PHP_INT_SIZE < 8) diff --git a/modules/file/file.controller.php b/modules/file/file.controller.php index d88a6fdd7..837f94b68 100644 --- a/modules/file/file.controller.php +++ b/modules/file/file.controller.php @@ -863,12 +863,15 @@ class fileController extends file // Sanitize filename $file_info['name'] = Rhymix\Framework\Filters\FilenameFilter::clean($file_info['name']); - $file_info['resized'] = false; // Get extension $extension = explode('.', $file_info['name']) ?: array(''); $extension = strtolower(array_pop($extension)); + // Add extra fields to file info array + $file_info['extension'] = $extension; + $file_info['resized'] = false; + // Check file type, size, and other attributes if(!$manual_insert && !$this->user->isAdmin()) { @@ -892,7 +895,7 @@ class fileController extends file } } - // Check image dimensions + // Check image type and size if(in_array($extension, array('gif', 'jpg', 'jpeg', 'png', 'webp', 'bmp'))) { $file_info = $this->checkUploadedImage($file_info, $config); @@ -953,7 +956,7 @@ class fileController extends file } // Move the file - if($manual_insert && !$file_info['resized']) + if($manual_insert && !$file_info['converted']) { @copy($file_info['tmp_name'], $filename); if(!file_exists($filename)) @@ -965,7 +968,7 @@ class fileController extends file } } } - elseif(starts_with(RX_BASEDIR . 'files/attach/chunks/', $file_info['tmp_name']) || $file_info['resized']) + elseif(starts_with(RX_BASEDIR . 'files/attach/chunks/', $file_info['tmp_name']) || $file_info['converted']) { if (!Rhymix\Framework\Storage::move($file_info['tmp_name'], $filename)) { @@ -1034,11 +1037,24 @@ class fileController extends file return $file_info; } + $image_width = $image_info[0]; + $image_height = $image_info[1]; + $image_type = $image_info[2]; + $convert = false; + + // Check image type + if($config->image_autoconv['bmp2jpg'] && function_exists('imagebmp') && $image_type === 6) + { + $convert = array($image_width, $image_height, 'jpg'); + } + if($config->image_autoconv['webp2jpg'] && function_exists('imagewebp') && $image_type === 18) + { + $convert = array($image_width, $image_height, 'jpg'); + } + // Check image size if($config->max_image_size_action && ($config->max_image_width || $config->max_image_height)) { - $image_width = $image_info[0]; - $image_height = $image_info[1]; $exceeded = false; if ($config->max_image_width > 0 && $image_width > $config->max_image_width) { @@ -1085,18 +1101,25 @@ class fileController extends file $resize_width = $resize_width * ($config->max_image_height / $resize_height); $resize_height = $config->max_image_height; } - $target_type = ($extension === 'webp' || $extension === 'bmp') ? 'jpg' : $extension; - $resize_result = FileHandler::createImageFile($file_info['tmp_name'], $file_info['tmp_name'] . '.resized', intval($resize_width), intval($resize_height), $target_type); - if ($resize_result) - { - $file_info['tmp_name'] = $file_info['tmp_name'] . '.resized'; - $file_info['size'] = filesize($file_info['tmp_name']); - $file_info['resized'] = true; - } + $target_type = in_array($image_type, array(6, 8, 18)) ? 'jpg' : $file_info['extension']; + $convert = array(intval($resize_width), intval($resize_height), $target_type); } } } + // Convert image if necessary + if ($convert) + { + $result = FileHandler::createImageFile($file_info['tmp_name'], $file_info['tmp_name'] . '.conv', $convert[0], $convert[1], $convert[2]); + if ($result) + { + $file_info['name'] = preg_replace('/\.' . preg_quote($file_info['extension'], '/') . '$/i', '.' . $convert[2], $file_info['name']); + $file_info['tmp_name'] = $file_info['tmp_name'] . '.conv'; + $file_info['size'] = filesize($file_info['tmp_name']); + $file_info['converted'] = true; + } + } + return $file_info; } diff --git a/modules/file/file.model.php b/modules/file/file.model.php index 25e85fed7..888bf08a1 100644 --- a/modules/file/file.model.php +++ b/modules/file/file.model.php @@ -192,6 +192,7 @@ class fileModel extends file $config->max_image_width = $file_config->max_image_width; $config->max_image_height = $file_config->max_image_height; $config->max_image_size_action = $file_config->max_image_size_action; + $config->image_autoconv = $file_config->image_autoconv; $config->download_grant = $file_config->download_grant; $config->allow_outlink = $file_config->allow_outlink; $config->allow_outlink_site = $file_config->allow_outlink_site; @@ -209,6 +210,7 @@ class fileModel extends file if(!$config->max_image_width) $config->max_image_width = $file_module_config->max_image_width; if(!$config->max_image_height) $config->max_image_height = $file_module_config->max_image_height; if(!$config->max_image_size_action) $config->max_image_size_action = $file_module_config->max_image_size_action; + if(!$config->image_autoconv) $config->image_autoconv = $file_module_config->image_autoconv; // Default setting if not exists if(!$config->allowed_filesize) $config->allowed_filesize = '2'; @@ -217,6 +219,7 @@ class fileModel extends file if(!$config->allow_outlink) $config->allow_outlink = 'Y'; if(!$config->download_grant) $config->download_grant = array(); if(!$config->inline_download_format) $config->inline_download_format = array(); + if(!$config->image_autoconv) $config->image_autoconv = array(); return $config; } diff --git a/modules/file/lang/en.php b/modules/file/lang/en.php index 59ca07299..7878e8893 100644 --- a/modules/file/lang/en.php +++ b/modules/file/lang/en.php @@ -21,6 +21,9 @@ $lang->max_image_size = 'Maximum Image Size'; $lang->max_image_size_action_nothing = 'If exceeded, do nothing'; $lang->max_image_size_action_block = 'If exceeded, block upload'; $lang->max_image_size_action_resize = 'If exceeded, resize automatically'; +$lang->image_autoconv = 'Auto-Convert Image'; +$lang->image_autoconv_bmp2jpg = 'BMP → JPG'; +$lang->image_autoconv_webp2jpg = 'WEBP → JPG'; $lang->inline_download_format = 'Open in current window'; $lang->inline_download_image = 'Image'; $lang->inline_download_audio = 'Audio'; @@ -39,6 +42,7 @@ $lang->about_allowed_attach_size_global = 'This is the global limit on the combi $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_max_image_size = 'You can limit the maximum width and height of uploaded images.'; +$lang->about_image_autoconv = 'Automatically convert types of images that often cause trouble or waste disk space into other types.'; $lang->cmd_delete_checked_file = 'Delete Selected Item(s)'; $lang->cmd_move_to_document = 'Move to Document'; $lang->cmd_download = 'Download'; diff --git a/modules/file/lang/ko.php b/modules/file/lang/ko.php index cc17f19b7..d914da0f8 100644 --- a/modules/file/lang/ko.php +++ b/modules/file/lang/ko.php @@ -21,6 +21,9 @@ $lang->max_image_size = '이미지 크기 제한'; $lang->max_image_size_action_nothing = '초과시 아무 것도 하지 않음'; $lang->max_image_size_action_block = '초과시 업로드 금지'; $lang->max_image_size_action_resize = '초과시 자동 크기 조정'; +$lang->image_autoconv = '이미지 자동 변환'; +$lang->image_autoconv_bmp2jpg = 'BMP → JPG'; +$lang->image_autoconv_webp2jpg = 'WEBP → JPG'; $lang->inline_download_format = '다운로드시 현재 창 사용'; $lang->inline_download_image = '이미지'; $lang->inline_download_audio = '오디오'; @@ -39,6 +42,7 @@ $lang->about_allowed_attach_size_global = '관리자를 포함하여 사이트 $lang->about_allowed_size_limits = 'IE9 이하, 구버전 안드로이드 등에서는 php.ini에서 지정한 %sB로 제한됩니다.'; $lang->about_allowed_filetypes = '"*.확장자"로 지정할 수 있고 ";" 으로 여러 개 지정이 가능합니다. 예) *.* or *.jpg;*.gif;'; $lang->about_max_image_size = '이미지 파일의 가로세로 크기를 제한할 수 있습니다.'; +$lang->about_image_autoconv = '종종 문제를 일으키거나 용량을 낭비하는 이미지 타입을 다른 타입으로 자동 변환합니다.'; $lang->cmd_delete_checked_file = '선택항목 삭제'; $lang->cmd_move_to_document = '문서로 이동'; $lang->cmd_download = '다운로드'; diff --git a/modules/file/tpl/upload_config.html b/modules/file/tpl/upload_config.html index 52bd3ff47..29729c6e9 100644 --- a/modules/file/tpl/upload_config.html +++ b/modules/file/tpl/upload_config.html @@ -23,7 +23,7 @@
    - +
    × px   @@ -35,6 +35,20 @@

    {$lang->about_max_image_size}

    +
    + +
    + + +

    {$lang->about_image_autoconv}

    +
    +
    From 8e3f489744a6a6df1bb95616eb34c5f865ecf4aa Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 1 Aug 2019 03:39:27 +0900 Subject: [PATCH 08/18] Edit message about max image size --- modules/file/lang/en.php | 6 +++--- modules/file/lang/ko.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/file/lang/en.php b/modules/file/lang/en.php index 7878e8893..67f86b890 100644 --- a/modules/file/lang/en.php +++ b/modules/file/lang/en.php @@ -23,7 +23,7 @@ $lang->max_image_size_action_block = 'If exceeded, block upload'; $lang->max_image_size_action_resize = 'If exceeded, resize automatically'; $lang->image_autoconv = 'Auto-Convert Image'; $lang->image_autoconv_bmp2jpg = 'BMP → JPG'; -$lang->image_autoconv_webp2jpg = 'WEBP → JPG'; +$lang->image_autoconv_webp2jpg = 'WebP → JPG'; $lang->inline_download_format = 'Open in current window'; $lang->inline_download_image = 'Image'; $lang->inline_download_audio = 'Audio'; @@ -41,8 +41,8 @@ $lang->about_allowed_filesize_global = 'This is the global limit on the size of $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_max_image_size = 'You can limit the maximum width and height of uploaded images.'; -$lang->about_image_autoconv = 'Automatically convert types of images that often cause trouble or waste disk space into other types.'; +$lang->about_max_image_size = 'You can limit the maximum width and/or height of uploaded images.'; +$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.'; $lang->cmd_delete_checked_file = 'Delete Selected Item(s)'; $lang->cmd_move_to_document = 'Move to Document'; $lang->cmd_download = 'Download'; diff --git a/modules/file/lang/ko.php b/modules/file/lang/ko.php index d914da0f8..f692b6578 100644 --- a/modules/file/lang/ko.php +++ b/modules/file/lang/ko.php @@ -23,7 +23,7 @@ $lang->max_image_size_action_block = '초과시 업로드 금지'; $lang->max_image_size_action_resize = '초과시 자동 크기 조정'; $lang->image_autoconv = '이미지 자동 변환'; $lang->image_autoconv_bmp2jpg = 'BMP → JPG'; -$lang->image_autoconv_webp2jpg = 'WEBP → JPG'; +$lang->image_autoconv_webp2jpg = 'WebP → JPG'; $lang->inline_download_format = '다운로드시 현재 창 사용'; $lang->inline_download_image = '이미지'; $lang->inline_download_audio = '오디오'; @@ -41,8 +41,8 @@ $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_max_image_size = '이미지 파일의 가로세로 크기를 제한할 수 있습니다.'; -$lang->about_image_autoconv = '종종 문제를 일으키거나 용량을 낭비하는 이미지 타입을 다른 타입으로 자동 변환합니다.'; +$lang->about_max_image_size = '이미지 파일의 가로세로 크기를 제한할 수 있습니다.
    가로세로 중 한 쪽만 제한하거나, 양쪽 모두 제한할 수도 있습니다.'; +$lang->about_image_autoconv = '종종 문제를 일으키거나 용량을 낭비하는 이미지 타입을 다른 타입으로 자동 변환합니다.
    WebP 이미지에 JPG 확장자가 잘못 부여된 경우에도 변환할 수 있습니다.'; $lang->cmd_delete_checked_file = '선택항목 삭제'; $lang->cmd_move_to_document = '문서로 이동'; $lang->cmd_download = '다운로드'; From 2b67798cab66f08c06108f9f401048324b9af435 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 1 Aug 2019 03:49:16 +0900 Subject: [PATCH 09/18] Add option to adjust quality of JPG output --- classes/file/FileHandler.class.php | 11 ++++++----- modules/file/file.controller.php | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/classes/file/FileHandler.class.php b/classes/file/FileHandler.class.php index e82938635..ca04eacbc 100644 --- a/classes/file/FileHandler.class.php +++ b/classes/file/FileHandler.class.php @@ -479,9 +479,10 @@ class FileHandler * @param int $resize_height Height to resize * @param string $target_type If $target_type is set (gif, jpg, png, bmp), result image will be saved as target type * @param string $thumbnail_type Thumbnail type(crop, ratio) + * @param int $quality Compression ratio (0~9) * @return bool TRUE: success, FALSE: failed */ - public static function createImageFile($source_file, $target_file, $resize_width = 0, $resize_height = 0, $target_type = '', $thumbnail_type = 'crop') + public static function createImageFile($source_file, $target_file, $resize_width = 0, $resize_height = 0, $target_type = '', $thumbnail_type = 'crop', $quality = 100) { // check params if (($source_file = self::exists($source_file)) === FALSE) @@ -673,7 +674,7 @@ class FileHandler case 'jpg' : if(function_exists('imagejpeg')) { - $output = imagejpeg($thumb, $target_file, 100); + $output = imagejpeg($thumb, $target_file, $quality); } break; case 'png' : @@ -685,19 +686,19 @@ class FileHandler case 'bmp' : if(function_exists('imagebmp')) { - $output = imagebmp($thumb, $target_file, 100); + $output = imagebmp($thumb, $target_file); } break; case 'wbmp' : if(function_exists('imagewbmp')) { - $output = imagewbmp($thumb, $target_file, 100); + $output = imagewbmp($thumb, $target_file); } break; case 'webp' : if(function_exists('imagewebp')) { - $output = imagewebp($thumb, $target_file, 100); + $output = imagewebp($thumb, $target_file); } break; } diff --git a/modules/file/file.controller.php b/modules/file/file.controller.php index 837f94b68..8c78ccf1c 100644 --- a/modules/file/file.controller.php +++ b/modules/file/file.controller.php @@ -1110,7 +1110,8 @@ class fileController extends file // Convert image if necessary if ($convert) { - $result = FileHandler::createImageFile($file_info['tmp_name'], $file_info['tmp_name'] . '.conv', $convert[0], $convert[1], $convert[2]); + $quality = 75; + $result = FileHandler::createImageFile($file_info['tmp_name'], $file_info['tmp_name'] . '.conv', $convert[0], $convert[1], $convert[2], 'crop', $quality); if ($result) { $file_info['name'] = preg_replace('/\.' . preg_quote($file_info['extension'], '/') . '$/i', '.' . $convert[2], $file_info['name']); From b9208a682b78a436733849e229b4e44557d81484 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 1 Aug 2019 14:28:29 +0900 Subject: [PATCH 10/18] Allow customization of resize and conversion quality --- modules/file/file.admin.controller.php | 2 ++ modules/file/file.controller.php | 9 ++++----- modules/file/file.model.php | 6 ++++++ modules/file/lang/en.php | 1 + modules/file/lang/ko.php | 1 + modules/file/tpl/upload_config.html | 12 ++++++++++++ 6 files changed, 26 insertions(+), 5 deletions(-) diff --git a/modules/file/file.admin.controller.php b/modules/file/file.admin.controller.php index 8e2fbe3ee..01851a752 100644 --- a/modules/file/file.admin.controller.php +++ b/modules/file/file.admin.controller.php @@ -69,8 +69,10 @@ class fileAdminController extends file $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') ?: ''; + $config->max_image_size_quality = max(50, min(100, intval(Context::get('max_image_size_quality')))); $config->image_autoconv['bmp2jpg'] = Context::get('image_autoconv_bmp2jpg') === 'Y' ? true : false; $config->image_autoconv['webp2jpg'] = Context::get('image_autoconv_webp2jpg') === 'Y' ? true : false; + $config->image_autoconv_quality = max(50, min(100, intval(Context::get('image_autoconv_quality')))); // Check maximum file size if (PHP_INT_SIZE < 8) diff --git a/modules/file/file.controller.php b/modules/file/file.controller.php index 8c78ccf1c..1848a6f1c 100644 --- a/modules/file/file.controller.php +++ b/modules/file/file.controller.php @@ -1045,11 +1045,11 @@ class fileController extends file // Check image type if($config->image_autoconv['bmp2jpg'] && function_exists('imagebmp') && $image_type === 6) { - $convert = array($image_width, $image_height, 'jpg'); + $convert = array($image_width, $image_height, 'jpg', $config->image_autoconv_quality ?: 75); } if($config->image_autoconv['webp2jpg'] && function_exists('imagewebp') && $image_type === 18) { - $convert = array($image_width, $image_height, 'jpg'); + $convert = array($image_width, $image_height, 'jpg', $config->image_autoconv_quality ?: 75); } // Check image size @@ -1102,7 +1102,7 @@ class fileController extends file $resize_height = $config->max_image_height; } $target_type = in_array($image_type, array(6, 8, 18)) ? 'jpg' : $file_info['extension']; - $convert = array(intval($resize_width), intval($resize_height), $target_type); + $convert = array(intval($resize_width), intval($resize_height), $target_type, $config->max_image_size_quality ?: 75); } } } @@ -1110,8 +1110,7 @@ class fileController extends file // Convert image if necessary if ($convert) { - $quality = 75; - $result = FileHandler::createImageFile($file_info['tmp_name'], $file_info['tmp_name'] . '.conv', $convert[0], $convert[1], $convert[2], 'crop', $quality); + $result = FileHandler::createImageFile($file_info['tmp_name'], $file_info['tmp_name'] . '.conv', $convert[0], $convert[1], $convert[2], 'crop', $convert[3]); if ($result) { $file_info['name'] = preg_replace('/\.' . preg_quote($file_info['extension'], '/') . '$/i', '.' . $convert[2], $file_info['name']); diff --git a/modules/file/file.model.php b/modules/file/file.model.php index 888bf08a1..3652cf18f 100644 --- a/modules/file/file.model.php +++ b/modules/file/file.model.php @@ -192,7 +192,9 @@ class fileModel extends file $config->max_image_width = $file_config->max_image_width; $config->max_image_height = $file_config->max_image_height; $config->max_image_size_action = $file_config->max_image_size_action; + $config->max_image_size_quality = $file_config->max_image_size_quality; $config->image_autoconv = $file_config->image_autoconv; + $config->image_autoconv_quality = $file_config->image_autoconv_quality; $config->download_grant = $file_config->download_grant; $config->allow_outlink = $file_config->allow_outlink; $config->allow_outlink_site = $file_config->allow_outlink_site; @@ -210,7 +212,9 @@ class fileModel extends file if(!$config->max_image_width) $config->max_image_width = $file_module_config->max_image_width; if(!$config->max_image_height) $config->max_image_height = $file_module_config->max_image_height; if(!$config->max_image_size_action) $config->max_image_size_action = $file_module_config->max_image_size_action; + if(!$config->max_image_size_quality) $config->max_image_size_quality = $file_module_config->max_image_size_quality; if(!$config->image_autoconv) $config->image_autoconv = $file_module_config->image_autoconv; + if(!$config->image_autoconv_quality) $config->image_autoconv_quality = $file_module_config->image_autoconv_quality; // Default setting if not exists if(!$config->allowed_filesize) $config->allowed_filesize = '2'; @@ -219,7 +223,9 @@ class fileModel extends file if(!$config->allow_outlink) $config->allow_outlink = 'Y'; if(!$config->download_grant) $config->download_grant = array(); if(!$config->inline_download_format) $config->inline_download_format = array(); + if(!$config->max_image_size_quality) $config->max_image_size_quality = 75; if(!$config->image_autoconv) $config->image_autoconv = array(); + if(!$config->image_autoconv_quality) $config->image_autoconv_quality = 75; return $config; } diff --git a/modules/file/lang/en.php b/modules/file/lang/en.php index 67f86b890..430ec89e3 100644 --- a/modules/file/lang/en.php +++ b/modules/file/lang/en.php @@ -21,6 +21,7 @@ $lang->max_image_size = 'Maximum Image Size'; $lang->max_image_size_action_nothing = 'If exceeded, do nothing'; $lang->max_image_size_action_block = 'If exceeded, block upload'; $lang->max_image_size_action_resize = 'If exceeded, resize automatically'; +$lang->image_resize_quality = 'Quality'; $lang->image_autoconv = 'Auto-Convert Image'; $lang->image_autoconv_bmp2jpg = 'BMP → JPG'; $lang->image_autoconv_webp2jpg = 'WebP → JPG'; diff --git a/modules/file/lang/ko.php b/modules/file/lang/ko.php index f692b6578..060db37b9 100644 --- a/modules/file/lang/ko.php +++ b/modules/file/lang/ko.php @@ -21,6 +21,7 @@ $lang->max_image_size = '이미지 크기 제한'; $lang->max_image_size_action_nothing = '초과시 아무 것도 하지 않음'; $lang->max_image_size_action_block = '초과시 업로드 금지'; $lang->max_image_size_action_resize = '초과시 자동 크기 조정'; +$lang->image_resize_quality = '화질'; $lang->image_autoconv = '이미지 자동 변환'; $lang->image_autoconv_bmp2jpg = 'BMP → JPG'; $lang->image_autoconv_webp2jpg = 'WebP → JPG'; diff --git a/modules/file/tpl/upload_config.html b/modules/file/tpl/upload_config.html index 29729c6e9..c2123462b 100644 --- a/modules/file/tpl/upload_config.html +++ b/modules/file/tpl/upload_config.html @@ -32,6 +32,12 @@ +

    {$lang->about_max_image_size}

    @@ -46,6 +52,12 @@ {$lang->image_autoconv_webp2jpg} +

    {$lang->about_image_autoconv}

  • From f3761fd93486693b406a0a857c6db72c49902b62 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 1 Aug 2019 14:35:25 +0900 Subject: [PATCH 11/18] Make image auto-conversion apply to the administrator, too --- modules/file/file.controller.php | 24 +++++++++++++++--------- modules/file/lang/en.php | 4 ++-- modules/file/lang/ko.php | 6 +++--- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/modules/file/file.controller.php b/modules/file/file.controller.php index 1848a6f1c..80ff3a83d 100644 --- a/modules/file/file.controller.php +++ b/modules/file/file.controller.php @@ -872,12 +872,13 @@ class fileController extends file $file_info['extension'] = $extension; $file_info['resized'] = false; - // Check file type, size, and other attributes + // Get file module configuration + $oFileModel = getModel('file'); + $config = $oFileModel->getFileConfig($module_srl); + + // Check file type if(!$manual_insert && !$this->user->isAdmin()) { - // Get file module configuration - $oFileModel = getModel('file'); - $config = $oFileModel->getFileConfig($module_srl); // Check file type if(isset($config->allowed_filetypes) && $config->allowed_filetypes !== '*.*') @@ -894,14 +895,20 @@ class fileController extends file throw new Rhymix\Framework\Exception('msg_not_allowed_filetype'); } } - - // Check image type and size + } + + // Check image type and size + if(!$manual_insert) + { if(in_array($extension, array('gif', 'jpg', 'jpeg', 'png', 'webp', 'bmp'))) { $file_info = $this->checkUploadedImage($file_info, $config); } + } - // Check file size + // Check file size + if(!$manual_insert && !$this->user->isAdmin()) + { $file_size = filesize($file_info['tmp_name']); $allowed_filesize = $config->allowed_filesize * 1024 * 1024; $allowed_attach_size = $config->allowed_attach_size * 1024 * 1024; @@ -910,7 +917,6 @@ class fileController extends file throw new Rhymix\Framework\Exception('msg_exceeds_limit_size'); } - // Get total size of all attachements $size_args = new stdClass; $size_args->upload_target_srl = $upload_target_srl; $output = executeQuery('file.getAttachedFileSize', $size_args); @@ -1053,7 +1059,7 @@ class fileController extends file } // Check image size - if($config->max_image_size_action && ($config->max_image_width || $config->max_image_height)) + if($config->max_image_size_action && ($config->max_image_width || $config->max_image_height) && !$this->user->isAdmin()) { $exceeded = false; if ($config->max_image_width > 0 && $image_width > $config->max_image_width) diff --git a/modules/file/lang/en.php b/modules/file/lang/en.php index 430ec89e3..0fdc23d03 100644 --- a/modules/file/lang/en.php +++ b/modules/file/lang/en.php @@ -42,8 +42,8 @@ $lang->about_allowed_filesize_global = 'This is the global limit on the size of $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_max_image_size = 'You can limit the maximum width and/or height of uploaded images.'; -$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.'; +$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->cmd_delete_checked_file = 'Delete Selected Item(s)'; $lang->cmd_move_to_document = 'Move to Document'; $lang->cmd_download = 'Download'; diff --git a/modules/file/lang/ko.php b/modules/file/lang/ko.php index 060db37b9..d24c371e4 100644 --- a/modules/file/lang/ko.php +++ b/modules/file/lang/ko.php @@ -38,12 +38,12 @@ $lang->about_allow_outlink_format = '파일 외부 링크 설정에 상관없이 $lang->about_allow_outlink_site = '파일 외부 링크 설정에 상관없이 허용하는 사이트 주소입니다.
    여러 개 입력시 줄을 바꿔서 구분해 주세요. 예) https://www.rhymix.org/'; $lang->about_allowed_filesize = '각 파일의 용량을 제한할 수 있습니다.
    관리자에게는 이 게시판의 제한과 파일 모듈의 제한 중 높은 쪽이 적용됩니다.'; $lang->about_allowed_attach_size = '하나의 문서에 첨부할 수 있는 최대 용량을 제한할 수 있습니다.
    관리자에게는 이 게시판의 제한과 파일 모듈의 제한 중 높은 쪽이 적용됩니다.'; -$lang->about_allowed_filesize_global = '관리자를 포함하여 사이트 전체에 적용되는 파일 크기 제한입니다.'; +$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_max_image_size = '이미지 파일의 가로세로 크기를 제한할 수 있습니다.
    가로세로 중 한 쪽만 제한하거나, 양쪽 모두 제한할 수도 있습니다.'; -$lang->about_image_autoconv = '종종 문제를 일으키거나 용량을 낭비하는 이미지 타입을 다른 타입으로 자동 변환합니다.
    WebP 이미지에 JPG 확장자가 잘못 부여된 경우에도 변환할 수 있습니다.'; +$lang->about_max_image_size = '이미지 파일의 가로, 세로, 또는 가로세로 크기를 모두 제한할 수 있습니다.
    관리자가 업로드한 파일에는 적용되지 않습니다.'; +$lang->about_image_autoconv = '종종 문제를 일으키거나 용량을 낭비하는 이미지 타입을 다른 타입으로 자동 변환합니다.
    WebP 이미지에 JPG 확장자가 잘못 부여된 경우에도 변환할 수 있습니다.
    관리자가 업로드한 파일에도 적용됩니다.'; $lang->cmd_delete_checked_file = '선택항목 삭제'; $lang->cmd_move_to_document = '문서로 이동'; $lang->cmd_download = '다운로드'; From 8c242327a8ced2fb479671b46a27acf3bccda8c9 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 1 Aug 2019 15:25:12 +0900 Subject: [PATCH 12/18] Implement auto-rotation of uploaded images --- classes/file/FileHandler.class.php | 131 ++++++++++++++----------- modules/file/file.admin.controller.php | 2 + modules/file/file.controller.php | 40 +++++++- modules/file/file.model.php | 5 + modules/file/lang/en.php | 2 + modules/file/lang/ko.php | 2 + modules/file/tpl/upload_config.html | 20 ++++ 7 files changed, 141 insertions(+), 61 deletions(-) diff --git a/classes/file/FileHandler.class.php b/classes/file/FileHandler.class.php index ca04eacbc..47ce5b4fb 100644 --- a/classes/file/FileHandler.class.php +++ b/classes/file/FileHandler.class.php @@ -480,9 +480,10 @@ class FileHandler * @param string $target_type If $target_type is set (gif, jpg, png, bmp), result image will be saved as target type * @param string $thumbnail_type Thumbnail type(crop, ratio) * @param int $quality Compression ratio (0~9) + * @param int $rotate Rotation degrees (0~360) * @return bool TRUE: success, FALSE: failed */ - public static function createImageFile($source_file, $target_file, $resize_width = 0, $resize_height = 0, $target_type = '', $thumbnail_type = 'crop', $quality = 100) + public static function createImageFile($source_file, $target_file, $resize_width = 0, $resize_height = 0, $target_type = '', $thumbnail_type = 'crop', $quality = 100, $rotate = 0) { // check params if (($source_file = self::exists($source_file)) === FALSE) @@ -544,49 +545,6 @@ class FileHandler } $target_type = strtolower($target_type); - // if original image is larger than specified size to resize, calculate the ratio - $width_per = ($resize_width > 0 && $width >= $resize_width) ? $resize_width / $width : 1; - $height_per = ($resize_height > 0 && $height >= $resize_height) ? $resize_height / $height : 1; - - $per = NULL; - if($thumbnail_type == 'ratio') - { - $per = ($width_per > $height_per) ? $height_per : $width_per; - $resize_width = $width * $per; - $resize_height = $height * $per; - } - else - { - $per = ($width_per < $height_per) ? $height_per : $width_per; - } - - // create temporary image with target size - $thumb = NULL; - if(function_exists('imagecreateTRUEcolor')) - { - $thumb = imagecreateTRUEcolor($resize_width, $resize_height); - } - else if(function_exists('imagecreate')) - { - $thumb = imagecreate($resize_width, $resize_height); - } - - if(!$thumb) - { - return FALSE; - } - - if($target_type == 'png' && function_exists('imagecolorallocatealpha') && function_exists('imagesavealpha') && function_exists('imagealphablending')) - { - imagefill($thumb, 0, 0, imagecolorallocatealpha($thumb, 0, 0, 0, 127)); - imagesavealpha($thumb, TRUE); - imagealphablending($thumb, TRUE); - } - else - { - imagefilledrectangle($thumb, 0, 0, $resize_width - 1, $resize_height - 1, imagecolorallocate($thumb, 255, 255, 255)); - } - // create temporary image having original type $source = NULL; switch($type) @@ -636,27 +594,86 @@ class FileHandler return FALSE; } - // resize original image and put it into temporary image - $new_width = (int) ($width * $per); - $new_height = (int) ($height * $per); - - $x = 0; - $y = 0; - if($thumbnail_type == 'crop') + // Rotate image + if ($rotate) { - $x = (int) ($resize_width / 2 - $new_width / 2); - $y = (int) ($resize_height / 2 - $new_height / 2); + $source = imagerotate($source, $rotate, 0); + $width = imagesx($source); + $height = imagesy($source); } - if(function_exists('imagecopyresampled')) + // If resize not needed, skip thumbnail generation + if ($width == $resize_width && $height == $resize_height) { - imagecopyresampled($thumb, $source, $x, $y, 0, 0, $new_width, $new_height, $width, $height); + $thumb = &$source; } else { - imagecopyresized($thumb, $source, $x, $y, 0, 0, $new_width, $new_height, $width, $height); - } + // if original image is larger than specified size to resize, calculate the ratio + $width_per = ($resize_width > 0 && $width >= $resize_width) ? $resize_width / $width : 1; + $height_per = ($resize_height > 0 && $height >= $resize_height) ? $resize_height / $height : 1; + $per = NULL; + if($thumbnail_type == 'ratio') + { + $per = ($width_per > $height_per) ? $height_per : $width_per; + $resize_width = $width * $per; + $resize_height = $height * $per; + } + else + { + $per = ($width_per < $height_per) ? $height_per : $width_per; + } + + // create temporary image with target size + $thumb = NULL; + if(function_exists('imagecreateTRUEcolor')) + { + $thumb = imagecreateTRUEcolor($resize_width, $resize_height); + } + else if(function_exists('imagecreate')) + { + $thumb = imagecreate($resize_width, $resize_height); + } + + if(!$thumb) + { + return FALSE; + } + + if($target_type == 'png' && function_exists('imagecolorallocatealpha') && function_exists('imagesavealpha') && function_exists('imagealphablending')) + { + imagefill($thumb, 0, 0, imagecolorallocatealpha($thumb, 0, 0, 0, 127)); + imagesavealpha($thumb, TRUE); + imagealphablending($thumb, TRUE); + } + else + { + imagefilledrectangle($thumb, 0, 0, $resize_width - 1, $resize_height - 1, imagecolorallocate($thumb, 255, 255, 255)); + } + + // resize original image and put it into temporary image + $new_width = (int) ($width * $per); + $new_height = (int) ($height * $per); + + $x = 0; + $y = 0; + if($thumbnail_type == 'crop') + { + $x = (int) ($resize_width / 2 - $new_width / 2); + $y = (int) ($resize_height / 2 - $new_height / 2); + } + + if(function_exists('imagecopyresampled')) + { + imagecopyresampled($thumb, $source, $x, $y, 0, 0, $new_width, $new_height, $width, $height); + } + else + { + imagecopyresized($thumb, $source, $x, $y, 0, 0, $new_width, $new_height, $width, $height); + } + } + // create directory self::makeDir(dirname($target_file)); diff --git a/modules/file/file.admin.controller.php b/modules/file/file.admin.controller.php index 01851a752..981205d0c 100644 --- a/modules/file/file.admin.controller.php +++ b/modules/file/file.admin.controller.php @@ -73,6 +73,8 @@ class fileAdminController extends file $config->image_autoconv['bmp2jpg'] = Context::get('image_autoconv_bmp2jpg') === 'Y' ? true : false; $config->image_autoconv['webp2jpg'] = Context::get('image_autoconv_webp2jpg') === 'Y' ? true : false; $config->image_autoconv_quality = max(50, min(100, intval(Context::get('image_autoconv_quality')))); + $config->image_autorotate = Context::get('image_autorotate') === 'Y' ? true : false; + $config->image_autorotate_quality = max(50, min(100, intval(Context::get('image_autorotate_quality')))); // Check maximum file size if (PHP_INT_SIZE < 8) diff --git a/modules/file/file.controller.php b/modules/file/file.controller.php index 80ff3a83d..328543fc8 100644 --- a/modules/file/file.controller.php +++ b/modules/file/file.controller.php @@ -1051,11 +1051,41 @@ class fileController extends file // Check image type if($config->image_autoconv['bmp2jpg'] && function_exists('imagebmp') && $image_type === 6) { - $convert = array($image_width, $image_height, 'jpg', $config->image_autoconv_quality ?: 75); + $convert = array($image_width, $image_height, 'jpg', $config->image_autoconv_quality ?: 75, 0); } if($config->image_autoconv['webp2jpg'] && function_exists('imagewebp') && $image_type === 18) { - $convert = array($image_width, $image_height, 'jpg', $config->image_autoconv_quality ?: 75); + $convert = array($image_width, $image_height, 'jpg', $config->image_autoconv_quality ?: 75, 0); + } + + // Check image rotation + if($config->image_autorotate && function_exists('exif_read_data')) + { + $exif = @exif_read_data($file_info['tmp_name']); + if($exif && isset($exif['Orientation'])) + { + switch ($exif['Orientation']) + { + case 3: $rotate = 180; break; + case 6: $rotate = 270; break; + case 8: $rotate = 90; break; + default: $rotate = 0; + } + if ($rotate) + { + $convert = $convert ?: array($image_width, $image_height, $file_info['extension']); + if ($rotate == 90 || $rotate == 270) + { + $image_height = $convert[0]; + $image_width = $convert[1]; + $convert[0] = $image_width; + $convert[1] = $image_height; + } + $convert[3] = $config->image_autorotate_quality ?: 75; + $convert[4] = $rotate; + } + } + unset($exif); } // Check image size @@ -1108,7 +1138,8 @@ class fileController extends file $resize_height = $config->max_image_height; } $target_type = in_array($image_type, array(6, 8, 18)) ? 'jpg' : $file_info['extension']; - $convert = array(intval($resize_width), intval($resize_height), $target_type, $config->max_image_size_quality ?: 75); + $rotate = ($convert && $convert[4]) ? $convert[4] : 0; + $convert = array(intval($resize_width), intval($resize_height), $target_type, $config->max_image_size_quality ?: 75, $rotate); } } } @@ -1116,12 +1147,13 @@ class fileController extends file // Convert image if necessary if ($convert) { - $result = FileHandler::createImageFile($file_info['tmp_name'], $file_info['tmp_name'] . '.conv', $convert[0], $convert[1], $convert[2], 'crop', $convert[3]); + $result = FileHandler::createImageFile($file_info['tmp_name'], $file_info['tmp_name'] . '.conv', $convert[0], $convert[1], $convert[2], 'crop', $convert[3], $convert[4]); if ($result) { $file_info['name'] = preg_replace('/\.' . preg_quote($file_info['extension'], '/') . '$/i', '.' . $convert[2], $file_info['name']); $file_info['tmp_name'] = $file_info['tmp_name'] . '.conv'; $file_info['size'] = filesize($file_info['tmp_name']); + $file_info['extension'] = $convert[2]; $file_info['converted'] = true; } } diff --git a/modules/file/file.model.php b/modules/file/file.model.php index 3652cf18f..ad562ef84 100644 --- a/modules/file/file.model.php +++ b/modules/file/file.model.php @@ -195,6 +195,8 @@ class fileModel extends file $config->max_image_size_quality = $file_config->max_image_size_quality; $config->image_autoconv = $file_config->image_autoconv; $config->image_autoconv_quality = $file_config->image_autoconv_quality; + $config->image_autorotate = $file_config->image_autorotate; + $config->image_autorotate_quality = $file_config->image_autorotate_quality; $config->download_grant = $file_config->download_grant; $config->allow_outlink = $file_config->allow_outlink; $config->allow_outlink_site = $file_config->allow_outlink_site; @@ -215,6 +217,8 @@ class fileModel extends file if(!$config->max_image_size_quality) $config->max_image_size_quality = $file_module_config->max_image_size_quality; if(!$config->image_autoconv) $config->image_autoconv = $file_module_config->image_autoconv; if(!$config->image_autoconv_quality) $config->image_autoconv_quality = $file_module_config->image_autoconv_quality; + if(!$config->image_autorotate) $config->image_autorotate = $file_module_config->image_autorotate; + if(!$config->image_autorotate_quality) $config->image_autorotate_quality = $file_module_config->image_autorotate_quality; // Default setting if not exists if(!$config->allowed_filesize) $config->allowed_filesize = '2'; @@ -226,6 +230,7 @@ class fileModel extends file if(!$config->max_image_size_quality) $config->max_image_size_quality = 75; 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; return $config; } diff --git a/modules/file/lang/en.php b/modules/file/lang/en.php index 0fdc23d03..0eba73a2d 100644 --- a/modules/file/lang/en.php +++ b/modules/file/lang/en.php @@ -25,6 +25,7 @@ $lang->image_resize_quality = 'Quality'; $lang->image_autoconv = 'Auto-Convert Image'; $lang->image_autoconv_bmp2jpg = 'BMP → JPG'; $lang->image_autoconv_webp2jpg = 'WebP → JPG'; +$lang->image_autorotate = 'Auto-Rotate Image'; $lang->inline_download_format = 'Open in current window'; $lang->inline_download_image = 'Image'; $lang->inline_download_audio = 'Audio'; @@ -44,6 +45,7 @@ $lang->about_allowed_size_limits = 'The file size will be limited to the value s $lang->about_allowed_filetypes = 'To allow an extension, use "*.[extention]". To allow multiple extensions, use ";" between each extension. ex) *.* or *.jpg;*.gif; '; $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.'; $lang->cmd_delete_checked_file = 'Delete Selected Item(s)'; $lang->cmd_move_to_document = 'Move to Document'; $lang->cmd_download = 'Download'; diff --git a/modules/file/lang/ko.php b/modules/file/lang/ko.php index d24c371e4..dbe2b31f0 100644 --- a/modules/file/lang/ko.php +++ b/modules/file/lang/ko.php @@ -25,6 +25,7 @@ $lang->image_resize_quality = '화질'; $lang->image_autoconv = '이미지 자동 변환'; $lang->image_autoconv_bmp2jpg = 'BMP → JPG'; $lang->image_autoconv_webp2jpg = 'WebP → JPG'; +$lang->image_autorotate = '이미지 자동 회전'; $lang->inline_download_format = '다운로드시 현재 창 사용'; $lang->inline_download_image = '이미지'; $lang->inline_download_audio = '오디오'; @@ -44,6 +45,7 @@ $lang->about_allowed_size_limits = 'IE9 이하, 구버전 안드로이드 등에 $lang->about_allowed_filetypes = '"*.확장자"로 지정할 수 있고 ";" 으로 여러 개 지정이 가능합니다. 예) *.* or *.jpg;*.gif;'; $lang->about_max_image_size = '이미지 파일의 가로, 세로, 또는 가로세로 크기를 모두 제한할 수 있습니다.
    관리자가 업로드한 파일에는 적용되지 않습니다.'; $lang->about_image_autoconv = '종종 문제를 일으키거나 용량을 낭비하는 이미지 타입을 다른 타입으로 자동 변환합니다.
    WebP 이미지에 JPG 확장자가 잘못 부여된 경우에도 변환할 수 있습니다.
    관리자가 업로드한 파일에도 적용됩니다.'; +$lang->about_image_autorotate = '모바일 기기 등에서 잘못 회전된 이미지를 바로잡습니다.
    관리자가 업로드한 파일에도 적용됩니다.'; $lang->cmd_delete_checked_file = '선택항목 삭제'; $lang->cmd_move_to_document = '문서로 이동'; $lang->cmd_download = '다운로드'; diff --git a/modules/file/tpl/upload_config.html b/modules/file/tpl/upload_config.html index c2123462b..fcb1d4d7e 100644 --- a/modules/file/tpl/upload_config.html +++ b/modules/file/tpl/upload_config.html @@ -61,6 +61,26 @@

    {$lang->about_image_autoconv}

    +
    + +
    + + + +

    {$lang->about_image_autorotate}

    +
    +
    From c40a47724d15f35885a6343d6251c40e60600f48 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 1 Aug 2019 15:57:05 +0900 Subject: [PATCH 13/18] 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}

    From b0b5c99dbab2b7e451b89efda74555325b964ad2 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 1 Aug 2019 16:03:04 +0900 Subject: [PATCH 14/18] Update language files for allowed_filetypes --- modules/file/lang/es.php | 2 +- modules/file/lang/fr.php | 2 +- modules/file/lang/ja.php | 2 +- modules/file/lang/zh-CN.php | 2 +- modules/file/lang/zh-TW.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/file/lang/es.php b/modules/file/lang/es.php index 1b3286f9b..ff6e96685 100644 --- a/modules/file/lang/es.php +++ b/modules/file/lang/es.php @@ -17,7 +17,7 @@ $lang->about_allow_outlink = 'Enlaces externos a Rusia Ripper puede bloquear el $lang->about_allow_outlink_site = 'Archivos, independientemente de la configuración para permitir a los enlaces externos es la dirección del sitio. Entrada múltiples gubunhaeju un cambio en la línea, por favor. Ej.) https://www.rhymix.org/'; $lang->about_allowed_filesize = 'Puede definir el límite del tamaño del archivo adjunto.(exceptuando el administrador)'; $lang->about_allowed_attach_size = 'Puede definir el límite del tamaño total de los archivos adjuntos por documento.(exceptuando el administrador)'; -$lang->about_allowed_filetypes = 'Para permitir una extensión use "*.extensión". Para permitir más de una extensión use ";". ej) *.* o *.jpg;*.gif;etc.'; +$lang->about_allowed_filetypes = 'Rhymix ya no usa la antigua sintaxis *. *. Simplemente enumere las extensiones que desea permitir.
    Utilice una coma (,) para separar los elementos: doc, zip, pdf'; $lang->cmd_delete_checked_file = 'Eliminar el archivo seleccionado'; $lang->cmd_move_to_document = 'Mover hacia el doncumento'; $lang->cmd_download = 'Descargar'; diff --git a/modules/file/lang/fr.php b/modules/file/lang/fr.php index c0629cd88..933214f56 100644 --- a/modules/file/lang/fr.php +++ b/modules/file/lang/fr.php @@ -13,7 +13,7 @@ $lang->allowed_filetypes = 'Extensions consentis seulement peuvent etre attaches $lang->enable_download_group = 'Groupe permis de telecharger'; $lang->about_allowed_filesize = 'Vous pouvez designer la limite de mesure pour chaque fichier.(Exclure administrateurs)'; $lang->about_allowed_attach_size = 'Vous pouvez designer la limite de mesure pour chaque document.(Exclure administrateurs)'; -$lang->about_allowed_filetypes = 'Pour consentir une extension, utilisez "*.[extention]". Pour consentir plusieurs extensions, utilisez ";" entre chaque extension. ex) *.* ou *.jpg;*.gif;'; +$lang->about_allowed_filetypes = 'Rhymix n\'utilise plus l\'ancienne syntaxe *. *. Indiquez simplement les extensions que vous souhaitez autoriser.
    Utilisez une virgule (,) pour séparer les éléments: par exemple. doc, zip, pdf'; $lang->cmd_delete_checked_file = 'Supprimer item(s) slectionne(s)'; $lang->cmd_move_to_document = 'Bouger au Document'; $lang->cmd_download = 'Telecharger'; diff --git a/modules/file/lang/ja.php b/modules/file/lang/ja.php index 87598b65f..0ba2105f1 100644 --- a/modules/file/lang/ja.php +++ b/modules/file/lang/ja.php @@ -22,7 +22,7 @@ $lang->about_allow_outlink_format = '外部からのファイルリンク設定 $lang->about_allow_outlink_site = '外部からのファイルリンク設定に関係なく、常に外部からのリンクを許可するURLです。
    複数登録時には、改行で記入してください。 ex) https://www.rhymix.org/'; $lang->about_allowed_filesize = '一つのファイルに対して、アップロード可能なファイルの最大サイズを指定します(管理者は除く)。'; $lang->about_allowed_attach_size = '一つの書き込みに対して、管理者以外のユーザーが添付可能な最大サイズを指定します。'; -$lang->about_allowed_filetypes = '"*.拡張子"で指定し、 ";"で区切って任意の拡張子を追加して指定できます。ex) *.* or *.jpg;*.gif; '; +$lang->about_allowed_filetypes = 'アップロードを許容する拡張者リストです。 前のバージョンの*.* 文法は使用しません。
    いろいろな入力時にdoc,zip,pdfのようにコンマ(,)に区分してください。'; $lang->cmd_delete_checked_file = '選択リスト削除'; $lang->cmd_move_to_document = '書き込みに移動する'; $lang->cmd_download = 'ダウンロード'; diff --git a/modules/file/lang/zh-CN.php b/modules/file/lang/zh-CN.php index 0e15fb82e..cc84af044 100644 --- a/modules/file/lang/zh-CN.php +++ b/modules/file/lang/zh-CN.php @@ -17,7 +17,7 @@ $lang->about_allow_outlink = '根据反向链接防止盗链。(*.wmv, *.mp3等 $lang->about_allow_outlink_site = '可以设置允许外链的站点。多个站点以换行来区分,即一行一个。 ex)https://www.rhymix.org/'; $lang->about_allowed_filesize = '最大单个上传文件大小(管理员不受此限制)。'; $lang->about_allowed_attach_size = '每个主题最大上传文件大小(管理员不受此限制)。'; -$lang->about_allowed_filetypes = '可以用"*.扩展名"来指定或用 ";"来 区分多个扩展名 例) *.* or *.jpg;*.gif;'; +$lang->about_allowed_filetypes = '允许上传的扩展者目录。 不使用前版本的*.*语法。
    输入多个时,请与doc,zip,pdf一起用逗号区分。'; $lang->cmd_delete_checked_file = '删除所选项目'; $lang->cmd_move_to_document = '查看源主题'; $lang->cmd_download = '下载'; diff --git a/modules/file/lang/zh-TW.php b/modules/file/lang/zh-TW.php index 9235e3cad..1be588670 100644 --- a/modules/file/lang/zh-TW.php +++ b/modules/file/lang/zh-TW.php @@ -19,7 +19,7 @@ $lang->about_allow_outlink_format = '設定允許外部連結的檔案格式。 $lang->about_allow_outlink_site = '可設置允許外部檔案連結的網站名單。當數量太多時,可換行輸入。 例) https://www.rhymix.org/'; $lang->about_allowed_filesize = '最大單一上傳檔案大小(管理員不受此限制)。'; $lang->about_allowed_attach_size = '每個主題最大上傳檔案大小(管理員不受此限制)。'; -$lang->about_allowed_filetypes = '可以用 "*.副檔名" 來指定或用分號 ";" 來區隔多個副檔名。 例) *.* or *.jpg; *.gif;'; +$lang->about_allowed_filetypes = '允許上傳的擴展者目錄。 不使用前版本的*.*語法。
    輸入多個時,請與doc,zip,pdf一起用逗號區分。'; $lang->cmd_delete_checked_file = '刪除所選項目'; $lang->cmd_move_to_document = '檢視原始主題'; $lang->cmd_download = '下載'; From 94efb351f7104e557a92d6e11a82fb0b9a2ce6f0 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 1 Aug 2019 16:10:10 +0900 Subject: [PATCH 15/18] Add image resizing and conversion options to per-module file config: --- modules/file/file.admin.controller.php | 12 +++-- modules/file/tpl/file_module_config.html | 59 ++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 3 deletions(-) diff --git a/modules/file/file.admin.controller.php b/modules/file/file.admin.controller.php index 788a7f005..e7ea054c9 100644 --- a/modules/file/file.admin.controller.php +++ b/modules/file/file.admin.controller.php @@ -150,12 +150,18 @@ class fileAdminController extends file $download_grant = Context::get('download_grant'); $file_config = new stdClass; - $file_config->allow_outlink = Context::get('allow_outlink'); - $file_config->allow_outlink_format = Context::get('allow_outlink_format'); - $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 = Context::get('allowed_filetypes'); + $file_config->max_image_width = intval(Context::get('max_image_width')) ?: ''; + $file_config->max_image_height = intval(Context::get('max_image_height')) ?: ''; + $file_config->max_image_size_action = Context::get('max_image_size_action') ?: ''; + $file_config->max_image_size_quality = max(50, min(100, intval(Context::get('max_image_size_quality')))); + $file_config->image_autoconv['bmp2jpg'] = Context::get('image_autoconv_bmp2jpg') === 'Y' ? true : false; + $file_config->image_autoconv['webp2jpg'] = Context::get('image_autoconv_webp2jpg') === 'Y' ? true : false; + $file_config->image_autoconv_quality = max(50, min(100, intval(Context::get('image_autoconv_quality')))); + $file_config->image_autorotate = Context::get('image_autorotate') === 'Y' ? true : false; + $file_config->image_autorotate_quality = max(50, min(100, intval(Context::get('image_autorotate_quality')))); if(!is_array($download_grant)) { diff --git a/modules/file/tpl/file_module_config.html b/modules/file/tpl/file_module_config.html index 5b9100106..bb78bd8f3 100644 --- a/modules/file/tpl/file_module_config.html +++ b/modules/file/tpl/file_module_config.html @@ -21,6 +21,65 @@

    {sprintf($lang->about_allowed_attach_size, getUrl('', 'module', 'admin', 'act', 'dispFileAdminConfig'))}
    {sprintf($lang->about_allowed_size_limits, ini_get('upload_max_filesize'))}

    +
    + +
    + × + px   + + +

    {$lang->about_max_image_size}

    +
    +
    +
    + +
    + + + +

    {$lang->about_image_autoconv}

    +
    +
    +
    + +
    + + + +

    {$lang->about_image_autorotate}

    +
    +
    From 68076b40c6250e41b17e2de6b3df3f162c217fcb Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 1 Aug 2019 16:37:05 +0900 Subject: [PATCH 16/18] Make JPG quality in document/comment thumbnails configurable, too --- classes/file/FileHandler.class.php | 2 +- modules/admin/admin.admin.controller.php | 1 + modules/admin/admin.admin.view.php | 1 + modules/admin/lang/en.php | 1 + modules/admin/lang/ko.php | 1 + modules/admin/tpl/config_advanced.html | 5 +++++ modules/comment/comment.item.php | 6 +++++- modules/document/document.item.php | 6 +++++- 8 files changed, 20 insertions(+), 3 deletions(-) diff --git a/classes/file/FileHandler.class.php b/classes/file/FileHandler.class.php index 47ce5b4fb..57de64d19 100644 --- a/classes/file/FileHandler.class.php +++ b/classes/file/FileHandler.class.php @@ -479,7 +479,7 @@ class FileHandler * @param int $resize_height Height to resize * @param string $target_type If $target_type is set (gif, jpg, png, bmp), result image will be saved as target type * @param string $thumbnail_type Thumbnail type(crop, ratio) - * @param int $quality Compression ratio (0~9) + * @param int $quality Compression ratio (0~100) * @param int $rotate Rotation degrees (0~360) * @return bool TRUE: success, FALSE: failed */ diff --git a/modules/admin/admin.admin.controller.php b/modules/admin/admin.admin.controller.php index ba5ddb566..7e220e215 100644 --- a/modules/admin/admin.admin.controller.php +++ b/modules/admin/admin.admin.controller.php @@ -758,6 +758,7 @@ class adminAdminController extends admin $document_config = $oDocumentModel->getDocumentConfig(); $document_config->thumbnail_target = $vars->thumbnail_target ?: 'all'; $document_config->thumbnail_type = $vars->thumbnail_type ?: 'crop'; + $document_config->thumbnail_quality = intval($vars->thumbnail_quality) ?: 75; $oModuleController = getController('module'); $oModuleController->insertModuleConfig('document', $document_config); diff --git a/modules/admin/admin.admin.view.php b/modules/admin/admin.admin.view.php index 67ce7107d..58b560d98 100644 --- a/modules/admin/admin.admin.view.php +++ b/modules/admin/admin.admin.view.php @@ -517,6 +517,7 @@ class adminAdminView extends admin $config = $oDocumentModel->getDocumentConfig(); Context::set('thumbnail_target', $config->thumbnail_target ?: 'all'); Context::set('thumbnail_type', $config->thumbnail_type ?: 'crop'); + Context::set('thumbnail_quality', $config->thumbnail_quality ?: 75); if ($config->thumbnail_type === 'none') { Context::set('thumbnail_target', 'none'); diff --git a/modules/admin/lang/en.php b/modules/admin/lang/en.php index d878732f0..0418b6f0b 100644 --- a/modules/admin/lang/en.php +++ b/modules/admin/lang/en.php @@ -270,6 +270,7 @@ $lang->thumbnail_target = 'Extract Thumbnail From'; $lang->thumbnail_target_all = 'All images'; $lang->thumbnail_target_attachment = 'Attached images only'; $lang->thumbnail_type = 'Thumbnail Type'; +$lang->thumbnail_quality = 'Quality'; $lang->input_header_script = 'Header Script'; $lang->detail_input_header_script = 'Content added here will be printed at the top of every page, except the admin module.'; $lang->input_footer_script = 'Footer Script'; diff --git a/modules/admin/lang/ko.php b/modules/admin/lang/ko.php index 47998ca54..79918b73f 100644 --- a/modules/admin/lang/ko.php +++ b/modules/admin/lang/ko.php @@ -273,6 +273,7 @@ $lang->detail_input_footer_script = '모든 페이지의 최하단에 코드를 $lang->thumbnail_crop = '크기에 맞추어 잘라내기'; $lang->thumbnail_ratio = '비율 유지 (여백이 생길 수 있음)'; $lang->thumbnail_none = '썸네일 생성하지 않음'; +$lang->thumbnail_quality = '화질'; $lang->admin_ip_allow = '관리자 로그인 허용 IP'; $lang->admin_ip_deny = '관리자 로그인 금지 IP'; $lang->local_ip_address = '로컬 IP 주소'; diff --git a/modules/admin/tpl/config_advanced.html b/modules/admin/tpl/config_advanced.html index 066e357e4..088889545 100644 --- a/modules/admin/tpl/config_advanced.html +++ b/modules/admin/tpl/config_advanced.html @@ -136,6 +136,11 @@ {$lang->thumbnail_ratio} +
    diff --git a/modules/comment/comment.item.php b/modules/comment/comment.item.php index 927a1a767..080c02d26 100644 --- a/modules/comment/comment.item.php +++ b/modules/comment/comment.item.php @@ -656,6 +656,10 @@ class commentItem extends BaseObject { $thumbnail_type = $config->thumbnail_type ?: 'crop'; } + if(!$config->thumbnail_quality) + { + $config->thumbnail_quality = 75; + } if(!$this->isAccessible()) { @@ -785,7 +789,7 @@ class commentItem extends BaseObject if($source_file) { - $output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type); + $output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type, $config->thumbnail_quality); } // Remove source file if it was temporary diff --git a/modules/document/document.item.php b/modules/document/document.item.php index 302d84a6f..2b2f9b796 100644 --- a/modules/document/document.item.php +++ b/modules/document/document.item.php @@ -1009,6 +1009,10 @@ class documentItem extends BaseObject { $thumbnail_type = $config->thumbnail_type ?: 'crop'; } + if(!$config->thumbnail_quality) + { + $config->thumbnail_quality = 75; + } if(!$this->isAccessible()) { @@ -1143,7 +1147,7 @@ class documentItem extends BaseObject if($source_file) { - $output_file = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type); + $output_file = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type, $config->thumbnail_quality); } // Remove source file if it was temporary From 9d08cac27bf8b10ee30b16d6ea5f027db5a802f3 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 1 Aug 2019 20:27:40 +0900 Subject: [PATCH 17/18] Update description for allow_outlink --- modules/file/lang/en.php | 2 +- modules/file/lang/ko.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/file/lang/en.php b/modules/file/lang/en.php index 69a127067..04c0f0d2b 100644 --- a/modules/file/lang/en.php +++ b/modules/file/lang/en.php @@ -34,7 +34,7 @@ $lang->inline_download_text = 'Text (except HTML)'; $lang->inline_download_pdf = 'PDF'; $lang->about_inline_download_format = 'Selected types of files will be opened in the current window instead of a download dialog when a user clicks the download link.'; $lang->enable_download_group = 'Downloadable Groups'; -$lang->about_allow_outlink = 'You can block other websites from accessing your download URLs directly.
    This does not apply to images and other files that can be embedded directly in a document.'; +$lang->about_allow_outlink = 'Allow other websites to link directly to your download URLs.
    Rhymix does not control links to image files that can be embedded directly in a document.
    in order to block external links to such images, you may need to modify your web server configuration.'; $lang->about_allow_outlink_format = 'These file formats will always be allowed.
    Please use a comma (,) to separate items: e.g. doc, zip, pdf'; $lang->about_allow_outlink_site = 'These referers will always be allowed.
    Please enter one full address per line: e.g. https://www.rhymix.org/'; $lang->about_allowed_filesize = 'You can limit the size of each attached file.
    Administrators are limited to this setting or the limit set in the file module, whichever is greater.'; diff --git a/modules/file/lang/ko.php b/modules/file/lang/ko.php index afb7a45e1..e4be7a262 100644 --- a/modules/file/lang/ko.php +++ b/modules/file/lang/ko.php @@ -34,7 +34,7 @@ $lang->inline_download_text = '텍스트 (HTML 제외)'; $lang->inline_download_pdf = 'PDF'; $lang->about_inline_download_format = '선택한 종류의 파일은 다운로드 링크를 클릭하더라도 다운로드 창을 열지 않고 현재 창에 표시합니다.'; $lang->enable_download_group = '다운로드 가능 그룹'; -$lang->about_allow_outlink = '다른 사이트에서 파일 다운로드 링크에 직접 접근하는 것을 차단합니다.
    다운로드 링크를 사용하지 않고 본문에 바로 삽입할 수 있는 이미지 파일 등에는 적용되지 않습니다.'; +$lang->about_allow_outlink = '다른 사이트에서 파일 다운로드 링크에 직접 접근하는 것을 허용합니다.
    본문에 바로 삽입할 수 있는 이미지 파일은 라이믹스에서 접근을 통제할 수 없으며, 이를 차단하려면 웹서버 설정이 필요합니다.'; $lang->about_allow_outlink_format = '파일 외부 링크 설정에 상관없이 허용하는 파일 확장자입니다.
    여러 개 입력시 쉼표(,)을 이용해서 구분해 주세요. 예) doc, zip, pdf'; $lang->about_allow_outlink_site = '파일 외부 링크 설정에 상관없이 허용하는 사이트 주소입니다.
    여러 개 입력시 줄을 바꿔서 구분해 주세요. 예) https://www.rhymix.org/'; $lang->about_allowed_filesize = '각 파일의 용량을 제한할 수 있습니다.
    관리자에게는 이 게시판의 제한과 파일 모듈의 제한 중 높은 쪽이 적용됩니다.'; From 6d2a91134ca39814aa017bda0d20473d2e96a5ab Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 1 Aug 2019 20:49:34 +0900 Subject: [PATCH 18/18] Add option to apply default file settings to module --- modules/editor/lang/en.php | 4 ++-- modules/editor/lang/ko.php | 2 +- modules/file/file.admin.controller.php | 28 ++++++++++++++---------- modules/file/file.model.php | 1 + modules/file/lang/en.php | 2 ++ modules/file/lang/ko.php | 2 ++ modules/file/tpl/css/config.css | 5 +++++ modules/file/tpl/file_module_config.html | 16 ++++++++++++++ modules/file/tpl/js/config.js | 12 ++++++++++ 9 files changed, 58 insertions(+), 14 deletions(-) create mode 100644 modules/file/tpl/css/config.css create mode 100644 modules/file/tpl/js/config.js diff --git a/modules/editor/lang/en.php b/modules/editor/lang/en.php index 2419c8867..77087dfc6 100644 --- a/modules/editor/lang/en.php +++ b/modules/editor/lang/en.php @@ -65,7 +65,7 @@ $lang->msg_auto_saved = 'Automatically Saved.'; $lang->cmd_disable = 'Inactive'; $lang->cmd_enable = 'Active'; $lang->cmd_select_cover = 'Be a cover image'; -$lang->default_editor_settings = 'Default settings for this module'; +$lang->default_editor_settings = 'Use Default Settings'; $lang->editor_skin = 'Editor Skin'; $lang->upload_file_grant = 'Permission to upload files'; $lang->enable_default_component_grant = 'Permission to use default components'; @@ -75,7 +75,7 @@ $lang->enable_autosave = 'Enable Auto-Save'; $lang->allow_html = 'allow HTML'; $lang->height_resizable = 'Height Resizable'; $lang->editor_height = 'Height of Editor'; -$lang->about_default_editor_settings = 'Follow editor settings of Rhymix Admin page through whole site.'; +$lang->about_default_editor_settings = 'Follow the default settings from the Editor module.'; $lang->about_content_font = 'Please use comma for multiple input.'; $lang->about_content_font_size = 'Please input units such as px or em.'; $lang->about_enable_autosave = 'You may decide whether the auto-save function will be used.'; diff --git a/modules/editor/lang/ko.php b/modules/editor/lang/ko.php index 2e80a7ebb..e6abe63e5 100644 --- a/modules/editor/lang/ko.php +++ b/modules/editor/lang/ko.php @@ -79,7 +79,7 @@ $lang->enable_autosave = '자동저장 사용'; $lang->allow_html = 'HTML 허용'; $lang->height_resizable = '높이 조절 가능'; $lang->editor_height = '에디터 높이'; -$lang->about_default_editor_settings = '사이트 전체 에디터 설정을 통일하여서 모듈별 에디터 설정을 단순하게 합니다.'; +$lang->about_default_editor_settings = '에디터 모듈의 기본 설정을 따릅니다.'; $lang->about_content_font = '콤마(,)로 여러 폰트를 지정할 수 있습니다.'; $lang->about_content_font_size = '12px, 1em등 단위까지 포함해서 입력해주세요.'; $lang->about_enable_autosave = '글 작성 시 자동 저장 기능을 활성화 시킬 수 있습니다.'; diff --git a/modules/file/file.admin.controller.php b/modules/file/file.admin.controller.php index e7ea054c9..1b11dd4f1 100644 --- a/modules/file/file.admin.controller.php +++ b/modules/file/file.admin.controller.php @@ -147,8 +147,6 @@ class fileAdminController extends file if(preg_match('/^([0-9,]+)$/',$module_srl)) $module_srl = explode(',',$module_srl); else $module_srl = array($module_srl); - $download_grant = Context::get('download_grant'); - $file_config = new stdClass; $file_config->allowed_filesize = Context::get('allowed_filesize'); $file_config->allowed_attach_size = Context::get('allowed_attach_size'); @@ -163,15 +161,6 @@ class fileAdminController extends file $file_config->image_autorotate = Context::get('image_autorotate') === 'Y' ? true : false; $file_config->image_autorotate_quality = max(50, min(100, intval(Context::get('image_autorotate_quality')))); - if(!is_array($download_grant)) - { - $file_config->download_grant = explode('|@|',$download_grant); - } - else - { - $file_config->download_grant = array_values($download_grant); - } - // Check maximum file size if (PHP_INT_SIZE < 8) { @@ -196,6 +185,23 @@ class fileAdminController extends file $file_config->allowed_filetypes = '*.*'; } + // Use default config + if(Context::get('use_default_file_config') === 'Y') + { + $file_config = new stdClass; + $file_config->use_default_file_config = true; + } + + // Check download grant + $download_grant = Context::get('download_grant'); + if(!is_array($download_grant)) + { + $file_config->download_grant = explode('|@|',$download_grant); + } + else + { + $file_config->download_grant = array_values($download_grant); + } $oModuleController = getController('module'); for($i=0;$iuse_default_file_config = $file_config->use_default_file_config; $config->allowed_filesize = $file_config->allowed_filesize; $config->allowed_attach_size = $file_config->allowed_attach_size; $config->allowed_filetypes = $file_config->allowed_filetypes; diff --git a/modules/file/lang/en.php b/modules/file/lang/en.php index 04c0f0d2b..62ae777ab 100644 --- a/modules/file/lang/en.php +++ b/modules/file/lang/en.php @@ -32,6 +32,8 @@ $lang->inline_download_audio = 'Audio'; $lang->inline_download_video = 'Video'; $lang->inline_download_text = 'Text (except HTML)'; $lang->inline_download_pdf = 'PDF'; +$lang->use_default_file_config = 'Use Default Settings'; +$lang->about_use_default_file_config = 'Follow the default settings from the File module.'; $lang->about_inline_download_format = 'Selected types of files will be opened in the current window instead of a download dialog when a user clicks the download link.'; $lang->enable_download_group = 'Downloadable Groups'; $lang->about_allow_outlink = 'Allow other websites to link directly to your download URLs.
    Rhymix does not control links to image files that can be embedded directly in a document.
    in order to block external links to such images, you may need to modify your web server configuration.'; diff --git a/modules/file/lang/ko.php b/modules/file/lang/ko.php index e4be7a262..d6dba863e 100644 --- a/modules/file/lang/ko.php +++ b/modules/file/lang/ko.php @@ -32,6 +32,8 @@ $lang->inline_download_audio = '오디오'; $lang->inline_download_video = '비디오'; $lang->inline_download_text = '텍스트 (HTML 제외)'; $lang->inline_download_pdf = 'PDF'; +$lang->use_default_file_config = '기본 파일 설정 사용'; +$lang->about_use_default_file_config = '파일 모듈의 기본 설정을 따릅니다.'; $lang->about_inline_download_format = '선택한 종류의 파일은 다운로드 링크를 클릭하더라도 다운로드 창을 열지 않고 현재 창에 표시합니다.'; $lang->enable_download_group = '다운로드 가능 그룹'; $lang->about_allow_outlink = '다른 사이트에서 파일 다운로드 링크에 직접 접근하는 것을 허용합니다.
    본문에 바로 삽입할 수 있는 이미지 파일은 라이믹스에서 접근을 통제할 수 없으며, 이를 차단하려면 웹서버 설정이 필요합니다.'; diff --git a/modules/file/tpl/css/config.css b/modules/file/tpl/css/config.css new file mode 100644 index 000000000..8dda1fea9 --- /dev/null +++ b/modules/file/tpl/css/config.css @@ -0,0 +1,5 @@ +.use_default_file_config { + margin-top: -10px; + border-bottom: 1px solid #ccc; + background: #f5f5f5; +} \ No newline at end of file diff --git a/modules/file/tpl/file_module_config.html b/modules/file/tpl/file_module_config.html index bb78bd8f3..da4f3d4df 100644 --- a/modules/file/tpl/file_module_config.html +++ b/modules/file/tpl/file_module_config.html @@ -1,3 +1,6 @@ + + +

    {$lang->file}

    @@ -7,6 +10,17 @@ +
    + +
    + +
    +
    +
    diff --git a/modules/file/tpl/js/config.js b/modules/file/tpl/js/config.js new file mode 100644 index 000000000..6b37187d5 --- /dev/null +++ b/modules/file/tpl/js/config.js @@ -0,0 +1,12 @@ +(function($) { + $(function() { + + $('#use_default_file_config').on('change', function() { + if ($(this).is(':checked')) { + $('.use_custom_file_config').hide(); + } else { + $('.use_custom_file_config').show(); + } + }); + }); +})(jQuery);