-
Notifications
You must be signed in to change notification settings - Fork 33
/
common.php
839 lines (746 loc) · 32.9 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
<?php
////////////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2016 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. //
// //
////////////////////////////////////////////////////////////////////////////////
/**
* This script bootstraps the Phorum web environment. It will load the
* Phorum API and handle tasks that are required for initializing and
* handling the request.
*/
// Check that this file is not loaded directly.
if (basename(__FILE__) == basename($_SERVER["PHP_SELF"])) exit();
require_once dirname(__FILE__).'/include/api.php';
phorum_api_request_parse();
/*
* [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['ref_thread_id']</literal> and
* <literal>$PHORUM['ref_message_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"] = "John.Doe@example.com";
* }
* }
* </hookcode>
*/
if (isset($PHORUM["hooks"]["common_pre"])) {
phorum_api_hook("common_pre", "");
}
// ----------------------------------------------------------------------
// Setup data for standard (not admin) pages
// ----------------------------------------------------------------------
if (!defined( "PHORUM_ADMIN" ))
{
$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 the Phorum is disabled, display a message.
if (isset($PHORUM["status"]) &&
$PHORUM["status"] == PHORUM_MASTER_STATUS_DISABLED) {
if (!empty($PHORUM["disabled_url"])) {
phorum_api_redirect($PHORUM['disabled_url']);
} else {
echo "This Phorum is currently administratively disabled. Please " .
"contact the web site owner at ".
htmlspecialchars($PHORUM['system_email_from_address'])." " .
"for more information.";
exit();
}
}
if(!empty($PHORUM["forum_id"])){
// Load the settings for the currently active forum.
$forum_settings = phorum_api_forums_get(
$PHORUM["forum_id"],null,null,null,PHORUM_FLAG_INCLUDE_INACTIVE);
if ($forum_settings === NULL)
{
/*
* [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_api_hook("common_no_forum", "");
}
phorum_api_redirect(PHORUM_INDEX_URL);
}
$PHORUM = array_merge($PHORUM, $forum_settings);
} 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 template DATA.
$PHORUM["DATA"]["NAME"] = isset($PHORUM["name"]) ? $PHORUM["name"] : "";
$PHORUM["DATA"]["HTML_DESCRIPTION"] = isset( $PHORUM["description"]) ? preg_replace("!\s+!", " ", $PHORUM["description"]) : "";
// Clean up for getting the description without html in it, so we
// can use it inside the HTML meta description element.
$PHORUM["DATA"]["DESCRIPTION"] = str_replace(
array('\'', '"'), array('', ''),
strip_tags($PHORUM["DATA"]["HTML_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 them here.
$modes = phorum_api_forums_get_display_modes($PHORUM);
$PHORUM["threaded_list"] = $modes['list'];
$PHORUM["threaded_read"] = $modes['read'];
// Provide the number of new private messages for the user in the
// "new_private_messages" field.
if (!empty($PHORUM["enable_pm"])) {
$PHORUM['user']['new_private_messages'] =
$PHORUM['user']['pm_new_count'];
}
}
/*
* [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_api_hook("common_post_user", "");
}
// Some code that only has to be run if the forum isn't set to fixed view.
if (empty($PHORUM['display_fixed']))
{
// User template override.
if (!empty($PHORUM['user']['user_template']) &&
(!isset($PHORUM["user_template"]) ||
!empty($PHORUM['user_template']))) {
$PHORUM['template'] = $PHORUM['user']['user_template'];
}
// Check for a template that is passed on through request parameters.
// Only use valid template names.
$template = NULL;
if (!empty($PHORUM["args"]["template"])) {
$template = basename($PHORUM["args"]["template"]);
} elseif (!empty($_POST['template'])) {
$template = basename($_POST['template']);
}
if ($template !== NULL && $template != '..') {
$PHORUM['template'] = $template;
$PHORUM['DATA']['GET_VARS'][] = "template=".urlencode($template);
$PHORUM['DATA']['POST_VARS'] .= "<input type=\"hidden\" name=\"template\" value=\"".htmlspecialchars($template)."\" />\n";
}
// User language override, when allowed by the general Phorum settings.
if (!empty($PHORUM['user_language']) &&
!empty($PHORUM['user']['user_language'])) {
$PHORUM['language'] = $PHORUM['user']['user_language'];
}
}
// If no language is set by now or if the language file for the
// configured language does not exist, then fallback to the
// language that is configured in the default forum settings.
if (empty($PHORUM["language"]) ||
!file_exists(PHORUM_PATH."/include/lang/$PHORUM[language].php")) {
$PHORUM['language'] = $PHORUM['default_forum_options']['language'];
// If the language file for the default forum settings language
// cannot be found, then fallback to the hard-coded default.
if (!file_exists(PHORUM_PATH."/include/lang/$PHORUM[language].php")) {
$PHORUM['language'] = PHORUM_DEFAULT_LANGUAGE;
}
}
// If the requested template does not exist, then fallback to the
// template that is configured in the default forum settings.
if (!file_exists(PHORUM_PATH."/templates/$PHORUM[template]/info.php")) {
$PHORUM['template'] = $PHORUM['default_forum_options']['template'];
// If the template directory for the default forum settings template
// cannot be found, then fallback to the hard-coded default.
if (!file_exists(PHORUM_PATH."/templates/$PHORUM[template]/info.php")) {
$PHORUM['template'] = PHORUM_DEFAULT_TEMPLATE;
}
}
// 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 or whitespace outside the php tags).
ob_start();
// User output buffering so we don't get header errors.
// Not loaded if we are running an external or scheduled script.
if (!defined('PHORUM_SCRIPT'))
{
include phorum_api_template('settings');
$PHORUM["DATA"]["TEMPLATE"] = htmlspecialchars($PHORUM['template']);
$PHORUM["DATA"]["URL"]["TEMPLATE"] = htmlspecialchars("$PHORUM[template_http_path]/$PHORUM[template]");
$PHORUM["DATA"]["URL"]["CSS"] = phorum_api_url(PHORUM_CSS_URL, "css");
$PHORUM["DATA"]["URL"]["CSS_PRINT"] = phorum_api_url(PHORUM_CSS_URL, "css_print");
$PHORUM["DATA"]["URL"]["JAVASCRIPT"] = phorum_api_url(PHORUM_JAVASCRIPT_URL);
$PHORUM["DATA"]["URL"]["AJAX"] = phorum_api_url(PHORUM_AJAX_URL);
}
// Language names that modules might be using to reference the same
// language. Before Phorum 5.3, the language filename format was
// not standardized, so some other formats might still be in use.
// The included language file can fill this array with appropriate
// language names when needed.
$PHORUM['compat_languages'] = array();
// Load the main language file.
$PHORUM['language'] = basename($PHORUM['language']);
if (file_exists(PHORUM_PATH."/include/lang/$PHORUM[language].php")) {
require_once PHORUM_PATH."/include/lang/$PHORUM[language].php";
} else trigger_error(
"Language file include/lang/$PHORUM[language].php not found",
E_USER_ERROR
);
// Add the active language and the default language to compat_languages,
// so we can simply use the language array to scan for language files.
$PHORUM['compat_languages'][$PHORUM['language']] = $PHORUM['language'];
$PHORUM['compat_languages'] = array_reverse($PHORUM['compat_languages']);
if (!isset($PHORUM['compat_languages'][PHORUM_DEFAULT_LANGUAGE])) {
$PHORUM['compat_languages'][PHORUM_DEFAULT_LANGUAGE] =
PHORUM_DEFAULT_LANGUAGE;
}
foreach (explode(',', PHORUM_DEFAULT_LANGUAGE_COMPAT) as $fallback) {
if (!isset($PHORUM['compat_languages'][$fallback])) {
$PHORUM['compat_languages'][$fallback] = $fallback;
}
}
// Load language file(s) for localized modules.
if (!empty($PHORUM['hooks']['lang']['mods'])) {
foreach($PHORUM['hooks']['lang']['mods'] as $mod) {
$mod = basename($mod);
$loaded = FALSE;
foreach ($PHORUM['compat_languages'] as $language) {
$language_file = PHORUM_PATH."/mods/$mod/lang/$language.php";
if (file_exists($language_file)) {
require_once $language_file;
$loaded = TRUE;
break;
}
}
if (!$loaded) trigger_error(
"No language file found for module $mod", E_USER_ERROR
);
}
}
// 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. The HCHARSET is implemented to work
// around the limitation of PHP that it does not support all charsets
// for the htmlspecialchars() call. For example iso-8859-9 (Turkish)
// is not supported, in which case the combination CHARSET=iso-8859-9
// with HCHARSET=iso-8859-1 can be used to prevent PHP warnings.
if (empty($PHORUM["DATA"]["HCHARSET"])) {
$PHORUM["DATA"]["HCHARSET"] = $PHORUM["DATA"]["CHARSET"];
}
// Set the internal encoding for mbstring functions.
mb_internal_encoding($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"]);
// For non-admin users, check if the forum is set to
// read-only or administrator-only mode.
if (empty($PHORUM["user"]["admin"]) && isset($PHORUM['status']))
{
if ($PHORUM["status"] == PHORUM_MASTER_STATUS_ADMIN_ONLY &&
phorum_page != 'css' &&
phorum_page != 'javascript' &&
phorum_page != 'login') {
phorum_build_common_urls();
$PHORUM["DATA"]["OKMSG"] = $PHORUM["DATA"]["LANG"]["AdminOnlyMessage"];
phorum_api_user_set_active_user(PHORUM_FORUM_SESSION, NULL);
/**
* @todo Not compatible with portable / embedded Phorum setups.
*/
phorum_api_output('message');
exit();
} elseif ($PHORUM['status'] == PHORUM_MASTER_STATUS_READ_ONLY) {
$PHORUM['DATA']['GLOBAL_ERROR'] = $PHORUM['DATA']['LANG']['ReadOnlyMessage'];
phorum_api_user_set_active_user(PHORUM_FORUM_SESSION, NULL);
}
}
// If moderator notifications are on and the person is a mod,
// lets find out if anything needs attention.
$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');
}
// Check for moderator notifications that have to be shown.
if (in_array(phorum_page, $show_notify_for_pages) &&
!empty($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_api_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_api_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_api_url(PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_GROUP_MODERATION);
}
}
// A quick template variable for deciding whether or not to show
// moderator notification.
$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"] = "John.Doe@example.com";
* }
* </hookcode>
*/
if (isset($PHORUM["hooks"]["common"])) {
phorum_api_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_api_hook($page_hook, "");
}
$formatted = phorum_api_format_users(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'];
$PHORUM['DATA']['POST_VARS'].="<input type=\"hidden\" name=\"forum_id\" value=\"{$PHORUM["forum_id"]}\" />\n";
if (!empty($PHORUM['ref_thread_id'])) {
$PHORUM['DATA']['POST_VARS'].="<input type=\"hidden\" name=\"ref_thread_id\" value=\"{$PHORUM["ref_thread_id"]}\" />\n";
}
if (!empty($PHORUM['ref_message_id'])) {
$PHORUM['DATA']['POST_VARS'].="<input type=\"hidden\" name=\"ref_message_id\" value=\"{$PHORUM["ref_message_id"]}\" />\n";
}
if (!empty($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";
}
}
$PHORUM['DATA']['BREADCRUMBS'] = array();
// Add the current forum path to the breadcrumbs.
$index_page_url_template = phorum_api_url(PHORUM_INDEX_URL, '%forum_id%');
if (!empty($PHORUM['forum_path']) && !is_array($PHORUM['forum_path'])) {
$PHORUM['forum_path'] = unserialize($PHORUM['forum_path']);
}
if (empty($PHORUM['forum_path']))
{
$id = $PHORUM['forum_id'];
$url = empty($id)
? phorum_api_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_api_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_api_url(PHORUM_LIST_URL, $track);
}
if (!empty($PHORUM['ref_thread_id'])) {
$PHORUM['DATA']['BREADCRUMBS'][] = array(
'URL' => phorum_api_url(
PHORUM_READ_URL,
$PHORUM['ref_thread_id'],
$PHORUM['ref_message_id']
),
'TEXT' => $PHORUM['DATA']['LANG']['Thread'],
'ID' => $PHORUM['ref_message_id'],
'TYPE' => 'message'
);
}
}
}
// ----------------------------------------------------------------------
// Setup data for admin pages
// ----------------------------------------------------------------------
else {
// The admin interface is not localized, but we might need language
// strings at some point after all, for example if we reset the
// author name in messages for deleted users to "anonymous".
$PHORUM["language"] = basename($PHORUM['default_forum_options']['language']);
if (file_exists(PHORUM_PATH."/include/lang/$PHORUM[language].php")) {
require_once PHORUM_PATH."/include/lang/$PHORUM[language].php";
}
}
// ----------------------------------------------------------------------
// Functions
// ----------------------------------------------------------------------
/**
* Check if the user has read permission for a forum page.
*
* If the user does not have read permission for the currently active
* forum, then an error message is shown. What message to show depends
* on the exact case. Possible cases are:
*
* - The user is logged in: final missing read permission message;
* - The user is not logged in, but wouldn't be allowed to read the
* forum, even if he were logged in: final missing read permission message;
* - The user is not logged in, but could be allowed to read the
* forum if he were logged in: please login message.
*
* @return boolean
* TRUE in case the user is allowed to read the forum,
* FALSE otherwise.
*/
function phorum_check_read_common()
{
global $PHORUM;
$retval = TRUE;
if ($PHORUM["forum_id"] > 0 &&
!$PHORUM["folder_flag"] &&
!phorum_api_user_check_access(PHORUM_USER_ALLOW_READ)) {
if ( $PHORUM["DATA"]["LOGGEDIN"] ) {
// if they are logged in and not allowed, they don't have rights
$PHORUM["DATA"]["OKMSG"] = $PHORUM["DATA"]["LANG"]["NoRead"];
} else {
// Check if they could read if logged in.
// If so, let them know to log in.
if (empty($PHORUM["DATA"]["POST"]["parentid"]) &&
$PHORUM["reg_perms"] & PHORUM_USER_ALLOW_READ) {
$PHORUM["DATA"]["OKMSG"] = $PHORUM["DATA"]["LANG"]["PleaseLoginRead"];
} else {
$PHORUM["DATA"]["OKMSG"] = $PHORUM["DATA"]["LANG"]["NoRead"];
}
}
phorum_build_common_urls();
phorum_api_output("message");
$retval = FALSE;
}
return $retval;
}
/**
* Generate the URLs that are used on most pages.
*/
function phorum_build_common_urls()
{
global $PHORUM;
$GLOBALS["PHORUM"]["DATA"]["URL"]["BASE"] = phorum_api_url(PHORUM_BASE_URL);
$GLOBALS["PHORUM"]["DATA"]["URL"]["HTTP_PATH"] = $PHORUM['http_path'];
$GLOBALS["PHORUM"]["DATA"]["URL"]["LIST"] = phorum_api_url(PHORUM_LIST_URL);
// These links are only needed in forums, not in folders.
if (isset($PHORUM['folder_flag']) && !$PHORUM['folder_flag']) {
$GLOBALS["PHORUM"]["DATA"]["URL"]["POST"] = phorum_api_url(PHORUM_POSTING_URL);
$GLOBALS["PHORUM"]["DATA"]["URL"]["SUBSCRIBE"] = phorum_api_url(PHORUM_SUBSCRIBE_URL);
}
$GLOBALS["PHORUM"]["DATA"]["URL"]["SEARCH"] = phorum_api_url(PHORUM_SEARCH_URL);
// Find the id for the index.
$index_id=-1;
// A folder where we usually don't show the index-link but on
// additional pages like search and login it is shown.
if ($PHORUM['folder_flag'] && phorum_page != 'index' &&
($PHORUM['forum_id'] == 0 || $PHORUM['vroot'] == $PHORUM['forum_id'])) {
$index_id = $PHORUM['forum_id'];
// Either a folder where the link should be shown (not vroot or root)
// or an active forum where the link should be shown.
} elseif (($PHORUM['folder_flag'] &&
($PHORUM['forum_id'] != 0 && $PHORUM['vroot'] != $PHORUM['forum_id'])) ||
(!$PHORUM['folder_flag'] && $PHORUM['active'])) {
// Go to root or vroot.
if (isset($PHORUM["index_style"]) && $PHORUM["index_style"] == PHORUM_INDEX_FLAT) {
// vroot is either 0 (root) or another id
$index_id = $PHORUM["vroot"];
// Go to the parent folder.
} else {
$index_id=$PHORUM["parent_id"];
}
}
if ($index_id > -1) {
// check if its the full root, avoid adding an id in this case (SE-optimized ;))
if (!empty($index_id))
$GLOBALS["PHORUM"]["DATA"]["URL"]["INDEX"] = phorum_api_url(PHORUM_INDEX_URL, $index_id);
else
$GLOBALS["PHORUM"]["DATA"]["URL"]["INDEX"] = phorum_api_url(PHORUM_INDEX_URL);
}
// these urls depend on the login-status of a user
if ($GLOBALS["PHORUM"]["DATA"]["LOGGEDIN"]) {
$GLOBALS["PHORUM"]["DATA"]["URL"]["LOGINOUT"] = phorum_api_url( PHORUM_LOGIN_URL, "logout=1" );
$GLOBALS["PHORUM"]["DATA"]["URL"]["REGISTERPROFILE"] = phorum_api_url( PHORUM_CONTROLCENTER_URL );
$GLOBALS["PHORUM"]["DATA"]["URL"]["VIEWPROFILE"] = phorum_api_url(PHORUM_PROFILE_URL, $PHORUM['user']['user_id']);
$GLOBALS["PHORUM"]["DATA"]["URL"]["PM"] = phorum_api_url( PHORUM_PM_URL );
} else {
$GLOBALS["PHORUM"]["DATA"]["URL"]["LOGINOUT"] = phorum_api_url( PHORUM_LOGIN_URL );
$GLOBALS["PHORUM"]["DATA"]["URL"]["REGISTERPROFILE"] = phorum_api_url( PHORUM_REGISTER_URL );
}
}
?>