Add option to limit the maximum thread depth of comments

This commit is contained in:
Kijin Sung 2024-10-09 16:45:36 +09:00
parent 81d9f46098
commit a4e9eb4a00
8 changed files with 60 additions and 0 deletions

View file

@ -735,6 +735,17 @@ class CommentController extends Comment
$list_args->head = $parent->head;
$list_args->depth = $parent->depth + 1;
// Check max thread depth.
$comment_config = ModuleModel::getModulePartConfig('comment', $obj->module_srl);
if (isset($comment_config->max_thread_depth) && $comment_config->max_thread_depth > 0)
{
if ($list_args->depth + 1 > $comment_config->max_thread_depth)
{
$oDB->rollback();
return new BaseObject(-1, 'msg_exceeds_max_thread_depth');
}
}
// if the depth of comments is less than 2, execute insert.
if($list_args->depth < 2)
{
@ -2041,6 +2052,7 @@ class CommentController extends Comment
{
$comment_config->comment_page_count = 10;
}
$comment_config->max_thread_depth = (int)Context::get('max_thread_depth') ?: 0;
$comment_config->default_page = Context::get('default_page');
if($comment_config->default_page !== 'first')

View file

@ -246,6 +246,18 @@ class CommentModel extends Comment
return $result;
}
/**
* Get comment depth.
*
* @param int $comment_srl
* @return ?int
*/
public static function getCommentDepth(int $comment_srl): ?int
{
$output = executeQuery('comment.getCommentDepth', ['comment_srl' => $comment_srl]);
return isset($output->data->depth) ? (int)$output->data->depth : null;
}
/**
* Get the total number of comments in corresponding with document_srl.
* @param int $document_srl

View file

@ -12,8 +12,11 @@ $lang->comment_default_page_first = 'First page';
$lang->comment_default_page_last = 'Last page';
$lang->about_comment_count = 'Set the number of comments to show on each page.';
$lang->about_comment_page_count = 'Set the number of pagination links to show at the bottom.';
$lang->max_thread_depth = 'Maximum Thread Depth';
$lang->about_max_thread_depth = '0: Unlimited, 1: No replies, 2 or more: Allow replies';
$lang->msg_cart_is_null = 'Please select an article to delete.';
$lang->msg_checked_comment_is_deleted = '%d comment(s) is(are) successfully deleted.';
$lang->msg_exceeds_max_thread_depth = 'You have exceeded the maximum thread depth. Please leave a reply elsewhere in the thread.';
$lang->search_target_list['content'] = 'Content';
$lang->search_target_list['user_id'] = 'ID';
$lang->search_target_list['user_name'] = 'Name';

View file

@ -12,8 +12,11 @@ $lang->comment_default_page_first = '첫 페이지';
$lang->comment_default_page_last = '마지막 페이지';
$lang->about_comment_count = '댓글을 정해진 수 만큼만 표시하고, 그 이상일 경우 페이지 번호를 표시해서 이동할 수 있게 합니다.';
$lang->about_comment_page_count = '하단에 표시할 페이지 링크 수를 설정할 수 있습니다.';
$lang->max_thread_depth = '대댓글 최대 깊이';
$lang->about_max_thread_depth = '0: 무제한, 1: 대댓글 금지, 2 이상: 대댓글 허용';
$lang->msg_cart_is_null = '삭제할 글을 선택해주세요.';
$lang->msg_checked_comment_is_deleted = '%d개의 댓글을 삭제했습니다.';
$lang->msg_exceeds_max_thread_depth = '대댓글 최대 깊이를 초과했습니다. 다른 자리에 댓글을 남겨 주세요.';
$lang->search_target_list['content'] = '내용';
$lang->search_target_list['user_id'] = '아이디';
$lang->search_target_list['user_name'] = '이름';

View file

@ -0,0 +1,11 @@
<query id="getCommentDepth" action="select">
<tables>
<table name="comments_list" />
</tables>
<columns>
<column name="depth" />
</columns>
<conditions>
<condition operation="equal" column="comment_srl" var="comment_srl" notnull="notnull" />
</conditions>
</query>

View file

@ -19,6 +19,13 @@
<p class="x_help-inline">{$lang->about_comment_page_count}</p>
</div>
</div>
<div class="x_control-group">
<label for="max_thread_depth" class="x_control-label">{$lang->max_thread_depth}</label>
<div class="x_controls">
<input type="number" min="0" name="max_thread_depth" id="max_thread_depth" value="{$comment_config->max_thread_depth ?? ''}" />
<p class="x_help-inline">{$lang->about_max_thread_depth}</p>
</div>
</div>
<div class="x_control-group">
<label for="comment_count" class="x_control-label">{$lang->comment_default_page}</label>
<div class="x_controls">