/index.php
PHP | 190 lines | 98 code | 36 blank | 56 comment | 37 complexity | 57e636e6aee258e7e33aecc4ff451f62 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0
- <?php
- /**
- * @name ElkArte Forum
- * @copyright ElkArte Forum contributors
- * @license BSD http://opensource.org/licenses/BSD-3-Clause
- *
- * This software is a derived product, based on:
- *
- * Simple Machines Forum (SMF)
- * copyright: 2011 Simple Machines (http://www.simplemachines.org)
- * license: BSD, See included LICENSE.TXT for terms and conditions.
- *
- * @version 1.0 Alpha
- *
- * This, as you have probably guessed, is the crux for all functions.
- * Everything should start here, so all the setup and security is done
- * properly.
- *
- */
- $forum_version = 'ELKARTE 1.0 Alpha';
- // Get everything started up...
- define('ELKARTE', 1);
- if (function_exists('set_magic_quotes_runtime'))
- @set_magic_quotes_runtime(0);
- error_reporting(defined('E_STRICT') ? E_ALL | E_STRICT : E_ALL);
- $time_start = microtime(true);
- // This makes it so headers can be sent!
- ob_start();
- // Do some cleaning, just in case.
- foreach (array('db_character_set', 'cachedir') as $variable)
- if (isset($GLOBALS[$variable]))
- unset($GLOBALS[$variable], $GLOBALS[$variable]);
- // Load the settings...
- require_once(dirname(__FILE__) . '/Settings.php');
- // Make absolutely sure the new directories are defined.
- if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
- $cachedir = $boarddir . '/cache';
- // Time to forget about variables and go with constants!
- DEFINE('BOARDDIR', $boarddir);
- DEFINE('CACHEDIR', $cachedir);
- DEFINE('EXTDIR', $extdir);
- DEFINE('LANGUAGEDIR', $languagedir);
- DEFINE('SOURCEDIR', $sourcedir);
- DEFINE('ADMINDIR', $sourcedir . '/admin');
- DEFINE('CONTROLLERDIR', $sourcedir . '/controllers');
- DEFINE('SUBSDIR', $sourcedir . '/subs');
- unset($boarddir, $cachedir, $sourcedir);
- // And important includes.
- require_once(SOURCEDIR . '/QueryString.php');
- require_once(SOURCEDIR . '/Session.php');
- require_once(SOURCEDIR . '/Subs.php');
- require_once(SOURCEDIR . '/Errors.php');
- require_once(SOURCEDIR . '/Logging.php');
- require_once(SOURCEDIR . '/Load.php');
- require_once(SUBSDIR . '/Cache.subs.php');
- require_once(SOURCEDIR . '/Security.php');
- require_once(SOURCEDIR . '/BrowserDetect.class.php');
- require_once(SOURCEDIR . '/Errors.class.php');
- // If $maintenance is set specifically to 2, then we're upgrading or something.
- if (!empty($maintenance) && $maintenance == 2)
- display_maintenance_message();
- // Create a variable to store some specific functions in.
- $smcFunc = array();
- // Initiate the database connection and define some database functions to use.
- loadDatabase();
- // Load the settings from the settings table, and perform operations like optimizing.
- reloadSettings();
- // Clean the request variables, add slashes, etc.
- cleanRequest();
- $context = array();
- // Seed the random generator.
- if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69)
- elk_seed_generator();
- // Before we get carried away, are we doing a scheduled task? If so save CPU cycles by jumping out!
- if (isset($_GET['scheduled']))
- {
- require_once(SOURCEDIR . '/ScheduledTasks.php');
- AutoTask();
- }
- // Check if compressed output is enabled, supported, and not already being done.
- if (!empty($modSettings['enableCompressedOutput']) && !headers_sent())
- {
- // If zlib is being used, turn off output compression.
- if (ini_get('zlib.output_compression') >= 1 || ini_get('output_handler') == 'ob_gzhandler')
- $modSettings['enableCompressedOutput'] = 0;
- else
- {
- ob_end_clean();
- ob_start('ob_gzhandler');
- }
- }
- // Register an error handler.
- set_error_handler('error_handler');
- // Start the session. (assuming it hasn't already been.)
- loadSession();
- // Restore post data if we are revalidating OpenID.
- if (isset($_GET['openid_restore_post']) && !empty($_SESSION['openid']['saved_data'][$_GET['openid_restore_post']]['post']) && empty($_POST))
- {
- $_POST = $_SESSION['openid']['saved_data'][$_GET['openid_restore_post']]['post'];
- unset($_SESSION['openid']['saved_data'][$_GET['openid_restore_post']]);
- }
- // Pre-dispatch
- elk_main();
- // Call obExit specially; we're coming from the main area ;).
- obExit(null, null, true);
- /**
- * The main dispatcher.
- * This delegates to each area.
- */
- function elk_main()
- {
- global $modSettings, $settings, $user_info, $board, $topic, $board_info, $maintenance;
- // Special case: session keep-alive, output a transparent pixel.
- if (isset($_GET['action']) && $_GET['action'] == 'keepalive')
- {
- header('Content-Type: image/gif');
- 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");
- }
- // Load the user's cookie (or set as guest) and load their settings.
- loadUserSettings();
- // Load the current board's information.
- loadBoard();
- // Load the current user's permissions.
- loadPermissions();
- // Load BadBehavior before we go much further
- loadBadBehavior();
- // Attachments don't require the entire theme to be loaded.
- if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach' && (!empty($modSettings['allow_guestAccess']) && $user_info['is_guest']))
- detectBrowser();
- // Load the current theme. (note that ?theme=1 will also work, may be used for guest theming.)
- else
- loadTheme();
- // Check if the user should be disallowed access.
- is_not_banned();
- // If we are in a topic and don't have permission to approve it then duck out now.
- if (!empty($topic) && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts') && ($user_info['id'] != $board_info['cur_topic_starter'] || $user_info['is_guest']))
- fatal_lang_error('not_a_topic', false);
- $no_stat_actions = array('dlattach', 'findmember', 'jsoption', 'requestmembers', '.xml', 'xmlhttp', 'verificationcode', 'viewquery', 'viewadminfile');
- call_integration_hook('integrate_pre_log_stats', array($no_stat_actions));
- // Do some logging, unless this is an attachment, avatar, toggle of editor buttons, theme option, XML feed etc.
- if (empty($_REQUEST['action']) || !in_array($_REQUEST['action'], $no_stat_actions))
- {
- // Log this user as online.
- writeLog();
- // Track forum statistics and hits...?
- if (!empty($modSettings['hitStats']))
- trackStats(array('hits' => '+'));
- }
- unset($no_stat_actions);
- // What shall we do?
- require_once(SOURCEDIR . '/Dispatcher.class.php');
- $dispatcher = new Site_Dispatcher();
- $dispatcher->dispatch();
- }