From a21d14ac094b744421a61161c262c573297ea8a4 Mon Sep 17 00:00:00 2001 From: dewekk <60457472+dewekk@users.noreply.github.com> Date: Wed, 23 Nov 2022 21:47:57 +0900 Subject: [PATCH] =?UTF-8?q?=EB=8C=93=EA=B8=80=20=EC=8B=A0=EA=B3=A0=20?= =?UTF-8?q?=EC=B7=A8=EC=86=8C=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/comment/comment.controller.php | 151 ++++++++++++++++++ modules/comment/comment.item.php | 38 +++++ modules/comment/comment.model.php | 26 +-- modules/comment/conf/module.xml | 1 + .../queries/updateDeclaredCommentCancel.xml | 11 ++ modules/comment/tpl/declare_comment.html | 15 +- 6 files changed, 229 insertions(+), 13 deletions(-) create mode 100644 modules/comment/queries/updateDeclaredCommentCancel.xml diff --git a/modules/comment/comment.controller.php b/modules/comment/comment.controller.php index 6537da25b..cf56ce8e8 100644 --- a/modules/comment/comment.controller.php +++ b/modules/comment/comment.controller.php @@ -292,6 +292,44 @@ class commentController extends comment return $this->declaredComment($comment_srl, $declare_message); } + /** + * Action to be called when cancel reporting a comment + * @return void|Object + */ + function procCommentDeclareCancel() + { + if (!Context::get('is_logged')) + { + throw new Rhymix\Framework\Exceptions\NotPermitted; + } + + $comment_srl = Context::get('target_srl'); + if (!$comment_srl) + { + throw new Rhymix\Framework\Exceptions\InvalidRequest; + } + $oComment = CommentModel::getComment($comment_srl, false, false); + if (!$oComment->isExists()) + { + throw new Rhymix\Framework\Exceptions\TargetNotFound; + } + if (!$oComment->isAccessible(true)) + { + throw new Rhymix\Framework\Exceptions\NotPermitted; + } + if ($this->module_info->cancel_vote !== 'Y') + { + throw new Rhymix\Framework\Exception('failed_declared_cancel'); + } + + if (Context::get('success_return_url')) + { + $this->setRedirectUrl(Context::get('success_return_url')); + } + + return $this->declaredCommentCancel($comment_srl); + } + /** * Trigger to delete its comments together with document deleted * @return Object @@ -1706,6 +1744,119 @@ class commentController extends comment $this->setMessage('success_declared'); } + /** + * Cancel a report + * @param $comment_srl + * @return BaseObject|object|void + */ + function declaredCommentCancel($comment_srl) + { + $member_srl = $this->user->member_srl; + if (!$_SESSION['declared_comment'][$comment_srl] && !$member_srl) + { + return new BaseObject(-1, 'failed_declared_cancel'); + } + + // Get the original document + $oComment = CommentModel::getComment($comment_srl, false, false); + + $oDB = DB::getInstance(); + $oDB->begin(); + + $args = new stdClass; + $args->comment_srl = $comment_srl; + if ($member_srl) + { + $args->member_srl = $member_srl; + } + else + { + $args->ipaddress = \RX_CLIENT_IP; + } + $log_output = executeQuery('comment.getCommentDeclaredLogInfo', $args); + if ($log_output->data->count <= 0 || !isset($log_output->data->count)) + { + unset($_SESSION['declared_comment'][$comment_srl]); + return new BaseObject(-1, 'failed_declared_cancel'); + } + + $args = new stdClass(); + $args->comment_srl = $comment_srl; + $output = executeQuery('comment.getDeclaredComment', $args); + + $declared_count = ($output->data->declared_count) ? $output->data->declared_count : 0; + + $trigger_obj = new stdClass(); + $trigger_obj->document_srl = $comment_srl; + $trigger_obj->declared_count = $declared_count; + // Call a trigger (before) + $trigger_output = ModuleHandler::triggerCall('comment.declaredCommentCancel', 'before', $trigger_obj); + if (!$trigger_output->toBool()) + { + return $trigger_output; + } + + if ($declared_count > 1) + { + $output = executeQuery('comment.updateDeclaredCommentCancel', $args); + } + else + { + $output = executeQuery('comment.deleteDeclaredComments', $args); + } + if (!$output->toBool()) + { + $oDB->rollback(); + return $output; + } + + $output = executeQuery('comment.deleteCommentDeclaredLog', $args); + if (!$output->toBool()) + { + $oDB->rollback(); + return $output; + } + + $message_targets = array(); + $module_srl = $oComment->get('module_srl'); + $comment_config = ModuleModel::getModulePartConfig('comment', $module_srl); + if ($comment_config->declared_message && in_array('admin', $comment_config->declared_message)) + { + $output = executeQueryArray('member.getAdmins', new stdClass); + foreach ($output->data as $admin) + { + $message_targets[$admin->member_srl] = true; + } + } + if ($comment_config->declared_message && in_array('manager', $comment_config->declared_message)) + { + $output = executeQueryArray('module.getModuleAdmin', (object)['module_srl' => $module_srl]); + foreach ($output->data as $manager) + { + $message_targets[$manager->member_srl] = true; + } + } + if ($message_targets) + { + $oCommunicationController = getController('communication'); + $message_title = lang('document.declared_cancel_message_title'); + $message_content = sprintf('

%s

', $oComment->getPermanentUrl(), $oComment->getContentText(50)); + foreach ($message_targets as $target_member_srl => $val) + { + $oCommunicationController->sendMessage($this->user->member_srl, $target_member_srl, $message_title, $message_content, false, null, false); + } + } + + $oDB->commit(); + + $trigger_obj->declared_count = $declared_count - 1; + ModuleHandler::triggerCall('comment.declaredCommentCancel', 'after', $trigger_obj); + + unset($_SESSION['declared_comment'][$comment_srl]); + + $this->setMessage('success_declared_cancel'); + } + /** * Method to add a pop-up menu when clicking for displaying child comments * @param string $url diff --git a/modules/comment/comment.item.php b/modules/comment/comment.item.php index 1ef079dde..0ba62f4f1 100644 --- a/modules/comment/comment.item.php +++ b/modules/comment/comment.item.php @@ -406,6 +406,44 @@ class commentItem extends BaseObject return $_SESSION['voted_comment'][$this->comment_srl] = false; } + function getDeclared() + { + if (!$this->isExists()) + { + return false; + } + + $logged_info = Context::get('logged_info'); + if (!$logged_info->member_srl) + { + return false; + } + + if (isset($_SESSION['declared_comment'][$this->comment_srl])) + { + return $_SESSION['declared_comment'][$this->comment_srl]; + } + + $args = new stdClass(); + if ($logged_info->member_srl) + { + $args->member_srl = $logged_info->member_srl; + } + else + { + $args->ipaddress = \RX_CLIENT_IP; + } + $args->comment_srl = $this->comment_srl; + $output = executeQuery('comment.getCommentDeclaredLogInfo', $args); + $declared_count = isset($output->data) ? intval($output->data->count) : 0; + if ($declared_count > 0) + { + return $_SESSION['declared_comment'][$this->comment_srl] = $declared_count; + } + + return false; + } + function getContentPlainText($strlen = 0) { if($this->isDeletedByAdmin()) diff --git a/modules/comment/comment.model.php b/modules/comment/comment.model.php index f63a4efb3..963ab4889 100644 --- a/modules/comment/comment.model.php +++ b/modules/comment/comment.model.php @@ -28,11 +28,9 @@ class commentModel extends comment */ public function getCommentMenu() { - // get the post's id number and the current login information + // get the post's id number $comment_srl = Context::get('target_srl'); $mid = Context::get('cur_mid'); - $logged_info = Context::get('logged_info'); - $act = Context::get('cur_act'); // array values for menu_list, "comment post, target, url" $menu_list = array(); @@ -43,7 +41,7 @@ class commentModel extends comment $oCommentController = getController('comment'); // feature that only member can do - if($logged_info->member_srl) + if($this->user->member_srl) { $columnList = array('comment_srl', 'module_srl', 'member_srl', 'ipaddress'); $oComment = self::getComment($comment_srl, FALSE, $columnList); @@ -52,14 +50,14 @@ class commentModel extends comment $comment_config = ModuleModel::getModulePartConfig('document', $module_srl); - if($comment_config->use_vote_up != 'N' && $member_srl != $logged_info->member_srl) + if($comment_config->use_vote_up != 'N' && $member_srl != $this->user->member_srl) { // Add a vote-up button for positive feedback $url = sprintf("doCallModuleAction('comment','procCommentVoteUp','%s')", $comment_srl); $oCommentController->addCommentPopupMenu($url, 'cmd_vote', '', 'javascript'); } - if($comment_config->use_vote_down != 'N' && $member_srl != $logged_info->member_srl) + if($comment_config->use_vote_down != 'N' && $member_srl != $this->user->member_srl) { // Add a vote-down button for negative feedback $url = sprintf("doCallModuleAction('comment','procCommentVoteDown','%s')", $comment_srl); @@ -67,8 +65,16 @@ class commentModel extends comment } // Add the report feature against abused posts - $url = getUrl('', 'act', 'dispCommentDeclare', 'target_srl', $comment_srl); - $oCommentController->addCommentPopupMenu($url, 'cmd_declare', '', 'popup'); + if($oComment->getDeclared()) + { + $url = getUrl('', 'mid', $mid, 'act', 'dispCommentDeclare', 'target_srl', $comment_srl, 'type', 'cancel'); + $oCommentController->addCommentPopupMenu($url,'cmd_cancel_declare','','popup'); + } + else + { + $url = getUrl('', 'mid', $mid, 'act', 'dispCommentDeclare', 'target_srl', $comment_srl); + $oCommentController->addCommentPopupMenu($url,'cmd_declare','','popup'); + } } // call a trigger (after) @@ -82,7 +88,7 @@ class commentModel extends comment } // find a comment by IP matching if an administrator. - if($logged_info->is_admin == 'Y') + if($this->user->is_admin == 'Y') { $oComment = self::getComment($comment_srl); @@ -90,7 +96,7 @@ class commentModel extends comment { // Find a post of the corresponding ip address $url = getUrl('', 'module', 'admin', 'act', 'dispCommentAdminList', 'search_target', 'ipaddress', 'search_keyword', $oComment->getIpAddress()); - $oCommentController->addCommentPopupMenu($url, 'cmd_search_by_ipaddress', $icon_path, 'TraceByIpaddress'); + $oCommentController->addCommentPopupMenu($url, 'cmd_search_by_ipaddress', '', 'TraceByIpaddress'); $url = sprintf("var params = new Array(); params['ipaddress_list']='%s'; exec_xml('spamfilter', 'procSpamfilterAdminInsertDeniedIP', params, completeCallModuleAction)", $oComment->getIpAddress()); $oCommentController->addCommentPopupMenu($url, 'cmd_add_ip_to_spamfilter', '', 'javascript'); diff --git a/modules/comment/conf/module.xml b/modules/comment/conf/module.xml index 3baf4a458..8679a4b13 100644 --- a/modules/comment/conf/module.xml +++ b/modules/comment/conf/module.xml @@ -12,6 +12,7 @@ + diff --git a/modules/comment/queries/updateDeclaredCommentCancel.xml b/modules/comment/queries/updateDeclaredCommentCancel.xml new file mode 100644 index 000000000..1d538510a --- /dev/null +++ b/modules/comment/queries/updateDeclaredCommentCancel.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/modules/comment/tpl/declare_comment.html b/modules/comment/tpl/declare_comment.html index 5ce687458..1660a63a8 100644 --- a/modules/comment/tpl/declare_comment.html +++ b/modules/comment/tpl/declare_comment.html @@ -2,9 +2,13 @@
+ + + + - +

{$lang->improper_comment_declare} {$lang->cmd_cancel}

@@ -16,6 +20,7 @@

{$target_comment->getSummary(200)}

+
@@ -26,16 +31,20 @@

{$lang->about_improper_comment_declare}

+