댓글 신고 취소 기능 추가

This commit is contained in:
dewekk 2022-11-23 21:47:57 +09:00
parent 5d012bee82
commit a21d14ac09
6 changed files with 229 additions and 13 deletions

View file

@ -292,6 +292,44 @@ class commentController extends comment
return $this->declaredComment($comment_srl, $declare_message); 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 * Trigger to delete its comments together with document deleted
* @return Object * @return Object
@ -1706,6 +1744,119 @@ class commentController extends comment
$this->setMessage('success_declared'); $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('<p><a href="%s">%s</a></p>', $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 * Method to add a pop-up menu when clicking for displaying child comments
* @param string $url * @param string $url

View file

@ -406,6 +406,44 @@ class commentItem extends BaseObject
return $_SESSION['voted_comment'][$this->comment_srl] = false; 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) function getContentPlainText($strlen = 0)
{ {
if($this->isDeletedByAdmin()) if($this->isDeletedByAdmin())

View file

@ -28,11 +28,9 @@ class commentModel extends comment
*/ */
public function getCommentMenu() 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'); $comment_srl = Context::get('target_srl');
$mid = Context::get('cur_mid'); $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" // array values for menu_list, "comment post, target, url"
$menu_list = array(); $menu_list = array();
@ -43,7 +41,7 @@ class commentModel extends comment
$oCommentController = getController('comment'); $oCommentController = getController('comment');
// feature that only member can do // 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'); $columnList = array('comment_srl', 'module_srl', 'member_srl', 'ipaddress');
$oComment = self::getComment($comment_srl, FALSE, $columnList); $oComment = self::getComment($comment_srl, FALSE, $columnList);
@ -52,14 +50,14 @@ class commentModel extends comment
$comment_config = ModuleModel::getModulePartConfig('document', $module_srl); $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 // Add a vote-up button for positive feedback
$url = sprintf("doCallModuleAction('comment','procCommentVoteUp','%s')", $comment_srl); $url = sprintf("doCallModuleAction('comment','procCommentVoteUp','%s')", $comment_srl);
$oCommentController->addCommentPopupMenu($url, 'cmd_vote', '', 'javascript'); $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 // Add a vote-down button for negative feedback
$url = sprintf("doCallModuleAction('comment','procCommentVoteDown','%s')", $comment_srl); $url = sprintf("doCallModuleAction('comment','procCommentVoteDown','%s')", $comment_srl);
@ -67,8 +65,16 @@ class commentModel extends comment
} }
// Add the report feature against abused posts // Add the report feature against abused posts
$url = getUrl('', 'act', 'dispCommentDeclare', 'target_srl', $comment_srl); if($oComment->getDeclared())
$oCommentController->addCommentPopupMenu($url, 'cmd_declare', '', 'popup'); {
$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) // call a trigger (after)
@ -82,7 +88,7 @@ class commentModel extends comment
} }
// find a comment by IP matching if an administrator. // 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); $oComment = self::getComment($comment_srl);
@ -90,7 +96,7 @@ class commentModel extends comment
{ {
// Find a post of the corresponding ip address // Find a post of the corresponding ip address
$url = getUrl('', 'module', 'admin', 'act', 'dispCommentAdminList', 'search_target', 'ipaddress', 'search_keyword', $oComment->getIpAddress()); $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()); $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'); $oCommentController->addCommentPopupMenu($url, 'cmd_add_ip_to_spamfilter', '', 'javascript');

View file

@ -12,6 +12,7 @@
<action name="procCommentVoteDown" type="controller" /> <action name="procCommentVoteDown" type="controller" />
<action name="procCommentVoteDownCancel" type="controller" /> <action name="procCommentVoteDownCancel" type="controller" />
<action name="procCommentDeclare" type="controller" permission="member" /> <action name="procCommentDeclare" type="controller" permission="member" />
<action name="procCommentDeclareCancel" type="controller" permission="member" />
<action name="procCommentGetList" type="controller" permission="manager" check_type="comment" check_var="comment_srls" /> <action name="procCommentGetList" type="controller" permission="manager" check_type="comment" check_var="comment_srls" />
<action name="procCommentInsertModuleConfig" type="controller" permission="manager" check_var="target_module_srl" ruleset="insertCommentModuleConfig" /> <action name="procCommentInsertModuleConfig" type="controller" permission="manager" check_var="target_module_srl" ruleset="insertCommentModuleConfig" />

View file

@ -0,0 +1,11 @@
<query id="updateDeclaredCommentCancel" action="update">
<tables>
<table name="comment_declared" />
</tables>
<columns>
<column name="declared_count" default="minus(1)" />
</columns>
<conditions>
<condition operation="equal" column="comment_srl" var="comment_srl" filter="number" notnull="notnull" />
</conditions>
</query>

View file

@ -2,9 +2,13 @@
<load target="./css/declare_comment.css" /> <load target="./css/declare_comment.css" />
<form action="./" method="post" id="fo_component" ruleset="insertDeclare"> <form action="./" method="post" id="fo_component" ruleset="insertDeclare">
<input type="hidden" name="module" value="comment" /> <input type="hidden" name="module" value="comment" />
<!--@if($type == 'cancel')-->
<input type="hidden" name="act" value="procCommentDeclareCancel" />
<!--@else-->
<input type="hidden" name="act" value="procCommentDeclare" /> <input type="hidden" name="act" value="procCommentDeclare" />
<!--@end-->
<input type="hidden" name="target_srl" value="{$target_srl}" /> <input type="hidden" name="target_srl" value="{$target_srl}" />
<input type="hidden" name="success_return_url" value="{getUrl('', 'act', $act, 'target_srl', $target_srl)}" /> <input type="hidden" name="success_return_url" value="{getUrl('', 'mid', $mid, 'act', $act, 'target_srl', $target_srl)}" />
<input type="hidden" name="xe_validator_id" value="modules/comment/tpl/1" /> <input type="hidden" name="xe_validator_id" value="modules/comment/tpl/1" />
<div class="x_modal-header"> <div class="x_modal-header">
<h1>{$lang->improper_comment_declare} <!--@if($type == 'cancel')-->{$lang->cmd_cancel}<!--@end--></h1> <h1>{$lang->improper_comment_declare} <!--@if($type == 'cancel')-->{$lang->cmd_cancel}<!--@end--></h1>
@ -16,6 +20,7 @@
<p>{$target_comment->getSummary(200)}</p> <p>{$target_comment->getSummary(200)}</p>
</section> </section>
</blockquote> </blockquote>
<!--@if($type !== 'cancel')-->
<div class="x_control-group"> <div class="x_control-group">
<label class="x_control-label" for="message_option">{$lang->improper_comment_declare_reason}</label> <label class="x_control-label" for="message_option">{$lang->improper_comment_declare_reason}</label>
<div class="x_controls"> <div class="x_controls">
@ -26,16 +31,20 @@
<p>{$lang->about_improper_comment_declare}<p> <p>{$lang->about_improper_comment_declare}<p>
</div> </div>
</div> </div>
<!--@end-->
<div class="x_modal-footer"> <div class="x_modal-footer">
<span class="x_btn-group x_pull-right"> <span class="x_btn-group x_pull-right">
<button type="submit" class="x_btn x_btn-primary">{$lang->cmd_submit}</button> <button type="submit" class="x_btn x_btn-primary"><!--@if($type == 'cancel')-->{$lang->cmd_cancel_declare}<!--@else-->{$lang->cmd_submit}<!--@end--></button>
</span> </span>
</div> </div>
</div> </div>
</form> </form>
<script cond="$XE_VALIDATOR_MESSAGE && $XE_VALIDATOR_ID == 'modules/comment/tpl/1'"> <script cond="$XE_VALIDATOR_MESSAGE && $XE_VALIDATOR_ID == 'modules/comment/tpl/1'">
alert("{$XE_VALIDATOR_MESSAGE}"); alert("{$XE_VALIDATOR_MESSAGE}");
window.close(); if (opener) {
opener.location.reload();
window.close();
}
</script> </script>
<script> <script>
(function($){ (function($){