From 3215631dfca87e4ab72ef3695d78b6d0693b975c Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Wed, 5 Jul 2023 22:27:17 +0900 Subject: [PATCH] Move non-member voting, vote canceling, and report canceling options from Board module to Document & Comment modules --- common/lang/en.php | 2 + common/lang/ko.php | 2 + modules/board/lang/en.php | 4 - modules/board/lang/ko.php | 4 - modules/board/tpl/board_insert.html | 24 -- modules/comment/comment.controller.php | 196 +++++++++++---- modules/comment/comment.view.php | 42 ++++ .../comment/tpl/comment_module_config.html | 60 ++--- modules/document/document.controller.php | 233 ++++++++++++------ modules/document/document.view.php | 41 ++- modules/document/lang/en.php | 3 + modules/document/lang/ko.php | 3 + .../document/tpl/document_module_config.html | 32 +-- 13 files changed, 454 insertions(+), 192 deletions(-) diff --git a/common/lang/en.php b/common/lang/en.php index 85bbc44ef..c735d68fa 100644 --- a/common/lang/en.php +++ b/common/lang/en.php @@ -31,6 +31,8 @@ $lang->cmd_vote = 'Upvote'; $lang->cmd_vote_down = 'Downvote'; $lang->cmd_declare = 'Report'; $lang->cmd_cancel_declare = 'Cancel Report'; +$lang->cmd_vote_config = 'Voting Configuration'; +$lang->cmd_declare_config = 'Reporting Configuration'; $lang->cmd_declared_list = 'Reported List'; $lang->cmd_copy = 'Copy'; $lang->cmd_move = 'Move'; diff --git a/common/lang/ko.php b/common/lang/ko.php index 713b7c045..0f27231c7 100644 --- a/common/lang/ko.php +++ b/common/lang/ko.php @@ -33,6 +33,8 @@ $lang->cmd_declare = '신고'; $lang->cmd_cancel_declare = '신고 취소'; $lang->cmd_cancel_vote = '추천 취소'; $lang->cmd_cancel_vote_down = '비추천 취소'; +$lang->cmd_vote_config = '추천 설정'; +$lang->cmd_declare_config = '신고 설정'; $lang->cmd_declared_list = '신고 목록'; $lang->cmd_copy = '복사'; $lang->cmd_move = '이동'; diff --git a/modules/board/lang/en.php b/modules/board/lang/en.php index 13d64d709..4d20938ec 100644 --- a/modules/board/lang/en.php +++ b/modules/board/lang/en.php @@ -60,7 +60,6 @@ $lang->protect_content = 'Protect Content'; $lang->protect_comment = 'Protect Comment'; $lang->protect_admin_content = 'Protect Admin Content'; $lang->protect_regdate = 'Update/Delete Time Limit'; -$lang->cancel_vote = 'Vote Cancellation'; $lang->filter_specialchars = 'Block Abuse of Unicode Symbols'; $lang->document_length_limit = 'Limit Document Size'; $lang->comment_length_limit = 'Limit Comment Size'; @@ -68,12 +67,9 @@ $lang->about_document_length_limit = 'Restrict documents that are too large. Thi $lang->about_comment_length_limit = 'Restrict comments that are too large.'; $lang->update_order_on_comment = 'Update Document on New Comment'; $lang->about_update_order_on_comment = 'When a new comment is posted, update the update timestamp of the parent document. This is needed for forums.'; -$lang->non_login_vote = 'Allow guest votes'; -$lang->about_cancel_vote = 'Allow users to cancel their votes'; $lang->about_filter_specialchars = 'Prevent use of excessive Unicode accents, RLO characters, and other symbols that hinder readability.'; $lang->document_force_to_move = 'Delete to Trash'; $lang->about_document_force_to_move = 'When a document is deleted, move to Trash instead of deleting it permamently.'; -$lang->about_non_login_vote = 'Allow users who are not logged in to vote on articles.'; $lang->about_protect_regdate = 'Prevent updating or deleting a document or comment after a certain amount of time has passed. (Unit: day)'; $lang->about_protect_content = 'Prevent updating a document if there are comments on it.'; $lang->about_protect_admin_content = 'Prevent updating or deleting a document or comment written by the administrator, even by a user who is permitted to manage the board.'; diff --git a/modules/board/lang/ko.php b/modules/board/lang/ko.php index 1739809a2..d15453650 100644 --- a/modules/board/lang/ko.php +++ b/modules/board/lang/ko.php @@ -61,7 +61,6 @@ $lang->protect_content = '글 보호 기능'; $lang->protect_comment = '댓글 보호 기능'; $lang->protect_admin_content = '최고관리자 보호 기능'; $lang->protect_regdate = '기간 제한 기능'; -$lang->cancel_vote = '추천/비추천/신고 취소 허용'; $lang->filter_specialchars = '유니코드 특수문자 오남용 금지'; $lang->document_length_limit = '문서 길이 제한'; $lang->comment_length_limit = '댓글 길이 제한'; @@ -69,10 +68,7 @@ $lang->about_document_length_limit = '지나치게 용량이 큰 글을 작성 $lang->about_comment_length_limit = '지나치게 용량이 큰 댓글을 작성하지 못하도록 합니다.'; $lang->update_order_on_comment = '댓글 작성시 글 수정 시각 갱신'; $lang->about_update_order_on_comment = '댓글이 작성되면 해당 글의 수정 시각을 갱신합니다. 포럼형 게시판, 최근 댓글 표시 기능 등에 필요합니다.'; -$lang->non_login_vote = '비회원 추천 허용'; -$lang->about_cancel_vote = '추천 비추천 신고를 취소할 수 있습니다.'; $lang->about_filter_specialchars = '가독성에 악영향을 주는 과도한 유니코드 악센트 기호의 조합, RLO 문자 등의 사용을 금지합니다.'; -$lang->about_non_login_vote = '로그인하지 않은 방문자도 추천할 수 있도록 합니다.'; $lang->about_protect_regdate = '글이나 댓글을 작성한 후 일정 기간이 지나면 수정 또는 삭제할 수 없도록 합니다. (단위 : day)'; $lang->about_protect_content = '댓글이 달린 글은 수정 또는 삭제할 수 없도록 합니다.'; $lang->about_protect_admin_content = '최고관리자가 작성한 글이나 댓글은 게시판 관리 권한이 있는 회원이라도 수정 또는 삭제할 수 없도록 합니다.'; diff --git a/modules/board/tpl/board_insert.html b/modules/board/tpl/board_insert.html index dbed3cf23..b3ff9bba0 100644 --- a/modules/board/tpl/board_insert.html +++ b/modules/board/tpl/board_insert.html @@ -318,30 +318,6 @@

