forked from Phorum/Core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
moderation.php
1075 lines (916 loc) · 39.3 KB
/
moderation.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
////////////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2017 Phorum Development Team //
// http://www.phorum.org //
// //
// This program is free software. You can redistribute it and/or modify //
// it under the terms of either the current Phorum License (viewable at //
// phorum.org) or the Phorum License that was distributed with this file //
// //
// This program 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. //
// //
// You should have received a copy of the Phorum License //
// along with this program. //
// //
////////////////////////////////////////////////////////////////////////////////
define('phorum_page','moderation');
include_once("./common.php");
include_once("./include/moderation_functions.php");
include_once("./include/thread_info.php");
include_once("./include/email_functions.php");
if(!phorum_check_read_common()) {
return;
}
// CSRF protection: we do not accept posting to this script,
// when the browser does not include a Phorum signed token
// in the request.
phorum_check_posting_token();
$PHORUM["DATA"]["MODERATOR"] =
phorum_api_user_check_access(PHORUM_USER_ALLOW_MODERATE_MESSAGES);
if(isset($_POST["thread"])) {
$msgthd_id = (int)$_POST["thread"];
} elseif(isset($PHORUM['args'][2])) {
$msgthd_id = (int)$PHORUM['args'][2];
} else {
$msgthd_id = 0;
}
if(isset($_POST["mod_step"])) {
$mod_step = (int)$_POST["mod_step"];
} elseif(isset($PHORUM['args'][1])) {
$mod_step = (int)$PHORUM['args'][1];
} else {
$mod_step = 0;
}
if(empty($msgthd_id) || !$PHORUM["DATA"]["MODERATOR"]) {
phorum_return_to_list();
}
// If the user is not fully logged in, send him to the login page.
// because moderation action can vary so much, the only safe bet is to send them
// to the referrer if they are not fully logged in
if(!$PHORUM["DATA"]["FULLY_LOGGEDIN"]){
phorum_redirect_by_url(phorum_get_url(PHORUM_LOGIN_URL, "redir=".$_SERVER["HTTP_REFERER"]));
exit;
}
// if we gave the user a confirmation form and they clicked No, send them back to the message
if(isset($_POST["confirmation"]) && $_POST["confirmation"]==$PHORUM["DATA"]["LANG"]["No"]){
if(isset($_POST["prepost"])) {
// add some additional args
$addcode = "";
if(isset($_POST['moddays']) && is_numeric($_POST['moddays'])) {
$addcode.="moddays=".$_POST['moddays'];
}
if(isset($_POST['onlyunapproved']) && is_numeric($_POST['onlyunapproved'])) {
if(!empty($addcode))
$addcode.=",";
$addcode.="onlyunapproved=".$_POST['onlyunapproved'];
}
$url = phorum_get_url(PHORUM_CONTROLCENTER_URL,"panel=".PHORUM_CC_UNAPPROVED,$addcode);
} else {
$message = phorum_db_get_message($msgthd_id);
$url = phorum_get_url(PHORUM_READ_URL, $message["thread"], $message["message_id"]);
}
phorum_redirect_by_url($url);
exit;
}
$template="message";
// set all our URL's
phorum_build_common_urls();
// make it possible to override this var in a hook
$is_admin_user=$PHORUM["user"]["admin"];
/*
* [hook]
* moderation
*
* [description]
* This hook can be used for logging moderator actions. You can
* use the <literal>$PHORUM</literal> array to retrieve additional info
* like the moderating user's id and similar.<sbr/>
* <sbr/>
* The moderation step id is the variable <literal>$mod_step</literal>
* that is used in <filename>moderation.php</filename>. Please read that
* script to see what moderation steps are available and for what moderation
* actions they stand.<sbr/>
* <sbr/>
* When checking the moderation step id for a certain step, always use
* the contstants that are defined for this in
* <filename>include/constants.php</filename>. The numerical value of this
* id can change between Phorum releases.
*
* [category]
* Moderation
*
* [when]
* At the start of <filename>moderation.php</filename>
*
* [input]
* The id of the moderation step which is run (read-only).
*
* [output]
* Same as input.
*
* [example]
* <hookcode>
* function phorum_mod_foo_moderation ($mod_step)
* {
* global $PHORUM;
*
* // Update the last timestamp for the moderation step
* $PHORUM["mod_foo"]["moderation_step_timestamps"][$mod_step] = time();
* phorum_db_update_settings(array("mod_foo" => $PHORUM["mod_foo"]));
*
* return $mod_step;
* }
* </hookcode>
*/
if (isset($PHORUM["hooks"]["moderation"]))
phorum_hook("moderation", $mod_step);
$invalidate_message_cache = array();
switch ($mod_step) {
case PHORUM_DELETE_MESSAGE: // this is a message delete
if(count($_GET) && empty($_POST["thread"])){
$args = array(
"mod_step" => PHORUM_DELETE_MESSAGE,
"thread" => $msgthd_id
);
foreach($PHORUM["args"] as $k=>$v){
if(!is_numeric($k)){
$args[$k] = $v;
}
}
return phorum_show_confirmation_form(
$PHORUM["DATA"]["LANG"]["ConfirmDeleteMessage"],
phorum_get_url(PHORUM_MODERATION_ACTION_URL),
$args
);
}
$message = phorum_db_get_message($msgthd_id);
/*
* [hook]
* before_delete
*
* [description]
* This hook allows modules to implement extra or different delete
* functionality.<sbr/>
* <sbr/>
* The primary use of this hook would be for moving the messages
* to some archive-area instead of really deleting them.
*
* [category]
* Moderation
*
* [when]
* In <filename>moderation.php</filename>, just before deleting
* the message(s)
*
* [input]
* An array containing the following 5 parameters:
* <ul>
* <li><literal>$delete_handled</literal>:
* default = <literal>false</literal>, set it to true to avoid
* the real delete afterwards</li>
* <li><literal>$msg_ids</literal>:
* an array containing all deleted message ids</li>
* <li><literal>$msgthd_id</literal>:
* the msg-id or thread-id to be deleted</li>
* <li><literal>$message</literal>:
* an array of the data for the message retrieved with
* <literal>$msgthd_id</literal></li>
* <li><literal>$delete_mode</literal>:
* mode of deletion, either
* <literal>PHORUM_DELETE_MESSAGE</literal> or
* <literal>PHORUM_DELETE_TREE</literal></li>
* </ul>
*
* [output]
* Same as input.<sbr/>
* <literal>$delete_handled</literal> and
* <literal>$msg_ids</literal> are used as return data for the hook.
*
* [example]
* <hookcode>
* function phorum_mod_foo_before_delete($data)
* {
* global $PHORUM;
*
* // Store the message data in the module's settings for
* // future use.
* $PHORUM["mod_foo"]["deleted_messages"][$msgthd_id] = $message;
* phorum_db_update_settings(array("mod_foo" => $PHORUM["mod_foo"]));
*
* return $data;
* }
* </hookcode>
*/
$delete_handled = 0;
if (isset($PHORUM["hooks"]["before_delete"]))
list($delete_handled,$msg_ids,$msgthd_id,$message,$delete_mode) = phorum_hook("before_delete", array(0,0,$msgthd_id,$message,PHORUM_DELETE_MESSAGE));
// Handle the delete action, unless a module already handled it.
if (!$delete_handled) {
// Delete the message from the database.
phorum_db_delete_message($msgthd_id, PHORUM_DELETE_MESSAGE);
// Delete the message attachments from the database.
require_once('./include/api/file_storage.php');
$files=phorum_db_get_message_file_list($msgthd_id);
foreach($files as $file_id=>$data) {
phorum_api_file_delete($file_id);
}
}
/*
* [hook]
* delete
*
* [description]
* This hook can be used for cleaning up anything you may have
* created with the post_post hook or any other hook that stored
* data tied to messages.
*
* [category]
* Moderation
*
* [when]
* In <filename>moderation.php</filename>, right after deleting a
* message from the database.
*
* [input]
* An array of ids for messages that have been deleted (read-only).
*
* [output]
* Same as input.
*
* [example]
* <hookcode>
* function phorum_mod_foo_delete($msgthd_ids)
* {
* global $PHORUM;
*
* // Log the deleted message ids
* foreach ($msgthd_ids as $msgthd_id) {
* $PHORUM["mod_foo"]["deleted_messages"][] = $msgthd_id;
* }
* phorum_db_update_settings(array("mod_foo" => $PHORUM["mod_foo"]));
*
* return $msgthd_ids;
* }
* </hookcode>
*/
if (isset($PHORUM["hooks"]["delete"]))
phorum_hook("delete", array($msgthd_id));
$PHORUM['DATA']['OKMSG']="1 ".$PHORUM["DATA"]['LANG']['MsgDeletedOk'];
if(isset($PHORUM['args']['old_forum']) && !empty($PHORUM['args']['old_forum'])) {
$PHORUM['forum_id']=(int)$PHORUM['args']['old_forum'];
}
if(isset($PHORUM['args']["prepost"])) {
$PHORUM['DATA']["URL"]["REDIRECT"]=phorum_get_url(PHORUM_CONTROLCENTER_URL,"panel=".PHORUM_CC_UNAPPROVED);
} else {
$PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["LIST"];
}
break;
case PHORUM_DELETE_TREE: // this is a message delete
if(count($_GET) && empty($_POST["thread"])){
$args = array(
"mod_step" => PHORUM_DELETE_TREE,
"thread" => $msgthd_id
);
foreach($PHORUM["args"] as $k=>$v){
if(!is_numeric($k)){
$args[$k] = $v;
}
}
return phorum_show_confirmation_form(
$PHORUM["DATA"]["LANG"]["ConfirmDeleteThread"],
phorum_get_url(PHORUM_MODERATION_ACTION_URL),
$args
);
}
$message = phorum_db_get_message($msgthd_id);
$nummsgs = 0;
$msg_ids = array();
// A hook to allow modules to implement extra or different
// delete functionality.
$delete_handled = 0;
if (isset($PHORUM["hooks"]["before_delete"]))
list($delete_handled,$msg_ids,$msgthd_id,$message,$delete_mode) = phorum_hook("before_delete", array(0,array(),$msgthd_id,$message,PHORUM_DELETE_TREE));
if(!$delete_handled) {
// Delete the message and all its replies.
$msg_ids = phorum_db_delete_message($msgthd_id, PHORUM_DELETE_TREE);
// Cleanup the attachments for all deleted messages.
require_once('./include/api/file_storage.php');
foreach($msg_ids as $id){
$files=phorum_db_get_message_file_list($id);
foreach($files as $file_id=>$data){
phorum_api_file_delete($file_id);
}
}
// Check if we have moved threads to delete.
// We unset the forum id, so phorum_db_get_messages()
// will return messages with the same thread id in
// other forums as well (those are the move notifications).
$forum_id = $PHORUM["forum_id"];
$PHORUM["forum_id"] = 0;
$moved = phorum_db_get_messages($msgthd_id);
$PHORUM["forum_id"] = $forum_id;
foreach ($moved as $id => $data) {
if (!empty($data["moved"])) {
phorum_db_delete_message($id, PHORUM_DELETE_MESSAGE);
}
}
}
$nummsgs=count($msg_ids);
// Run a hook for performing custom actions after cleanup.
if (isset($PHORUM["hooks"]["delete"]))
phorum_hook("delete", $msg_ids);
$PHORUM['DATA']['OKMSG']=$nummsgs." ".$PHORUM["DATA"]["LANG"]['MsgDeletedOk'];
if(isset($PHORUM['args']['old_forum']) && !empty($PHORUM['args']['old_forum'])) {
$PHORUM['forum_id']=(int)$PHORUM['args']['old_forum'];
}
if(isset($PHORUM['args']["prepost"])) {
// add some additional args
$addcode = "";
if(isset($PHORUM['args']['moddays']) && is_numeric($PHORUM['args']['moddays'])) {
$addcode.="moddays=".$PHORUM['args']['moddays'];
}
if(isset($PHORUM['args']['onlyunapproved']) && is_numeric($PHORUM['args']['onlyunapproved'])) {
if(!empty($addcode))
$addcode.=",";
$addcode.="onlyunapproved=".$PHORUM['args']['onlyunapproved'];
}
$PHORUM['DATA']["URL"]["REDIRECT"]=phorum_get_url(PHORUM_CONTROLCENTER_URL,"panel=".PHORUM_CC_UNAPPROVED,$addcode);
} else {
$PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["LIST"];
}
break;
case PHORUM_MOVE_THREAD: // this is the first step of a message move
include_once './include/forum_functions.php';
$message = phorum_db_get_message($msgthd_id);
$PHORUM['DATA']['URL']["ACTION"]=phorum_get_url(PHORUM_MODERATION_ACTION_URL);
$PHORUM['DATA']["FORM"]["forum_id"]=$PHORUM["forum_id"];
$PHORUM['DATA']["FORM"]["thread_id"]=$msgthd_id;
$PHORUM['DATA']["FORM"]["mod_step"]=PHORUM_DO_THREAD_MOVE;
$PHORUM['DATA']["FORM"]["subject"] =htmlspecialchars($message["subject"], ENT_COMPAT, $PHORUM["DATA"]["HCHARSET"]);
// get all the forums the moderator may move to
$PHORUM['DATA']["MoveForumsOption"]="";
// TODO: this does not match the check at the start of the read
// TODO: and list scripts, where we check if this user has perms
// TODO: for moderation of two or more forums, before we
// TODO: enable the move feature. We should either check
// TODO: for 2 or more moderated forums and check that moving
// TODO: is only done between moderated forums or check for
// TODO: 1 or more moderated forums and allow moving between
// TODO: any two forums. Now we have a mix of those two.
// add && phorum_api_user_check_access(PHORUM_USER_ALLOW_MODERATE_MESSAGES, $id) if the
// mod should only be able to move to forums he also moderates
// get the forumlist
$forums=phorum_build_forum_list();
// ignore the current forum
unset($forums[$PHORUM["forum_id"]]);
$PHORUM['DATA']['FORUMS']=$forums;
$PHORUM['DATA']['FRM']=1;
$output=true;
$template="move_form";
break;
case PHORUM_DO_THREAD_MOVE: // this is the last step of a message move
$movetoid=(int)$_POST['moveto'];
// only do something if a forum was selected
if(empty($movetoid)) {
$PHORUM['DATA']['MESSAGE']=$PHORUM["DATA"]['LANG']['MsgMoveSelectForum'];
} else {
$PHORUM['DATA']['OKMSG']=$PHORUM["DATA"]['LANG']['MsgMoveOk'];
$PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["LIST"];
$message = phorum_db_get_message($msgthd_id);
// find out if we have a notification-message already in this
// target-forum for this thread ... it doesn't make sense to keep this
// message any longer as the thread has reappeared on its original location
$temp_forum_id=$PHORUM['forum_id'];
$PHORUM['forum_id']=$movetoid;
$check_messages=phorum_db_get_messages($msgthd_id);
unset($check_messages['users']);
// ok, we found exactly one message of this thread in the target forum
if(is_array($check_messages) && count($check_messages) == 1) {
// ... going to delete it
$tmp_message=array_shift($check_messages);
$retval=phorum_db_delete_message($tmp_message['message_id']);
}
$PHORUM['forum_id']=$temp_forum_id;
// Move the thread to another forum.
phorum_db_move_thread($msgthd_id, $movetoid);
// Create a new message in place of the old one to notify
// visitors that the thread was moved.
if(isset($_POST['create_notification']) && $_POST['create_notification']) {
$newmessage = $message;
$newmessage['body']=" -- moved topic -- ";
$newmessage['moved']=1;
$newmessage['sort']=PHORUM_SORT_DEFAULT;
unset($newmessage['message_id']);
phorum_db_post_message($newmessage);
}
/*
* [hook]
* move_thread
*
* [description]
* This hook can be used for performing actions like sending
* notifications or for making log entries after moving a
* thread.
*
* [category]
* Moderation
*
* [when]
* In <filename>moderation.php</filename>, right after a thread
* has been moved by a moderator.
*
* [input]
* The id of the thread that has been moved (read-only).
*
* [output]
* Same as input.
*
* [example]
* <hookcode>
* function phorum_mod_foo_move_thread($msgthd_id)
* {
* global $PHORUM;
*
* // Log the moved thread id
* $PHORUM["mod_foo"]["moved_threads"][] = $msgthd_id;
* phorum_db_update_settings(array("mod_foo" => $PHORUM["mod_foo"]));
*
* return $msgthd_ids;
* }
* </hookcode>
*/
if (isset($PHORUM["hooks"]["move_thread"]))
phorum_hook("move_thread", $msgthd_id);
foreach ($message['meta']['message_ids'] as $message_id) {
$invalidate_message_cache[] = array(
"message_id" => $message_id,
"forum_id" => $message['forum_id']
);
}
}
break;
case PHORUM_CLOSE_THREAD: // we have to close a thread
$PHORUM['DATA']['OKMSG']=$PHORUM["DATA"]['LANG']['ThreadClosedOk'];
$PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["LIST"];
phorum_db_close_thread($msgthd_id);
/*
* [hook]
* close_thread
*
* [description]
* This hook can be used for performing actions like sending
* notifications or making log entries after closing threads.
*
* [category]
* Moderation
*
* [when]
* In <filename>moderation.php</filename>, right after a thread has
* been closed by a moderator.
*
* [input]
* The id of the thread that has been closed (read-only).
*
* [output]
* Same as input.
*
* [example]
* <hookcode>
* function phorum_mod_foo_close_thread($msgthd_id)
* {
* global $PHORUM;
*
* // Log the closed thread id
* $PHORUM["mod_foo"]["closed_threads"][] = $msgthd_id;
* phorum_db_update_settings(array("mod_foo" => $PHORUM["mod_foo"]));
*
* return $msgthd_ids;
* }
* </hookcode>
*/
if (isset($PHORUM["hooks"]["close_thread"]))
phorum_hook("close_thread", $msgthd_id);
$invalidate_message_cache[] = array(
"message_id" => $msgthd_id,
"forum_id" => $PHORUM["forum_id"]
);
break;
case PHORUM_REOPEN_THREAD: // we have to reopen a thread
$PHORUM['DATA']['OKMSG']=$PHORUM["DATA"]['LANG']['ThreadReopenedOk'];
$PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["LIST"];
phorum_db_reopen_thread($msgthd_id);
/*
* [hook]
* reopen_thread
*
* [description]
* This hook can be used for performing actions like sending
* notifications or making log entries after reopening threads.
*
* [category]
* Moderation
*
* [when]
* In <filename>moderation.php</filename>, right after a thread has
* been reopened by a moderator.
*
* [input]
* The id of the thread that has been reopened (read-only).
*
* [output]
* Same as input.
*
* [example]
* <hookcode>
* function phorum_mod_foo_reopen_thread($msgthd_id)
* {
* global $PHORUM;
*
* // Log the reopened thread id
* $PHORUM["mod_foo"]["reopened_threads"][] = $msgthd_id;
* phorum_db_update_settings(array("mod_foo" => $PHORUM["mod_foo"]));
*
* return $msgthd_id;
* }
* </hookcode>
*/
if (isset($PHORUM["hooks"]["reopen_thread"]))
phorum_hook("reopen_thread", $msgthd_id);
$invalidate_message_cache[] = array(
"message_id" => $msgthd_id,
"forum_id" => $PHORUM["forum_id"]
);
break;
case PHORUM_APPROVE_MESSAGE: // approving a message
$PHORUM['DATA']['OKMSG']="1 ".$PHORUM["DATA"]['LANG']['MsgApprovedOk'];
$old_message = phorum_db_get_message($msgthd_id);
$newpost=array("status"=>PHORUM_STATUS_APPROVED);
// setting the new status
phorum_db_update_message($msgthd_id, $newpost);
// updating the thread-info
phorum_update_thread_info($old_message['thread']);
// updating the forum-stats
phorum_db_update_forum_stats(false, 1, $old_message["datestamp"]);
/*
* [hook]
* after_approve
*
* [description]
* This hook can be used for performing extra actions after a
* message has been approved.
*
* [category]
* Moderation
*
* [when]
* In <filename>moderation.php</filename>, right approving a message
* and possibly its replies.
*
* [input]
* An array containing two elements:
* <ul>
* <li>The message data</li>
* <li>The type of approval (either
* <literal>PHORUM_APPROVE_MESSAGE</literal> or
* <literal>PHORUM_APPROVE_MESSAGE_TREE</literal>)</li>
* </ul>
*
* [output]
* Same as input.
*
* [example]
* <hookcode>
* function phorum_mod_foo_after_approve($data)
* {
* global $PHORUM;
*
* // alert the message author that their message has been
* // approved
* $pm_message = preg_replace(
* "%message_subject%",
* $data[0]["subject"],
* $PHORUM["DATA"]["LANG"]["mod_foo"]["MessageApprovedBody"]
* );
* phorum_db_pm_send(
* $PHORUM["DATA"]["LANG"]["mod_foo"]["MessageApprovedSubject"],
* $pm_message,
* $data[0]["user_id"]
* );
*
* return $data;
*
* }
* </hookcode>
*/
if (isset($PHORUM["hooks"]["after_approve"]))
phorum_hook("after_approve", array($old_message, PHORUM_APPROVE_MESSAGE));
if($old_message['status'] != PHORUM_STATUS_HIDDEN ) {
phorum_email_notice($old_message);
}
if(isset($PHORUM['args']['old_forum']) && is_numeric($PHORUM['args']['old_forum'])) {
$PHORUM['forum_id']=(int)$PHORUM['args']['old_forum'];
}
if(isset($PHORUM['args']["prepost"])) {
// add some additional args
$addcode = "";
if(isset($PHORUM['args']['moddays']) && is_numeric($PHORUM['args']['moddays'])) {
$addcode.="moddays=".$PHORUM['args']['moddays'];
}
if(isset($PHORUM['args']['onlyunapproved']) && is_numeric($PHORUM['args']['onlyunapproved'])) {
if(!empty($addcode))
$addcode.=",";
$addcode.="onlyunapproved=".$PHORUM['args']['onlyunapproved'];
}
$PHORUM['DATA']["URL"]["REDIRECT"]=phorum_get_url(PHORUM_CONTROLCENTER_URL,"panel=".PHORUM_CC_UNAPPROVED,$addcode);
} else {
$PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["LIST"];
}
$invalidate_message_cache[] = array(
"message_id" => $msgthd_id,
"forum_id" => $PHORUM["forum_id"]
);
break;
case PHORUM_APPROVE_MESSAGE_TREE: // approve a message and all answers to it
$old_message = phorum_db_get_message($msgthd_id);
$newpost=array("status"=>PHORUM_STATUS_APPROVED);
$mids = phorum_db_get_messagetree($msgthd_id, $old_message["forum_id"]);
// make an array from the string
$mids_arr=explode(",",$mids);
// count the entries for later use
$num_approved=count($mids_arr);
foreach($mids_arr as $key => $mid) {
// setting the new status
phorum_db_update_message($mid, $newpost);
$invalidate_message_cache[] = array(
"message_id" => $mid,
"forum_id" => $PHORUM["forum_id"]
);
}
// updating the thread-info
phorum_update_thread_info($old_message['thread']);
// updating the forum-stats
phorum_db_update_forum_stats(false, "+$num_approved", $old_message["datestamp"]);
if (isset($PHORUM["hooks"]["after_approve"]))
phorum_hook("after_approve", array($old_message, PHORUM_APPROVE_MESSAGE_TREE));
$PHORUM['DATA']['OKMSG']="$num_approved ".$PHORUM['DATA']['LANG']['MsgApprovedOk'];
if(isset($PHORUM['args']["prepost"])) {
// add some additional args
$addcode = "";
if(isset($PHORUM['args']['moddays']) && is_numeric($PHORUM['args']['moddays'])) {
$addcode.="moddays=".$PHORUM['args']['moddays'];
}
if(isset($PHORUM['args']['onlyunapproved']) && is_numeric($PHORUM['args']['onlyunapproved'])) {
if(!empty($addcode))
$addcode.=",";
$addcode.="onlyunapproved=".$PHORUM['args']['onlyunapproved'];
}
$PHORUM['DATA']["URL"]["REDIRECT"]=phorum_get_url(PHORUM_CONTROLCENTER_URL,"panel=".PHORUM_CC_UNAPPROVED,$addcode);
} else {
$PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["LIST"];
}
break;
case PHORUM_HIDE_POST: // hiding a message (and its replies)
$old_message = phorum_db_get_message($msgthd_id);
$newpost=array("status"=>PHORUM_STATUS_HIDDEN);
$mids = phorum_db_get_messagetree($msgthd_id, $old_message["forum_id"]);
// make an array from the string
$mids_arr=explode(",",$mids);
// count the entries for later use
$num_hidden=count($mids_arr);
foreach($mids_arr as $key => $mid) {
// setting the new status
phorum_db_update_message($mid, $newpost);
}
/*
* [hook]
* hide_thread
*
* [description]
* This hook can be used for performing actions like sending
* notifications or making log entries after hiding a message.
*
* [category]
* Moderation
*
* [when]
* In <filename>moderation.php</filename>, right after a message has
* been hidden by a moderator.
*
* [input]
* The id of the thread that has been hidden (read-only).
*
* [output]
* Same as input.
*
* [example]
* <hookcode>
* function phorum_mod_foo_hide_thread($msgthd_id)
* {
* global $PHORUM;
*
* // Log the hidden thread id
* $PHORUM["mod_foo"]["hidden_threads"][] = $msgthd_id;
* phorum_db_update_settings(array("mod_foo" => $PHORUM["mod_foo"]));
*
* return $msgthd_id;
* }
* </hookcode>
*/
if (isset($PHORUM["hooks"]["hide_thread"]))
phorum_hook("hide_thread", $msgthd_id);
// updating the thread-info
phorum_update_thread_info($old_message['thread']);
// updating the forum-stats
phorum_db_update_forum_stats(false, "-$num_hidden");
$PHORUM['DATA']['OKMSG']="$num_hidden ".$PHORUM['DATA']['LANG']['MsgHiddenOk'];
if(isset($PHORUM['args']["prepost"])) {
$PHORUM['DATA']["URL"]["REDIRECT"]=phorum_get_url(PHORUM_CONTROLCENTER_URL,"panel=".PHORUM_CC_UNAPPROVED);
} else {
$PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["LIST"];
}
break;
case PHORUM_MERGE_THREAD: // this is the first step of a thread merge
$template="merge_form";
$PHORUM['DATA']['URL']["ACTION"] = phorum_get_url(PHORUM_MODERATION_ACTION_URL);
$PHORUM['DATA']["FORM"]["forum_id"] = $PHORUM["forum_id"];
$PHORUM['DATA']["FORM"]["thread_id"] = $msgthd_id;
$PHORUM['DATA']["FORM"]["mod_step"] = PHORUM_DO_THREAD_MERGE;
// the moderator selects the target thread to merge to
$merge_t1 = phorum_moderator_data_get('merge_t1');
if( !$merge_t1 || $merge_t1==$msgthd_id ) {
phorum_moderator_data_put('merge_t1', $msgthd_id);
$PHORUM['DATA']["FORM"]["merge_none"] =true;
$message = phorum_db_get_message($msgthd_id, "message_id", true);
$PHORUM['DATA']["FORM"]["merge_subject1"] =htmlspecialchars($message["subject"], ENT_COMPAT, $PHORUM["DATA"]["HCHARSET"]);
}
// the moderator selects the source thread to merge from
else {
$PHORUM['DATA']["FORM"]["merge_t1"] =$merge_t1;
$message = phorum_db_get_message($merge_t1, "message_id", true);
$PHORUM['DATA']["FORM"]["merge_subject1"] =htmlspecialchars($message["subject"], ENT_COMPAT, $PHORUM["DATA"]["HCHARSET"]);
$message = phorum_db_get_message($msgthd_id);
$PHORUM['DATA']["FORM"]["thread_subject"] =htmlspecialchars($message["subject"], ENT_COMPAT, $PHORUM["DATA"]["HCHARSET"]);
}
break;
case PHORUM_DO_THREAD_MERGE: // this is the last step of a thread merge
if( isset($_POST['thread1']) && $_POST['thread1']) {
// Commit Thread Merge
settype($_POST['thread1'], "int");
settype($_POST['thread'], "int"); // Thread 2
$PHORUM['DATA']['OKMSG'] = $PHORUM["DATA"]['LANG']['MsgMergeOk'];
$PHORUM['DATA']["URL"]["REDIRECT"] = $PHORUM["DATA"]["URL"]["LIST"];
$PHORUM["reverse_threading"] = 0;
// Get the target thread.
$target =phorum_db_get_message($_POST['thread1'], "message_id", true);
if (!$target) trigger_error(
"Can't retrieve target thread " . $_POST['thread1'],
E_USER_ERROR
);
// Get all messages from the thread that we have to merge.
$merge_messages=phorum_db_get_messages($_POST['thread']);
unset($merge_messages['users']);
// Create new messages in the target thread for
// all messages that have to be merged.
$msgid_translation=array();
foreach($merge_messages as $msg)
{
$oldid=$msg['message_id'];
$msg['thread'] = $target['thread']; // the thread we merge with
$msg['forum_id'] = $target['forum_id']; // the forum_id of the new thread
$msg['sort'] = $target['sort']; // the sort type of the new thread
if($msg['message_id'] == $msg['thread']) {
$msg['parent_id']=$target['thread'];
} elseif(isset($msgid_translation[$msg['parent_id']])) {
$msg['parent_id']=$msgid_translation[$msg['parent_id']];
} else {
$msg['parent_id']=$msg['thread'];
}
unset($msg['message_id']);
unset($msg['modifystamp']);
phorum_db_post_message($msg,true);
// Link attached files to the new message id.
$linked_files = phorum_db_get_message_file_list($oldid);
foreach ($linked_files as $linked_file) {
phorum_db_file_link($linked_file["file_id"], $msg["message_id"], PHORUM_LINK_MESSAGE);
}
// save the new message-id for later use
$msgid_translation[$oldid]=$msg['message_id'];
}
// deleting messages which are now doubled
phorum_db_delete_message($_POST['thread'], PHORUM_DELETE_TREE);
// update message count / stats
phorum_db_update_forum_stats(true);
// change forum_id for the following calls to update the right forum
$PHORUM["forum_id"] =$target['forum_id'];
// update message count / stats
phorum_update_thread_info($target['thread']);
phorum_db_update_forum_stats(true);
/*
* [hook]
* after_merge
*
* [description]
* This hook can be used for performing actions on
* merging threads
*
* [category]
* Moderation
*
* [when]
* In <filename>moderation.php</filename>, right after two threads have
* been merged by a moderator.
*
* [input]
* An array with the translated message-ids; old-message_id -> new-message_id
*
* [output]
* Same as input.
*/
phorum_hook('after_merge', $msgid_translation);
} else {
// Cancel Thread Merge
$PHORUM['DATA']['OKMSG']=$PHORUM["DATA"]['LANG']['MsgMergeCancel'];
$PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["LIST"];
}
// unset temporary moderator_data
phorum_moderator_data_remove('merge_t1');
break;
case PHORUM_SPLIT_THREAD: // this is the first step of a thread split
$PHORUM['DATA']['URL']["ACTION"]=phorum_get_url(PHORUM_MODERATION_ACTION_URL);
$PHORUM['DATA']["FORM"]["forum_id"]=$PHORUM["forum_id"];
$message =phorum_db_get_message($msgthd_id);
$PHORUM['DATA']["FORM"]["thread_id"]=$message["thread"];
$PHORUM['DATA']["FORM"]["message_id"]=$msgthd_id;
$PHORUM['DATA']["FORM"]["message_subject"]=htmlspecialchars($message["subject"], ENT_COMPAT, $PHORUM["DATA"]["HCHARSET"]);
$PHORUM['DATA']["FORM"]["mod_step"]=PHORUM_DO_THREAD_SPLIT;
$template="split_form";
break;
case PHORUM_DO_THREAD_SPLIT: // this is the last step of a thread split
$PHORUM['DATA']['OKMSG']=$PHORUM["DATA"]['LANG']['MsgSplitOk'];
$PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["LIST"];
settype($_POST['forum_id'], "int");
settype($_POST['message'], "int");