Chris@76: array('Source-File.php', 'FunctionToCall'), Chris@76: Chris@76: Then, you can access the FunctionToCall() function from Source-File.php Chris@76: with the URL index.php?action=action-in-url. Relatively simple, no? Chris@76: */ Chris@76: Chris@76: $forum_version = 'SMF 2.0.4'; Chris@76: Chris@76: // Get everything started up... Chris@76: define('SMF', 1); Chris@76: if (function_exists('set_magic_quotes_runtime')) Chris@76: @set_magic_quotes_runtime(0); Chris@76: error_reporting(defined('E_STRICT') ? E_ALL | E_STRICT : E_ALL); Chris@76: $time_start = microtime(); Chris@76: Chris@76: // This makes it so headers can be sent! Chris@76: ob_start(); Chris@76: Chris@76: // Do some cleaning, just in case. Chris@76: foreach (array('db_character_set', 'cachedir') as $variable) Chris@76: if (isset($GLOBALS[$variable])) Chris@76: unset($GLOBALS[$variable], $GLOBALS[$variable]); Chris@76: Chris@76: // Load the settings... Chris@76: require_once(dirname(__FILE__) . '/Settings.php'); Chris@76: Chris@76: // Make absolutely sure the cache directory is defined. Chris@76: if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) Chris@76: $cachedir = $boarddir . '/cache'; Chris@76: Chris@76: // And important includes. Chris@76: require_once($sourcedir . '/QueryString.php'); Chris@76: require_once($sourcedir . '/Subs.php'); Chris@76: require_once($sourcedir . '/Errors.php'); Chris@76: require_once($sourcedir . '/Load.php'); Chris@76: require_once($sourcedir . '/Security.php'); Chris@76: Chris@76: // Using an pre-PHP 5.1 version? Chris@76: if (@version_compare(PHP_VERSION, '5.1') == -1) Chris@76: require_once($sourcedir . '/Subs-Compat.php'); Chris@76: Chris@76: // If $maintenance is set specifically to 2, then we're upgrading or something. Chris@76: if (!empty($maintenance) && $maintenance == 2) Chris@76: db_fatal_error(); Chris@76: Chris@76: // Create a variable to store some SMF specific functions in. Chris@76: $smcFunc = array(); Chris@76: Chris@76: // Initate the database connection and define some database functions to use. Chris@76: loadDatabase(); Chris@76: Chris@76: // Load the settings from the settings table, and perform operations like optimizing. Chris@76: reloadSettings(); Chris@76: // Clean the request variables, add slashes, etc. Chris@76: cleanRequest(); Chris@76: $context = array(); Chris@76: Chris@76: // Seed the random generator. Chris@76: if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69) Chris@76: smf_seed_generator(); Chris@76: Chris@76: // Before we get carried away, are we doing a scheduled task? If so save CPU cycles by jumping out! Chris@76: if (isset($_GET['scheduled'])) Chris@76: { Chris@76: require_once($sourcedir . '/ScheduledTasks.php'); Chris@76: AutoTask(); Chris@76: } Chris@76: Chris@76: // Check if compressed output is enabled, supported, and not already being done. Chris@76: if (!empty($modSettings['enableCompressedOutput']) && !headers_sent()) Chris@76: { Chris@76: // If zlib is being used, turn off output compression. Chris@76: if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler' || @version_compare(PHP_VERSION, '4.2.0') == -1) Chris@76: $modSettings['enableCompressedOutput'] = '0'; Chris@76: else Chris@76: { Chris@76: ob_end_clean(); Chris@76: ob_start('ob_gzhandler'); Chris@76: } Chris@76: } Chris@76: Chris@76: // Register an error handler. Chris@76: set_error_handler('error_handler'); Chris@76: Chris@76: // Start the session. (assuming it hasn't already been.) Chris@76: loadSession(); Chris@76: Chris@76: // 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: if (isset($_REQUEST['wap']) || isset($_REQUEST['wap2']) || isset($_REQUEST['imode'])) Chris@76: unset($_SESSION['nowap']); Chris@76: elseif (isset($_REQUEST['nowap'])) Chris@76: $_SESSION['nowap'] = true; Chris@76: elseif (!isset($_SESSION['nowap'])) Chris@76: { Chris@76: if (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'application/vnd.wap.xhtml+xml') !== false) Chris@76: $_REQUEST['wap2'] = 1; Chris@76: elseif (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'text/vnd.wap.wml') !== false) Chris@76: { Chris@76: if (strpos($_SERVER['HTTP_USER_AGENT'], 'DoCoMo/') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'portalmmm/') !== false) Chris@76: $_REQUEST['imode'] = 1; Chris@76: else Chris@76: $_REQUEST['wap'] = 1; Chris@76: } Chris@76: } Chris@76: Chris@76: if (!defined('WIRELESS')) Chris@76: define('WIRELESS', isset($_REQUEST['wap']) || isset($_REQUEST['wap2']) || isset($_REQUEST['imode'])); Chris@76: Chris@76: // Some settings and headers are different for wireless protocols. Chris@76: if (WIRELESS) Chris@76: { Chris@76: define('WIRELESS_PROTOCOL', isset($_REQUEST['wap']) ? 'wap' : (isset($_REQUEST['wap2']) ? 'wap2' : (isset($_REQUEST['imode']) ? 'imode' : ''))); Chris@76: Chris@76: // Some cellphones can't handle output compression... Chris@76: $modSettings['enableCompressedOutput'] = '0'; Chris@76: // !!! Do we want these hard coded? Chris@76: $modSettings['defaultMaxMessages'] = 5; Chris@76: $modSettings['defaultMaxTopics'] = 9; Chris@76: Chris@76: // Wireless protocol header. Chris@76: if (WIRELESS_PROTOCOL == 'wap') Chris@76: header('Content-Type: text/vnd.wap.wml'); Chris@76: } Chris@76: Chris@76: // Restore post data if we are revalidating OpenID. Chris@76: if (isset($_GET['openid_restore_post']) && !empty($_SESSION['openid']['saved_data'][$_GET['openid_restore_post']]['post']) && empty($_POST)) Chris@76: { Chris@76: $_POST = $_SESSION['openid']['saved_data'][$_GET['openid_restore_post']]['post']; Chris@76: unset($_SESSION['openid']['saved_data'][$_GET['openid_restore_post']]); Chris@76: } Chris@76: Chris@76: // What function shall we execute? (done like this for memory's sake.) Chris@76: call_user_func(smf_main()); Chris@76: Chris@76: // Call obExit specially; we're coming from the main area ;). Chris@76: obExit(null, null, true); Chris@76: Chris@76: // The main controlling function. Chris@76: function smf_main() Chris@76: { Chris@76: global $modSettings, $settings, $user_info, $board, $topic, $board_info, $maintenance, $sourcedir; Chris@76: Chris@76: // Special case: session keep-alive, output a transparent pixel. Chris@76: if (isset($_GET['action']) && $_GET['action'] == 'keepalive') Chris@76: { Chris@76: header('Content-Type: image/gif'); Chris@76: 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: } Chris@76: Chris@76: // Load the user's cookie (or set as guest) and load their settings. Chris@76: loadUserSettings(); Chris@76: Chris@76: // Load the current board's information. Chris@76: loadBoard(); Chris@76: Chris@76: // Load the current user's permissions. Chris@76: loadPermissions(); Chris@76: Chris@76: // Attachments don't require the entire theme to be loaded. Chris@76: if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach' && (!empty($modSettings['allow_guestAccess']) && $user_info['is_guest'])) Chris@76: detectBrowser(); Chris@76: // Load the current theme. (note that ?theme=1 will also work, may be used for guest theming.) Chris@76: else Chris@76: loadTheme(); Chris@76: Chris@76: // Check if the user should be disallowed access. Chris@76: is_not_banned(); Chris@76: Chris@76: // If we are in a topic and don't have permission to approve it then duck out now. Chris@76: 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: fatal_lang_error('not_a_topic', false); Chris@76: Chris@76: // Do some logging, unless this is an attachment, avatar, toggle of editor buttons, theme option, XML feed etc. Chris@76: if (empty($_REQUEST['action']) || !in_array($_REQUEST['action'], array('dlattach', 'findmember', 'jseditor', 'jsoption', 'requestmembers', 'smstats', '.xml', 'xmlhttp', 'verificationcode', 'viewquery', 'viewsmfile'))) Chris@76: { Chris@76: // Log this user as online. Chris@76: writeLog(); Chris@76: Chris@76: // Track forum statistics and hits...? Chris@76: if (!empty($modSettings['hitStats'])) Chris@76: trackStats(array('hits' => '+')); Chris@76: } Chris@76: Chris@76: // Is the forum in maintenance mode? (doesn't apply to administrators.) Chris@76: if (!empty($maintenance) && !allowedTo('admin_forum')) Chris@76: { Chris@76: // You can only login.... otherwise, you're getting the "maintenance mode" display. Chris@76: if (isset($_REQUEST['action']) && ($_REQUEST['action'] == 'login2' || $_REQUEST['action'] == 'logout')) Chris@76: { Chris@76: require_once($sourcedir . '/LogInOut.php'); Chris@76: return $_REQUEST['action'] == 'login2' ? 'Login2' : 'Logout'; Chris@76: } Chris@76: // Don't even try it, sonny. Chris@76: else Chris@76: { Chris@76: require_once($sourcedir . '/Subs-Auth.php'); Chris@76: return 'InMaintenance'; Chris@76: } Chris@76: } Chris@76: // If guest access is off, a guest can only do one of the very few following actions. Chris@76: 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: { Chris@76: require_once($sourcedir . '/Subs-Auth.php'); Chris@76: return 'KickGuest'; Chris@76: } Chris@76: elseif (empty($_REQUEST['action'])) Chris@76: { Chris@76: // Action and board are both empty... BoardIndex! Chris@76: if (empty($board) && empty($topic)) Chris@76: { Chris@76: require_once($sourcedir . '/BoardIndex.php'); Chris@76: return 'BoardIndex'; Chris@76: } Chris@76: // Topic is empty, and action is empty.... MessageIndex! Chris@76: elseif (empty($topic)) Chris@76: { Chris@76: require_once($sourcedir . '/MessageIndex.php'); Chris@76: return 'MessageIndex'; Chris@76: } Chris@76: // Board is not empty... topic is not empty... action is empty.. Display! Chris@76: else Chris@76: { Chris@76: require_once($sourcedir . '/Display.php'); Chris@76: return 'Display'; Chris@76: } Chris@76: } Chris@76: Chris@76: // Here's the monstrous $_REQUEST['action'] array - $_REQUEST['action'] => array($file, $function). Chris@76: $actionArray = array( Chris@76: 'activate' => array('Register.php', 'Activate'), Chris@76: 'admin' => array('Admin.php', 'AdminMain'), Chris@76: 'announce' => array('Post.php', 'AnnounceTopic'), Chris@76: 'attachapprove' => array('ManageAttachments.php', 'ApproveAttach'), Chris@76: 'buddy' => array('Subs-Members.php', 'BuddyListToggle'), Chris@76: 'calendar' => array('Calendar.php', 'CalendarMain'), Chris@76: 'clock' => array('Calendar.php', 'clock'), Chris@76: 'collapse' => array('BoardIndex.php', 'CollapseCategory'), Chris@76: 'coppa' => array('Register.php', 'CoppaForm'), Chris@76: 'credits' => array('Who.php', 'Credits'), Chris@76: 'deletemsg' => array('RemoveTopic.php', 'DeleteMessage'), Chris@76: 'display' => array('Display.php', 'Display'), Chris@76: 'dlattach' => array('Display.php', 'Download'), Chris@76: 'editpoll' => array('Poll.php', 'EditPoll'), Chris@76: 'editpoll2' => array('Poll.php', 'EditPoll2'), Chris@76: 'emailuser' => array('SendTopic.php', 'EmailUser'), Chris@76: 'findmember' => array('Subs-Auth.php', 'JSMembers'), Chris@76: 'groups' => array('Groups.php', 'Groups'), Chris@76: 'help' => array('Help.php', 'ShowHelp'), Chris@76: 'helpadmin' => array('Help.php', 'ShowAdminHelp'), Chris@76: 'im' => array('PersonalMessage.php', 'MessageMain'), Chris@76: 'jseditor' => array('Subs-Editor.php', 'EditorMain'), Chris@76: 'jsmodify' => array('Post.php', 'JavaScriptModify'), Chris@76: 'jsoption' => array('Themes.php', 'SetJavaScript'), Chris@76: 'lock' => array('LockTopic.php', 'LockTopic'), Chris@76: 'lockvoting' => array('Poll.php', 'LockVoting'), Chris@76: 'login' => array('LogInOut.php', 'Login'), Chris@76: 'login2' => array('LogInOut.php', 'Login2'), Chris@76: 'logout' => array('LogInOut.php', 'Logout'), Chris@76: 'markasread' => array('Subs-Boards.php', 'MarkRead'), Chris@76: 'mergetopics' => array('SplitTopics.php', 'MergeTopics'), Chris@76: 'mlist' => array('Memberlist.php', 'Memberlist'), Chris@76: 'moderate' => array('ModerationCenter.php', 'ModerationMain'), Chris@76: 'modifycat' => array('ManageBoards.php', 'ModifyCat'), Chris@76: 'modifykarma' => array('Karma.php', 'ModifyKarma'), Chris@76: 'movetopic' => array('MoveTopic.php', 'MoveTopic'), Chris@76: 'movetopic2' => array('MoveTopic.php', 'MoveTopic2'), Chris@76: 'notify' => array('Notify.php', 'Notify'), Chris@76: 'notifyboard' => array('Notify.php', 'BoardNotify'), Chris@76: 'openidreturn' => array('Subs-OpenID.php', 'smf_openID_return'), Chris@76: 'pm' => array('PersonalMessage.php', 'MessageMain'), Chris@76: 'post' => array('Post.php', 'Post'), Chris@76: 'post2' => array('Post.php', 'Post2'), Chris@76: 'printpage' => array('Printpage.php', 'PrintTopic'), Chris@76: 'profile' => array('Profile.php', 'ModifyProfile'), Chris@76: 'quotefast' => array('Post.php', 'QuoteFast'), Chris@76: 'quickmod' => array('MessageIndex.php', 'QuickModeration'), Chris@76: 'quickmod2' => array('Display.php', 'QuickInTopicModeration'), Chris@76: 'recent' => array('Recent.php', 'RecentPosts'), Chris@76: 'register' => array('Register.php', 'Register'), Chris@76: 'register2' => array('Register.php', 'Register2'), Chris@76: 'reminder' => array('Reminder.php', 'RemindMe'), Chris@76: 'removepoll' => array('Poll.php', 'RemovePoll'), Chris@76: 'removetopic2' => array('RemoveTopic.php', 'RemoveTopic2'), Chris@76: 'reporttm' => array('SendTopic.php', 'ReportToModerator'), Chris@76: 'requestmembers' => array('Subs-Auth.php', 'RequestMembers'), Chris@76: 'restoretopic' => array('RemoveTopic.php', 'RestoreTopic'), Chris@76: 'search' => array('Search.php', 'PlushSearch1'), Chris@76: 'search2' => array('Search.php', 'PlushSearch2'), Chris@76: 'sendtopic' => array('SendTopic.php', 'EmailUser'), Chris@76: 'smstats' => array('Stats.php', 'SMStats'), Chris@76: 'suggest' => array('Subs-Editor.php', 'AutoSuggestHandler'), Chris@76: 'spellcheck' => array('Subs-Post.php', 'SpellCheck'), Chris@76: 'splittopics' => array('SplitTopics.php', 'SplitTopics'), Chris@76: 'stats' => array('Stats.php', 'DisplayStats'), Chris@76: 'sticky' => array('LockTopic.php', 'Sticky'), Chris@76: 'theme' => array('Themes.php', 'ThemesMain'), Chris@76: 'trackip' => array('Profile-View.php', 'trackIP'), Chris@76: 'about:mozilla' => array('Karma.php', 'BookOfUnknown'), Chris@76: 'about:unknown' => array('Karma.php', 'BookOfUnknown'), Chris@76: 'unread' => array('Recent.php', 'UnreadTopics'), Chris@76: 'unreadreplies' => array('Recent.php', 'UnreadTopics'), Chris@76: 'verificationcode' => array('Register.php', 'VerificationCode'), Chris@76: 'viewprofile' => array('Profile.php', 'ModifyProfile'), Chris@76: 'vote' => array('Poll.php', 'Vote'), Chris@76: 'viewquery' => array('ViewQuery.php', 'ViewQuery'), Chris@76: 'viewsmfile' => array('Admin.php', 'DisplayAdminFile'), Chris@76: 'who' => array('Who.php', 'Who'), Chris@76: '.xml' => array('News.php', 'ShowXmlFeed'), Chris@76: 'xmlhttp' => array('Xml.php', 'XMLhttpMain'), Chris@76: ); Chris@76: Chris@76: // Allow modifying $actionArray easily. Chris@76: call_integration_hook('integrate_actions', array(&$actionArray)); Chris@76: Chris@76: // Get the function and file to include - if it's not there, do the board index. Chris@76: if (!isset($_REQUEST['action']) || !isset($actionArray[$_REQUEST['action']])) Chris@76: { Chris@76: // Catch the action with the theme? Chris@76: if (!empty($settings['catch_action'])) Chris@76: { Chris@76: require_once($sourcedir . '/Themes.php'); Chris@76: return 'WrapAction'; Chris@76: } Chris@76: Chris@76: // Fall through to the board index then... Chris@76: require_once($sourcedir . '/BoardIndex.php'); Chris@76: return 'BoardIndex'; Chris@76: } Chris@76: Chris@76: // Otherwise, it was set - so let's go to that action. Chris@76: require_once($sourcedir . '/' . $actionArray[$_REQUEST['action']][0]); Chris@76: return $actionArray[$_REQUEST['action']][1]; Chris@76: } Chris@76: Chris@76: ?>