From e675f372cd772ff2b223cee9b9b77d318166400f Mon Sep 17 00:00:00 2001 From: Bogdanova Olga Date: Fri, 26 Mar 2021 22:40:08 +0300 Subject: [PATCH 1/2] Issues-490: Add reply link in comment/discission options --- ReplyTo/class.replyto.plugin.php | 74 ++++++++++++++++---------------- ReplyTo/design/replyto.css | 4 +- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/ReplyTo/class.replyto.plugin.php b/ReplyTo/class.replyto.plugin.php index 075e229..2047455 100644 --- a/ReplyTo/class.replyto.plugin.php +++ b/ReplyTo/class.replyto.plugin.php @@ -91,39 +91,6 @@ public function base_InlineDiscussionOptionsLeft_handler($sender, $args){ echo ''; } - public function base_inlineCommentOptionsRight_handler($sender, $args) { - ReplyToPlugin::log('base_inlineCommentOptionsRight_handler', []); - - if (!Gdn::Session()->isValid()) { - return; - } - - $discussion = $sender->data('Discussion'); - $isClosed = ((int)$discussion->Closed) == 1; - if ($isClosed) { - return; - } - - //Check permission - $CategoryID = val('PermissionCategoryID', $discussion) ? val('PermissionCategoryID', $discussion) : val('CategoryID', $discussion); - - // Can the user comment on this category, and is the discussion open for comments? - if (!Gdn::Session()->CheckPermission('Vanilla.Comments.Add', TRUE, 'Category', $CategoryID)) { - return; - } - - $viewMode = self::getViewMode(); - $comment = &$args['Comment']; - $items = & $args['Items']; - $commentID = val('CommentID', $comment); - if(empty($items)) { - $items = []; - } - array_push( $items, anchor( - t('Reply'), - url("/?ParentCommentID=".$commentID."&view=".$viewMode, false), 'ReplyComment')); - } - /** * Set the tree order of all comments in the model as soon as it is instantiated. * It is not clear if there are other plugins that may also wish to change the ordering. @@ -242,9 +209,8 @@ public function base_commentOptions_handler($sender, $args) { return; } - /* $options = &$args['CommentOptions']; - $comment = &$args['Comment']; + $comment = $args['Comment']; $options['ReplyToComment'] = [ 'Label' => t('Reply'), 'Url' => '/?ParentCommentID='.$comment->CommentID, @@ -264,7 +230,43 @@ public function base_commentOptions_handler($sender, $args) { $options[$key]['Url'] = $currentUrl.'?view='.$viewMode; } } - */ + } + + /** + * Add 'Reply' option to discussion. + * + * @param Gdn_Controller $sender + * @param array $args + */ + public function base_inlineDiscussionOptions_handler($sender, $args) { + $discussion = $args['Discussion']; + if (!$discussion) { + return; + } + + $isClosed = ((int)$discussion->Closed) == 1; + if ($isClosed) { + return; + } + + if (!Gdn::session()->UserID) { + return; + } + + //Check permission + if (isset($discussion->PermissionCategoryID)) { + $CategoryID = val('PermissionCategoryID', $discussion); + } else { + $CategoryID = $discussion->CategoryID; + } + + // Can the user comment on this category, and is the discussion open for comments? + if (!Gdn::Session()->CheckPermission('Vanilla.Comments.Add', TRUE, 'Category', $CategoryID)) { + return; + } + // DropdownModule options + $options = & $args['DiscussionOptions']; + $options->addLink('Reply', url("/", true), 'reply', 'ReplyComment'); } /** diff --git a/ReplyTo/design/replyto.css b/ReplyTo/design/replyto.css index 7b8916a..dea2380 100644 --- a/ReplyTo/design/replyto.css +++ b/ReplyTo/design/replyto.css @@ -1,5 +1,6 @@ .ReplyViewOptions { + font-family: roboto, Segoe UI, Helvetica Neue, Helvetica, Raleway, Arial, sans-serif; display: inline-block; line-height: 1.5; } @@ -8,8 +9,7 @@ } .MessageList .ItemDiscussion .Item-Body .Controls a.ReplyViewOptionLink.Active, .ReplyViewOptions .ReplyViewOptionLink.Active { - color: #696969; - font-weight: 800; + color: #555555; } /* Indent comments according to their depth. From f6ba15fc199fe544f9d777c18398c86d38125e3e Mon Sep 17 00:00:00 2001 From: Bogdanova Olga Date: Fri, 26 Mar 2021 23:57:38 +0300 Subject: [PATCH 2/2] Issues-490: Render reply link if user has permissison --- ReplyTo/class.replyto.plugin.php | 39 +++++++++++++------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/ReplyTo/class.replyto.plugin.php b/ReplyTo/class.replyto.plugin.php index 2047455..298cab1 100644 --- a/ReplyTo/class.replyto.plugin.php +++ b/ReplyTo/class.replyto.plugin.php @@ -192,22 +192,20 @@ public function base_commentOptions_handler($sender, $args) { return; } $discussion = $sender->data('Discussion'); - $isClosed = ((int)$discussion->Closed) == 1; - if ($isClosed) { - return; - } //Check permission - if (isset($discussion->PermissionCategoryID)) { - $CategoryID = val('PermissionCategoryID', $discussion); - } else { - $CategoryID = $discussion->CategoryID; - } + $CategoryID = val('PermissionCategoryID', $discussion)? val('PermissionCategoryID', $discussion):val('CategoryID', $discussion); + $userCanClose = CategoryModel::checkPermission($CategoryID, 'Vanilla.Discussions.Close'); + $userCanComment = CategoryModel::checkPermission($CategoryID, 'Vanilla.Comments.Add'); - // Can the user comment on this category, and is the discussion open for comments? - if (!Gdn::Session()->CheckPermission('Vanilla.Comments.Add', TRUE, 'Category', $CategoryID)) { + $canAddComment = ($discussion->Closed == '1' && $userCanClose) || ($discussion->Closed == '0' && $userCanComment); + if (!$canAddComment) { return; } + // Can the user comment on this category, and is the discussion open for comments? + // if (!Gdn::Session()->CheckPermission('Vanilla.Comments.Add', TRUE, 'Category', $CategoryID)) { + // return; + // } $options = &$args['CommentOptions']; $comment = $args['Comment']; @@ -244,26 +242,21 @@ public function base_inlineDiscussionOptions_handler($sender, $args) { return; } - $isClosed = ((int)$discussion->Closed) == 1; - if ($isClosed) { - return; - } - if (!Gdn::session()->UserID) { return; } //Check permission - if (isset($discussion->PermissionCategoryID)) { - $CategoryID = val('PermissionCategoryID', $discussion); - } else { - $CategoryID = $discussion->CategoryID; - } + $CategoryID = val('PermissionCategoryID', $discussion)? val('PermissionCategoryID', $discussion):val('CategoryID', $discussion); + $userCanClose = CategoryModel::checkPermission($CategoryID, 'Vanilla.Discussions.Close'); + $userCanComment = CategoryModel::checkPermission($CategoryID, 'Vanilla.Comments.Add'); - // Can the user comment on this category, and is the discussion open for comments? - if (!Gdn::Session()->CheckPermission('Vanilla.Comments.Add', TRUE, 'Category', $CategoryID)) { + // See the 'writeCommentForm' method vanilla/applications/vanilla/views/discussion/helper_functions.php + $canAddComment = ($discussion->Closed == '1' && $userCanClose) || ($discussion->Closed == '0' && $userCanComment); + if (!$canAddComment) { return; } + // DropdownModule options $options = & $args['DiscussionOptions']; $options->addLink('Reply', url("/", true), 'reply', 'ReplyComment');