diff --git a/config/vanilla/bootstrap.before.php b/config/vanilla/bootstrap.before.php index 7b7775a..86082a3 100644 --- a/config/vanilla/bootstrap.before.php +++ b/config/vanilla/bootstrap.before.php @@ -819,24 +819,33 @@ function writeInlineDiscussionOptions($discussionRow) { echo '
'; echo '
'; - // Write the items. - static $items = []; - - // $canEdit = DiscussionModel::canEdit($discussionRow, $timeLeft); - // if($canEdit) { - // array_push($items, anchor(t('Edit'), '/post/editdiscussion/'.$discussionID)); - // } - - Gdn::controller()->EventArguments['Items'] = &$items; - // Allow addons to work with items - Gdn::controller()->fireEvent('InlineDiscussionOptionsRight'); - if (!empty($items) && is_array($items)) { - array_walk($items, function(&$value, $key) { - $value = ''.$value.''; + // Write the items. + // DropdownModule + $discussionDropdown = getDiscussionOptionsDropdown($discussionRow); + + // Allow plugins to edit the dropdown. + $sender = Gdn::controller(); + $sender->EventArguments['DiscussionOptions'] = &$discussionDropdown ; + $sender->EventArguments['Discussion'] = $discussionRow; + $sender->fireEvent('InlineDiscussionOptions'); + + $discussionDropdownItems = $discussionDropdown->toArray()['items']; + + unset($discussionDropdownItems['announce']); + unset($discussionDropdownItems['sink']); + unset($discussionDropdownItems['close']); + unset($discussionDropdownItems['dismiss']); + unset($discussionDropdownItems['move']); + unset($discussionDropdownItems['tag']); + + if (!empty($discussionDropdownItems) && is_array($discussionDropdownItems)) { + array_walk($discussionDropdownItems, function(&$value, $key) { + $anchor = anchor($value['text'], $value['url'], val('cssClass', $value, $key)); + $value = ''.$anchor.''; }); - echo implode('·', $items); - } + echo implode('·', $discussionDropdownItems); + } echo '
'; echo ''; @@ -849,31 +858,18 @@ function writeInlineCommentOptions($comment) { Gdn::controller()->EventArguments['RecordID'] = $iD; //Gdn_Theme::bulletRow(); echo '
'; - echo '
'; - - $commentOptions = getCommentOptions($comment); - if (!empty($commentOptions) && is_array($commentOptions)) { - - array_walk($commentOptions, function(&$value, $key) { - $anchor = anchor($value['Label'], $value['Url'], val('Class', $value, $key)); - $value = ''.$anchor.''; - }); - - echo implode('·', $commentOptions); - } - echo '
'; + echo '
'; echo '
'; echo '
'; // Write the items. - $items = null; - Gdn::controller()->EventArguments['Comment'] = $comment; - Gdn::controller()->EventArguments['Items'] = &$items; - // Allow addons to work with items - Gdn::controller()->fireEvent('InlineCommentOptionsRight'); + $items = getCommentOptions($comment); if (!empty($items) && is_array($items)) { - array_walk($items, function(&$x) {$x = ''.$x.'';}); - echo implode('·', $items); + array_walk($items, function(&$value, $key) { + $anchor = anchor($value['Label'], $value['Url'], val('Class', $value, $key)); + $value = ''.$anchor.''; + }); + echo implode('·', $items); } echo '
'; echo '
'; diff --git a/vanilla/applications/vanilla/views/discussion/helper_functions.php b/vanilla/applications/vanilla/views/discussion/helper_functions.php index bcd5394..5e3646b 100644 --- a/vanilla/applications/vanilla/views/discussion/helper_functions.php +++ b/vanilla/applications/vanilla/views/discussion/helper_functions.php @@ -121,27 +121,44 @@ function writeComment($comment, $sender, $session, $currentOffset) { fireEvent('BeforeCommentMeta'); ?>
-
- - fireEvent('AuthorPhoto'); - ?> - - - 'MItem AuthorTitle']); - echo ' '.wrapIf(htmlspecialchars(val('Location', $author)), 'span', ['class' => 'MItem AuthorLocation']); - $sender->fireEvent('AuthorInfo'); - ?> - +
+ + fireEvent('AuthorPhoto'); + ?> + + + 'MItem AuthorTitle']); + echo ' '.wrapIf(htmlspecialchars(val('Location', $author)), 'span', ['class' => 'MItem AuthorLocation']); + $sender->fireEvent('AuthorInfo'); + ?> + + + data('Discussion')); + $parentCommentID = $comment->ParentCommentID; + if($parentCommentID) { + $commentModel = new CommentModel(); + $parentComment = $commentModel->getID($parentCommentID); + $parentCommentPermalink = '/discussion/comment/' . $parentCommentID . '/#Comment_' . $parentCommentID; + $parentCommentAuthor = Gdn::userModel()->getID($parentComment->InsertUserID); + $parentCommentAuthor = userAnchor($parentCommentAuthor); + $post = anchor('post', $parentCommentPermalink, 'ParentComment'); + echo ''. wrapIf($discussionName . ' (response to '.$post.' by '.$parentCommentAuthor.')', 'span', ['class' => '']); + } else { + echo ''. wrapIf($discussionName, 'span', ['class' => '']); + } + ?> +
@@ -366,7 +383,7 @@ function getDiscussionOptionsDropdown($discussion = null) { ->addLinkIf($canRefetch, t('Refetch Page'), '/discussion/refetchpageinfo.json?discussionid='.$discussionID, 'refetch', 'RefetchPage Hijack') ->addLinkIf($canMove, t('Move'), '/moderation/confirmdiscussionmoves?discussionid='.$discussionID, 'move', 'MoveDiscussion Popup') ->addLinkIf($canTag, t('Tag'), '/discussion/tag?discussionid='.$discussionID, 'tag', 'TagDiscussion Popup') - ->addLinkIf($canDelete, t('Delete Discussion'), '/discussion/delete?discussionid='.$discussionID.'&target='.$categoryUrl, 'delete', 'DeleteDiscussion Popup'); + ->addLinkIf($canDelete, t('Delete'), '/discussion/delete?discussionid='.$discussionID.'&target='.$categoryUrl, 'delete', 'DeleteDiscussion Popup'); // DEPRECATED $options = []; diff --git a/vanilla/plugins/Quotes/class.quotes.plugin.php b/vanilla/plugins/Quotes/class.quotes.plugin.php index c963a5d..df89e77 100644 --- a/vanilla/plugins/Quotes/class.quotes.plugin.php +++ b/vanilla/plugins/Quotes/class.quotes.plugin.php @@ -238,13 +238,13 @@ public function postController_render_before($sender) { * @param Gdn_Controller $sender * @param array $args */ - public function base_InlineDiscussionOptionsRight_handler($sender, $args) { + public function base_inlineDiscussionOptions_handler($sender, $args) { if ($this->isSupportedFormat(c('Garden.InputFormatter'))) { $this->addQuoteButton($sender, $args); } } - public function base_inlineCommentOptionsRight_handler($sender, $args) { + public function base_commentOptions_handler($sender, $args) { if ($this->isSupportedFormat(c('Garden.InputFormatter'))) { $this->addQuoteButton($sender, $args); } @@ -258,7 +258,8 @@ public function base_inlineCommentOptionsRight_handler($sender, $args) { */ protected function addQuoteButton($sender, $args) { // There are some case were Discussion is not set as an event argument so we use the sender data instead. - $discussion = $sender->data('Discussion'); + // $sender->data('Discussion') is used for updating comment + $discussion = $args['Discussion'] ? $args['Discussion'] : $sender->data('Discussion'); if (!$discussion) { return; } @@ -267,31 +268,36 @@ protected function addQuoteButton($sender, $args) { return; } - if (!Gdn::session()->checkPermission('Vanilla.Comments.Add', false, 'Category', $discussion->PermissionCategoryID)) { + //Check permission + $CategoryID = val('PermissionCategoryID', $discussion)? val('PermissionCategoryID', $discussion):val('CategoryID', $discussion); + $userCanClose = CategoryModel::checkPermission($CategoryID, 'Vanilla.Discussions.Close'); + $userCanComment = CategoryModel::checkPermission($CategoryID, 'Vanilla.Comments.Add'); + + // See the 'writeCommentForm' method vanilla/applications/vanilla/views/discussion/helper_functions.php + $canAddComment = ($discussion->Closed == '1' && $userCanClose) || ($discussion->Closed == '0' && $userCanComment); + if (!$canAddComment) { return; } if (isset($args['Comment'])) { $object = $args['Comment']; $objectID = 'Comment_'.$object->CommentID; + $options = &$args['CommentOptions']; + $options['Quote'] = [ + 'Label' => t('Quote'), + 'Url' => url("post/quote/{$object->DiscussionID}/{$objectID}", true), + 'Class' => 'ReactButton Quote Visible' + ]; + } elseif ($discussion) { $object = $discussion; $objectID = 'Discussion_'.$object->DiscussionID; - } else { - return; + // DropdownModule options + $options = & $args['DiscussionOptions']; + $options->addLink('Quote', url("post/quote/{$object->DiscussionID}/{$objectID}", true), + 'quote', 'ReactButton Quote Visible'); } - $items = & $args['Items']; - //echo Gdn_Theme::bulletItem('Flags'); - if(empty($items)) { - $items = []; - } - array_push( $items, anchor( - t('Quote'), - url("post/quote/{$object->DiscussionID}/{$objectID}", true), - 'ReactButton Quote Visible', - ['role' => 'button'] - ).' '); } /**