Skip to content

Commit 70cb0e3

Browse files
authored
Merge pull request #73 from topcoder-platform/issues-490
Issues-490: Add reply link in comment/discussion options
2 parents 643ca40 + f6ba15f commit 70cb0e3

File tree

2 files changed

+44
-49
lines changed

2 files changed

+44
-49
lines changed

ReplyTo/class.replyto.plugin.php

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -91,39 +91,6 @@ public function base_InlineDiscussionOptionsLeft_handler($sender, $args){
9191
echo '</span>';
9292
}
9393

94-
public function base_inlineCommentOptionsRight_handler($sender, $args) {
95-
ReplyToPlugin::log('base_inlineCommentOptionsRight_handler', []);
96-
97-
if (!Gdn::Session()->isValid()) {
98-
return;
99-
}
100-
101-
$discussion = $sender->data('Discussion');
102-
$isClosed = ((int)$discussion->Closed) == 1;
103-
if ($isClosed) {
104-
return;
105-
}
106-
107-
//Check permission
108-
$CategoryID = val('PermissionCategoryID', $discussion) ? val('PermissionCategoryID', $discussion) : val('CategoryID', $discussion);
109-
110-
// Can the user comment on this category, and is the discussion open for comments?
111-
if (!Gdn::Session()->CheckPermission('Vanilla.Comments.Add', TRUE, 'Category', $CategoryID)) {
112-
return;
113-
}
114-
115-
$viewMode = self::getViewMode();
116-
$comment = &$args['Comment'];
117-
$items = & $args['Items'];
118-
$commentID = val('CommentID', $comment);
119-
if(empty($items)) {
120-
$items = [];
121-
}
122-
array_push( $items, anchor(
123-
t('Reply'),
124-
url("/?ParentCommentID=".$commentID."&view=".$viewMode, false), 'ReplyComment'));
125-
}
126-
12794
/**
12895
* Set the tree order of all comments in the model as soon as it is instantiated.
12996
* It is not clear if there are other plugins that may also wish to change the ordering.
@@ -225,26 +192,23 @@ public function base_commentOptions_handler($sender, $args) {
225192
return;
226193
}
227194
$discussion = $sender->data('Discussion');
228-
$isClosed = ((int)$discussion->Closed) == 1;
229-
if ($isClosed) {
230-
return;
231-
}
232195

233196
//Check permission
234-
if (isset($discussion->PermissionCategoryID)) {
235-
$CategoryID = val('PermissionCategoryID', $discussion);
236-
} else {
237-
$CategoryID = $discussion->CategoryID;
238-
}
197+
$CategoryID = val('PermissionCategoryID', $discussion)? val('PermissionCategoryID', $discussion):val('CategoryID', $discussion);
198+
$userCanClose = CategoryModel::checkPermission($CategoryID, 'Vanilla.Discussions.Close');
199+
$userCanComment = CategoryModel::checkPermission($CategoryID, 'Vanilla.Comments.Add');
239200

240-
// Can the user comment on this category, and is the discussion open for comments?
241-
if (!Gdn::Session()->CheckPermission('Vanilla.Comments.Add', TRUE, 'Category', $CategoryID)) {
201+
$canAddComment = ($discussion->Closed == '1' && $userCanClose) || ($discussion->Closed == '0' && $userCanComment);
202+
if (!$canAddComment) {
242203
return;
243204
}
205+
// Can the user comment on this category, and is the discussion open for comments?
206+
// if (!Gdn::Session()->CheckPermission('Vanilla.Comments.Add', TRUE, 'Category', $CategoryID)) {
207+
// return;
208+
// }
244209

245-
/*
246210
$options = &$args['CommentOptions'];
247-
$comment = &$args['Comment'];
211+
$comment = $args['Comment'];
248212
$options['ReplyToComment'] = [
249213
'Label' => t('Reply'),
250214
'Url' => '/?ParentCommentID='.$comment->CommentID,
@@ -264,7 +228,38 @@ public function base_commentOptions_handler($sender, $args) {
264228
$options[$key]['Url'] = $currentUrl.'?view='.$viewMode;
265229
}
266230
}
267-
*/
231+
}
232+
233+
/**
234+
* Add 'Reply' option to discussion.
235+
*
236+
* @param Gdn_Controller $sender
237+
* @param array $args
238+
*/
239+
public function base_inlineDiscussionOptions_handler($sender, $args) {
240+
$discussion = $args['Discussion'];
241+
if (!$discussion) {
242+
return;
243+
}
244+
245+
if (!Gdn::session()->UserID) {
246+
return;
247+
}
248+
249+
//Check permission
250+
$CategoryID = val('PermissionCategoryID', $discussion)? val('PermissionCategoryID', $discussion):val('CategoryID', $discussion);
251+
$userCanClose = CategoryModel::checkPermission($CategoryID, 'Vanilla.Discussions.Close');
252+
$userCanComment = CategoryModel::checkPermission($CategoryID, 'Vanilla.Comments.Add');
253+
254+
// See the 'writeCommentForm' method vanilla/applications/vanilla/views/discussion/helper_functions.php
255+
$canAddComment = ($discussion->Closed == '1' && $userCanClose) || ($discussion->Closed == '0' && $userCanComment);
256+
if (!$canAddComment) {
257+
return;
258+
}
259+
260+
// DropdownModule options
261+
$options = & $args['DiscussionOptions'];
262+
$options->addLink('Reply', url("/", true), 'reply', 'ReplyComment');
268263
}
269264

270265
/**

ReplyTo/design/replyto.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
.ReplyViewOptions {
3+
font-family: roboto, Segoe UI, Helvetica Neue, Helvetica, Raleway, Arial, sans-serif;
34
display: inline-block;
45
line-height: 1.5;
56
}
@@ -8,8 +9,7 @@
89
}
910

1011
.MessageList .ItemDiscussion .Item-Body .Controls a.ReplyViewOptionLink.Active, .ReplyViewOptions .ReplyViewOptionLink.Active {
11-
color: #696969;
12-
font-weight: 800;
12+
color: #555555;
1313
}
1414
/*
1515
Indent comments according to their depth.

0 commit comments

Comments
 (0)