@@ -91,39 +91,6 @@ public function base_InlineDiscussionOptionsLeft_handler($sender, $args){
91
91
echo '</span> ' ;
92
92
}
93
93
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
-
127
94
/**
128
95
* Set the tree order of all comments in the model as soon as it is instantiated.
129
96
* 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) {
225
192
return ;
226
193
}
227
194
$ discussion = $ sender ->data ('Discussion ' );
228
- $ isClosed = ((int )$ discussion ->Closed ) == 1 ;
229
- if ($ isClosed ) {
230
- return ;
231
- }
232
195
233
196
//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 ' );
239
200
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 ) {
242
203
return ;
243
204
}
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
+ // }
244
209
245
- /*
246
210
$ options = &$ args ['CommentOptions ' ];
247
- $comment = & $args['Comment'];
211
+ $ comment = $ args ['Comment ' ];
248
212
$ options ['ReplyToComment ' ] = [
249
213
'Label ' => t ('Reply ' ),
250
214
'Url ' => '/?ParentCommentID= ' .$ comment ->CommentID ,
@@ -264,7 +228,38 @@ public function base_commentOptions_handler($sender, $args) {
264
228
$ options [$ key ]['Url ' ] = $ currentUrl .'?view= ' .$ viewMode ;
265
229
}
266
230
}
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 ' );
268
263
}
269
264
270
265
/**
0 commit comments