forked from Phorum/Core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon.php
2400 lines (2156 loc) · 84.1 KB
/
common.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. //
// //
////////////////////////////////////////////////////////////////////////////////
// Check that this file is not loaded directly.
if ( basename( __FILE__ ) == basename( $_SERVER["PHP_SELF"] ) ) exit;
// ----------------------------------------------------------------------
// Initialize variables and constants and load required libraries
// ----------------------------------------------------------------------
// the Phorum version
define( "PHORUM", "5.2.23" );
// our database schema version in format of year-month-day-serial
define( "PHORUM_SCHEMA_VERSION", "2010101500" );
// our database patch level in format of year-month-day-serial
define( "PHORUM_SCHEMA_PATCHLEVEL", "2016101000" );
// Initialize the global $PHORUM variable, which holds all Phorum data.
global $PHORUM;
$PHORUM = array
(
// The DATA member holds the template variables.
'DATA' => array(
'GET_VARS' => array(),
'POST_VARS' => ''
),
// The TMP member hold template {DEFINE ..} definitions, temporary
// arrays and such in template code.
'TMP' => array(),
// Query arguments.
'args' => array(),
// The active forum id.
'forum_id' => 0
);
// Load all constants from ./include/constants.php
require_once( "./include/constants.php" );
// Load the API code that is required for all pages.
require_once("./include/api/base.php");
require_once("./include/api/user.php");
// PHP 5.x fallback for random_bytes and random_int functions.
//
// Thanks to Paragon Initiative Enterprises for the implementation of his
// Random_* Compatibility Library. See: https://github.com/paragonie/random_compat
if (!function_exists('random_int') || !function_exists('random_bytes'))
{
require_once('./include/random_compat-2.0.2/lib/random.php');
}
// ----------------------------------------------------------------------
// Load the database layer and setup a connection
// ----------------------------------------------------------------------
// Get the database settings. It is possible to override the database
// settings by defining a global variable $PHORUM_ALT_DBCONFIG which
// overrides $PHORUM["DBCONFIG"] (from include/db/config.php). This is
// only allowed if "PHORUM_WRAPPER" is defined and if the alternative
// configuration wasn't passed as a request parameter (which could
// set $PHORUM_ALT_DBCONFIG if register_globals is enabled for PHP).
if (empty( $GLOBALS["PHORUM_ALT_DBCONFIG"] ) || $GLOBALS["PHORUM_ALT_DBCONFIG"]==$_REQUEST["PHORUM_ALT_DBCONFIG"] || !defined("PHORUM_WRAPPER")) {
// Backup display_errors setting.
$orig = ini_get("display_errors");
@ini_set("display_errors", 0);
// Use output buffering so we don't get header errors if there's
// some additional output in the database config file (e.g. a UTF-8
// byte order marker).
ob_start();
// Load configuration.
if (! include_once( "./include/db/config.php" )) {
print '<html><head><title>Phorum error</title></head><body>';
print '<h2>Phorum database configuration error</h2>';
// No database configuration found.
if (!file_exists("./include/db/config.php")) { ?>
Phorum has been installed on this server, but the configuration<br />
for the database connection has not yet been made. Please read<br />
<a href="docs/install.txt">docs/install.txt</a> for installation
instructions. <?php
} else {
$fp = fopen("./include/db/config.php", "r");
// Unable to read the configuration file.
if (!$fp) { ?>
A database configuration file was found in
./include/db/config.php,<br />but Phorum was unable to read it.
Please check the file permissions<br />for this file. <?php
// Unknown error.
} else {
fclose($fp); ?>
A database configuration file was found in
./include/dbconfig.php,<br />but it could not be loaded.
It possibly contains one or more errors.<br />Please check
your configuration file. <?php
}
}
print '</body></html>';
exit(1);
}
// Clean up the output buffer.
ob_end_clean();
// Restore original display_errors setting.
@ini_set("display_errors", $orig);
} else {
$PHORUM["DBCONFIG"] = $GLOBALS["PHORUM_ALT_DBCONFIG"];
}
// Backward compatbility: the "mysqli" layer was merged with the "mysql"
// layer, but people might still be using "mysqli" as their configured
// database type.
if ($PHORUM["DBCONFIG"]["type"] == "mysqli" &&
!file_exists("./include/db/mysqli.php")) {
$PHORUM["DBCONFIG"]["type"] = "mysql";
}
// Load the database layer.
$PHORUM['DBCONFIG']['type'] = basename($PHORUM['DBCONFIG']['type']);
require_once( "./include/db/{$PHORUM['DBCONFIG']['type']}.php" );
// Try to setup a connection to the database.
if(!phorum_db_check_connection()){
if(isset($PHORUM["DBCONFIG"]["down_page"])){
phorum_redirect_by_url($PHORUM["DBCONFIG"]["down_page"]);
exit;
} else {
header('HTTP/1.1 500 Internal Server Error');
echo "The database connection failed. Please check your database configuration in include/db/config.php. If the configuration is okay, check if the database server is running.";
exit;
}
}
// ----------------------------------------------------------------------
// Load and process the Phorum settings
// ----------------------------------------------------------------------
// Load the Phorum settings from the database.
phorum_db_load_settings();
// checking for upgrade or new install
if (!defined('PHORUM_ADMIN')) {
if (!isset($PHORUM['internal_version']))
{
echo "<html><head><title>Phorum error</title></head><body>No Phorum settings were found. Either this is a brand new installation of Phorum or there is a problem with your database server. If this is a new install, please <a href=\"admin.php\">go to the admin page</a> to complete the installation. If not, check your database server.</body></html>";
exit;
} elseif ($PHORUM['internal_version'] < PHORUM_SCHEMA_VERSION ||
!isset($PHORUM['internal_patchlevel']) ||
$PHORUM['internal_patchlevel'] < PHORUM_SCHEMA_PATCHLEVEL) {
if (isset($PHORUM["DBCONFIG"]["upgrade_page"])) {
phorum_redirect_by_url($PHORUM["DBCONFIG"]["upgrade_page"]);
exit;
}
echo "<html><head><title>Upgrade notification</title></head><body>It looks like you have installed a new version of Phorum.<br />Please visit the admin page to complete the upgrade!</body></html>";
exit;
}
}
// For command line scripts, disable caching.
// The command line user is often different from the web server
// user, possibly causing permission problems on the cache.
if (defined('PHORUM_SCRIPT'))
{
$PHORUM['cache_banlists'] = 0;
$PHORUM['cache_css'] = 0;
$PHORUM['cache_javascript'] = 0;
$PHORUM['cache_layer'] = 0;
$PHORUM['cache_messages'] = 0;
$PHORUM['cache_newflags'] = 0;
$PHORUM['cache_rss'] = 0;
$PHORUM['cache_users'] = 0;
}
// If we have no private key for signing data, generate one now,
// but only if it's not a fresh install.
if ( isset($PHORUM['internal_version']) && $PHORUM['internal_version'] >= PHORUM_SCHEMA_VERSION && (!isset($PHORUM["private_key"]) || empty($PHORUM["private_key"]))) {
$chars = "0123456789!@#$%&abcdefghijklmnopqr".
"stuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$private_key = "";
for ($i = 0; $i<40; $i++) {
$private_key .= substr($chars, random_int(0, strlen($chars)-1), 1);
}
$PHORUM["private_key"] = $private_key;
phorum_db_update_settings(array("private_key" => $PHORUM["private_key"]));
}
// Determine the caching layer to load.
if(!isset($PHORUM['cache_layer']) || empty($PHORUM['cache_layer'])) {
$PHORUM['cache_layer'] = 'file';
} else {
// Safeguard for wrongly selected cache-layers.
// Falling back to file-layer if descriptive functions aren't existing.
if($PHORUM['cache_layer'] == 'memcached' && !function_exists('memcache_connect')) {
$PHORUM['cache_layer'] = 'file';
} elseif($PHORUM['cache_layer'] == 'apc' && !function_exists('apc_fetch')) {
$PHORUM['cache_layer'] = 'file';
}
}
// Load the caching-layer. You can specify a different one in the settings.
// One caching layer *needs* to be loaded.
$PHORUM['cache_layer'] = basename($PHORUM['cache_layer']);
require_once( "./include/cache/$PHORUM[cache_layer].php" );
// Load phorum_get_url().
// This function is used for generating all Phorum URLs.
require_once("./include/phorum_get_url.php");
// Setup the template path and http path. These are put in a variable to give
// module authors a chance to override them. This can be especially useful
// for distibuting a module that contains a full Phorum template as well.
// For switching, the function phorum_switch_template() can be used.
$PHORUM['template_path'] = './templates';
$PHORUM['template_http_path'] = $PHORUM['http_path'].'/templates';
// ----------------------------------------------------------------------
// Parse and handle request data
// ----------------------------------------------------------------------
// Thanks a lot for magic quotes :-/
// In PHP7, magic quotes are (finally) removed, so we have to check for
// the get_magic_quotes_gpc() function here. The "@" is for suppressing
// deprecation warnings that are spawned by PHP 5.3 and higher when
// using the get_magic_quotes_gpc() function.
if ( function_exists('get_magic_quotes_gpc') &&
@get_magic_quotes_gpc() && count( $_REQUEST ) ) {
foreach( $_POST as $key => $value ) {
if ( !is_array( $value ) )
$_POST[$key] = stripslashes( $value );
else
$_POST[$key] = phorum_recursive_stripslashes( $value );
}
foreach( $_GET as $key => $value ) {
if ( !is_array( $value ) )
$_GET[$key] = stripslashes( $value );
else
$_GET[$key] = phorum_recursive_stripslashes( $value );
}
}
// Also make sure that magic_quotes_runtime is disabled.
if (function_exists('set_magic_quotes_runtime')) {
@set_magic_quotes_runtime(FALSE);
}
// Thanks a lot for configurable argument separators :-/
// In some cases we compose GET based URLs, with & and = as respectively
// argument and key/value separators. On some systems, the "&" character
// is not configured as a valid separator. For those systems, we have
// to parse the query string ourselves.
if (isset($_SERVER['QUERY_STRING']) &&
strpos($_SERVER['QUERY_STRING'], '&') !== FALSE)
{
$separator = get_cfg_var('arg_separator.input');
if ($separator !== FALSE && strpos($separator, '&') === FALSE)
{
$parts = explode('&', $_SERVER['QUERY_STRING']);
$_GET = array();
foreach ($parts as $part)
{
list ($key, $val) = explode('=', rawurldecode($part), 2);
// Handle array[] style GET arguments.
if (preg_match('/^(.+)\[(.*)\]$/', $key, $m))
{
if (!isset($_GET[$m[1]]) || !is_array($_GET[$m[1]])) {
$_GET[$m[1]] = array();
}
if ($m[2] == '') {
$_GET[$m[1]][] = $val;
} else {
$_GET[$m[1]][$m[2]] = $val;
}
}
// Handle standard GET arguments.
else
{
$_GET[$key] = $val;
$_REQUEST[$key] = $val;
}
}
}
}
/*
* [hook]
* parse_request
*
* [description]
* This hook gives modules a chance to tweak the request environment,
* before Phorum parses and handles the request data. For tweaking the
* request environment, some of the options are:
* <ul>
* <li>
* Changing the value of <literal>$_REQUEST["forum_id"]</literal>
* to override the used forum_id.
* </li>
* <li>
* Changing the value of <literal>$_SERVER["QUERY_STRING"]</literal>
* or setting the global override variable
* <literal>$PHORUM_CUSTOM_QUERY_STRING</literal> to feed Phorum a
* different query string than the one provided by the webserver.
* </li>
* </ul>
* Tweaking the request data should result in data that Phorum can handle.
*
* [category]
* Request initialization
*
* [when]
* Right before Phorum runs the request parsing code in
* <filename>common.php</filename>.
*
* [input]
* No input.
*
* [output]
* No output.
*
* [example]
* <hookcode>
* function phorum_mod_foo_parse_request()
* {
* // Override the query string.
* global $PHORUM_CUSTOM_QUERY_STRING
* $PHORUM_CUSTOM_QUERY_STRING = "1,some,phorum,query=string";
*
* // Override the forum_id.
* $_SERVER['forum_id'] = "1234";
* }
* </hookcode>
*/
if (isset($PHORUM["hooks"]["parse_request"])) {
phorum_hook("parse_request");
}
// Get the forum id if set using a request parameter.
if ( isset( $_REQUEST["forum_id"] ) && is_numeric( $_REQUEST["forum_id"] ) ) {
$PHORUM["forum_id"] = $_REQUEST["forum_id"];
}
// Look for and parse the QUERY_STRING.
// This only applies to URLs that we create using phorum_get_url().
// Scripts using data originating from standard HTML forms (e.g. search)
// will have to use $_GET or $_POST.
if (!defined("PHORUM_ADMIN") && (isset($_SERVER["QUERY_STRING"]) || isset($GLOBALS["PHORUM_CUSTOM_QUERY_STRING"]))) {
$Q_STR = empty( $GLOBALS["PHORUM_CUSTOM_QUERY_STRING"] )
? $_SERVER["QUERY_STRING"]
: $GLOBALS["PHORUM_CUSTOM_QUERY_STRING"];
if(strpos($Q_STR, "&")!==false){
$PHORUM["args"] = $_GET;
} else {
// ignore stuff past a #
if ( strstr( $Q_STR, "#" ) ) list( $Q_STR, $other ) = explode( "#", $Q_STR, 2 );
// explode it on comma
$PHORUM["args"] = $Q_STR == '' ? array() : explode( ",", $Q_STR );
// check for any assigned values
if ( strstr( $Q_STR, "=" ) ) {
foreach( $PHORUM["args"] as $key => $arg ) {
// if an arg has an = create an element in args
// with left part as key and right part as value
if ( strstr( $arg, "=" ) ) {
list( $var, $value ) = explode( "=", $arg, 2 );
// get rid of the numbered arg, it is useless.
unset( $PHORUM["args"][$key] );
// add the named arg
// TODO: Why is urldecode() used here? IMO this can be omitted.
$PHORUM["args"][$var] = urldecode( $value );
}
}
}
}
// Handle path info based URLs for the file script.
if (phorum_page == 'file' &&
!empty($_SERVER['PATH_INFO']) &&
preg_match('!^/(download/)?(\d+)/(\d+)/!', $_SERVER['PATH_INFO'], $m))
{
$PHORUM['args']['file'] = $m[3];
$PHORUM['args'][0] = $PHORUM['forum_id'] = $m[2];
$PHORUM['args']['download'] = empty($m[1]) ? 0 : 1;
}
// set forum_id if not set already by a forum_id request parameter
if ( empty( $PHORUM["forum_id"] ) && isset( $PHORUM["args"][0] ) ) {
$PHORUM["forum_id"] = ( int )$PHORUM["args"][0];
}
}
// set the forum_id to 0 if not set by now.
if ( empty( $PHORUM["forum_id"] ) ) $PHORUM["forum_id"] = 0;
/*
* [hook]
* common_pre
*
* [description]
* This hook can be used for overriding settings that were loaded and
* setup at the start of the <filename>common.php</filename> script.
* If you want to dynamically assign and tweak certain settings, then
* this is the designated hook to use for that.<sbr/>
* <sbr/>
* Because the hook was put after the request parsing phase, you can
* make use of the request data that is stored in the global variables
* <literal>$PHORUM['forum_id']</literal> and
* <literal>$PHORUM['args']</literal>.
*
* [category]
* Request initialization
*
* [when]
* Right after loading the settings from the database and parsing the
* request, but before making descisions on user, language and template.
*
* [input]
* No input.
*
* [output]
* No output.
*
* [example]
* <hookcode>
* function phorum_mod_foo_common_pre()
* {
* global $PHORUM;
*
* // If we are in the forum with id = 10, we set the administrator
* // email information to a different value than the one configured
* // in the general settings.
* if ($PHORUM["forum_id"] == 10)
* {
* $PHORUM["system_email_from_name"] = "John Doe";
* $PHORUM["system_email_from_address"] = "[email protected]";
* }
* }
* </hookcode>
*/
if (isset($PHORUM["hooks"]["common_pre"])) {
phorum_hook("common_pre", "");
}
// ----------------------------------------------------------------------
// Setup data for standard (not admin) pages
// ----------------------------------------------------------------------
// TODO: Do we ever need this in admin? If not, it can go inside the block.
// stick some stuff from the settings into the DATA member
$PHORUM["DATA"]["TITLE"] = ( isset( $PHORUM["title"] ) ) ? $PHORUM["title"] : "";
$PHORUM["DATA"]["DESCRIPTION"] = ( isset( $PHORUM["description"] ) ) ? $PHORUM["description"] : "";
$PHORUM["DATA"]["HTML_TITLE"] = ( !empty( $PHORUM["html_title"] ) ) ? $PHORUM["html_title"] : $PHORUM["DATA"]["TITLE"];
$PHORUM["DATA"]["HEAD_TAGS"] = ( isset( $PHORUM["head_tags"] ) ) ? $PHORUM["head_tags"] : "";
$PHORUM["DATA"]["FORUM_ID"] = $PHORUM["forum_id"];
if ( !defined( "PHORUM_ADMIN" ) ) {
// if the Phorum is disabled, display a message.
if(isset($PHORUM["status"]) && $PHORUM["status"]==PHORUM_MASTER_STATUS_DISABLED){
if(!empty($PHORUM["disabled_url"])){
header("Location: ".$PHORUM["disabled_url"]);
exit;
} else {
echo "This Phorum is currently disabled. Please contact the web site owner at ".$PHORUM['system_email_from_address']." for more information.\n";
exit;
}
}
// load the forum's settings
if(!empty($PHORUM["forum_id"])){
$forum_settings = phorum_db_get_forums( $PHORUM["forum_id"] );
if ( !isset($forum_settings[$PHORUM["forum_id"]]) )
{
/*
* [hook]
* common_no_forum
*
* [description]
* This hook is called in case a forum_id is requested for
* an unknown or inaccessible forum. It can be used for
* doing things like logging the bad requests or fully
* overriding Phorum's default behavior for these cases
* (which is redirecting the user back to the index page).
*
* [category]
* Request initialization
*
* [when]
* In <filename>common.php</filename>, right after detecting
* that a requested forum does not exist or is inaccessible
* and right before redirecting the user back to the Phorum
* index page.
*
* [input]
* No input.
*
* [output]
* No output.
*
* [example]
* <hookcode>
* function phorum_mod_foo_common_no_forum()
* {
* // Return a 404 Not found error instead of redirecting
* // the user back to the index.
* header("HTTP/1.0 404 Not Found");
* print "<html><head>\n";
* print " <title>404 - Not Found</title>\n";
* print "</head><body>";
* print " <h1>404 - Forum Not Found</h1>";
* print "</body></html>";
* exit;
* }
* </hookcode>
*/
if (isset($PHORUM["hooks"]["common_no_forum"])) {
phorum_hook("common_no_forum", "");
}
phorum_redirect_by_url( phorum_get_url( PHORUM_INDEX_URL ) );
exit;
}
$PHORUM = array_merge( $PHORUM, $forum_settings[$PHORUM["forum_id"]] );
} elseif(isset($PHORUM["forum_id"]) && $PHORUM["forum_id"]==0){
$PHORUM = array_merge( $PHORUM, $PHORUM["default_forum_options"] );
// some hard settings are needed if we are looking at forum_id 0
$PHORUM['vroot']=0;
$PHORUM['parent_id']=0;
$PHORUM['active']=1;
$PHORUM['folder_flag']=1;
$PHORUM['cache_version']=0;
}
// handling vroots
if(!empty($PHORUM['vroot'])) {
$vroot_folders = phorum_db_get_forums($PHORUM['vroot']);
$PHORUM["title"] = $vroot_folders[$PHORUM['vroot']]['name'];
$PHORUM["DATA"]["TITLE"] = $PHORUM["title"];
$PHORUM["DATA"]["HTML_TITLE"] = $PHORUM["title"];
if($PHORUM['vroot'] == $PHORUM['forum_id']) {
// unset the forum-name if we are in the vroot-index
// otherwise the NAME and TITLE would be the same and still shown twice
unset($PHORUM['name']);
}
}
// stick some stuff from the settings into the DATA member
$PHORUM["DATA"]["NAME"] = ( isset( $PHORUM["name"] ) ) ? $PHORUM["name"] : "";
$PHORUM["DATA"]["HTML_DESCRIPTION"] = ( isset( $PHORUM["description"] ) ) ? preg_replace("!\s+!", " ", $PHORUM["description"]) : "";
$PHORUM["DATA"]["DESCRIPTION"] = strip_tags($PHORUM["DATA"]["HTML_DESCRIPTION"]);
// clean up some more stuff in the description without html
$search_arr = array('\'','"');
$replace_arr = array('','');
$PHORUM["DATA"]["DESCRIPTION"]=str_replace($search_arr,$replace_arr,$PHORUM["DATA"]["DESCRIPTION"]);
$PHORUM["DATA"]["ENABLE_PM"] = ( isset( $PHORUM["enable_pm"] ) ) ? $PHORUM["enable_pm"] : "";
if ( !empty( $PHORUM["DATA"]["HTML_TITLE"] ) && !empty( $PHORUM["DATA"]["NAME"] ) ) {
$PHORUM["DATA"]["HTML_TITLE"] .= PHORUM_SEPARATOR;
}
$PHORUM["DATA"]["HTML_TITLE"] .= $PHORUM["DATA"]["NAME"];
// Try to restore a user session.
if (phorum_api_user_session_restore(PHORUM_FORUM_SESSION))
{
// if the user has overridden thread settings, change it here.
if ( !isset( $PHORUM['display_fixed'] ) || !$PHORUM['display_fixed'] ) {
if ( $PHORUM["user"]["threaded_list"] == PHORUM_THREADED_ON ) {
$PHORUM["threaded_list"] = true;
} elseif ( $PHORUM["user"]["threaded_list"] == PHORUM_THREADED_OFF ) {
$PHORUM["threaded_list"] = false;
}
if ( $PHORUM["user"]["threaded_read"] == PHORUM_THREADED_ON ) {
$PHORUM["threaded_read"] = 1;
} elseif ( $PHORUM["user"]["threaded_read"] == PHORUM_THREADED_OFF ) {
$PHORUM["threaded_read"] = 0;
} elseif ( $PHORUM["user"]["threaded_read"] == PHORUM_THREADED_HYBRID ) {
$PHORUM["threaded_read"] = 2;
}
}
// check if the user has new private messages
if (!empty($PHORUM["enable_new_pm_count"]) &&
!empty($PHORUM["enable_pm"])) {
$PHORUM['user']['new_private_messages'] =
phorum_db_pm_checknew($PHORUM['user']['user_id']);
}
}
/*
* [hook]
* common_post_user
*
* [description]
* This hook gives modules a chance to override Phorum variables
* and settings, after the active user has been loaded. The settings
* for the active forum are also loaded before this hook is called,
* therefore this hook can be used for overriding general settings,
* forum settings and user settings.
*
* [category]
* Request initialization
*
* [when]
* Right after loading the data for the active user in
* <filename>common.php</filename>, but before deciding on the
* language and template to use.
*
* [input]
* No input.
*
* [output]
* No output.
*
* [example]
* <hookcode>
* function phorum_mod_foo_common_post_user()
* {
* global $PHORUM;
*
* // Switch the read mode for admin users to threaded.
* if ($PHORUM['user']['user_id'] && $PHORUM['user']['admin']) {
* $PHORUM['threaded_read'] = PHORUM_THREADED_ON;
* }
*
* // Disable "float_to_top" for anonymous users.
* if (!$PHORUM['user']['user_id']) {
* $PHORUM['float_to_top'] = 0;
* }
* }
* </hookcode>
*/
if (isset($PHORUM["hooks"]["common_post_user"])) {
phorum_hook("common_post_user", "");
}
// only do those parts if the forum is not set to fixed view
if ( !isset( $PHORUM['display_fixed'] ) || !$PHORUM['display_fixed'] ) {
// check for a template being passed on the url
// only use valid template names
if(!empty( $PHORUM["args"]["template"] ) ) {
$template = basename( $PHORUM["args"]["template"] );
if ($template != '..') {
$PHORUM["template"] = $template;
$PHORUM['DATA']['GET_VARS'][]="template=".urlencode($template);
$PHORUM['DATA']['POST_VARS'].="<input type=\"hidden\" name=\"template\" value=\"".htmlspecialchars($template)."\" />\n";
}
}
// get the language file
if(isset( $PHORUM['user']['user_language'] ) && !empty($PHORUM['user']['user_language']) ) {
$PHORUM['language'] = $PHORUM['user']['user_language'];
}
if( isset( $PHORUM['user']['user_template'] ) && !empty($PHORUM['user']['user_template']) &&
(!isset( $PHORUM["user_template"] ) || !empty($PHORUM['user_template']))
) {
$PHORUM['template'] = $PHORUM['user']['user_template'];
}
}
if ( !isset( $PHORUM["language"] ) || empty( $PHORUM["language"] ) || !file_exists( "./include/lang/$PHORUM[language].php" ) )
$PHORUM["language"] = $PHORUM["default_forum_options"]["language"];
if ( !file_exists("./include/lang/$PHORUM[language].php") ) {
$PHORUM["language"] = PHORUM_DEFAULT_LANGUAGE;
}
// Use output buffering so we don't get header errors if there's
// some additional output in the upcoming included files (e.g. UTF-8
// byte order markers).
ob_start();
// Not loaded if we are running an external or scheduled script
if (! defined('PHORUM_SCRIPT')) {
require_once( phorum_get_template( "settings" ) );
$PHORUM["DATA"]["TEMPLATE"] = htmlspecialchars($PHORUM['template']);
$PHORUM["DATA"]["URL"]["TEMPLATE"] = htmlspecialchars("$PHORUM[template_http_path]/$PHORUM[template]");
$PHORUM["DATA"]["URL"]["CSS"] = phorum_get_url(PHORUM_CSS_URL, "css");
$PHORUM["DATA"]["URL"]["CSS_PRINT"] = phorum_get_url(PHORUM_CSS_URL, "css_print");
$PHORUM["DATA"]["URL"]["JAVASCRIPT"] = phorum_get_url(PHORUM_JAVASCRIPT_URL);
$PHORUM["DATA"]["URL"]["AJAX"] = phorum_get_url(PHORUM_AJAX_URL);
}
$PHORUM['language'] = basename($PHORUM['language']);
if ( file_exists( "./include/lang/$PHORUM[language].php" ) ) {
require_once( "./include/lang/$PHORUM[language].php" );
}
// load languages for localized modules
if ( isset( $PHORUM["hooks"]["lang"] ) && is_array($PHORUM["hooks"]["lang"]) ) {
foreach( $PHORUM["hooks"]["lang"]["mods"] as $mod )
{
// load mods for this hook
$mod = basename($mod);
if ( file_exists( "./mods/$mod/lang/$PHORUM[language].php" ) ) {
require_once "./mods/$mod/lang/$PHORUM[language].php";
}
elseif ( file_exists( "./mods/$mod/lang/".PHORUM_DEFAULT_LANGUAGE.".php" ) ) {
require_once "./mods/$mod/lang/".PHORUM_DEFAULT_LANGUAGE.".php";
}
}
}
// Clean up the output buffer.
ob_end_clean();
// load the locale from the language file into the template vars
$PHORUM["DATA"]["LOCALE"] = ( isset( $PHORUM["locale"] ) ) ? $PHORUM["locale"] : "";
// If there is no HCHARSET (used by the htmlspecialchars() calls), then
// use the CHARSET for it instead.
if (empty($PHORUM["DATA"]["HCHARSET"])) {
$PHORUM["DATA"]["HCHARSET"] = $PHORUM["DATA"]["CHARSET"];
}
// HTML titles can't contain HTML code, so we strip HTML tags
// and HTML escape the title.
$PHORUM["DATA"]["HTML_TITLE"] = htmlspecialchars(strip_tags($PHORUM["DATA"]["HTML_TITLE"]), ENT_COMPAT, $PHORUM["DATA"]["HCHARSET"]);
// if the Phorum is disabled, display a message.
if( empty($PHORUM["user"]["admin"]) ) {
if(isset($PHORUM["status"]) && $PHORUM["status"]==PHORUM_MASTER_STATUS_ADMIN_ONLY && phorum_page != 'css' && phorum_page != 'javascript'){
// set all our URL's
phorum_build_common_urls();
$PHORUM["DATA"]["OKMSG"]=$PHORUM["DATA"]["LANG"]["AdminOnlyMessage"];
$PHORUM["user"] = array("user_id" => 0, "username" => "", "admin" => false, "newinfo" => array());
$PHORUM["DATA"]["LOGGEDIN"] = false;
if (phorum_page != 'login') {
phorum_output("message");
exit;
}
} elseif(isset($PHORUM["status"]) && $PHORUM["status"]==PHORUM_MASTER_STATUS_READ_ONLY){
$PHORUM["DATA"]["GLOBAL_ERROR"]=$PHORUM["DATA"]["LANG"]["ReadOnlyMessage"];
$PHORUM["user"] = array("user_id" => 0, "username" => "", "admin" => false, "newinfo" => array(),"tz_offset" => -99);
$PHORUM["DATA"]["LOGGEDIN"] = false;
}
}
// If moderator notifications are on and the person is a mod,
// lets find out if anything is new.
$PHORUM["user"]["NOTICE"]["MESSAGES"] = false;
$PHORUM["user"]["NOTICE"]["USERS"] = false;
$PHORUM["user"]["NOTICE"]["GROUPS"] = false;
if ( $PHORUM["DATA"]["LOGGEDIN"] ) {
// By default, only bug the user on the list, index and cc pages.
// The template can override this behaviour by setting a comma
// separated list of phorum_page names in a template define statement
// like this: {DEFINE show_notify_for_pages "page 1,page 2,..,page n"}
if (isset($PHORUM["TMP"]["show_notify_for_pages"])) {
$show_notify_for_pages = explode(",", $PHORUM["TMP"]["show_notify_for_pages"]);
} else {
$show_notify_for_pages = array('index','list','cc');
}
if ( in_array(phorum_page, $show_notify_for_pages) ) {
if ( $PHORUM["enable_moderator_notifications"] ) {
$forummodlist = phorum_api_user_check_access(
PHORUM_USER_ALLOW_MODERATE_MESSAGES, PHORUM_ACCESS_LIST
);
if ( count( $forummodlist ) > 0 ) {
$PHORUM["user"]["NOTICE"]["MESSAGES"] = ( phorum_db_get_unapproved_list( $forummodlist, true, 0, true) > 0 );
$PHORUM["DATA"]["URL"]["NOTICE"]["MESSAGES"] = phorum_get_url( PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_UNAPPROVED );
}
if ( phorum_api_user_check_access( PHORUM_USER_ALLOW_MODERATE_USERS ) ) {
$PHORUM["user"]["NOTICE"]["USERS"] = ( count( phorum_db_user_get_unapproved() ) > 0 );
$PHORUM["DATA"]["URL"]["NOTICE"]["USERS"] = phorum_get_url( PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_USERS );
}
$groups = phorum_api_user_check_group_access(PHORUM_USER_GROUP_MODERATOR, PHORUM_ACCESS_LIST);
if (count($groups) > 0) {
$PHORUM["user"]["NOTICE"]["GROUPS"] = count( phorum_db_get_group_members( array_keys( $groups ), PHORUM_USER_GROUP_UNAPPROVED ) );
$PHORUM["DATA"]["URL"]["NOTICE"]["GROUPS"] = phorum_get_url( PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_GROUP_MODERATION );
}
}
$PHORUM["user"]["NOTICE"]["SHOW"] = $PHORUM["user"]["NOTICE"]["MESSAGES"] || $PHORUM["user"]["NOTICE"]["USERS"] || $PHORUM["user"]["NOTICE"]["GROUPS"];
}
}
/*
* [hook]
* common
*
* [description]
* This hook gives modules a chance to override Phorum variables
* and settings near the end of the <filename>common.php</filename>
* script. This can be used to override the Phorum (settings)
* variables that are setup during this script.
*
* [category]
* Request initialization
*
* [when]
* At the end of <filename>common.php</filename>.
*
* [input]
* No input.
*
* [output]
* No output.
*
* [example]
* <hookcode>
* function phorum_mod_foo_common()
* {
* global $PHORUM;
*
* // Override the admin email address.
* $PHORUM["system_email_from_name"] = "John Doe";
* $PHORUM["system_email_from_address"] = "[email protected]";
* }
* </hookcode>
*/
if (isset($PHORUM["hooks"]["common"])) {
phorum_hook("common", "");
}
/*
* [hook]
* page_<phorum_page>
*
* [availability]
* Phorum 5 >= 5.2.7
*
*
* [description]
* This hook gives modules a chance to run hook code for a specific
* Phorum page near the end of the the <filename>common.php</filename>
* script.<sbr/>
* <sbr/>
* It gives modules a chance to override Phorum variables
* and settings near the end of the <filename>common.php</filename>
* script. This can be used to override the Phorum (settings)
* variables that are setup during this script.
* <sbr/>
* The <literal>phorum_page</literal> definition that is set
* for each script is used to construct the name of the hook that will
* be called. For example the <filename>index.php</filename> script
* uses phorum_page <literal>index</literal>, which means that the
* called hook will be <literal>page_index</literal>.
*
* [category]
* Request initialization
*
* [when]
* At the end of <filename>common.php</filename>, right after the
* <hook>common</hook> hook is called.<sbr/>
* <sbr/>
* You can look at this as if the hook is called at the start of the
* called script, since including <filename>common.php</filename>
* is about the first thing that a Phorum script does.
*
* [input]
* No input.
*
* [output]
* No output.
*
* [example]
* <hookcode>
* function phorum_mod_foo_page_list()
* {
* global $PHORUM;
*
* // Set the type of list page to use, based on a cookie.
* if (empty($_COOKIE['list_style'])) {
* $PHORUM['threaded_list'] = PHORUM_THREADED_DEFAULT;
* } elseif ($_COOKIE['list_style'] == 'threaded') {
* $PHORUM['threaded_list'] = PHORUM_THREADED_ON;
* } elseif ($_COOKIE['list_style'] == 'flat') {
* $PHORUM['threaded_list'] = PHORUM_THREADED_OFF;
* } elseif ($_COOKIE['list_style'] == 'hybrid') {
* $PHORUM['threaded_list'] = PHORUM_THREADED_HYBRID;
* }
* }
* </hookcode>
*/
$page_hook = 'page_'.phorum_page;
if (isset($PHORUM["hooks"][$page_hook])) {
phorum_hook($page_hook, "");
}
$formatted = phorum_api_user_format(array($PHORUM['user']));
$PHORUM['DATA']['USER'] = $formatted[0];
$PHORUM['DATA']['PHORUM_PAGE'] = phorum_page;
$PHORUM['DATA']['USERTRACK'] = $PHORUM['track_user_activity'];
$PHORUM['DATA']['VROOT'] = $PHORUM['vroot'];
// used in all forms as it seems
$PHORUM['DATA']['POST_VARS'].="<input type=\"hidden\" name=\"forum_id\" value=\"{$PHORUM["forum_id"]}\" />\n";
if(isset($PHORUM['use_rss']) && $PHORUM['use_rss']){
if($PHORUM["default_feed"]=="rss"){
$PHORUM["DATA"]["FEED"] = $PHORUM["DATA"]["LANG"]["RSS"];
$PHORUM["DATA"]["FEED_CONTENT_TYPE"] = "application/rss+xml";
} else {
$PHORUM["DATA"]["FEED"] = $PHORUM["DATA"]["LANG"]["ATOM"];
$PHORUM["DATA"]["FEED_CONTENT_TYPE"] = "application/atom+xml";
}
}
if(!empty($PHORUM['forum_path']) && !is_array($PHORUM['forum_path']))
$PHORUM['forum_path'] = unserialize($PHORUM['forum_path']);
$PHORUM['DATA']['BREADCRUMBS']=array();
// Add the current forum path to the breadcrumbs.
$index_page_url_template = phorum_get_url(PHORUM_INDEX_URL, '%forum_id%');
if(empty($PHORUM['forum_path']) || $PHORUM['forum_id'] == $PHORUM['vroot']) {
$id = $PHORUM['forum_id'];
$url = empty($id)? phorum_get_url(PHORUM_INDEX_URL) : str_replace('%forum_id%',$id,$index_page_url_template);
$PHORUM['DATA']['BREADCRUMBS'][]=array(
'URL' => $url,
'TEXT' => $PHORUM['DATA']['LANG']['Home'],
'ID' => $id,
'TYPE' => 'root'
);
} else {
$track = NULL;
foreach ($PHORUM['forum_path'] as $id => $name)
{
if ($track === NULL) {
$name = $PHORUM['DATA']['LANG']['Home'];
$type = 'root';
$first = FALSE;
} else {
$type = 'folder';
}
if(empty($id)) {
$url = phorum_get_url(PHORUM_INDEX_URL);
} else {
$url = str_replace('%forum_id%',$id,$index_page_url_template);
}
// Note: $id key is not required in general. Only used for
// fixing up the last entry's TYPE.
$PHORUM['DATA']['BREADCRUMBS'][$id]=array(
'URL' => $url,
'TEXT' => strip_tags($name),
'ID' => $id,
'TYPE' => $type
);
$track = $id;
}
if (!$PHORUM['folder_flag']) {
$PHORUM['DATA']['BREADCRUMBS'][$track]['TYPE'] = 'forum';
$PHORUM['DATA']['BREADCRUMBS'][$track]['URL'] = phorum_get_url(PHORUM_LIST_URL, $track);
}
}
// Check if user is forced to change his password and redirect to control center