PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/index.php

https://github.com/Arantor/Elkarte
PHP | 190 lines | 98 code | 36 blank | 56 comment | 37 complexity | 57e636e6aee258e7e33aecc4ff451f62 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0
  1. <?php
  2. /**
  3. * @name ElkArte Forum
  4. * @copyright ElkArte Forum contributors
  5. * @license BSD http://opensource.org/licenses/BSD-3-Clause
  6. *
  7. * This software is a derived product, based on:
  8. *
  9. * Simple Machines Forum (SMF)
  10. * copyright: 2011 Simple Machines (http://www.simplemachines.org)
  11. * license: BSD, See included LICENSE.TXT for terms and conditions.
  12. *
  13. * @version 1.0 Alpha
  14. *
  15. * This, as you have probably guessed, is the crux for all functions.
  16. * Everything should start here, so all the setup and security is done
  17. * properly.
  18. *
  19. */
  20. $forum_version = 'ELKARTE 1.0 Alpha';
  21. // Get everything started up...
  22. define('ELKARTE', 1);
  23. if (function_exists('set_magic_quotes_runtime'))
  24. @set_magic_quotes_runtime(0);
  25. error_reporting(defined('E_STRICT') ? E_ALL | E_STRICT : E_ALL);
  26. $time_start = microtime(true);
  27. // This makes it so headers can be sent!
  28. ob_start();
  29. // Do some cleaning, just in case.
  30. foreach (array('db_character_set', 'cachedir') as $variable)
  31. if (isset($GLOBALS[$variable]))
  32. unset($GLOBALS[$variable], $GLOBALS[$variable]);
  33. // Load the settings...
  34. require_once(dirname(__FILE__) . '/Settings.php');
  35. // Make absolutely sure the new directories are defined.
  36. if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
  37. $cachedir = $boarddir . '/cache';
  38. // Time to forget about variables and go with constants!
  39. DEFINE('BOARDDIR', $boarddir);
  40. DEFINE('CACHEDIR', $cachedir);
  41. DEFINE('EXTDIR', $extdir);
  42. DEFINE('LANGUAGEDIR', $languagedir);
  43. DEFINE('SOURCEDIR', $sourcedir);
  44. DEFINE('ADMINDIR', $sourcedir . '/admin');
  45. DEFINE('CONTROLLERDIR', $sourcedir . '/controllers');
  46. DEFINE('SUBSDIR', $sourcedir . '/subs');
  47. unset($boarddir, $cachedir, $sourcedir);
  48. // And important includes.
  49. require_once(SOURCEDIR . '/QueryString.php');
  50. require_once(SOURCEDIR . '/Session.php');
  51. require_once(SOURCEDIR . '/Subs.php');
  52. require_once(SOURCEDIR . '/Errors.php');
  53. require_once(SOURCEDIR . '/Logging.php');
  54. require_once(SOURCEDIR . '/Load.php');
  55. require_once(SUBSDIR . '/Cache.subs.php');
  56. require_once(SOURCEDIR . '/Security.php');
  57. require_once(SOURCEDIR . '/BrowserDetect.class.php');
  58. require_once(SOURCEDIR . '/Errors.class.php');
  59. // If $maintenance is set specifically to 2, then we're upgrading or something.
  60. if (!empty($maintenance) && $maintenance == 2)
  61. display_maintenance_message();
  62. // Create a variable to store some specific functions in.
  63. $smcFunc = array();
  64. // Initiate 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. elk_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')
  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. // Restore post data if we are revalidating OpenID.
  97. if (isset($_GET['openid_restore_post']) && !empty($_SESSION['openid']['saved_data'][$_GET['openid_restore_post']]['post']) && empty($_POST))
  98. {
  99. $_POST = $_SESSION['openid']['saved_data'][$_GET['openid_restore_post']]['post'];
  100. unset($_SESSION['openid']['saved_data'][$_GET['openid_restore_post']]);
  101. }
  102. // Pre-dispatch
  103. elk_main();
  104. // Call obExit specially; we're coming from the main area ;).
  105. obExit(null, null, true);
  106. /**
  107. * The main dispatcher.
  108. * This delegates to each area.
  109. */
  110. function elk_main()
  111. {
  112. global $modSettings, $settings, $user_info, $board, $topic, $board_info, $maintenance;
  113. // Special case: session keep-alive, output a transparent pixel.
  114. if (isset($_GET['action']) && $_GET['action'] == 'keepalive')
  115. {
  116. header('Content-Type: image/gif');
  117. 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");
  118. }
  119. // Load the user's cookie (or set as guest) and load their settings.
  120. loadUserSettings();
  121. // Load the current board's information.
  122. loadBoard();
  123. // Load the current user's permissions.
  124. loadPermissions();
  125. // Load BadBehavior before we go much further
  126. loadBadBehavior();
  127. // Attachments don't require the entire theme to be loaded.
  128. if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach' && (!empty($modSettings['allow_guestAccess']) && $user_info['is_guest']))
  129. detectBrowser();
  130. // Load the current theme. (note that ?theme=1 will also work, may be used for guest theming.)
  131. else
  132. loadTheme();
  133. // Check if the user should be disallowed access.
  134. is_not_banned();
  135. // If we are in a topic and don't have permission to approve it then duck out now.
  136. if (!empty($topic) && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts') && ($user_info['id'] != $board_info['cur_topic_starter'] || $user_info['is_guest']))
  137. fatal_lang_error('not_a_topic', false);
  138. $no_stat_actions = array('dlattach', 'findmember', 'jsoption', 'requestmembers', '.xml', 'xmlhttp', 'verificationcode', 'viewquery', 'viewadminfile');
  139. call_integration_hook('integrate_pre_log_stats', array($no_stat_actions));
  140. // Do some logging, unless this is an attachment, avatar, toggle of editor buttons, theme option, XML feed etc.
  141. if (empty($_REQUEST['action']) || !in_array($_REQUEST['action'], $no_stat_actions))
  142. {
  143. // Log this user as online.
  144. writeLog();
  145. // Track forum statistics and hits...?
  146. if (!empty($modSettings['hitStats']))
  147. trackStats(array('hits' => '+'));
  148. }
  149. unset($no_stat_actions);
  150. // What shall we do?
  151. require_once(SOURCEDIR . '/Dispatcher.class.php');
  152. $dispatcher = new Site_Dispatcher();
  153. $dispatcher->dispatch();
  154. }