@@ -9,7 +9,6 @@ class ReplyToPlugin extends Gdn_Plugin {
9
9
10
10
const QUERY_PARAMETER_VIEW ='view ' ;
11
11
const VIEW_FLAT = 'flat ' ;
12
- const VIEW_TREE = 'tree ' ;
13
12
const VIEW_THREADED = 'threaded ' ;
14
13
15
14
private $ replyToModel ;
@@ -83,12 +82,11 @@ public function base_Replies_handler($sender, $args){
83
82
}
84
83
85
84
$ discussionUrl = discussionUrl ($ discussion , '' , '/ ' );
86
- $ viewMode = getIncomingValue ( self ::QUERY_PARAMETER_VIEW , self :: VIEW_FLAT );
85
+ $ viewMode = self ::getViewMode ( );
87
86
88
87
echo '<div class="ReplyViewOptions"><span class="MLabel">View: </span> ' ;
89
- echo anchor ('Flat ' , $ discussionUrl .'? ' .self ::QUERY_PARAMETER_VIEW .'= ' .self ::VIEW_FLAT , $ viewMode == self ::VIEW_FLAT ?'Active ' :'' ).' | ' ;
90
88
echo anchor ('Threaded ' , $ discussionUrl .'? ' .self ::QUERY_PARAMETER_VIEW .'= ' .self ::VIEW_THREADED , $ viewMode == self ::VIEW_THREADED ?'Active ' :'' ).' | ' ;
91
- echo anchor ('Tree ' , $ discussionUrl .'? ' .self ::QUERY_PARAMETER_VIEW .'= ' .self ::VIEW_TREE , $ viewMode == self ::VIEW_TREE ?'Active ' :'' );
89
+ echo anchor ('Flat ' , $ discussionUrl .'? ' .self ::QUERY_PARAMETER_VIEW .'= ' .self ::VIEW_FLAT , $ viewMode == self ::VIEW_FLAT ?'Active ' :'' );
92
90
echo '</div> ' ;
93
91
}
94
92
@@ -98,9 +96,9 @@ public function base_Replies_handler($sender, $args){
98
96
* @param $sender
99
97
*/
100
98
public function commentModel_afterConstruct_handler (&$ sender ) {
101
- self :: log ( ' commentModel_afterConstruct_handler ' , [ ' path ' => Gdn:: request ()-> pathAndQuery ()] );
102
- $ viewMode = getIncomingValue ( self :: QUERY_PARAMETER_VIEW , self :: VIEW_FLAT );
103
- if ($ viewMode == self ::VIEW_TREE || $ viewMode == self :: VIEW_THREADED ) {
99
+ $ viewMode = self :: getViewMode ( );
100
+
101
+ if ($ viewMode == self ::VIEW_THREADED ) {
104
102
$ sender ->orderBy (array ('TreeLeft asc ' , 'DateInserted asc ' ));
105
103
}
106
104
}
@@ -138,10 +136,8 @@ public function discussionController_BeforeCalculatingOffsetLimit_handler($sende
138
136
if (!Gdn::session ()->isValid ()) {
139
137
return ;
140
138
}
141
- $ viewMode = getIncomingValue (self ::QUERY_PARAMETER_VIEW );
142
- if (!$ viewMode ) {
143
- return ;
144
- }
139
+ $ viewMode = self ::getViewMode ();
140
+ // $offsetProvided = $args['OffsetProvided'];
145
141
$ discussion = $ args ['Discussion ' ];
146
142
$ offset = & $ args ['Offset ' ];
147
143
$ limit = & $ args ['Limit ' ];
@@ -152,7 +148,6 @@ public function discussionController_BeforeCalculatingOffsetLimit_handler($sende
152
148
}
153
149
154
150
if ($ viewMode === self ::VIEW_FLAT ) {
155
- $ offset = 0 ;
156
151
$ enableAutoOffset = false ;
157
152
} else {
158
153
// Show all comment on one offset for Tree/Threaded View
@@ -176,7 +171,7 @@ public function discussionController_beforeDiscussionRender_handler($sender, $ar
176
171
return ;
177
172
}
178
173
179
- $ viewMode = getIncomingValue ( self ::QUERY_PARAMETER_VIEW , self :: VIEW_FLAT );
174
+ $ viewMode = self ::getViewMode ( );
180
175
if ($ viewMode == self ::VIEW_FLAT ) {
181
176
return ;
182
177
}
@@ -221,7 +216,7 @@ public function base_commentOptions_handler($sender, $args) {
221
216
'Class ' => 'ReplyComment '
222
217
];
223
218
224
- $ viewMode = getIncomingValue ( self ::QUERY_PARAMETER_VIEW , self :: VIEW_FLAT );
219
+ $ viewMode = self ::getViewMode ( );
225
220
foreach ($ options as $ key => $ value ) {
226
221
$ currentUrl = $ options [$ key ]['Url ' ];
227
222
if (strpos ($ currentUrl , '? ' ) !== false ) {
@@ -242,20 +237,30 @@ public function base_commentOptions_handler($sender, $args) {
242
237
* @param $args
243
238
*/
244
239
public function base_beforeCommentDisplay_handler ($ sender , $ args ) {
245
- ReplyToPlugin::log ('base_beforeCommentDisplay_handler ' , []);
246
-
247
- $ viewMode = getIncomingValue (self ::QUERY_PARAMETER_VIEW , self ::VIEW_FLAT );
248
- if ($ viewMode == self ::VIEW_FLAT ) {
249
- return ;
250
- }
251
240
if ($ sender ->deliveryType () != DELIVERY_TYPE_ALL ) {
252
- ReplyToPlugin::log ('base_beforeCommentDisplay_handler ' , ['' ]);
253
- $ this ->buildCommentReplyToCssClasses ($ sender );
241
+ if (isset ($ _SERVER ['HTTP_REFERER ' ])) {
242
+ $ previous = $ _SERVER ['HTTP_REFERER ' ];
243
+ $ query = parse_url ($ previous , PHP_URL_QUERY );
244
+ parse_str ($ query , $ params );
245
+ $ viewMode = $ params ['view ' ];
246
+ if (!$ viewMode ) {
247
+ $ viewMode = self ::isPagingUrl ($ previous ) ? self ::VIEW_FLAT : self ::VIEW_THREADED ;
248
+ }
249
+
250
+ if ($ viewMode == self ::VIEW_THREADED ) {
251
+ $ this ->buildCommentReplyToCssClasses ($ sender );
252
+ }
253
+ }
254
+ } else {
255
+ $ viewMode = self ::getViewMode ();
256
+ if ($ viewMode == self ::VIEW_THREADED ) {
257
+ $ this ->buildCommentReplyToCssClasses ($ sender );
258
+ }
254
259
}
255
260
$ comment = &$ args ['Comment ' ];
256
261
$ cssClass = &$ args ['CssClass ' ];
257
- $ displayBody = &$ args ['DisplayBody ' ];
258
- $ displayBody = $ viewMode == self ::VIEW_FLAT || $ viewMode == self ::VIEW_THREADED ;
262
+ // $displayBody = &$args['DisplayBody'];
263
+ // $displayBody = $viewMode == self::VIEW_FLAT || $viewMode == self::VIEW_THREADED;
259
264
$ cssClass .= (!empty ($ comment ->ReplyToClass )? ' ' . $ comment ->ReplyToClass : '' );
260
265
}
261
266
@@ -330,6 +335,19 @@ private function buildCommentReplyToCssClasses(&$sender){
330
335
}
331
336
}
332
337
338
+ private static function isPagingUrl ($ url ) {
339
+ return preg_match ('/\/p\d+$/ ' , $ url );
340
+ }
341
+
342
+ private static function getViewMode (){
343
+ $ viewMode = getIncomingValue (self ::QUERY_PARAMETER_VIEW );
344
+ if (!$ viewMode ) {
345
+ $ viewMode = self ::isPagingUrl (Gdn::request ()->path ())? self ::VIEW_FLAT : self ::VIEW_THREADED ;
346
+ }
347
+
348
+ return $ viewMode ;
349
+ }
350
+
333
351
public static function log ($ message , $ data ) {
334
352
if (c ('Debug ' )) {
335
353
Logger::event (
0 commit comments