-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforumdisplay.php
1555 lines (1345 loc) · 41.7 KB
/
forumdisplay.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
*
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*
*/
define("IN_MYBB", 1);
define('THIS_SCRIPT', 'forumdisplay.php');
$templatelist = "forumdisplay,forumdisplay_thread,forumbit_depth1_cat,forumbit_depth2_cat,forumbit_depth2_forum,forumdisplay_subforums,forumdisplay_threadlist,forumdisplay_moderatedby,forumdisplay_searchforum,forumdisplay_forumsort,forumdisplay_thread_rating,forumdisplay_threadlist_rating";
$templatelist .= ",forumbit_depth1_forum_lastpost,forumdisplay_thread_multipage_page,forumdisplay_thread_multipage,forumdisplay_thread_multipage_more,forumdisplay_thread_gotounread,forumbit_depth2_forum_lastpost,forumdisplay_rules_link,forumdisplay_orderarrow,forumdisplay_newthread";
$templatelist .= ",multipage,multipage_breadcrumb,multipage_end,multipage_jump_page,multipage_nextpage,multipage_page,multipage_page_current,multipage_page_link_current,multipage_prevpage,multipage_start,forumdisplay_thread_unapproved_posts,forumdisplay_nothreads";
$templatelist .= ",forumjump_advanced,forumjump_special,forumjump_bit,forumdisplay_password_wrongpass,forumdisplay_password,forumdisplay_inlinemoderation_custom_tool,forumbit_subforums,forumbit_moderators,forumbit_depth2_forum_lastpost_never,forumbit_depth2_forum_lastpost_hidden";
$templatelist .= ",forumdisplay_usersbrowsing_user,forumdisplay_usersbrowsing,forumdisplay_inlinemoderation,forumdisplay_thread_modbit,forumdisplay_inlinemoderation_col,forumdisplay_inlinemoderation_selectall,forumdisplay_threadlist_clearpass,forumdisplay_thread_rating_moved";
$templatelist .= ",forumdisplay_announcements_announcement,forumdisplay_announcements,forumdisplay_threads_sep,forumbit_depth3_statusicon,forumbit_depth3,forumdisplay_sticky_sep,forumdisplay_thread_attachment_count,forumdisplay_rssdiscovery,forumbit_moderators_group";
$templatelist .= ",forumdisplay_inlinemoderation_openclose,forumdisplay_inlinemoderation_stickunstick,forumdisplay_inlinemoderation_softdelete,forumdisplay_inlinemoderation_restore,forumdisplay_inlinemoderation_delete,forumdisplay_inlinemoderation_manage,forumdisplay_nopermission";
$templatelist .= ",forumbit_depth2_forum_unapproved_posts,forumbit_depth2_forum_unapproved_threads,forumbit_moderators_user,forumdisplay_inlinemoderation_standard,forumdisplay_threadlist_prefixes_prefix,forumdisplay_threadlist_prefixes,forumdisplay_thread_icon,forumdisplay_rules";
$templatelist .= ",forumdisplay_thread_deleted,forumdisplay_announcements_announcement_modbit,forumbit_depth2_forum_viewers,forumdisplay_threadlist_sortrating,forumdisplay_inlinemoderation_custom,forumdisplay_announcement_rating,forumdisplay_inlinemoderation_approveunapprove,forumdisplay_threadlist_subscription";
require_once "./global.php";
require_once MYBB_ROOT."inc/functions_post.php";
require_once MYBB_ROOT."inc/functions_forumlist.php";
require_once MYBB_ROOT."inc/class_parser.php";
$parser = new postParser;
$orderarrow = $sortsel = array('rating' => '', 'subject' => '', 'starter' => '', 'started' => '', 'replies' => '', 'views' => '', 'lastpost' => '');
$ordersel = array('asc' => '', 'desc' => '');
$datecutsel = array(1 => '', 5 => '', 10 => '', 20 => '', 50 => '', 75 => '', 100 => '', 365 => '', 9999 => '');
$rules = '';
// Load global language phrases
$lang->load("forumdisplay");
$plugins->run_hooks("forumdisplay_start");
$fid = $mybb->get_input('fid', MyBB::INPUT_INT);
if($fid < 0)
{
switch($fid)
{
case "-1":
$location = "index.php";
break;
case "-2":
$location = "search.php";
break;
case "-3":
$location = "usercp.php";
break;
case "-4":
$location = "private.php";
break;
case "-5":
$location = "online.php";
break;
}
if($location)
{
header("Location: ".$location);
exit;
}
}
// Get forum info
$foruminfo = get_forum($fid);
if(!$foruminfo)
{
error($lang->error_invalidforum);
}
$archive_url = build_archive_link("forum", $fid);
$currentitem = $fid;
build_forum_breadcrumb($fid);
$parentlist = $foruminfo['parentlist'];
// To validate, turn & to & but support unicode
$foruminfo['name'] = preg_replace("#&(?!\#[0-9]+;)#si", "&", $foruminfo['name']);
$forumpermissions = forum_permissions();
$fpermissions = $forumpermissions[$fid];
if($fpermissions['canview'] != 1)
{
error_no_permission();
}
if($mybb->user['uid'] == 0)
{
// Cookie'd forum read time
$forumsread = array();
if(isset($mybb->cookies['mybb']['forumread']))
{
$forumsread = my_unserialize($mybb->cookies['mybb']['forumread']);
}
if(is_array($forumsread) && empty($forumsread))
{
if(isset($mybb->cookies['mybb']['readallforums']))
{
$forumsread[$fid] = $mybb->cookies['mybb']['lastvisit'];
}
else
{
$forumsread = array();
}
}
$query = $db->simple_select("forums", "*", "active != 0", array("order_by" => "pid, disporder"));
}
else
{
// Build a forum cache from the database
$query = $db->query("
SELECT f.*, fr.dateline AS lastread
FROM ".TABLE_PREFIX."forums f
LEFT JOIN ".TABLE_PREFIX."forumsread fr ON (fr.fid=f.fid AND fr.uid='{$mybb->user['uid']}')
WHERE f.active != 0
ORDER BY pid, disporder
");
}
while($forum = $db->fetch_array($query))
{
if($mybb->user['uid'] == 0 && isset($forumsread[$forum['fid']]))
{
$forum['lastread'] = $forumsread[$forum['fid']];
}
$fcache[$forum['pid']][$forum['disporder']][$forum['fid']] = $forum;
}
// Get the forum moderators if the setting is enabled.
if($mybb->settings['modlist'] != 0)
{
$moderatorcache = $cache->read("moderators");
}
$bgcolor = "trow1";
if($mybb->settings['subforumsindex'] != 0)
{
$showdepth = 3;
}
else
{
$showdepth = 2;
}
$subforums = '';
$child_forums = build_forumbits($fid, 2);
if(!empty($child_forums) && !empty($child_forums['forum_list']))
{
$forums = $child_forums['forum_list'];
$lang->sub_forums_in = $lang->sprintf($lang->sub_forums_in, $foruminfo['name']);
eval("\$subforums = \"".$templates->get("forumdisplay_subforums")."\";");
}
$excols = "forumdisplay";
// Password protected forums
check_forum_password($foruminfo['fid']);
if($foruminfo['linkto'])
{
header("Location: {$foruminfo['linkto']}");
exit;
}
// Make forum jump...
if($mybb->settings['enableforumjump'] != 0)
{
$forumjump = build_forum_jump("", $fid, 1);
}
$newthread = '';
if($foruminfo['type'] == "f" && $foruminfo['open'] != 0 && $fpermissions['canpostthreads'] != 0 && $mybb->user['suspendposting'] == 0)
{
eval("\$newthread = \"".$templates->get("forumdisplay_newthread")."\";");
}
$searchforum = '';
if($fpermissions['cansearch'] != 0 && $foruminfo['type'] == "f")
{
eval("\$searchforum = \"".$templates->get("forumdisplay_searchforum")."\";");
}
// Gather forum stats
$has_announcements = $has_modtools = false;
$forum_stats = $cache->read("forumsdisplay");
if(is_array($forum_stats))
{
if(!empty($forum_stats[-1]['modtools']) || !empty($forum_stats[$fid]['modtools']))
{
// Mod tools are specific to forums, not parents
$has_modtools = true;
}
if(!empty($forum_stats[-1]['announcements']) || !empty($forum_stats[$fid]['announcements']))
{
// Global or forum-specific announcements
$has_announcements = true;
}
}
$done_moderators = array(
"users" => array(),
"groups" => array()
);
$moderators = '';
$parentlistexploded = explode(",", $parentlist);
$comma = '';
foreach($parentlistexploded as $mfid)
{
// This forum has moderators
if(isset($moderatorcache[$mfid]) && is_array($moderatorcache[$mfid]))
{
// Fetch each moderator from the cache and format it, appending it to the list
foreach($moderatorcache[$mfid] as $modtype)
{
foreach($modtype as $moderator)
{
if($moderator['isgroup'])
{
if(in_array($moderator['id'], $done_moderators['groups']))
{
continue;
}
$moderator['title'] = htmlspecialchars_uni($moderator['title']);
eval("\$moderators .= \"".$templates->get("forumbit_moderators_group", 1, 0)."\";");
$done_moderators['groups'][] = $moderator['id'];
}
else
{
if(in_array($moderator['id'], $done_moderators['users']))
{
continue;
}
$moderator['profilelink'] = get_profile_link($moderator['id']);
$moderator['username'] = format_name(htmlspecialchars_uni($moderator['username']), $moderator['usergroup'], $moderator['displaygroup']);
eval("\$moderators .= \"".$templates->get("forumbit_moderators_user", 1, 0)."\";");
$done_moderators['users'][] = $moderator['id'];
}
$comma = $lang->comma;
}
}
}
if(!empty($forum_stats[$mfid]['announcements']))
{
$has_announcements = true;
}
}
$comma = '';
// If we have a moderators list, load the template
if($moderators)
{
eval("\$moderatedby = \"".$templates->get("forumdisplay_moderatedby")."\";");
}
else
{
$moderatedby = '';
}
// Get the users browsing this forum.
if($mybb->settings['browsingthisforum'] != 0)
{
$timecut = TIME_NOW - $mybb->settings['wolcutoff'];
$comma = '';
$guestcount = 0;
$membercount = 0;
$inviscount = 0;
$onlinemembers = '';
$doneusers = array();
$query = $db->simple_select("sessions", "COUNT(DISTINCT ip) AS guestcount", "uid = 0 AND time > $timecut AND location1 = $fid AND nopermission != 1");
$guestcount = $db->fetch_field($query, 'guestcount');
$query = $db->query("
SELECT
s.ip, s.uid, u.username, s.time, u.invisible, u.usergroup, u.usergroup, u.displaygroup
FROM
".TABLE_PREFIX."sessions s
LEFT JOIN ".TABLE_PREFIX."users u ON (s.uid=u.uid)
WHERE s.uid != 0 AND s.time > $timecut AND location1 = $fid AND nopermission != 1
ORDER BY u.username ASC, s.time DESC
");
while($user = $db->fetch_array($query))
{
if(empty($doneusers[$user['uid']]) || $doneusers[$user['uid']] < $user['time'])
{
$doneusers[$user['uid']] = $user['time'];
++$membercount;
if($user['invisible'] == 1 && $mybb->usergroup['canbeinvisible'] == 1)
{
$invisiblemark = "*";
++$inviscount;
}
else
{
$invisiblemark = '';
}
if($user['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1 || $user['uid'] == $mybb->user['uid'])
{
$user['username'] = format_name(htmlspecialchars_uni($user['username']), $user['usergroup'], $user['displaygroup']);
$user['profilelink'] = build_profile_link($user['username'], $user['uid']);
eval("\$onlinemembers .= \"".$templates->get("forumdisplay_usersbrowsing_user", 1, 0)."\";");
$comma = $lang->comma;
}
}
}
$guestsonline = '';
if($guestcount)
{
$guestsonline = $lang->sprintf($lang->users_browsing_forum_guests, $guestcount);
}
$invisonline = '';
if($mybb->user['invisible'] == 1)
{
// the user was counted as invisible user --> correct the inviscount
$inviscount -= 1;
}
if($inviscount && $mybb->usergroup['canviewwolinvis'] != 1)
{
$invisonline = $lang->sprintf($lang->users_browsing_forum_invis, $inviscount);
}
$onlinesep = '';
if($invisonline != '' && $onlinemembers)
{
$onlinesep = $lang->comma;
}
$onlinesep2 = '';
if($invisonline != '' && $guestcount || $onlinemembers && $guestcount)
{
$onlinesep2 = $lang->comma;
}
eval("\$usersbrowsing = \"".$templates->get("forumdisplay_usersbrowsing")."\";");
}
// Do we have any forum rules to show for this forum?
$forumrules = '';
if($foruminfo['rulestype'] != 0 && $foruminfo['rules'])
{
if(!$foruminfo['rulestitle'])
{
$foruminfo['rulestitle'] = $lang->sprintf($lang->forum_rules, $foruminfo['name']);
}
$rules_parser = array(
"allow_html" => 1,
"allow_mycode" => 1,
"allow_smilies" => 1,
"allow_imgcode" => 1
);
$foruminfo['rules'] = $parser->parse_message($foruminfo['rules'], $rules_parser);
if($foruminfo['rulestype'] == 1 || $foruminfo['rulestype'] == 3)
{
eval("\$rules = \"".$templates->get("forumdisplay_rules")."\";");
}
else if($foruminfo['rulestype'] == 2)
{
eval("\$rules = \"".$templates->get("forumdisplay_rules_link")."\";");
}
}
$bgcolor = "trow1";
// Set here to fetch only approved/deleted topics (and then below for a moderator we change this).
$visible_states = array("1");
if($fpermissions['canviewdeletionnotice'] != 0)
{
$visible_states[] = "-1";
}
// Check if the active user is a moderator and get the inline moderation tools.
if(is_moderator($fid))
{
eval("\$inlinemodcol = \"".$templates->get("forumdisplay_inlinemoderation_col")."\";");
$ismod = true;
$inlinecount = "0";
$inlinemod = '';
$inlinecookie = "inlinemod_forum".$fid;
if(is_moderator($fid, "canviewdeleted") == true)
{
$visible_states[] = "-1";
}
if(is_moderator($fid, "canviewunapprove") == true)
{
$visible_states[] = "0";
}
}
else
{
$inlinemod = $inlinemodcol = '';
$ismod = false;
}
$visible_condition = "visible IN (".implode(',', array_unique($visible_states)).")";
$visibleonly = "AND ".$visible_condition;
// Allow viewing own unapproved threads for logged in users
if($mybb->user['uid'] && $mybb->settings['showownunapproved'])
{
$visible_condition .= " OR (t.visible=0 AND t.uid=".(int)$mybb->user['uid'].")";
}
$tvisibleonly = "AND (t.".$visible_condition.")";
if(is_moderator($fid, "caneditposts") || $fpermissions['caneditposts'] == 1)
{
$can_edit_titles = 1;
}
else
{
$can_edit_titles = 0;
}
unset($rating);
// Pick out some sorting options.
// First, the date cut for the threads.
$datecut = 9999;
if(empty($mybb->input['datecut']))
{
// If the user manually set a date cut, use it.
if(!empty($mybb->user['daysprune']))
{
$datecut = $mybb->user['daysprune'];
}
else
{
// If the forum has a non-default date cut, use it.
if(!empty($foruminfo['defaultdatecut']))
{
$datecut = $foruminfo['defaultdatecut'];
}
}
}
// If there was a manual date cut override, use it.
else
{
$datecut = $mybb->get_input('datecut', MyBB::INPUT_INT);
}
$datecutsel[(int)$datecut] = ' selected="selected"';
if($datecut > 0 && $datecut != 9999)
{
$checkdate = TIME_NOW - ($datecut * 86400);
$datecutsql = "AND (lastpost >= '$checkdate' OR sticky = '1')";
$datecutsql2 = "AND (t.lastpost >= '$checkdate' OR t.sticky = '1')";
}
else
{
$datecutsql = '';
$datecutsql2 = '';
}
// Sort by thread prefix
$tprefix = $mybb->get_input('prefix', MyBB::INPUT_INT);
if($tprefix > 0)
{
$prefixsql = "AND prefix = {$tprefix}";
$prefixsql2 = "AND t.prefix = {$tprefix}";
}
else if($tprefix == -1)
{
$prefixsql = "AND prefix = 0";
$prefixsql2 = "AND t.prefix = 0";
}
else if($tprefix == -2)
{
$prefixsql = "AND prefix != 0";
$prefixsql2 = "AND t.prefix != 0";
}
else
{
$prefixsql = $prefixsql2 = '';
}
// Pick the sort order.
if(!isset($mybb->input['order']) && !empty($foruminfo['defaultsortorder']))
{
$mybb->input['order'] = $foruminfo['defaultsortorder'];
}
else
{
$mybb->input['order'] = $mybb->get_input('order');
}
$mybb->input['order'] = htmlspecialchars_uni($mybb->get_input('order'));
switch(my_strtolower($mybb->input['order']))
{
case "asc":
$sortordernow = "asc";
$ordersel['asc'] = ' selected="selected"';
$oppsort = $lang->desc;
$oppsortnext = "desc";
break;
default:
$sortordernow = "desc";
$ordersel['desc'] = ' selected="selected"';
$oppsort = $lang->asc;
$oppsortnext = "asc";
break;
}
// Sort by which field?
if(!isset($mybb->input['sortby']) && !empty($foruminfo['defaultsortby']))
{
$mybb->input['sortby'] = $foruminfo['defaultsortby'];
}
else
{
$mybb->input['sortby'] = $mybb->get_input('sortby');
}
$t = 't.';
$sortfield2 = '';
$sortby = htmlspecialchars_uni($mybb->input['sortby']);
switch($mybb->input['sortby'])
{
case "subject":
$sortfield = "subject";
break;
case "replies":
$sortfield = "replies";
break;
case "views":
$sortfield = "views";
break;
case "starter":
$sortfield = "username";
break;
case "rating":
$t = "";
$sortfield = "averagerating";
$sortfield2 = ", t.totalratings DESC";
break;
case "started":
$sortfield = "dateline";
break;
default:
$sortby = "lastpost";
$sortfield = "lastpost";
$mybb->input['sortby'] = "lastpost";
break;
}
$sortsel['rating'] = ''; // Needs to be initialized in order to speed-up things. Fixes #2031
$sortsel[$mybb->input['sortby']] = ' selected="selected"';
// Pick the right string to join the sort URL
if($mybb->seo_support == true)
{
$string = "?";
}
else
{
$string = "&";
}
// Are we viewing a specific page?
$mybb->input['page'] = $mybb->get_input('page', MyBB::INPUT_INT);
if($mybb->input['page'] > 1)
{
$sorturl = get_forum_link($fid, $mybb->input['page']).$string."datecut=$datecut&prefix=$tprefix";
}
else
{
$sorturl = get_forum_link($fid).$string."datecut=$datecut&prefix=$tprefix";
}
eval("\$orderarrow['$sortby'] = \"".$templates->get("forumdisplay_orderarrow")."\";");
$threadcount = 0;
$useronly = $tuseronly = "";
if(isset($fpermissions['canonlyviewownthreads']) && $fpermissions['canonlyviewownthreads'] == 1)
{
$useronly = "AND uid={$mybb->user['uid']}";
$tuseronly = "AND t.uid={$mybb->user['uid']}";
}
if($fpermissions['canviewthreads'] != 0)
{
// How many threads are there?
if ($useronly === "" && $datecutsql === "" && $prefixsql === "")
{
$threadcount = 0;
$query = $db->simple_select("forums", "threads, unapprovedthreads, deletedthreads", "fid=".(int)$fid);
$forum_threads = $db->fetch_array($query);
if(in_array(1, $visible_states))
{
$threadcount += $forum_threads['threads'];
}
if(in_array(-1, $visible_states))
{
$threadcount += $forum_threads['deletedthreads'];
}
if(in_array(0, $visible_states))
{
$threadcount += $forum_threads['unapprovedthreads'];
}
elseif($mybb->user['uid'] && $mybb->settings['showownunapproved'])
{
$query = $db->simple_select("threads t", "COUNT(tid) AS threads", "fid = '$fid' AND t.visible=0 AND t.uid=".(int)$mybb->user['uid']);
$threadcount += $db->fetch_field($query, "threads");
}
}
else
{
$query = $db->simple_select("threads t", "COUNT(tid) AS threads", "fid = '$fid' $tuseronly $tvisibleonly $datecutsql2 $prefixsql2");
$threadcount = $db->fetch_field($query, "threads");
}
}
// How many pages are there?
if(!$mybb->settings['threadsperpage'] || (int)$mybb->settings['threadsperpage'] < 1)
{
$mybb->settings['threadsperpage'] = 20;
}
$perpage = $mybb->settings['threadsperpage'];
if($mybb->input['page'] > 0)
{
$page = $mybb->input['page'];
$start = ($page-1) * $perpage;
$pages = $threadcount / $perpage;
$pages = ceil($pages);
if($page > $pages || $page <= 0)
{
$start = 0;
$page = 1;
}
}
else
{
$start = 0;
$page = 1;
}
$end = $start + $perpage;
$lower = $start + 1;
$upper = $end;
if($upper > $threadcount)
{
$upper = $threadcount;
}
// Assemble page URL
if($mybb->input['sortby'] || $mybb->input['order'] || $mybb->input['datecut'] || $mybb->input['prefix']) // Ugly URL
{
$page_url = str_replace("{fid}", $fid, FORUM_URL_PAGED);
if($mybb->seo_support == true)
{
$q = "?";
$and = '';
}
else
{
$q = '';
$and = "&";
}
if((!empty($foruminfo['defaultsortby']) && $sortby != $foruminfo['defaultsortby']) || (empty($foruminfo['defaultsortby']) && $sortby != "lastpost"))
{
$page_url .= "{$q}{$and}sortby={$sortby}";
$q = '';
$and = "&";
}
if($sortordernow != "desc")
{
$page_url .= "{$q}{$and}order={$sortordernow}";
$q = '';
$and = "&";
}
if($datecut > 0 && $datecut != 9999)
{
$page_url .= "{$q}{$and}datecut={$datecut}";
$q = '';
$and = "&";
}
if($tprefix != 0)
{
$page_url .= "{$q}{$and}prefix={$tprefix}";
}
}
else
{
$page_url = str_replace("{fid}", $fid, FORUM_URL_PAGED);
}
$multipage = multipage($threadcount, $perpage, $page, $page_url);
$ratingcol = $ratingsort = '';
if($mybb->settings['allowthreadratings'] != 0 && $foruminfo['allowtratings'] != 0 && $fpermissions['canviewthreads'] != 0)
{
$lang->load("ratethread");
switch($db->type)
{
case "pgsql":
$ratingadd = "CASE WHEN t.numratings=0 THEN 0 ELSE t.totalratings/t.numratings::numeric END AS averagerating, ";
break;
default:
$ratingadd = "(t.totalratings/t.numratings) AS averagerating, ";
}
$lpbackground = "trow2";
eval("\$ratingcol = \"".$templates->get("forumdisplay_threadlist_rating")."\";");
eval("\$ratingsort = \"".$templates->get("forumdisplay_threadlist_sortrating")."\";");
$colspan = "7";
}
else
{
if($sortfield == "averagerating")
{
$t = "t.";
$sortfield = "lastpost";
}
$ratingadd = '';
$lpbackground = "trow1";
$colspan = "6";
}
if($ismod)
{
++$colspan;
}
// Get Announcements
$announcementlist = '';
if($has_announcements == true)
{
$limit = '';
$announcements = '';
if($mybb->settings['announcementlimit'])
{
$limit = "LIMIT 0, ".$mybb->settings['announcementlimit'];
}
$sql = build_parent_list($fid, "fid", "OR", $parentlist);
$time = TIME_NOW;
$query = $db->query("
SELECT a.*, u.username
FROM ".TABLE_PREFIX."announcements a
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=a.uid)
WHERE a.startdate<='$time' AND (a.enddate>='$time' OR a.enddate='0') AND ($sql OR fid='-1')
ORDER BY a.startdate DESC $limit
");
// See if this announcement has been read in our announcement array
$cookie = array();
if(isset($mybb->cookies['mybb']['announcements']))
{
$cookie = my_unserialize(stripslashes($mybb->cookies['mybb']['announcements']));
}
$announcementlist = '';
$bgcolor = alt_trow(true); // Reset the trow colors
while($announcement = $db->fetch_array($query))
{
if($announcement['startdate'] > $mybb->user['lastvisit'] && !$cookie[$announcement['aid']])
{
$new_class = ' class="subject_new"';
$folder = "newfolder";
}
else
{
$new_class = ' class="subject_old"';
$folder = "folder";
}
// Mmm, eat those announcement cookies if they're older than our last visit
if(isset($cookie[$announcement['aid']]) && $cookie[$announcement['aid']] < $mybb->user['lastvisit'])
{
unset($cookie[$announcement['aid']]);
}
$announcement['announcementlink'] = get_announcement_link($announcement['aid']);
$announcement['subject'] = $parser->parse_badwords($announcement['subject']);
$announcement['subject'] = htmlspecialchars_uni($announcement['subject']);
$postdate = my_date('relative', $announcement['startdate']);
$announcement['username'] = htmlspecialchars_uni($announcement['username']);
$announcement['profilelink'] = build_profile_link($announcement['username'], $announcement['uid']);
if($mybb->settings['allowthreadratings'] != 0 && $foruminfo['allowtratings'] != 0 && $fpermissions['canviewthreads'] != 0)
{
eval("\$rating = \"".$templates->get("forumdisplay_announcement_rating")."\";");
$lpbackground = "trow2";
}
else
{
$rating = '';
$lpbackground = "trow1";
}
if($ismod)
{
eval("\$modann = \"".$templates->get("forumdisplay_announcements_announcement_modbit")."\";");
}
else
{
$modann = '';
}
$plugins->run_hooks("forumdisplay_announcement");
eval("\$announcements .= \"".$templates->get("forumdisplay_announcements_announcement")."\";");
$bgcolor = alt_trow();
}
if($announcements)
{
eval("\$announcementlist = \"".$templates->get("forumdisplay_announcements")."\";");
$shownormalsep = true;
}
if(empty($cookie))
{
// Clean up cookie crumbs
my_setcookie('mybb[announcements]', 0, (TIME_NOW - (60*60*24*365)));
}
else if(!empty($cookie))
{
my_setcookie("mybb[announcements]", addslashes(my_serialize($cookie)), -1);
}
}
else
{
$announcementlist = '';
}
$tids = $threadcache = array();
$icon_cache = $cache->read("posticons");
if($fpermissions['canviewthreads'] != 0)
{
$plugins->run_hooks("forumdisplay_get_threads");
// Start Getting Threads
$query = $db->query("
SELECT t.*, {$ratingadd}t.username AS threadusername, u.username
FROM ".TABLE_PREFIX."threads t
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
WHERE t.fid='$fid' $tuseronly $tvisibleonly $datecutsql2 $prefixsql2
ORDER BY t.sticky DESC, {$t}{$sortfield} $sortordernow $sortfield2
LIMIT $start, $perpage
");
$ratings = false;
$moved_threads = array();
while($thread = $db->fetch_array($query))
{
$threadcache[$thread['tid']] = $thread;
if($thread['numratings'] > 0 && $ratings == false)
{
$ratings = true; // Looks for ratings in the forum
}
// If this is a moved thread - set the tid for participation marking and thread read marking to that of the moved thread
if(substr($thread['closed'], 0, 5) == "moved")
{
$tid = substr($thread['closed'], 6);
if(!isset($tids[$tid]))
{
$moved_threads[$tid] = $thread['tid'];
$tids[$thread['tid']] = $tid;
}
}
// Otherwise - set it to the plain thread ID
else
{
$tids[$thread['tid']] = $thread['tid'];
if(isset($moved_threads[$thread['tid']]))
{
unset($moved_threads[$thread['tid']]);
}
}
}
$args = array(
'threadcache' => &$threadcache,
'tids' => &$tids
);
$plugins->run_hooks("forumdisplay_before_thread", $args);
if($mybb->settings['allowthreadratings'] != 0 && $foruminfo['allowtratings'] != 0 && $mybb->user['uid'] && !empty($threadcache) && $ratings == true)
{
// Check if we've rated threads on this page
// Guests get the pleasure of not being ID'd, but will be checked when they try and rate
$imp = implode(",", array_keys($threadcache));
$query = $db->simple_select("threadratings", "tid, uid", "tid IN ({$imp}) AND uid = '{$mybb->user['uid']}'");
while($rating = $db->fetch_array($query))
{
$threadcache[$rating['tid']]['rated'] = 1;
}
}
}
// If user has moderation tools available, prepare the Select All feature
$selectall = '';
if(is_moderator($fid) && $threadcount > $perpage)
{
$lang->page_selected = $lang->sprintf($lang->page_selected, count($threadcache));
$lang->select_all = $lang->sprintf($lang->select_all, (int)$threadcount);
$lang->all_selected = $lang->sprintf($lang->all_selected, (int)$threadcount);
eval("\$selectall = \"".$templates->get("forumdisplay_inlinemoderation_selectall")."\";");
}
if(!empty($tids))
{
$tids = implode(",", $tids);
}
// Check participation by the current user in any of these threads - for 'dot' folder icons
if($mybb->settings['dotfolders'] != 0 && $mybb->user['uid'] && !empty($threadcache))
{
$query = $db->simple_select("posts", "DISTINCT tid,uid", "uid='{$mybb->user['uid']}' AND tid IN ({$tids}) {$visibleonly}");
while($post = $db->fetch_array($query))
{
if(!empty($moved_threads[$post['tid']]))
{
$post['tid'] = $moved_threads[$post['tid']];
}
if($threadcache[$post['tid']])
{
$threadcache[$post['tid']]['doticon'] = 1;
}
}
}
// Read threads
if($mybb->user['uid'] && $mybb->settings['threadreadcut'] > 0 && !empty($threadcache))
{
$query = $db->simple_select("threadsread", "*", "uid='{$mybb->user['uid']}' AND tid IN ({$tids})");
while($readthread = $db->fetch_array($query))
{
if(!empty($moved_threads[$readthread['tid']]))
{
$readthread['tid'] = $moved_threads[$readthread['tid']];
}
if($threadcache[$readthread['tid']])
{
$threadcache[$readthread['tid']]['lastread'] = $readthread['dateline'];
}
}
}
if($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid'])
{
$forum_read = 0;
$query = $db->simple_select("forumsread", "dateline", "fid='{$fid}' AND uid='{$mybb->user['uid']}'");
if($db->num_rows($query) > 0)
{
$forum_read = $db->fetch_field($query, "dateline");
}
$read_cutoff = TIME_NOW-$mybb->settings['threadreadcut']*60*60*24;
if($forum_read == 0 || $forum_read < $read_cutoff)