PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/forum/index.php

https://github.com/leftnode/nooges.com
PHP | 362 lines | 237 code | 43 blank | 82 comment | 72 complexity | d6586e506f329dd27a807edddf955bd9 MD5 | raw file
  1. <?php
  2. /**********************************************************************************
  3. * index.php *
  4. ***********************************************************************************
  5. * SMF: Simple Machines Forum *
  6. * Open-Source Project Inspired by Zef Hemel (zef@zefhemel.com) *
  7. * =============================================================================== *
  8. * Software Version: SMF 2.0 RC2 *
  9. * Software by: Simple Machines (http://www.simplemachines.org) *
  10. * Copyright 2006-2009 by: Simple Machines LLC (http://www.simplemachines.org) *
  11. * 2001-2006 by: Lewis Media (http://www.lewismedia.com) *
  12. * Support, News, Updates at: http://www.simplemachines.org *
  13. ***********************************************************************************
  14. * This program is free software; you may redistribute it and/or modify it under *
  15. * the terms of the provided license as published by Simple Machines LLC. *
  16. * *
  17. * This program is distributed in the hope that it is and will be useful, but *
  18. * WITHOUT ANY WARRANTIES; without even any implied warranty of MERCHANTABILITY *
  19. * or FITNESS FOR A PARTICULAR PURPOSE. *
  20. * *
  21. * See the "license.txt" file for details of the Simple Machines license. *
  22. * The latest version can always be found at http://www.simplemachines.org. *
  23. **********************************************************************************/
  24. /* This, as you have probably guessed, is the crux on which SMF functions.
  25. Everything should start here, so all the setup and security is done
  26. properly. The most interesting part of this file is the action array in
  27. the smf_main() function. It is formatted as so:
  28. 'action-in-url' => array('Source-File.php', 'FunctionToCall'),
  29. Then, you can access the FunctionToCall() function from Source-File.php
  30. with the URL index.php?action=action-in-url. Relatively simple, no?
  31. */
  32. $forum_version = 'SMF 2.0 RC2';
  33. // Get everything started up...
  34. define('SMF', 1);
  35. if (function_exists('set_magic_quotes_runtime'))
  36. @set_magic_quotes_runtime(0);
  37. error_reporting(defined('E_STRICT') ? E_ALL | E_STRICT : E_ALL);
  38. $time_start = microtime();
  39. // This makes it so headers can be sent!
  40. ob_start();
  41. // Do some cleaning, just in case.
  42. foreach (array('db_character_set', 'cachedir') as $variable)
  43. if (isset($GLOBALS[$variable]))
  44. unset($GLOBALS[$variable]);
  45. // Load the settings...
  46. require_once(dirname(__FILE__) . '/Settings.php');
  47. // Make absolutely sure the cache directory is defined.
  48. if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
  49. $cachedir = $boarddir . '/cache';
  50. // And important includes.
  51. require_once($sourcedir . '/QueryString.php');
  52. require_once($sourcedir . '/Subs.php');
  53. require_once($sourcedir . '/Errors.php');
  54. require_once($sourcedir . '/Load.php');
  55. require_once($sourcedir . '/Security.php');
  56. // Using an pre-PHP5 version?
  57. if (@version_compare(PHP_VERSION, '5') == -1)
  58. require_once($sourcedir . '/Subs-Compat.php');
  59. // If $maintenance is set specifically to 2, then we're upgrading or something.
  60. if (!empty($maintenance) && $maintenance == 2)
  61. db_fatal_error();
  62. // Create a variable to store some SMF specific functions in.
  63. $smcFunc = array();
  64. // Initate the database connection and define some database functions to use.
  65. loadDatabase();
  66. // Load the settings from the settings table, and perform operations like optimizing.
  67. reloadSettings();
  68. // Clean the request variables, add slashes, etc.
  69. cleanRequest();
  70. $context = array();
  71. // Seed the random generator.
  72. if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69)
  73. smf_seed_generator();
  74. // Before we get carried away, are we doing a scheduled task? If so save CPU cycles by jumping out!
  75. if (isset($_GET['scheduled']))
  76. {
  77. require_once($sourcedir . '/ScheduledTasks.php');
  78. AutoTask();
  79. }
  80. // Check if compressed output is enabled, supported, and not already being done.
  81. if (!empty($modSettings['enableCompressedOutput']) && !headers_sent())
  82. {
  83. // If zlib is being used, turn off output compression.
  84. if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler' || @version_compare(PHP_VERSION, '4.2.0') == -1)
  85. $modSettings['enableCompressedOutput'] = '0';
  86. else
  87. {
  88. ob_end_clean();
  89. ob_start('ob_gzhandler');
  90. }
  91. }
  92. // Register an error handler.
  93. set_error_handler('error_handler');
  94. // Start the session. (assuming it hasn't already been.)
  95. loadSession();
  96. // Determine if this is using WAP, WAP2, or imode. Technically, we should check that wap comes before application/xhtml or text/html, but this doesn't work in practice as much as it should.
  97. if (isset($_REQUEST['wap']) || isset($_REQUEST['wap2']) || isset($_REQUEST['imode']))
  98. unset($_SESSION['nowap']);
  99. elseif (isset($_REQUEST['nowap']))
  100. $_SESSION['nowap'] = true;
  101. elseif (!isset($_SESSION['nowap']))
  102. {
  103. if (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'application/vnd.wap.xhtml+xml') !== false)
  104. $_REQUEST['wap2'] = 1;
  105. elseif (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'text/vnd.wap.wml') !== false)
  106. {
  107. if (strpos($_SERVER['HTTP_USER_AGENT'], 'DoCoMo/') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'portalmmm/') !== false)
  108. $_REQUEST['imode'] = 1;
  109. else
  110. $_REQUEST['wap'] = 1;
  111. }
  112. }
  113. if (!defined('WIRELESS'))
  114. define('WIRELESS', isset($_REQUEST['wap']) || isset($_REQUEST['wap2']) || isset($_REQUEST['imode']));
  115. // Some settings and headers are different for wireless protocols.
  116. if (WIRELESS)
  117. {
  118. define('WIRELESS_PROTOCOL', isset($_REQUEST['wap']) ? 'wap' : (isset($_REQUEST['wap2']) ? 'wap2' : (isset($_REQUEST['imode']) ? 'imode' : '')));
  119. // Some cellphones can't handle output compression...
  120. $modSettings['enableCompressedOutput'] = '0';
  121. // !!! Do we want these hard coded?
  122. $modSettings['defaultMaxMessages'] = 5;
  123. $modSettings['defaultMaxTopics'] = 9;
  124. // Wireless protocol header.
  125. if (WIRELESS_PROTOCOL == 'wap')
  126. header('Content-Type: text/vnd.wap.wml');
  127. }
  128. // Restore post data if we are revalidating OpenID.
  129. if (isset($_GET['openid_restore_post']) && !empty($_SESSION['openid']['saved_data'][$_GET['openid_restore_post']]['post']) && empty($_POST))
  130. {
  131. $_POST = $_SESSION['openid']['saved_data'][$_GET['openid_restore_post']]['post'];
  132. unset($_SESSION['openid']['saved_data'][$_GET['openid_restore_post']]);
  133. }
  134. // What function shall we execute? (done like this for memory's sake.)
  135. call_user_func(smf_main());
  136. // Call obExit specially; we're coming from the main area ;).
  137. obExit(null, null, true);
  138. // The main controlling function.
  139. function smf_main()
  140. {
  141. global $modSettings, $settings, $user_info, $board, $topic, $board_info, $maintenance, $sourcedir;
  142. // Special case: session keep-alive, output a transparent pixel.
  143. if (isset($_GET['action']) && $_GET['action'] == 'keepalive')
  144. {
  145. header('Content-Type: image/gif');
  146. die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B");
  147. }
  148. // Load the user's cookie (or set as guest) and load their settings.
  149. loadUserSettings();
  150. // Load the current board's information.
  151. loadBoard();
  152. // Load the current user's permissions.
  153. loadPermissions();
  154. // Attachments don't require the entire theme to be loaded.
  155. if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach' && (!empty($modSettings['allow_guestAccess']) && $user_info['is_guest']))
  156. detectBrowser();
  157. // Load the current theme. (note that ?theme=1 will also work, may be used for guest theming.)
  158. else
  159. loadTheme();
  160. // Check if the user should be disallowed access.
  161. is_not_banned();
  162. // If we are in a topic and don't have permission to approve it then duck out now.
  163. if (!empty($topic) && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts') && ($user_info['id'] != $board_info['cur_topic_starter'] || $user_info['is_guest']))
  164. fatal_lang_error('not_a_topic', false);
  165. // Do some logging, unless this is an attachment, avatar, theme option or XML feed.
  166. if (empty($_REQUEST['action']) || !in_array($_REQUEST['action'], array('dlattach', 'jsoption', '.xml', 'xmlhttp', 'verificationcode')))
  167. {
  168. // Log this user as online.
  169. writeLog();
  170. // Track forum statistics and hits...?
  171. if (!empty($modSettings['hitStats']))
  172. trackStats(array('hits' => '+'));
  173. }
  174. // Is the forum in maintenance mode? (doesn't apply to administrators.)
  175. if (!empty($maintenance) && !allowedTo('admin_forum'))
  176. {
  177. // You can only login.... otherwise, you're getting the "maintenance mode" display.
  178. if (isset($_REQUEST['action']) && ($_REQUEST['action'] == 'login2' || $_REQUEST['action'] == 'logout'))
  179. {
  180. require_once($sourcedir . '/LogInOut.php');
  181. return $_REQUEST['action'] == 'login2' ? 'Login2' : 'Logout';
  182. }
  183. // Don't even try it, sonny.
  184. else
  185. {
  186. require_once($sourcedir . '/Subs-Auth.php');
  187. return 'InMaintenance';
  188. }
  189. }
  190. // If guest access is off, a guest can only do one of the very few following actions.
  191. elseif (empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('coppa', 'login', 'login2', 'register', 'register2', 'reminder', 'activate', 'help', 'smstats', 'mailq', 'verificationcode', 'openidreturn',))))
  192. {
  193. require_once($sourcedir . '/Subs-Auth.php');
  194. return 'KickGuest';
  195. }
  196. elseif (empty($_REQUEST['action']))
  197. {
  198. // Action and board are both empty... BoardIndex!
  199. if (empty($board) && empty($topic))
  200. {
  201. require_once($sourcedir . '/BoardIndex.php');
  202. return 'BoardIndex';
  203. }
  204. // Topic is empty, and action is empty.... MessageIndex!
  205. elseif (empty($topic))
  206. {
  207. require_once($sourcedir . '/MessageIndex.php');
  208. return 'MessageIndex';
  209. }
  210. // Board is not empty... topic is not empty... action is empty.. Display!
  211. else
  212. {
  213. require_once($sourcedir . '/Display.php');
  214. return 'Display';
  215. }
  216. }
  217. // Here's the monstrous $_REQUEST['action'] array - $_REQUEST['action'] => array($file, $function).
  218. $actionArray = array(
  219. 'activate' => array('Register.php', 'Activate'),
  220. 'admin' => array('Admin.php', 'AdminMain'),
  221. 'announce' => array('Post.php', 'AnnounceTopic'),
  222. 'attachapprove' => array('ManageAttachments.php', 'ApproveAttach'),
  223. 'buddy' => array('Subs-Members.php', 'BuddyListToggle'),
  224. 'calendar' => array('Calendar.php', 'CalendarMain'),
  225. 'clock' => array('Calendar.php', 'clock'),
  226. 'collapse' => array('BoardIndex.php', 'CollapseCategory'),
  227. 'coppa' => array('Register.php', 'CoppaForm'),
  228. 'credits' => array('Who.php', 'Credits'),
  229. 'deletemsg' => array('RemoveTopic.php', 'DeleteMessage'),
  230. 'display' => array('Display.php', 'Display'),
  231. 'dlattach' => array('Display.php', 'Download'),
  232. 'editpoll' => array('Poll.php', 'EditPoll'),
  233. 'editpoll2' => array('Poll.php', 'EditPoll2'),
  234. 'emailuser' => array('SendTopic.php', 'EmailUser'),
  235. 'findmember' => array('Subs-Auth.php', 'JSMembers'),
  236. 'groups' => array('Groups.php', 'Groups'),
  237. 'help' => array('Help.php', 'ShowHelp'),
  238. 'helpadmin' => array('Help.php', 'ShowAdminHelp'),
  239. 'im' => array('PersonalMessage.php', 'MessageMain'),
  240. 'jseditor' => array('Subs-Editor.php', 'EditorMain'),
  241. 'jsmodify' => array('Post.php', 'JavaScriptModify'),
  242. 'jsoption' => array('Themes.php', 'SetJavaScript'),
  243. 'lock' => array('LockTopic.php', 'LockTopic'),
  244. 'lockvoting' => array('Poll.php', 'LockVoting'),
  245. 'login' => array('LogInOut.php', 'Login'),
  246. 'login2' => array('LogInOut.php', 'Login2'),
  247. 'logout' => array('LogInOut.php', 'Logout'),
  248. 'markasread' => array('Subs-Boards.php', 'MarkRead'),
  249. 'mergetopics' => array('SplitTopics.php', 'MergeTopics'),
  250. 'mlist' => array('Memberlist.php', 'Memberlist'),
  251. 'moderate' => array('ModerationCenter.php', 'ModerationMain'),
  252. 'modifycat' => array('ManageBoards.php', 'ModifyCat'),
  253. 'modifykarma' => array('Karma.php', 'ModifyKarma'),
  254. 'movetopic' => array('MoveTopic.php', 'MoveTopic'),
  255. 'movetopic2' => array('MoveTopic.php', 'MoveTopic2'),
  256. 'notify' => array('Notify.php', 'Notify'),
  257. 'notifyboard' => array('Notify.php', 'BoardNotify'),
  258. 'openidreturn' => array('Subs-OpenID.php', 'smf_openID_return'),
  259. 'pm' => array('PersonalMessage.php', 'MessageMain'),
  260. 'post' => array('Post.php', 'Post'),
  261. 'post2' => array('Post.php', 'Post2'),
  262. 'printpage' => array('Printpage.php', 'PrintTopic'),
  263. 'profile' => array('Profile.php', 'ModifyProfile'),
  264. 'quotefast' => array('Post.php', 'QuoteFast'),
  265. 'quickmod' => array('MessageIndex.php', 'QuickModeration'),
  266. 'quickmod2' => array('Display.php', 'QuickInTopicModeration'),
  267. 'recent' => array('Recent.php', 'RecentPosts'),
  268. 'register' => array('Register.php', 'Register'),
  269. 'register2' => array('Register.php', 'Register2'),
  270. 'reminder' => array('Reminder.php', 'RemindMe'),
  271. 'removepoll' => array('Poll.php', 'RemovePoll'),
  272. 'removetopic2' => array('RemoveTopic.php', 'RemoveTopic2'),
  273. 'reporttm' => array('SendTopic.php', 'ReportToModerator'),
  274. 'requestmembers' => array('Subs-Auth.php', 'RequestMembers'),
  275. 'restoretopic' => array('RemoveTopic.php', 'RestoreTopic'),
  276. 'search' => array('Search.php', 'PlushSearch1'),
  277. 'search2' => array('Search.php', 'PlushSearch2'),
  278. 'sendtopic' => array('SendTopic.php', 'EmailUser'),
  279. 'smstats' => array('Stats.php', 'SMStats'),
  280. 'suggest' => array('Subs-Editor.php', 'AutoSuggestHandler'),
  281. 'spellcheck' => array('Subs-Post.php', 'SpellCheck'),
  282. 'splittopics' => array('SplitTopics.php', 'SplitTopics'),
  283. 'stats' => array('Stats.php', 'DisplayStats'),
  284. 'sticky' => array('LockTopic.php', 'Sticky'),
  285. 'theme' => array('Themes.php', 'ThemesMain'),
  286. 'trackip' => array('Profile-View.php', 'trackIP'),
  287. 'about:mozilla' => array('Karma.php', 'BookOfUnknown'),
  288. 'about:unknown' => array('Karma.php', 'BookOfUnknown'),
  289. 'unread' => array('Recent.php', 'UnreadTopics'),
  290. 'unreadreplies' => array('Recent.php', 'UnreadTopics'),
  291. 'verificationcode' => array('Register.php', 'VerificationCode'),
  292. 'viewprofile' => array('Profile.php', 'ModifyProfile'),
  293. 'vote' => array('Poll.php', 'Vote'),
  294. 'viewquery' => array('ViewQuery.php', 'ViewQuery'),
  295. 'viewsmfile' => array('Admin.php', 'DisplayAdminFile'),
  296. 'who' => array('Who.php', 'Who'),
  297. '.xml' => array('News.php', 'ShowXmlFeed'),
  298. 'xmlhttp' => array('Xml.php', 'XMLhttpMain'),
  299. );
  300. // Get the function and file to include - if it's not there, do the board index.
  301. if (!isset($_REQUEST['action']) || !isset($actionArray[$_REQUEST['action']]))
  302. {
  303. // Catch the action with the theme?
  304. if (!empty($settings['catch_action']))
  305. {
  306. require_once($sourcedir . '/Themes.php');
  307. return 'WrapAction';
  308. }
  309. // Fall through to the board index then...
  310. require_once($sourcedir . '/BoardIndex.php');
  311. return 'BoardIndex';
  312. }
  313. // Otherwise, it was set - so let's go to that action.
  314. require_once($sourcedir . '/' . $actionArray[$_REQUEST['action']][0]);
  315. return $actionArray[$_REQUEST['action']][1];
  316. }
  317. ?>