From 60ed01391554d1a41e140b502b410ffe00cf09da Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Tue, 4 Jul 2023 23:15:31 +0900 Subject: [PATCH] Add options to allow voting and reporting from the same IP as the author of a document or comment --- modules/comment/comment.controller.php | 26 +++++++---- .../comment/tpl/comment_module_config.html | 46 +++++++++++++++---- modules/document/document.controller.php | 26 +++++++---- modules/document/lang/en.php | 2 + modules/document/lang/ko.php | 2 + .../document/tpl/document_module_config.html | 34 ++++++++++++-- 6 files changed, 106 insertions(+), 30 deletions(-) diff --git a/modules/comment/comment.controller.php b/modules/comment/comment.controller.php index 2920ae40d..c655a4494 100644 --- a/modules/comment/comment.controller.php +++ b/modules/comment/comment.controller.php @@ -55,7 +55,8 @@ class CommentController extends Comment } $point = 1; - $output = $this->updateVotedCount($comment_srl, $point); + $allow_same_ip = ($comment_config->allow_vote_from_same_ip ?? 'N') === 'Y'; + $output = $this->updateVotedCount($comment_srl, $point, $allow_same_ip); $this->add('voted_count', $output->get('voted_count')); return $output; } @@ -134,7 +135,8 @@ class CommentController extends Comment } $point = -1; - $output = $this->updateVotedCount($comment_srl, $point); + $allow_same_ip = ($comment_config->allow_vote_from_same_ip ?? 'N') === 'Y'; + $output = $this->updateVotedCount($comment_srl, $point, $allow_same_ip); $this->add('blamed_count', $output->get('blamed_count')); return $output; } @@ -1461,9 +1463,10 @@ class CommentController extends Comment * Increase vote-up counts of the comment * @param int $comment_srl * @param int $point + * @param bool $allow_same_ip * @return Object */ - function updateVotedCount($comment_srl, $point = 1) + function updateVotedCount($comment_srl, $point = 1, $allow_same_ip = false) { if($point > 0) { @@ -1484,9 +1487,8 @@ class CommentController extends Comment $oComment = CommentModel::getComment($comment_srl); // Pass if the author's IP address is as same as visitor's. - if($oComment->get('ipaddress') == \RX_CLIENT_IP) + if(!$allow_same_ip && $oComment->get('ipaddress') == \RX_CLIENT_IP && !$this->user->isAdmin()) { - $_SESSION['voted_comment'][$comment_srl] = false; return new BaseObject(-1, $failed_voted); } @@ -1628,9 +1630,11 @@ class CommentController extends Comment $oComment = CommentModel::getComment($comment_srl); // failed if both ip addresses between author's and the current user are same. - if($oComment->get('ipaddress') == \RX_CLIENT_IP && !$this->user->isAdmin()) + $module_srl = $oComment->get('module_srl'); + $comment_config = ModuleModel::getModulePartConfig('comment', $module_srl); + $allow_same_ip = ($comment_config->allow_declare_from_same_ip ?? 'N') === 'Y'; + if(!$allow_same_ip && $oComment->get('ipaddress') == \RX_CLIENT_IP && !$this->user->isAdmin()) { - $_SESSION['declared_comment'][$comment_srl] = FALSE; return new BaseObject(-1, 'failed_declared'); } @@ -1703,8 +1707,6 @@ class CommentController extends Comment // Send message to admin $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); @@ -1944,6 +1946,12 @@ class CommentController extends Comment $comment_config->use_vote_down = 'Y'; } + $comment_config->allow_vote_from_same_ip = Context::get('allow_vote_from_same_ip'); + if(!$comment_config->allow_vote_from_same_ip) $comment_config->allow_vote_from_same_ip = 'N'; + + $comment_config->allow_declare_from_same_ip = Context::get('allow_declare_from_same_ip'); + if(!$comment_config->allow_declare_from_same_ip) $comment_config->allow_declare_from_same_ip = 'N'; + $comment_config->declared_message = Context::get('declared_message'); if(!is_array($comment_config->declared_message)) $comment_config->declared_message = array(); $comment_config->declared_message = array_values($comment_config->declared_message); diff --git a/modules/comment/tpl/comment_module_config.html b/modules/comment/tpl/comment_module_config.html index 070dfbbd7..1b97616cd 100644 --- a/modules/comment/tpl/comment_module_config.html +++ b/modules/comment/tpl/comment_module_config.html @@ -29,9 +29,9 @@
- +
- @@ -39,22 +39,52 @@
- +
-
+
+ +
+ + +
+
+
+ +
+ + +
+
- + +

{$lang->about_comment_validation}

diff --git a/modules/document/document.controller.php b/modules/document/document.controller.php index dc5f558e3..3ce08ab9c 100644 --- a/modules/document/document.controller.php +++ b/modules/document/document.controller.php @@ -59,7 +59,8 @@ class DocumentController extends Document } $point = 1; - $output = $this->updateVotedCount($document_srl, $point); + $allow_same_ip = ($document_config->allow_vote_from_same_ip ?? 'N') === 'Y'; + $output = $this->updateVotedCount($document_srl, $point, $allow_same_ip); if(!$output->toBool()) { return $output; @@ -173,7 +174,8 @@ class DocumentController extends Document } $point = -1; - $output = $this->updateVotedCount($document_srl, $point); + $allow_same_ip = ($document_config->allow_vote_from_same_ip ?? 'N') === 'Y'; + $output = $this->updateVotedCount($document_srl, $point, $allow_same_ip); if(!$output->toBool()) { return $output; @@ -1729,9 +1731,10 @@ class DocumentController extends Document * Increase the number of vote-up of the document * @param int $document_srl * @param int $point + * @param bool $allow_same_ip * @return Object */ - function updateVotedCount($document_srl, $point = 1) + function updateVotedCount($document_srl, $point = 1, $allow_same_ip = false) { if($point > 0) { @@ -1752,9 +1755,8 @@ class DocumentController extends Document $oDocument = DocumentModel::getDocument($document_srl, false, false); // Pass if the author's IP address is as same as visitor's. - if($oDocument->get('ipaddress') == \RX_CLIENT_IP) + if(!$allow_same_ip && $oDocument->get('ipaddress') == \RX_CLIENT_IP && !$this->user->isAdmin()) { - $_SESSION['voted_document'][$document_srl] = false; return new BaseObject(-1, $failed_voted); } @@ -1908,9 +1910,11 @@ class DocumentController extends Document $oDocument = DocumentModel::getDocument($document_srl, false, false); // Pass if the author's IP address is as same as visitor's. - if($oDocument->get('ipaddress') == \RX_CLIENT_IP && !$this->user->isAdmin()) + $module_srl = $oDocument->get('module_srl'); + $document_config = ModuleModel::getModulePartConfig('document', $module_srl); + $allow_same_ip = ($document_config->allow_declare_from_same_ip ?? 'N') === 'Y'; + if(!$allow_same_ip && $oDocument->get('ipaddress') == \RX_CLIENT_IP && !$this->user->isAdmin()) { - $_SESSION['declared_document'][$document_srl] = false; return new BaseObject(-1, 'failed_declared'); } @@ -1983,8 +1987,6 @@ class DocumentController extends Document // Send message to admin $message_targets = array(); - $module_srl = $oDocument->get('module_srl'); - $document_config = ModuleModel::getModulePartConfig('document', $module_srl); if ($document_config->declared_message && in_array('admin', $document_config->declared_message)) { $output = executeQueryArray('member.getAdmins', new stdClass); @@ -3263,6 +3265,12 @@ Content; $document_config->use_vote_down = Context::get('use_vote_down'); if(!$document_config->use_vote_down) $document_config->use_vote_down = 'Y'; + $document_config->allow_vote_from_same_ip = Context::get('allow_vote_from_same_ip'); + if(!$document_config->allow_vote_from_same_ip) $document_config->allow_vote_from_same_ip = 'N'; + + $document_config->allow_declare_from_same_ip = Context::get('allow_declare_from_same_ip'); + if(!$document_config->allow_declare_from_same_ip) $document_config->allow_declare_from_same_ip = 'N'; + $document_config->declared_message = Context::get('declared_message'); if(!is_array($document_config->declared_message)) $document_config->declared_message = array(); $document_config->declared_message = array_values($document_config->declared_message); diff --git a/modules/document/lang/en.php b/modules/document/lang/en.php index b295aed88..abdc1444b 100644 --- a/modules/document/lang/en.php +++ b/modules/document/lang/en.php @@ -117,3 +117,5 @@ $lang->improper_document_reasons['pornography'] = 'Pornography.'; $lang->improper_document_reasons['privacy'] = 'Privacy issue.'; $lang->improper_document_reasons['others'] = 'Others (Write your own)'; $lang->about_improper_document_declare = 'Write here why you report this article as an improper document.'; +$lang->allow_vote_from_same_ip = 'Allow voting from same IP'; +$lang->allow_declare_from_same_ip = 'Allow reporting from same IP'; diff --git a/modules/document/lang/ko.php b/modules/document/lang/ko.php index 8dac794aa..c75020b6f 100644 --- a/modules/document/lang/ko.php +++ b/modules/document/lang/ko.php @@ -117,3 +117,5 @@ $lang->improper_document_reasons['pornography'] = '음란물을 포함하고 있 $lang->improper_document_reasons['privacy'] = '민감한 개인정보가 노출 되어있습니다.'; $lang->improper_document_reasons['others'] = '기타(직접작성)'; $lang->about_improper_document_declare = '게시글을 신고하신 이유를 간단히 적어서 제출해주시면 관리자 검토 후 조치하겠습니다.'; +$lang->allow_vote_from_same_ip = '동일 IP 추천 허용'; +$lang->allow_declare_from_same_ip = '동일 IP 신고 허용'; diff --git a/modules/document/tpl/document_module_config.html b/modules/document/tpl/document_module_config.html index c6d18db61..f205a0219 100644 --- a/modules/document/tpl/document_module_config.html +++ b/modules/document/tpl/document_module_config.html @@ -18,9 +18,9 @@
- +
- @@ -28,15 +28,41 @@
- +
-
+
+ +
+ + +
+
+
+ +
+ + +
+