Guest User

Untitled

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