Skip to content

Commit 176d434

Browse files
authored
Merge pull request #497 from topcoder-platform/issues-480
Issues-490: fixed discussion/comment options
2 parents ae5075c + 664f738 commit 176d434

File tree

3 files changed

+94
-75
lines changed

3 files changed

+94
-75
lines changed

config/vanilla/bootstrap.before.php

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -819,24 +819,33 @@ function writeInlineDiscussionOptions($discussionRow) {
819819
echo '<div class="center"></div>';
820820
echo '<div class="right">';
821821

822-
// Write the items.
823-
static $items = [];
824-
825-
// $canEdit = DiscussionModel::canEdit($discussionRow, $timeLeft);
826-
// if($canEdit) {
827-
// array_push($items, anchor(t('Edit'), '/post/editdiscussion/'.$discussionID));
828-
// }
829-
830-
Gdn::controller()->EventArguments['Items'] = &$items;
831-
// Allow addons to work with items
832-
Gdn::controller()->fireEvent('InlineDiscussionOptionsRight');
833-
if (!empty($items) && is_array($items)) {
834-
array_walk($items, function(&$value, $key) {
835-
$value = '<span class="" style="">'.$value.'</span>';
822+
// Write the items.
823+
// DropdownModule
824+
$discussionDropdown = getDiscussionOptionsDropdown($discussionRow);
825+
826+
// Allow plugins to edit the dropdown.
827+
$sender = Gdn::controller();
828+
$sender->EventArguments['DiscussionOptions'] = &$discussionDropdown ;
829+
$sender->EventArguments['Discussion'] = $discussionRow;
830+
$sender->fireEvent('InlineDiscussionOptions');
831+
832+
$discussionDropdownItems = $discussionDropdown->toArray()['items'];
833+
834+
unset($discussionDropdownItems['announce']);
835+
unset($discussionDropdownItems['sink']);
836+
unset($discussionDropdownItems['close']);
837+
unset($discussionDropdownItems['dismiss']);
838+
unset($discussionDropdownItems['move']);
839+
unset($discussionDropdownItems['tag']);
840+
841+
if (!empty($discussionDropdownItems) && is_array($discussionDropdownItems)) {
842+
array_walk($discussionDropdownItems, function(&$value, $key) {
843+
$anchor = anchor($value['text'], $value['url'], val('cssClass', $value, $key));
844+
$value = '<span class="" style="">'.$anchor.'</span>';
836845
});
837846

838-
echo implode('<span class="MiddleDot">·</span>', $items);
839-
}
847+
echo implode('<span class="MiddleDot">·</span>', $discussionDropdownItems);
848+
}
840849
echo '</div>';
841850
echo '</div>';
842851

@@ -849,31 +858,18 @@ function writeInlineCommentOptions($comment) {
849858
Gdn::controller()->EventArguments['RecordID'] = $iD;
850859
//Gdn_Theme::bulletRow();
851860
echo '<div class="Controls flex">';
852-
echo '<div class="left">';
853-
854-
$commentOptions = getCommentOptions($comment);
855-
if (!empty($commentOptions) && is_array($commentOptions)) {
856-
857-
array_walk($commentOptions, function(&$value, $key) {
858-
$anchor = anchor($value['Label'], $value['Url'], val('Class', $value, $key));
859-
$value = '<span class="" style="">'.$anchor.'</span>';
860-
});
861-
862-
echo implode('<span class="MiddleDot">·</span>', $commentOptions);
863-
}
864-
echo '</div>';
861+
echo '<div class="left"></div>';
865862
echo '<div class="center"></div>';
866863
echo '<div class="right">';
867864

868865
// Write the items.
869-
$items = null;
870-
Gdn::controller()->EventArguments['Comment'] = $comment;
871-
Gdn::controller()->EventArguments['Items'] = &$items;
872-
// Allow addons to work with items
873-
Gdn::controller()->fireEvent('InlineCommentOptionsRight');
866+
$items = getCommentOptions($comment);
874867
if (!empty($items) && is_array($items)) {
875-
array_walk($items, function(&$x) {$x = '<span class="" style="">'.$x.'</span>';});
876-
echo implode('<span class="MiddleDot">·</span>', $items);
868+
array_walk($items, function(&$value, $key) {
869+
$anchor = anchor($value['Label'], $value['Url'], val('Class', $value, $key));
870+
$value = '<span class="" style="">'.$anchor.'</span>';
871+
});
872+
echo implode('<span class="MiddleDot">·</span>', $items);
877873
}
878874
echo '</div>';
879875
echo '</div>';

vanilla/applications/vanilla/views/discussion/helper_functions.php

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -121,27 +121,44 @@ function writeComment($comment, $sender, $session, $currentOffset) {
121121
</div>
122122
<?php $sender->fireEvent('BeforeCommentMeta'); ?>
123123
<div class="Item-Header CommentHeader">
124-
<div class="AuthorWrap">
125-
<span class="Author">
126-
<?php
127-
if ($userPhotoFirst) {
128-
echo userPhoto($author);
129-
echo userAnchor($author, 'Username');
130-
} else {
131-
echo userAnchor($author, 'Username');
132-
echo userPhoto($author);
133-
}
134-
echo formatMeAction($comment);
135-
$sender->fireEvent('AuthorPhoto');
136-
?>
137-
</span>
138-
<span class="AuthorInfo">
139-
<?php
140-
echo ' '.wrapIf(htmlspecialchars(val('Title', $author)), 'span', ['class' => 'MItem AuthorTitle']);
141-
echo ' '.wrapIf(htmlspecialchars(val('Location', $author)), 'span', ['class' => 'MItem AuthorLocation']);
142-
$sender->fireEvent('AuthorInfo');
143-
?>
144-
</span>
124+
<div class="AuthorWrap flex">
125+
<span class="Author">
126+
<?php
127+
if ($userPhotoFirst) {
128+
echo userPhoto($author);
129+
echo userAnchor($author, 'Username');
130+
} else {
131+
echo userAnchor($author, 'Username');
132+
echo userPhoto($author);
133+
}
134+
echo formatMeAction($comment);
135+
$sender->fireEvent('AuthorPhoto');
136+
?>
137+
</span>
138+
<span class="AuthorInfo">
139+
<?php
140+
echo ' '.wrapIf(htmlspecialchars(val('Title', $author)), 'span', ['class' => 'MItem AuthorTitle']);
141+
echo ' '.wrapIf(htmlspecialchars(val('Location', $author)), 'span', ['class' => 'MItem AuthorLocation']);
142+
$sender->fireEvent('AuthorInfo');
143+
?>
144+
</span>
145+
<span class="DiscussionInfo right">
146+
<?php
147+
$discussionName = 'Re: '. val('Name', $sender->data('Discussion'));
148+
$parentCommentID = $comment->ParentCommentID;
149+
if($parentCommentID) {
150+
$commentModel = new CommentModel();
151+
$parentComment = $commentModel->getID($parentCommentID);
152+
$parentCommentPermalink = '/discussion/comment/' . $parentCommentID . '/#Comment_' . $parentCommentID;
153+
$parentCommentAuthor = Gdn::userModel()->getID($parentComment->InsertUserID);
154+
$parentCommentAuthor = userAnchor($parentCommentAuthor);
155+
$post = anchor('post', $parentCommentPermalink, 'ParentComment');
156+
echo ''. wrapIf($discussionName . ' (response to '.$post.' by '.$parentCommentAuthor.')', 'span', ['class' => '']);
157+
} else {
158+
echo ''. wrapIf($discussionName, 'span', ['class' => '']);
159+
}
160+
?>
161+
</span>
145162
</div>
146163
<div class="Meta CommentMeta CommentInfo">
147164
<span class="MItem DateCreated">
@@ -366,7 +383,7 @@ function getDiscussionOptionsDropdown($discussion = null) {
366383
->addLinkIf($canRefetch, t('Refetch Page'), '/discussion/refetchpageinfo.json?discussionid='.$discussionID, 'refetch', 'RefetchPage Hijack')
367384
->addLinkIf($canMove, t('Move'), '/moderation/confirmdiscussionmoves?discussionid='.$discussionID, 'move', 'MoveDiscussion Popup')
368385
->addLinkIf($canTag, t('Tag'), '/discussion/tag?discussionid='.$discussionID, 'tag', 'TagDiscussion Popup')
369-
->addLinkIf($canDelete, t('Delete Discussion'), '/discussion/delete?discussionid='.$discussionID.'&target='.$categoryUrl, 'delete', 'DeleteDiscussion Popup');
386+
->addLinkIf($canDelete, t('Delete'), '/discussion/delete?discussionid='.$discussionID.'&target='.$categoryUrl, 'delete', 'DeleteDiscussion Popup');
370387

371388
// DEPRECATED
372389
$options = [];

vanilla/plugins/Quotes/class.quotes.plugin.php

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,13 @@ public function postController_render_before($sender) {
238238
* @param Gdn_Controller $sender
239239
* @param array $args
240240
*/
241-
public function base_InlineDiscussionOptionsRight_handler($sender, $args) {
241+
public function base_inlineDiscussionOptions_handler($sender, $args) {
242242
if ($this->isSupportedFormat(c('Garden.InputFormatter'))) {
243243
$this->addQuoteButton($sender, $args);
244244
}
245245
}
246246

247-
public function base_inlineCommentOptionsRight_handler($sender, $args) {
247+
public function base_commentOptions_handler($sender, $args) {
248248
if ($this->isSupportedFormat(c('Garden.InputFormatter'))) {
249249
$this->addQuoteButton($sender, $args);
250250
}
@@ -258,7 +258,8 @@ public function base_inlineCommentOptionsRight_handler($sender, $args) {
258258
*/
259259
protected function addQuoteButton($sender, $args) {
260260
// There are some case were Discussion is not set as an event argument so we use the sender data instead.
261-
$discussion = $sender->data('Discussion');
261+
// $sender->data('Discussion') is used for updating comment
262+
$discussion = $args['Discussion'] ? $args['Discussion'] : $sender->data('Discussion');
262263
if (!$discussion) {
263264
return;
264265
}
@@ -267,31 +268,36 @@ protected function addQuoteButton($sender, $args) {
267268
return;
268269
}
269270

270-
if (!Gdn::session()->checkPermission('Vanilla.Comments.Add', false, 'Category', $discussion->PermissionCategoryID)) {
271+
//Check permission
272+
$CategoryID = val('PermissionCategoryID', $discussion)? val('PermissionCategoryID', $discussion):val('CategoryID', $discussion);
273+
$userCanClose = CategoryModel::checkPermission($CategoryID, 'Vanilla.Discussions.Close');
274+
$userCanComment = CategoryModel::checkPermission($CategoryID, 'Vanilla.Comments.Add');
275+
276+
// See the 'writeCommentForm' method vanilla/applications/vanilla/views/discussion/helper_functions.php
277+
$canAddComment = ($discussion->Closed == '1' && $userCanClose) || ($discussion->Closed == '0' && $userCanComment);
278+
if (!$canAddComment) {
271279
return;
272280
}
273281

274282
if (isset($args['Comment'])) {
275283
$object = $args['Comment'];
276284
$objectID = 'Comment_'.$object->CommentID;
285+
$options = &$args['CommentOptions'];
286+
$options['Quote'] = [
287+
'Label' => t('Quote'),
288+
'Url' => url("post/quote/{$object->DiscussionID}/{$objectID}", true),
289+
'Class' => 'ReactButton Quote Visible'
290+
];
291+
277292
} elseif ($discussion) {
278293
$object = $discussion;
279294
$objectID = 'Discussion_'.$object->DiscussionID;
280-
} else {
281-
return;
295+
// DropdownModule options
296+
$options = & $args['DiscussionOptions'];
297+
$options->addLink('Quote', url("post/quote/{$object->DiscussionID}/{$objectID}", true),
298+
'quote', 'ReactButton Quote Visible');
282299
}
283300

284-
$items = & $args['Items'];
285-
//echo Gdn_Theme::bulletItem('Flags');
286-
if(empty($items)) {
287-
$items = [];
288-
}
289-
array_push( $items, anchor(
290-
t('Quote'),
291-
url("post/quote/{$object->DiscussionID}/{$objectID}", true),
292-
'ReactButton Quote Visible',
293-
['role' => 'button']
294-
).' ');
295301
}
296302

297303
/**

0 commit comments

Comments
 (0)