-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.php
1252 lines (1084 loc) · 35.9 KB
/
global.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
*
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*
*/
$working_dir = dirname(__FILE__);
if(!$working_dir)
{
$working_dir = '.';
}
$shutdown_queries = $shutdown_functions = array();
// Load main MyBB core file which begins all of the magic
require_once $working_dir.'/inc/init.php';
// Read the usergroups cache as well as the moderators cache
$groupscache = $cache->read('usergroups');
// If the groups cache doesn't exist, update it and re-read it
if(!is_array($groupscache))
{
$cache->update_usergroups();
$groupscache = $cache->read('usergroups');
}
$current_page = my_strtolower(basename(THIS_SCRIPT));
// Send page headers - don't send no-cache headers for attachment.php
if($current_page != 'attachment.php')
{
send_page_headers();
}
// Do not use session system for defined pages
if((isset($mybb->input['action']) && isset($nosession[$mybb->input['action']])) || (isset($mybb->input['thumbnail']) && $current_page == 'attachment.php'))
{
define('NO_ONLINE', 1);
}
// Create session for this user
require_once MYBB_ROOT.'inc/class_session.php';
$session = new session;
$session->init();
$mybb->session = &$session;
$mybb->user['ismoderator'] = is_moderator(0, '', $mybb->user['uid']);
// Set our POST validation code here
$mybb->post_code = generate_post_check();
// Set and load the language
if(isset($mybb->input['language']) && $lang->language_exists($mybb->get_input('language')) && verify_post_check($mybb->get_input('my_post_key'), true))
{
$mybb->settings['bblanguage'] = $mybb->get_input('language');
// If user is logged in, update their language selection with the new one
if($mybb->user['uid'])
{
if(isset($mybb->cookies['mybblang']))
{
my_unsetcookie('mybblang');
}
$db->update_query('users', array('language' => $db->escape_string($mybb->settings['bblanguage'])), "uid = '{$mybb->user['uid']}'");
}
// Guest = cookie
else
{
my_setcookie('mybblang', $mybb->settings['bblanguage']);
}
$mybb->user['language'] = $mybb->settings['bblanguage'];
}
// Cookied language!
else if(!$mybb->user['uid'] && !empty($mybb->cookies['mybblang']) && $lang->language_exists($mybb->cookies['mybblang']))
{
$mybb->settings['bblanguage'] = $mybb->cookies['mybblang'];
}
else if(!isset($mybb->settings['bblanguage']))
{
$mybb->settings['bblanguage'] = 'english';
}
// Load language
$lang->set_language($mybb->settings['bblanguage']);
$lang->load('global');
$lang->load('messages');
// Wipe lockout cookie if enough time has passed
if($mybb->cookies['lockoutexpiry'] && $mybb->cookies['lockoutexpiry'] < TIME_NOW)
{
my_unsetcookie('lockoutexpiry');
}
// Run global_start plugin hook now that the basics are set up
$plugins->run_hooks('global_start');
if(function_exists('mb_internal_encoding') && !empty($lang->settings['charset']))
{
@mb_internal_encoding($lang->settings['charset']);
}
// Select the board theme to use.
$loadstyle = '';
$load_from_forum = $load_from_user = 0;
$style = array();
// The user used our new quick theme changer
if(isset($mybb->input['theme']) && verify_post_check($mybb->get_input('my_post_key'), true))
{
// Set up user handler.
require_once MYBB_ROOT.'inc/datahandlers/user.php';
$userhandler = new UserDataHandler('update');
$user = array(
'uid' => $mybb->user['uid'],
'style' => $mybb->get_input('theme', MyBB::INPUT_INT),
'usergroup' => $mybb->user['usergroup'],
'additionalgroups' => $mybb->user['additionalgroups']
);
$userhandler->set_data($user);
// validate_user verifies the style if it is set in the data array.
if($userhandler->validate_user())
{
$mybb->user['style'] = $user['style'];
// If user is logged in, update their theme selection with the new one
if($mybb->user['uid'])
{
if(isset($mybb->cookies['mybbtheme']))
{
my_unsetcookie('mybbtheme');
}
$userhandler->update_user();
}
// Guest = cookie
else
{
my_setcookie('mybbtheme', $user['style']);
}
}
}
// Cookied theme!
else if(!$mybb->user['uid'] && !empty($mybb->cookies['mybbtheme']))
{
$mybb->user['style'] = (int)$mybb->cookies['mybbtheme'];
}
// This user has a custom theme set in their profile
if(isset($mybb->user['style']) && (int)$mybb->user['style'] != 0)
{
$mybb->user['style'] = (int)$mybb->user['style'];
$loadstyle = "tid = '{$mybb->user['style']}'";
$load_from_user = 1;
}
$valid = array(
'showthread.php',
'forumdisplay.php',
'newthread.php',
'newreply.php',
'ratethread.php',
'editpost.php',
'polls.php',
'sendthread.php',
'printthread.php',
'moderation.php'
);
if(in_array($current_page, $valid))
{
cache_forums();
// If we're accessing a post, fetch the forum theme for it and if we're overriding it
if(isset($mybb->input['pid']) && THIS_SCRIPT != "polls.php")
{
$query = $db->simple_select("posts", "fid", "pid = '{$mybb->input['pid']}'", array("limit" => 1));
$fid = $db->fetch_field($query, 'fid');
if($fid)
{
$style = $forum_cache[$fid];
$load_from_forum = 1;
}
}
// We have a thread id and a forum id, we can easily fetch the theme for this forum
else if(isset($mybb->input['tid']))
{
$query = $db->simple_select('threads', 'fid', "tid = '{$mybb->input['tid']}'", array('limit' => 1));
$fid = $db->fetch_field($query, 'fid');
if($fid)
{
$style = $forum_cache[$fid];
$load_from_forum = 1;
}
}
// If we're accessing poll results, fetch the forum theme for it and if we're overriding it
else if(isset($mybb->input['pid']) && THIS_SCRIPT == "polls.php")
{
$query = $db->query("SELECT t.fid FROM ".TABLE_PREFIX."polls p INNER JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid) WHERE p.pid = '{$mybb->input['pid']}' LIMIT 1");
$fid = $db->fetch_field($query, 'fid');
if($fid)
{
$style = $forum_cache[$fid];
$load_from_forum = 1;
}
}
// We have a forum id - simply load the theme from it
else if(isset($mybb->input['fid']) && isset($forum_cache[$mybb->input['fid']]))
{
$style = $forum_cache[$mybb->input['fid']];
$load_from_forum = 1;
}
}
unset($valid);
// From all of the above, a theme was found
if(isset($style['style']) && $style['style'] > 0)
{
$style['style'] = (int)$style['style'];
// This theme is forced upon the user, overriding their selection
if($style['overridestyle'] == 1 || !isset($mybb->user['style']))
{
$loadstyle = "tid = '{$style['style']}'";
}
}
// After all of that no theme? Load the board default
if(empty($loadstyle))
{
$loadstyle = "def='1'";
}
// Fetch the theme to load from the cache
if($loadstyle != "def='1'")
{
$query = $db->simple_select('themes', 'name, tid, properties, stylesheets, allowedgroups', $loadstyle, array('limit' => 1));
$theme = $db->fetch_array($query);
if(isset($theme['tid']) && !$load_from_forum && !is_member($theme['allowedgroups']) && $theme['allowedgroups'] != 'all')
{
if($load_from_user == 1)
{
$db->update_query('users', array('style' => 0), "style='{$mybb->user['style']}' AND uid='{$mybb->user['uid']}'");
}
if(isset($mybb->cookies['mybbtheme']))
{
my_unsetcookie('mybbtheme');
}
$loadstyle = "def='1'";
}
}
if($loadstyle == "def='1'")
{
if(!$cache->read('default_theme'))
{
$cache->update_default_theme();
}
$theme = $cache->read('default_theme');
$load_from_forum = $load_from_user = 0;
}
// No theme was found - we attempt to load the master or any other theme
if(!isset($theme['tid']) || isset($theme['tid']) && !$theme['tid'])
{
// Missing theme was from a forum, run a query to set any forums using the theme to the default
if($load_from_forum == 1)
{
$db->update_query('forums', array('style' => 0), "style = '{$style['style']}'");
}
// Missing theme was from a user, run a query to set any users using the theme to the default
else if($load_from_user == 1)
{
$db->update_query('users', array('style' => 0), "style = '{$mybb->user['style']}'");
}
// Attempt to load the master or any other theme if the master is not available
$query = $db->simple_select('themes', 'name, tid, properties, stylesheets', '', array('order_by' => 'tid', 'limit' => 1));
$theme = $db->fetch_array($query);
}
$theme = @array_merge($theme, my_unserialize($theme['properties']));
// Fetch all necessary stylesheets
$stylesheets = '';
$theme['stylesheets'] = my_unserialize($theme['stylesheets']);
$stylesheet_scripts = array("global", basename($_SERVER['PHP_SELF']));
if(!empty($theme['color']))
{
$stylesheet_scripts[] = $theme['color'];
}
$stylesheet_actions = array("global");
if(!empty($mybb->input['action']))
{
$stylesheet_actions[] = $mybb->get_input('action');
}
foreach($stylesheet_scripts as $stylesheet_script)
{
// Load stylesheets for global actions and the current action
foreach($stylesheet_actions as $stylesheet_action)
{
if(!$stylesheet_action)
{
continue;
}
if(!empty($theme['stylesheets'][$stylesheet_script][$stylesheet_action]))
{
// Actually add the stylesheets to the list
foreach($theme['stylesheets'][$stylesheet_script][$stylesheet_action] as $page_stylesheet)
{
if(!empty($already_loaded[$page_stylesheet]))
{
continue;
}
if(strpos($page_stylesheet, 'css.php') !== false)
{
$stylesheet_url = $mybb->settings['bburl'] . '/' . $page_stylesheet;
}
else
{
$stylesheet_url = $mybb->get_asset_url($page_stylesheet);
}
if($mybb->settings['minifycss'])
{
$stylesheet_url = str_replace('.css', '.min.css', $stylesheet_url);
}
if(strpos($page_stylesheet, 'css.php') !== false)
{
// We need some modification to get it working with the displayorder
$query_string = parse_url($stylesheet_url, PHP_URL_QUERY);
$id = (int) my_substr($query_string, 11);
$query = $db->simple_select("themestylesheets", "name", "sid={$id}");
$real_name = $db->fetch_field($query, "name");
$theme_stylesheets[$real_name] = $id;
}
else
{
$theme_stylesheets[basename($page_stylesheet)] = "<link type=\"text/css\" rel=\"stylesheet\" href=\"{$stylesheet_url}\" />\n";
}
$already_loaded[$page_stylesheet] = 1;
}
}
}
}
unset($actions);
$css_php_script_stylesheets = array();
if(!empty($theme_stylesheets) && is_array($theme['disporder']))
{
foreach($theme['disporder'] as $style_name => $order)
{
if(!empty($theme_stylesheets[$style_name]))
{
if(is_int($theme_stylesheets[$style_name]))
{
$css_php_script_stylesheets[] = $theme_stylesheets[$style_name];
}
else
{
$stylesheets .= $theme_stylesheets[$style_name];
}
}
}
}
if(!empty($css_php_script_stylesheets))
{
$sheet = $mybb->settings['bburl'] . '/css.php?' . http_build_query(array(
'stylesheet' => $css_php_script_stylesheets
));
$stylesheets .= "<link type=\"text/css\" rel=\"stylesheet\" href=\"{$sheet}\" />\n";
}
// Are we linking to a remote theme server?
if(my_validate_url($theme['imgdir']))
{
// If a language directory for the current language exists within the theme - we use it
if(!empty($mybb->user['language']))
{
$theme['imglangdir'] = $theme['imgdir'].'/'.$mybb->user['language'];
}
else
{
// Check if a custom language directory exists for this theme
if(!empty($mybb->settings['bblanguage']))
{
$theme['imglangdir'] = $theme['imgdir'].'/'.$mybb->settings['bblanguage'];
}
// Otherwise, the image language directory is the same as the language directory for the theme
else
{
$theme['imglangdir'] = $theme['imgdir'];
}
}
}
else
{
$img_directory = $theme['imgdir'];
if($mybb->settings['usecdn'] && !empty($mybb->settings['cdnpath']))
{
$img_directory = rtrim($mybb->settings['cdnpath'], '/') . '/' . ltrim($theme['imgdir'], '/');
}
if(!@is_dir($img_directory))
{
$theme['imgdir'] = 'images';
}
// If a language directory for the current language exists within the theme - we use it
if(!empty($mybb->user['language']) && is_dir($img_directory.'/'.$mybb->user['language']))
{
$theme['imglangdir'] = $theme['imgdir'].'/'.$mybb->user['language'];
}
else
{
// Check if a custom language directory exists for this theme
if(is_dir($img_directory.'/'.$mybb->settings['bblanguage']))
{
$theme['imglangdir'] = $theme['imgdir'].'/'.$mybb->settings['bblanguage'];
}
// Otherwise, the image language directory is the same as the language directory for the theme
else
{
$theme['imglangdir'] = $theme['imgdir'];
}
}
$theme['imgdir'] = $mybb->get_asset_url($theme['imgdir']);
$theme['imglangdir'] = $mybb->get_asset_url($theme['imglangdir']);
}
// Theme logo - is it a relative URL to the forum root? Append bburl
if(!preg_match("#^(\.\.?(/|$)|([a-z0-9]+)://)#i", $theme['logo']) && substr($theme['logo'], 0, 1) != '/')
{
$theme['logo'] = $mybb->get_asset_url($theme['logo']);
}
// Load Main Templates and Cached Templates
if(isset($templatelist))
{
$templatelist .= ',';
}
else
{
$templatelist = '';
}
$templatelist .= "headerinclude,header,footer,gobutton,htmldoctype,header_welcomeblock_member,header_welcomeblock_member_user,header_welcomeblock_member_moderator,header_welcomeblock_member_admin,error";
$templatelist .= ",global_pending_joinrequests,global_awaiting_activation,nav,nav_sep,nav_bit,nav_sep_active,nav_bit_active,footer_languageselect,footer_themeselect,global_unreadreports,footer_contactus";
$templatelist .= ",global_boardclosed_warning,global_bannedwarning,error_inline,error_inline_item,error_nopermission_loggedin,error_nopermission,global_pm_alert,header_menu_search,header_menu_portal,redirect,footer_languageselect_option";
$templatelist .= ",video_dailymotion_embed,video_facebook_embed,video_liveleak_embed,video_metacafe_embed,video_myspacetv_embed,video_mixer_embed,video_vimeo_embed,video_yahoo_embed,video_youtube_embed,debug_summary";
$templatelist .= ",smilieinsert_row,smilieinsert_row_empty,smilieinsert,smilieinsert_getmore,smilieinsert_smilie,global_board_offline_modal,footer_showteamlink,footer_themeselector,task_image,usercp_themeselector_option,php_warnings";
$templatelist .= ",mycode_code,mycode_email,mycode_img,mycode_php,mycode_quote_post,mycode_size_int,mycode_url,global_no_permission_modal,global_boardclosed_reason,nav_dropdown,global_remote_avatar_notice,global_modqueue,global_modqueue_notice";
$templatelist .= ",header_welcomeblock_member_buddy,header_welcomeblock_member_pms,header_welcomeblock_member_search,header_welcomeblock_guest,header_welcomeblock_guest_login_modal,header_welcomeblock_guest_login_modal_lockout";
$templatelist .= ",header_menu_calendar,header_menu_memberlist,global_dst_detection,header_quicksearch,smilie,modal,modal_button";
$templates->cache($db->escape_string($templatelist));
// Set the current date and time now
$datenow = my_date($mybb->settings['dateformat'], TIME_NOW, '', false);
$timenow = my_date($mybb->settings['timeformat'], TIME_NOW);
$lang->welcome_current_time = $lang->sprintf($lang->welcome_current_time, $datenow . $lang->comma . $timenow);
// Format the last visit date of this user appropriately
if(isset($mybb->user['lastvisit']))
{
$lastvisit = my_date('relative', $mybb->user['lastvisit'], '', 2);
}
// Otherwise, they've never visited before
else
{
$lastvisit = $lang->lastvisit_never;
}
$plugins->run_hooks('global_intermediate');
// If the board is closed and we have a usergroup allowed to view the board when closed, then show board closed warning
$bbclosedwarning = '';
if($mybb->settings['boardclosed'] == 1 && $mybb->usergroup['canviewboardclosed'] == 1)
{
eval('$bbclosedwarning = "'.$templates->get('global_boardclosed_warning').'";');
}
// Prepare the main templates for use
$admincplink = $modcplink = $usercplink = '';
// Load appropriate welcome block for the current logged in user
if($mybb->user['uid'] != 0)
{
// User can access the admin cp and we're not hiding admin cp links, fetch it
if($mybb->usergroup['cancp'] == 1 && $mybb->config['hide_admin_links'] != 1)
{
$admin_dir = $config['admin_dir'];
eval('$admincplink = "'.$templates->get('header_welcomeblock_member_admin').'";');
}
if($mybb->usergroup['canmodcp'] == 1)
{
eval('$modcplink = "'.$templates->get('header_welcomeblock_member_moderator').'";');
}
if($mybb->usergroup['canusercp'] == 1)
{
eval('$usercplink = "'.$templates->get('header_welcomeblock_member_user').'";');
}
// Format the welcome back message
$lang->welcome_back = $lang->sprintf($lang->welcome_back, build_profile_link(htmlspecialchars_uni($mybb->user['username']), $mybb->user['uid']), $lastvisit);
$buddylink = $searchlink = $pmslink = '';
if(!empty($mybb->user['buddylist']))
{
eval('$buddylink = "' . $templates->get('header_welcomeblock_member_buddy') . '";');
}
if($mybb->usergroup['cansearch'] == 1)
{
eval('$searchlink = "'.$templates->get('header_welcomeblock_member_search').'";');
}
// Tell the user their PM usage
if($mybb->settings['enablepms'] != 0 && $mybb->usergroup['canusepms'] == 1)
{
$lang->welcome_pms_usage = $lang->sprintf($lang->welcome_pms_usage, my_number_format($mybb->user['pms_unread']), my_number_format($mybb->user['pms_total']));
eval('$pmslink = "'.$templates->get('header_welcomeblock_member_pms').'";');
}
eval('$welcomeblock = "'.$templates->get('header_welcomeblock_member').'";');
}
// Otherwise, we have a guest
else
{
switch($mybb->settings['username_method'])
{
case 0:
$login_username = $lang->login_username;
break;
case 1:
$login_username = $lang->login_username1;
break;
case 2:
$login_username = $lang->login_username2;
break;
default:
$login_username = $lang->login_username;
break;
}
if($mybb->cookies['lockoutexpiry'])
{
$secsleft = (int)($mybb->cookies['lockoutexpiry'] - TIME_NOW);
$hoursleft = floor($secsleft / 3600);
$minsleft = floor(($secsleft / 60) % 60);
$secsleft = floor($secsleft % 60);
$lang->failed_login_wait = $lang->sprintf($lang->failed_login_wait, $hoursleft, $minsleft, $secsleft);
eval('$loginform = "'.$templates->get('header_welcomeblock_guest_login_modal_lockout').'";');
}
else
{
eval('$loginform = "'.$templates->get('header_welcomeblock_guest_login_modal').'";');
}
eval('$welcomeblock = "'.$templates->get('header_welcomeblock_guest').'";');
}
// Display menu links and quick search if user has permission
$menu_search = $menu_memberlist = $menu_portal = $menu_calendar = $quicksearch = '';
if($mybb->usergroup['cansearch'] == 1)
{
eval('$menu_search = "'.$templates->get('header_menu_search').'";');
eval('$quicksearch = "'.$templates->get('header_quicksearch').'";');
}
if($mybb->settings['enablememberlist'] == 1 && $mybb->usergroup['canviewmemberlist'] == 1)
{
eval('$menu_memberlist = "'.$templates->get('header_menu_memberlist').'";');
}
if($mybb->settings['enablecalendar'] == 1 && $mybb->usergroup['canviewcalendar'] == 1)
{
eval('$menu_calendar = "'.$templates->get('header_menu_calendar').'";');
}
if($mybb->settings['portal'] == 1)
{
eval('$menu_portal = "'.$templates->get('header_menu_portal').'";');
}
// See if there are any pending join requests for group leaders
$pending_joinrequests = '';
$groupleaders = $cache->read('groupleaders');
if($mybb->user['uid'] != 0 && is_array($groupleaders) && array_key_exists($mybb->user['uid'], $groupleaders))
{
$groupleader = $groupleaders[$mybb->user['uid']];
$showjoinnotice = false;
$gids = "'0'";
foreach($groupleader as $user)
{
if($user['canmanagerequests'] != 1)
{
continue;
}
$user['gid'] = (int)$user['gid'];
if(!empty($groupscache[$user['gid']]['type']) && $groupscache[$user['gid']]['type'] == 4)
{
$showjoinnotice = true;
$gids .= ",'{$user['gid']}'";
}
}
if($showjoinnotice)
{
$query = $db->simple_select('joinrequests', 'COUNT(uid) as total', "gid IN ({$gids}) AND invite='0'");
$total_joinrequests = $db->fetch_field($query, 'total');
if($total_joinrequests > 0)
{
if($total_joinrequests == 1)
{
$lang->pending_joinrequests = $lang->pending_joinrequest;
}
else
{
$total_joinrequests = my_number_format($total_joinrequests);
$lang->pending_joinrequests = $lang->sprintf($lang->pending_joinrequests, $total_joinrequests);
}
eval('$pending_joinrequests = "'.$templates->get('global_pending_joinrequests').'";');
}
}
}
$modnotice = '';
$moderation_queue = array();
// This user is a moderator, super moderator or administrator
if($mybb->settings['reportmethod'] == "db" && ($mybb->usergroup['cancp'] == 1 || ($mybb->user['ismoderator'] && $mybb->usergroup['canmodcp'] == 1 && $mybb->usergroup['canmanagereportedcontent'] == 1)))
{
// Only worth checking if we are here because we have ACP permissions and the other condition fails
if($mybb->usergroup['cancp'] == 1 && !($mybb->user['ismoderator'] && $mybb->usergroup['canmodcp'] == 1 && $mybb->usergroup['canmanagereportedcontent'] == 1))
{
// First we check if the user's a super admin: if yes, we don't care about permissions
$can_access_moderationqueue = true;
$is_super_admin = is_super_admin($mybb->user['uid']);
if(!$is_super_admin)
{
// Include admin functions
if(!file_exists(MYBB_ROOT.$mybb->config['admin_dir']."/inc/functions.php"))
{
$can_access_moderationqueue = false;
}
require_once MYBB_ROOT.$mybb->config['admin_dir']."/inc/functions.php";
// Verify if we have permissions to access forum-moderation_queue
require_once MYBB_ROOT.$mybb->config['admin_dir']."/modules/forum/module_meta.php";
if(function_exists("forum_admin_permissions"))
{
// Get admin permissions
$adminperms = get_admin_permissions($mybb->user['uid']);
$permissions = forum_admin_permissions();
if(array_key_exists('moderation_queue', $permissions['permissions']) && $adminperms['forum']['moderation_queue'] != 1)
{
$can_access_moderationqueue = false;
}
}
}
}
else
{
$can_access_moderationqueue = false;
}
if($can_access_moderationqueue || ($mybb->user['ismoderator'] && $mybb->usergroup['canmodcp'] == 1 && $mybb->usergroup['canmanagereportedcontent'] == 1))
{
// Read the reported content cache
$reported = $cache->read('reportedcontent');
// 0 or more reported items currently exist
if($reported['unread'] > 0)
{
// We want to avoid one extra query for users that can moderate any forum
if($mybb->usergroup['cancp'] || $mybb->usergroup['issupermod'])
{
$unread = (int)$reported['unread'];
}
else
{
$unread = 0;
$query = $db->simple_select('reportedcontent', 'id3', "reportstatus='0' AND (type = 'post' OR type = '')");
while($fid = $db->fetch_field($query, 'id3'))
{
if(is_moderator($fid, "canmanagereportedposts"))
{
++$unread;
}
}
}
if($unread > 0)
{
if($unread == 1)
{
$lang->unread_reports = $lang->unread_report;
}
else
{
$lang->unread_reports = $lang->sprintf($lang->unread_reports, my_number_format($unread));
}
eval('$moderation_queue[] = "'.$templates->get('global_unreadreports', 1, 0).'";');
}
}
}
}
// Get awaiting moderation queue stats
if($can_access_moderationqueue || ($mybb->user['ismoderator'] && $mybb->usergroup['canmodcp'] == 1 && $mybb->usergroup['canmanagemodqueue'] == 1))
{
$unapproved_posts = $unapproved_threads = 0;
$query = $db->simple_select("posts", "replyto", "visible = 0");
while($unapproved = $db->fetch_array($query))
{
if($unapproved["replyto"] == 0){
$unapproved_threads++;
} else {
$unapproved_posts++;
}
}
$query = $db->simple_select("attachments", "COUNT(aid) AS unapprovedattachments", "visible=0");
$unapproved_attachments = $db->fetch_field($query, "unapprovedattachments");
$modqueue_types = array('threads', 'posts', 'attachments');
foreach($modqueue_types as $modqueue_type)
{
if(!empty(${'unapproved_'.$modqueue_type}))
{
if(${'unapproved_'.$modqueue_type} == 1)
{
$modqueue_message = $lang->{'unapproved_'.substr($modqueue_type, 0, -1)};
}
else
{
$modqueue_message = $lang->sprintf($lang->{'unapproved_'.$modqueue_type}, my_number_format(${'unapproved_'.$modqueue_type}));
}
eval('$moderation_queue[] = "'.$templates->get('global_modqueue', 1, 0).'";');
}
}
}
if(!empty($moderation_queue))
{
$moderation_queue_last = array_pop($moderation_queue);
if(empty($moderation_queue))
{
$moderation_queue = $moderation_queue_last;
}
else
{
$moderation_queue = implode($lang->comma, $moderation_queue).' '.$lang->and.' '.$moderation_queue_last;
}
$moderation_queue = $lang->sprintf($lang->mod_notice, $moderation_queue);
eval('$modnotice = "'.$templates->get('global_modqueue_notice').'";');
}
// Got a character set?
$charset = 'UTF-8';
if(isset($lang->settings['charset']) && $lang->settings['charset'])
{
$charset = $lang->settings['charset'];
}
// Is this user apart of a banned group?
$bannedwarning = '';
if($mybb->usergroup['isbannedgroup'] == 1)
{
// Format their ban lift date and reason appropriately
if(!empty($mybb->user['banned']))
{
if(!empty($mybb->user['banlifted']))
{
$banlift = my_date('normal', $mybb->user['banlifted']);
}
else
{
$banlift = $lang->banned_lifted_never;
}
}
else
{
$banlift = $lang->unknown;
}
if(!empty($mybb->user['banreason']))
{
$reason = htmlspecialchars_uni($mybb->user['banreason']);
}
else
{
$reason = $lang->unknown;
}
// Display a nice warning to the user
eval('$bannedwarning = "'.$templates->get('global_bannedwarning').'";');
}
$lang->ajax_loading = str_replace("'", "\\'", $lang->ajax_loading);
// Check if this user has a new private message.
$pm_notice = '';
if(isset($mybb->user['pmnotice']) && $mybb->user['pmnotice'] == 2 && $mybb->user['pms_unread'] > 0 && $mybb->settings['enablepms'] != 0 && $mybb->usergroup['canusepms'] != 0 && $mybb->usergroup['canview'] != 0 && ($current_page != "private.php" || $mybb->get_input('action') != "read"))
{
if(!isset($parser))
{
require_once MYBB_ROOT.'inc/class_parser.php';
$parser = new postParser;
}
$query = $db->query("
SELECT pm.subject, pm.pmid, fu.username AS fromusername, fu.uid AS fromuid
FROM ".TABLE_PREFIX."privatemessages pm
LEFT JOIN ".TABLE_PREFIX."users fu on (fu.uid=pm.fromid)
WHERE pm.folder = '1' AND pm.uid = '{$mybb->user['uid']}' AND pm.status = '0'
ORDER BY pm.dateline DESC
LIMIT 1
");
$pm = $db->fetch_array($query);
$pm['subject'] = $parser->parse_badwords($pm['subject']);
if($pm['fromuid'] == 0)
{
$pm['fromusername'] = $lang->mybb_engine;
$user_text = $pm['fromusername'];
}
else
{
$pm['fromusername'] = htmlspecialchars_uni($pm['fromusername']);
$user_text = build_profile_link($pm['fromusername'], $pm['fromuid']);
}
if($mybb->user['pms_unread'] == 1)
{
$privatemessage_text = $lang->sprintf($lang->newpm_notice_one, $user_text, $mybb->settings['bburl'], $pm['pmid'], htmlspecialchars_uni($pm['subject']));
}
else
{
$privatemessage_text = $lang->sprintf($lang->newpm_notice_multiple, $mybb->user['pms_unread'], $user_text, $mybb->settings['bburl'], $pm['pmid'], htmlspecialchars_uni($pm['subject']));
}
eval('$pm_notice = "'.$templates->get('global_pm_alert').'";');
}
$remote_avatar_notice = '';
if(($mybb->user['avatartype'] === 'remote' || $mybb->user['avatartype'] === 'gravatar') && !$mybb->settings['allowremoteavatars'])
{
eval('$remote_avatar_notice = "'.$templates->get('global_remote_avatar_notice').'";');
}
if($mybb->settings['awactialert'] == 1 && $mybb->usergroup['cancp'] == 1)
{
$awaitingusers = $cache->read('awaitingactivation');
if(isset($awaitingusers['time']) && $awaitingusers['time'] + 86400 < TIME_NOW)
{
$cache->update_awaitingactivation();
$awaitingusers = $cache->read('awaitingactivation');
}
if(!empty($awaitingusers['users']))
{
$awaitingusers = (int)$awaitingusers['users'];
}
else
{
$awaitingusers = 0;
}
if($awaitingusers < 1)
{
$awaitingusers = 0;
}
else
{
$awaitingusers = my_number_format($awaitingusers);
}
if($awaitingusers > 0)
{
if($awaitingusers == 1)
{
$awaiting_message = $lang->awaiting_message_single;
}
else
{
$awaiting_message = $lang->sprintf($lang->awaiting_message_plural, $awaitingusers);
}
if($admincplink)
{
$awaiting_message .= $lang->sprintf($lang->awaiting_message_link, $mybb->settings['bburl'], $admin_dir);
}
eval('$awaitingusers = "'.$templates->get('global_awaiting_activation').'";');
}
else
{
$awaitingusers = '';
}
}
$jsTemplates = array();
foreach (array('modal', 'modal_button') as $template) {
eval('$jsTemplates["'.$template.'"] = "'.$templates->get($template, 1, 0).'";');
$jsTemplates[$template] = str_replace(array("\n","\r"), array("\\\n", ""), addslashes($jsTemplates[$template]));
}
// Set up some of the default templates
eval('$headerinclude = "'.$templates->get('headerinclude').'";');
eval('$gobutton = "'.$templates->get('gobutton').'";');
eval('$htmldoctype = "'.$templates->get('htmldoctype', 1, 0).'";');
eval('$header = "'.$templates->get('header').'";');
$copy_year = my_date('Y', TIME_NOW);
// Are we showing version numbers in the footer?
$mybbversion = '';
if($mybb->settings['showvernum'] == 1)
{
$mybbversion = ' '.$mybb->version;
}
// Check to see if we have any tasks to run
$task_image = '';
$task_cache = $cache->read('tasks');
if(!$task_cache['nextrun'])
{
$task_cache['nextrun'] = TIME_NOW;
}
if($task_cache['nextrun'] <= TIME_NOW)
{
eval("\$task_image = \"".$templates->get("task_image")."\";");
}
// Post code
$post_code_string = '';
if($mybb->user['uid'])
{
$post_code_string = '&my_post_key='.$mybb->post_code;
}
// Are we showing the quick language selection box?
$lang_select = $lang_options = '';
if($mybb->settings['showlanguageselect'] != 0)
{
$languages = $lang->get_languages();
if(count($languages) > 1)
{
foreach($languages as $key => $language)
{
$language = htmlspecialchars_uni($language);
// Current language matches
if($lang->language == $key)