Advertisement
Guest User

Untitled

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