annotate forum/index.php @ 76:e3e11437ecea website

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