{$lang->about_document_force_to_move}

-
- -
- - -

{$lang->about_non_login_vote}

-
-
-
- -
- - -

{$lang->about_cancel_vote}

-
-
diff --git a/modules/comment/comment.controller.php b/modules/comment/comment.controller.php index c655a4494..d2e8c986b 100644 --- a/modules/comment/comment.controller.php +++ b/modules/comment/comment.controller.php @@ -11,34 +11,19 @@ */ class CommentController extends Comment { - /** - * Initialization - * @return void - */ - function init() - { - - } - /** * Action to handle recommendation votes on comments (Up) * @return Object */ function procCommentVoteUp() { - if($this->module_info->non_login_vote !== 'Y') - { - 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; } + + // Check target comment. $oComment = CommentModel::getComment($comment_srl); if(!$oComment->isExists()) { @@ -48,11 +33,31 @@ class CommentController extends Comment { throw new Rhymix\Framework\Exceptions\NotPermitted; } + + // Check if voting is enabled. $comment_config = ModuleModel::getModulePartConfig('comment', $oComment->get('module_srl')); if($comment_config->use_vote_up === 'N') { throw new Rhymix\Framework\Exceptions\FeatureDisabled; } + if(!Context::get('is_logged')) + { + if (isset($comment_config->allow_vote_non_member)) + { + if ($comment_config->allow_vote_non_member !== 'Y') + { + throw new Rhymix\Framework\Exceptions\MustLogin; + } + } + else + { + $module_info = $this->module_info ?: ModuleModel::getModuleInfoByModuleSrl($oComment->get('module_srl')); + if (($module_info->non_login_vote ?? 'N') !== 'Y') + { + throw new Rhymix\Framework\Exceptions\MustLogin; + } + } + } $point = 1; $allow_same_ip = ($comment_config->allow_vote_from_same_ip ?? 'N') === 'Y'; @@ -63,19 +68,13 @@ class CommentController extends Comment function procCommentVoteUpCancel() { - if($this->module_info->non_login_vote !== 'Y') - { - 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; } + + // Check target comment. $oComment = CommentModel::getComment($comment_srl); if(!$oComment->isExists()) { @@ -90,8 +89,47 @@ class CommentController extends Comment throw new Rhymix\Framework\Exception('failed_voted_canceled'); } + // Check if voting and canceling are enabled. + $comment_config = ModuleModel::getModulePartConfig('comment', $oComment->get('module_srl')); + $module_info = $this->module_info ?: ModuleModel::getModuleInfoByModuleSrl($oComment->get('module_srl')); + if (isset($comment_config->allow_vote_cancel)) + { + if ($comment_config->allow_vote_cancel !== 'Y') + { + throw new Rhymix\Framework\Exceptions\FeatureDisabled; + } + } + else + { + if (($module_info->cancel_vote ?? 'N') !== 'Y') + { + throw new Rhymix\Framework\Exceptions\FeatureDisabled; + } + } + if(!Context::get('is_logged')) + { + if (isset($comment_config->allow_vote_non_member)) + { + if ($comment_config->allow_vote_non_member !== 'Y') + { + throw new Rhymix\Framework\Exceptions\MustLogin; + } + } + else + { + if (($module_info->non_login_vote ?? 'N') !== 'Y') + { + throw new Rhymix\Framework\Exceptions\MustLogin; + } + } + } + $point = 1; $output = $this->updateVotedCountCancel($comment_srl, $oComment, $point); + if(!$output->toBool()) + { + return $output; + } $output = new BaseObject(); $output->setMessage('success_voted_canceled'); @@ -106,19 +144,13 @@ class CommentController extends Comment */ function procCommentVoteDown() { - if($this->module_info->non_login_vote !== 'Y') - { - 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; } + + // Check target comment. $oComment = CommentModel::getComment($comment_srl); if(!$oComment->isExists()) { @@ -128,11 +160,31 @@ class CommentController extends Comment { throw new Rhymix\Framework\Exceptions\NotPermitted; } + + // Check if voting is enabled. $comment_config = ModuleModel::getModulePartConfig('comment', $oComment->get('module_srl')); if($comment_config->use_vote_down === 'N') { throw new Rhymix\Framework\Exceptions\FeatureDisabled; } + if(!Context::get('is_logged')) + { + if (isset($comment_config->allow_vote_non_member)) + { + if ($comment_config->allow_vote_non_member !== 'Y') + { + throw new Rhymix\Framework\Exceptions\MustLogin; + } + } + else + { + $module_info = $this->module_info ?: ModuleModel::getModuleInfoByModuleSrl($oComment->get('module_srl')); + if (($module_info->non_login_vote ?? 'N') !== 'Y') + { + throw new Rhymix\Framework\Exceptions\MustLogin; + } + } + } $point = -1; $allow_same_ip = ($comment_config->allow_vote_from_same_ip ?? 'N') === 'Y'; @@ -143,19 +195,13 @@ class CommentController extends Comment function procCommentVoteDownCancel() { - if($this->module_info->non_login_vote !== 'Y') - { - 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; } + + // Check target comment. $oComment = CommentModel::getComment($comment_srl); if(!$oComment->isExists()) { @@ -170,8 +216,47 @@ class CommentController extends Comment throw new Rhymix\Framework\Exception('failed_blamed_canceled'); } + // Check if voting and canceling are enabled. + $comment_config = ModuleModel::getModulePartConfig('comment', $oComment->get('module_srl')); + $module_info = $this->module_info ?: ModuleModel::getModuleInfoByModuleSrl($oComment->get('module_srl')); + if (isset($comment_config->allow_vote_cancel)) + { + if ($comment_config->allow_vote_cancel !== 'Y') + { + throw new Rhymix\Framework\Exceptions\FeatureDisabled; + } + } + else + { + if (($module_info->cancel_vote ?? 'N') !== 'Y') + { + throw new Rhymix\Framework\Exceptions\FeatureDisabled; + } + } + if(!Context::get('is_logged')) + { + if (isset($comment_config->allow_vote_non_member)) + { + if ($comment_config->allow_vote_non_member !== 'Y') + { + throw new Rhymix\Framework\Exceptions\MustLogin; + } + } + else + { + if (($module_info->non_login_vote ?? 'N') !== 'Y') + { + throw new Rhymix\Framework\Exceptions\MustLogin; + } + } + } + $point = -1; $output = $this->updateVotedCountCancel($comment_srl, $oComment, $point); + if(!$output->toBool()) + { + return $output; + } $output = new BaseObject(); $output->setMessage('success_blamed_canceled'); @@ -305,6 +390,7 @@ class CommentController extends Comment throw new Rhymix\Framework\Exceptions\MustLogin; } + // Check if the comment exists and is accessible to the current user. $comment_srl = Context::get('target_srl'); if (!$comment_srl) { @@ -319,10 +405,23 @@ class CommentController extends Comment { throw new Rhymix\Framework\Exceptions\NotPermitted; } - $module_info = ModuleModel::getModuleInfoByModuleSrl($oComment->get('module_srl')); - if ($module_info->cancel_vote !== 'Y') + + // Check if canceling is allowed. + $comment_config = ModuleModel::getModulePartConfig('comment', $oComment->get('module_srl')); + if (isset($comment_config->allow_declare_cancel)) { - throw new Rhymix\Framework\Exception('failed_declared_cancel'); + if ($comment_config->allow_declare_cancel !== 'Y') + { + throw new Rhymix\Framework\Exception('failed_declared_cancel'); + } + } + else + { + $module_info = ModuleModel::getModuleInfoByModuleSrl($oComment->get('module_srl')); + if (($module_info->cancel_vote ?? 'N') !== 'Y') + { + throw new Rhymix\Framework\Exception('failed_declared_cancel'); + } } if (Context::get('success_return_url')) @@ -1949,9 +2048,18 @@ class CommentController extends Comment $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_vote_cancel = Context::get('allow_vote_cancel'); + if(!$comment_config->allow_vote_cancel) $comment_config->allow_vote_cancel = 'N'; + + $comment_config->allow_vote_non_member = Context::get('allow_vote_non_member'); + if(!$comment_config->allow_vote_non_member) $comment_config->allow_vote_non_member = '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->allow_declare_cancel = Context::get('allow_declare_cancel'); + if(!$comment_config->allow_declare_cancel) $comment_config->allow_declare_cancel = '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/comment.view.php b/modules/comment/comment.view.php index fb5a1c62c..87f4226dd 100644 --- a/modules/comment/comment.view.php +++ b/modules/comment/comment.view.php @@ -44,6 +44,48 @@ class CommentView extends Comment // get the comment configuration $comment_config = CommentModel::getCommentConfig($current_module_srl); + if(!$comment_config) + { + $comment_config = new stdClass(); + } + if(!isset($comment_config->cmd_comment_validation)) + { + $comment_config->cmd_comment_validation = 'N'; + } + if(!isset($comment_config->use_vote_up)) + { + $comment_config->use_vote_up = 'Y'; + } + if(!isset($comment_config->use_vote_down)) + { + $comment_config->use_vote_down = 'Y'; + } + if(!isset($comment_config->allow_vote_from_same_ip)) + { + $comment_config->allow_vote_from_same_ip = 'N'; + } + if(!isset($comment_config->allow_declare_from_same_ip)) + { + $comment_config->allow_declare_from_same_ip = 'N'; + } + + if ($current_module_srl) + { + $module_info = ModuleModel::getModuleInfoByModuleSrl($current_module_srl); + if (!isset($comment_config->allow_vote_cancel)) + { + $comment_config->allow_vote_cancel = (($module_info->cancel_vote ?? 'N') === 'Y') ? 'Y' : 'N'; + } + if (!isset($comment_config->allow_vote_non_member)) + { + $comment_config->allow_vote_non_member = (($module_info->non_login_vote ?? 'N') === 'Y') ? 'Y' : 'N'; + } + if (!isset($comment_config->allow_declare_cancel)) + { + $comment_config->allow_declare_cancel = (($module_info->cancel_vote ?? 'N') === 'Y') ? 'Y' : 'N'; + } + } + Context::set('comment_config', $comment_config); // get a group list diff --git a/modules/comment/tpl/comment_module_config.html b/modules/comment/tpl/comment_module_config.html index 1b97616cd..6a4cdac7d 100644 --- a/modules/comment/tpl/comment_module_config.html +++ b/modules/comment/tpl/comment_module_config.html @@ -28,6 +28,20 @@
+
+ +
+ + +

{$lang->about_comment_validation}

+
+
@@ -49,45 +63,35 @@
- +
-
- +
-
-
- -
- - -

{$lang->about_comment_validation}

-
-
diff --git a/modules/document/document.controller.php b/modules/document/document.controller.php index 3ce08ab9c..65458b9a9 100644 --- a/modules/document/document.controller.php +++ b/modules/document/document.controller.php @@ -30,19 +30,7 @@ class DocumentController extends Document throw new Rhymix\Framework\Exceptions\InvalidRequest; } - $module_info = $this->module_info; - if(!$module_info->module_srl) - { - $module_info = ModuleModel::getModuleInfoByDocumentSrl($document_srl); - } - if($module_info->non_login_vote !== 'Y') - { - if(!Context::get('is_logged')) - { - throw new Rhymix\Framework\Exceptions\NotPermitted; - } - } - + // Check target document. $oDocument = DocumentModel::getDocument($document_srl, false, false); if(!$oDocument->isExists()) { @@ -52,11 +40,31 @@ class DocumentController extends Document { throw new Rhymix\Framework\Exceptions\NotPermitted; } + + // Check if voting is enabled. $document_config = ModuleModel::getModulePartConfig('document', $oDocument->get('module_srl')); if($document_config->use_vote_up === 'N') { throw new Rhymix\Framework\Exceptions\FeatureDisabled; } + if(!Context::get('is_logged')) + { + if (isset($document_config->allow_vote_non_member)) + { + if ($document_config->allow_vote_non_member !== 'Y') + { + throw new Rhymix\Framework\Exceptions\MustLogin; + } + } + else + { + $module_info = $this->module_info ?: ModuleModel::getModuleInfoByModuleSrl($oDocument->get('module_srl')); + if (($module_info->non_login_vote ?? 'N') !== 'Y') + { + throw new Rhymix\Framework\Exceptions\MustLogin; + } + } + } $point = 1; $allow_same_ip = ($document_config->allow_vote_from_same_ip ?? 'N') === 'Y'; @@ -77,23 +85,7 @@ class DocumentController extends Document throw new Rhymix\Framework\Exceptions\InvalidRequest; } - $module_info = $this->module_info; - if(!$module_info->module_srl) - { - $module_info = ModuleModel::getModuleInfoByDocumentSrl($document_srl); - } - if($module_info->non_login_vote !== 'Y') - { - if(!Context::get('is_logged')) - { - throw new Rhymix\Framework\Exceptions\NotPermitted; - } - } - if($module_info->cancel_vote !== 'Y') - { - throw new Rhymix\Framework\Exception('failed_voted_cancel'); - } - + // Check target document. $oDocument = DocumentModel::getDocument($document_srl, false, false); if(!$oDocument->isExists()) { @@ -108,6 +100,41 @@ class DocumentController extends Document throw new Rhymix\Framework\Exception('failed_voted_canceled'); } + // Check if voting and canceling are enabled. + $document_config = ModuleModel::getModulePartConfig('document', $oDocument->get('module_srl')); + $module_info = $this->module_info ?: ModuleModel::getModuleInfoByModuleSrl($oDocument->get('module_srl')); + if (isset($document_config->allow_vote_cancel)) + { + if ($document_config->allow_vote_cancel !== 'Y') + { + throw new Rhymix\Framework\Exceptions\FeatureDisabled; + } + } + else + { + if (($module_info->cancel_vote ?? 'N') !== 'Y') + { + throw new Rhymix\Framework\Exceptions\FeatureDisabled; + } + } + if(!Context::get('is_logged')) + { + if (isset($document_config->allow_vote_non_member)) + { + if ($document_config->allow_vote_non_member !== 'Y') + { + throw new Rhymix\Framework\Exceptions\MustLogin; + } + } + else + { + if (($module_info->non_login_vote ?? 'N') !== 'Y') + { + throw new Rhymix\Framework\Exceptions\MustLogin; + } + } + } + $point = 1; $output = $this->updateVotedCountCancel($document_srl, $oDocument, $point); if(!$output->toBool()) @@ -120,44 +147,19 @@ class DocumentController extends Document return $output; } - /** - * insert alias - * @param int $module_srl - * @param int $document_srl - * @param string $alias_title - * @return object - */ - function insertAlias($module_srl, $document_srl, $alias_title) - { - $args = new stdClass; - $args->alias_srl = getNextSequence(); - $args->module_srl = $module_srl; - $args->document_srl = $document_srl; - $args->alias_title = urldecode($alias_title); - $query = "document.insertAlias"; - $output = executeQuery($query, $args); - return $output; - } - /** * Action to handle vote-up of the post (Down) * @return Object */ function procDocumentVoteDown() { - if($this->module_info->non_login_vote !== 'Y') - { - if(!Context::get('is_logged')) - { - throw new Rhymix\Framework\Exceptions\NotPermitted; - } - } - $document_srl = Context::get('target_srl'); if(!$document_srl) { throw new Rhymix\Framework\Exceptions\InvalidRequest; } + + // Check target document. $oDocument = DocumentModel::getDocument($document_srl, false, false); if(!$oDocument->isExists()) { @@ -167,11 +169,31 @@ class DocumentController extends Document { throw new Rhymix\Framework\Exceptions\NotPermitted; } + + // Check if voting is enabled. $document_config = ModuleModel::getModulePartConfig('document', $oDocument->get('module_srl')); if($document_config->use_vote_down === 'N') { throw new Rhymix\Framework\Exceptions\FeatureDisabled; } + if(!Context::get('is_logged')) + { + if (isset($document_config->allow_vote_non_member)) + { + if ($document_config->allow_vote_non_member !== 'Y') + { + throw new Rhymix\Framework\Exceptions\MustLogin; + } + } + else + { + $module_info = $this->module_info ?: ModuleModel::getModuleInfoByModuleSrl($oDocument->get('module_srl')); + if (($module_info->non_login_vote ?? 'N') !== 'Y') + { + throw new Rhymix\Framework\Exceptions\MustLogin; + } + } + } $point = -1; $allow_same_ip = ($document_config->allow_vote_from_same_ip ?? 'N') === 'Y'; @@ -186,23 +208,13 @@ class DocumentController extends Document function procDocumentVoteDownCancel() { - if($this->module_info->non_login_vote !== 'Y') - { - if(!Context::get('is_logged')) - { - throw new Rhymix\Framework\Exceptions\NotPermitted; - } - } - if($this->module_info->cancel_vote !== 'Y') - { - return new Rhymix\Framework\Exception('failed_voted_canceled'); - } - $document_srl = Context::get('target_srl'); if(!$document_srl) { throw new Rhymix\Framework\Exceptions\InvalidRequest; } + + // Check target document. $oDocument = DocumentModel::getDocument($document_srl, false, false); if(!$oDocument->isExists()) { @@ -217,6 +229,41 @@ class DocumentController extends Document throw new Rhymix\Framework\Exception('failed_blamed_canceled'); } + // Check if voting and canceling are enabled. + $document_config = ModuleModel::getModulePartConfig('document', $oDocument->get('module_srl')); + $module_info = $this->module_info ?: ModuleModel::getModuleInfoByModuleSrl($oDocument->get('module_srl')); + if (isset($document_config->allow_vote_cancel)) + { + if ($document_config->allow_vote_cancel !== 'Y') + { + throw new Rhymix\Framework\Exceptions\FeatureDisabled; + } + } + else + { + if (($module_info->cancel_vote ?? 'N') !== 'Y') + { + throw new Rhymix\Framework\Exceptions\FeatureDisabled; + } + } + if(!Context::get('is_logged')) + { + if (isset($document_config->allow_vote_non_member)) + { + if ($document_config->allow_vote_non_member !== 'Y') + { + throw new Rhymix\Framework\Exceptions\MustLogin; + } + } + else + { + if (($module_info->non_login_vote ?? 'N') !== 'Y') + { + throw new Rhymix\Framework\Exceptions\MustLogin; + } + } + } + $point = -1; $output = $this->updateVotedCountCancel($document_srl, $oDocument, $point); if(!$output->toBool()) @@ -367,6 +414,7 @@ class DocumentController extends Document throw new Rhymix\Framework\Exceptions\MustLogin; } + // Check if the document exists and is accessible to the current user. $document_srl = Context::get('target_srl'); if(!$document_srl) { @@ -381,10 +429,23 @@ class DocumentController extends Document { throw new Rhymix\Framework\Exceptions\NotPermitted; } - $module_info = ModuleModel::getModuleInfoByDocumentSrl($document_srl); - if($module_info->cancel_vote !== 'Y') + + // Check if canceling is allowed. + $document_config = ModuleModel::getModulePartConfig('document', $oDocument->get('module_srl')); + if (isset($document_config->allow_declare_cancel)) { - throw new Rhymix\Framework\Exception('failed_declared_cancel'); + if ($document_config->allow_declare_cancel !== 'Y') + { + throw new Rhymix\Framework\Exception('failed_declared_cancel'); + } + } + else + { + $module_info = ModuleModel::getModuleInfoByModuleSrl($oDocument->get('module_srl')); + if (($module_info->cancel_vote ?? 'N') !== 'Y') + { + throw new Rhymix\Framework\Exception('failed_declared_cancel'); + } } if(Context::get('success_return_url')) @@ -423,6 +484,25 @@ class DocumentController extends Document } } + /** + * insert alias + * @param int $module_srl + * @param int $document_srl + * @param string $alias_title + * @return object + */ + function insertAlias($module_srl, $document_srl, $alias_title) + { + $args = new stdClass; + $args->alias_srl = getNextSequence(); + $args->module_srl = $module_srl; + $args->document_srl = $document_srl; + $args->alias_title = urldecode($alias_title); + $query = "document.insertAlias"; + $output = executeQuery($query, $args); + return $output; + } + /** * Delete alias when module deleted * @param int $module_srl @@ -3268,9 +3348,18 @@ Content; $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_vote_cancel = Context::get('allow_vote_cancel'); + if(!$document_config->allow_vote_cancel) $document_config->allow_vote_cancel = 'N'; + + $document_config->allow_vote_non_member = Context::get('allow_vote_non_member'); + if(!$document_config->allow_vote_non_member) $document_config->allow_vote_non_member = '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->allow_declare_cancel = Context::get('allow_declare_cancel'); + if(!$document_config->allow_declare_cancel) $document_config->allow_declare_cancel = '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/document.view.php b/modules/document/document.view.php index 34c072bae..20c2d972e 100644 --- a/modules/document/document.view.php +++ b/modules/document/document.view.php @@ -174,10 +174,47 @@ class DocumentView extends Document { $document_config = new stdClass(); } - if(!isset($document_config->use_history)) $document_config->use_history = 'N'; + if(!isset($document_config->use_history)) + { + $document_config->use_history = 'N'; + } + if(!isset($document_config->use_vote_up)) + { + $document_config->use_vote_up = 'Y'; + } + if(!isset($document_config->use_vote_down)) + { + $document_config->use_vote_down = 'Y'; + } + if(!isset($document_config->allow_vote_from_same_ip)) + { + $document_config->allow_vote_from_same_ip = 'N'; + } + if(!isset($document_config->allow_declare_from_same_ip)) + { + $document_config->allow_declare_from_same_ip = 'N'; + } + + if ($current_module_srl) + { + $module_info = ModuleModel::getModuleInfoByModuleSrl($current_module_srl); + if (!isset($document_config->allow_vote_cancel)) + { + $document_config->allow_vote_cancel = (($module_info->cancel_vote ?? 'N') === 'Y') ? 'Y' : 'N'; + } + if (!isset($document_config->allow_vote_non_member)) + { + $document_config->allow_vote_non_member = (($module_info->non_login_vote ?? 'N') === 'Y') ? 'Y' : 'N'; + } + if (!isset($document_config->allow_declare_cancel)) + { + $document_config->allow_declare_cancel = (($module_info->cancel_vote ?? 'N') === 'Y') ? 'Y' : 'N'; + } + } + Context::set('document_config', $document_config); - $oTemplate = &TemplateHandler::getInstance(); + $oTemplate = TemplateHandler::getInstance(); $tpl = $oTemplate->compile($this->module_path.'tpl', 'document_module_config'); $obj = $tpl . $obj; diff --git a/modules/document/lang/en.php b/modules/document/lang/en.php index abdc1444b..c0293406e 100644 --- a/modules/document/lang/en.php +++ b/modules/document/lang/en.php @@ -118,4 +118,7 @@ $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_vote_non_member = 'Allow voting by non-members'; +$lang->allow_vote_cancel = 'Allow vote cancellation'; $lang->allow_declare_from_same_ip = 'Allow reporting from same IP'; +$lang->allow_declare_cancel = 'Allow report cancellation'; diff --git a/modules/document/lang/ko.php b/modules/document/lang/ko.php index c75020b6f..fa7b98279 100644 --- a/modules/document/lang/ko.php +++ b/modules/document/lang/ko.php @@ -118,4 +118,7 @@ $lang->improper_document_reasons['privacy'] = '민감한 개인정보가 노출 $lang->improper_document_reasons['others'] = '기타(직접작성)'; $lang->about_improper_document_declare = '게시글을 신고하신 이유를 간단히 적어서 제출해주시면 관리자 검토 후 조치하겠습니다.'; $lang->allow_vote_from_same_ip = '동일 IP 추천 허용'; +$lang->allow_vote_non_member = '비회원 추천 허용'; +$lang->allow_vote_cancel = '추천 취소 허용'; $lang->allow_declare_from_same_ip = '동일 IP 신고 허용'; +$lang->allow_declare_cancel = '신고 취소 허용'; diff --git a/modules/document/tpl/document_module_config.html b/modules/document/tpl/document_module_config.html index f205a0219..75f7b2fe6 100644 --- a/modules/document/tpl/document_module_config.html +++ b/modules/document/tpl/document_module_config.html @@ -38,28 +38,32 @@
- +
-
- +
-