-
Notifications
You must be signed in to change notification settings - Fork 513
Expand file tree
/
Copy pathforum.inc
More file actions
1529 lines (1387 loc) · 48.1 KB
/
forum.inc
File metadata and controls
1529 lines (1387 loc) · 48.1 KB
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
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2008 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
require_once("../inc/forum_db.inc");
require_once("../inc/pm.inc");
require_once("../inc/team.inc");
require_once("../inc/user.inc");
require_once("../inc/news.inc");
require_once("../inc/text_transform.inc");
define('THREADS_PER_PAGE', 50);
define('FORUM_LH_PCT', '25%'); // width of LH column
$forum_error = "";
// for functions that return null on error,
// look here for an explanation
// sorting styles (for both threads and posts)
//
define('MODIFIED_NEW', 1);
define('MODIFIED_OLD', 2);
define('VIEWS_MOST', 3);
define('REPLIES_MOST', 4);
define('CREATE_TIME_NEW', 5);
define('CREATE_TIME_OLD', 6);
define('POST_SCORE', 7);
// names for the above
//
$thread_sort_styles[CREATE_TIME_OLD] = tra("Oldest first");
$thread_sort_styles[CREATE_TIME_NEW] = tra("Newest first");
$thread_sort_styles[POST_SCORE] = tra("Highest rated posts first");
$forum_sort_styles[MODIFIED_NEW] = tra("Newest post first");
$forum_sort_styles[VIEWS_MOST] = tra("Most views first");
$forum_sort_styles[REPLIES_MOST] = tra("Most posts first");
$forum_sort_styles[CREATE_TIME_NEW] = tra("Newest first");
// values for thread.status
define('THREAD_SOLVED', 1);
define('AVATAR_WIDTH', 100);
define('AVATAR_HEIGHT',100);
define('ST_NEW_TIME', 1209600); //3600*24*14 - 14 days
define('ST_NEW', 'New member');
if (!defined('MAXIMUM_EDIT_TIME')) {
define('MAXIMUM_EDIT_TIME', 3600);
// allow edits of forums posts up till one hour after posting.
}
define('MAX_FORUM_LOGGING_TIME', 2419200); //3600*24*28 - 28 days
define('NO_CONTROLS', 0);
define('FORUM_CONTROLS', 1);
define('HELPDESK_CONTROLS', 2);
define("EXCERPT_LENGTH", "120");
define('NEW_IMAGE', 'img/unread_post.png');
define('NEW_IMAGE_STICKY', 'img/unread_sticky.png');
define('NEW_IMAGE_LOCKED', 'img/unread_locked.png');
define('NEW_IMAGE_STICKY_LOCKED', 'img/unread_sticky_locked.png');
define('IMAGE_STICKY', 'img/sticky_post.png');
define('IMAGE_LOCKED', 'img/locked_post.png');
define('IMAGE_HIDDEN', 'img/hidden.png');
define('IMAGE_STICKY_LOCKED', 'img/sticky_locked_post.png');
define('IMAGE_POST', 'img/post.png');
define('NEW_IMAGE_HEIGHT','15');
define('EMPHASIZE_IMAGE', 'img/emphasized_post.png');
define('EMPHASIZE_IMAGE_HEIGHT','15');
define('FILTER_IMAGE', 'img/filtered_post.png');
define('FILTER_IMAGE_HEIGHT','15');
define('RATE_POSITIVE_IMAGE', 'img/rate_positive.png');
define('RATE_POSITIVE_IMAGE_HEIGHT','9');
define('RATE_NEGATIVE_IMAGE', 'img/rate_negative.png');
define('RATE_NEGATIVE_IMAGE_HEIGHT','9');
define('REPORT_POST_IMAGE', 'img/report_post.png');
define('REPORT_POST_IMAGE_HEIGHT','9');
define('SOLUTION', tra('This answered my question'));
define('SUFFERER', tra('I also have this question'));
define('OFF_TOPIC', tra('Off-topic'));
define ('DEFAULT_LOW_RATING_THRESHOLD', -25);
define ('DEFAULT_HIGH_RATING_THRESHOLD', 5);
// special user attributes
//
define('S_MODERATOR', 0);
define('S_ADMIN', 1);
define('S_DEV', 2);
define('S_TESTER', 3);
define('S_VOLUNTEER', 4);
define('S_VOLUNTEER_TESTER', 5);
define('S_SCIENTIST', 6);
define('S_HELP_DESK_EXPERT', 7);
define('S_NFLAGS', 8);
$special_user_bitfield[S_MODERATOR] = tra("Volunteer moderator");
$special_user_bitfield[S_ADMIN] = tra("Project administrator");
$special_user_bitfield[S_DEV] = tra("Project developer");
$special_user_bitfield[S_TESTER] = tra("Project tester");
$special_user_bitfield[S_VOLUNTEER] = tra("Volunteer developer");
$special_user_bitfield[S_VOLUNTEER_TESTER] = tra("Volunteer tester");
$special_user_bitfield[S_SCIENTIST] = tra("Project scientist");
$special_user_bitfield[S_HELP_DESK_EXPERT] = tra("Help desk expert");
function link_count($x) {
$n = 0;
while (1) {
$x = strstr($x, "[url");
if (!$x) break;
$n++;
$x = substr($x, 4);
}
return $n;
}
// show a banner with search form on left and PM info on right
//
function show_forum_header($user) {
echo '<form action="forum_search_action.php" method="POST">
';
start_table();
echo '
<tr>
';
// Search
echo '
<td>
<input type="hidden" name="search_max_time" value="0">
<input type="hidden" name="search_forum" value="-1">
<input type="hidden" name="search_sort" value="'.CREATE_TIME_NEW.'">
<input type="text" class="" name="search_keywords">
';
echo sprintf(
'<input class="btn" %s title="%s" type="submit" value="%s"><br>',
button_style(),
tra("Search for words in forum messages"),
tra("Search forums")
);
echo '
<small><a href="forum_search.php">'.tra("Advanced search").'</a></small>
</td>
';
if ($user) {
echo "<td align=\"right\">\n";
echo "<p>".tra("Private messages").": ", pm_notification($user);
echo "</td>\n";
}
echo "</tr>
";
end_table();
echo "</form>
";
}
// return forum/thread title, with links.
//
function forum_title($category, $forum, $thread, $link_thread=false) {
if ($category) {
$is_helpdesk = $category->is_helpdesk;
} else {
$is_helpdesk = false;
}
$where = $is_helpdesk?tra("Questions and Answers"):tra("Message boards");
$top_url = $is_helpdesk?"forum_help_desk.php":"forum_index.php";
$x = '';
if (!$forum && !$thread) {
$x .= $where;
} else if ($forum && !$thread) {
$x .= sprintf('<a href="%s">%s</a> : %s',
$top_url,
$where,
$forum->title
);
} else if ($forum && $thread) {
$x .= sprintf('<a href="%s">%s</a> : ',
$top_url,
$where
);
$x .= sprintf('<a href="forum_forum.php?id=%d">%s</a> : ',
$forum->id,
$forum->title
);
if ($link_thread) {
$x .= sprintf('<a href=forum_thread.php?id=%d>%s</a>',
$thread->id,
cleanup_title($thread->title)
);
} else {
$x .= cleanup_title($thread->title);
}
} else {
$x = "Invalid thread ID";
}
return $x;
}
function team_forum_title($forum, $thread=null, $link_thread=false) {
$team = BoincTeam::lookup_id($forum->category);
$x = sprintf('<a href="forum_index.php">%s</a> :',
tra("Message boards")
);
if ($thread) {
$x .= sprintf('<a href=team_forum.php?teamid=%d>%s</a>',
$team->id,
tra("%1 message board", $team->name)
);
if ($link_thread) {
$x .= " : <a href=forum_thread.php?id=$thread->id>$thread->title</a>";
} else {
$x .= " : $thread->title";
}
} else {
$x .= tra("%1 message board", $team->name);
}
return $x;
}
// start a table of forum posts
//
function start_forum_table($headings) {
$a = array();
foreach ($headings as $h) {
$a[] = null;
}
$a[1] = 'style="width: 100%"';
start_table('table-striped');
row_heading_array($headings, $a);
}
function page_link($url, $page_num, $items_per_page, $text) {
return " <a href=\"$url&start=" . $page_num*$items_per_page . "\">$text</a> ";
}
// return a string for navigating pages
//
function page_links($url, $nitems, $items_per_page, $start){
// How many pages to potentially show before and after this one:
$preshow = 3;
$postshow = 3;
$x = "";
if ($nitems <= $items_per_page) return "";
$npages = ceil($nitems / $items_per_page);
$curpage = ceil($start / $items_per_page);
// If this is not the first page, display "previous"
//
if ($curpage > 0){
$x .= page_link(
$url, $curpage-1, $items_per_page,
tra("Previous")." · "
);
}
if ($curpage - $preshow > 0) {
$x .= page_link($url, 0, $items_per_page, "1");
if ($curpage - $preshow > 1) {
$x .= " . . . ";
} else {
$x .= " · ";
}
}
// Display a list of pages surrounding this one
//
for ($i=$curpage-$preshow; $i<=$curpage+$postshow; $i++){
$page_str = (string)($i+1);
if ($i < 0) continue;
if ($i >= $npages) break;
if ($i == $curpage) {
$x .= "<b>$page_str</b>";
} else {
$x .= page_link($url, $i, $items_per_page, $page_str);
}
if ($i == $npages-1) break;
if ($i == $curpage+$postshow) break;
$x .= " · ";
}
if ($curpage + $postshow < $npages-1) {
$x .= " . . . ";
$x .= page_link($url, $npages-1, $items_per_page, $npages);
}
// If there is a next page
//
if ($curpage < $npages-1){
$x .= page_link(
$url, $curpage+1, $items_per_page,
" · ".tra("Next")
);
}
$x .= "\n";
return $x;
}
function thread_is_unread($user, $thread) {
if (!$user) return false;
if ($thread->timestamp <= $user->prefs->mark_as_read_timestamp) return false;
$log = BoincForumLogging::lookup($user->id, $thread->id);
if ($log && ($thread->timestamp <= $log->timestamp)) return false;
return true;
}
// Process a user-supplied title to remove HTML stuff
//
function cleanup_title($title) {
$x = sanitize_tags(bb2html($title));
$x = trim($x);
if (strlen($x)==0) return "(no title)";
else return $x;
}
function can_reply($thread, $forum, $user) {
if ($thread->locked) {
if (!is_moderator($user, $forum)) return false;
}
return true;
}
// Show the posts in a thread for a user.
// If $start is null, enforce jump-to-first-unread
//
function show_posts(
$thread, $forum, $start, $postid, $sort_style, $filter, $logged_in_user
) {
$num_to_show = 20;
if ($logged_in_user && $logged_in_user->prefs->display_wrap_postcount > 0) {
$num_to_show = $logged_in_user->prefs->display_wrap_postcount;
}
// let moderators see all posts, including hidden ones
//
if (is_moderator($logged_in_user, $forum)) {
$show_hidden = true;
} else {
$show_hidden = false;
}
$posts = get_thread_posts($thread->id, $sort_style, $show_hidden);
$latest_viewed = 0;
$forum_log = null;
if ($logged_in_user) {
$forum_log = BoincForumLogging::lookup($logged_in_user->id, $thread->id);
if ($forum_log) {
$latest_viewed = $forum_log->timestamp;
}
}
if ($sort_style == CREATE_TIME_OLD) {
// show the last page
//
$nposts = sizeof($posts);
if ($nposts) $nposts -= 1;
$page = (int)($nposts/$num_to_show);
$default_start = $page*$num_to_show;
} else {
$default_start = 0;
}
// jump to a specific post if needed
//
$jump_to_post = null;
if ($start === null) {
if ($postid) {
// jump to a specific post
//
$i = 0;
foreach ($posts as $post) {
if ($post->id == $postid) {
$start = $i - ($i % $num_to_show);
$jump_to_post = $post;
break;
}
$i++;
}
if ($start === null) {
echo "Post $postid not found.";
return;
}
} else if ($logged_in_user && $logged_in_user->prefs->jump_to_unread) {
// jump to the first unread post
//
$i = 0;
$ibest = 0;
foreach ($posts as $post) {
if ($post->timestamp > $latest_viewed) {
if (!$jump_to_post || ($post->timestamp < $jump_to_post->timestamp)) {
$jump_to_post = $post;
$ibest = $i;
}
}
$i++;
}
// if jump to post, figure out what page to show
//
if ($jump_to_post) {
$start = $ibest - ($ibest % $num_to_show);
} else {
$start = $default_start;
}
} else {
$start = $default_start;
}
}
$page_nav = page_links(
"forum_thread.php?id=$thread->id&sort_style=$sort_style",
sizeof($posts),
$num_to_show,
$start
);
echo $page_nav;
$num_shown = 0;
$num_skipped = 0;
$headings = array(tra("Author"), tra("Message"));
start_forum_table($headings);
$latest_shown_timestamp = 0;
foreach ($posts as $post) {
if ($num_skipped < $start) {
$num_skipped++;
continue;
}
if ($num_shown == $num_to_show) {
break;
}
show_post(
$post, $thread, $forum, $logged_in_user, $start, $latest_viewed,
FORUM_CONTROLS, $filter
);
if ($post->timestamp > $latest_shown_timestamp) {
$latest_shown_timestamp = $post->timestamp;
}
$num_shown++;
}
end_table();
echo $page_nav;
if ($jump_to_post) {
echo "<script>function jumpToUnread(){location.href='#".$jump_to_post->id."';}</script>";
} else {
echo "<script>function jumpToUnread(){};</script>";
}
// if thread has no visible posts, user has seen them all
//
if ($num_shown == 0) {
$latest_shown_timestamp = time();
}
if ($logged_in_user) {
if (!$forum_log || $latest_shown_timestamp > $forum_log->timestamp) {
BoincForumLogging::replace(
$logged_in_user->id, $thread->id, $latest_shown_timestamp
);
}
}
}
function get_ignored_list($user) {
return explode("|", $user->prefs->ignorelist);
}
function add_ignored_user($user, $other_user) {
$list = explode("|", $user->prefs->ignorelist);
foreach ($list as $key=>$userid) {
if ($userid == $other_user->id) {
return true;
}
}
$list[] = $other_user->id;
$x = implode("|", array_values($list));
return $user->prefs->update("ignorelist='$x'");
}
function remove_ignored_user($user, $other_user) {
$list = explode("|", $user->prefs->ignorelist);
foreach ($list as $key=>$userid) {
if ($userid == $other_user->id) {
unset($list[$key]);
}
}
$x = implode("|", array_values($list));
return $user->prefs->update("ignorelist='$x'");
}
function is_ignoring($user, $other_user) {
$list = explode("|", $user->prefs->ignorelist);
return in_array($other_user->id, $list);
}
// if avatar is from gravatar, make it HTTPS
//
function avatar_url($url) {
return str_replace('http:', 'https:', $url);
}
// Display an individual post.
// Generates a table row with two cells: author and message
//
function show_post(
$post, $thread, $forum, $logged_in_user, $start=0,
$latest_viewed=0, $controls=FORUM_CONTROLS, $filter=true
) {
global $country_to_iso3166_2;
$user = BoincUser::lookup_id($post->user);
// If the user no longer exists, skip the post
//
if (!$user){
return;
}
$config = get_config();
BoincForumPrefs::lookup($user);
if (is_banished($user) && !is_moderator($logged_in_user, $forum)) {
return;
}
$no_forum_rating = parse_bool($config, "no_forum_rating");
$tokens = "";
$options = get_output_options($logged_in_user);
if (is_admin($user)) {
$options->htmlitems = false;
}
// check whether the poster is on the list of people to ignore
//
$ignore_poster = false;
if ($logged_in_user){
$tokens = url_tokens($logged_in_user->authenticator);
if (is_ignoring($logged_in_user, $user)){
$ignore_poster = true;
}
}
// The creator can edit the post, but only in a specified amount of time
// (exception: a moderator can edit his/her posts at any time)
//
$can_edit = false;
if ($logged_in_user) {
if ($user->id == $logged_in_user->id) {
if (is_moderator($logged_in_user, $forum)) {
$can_edit = true;
} else if (can_reply($thread, $forum, $logged_in_user)) {
$time_limit = $post->timestamp+MAXIMUM_EDIT_TIME;
$can_edit = time()<$time_limit;
} else {
$can_edit = false;
}
}
}
// Print the special user lines, if any
//
global $special_user_bitfield;
$fstatus="";
$keys = array_keys($special_user_bitfield);
$is_posted_by_special = false;
for ($i=0; $i<sizeof($special_user_bitfield);$i++) {
if ($user->prefs && $user->prefs->privilege($keys[$i])) {
$fstatus .= "<nobr>".$special_user_bitfield[$keys[$i]]."<nobr><br>";
$is_posted_by_special = true;
}
}
if (is_moderator($logged_in_user, $forum) && is_banished($user)) {
$fstatus .= '(banished)';
}
// Highlight special users if set in prefs;
//
if ($logged_in_user && $logged_in_user->prefs){
$highlight = $logged_in_user->prefs->highlight_special && $is_posted_by_special;
} else {
$highlight = $is_posted_by_special;
}
$class = $highlight?' style="border-left: 5px solid LightGreen" ':'';
// row and start of author col
//
echo "
<tr>
<td $class>
<a name=\"$post->id\"></a>
";
echo user_links($user, 0, 30);
echo "<br>";
if ($user->create_time > time()-ST_NEW_TIME) $fstatus.=ST_NEW."<br>";
echo "<span class=\"small\">";
if ($fstatus) echo "$fstatus";
if (!$filter || !$ignore_poster){
if ($user->prefs && $user->prefs->avatar!="" && (!$logged_in_user || ($logged_in_user->prefs->hide_avatars==false))) {
echo "<img width=\"".AVATAR_WIDTH."\" height=\"".AVATAR_HEIGHT."\" src=\"".avatar_url($user->prefs->avatar)."\" alt=\"Avatar\"><br>";
}
}
echo "<p> </p>";
$url = "pm.php?action=new&userid=".$user->id;
$name = $user->name;
show_button_small($url, tra("Send message"), tra("Send %1 a private message",$name));
echo '<br>'.tra("Joined: %1", gmdate('j M y', $user->create_time)), "<br>";
if (!isset($user->nposts)) {
$user->nposts = BoincPost::count("user=$user->id");
}
if (function_exists('project_forum_user_info')){
project_forum_user_info($user);
} else {
echo tra("Posts: %1", $user->nposts)."<br>";
// circumvent various forms of identity spoofing
// by displaying the user id of the poster.
//
//echo "ID: ".$user->id."<br>";
if (!NO_COMPUTING) {
echo tra("Credit: %1", number_format($user->total_credit)) ."<br>";
echo tra("RAC: %1", number_format($user->expavg_credit))."<br>";
}
// to use this feature:
// - get flags from http://www.famfamfam.com/lab/icons/flags/famfamfam_flag_icons.zip
// - put the .png's in html/user/flags/
// - put define("COUNTRY_FLAGS", 1); in your html/project/project.inc
//
if (USER_COUNTRY && defined("COUNTRY_FLAGS")) {
if (array_key_exists($user->country, $country_to_iso3166_2)) {
$code = $country_to_iso3166_2[$user->country];
echo "<img class=flag alt=\"$user->country\" title=\"$user->country\" src=flags/$code.png>\n";
}
}
echo badges_string(true, $user, BADGE_HEIGHT_SMALL);
}
// end of author col, start of message col
//
echo '</span>
</td>
<td height="1%">
<div class="small">
';
if ($controls == FORUM_CONTROLS) {
echo "<form action=\"forum_rate.php?post=", $post->id, "\" method=\"post\">";
}
if ($logged_in_user && $post->timestamp > $latest_viewed){
show_image(NEW_IMAGE, tra("You haven't read this message yet"), tra("Unread"), NEW_IMAGE_HEIGHT);
}
echo " <a href=\"forum_thread.php?id=".$thread->id."&postid=$post->id\">".tra("Message %1", $post->id)."</a> - ";
if ($post->hidden) echo "<font color=red>[".tra("hidden")."] </font>";
echo tra("Posted: %1", pretty_time_str($post->timestamp)), " ";
if ($post->parent_post) {
echo tra(" - in response to ")."<a href=\"forum_thread.php?id=".$thread->id."&postid=".$post->parent_post."\">".tra("Message %1", $post->parent_post)."</a>. ";
}
if ($can_edit && $controls != NO_CONTROLS) {
show_button_small("forum_edit.php?id=".$post->id."$tokens", tra("Edit"), tra("Edit this message"));
}
if (is_moderator($logged_in_user, $forum)) {
show_post_moderation_links($config, $logged_in_user, $post, $forum, $tokens);
}
if ($post->modified) {
echo "<br>".tra("Last modified: %1", pretty_time_Str($post->modified));
}
if ($ignore_poster && $filter){
echo "<br>" .tra(
"This post is hidden because the sender is on your 'ignore' list. Click %1 here %2 to view hidden posts",
"<a href=\"?id=".$thread->id."&filter=false&start=$start#".$post->id."\">",
"</a>"
);
}
if ($controls == FORUM_CONTROLS) {
echo "</form>\n";
}
echo "</div>
<p>
";
if (!$filter || !$ignore_poster){
$posttext = $post->content;
// If the creator of this post has a signature and
// wants it to be shown for this post AND the logged in
// user has signatures enabled: show it
//
$posttext = output_transform($posttext, $options);
if ($post->signature && (!$logged_in_user || !$logged_in_user->prefs->hide_signatures)){
$sig = output_transform($user->prefs->signature, $options);
$posttext .= "<hr>$sig\n";
}
// show message in a panel
//
echo '<div class="panel panel-default" style="word-break: break-word;">
<div class="panel-body">'
.$posttext
.'</div></div>
';
echo '<div class="small"
<span>ID: '. $post->id
;
if ($no_forum_rating) {
echo " · <a href=\"forum_report_post.php?post=".$post->id."\">";
show_image(REPORT_POST_IMAGE, tra("Report this post as offensive"), tra("Report as offensive"), REPORT_POST_IMAGE_HEIGHT);
echo "</a>";
} else {
$rating = $post->rating();
echo " · ".tra("Rating: %1", $rating)." · ".tra("rate: ")."
<a href=\"forum_rate.php?post=".$post->id."&choice=p$tokens\">
";
show_image(RATE_POSITIVE_IMAGE, tra("Click if you like this message"), tra("Rate +"), RATE_POSITIVE_IMAGE_HEIGHT);
echo "</a> / <a href=\"forum_rate.php?post=".$post->id."&choice=n$tokens\">";
show_image(RATE_NEGATIVE_IMAGE, tra("Click if you don't like this message"), tra("Rate -"), RATE_NEGATIVE_IMAGE_HEIGHT);
echo "</a> <a href=\"forum_report_post.php?post=".$post->id."\">";
show_image(REPORT_POST_IMAGE, tra("Report this post as offensive"), tra("Report as offensive"), REPORT_POST_IMAGE_HEIGHT);
echo "</a>";
}
if (($controls == FORUM_CONTROLS) && (can_reply($thread, $forum, $logged_in_user))) {
echo " ";
$url = "forum_reply.php?thread=" . $thread->id . "&post=" . $post->id . "&no_quote=1#input";
// "Reply" is used as a verb
show_button($url, tra("Reply"), tra("Post a reply to this message"));
$url = "forum_reply.php?thread=" . $thread->id . "&post=" . $post->id . "#input";
// "Quote" is used as a verb
show_button($url, tra("Quote"), tra("Post a reply by quoting this message"));
}
echo "</span>";
}
// end of message col and row; add separator row
//
echo "</td></tr>
<tr><td colspan=2></td></tr>
";
}
// Show a post and its context (e.g. for search results, user posts)
//
function show_post_and_context($post, $thread, $forum, $options, $n) {
$thread = BoincThread::lookup_id($post->thread);
$forum = BoincForum::lookup_id($thread->forum);
$content = output_transform($post->content, $options);
$when = time_diff_str($post->timestamp, time());
$user = BoincUser::lookup_id($post->user);
if (!$user){
return;
}
$config = get_config();
$title = cleanup_title($thread->title);
if ($post->hidden) {
$deleted = "<br><font color=red>[".tra("Hidden by a moderator")."]</font>";
} else {
$deleted = "";
}
switch ($forum->parent_type) {
case 0:
$category = BoincCategory::lookup_id($forum->category);
$title= forum_title($category, $forum, $thread, true);
break;
case 1:
$title= team_forum_title($forum);
break;
}
row_array([
sprintf(
'%d) %s
<br><a href="forum_thread.php?id=%d&postid=%d">%s</a>
<br>%s%s
',
$n, $title,
$thread->id, $post->id,
tra("Message %1", $post->id),
tra("Posted %1 by %2", $when, user_links($user)),
$deleted
),
$content
]);
}
function is_banished($user) {
BoincForumPrefs::lookup($user);
return ($user->prefs->banished_until > time());
}
// $user is the logged-in user.
// They're trying to make a forum post or send a personal message.
// If they're banished, don't allow it
//
function check_banished($user) {
if (is_banished($user)) {
error_page(
tra("You may not post or rate messages until %1", gmdate('M j, Y', $user->prefs->banished_until))
);
}
}
function post_rules() {
if (defined('FORUM_RULES')) return FORUM_RULES;
if (function_exists("project_forum_post_rules")) {
$project_rules=project_forum_post_rules();
} else {
$project_rules="";
}
return sprintf("
<ul>
<li> %s
<li> %s
<li> %s
<li> %s
<li> %s
<li> %s
<li> %s
<li> %s
<li> %s
%s
</ul>
",
tra("Posts must be 'kid friendly': they may not contain content that is obscene, hate-related, sexually explicit or suggestive."),
tra("No commercial advertisements."),
tra("No links to web sites involving sexual content, gambling, or intolerance of others."),
tra("No messages intended to annoy or antagonize other people, or to hijack a thread."),
tra("No messages that are deliberately hostile, threatening, or insulting."),
tra("No abusive messages involving race, religion, nationality, gender, class or sexuality."),
tra("Posts that violate these rules may be deleted."),
tra("The posting privileges of violators may be suspended or revoked."),
tra("If your account is suspended, don't create a new one."),
$project_rules
);
}
function post_warning($forum=null) {
$x = '<p><div style="text-align:left">';
// let projects add extra instructions in specific forums,
// e.g. Questions and Problems
//
if (function_exists('project_forum_post_info')) {
$x .= project_forum_post_info($forum);
}
$x .= "
<small>
".post_rules()."
</small>
</div>
";
return $x;
}
function notify_thread_subscriber($thread, $user) {
BoincForumPrefs::lookup($user);
if ($user->prefs->pm_notification == 1) {
send_thread_notification_email($thread, $user);
}
$now = time();
$type = NOTIFY_SUBSCRIBED_THREAD;
BoincNotify::replace(
"userid=$user->id, create_time=$now, type=$type, opaque=$thread->id"
);
}
// notify subscribed users, except for the given user
//
function notify_thread_subscribers($thread, $user) {
$subs = BoincSubscription::enum("threadid=$thread->id");
foreach ($subs as $sub) {
if ($user && ($user->id == $sub->userid)) continue;
$user2 = BoincUser::lookup_id($sub->userid);
if ($user2) {
notify_thread_subscriber($thread, $user2);
}
}
}
function notify_forum_subscriber($forum, $user) {
BoincForumPrefs::lookup($user);
if ($user->prefs->pm_notification == 1) {
send_forum_notification_email($forum, $user);
}
$now = time();
$type = NOTIFY_SUBSCRIBED_FORUM;
BoincNotify::replace(
"userid=$user->id, create_time=$now, type=$type, opaque=$forum->id"
);
}
// notify subscribed users, except for the given user
//
function notify_forum_subscribers($forum, $user) {
$id = -$forum->id;
$subs = BoincSubscription::enum("threadid=$id");
foreach ($subs as $sub) {
if ($user && ($user->id == $sub->userid)) continue;
$user2 = BoincUser::lookup_id($sub->userid);
if ($user2) {
notify_forum_subscriber($forum, $user2);
}
}
}
// Various functions for adding/hiding/unhiding stuff.
// These take care of counts and timestamps.
// Don't do these things directly - use these functions
//
function create_post($content, $parent_id, $user, $forum, $thread, $signature) {
global $forum_error;
if (POST_MAX_LINKS
&& link_count($content) > POST_MAX_LINKS
&& !is_moderator($user, $forum)
) {
$forum_error = "Too many links.";
return null;
}
$content = substr($content, 0, 64000);
$content = BoincDb::escape_string($content);
$now = time();
$sig = $signature?1:0;
$id = BoincPost::insert("(thread, user, timestamp, content, modified, parent_post, score, votes, signature, hidden) values ($thread->id, $user->id, $now, '$content', 0, $parent_id, 0, 0, $sig, 0)");
if (!$id) {
$forum_error = "Failed to add post to DB.";
return null;
}
notify_thread_subscribers($thread, $user);
$user->prefs->update("posts=posts+1");
$thread->update("replies=replies+1, timestamp=$now");
$forum->update("posts=posts+1, timestamp=$now");
return $id;
}
// call this when hide or delete a post;
// it sets timestamp to time of last non-hidden post
//
function update_thread_timestamp($thread) {
$posts = BoincPost::enum("thread=$thread->id and hidden=0 order by timestamp desc limit 1");
if (count($posts)>0) {
$post = $posts[0];
$thread->update("timestamp=$post->timestamp");
}
}
function update_forum_timestamp($forum) {
$threads = BoincThread::enum("forum=$forum->id and hidden=0 order by timestamp desc limit 1");
if (count($threads)>0) {
$thread = $threads[0];
$forum->update("timestamp=$thread->timestamp");
}
}
function create_thread($title, $content, $user, $forum, $signature, $export) {
global $forum_error;
if (POST_MAX_LINKS
&& link_count($content) > POST_MAX_LINKS
&& !is_moderator($user, $forum)
) {
$forum_error = "Too many links.";
return null;
}
$title = trim($title);
$title = sanitize_tags($title);
$title = BoincDb::escape_string($title);
$now = time();
$status = 0;
if (is_news_forum($forum) && !$export) {