Skip to content

Issues-490: fixed discussion/comment options #497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 32 additions & 36 deletions config/vanilla/bootstrap.before.php
Original file line number Diff line number Diff line change
Expand Up @@ -819,24 +819,33 @@ function writeInlineDiscussionOptions($discussionRow) {
echo '<div class="center"></div>';
echo '<div class="right">';

// 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 = '<span class="" style="">'.$value.'</span>';
// 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 = '<span class="" style="">'.$anchor.'</span>';
});

echo implode('<span class="MiddleDot">·</span>', $items);
}
echo implode('<span class="MiddleDot">·</span>', $discussionDropdownItems);
}
echo '</div>';
echo '</div>';

Expand All @@ -849,31 +858,18 @@ function writeInlineCommentOptions($comment) {
Gdn::controller()->EventArguments['RecordID'] = $iD;
//Gdn_Theme::bulletRow();
echo '<div class="Controls flex">';
echo '<div class="left">';

$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 = '<span class="" style="">'.$anchor.'</span>';
});

echo implode('<span class="MiddleDot">·</span>', $commentOptions);
}
echo '</div>';
echo '<div class="left"></div>';
echo '<div class="center"></div>';
echo '<div class="right">';

// 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 = '<span class="" style="">'.$x.'</span>';});
echo implode('<span class="MiddleDot">·</span>', $items);
array_walk($items, function(&$value, $key) {
$anchor = anchor($value['Label'], $value['Url'], val('Class', $value, $key));
$value = '<span class="" style="">'.$anchor.'</span>';
});
echo implode('<span class="MiddleDot">·</span>', $items);
}
echo '</div>';
echo '</div>';
Expand Down
61 changes: 39 additions & 22 deletions vanilla/applications/vanilla/views/discussion/helper_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,27 +121,44 @@ function writeComment($comment, $sender, $session, $currentOffset) {
</div>
<?php $sender->fireEvent('BeforeCommentMeta'); ?>
<div class="Item-Header CommentHeader">
<div class="AuthorWrap">
<span class="Author">
<?php
if ($userPhotoFirst) {
echo userPhoto($author);
echo userAnchor($author, 'Username');
} else {
echo userAnchor($author, 'Username');
echo userPhoto($author);
}
echo formatMeAction($comment);
$sender->fireEvent('AuthorPhoto');
?>
</span>
<span class="AuthorInfo">
<?php
echo ' '.wrapIf(htmlspecialchars(val('Title', $author)), 'span', ['class' => 'MItem AuthorTitle']);
echo ' '.wrapIf(htmlspecialchars(val('Location', $author)), 'span', ['class' => 'MItem AuthorLocation']);
$sender->fireEvent('AuthorInfo');
?>
</span>
<div class="AuthorWrap flex">
<span class="Author">
<?php
if ($userPhotoFirst) {
echo userPhoto($author);
echo userAnchor($author, 'Username');
} else {
echo userAnchor($author, 'Username');
echo userPhoto($author);
}
echo formatMeAction($comment);
$sender->fireEvent('AuthorPhoto');
?>
</span>
<span class="AuthorInfo">
<?php
echo ' '.wrapIf(htmlspecialchars(val('Title', $author)), 'span', ['class' => 'MItem AuthorTitle']);
echo ' '.wrapIf(htmlspecialchars(val('Location', $author)), 'span', ['class' => 'MItem AuthorLocation']);
$sender->fireEvent('AuthorInfo');
?>
</span>
<span class="DiscussionInfo right">
<?php
$discussionName = 'Re: '. val('Name', $sender->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' => '']);
}
?>
</span>
</div>
<div class="Meta CommentMeta CommentInfo">
<span class="MItem DateCreated">
Expand Down Expand Up @@ -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 = [];
Expand Down
40 changes: 23 additions & 17 deletions vanilla/plugins/Quotes/class.quotes.plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
}
Expand All @@ -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']
).' ');
}

/**
Expand Down