From 46f19a9f1793884f9def7ca3756c2341cd0f8f95 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Fri, 22 Nov 2019 18:20:52 +0900 Subject: [PATCH] Enable file upload when sending messages --- common/lang/en.php | 1 + common/lang/ko.php | 1 + .../communication.admin.controller.php | 2 +- .../communication.controller.php | 20 ++++++++++++++++--- modules/communication/communication.view.php | 14 +++++++++---- modules/communication/lang/en.php | 1 + modules/communication/lang/ko.php | 1 + modules/communication/tpl/index.html | 15 ++++++++++++-- modules/file/tpl/file_list.html | 5 ++++- 9 files changed, 49 insertions(+), 11 deletions(-) diff --git a/common/lang/en.php b/common/lang/en.php index 84ea3735e..c60b13497 100644 --- a/common/lang/en.php +++ b/common/lang/en.php @@ -108,6 +108,7 @@ $lang->replies = 'Comment'; $lang->content = 'Content'; $lang->document = 'Article'; $lang->comment = 'Comment'; +$lang->member_message = 'Message'; $lang->description = 'Description'; $lang->trackback = 'Trackback'; $lang->tag = 'Tag'; diff --git a/common/lang/ko.php b/common/lang/ko.php index b083635ad..5de36f559 100644 --- a/common/lang/ko.php +++ b/common/lang/ko.php @@ -110,6 +110,7 @@ $lang->replies = '댓글'; $lang->content = '내용'; $lang->document = '문서'; $lang->comment = '댓글'; +$lang->member_message = '쪽지'; $lang->description = '설명'; $lang->trackback = '엮인글'; $lang->tag = '태그'; diff --git a/modules/communication/communication.admin.controller.php b/modules/communication/communication.admin.controller.php index fd05dcb35..45cd6a1e3 100644 --- a/modules/communication/communication.admin.controller.php +++ b/modules/communication/communication.admin.controller.php @@ -24,7 +24,7 @@ class communicationAdminController extends communication function procCommunicationAdminInsertConfig() { // get the default information - $args = Context::gets('enable_message', 'enable_friend', 'skin', 'colorset', 'editor_skin', 'sel_editor_colorset', 'mskin', 'mcolorset', 'layout_srl', 'mlayout_srl', 'grant_send_default','grant_send_group'); + $args = Context::gets('enable_message', 'enable_friend', 'enable_attachment', 'skin', 'colorset', 'editor_skin', 'sel_editor_colorset', 'mskin', 'mcolorset', 'layout_srl', 'mlayout_srl', 'grant_send_default','grant_send_group'); $args->editor_colorset = $args->sel_editor_colorset; unset($args->sel_editor_colorset); diff --git a/modules/communication/communication.controller.php b/modules/communication/communication.controller.php index a1c228db7..f185a9177 100644 --- a/modules/communication/communication.controller.php +++ b/modules/communication/communication.controller.php @@ -77,6 +77,12 @@ class communicationController extends communication { throw new Rhymix\Framework\Exception('msg_content_is_null'); } + + $temp_srl = intval(Context::get('temp_srl')) ?: null; + if($temp_srl && !$_SESSION['upload_info'][$temp_srl]->enabled) + { + throw new Rhymix\Framework\Exceptions\InvalidRequest; + } // Check if there is a member to receive a message $oMemberModel = getModel('member'); @@ -111,7 +117,7 @@ class communicationController extends communication } // send a message - $output = $this->sendMessage($logged_info->member_srl, $receiver_srl, $title, $content); + $output = $this->sendMessage($logged_info->member_srl, $receiver_srl, $title, $content, true, $temp_srl); if(!$output->toBool()) { @@ -148,9 +154,10 @@ class communicationController extends communication * @param string $title * @param string $content * @param boolean $sender_log (default true) + * @param int|null $temp_srl (default null) * @return Object */ - function sendMessage($sender_srl, $receiver_srl, $title, $content, $sender_log = TRUE) + function sendMessage($sender_srl, $receiver_srl, $title, $content, $sender_log = true, $temp_srl = null) { // Encode the title and content. $title = escape($title, false); @@ -158,7 +165,7 @@ class communicationController extends communication $title = utf8_mbencode($title); $content = utf8_mbencode($content); - $message_srl = getNextSequence(); + $message_srl = $temp_srl ?: getNextSequence(); $related_srl = getNextSequence(); // messages to save in the sendor's message box @@ -227,6 +234,13 @@ class communicationController extends communication $oDB->rollback(); return $output; } + + // update attached files + if ($temp_srl) + { + $oFileController = getController('file'); + $oFileController->setFilesValid($message_srl, 'msg'); + } // Call a trigger (after) ModuleHandler::triggerCall('communication.sendMessage', 'after', $trigger_obj); diff --git a/modules/communication/communication.view.php b/modules/communication/communication.view.php index 8a43b1c48..7deaa7c09 100644 --- a/modules/communication/communication.view.php +++ b/modules/communication/communication.view.php @@ -197,6 +197,12 @@ class communicationView extends communication throw new Rhymix\Framework\Exceptions\NotPermitted; } + // Fix missing mid (it causes errors when uploading) + if(!Context::get('mid')) + { + Context::set('mid', Context::get('site_module_info')->mid); + } + // Error appears if not logged-in if(!Context::get('is_logged')) { @@ -249,9 +255,9 @@ class communicationView extends communication // set a signiture by calling getEditor of the editor module $oEditorModel = getModel('editor'); $option = $oEditorModel->getEditorConfig(); - $option->primary_key_name = 'receiver_srl'; + $option->primary_key_name = 'temp_srl'; $option->content_key_name = 'content'; - $option->allow_fileupload = FALSE; + $option->allow_fileupload = $this->config->enable_attachment === 'Y'; $option->enable_autosave = FALSE; $option->enable_default_component = TRUE; // FALSE; $option->enable_component = FALSE; @@ -261,9 +267,9 @@ class communicationView extends communication $option->skin = $this->config->editor_skin; $option->colorset = $this->config->editor_colorset; $option->editor_focus = Context::get('source_message') ? 'Y' : 'N'; - $editor = $oEditorModel->getEditor($logged_info->member_srl, $option); + $editor = $oEditorModel->getEditor(getNextSequence(), $option); + $editor = $editor . "\n" . '' . "\n"; Context::set('editor', $editor); - $this->setTemplateFile('send_message'); } diff --git a/modules/communication/lang/en.php b/modules/communication/lang/en.php index 2394e894c..9c20e521d 100644 --- a/modules/communication/lang/en.php +++ b/modules/communication/lang/en.php @@ -44,3 +44,4 @@ $lang->cmd_manage_base = 'Basic infomation'; $lang->alert_new_message_arrived = 'You have %d new message(s). Do you want to check it now?'; $lang->enable_communication_friend = 'Friend Enable'; $lang->enable_communication_message = 'Message Enable'; +$lang->enable_attachment = 'Allow Attachment'; diff --git a/modules/communication/lang/ko.php b/modules/communication/lang/ko.php index 05267f8e8..1b9dbbeb4 100644 --- a/modules/communication/lang/ko.php +++ b/modules/communication/lang/ko.php @@ -44,6 +44,7 @@ $lang->cmd_manage_base = '기본 정보'; $lang->alert_new_message_arrived = '%d개의 새로운 메시지가 도착하였습니다. 확인하시겠습니까?'; $lang->enable_communication_friend = '친구기능 사용'; $lang->enable_communication_message = '쪽지기능 사용'; +$lang->enable_attachment = '파일첨부 허용'; $lang->warning = '알려드립니다!'; $lang->msg_allow_message_friend = '현재 회원님은 친구에게만 수신 가능한 상태입니다.'; $lang->msg_allow_meesage_Block = '현재 회원님은 수신거부 상태입니다.'; diff --git a/modules/communication/tpl/index.html b/modules/communication/tpl/index.html index 9fc84762e..dd4e74abd 100644 --- a/modules/communication/tpl/index.html +++ b/modules/communication/tpl/index.html @@ -27,7 +27,7 @@ {$lang->cmd_yes} @@ -38,7 +38,18 @@ {$lang->cmd_yes} + + +
+
{$lang->enable_attachment}
+
+ +
diff --git a/modules/file/tpl/file_list.html b/modules/file/tpl/file_list.html index 8179355a0..77b8460c0 100644 --- a/modules/file/tpl/file_list.html +++ b/modules/file/tpl/file_list.html @@ -55,10 +55,13 @@ xe.lang.msg_empty_search_keyword = '{$lang->msg_empty_search_keyword}'; [{$lang->comment}] [{$lang->module}] + [{$lang->member_message}] [{$lang->cmd_temp_save}] [{$lang->cmd_trash}] - {$module_list[$val->module_srl]->browser_title} + + {$module_list[$val->module_srl]->browser_title} + - {$document_list[$document_srl]->getTitle()}{$document_list[$document_srl]->getTitle()}