elkarte /
Elkarte
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * This, as you have probably guessed, is the crux for all functions. |
||
| 5 | * Everything should start here, so all the setup and security is done |
||
| 6 | * properly. |
||
| 7 | * |
||
| 8 | * @name ElkArte Forum |
||
| 9 | * @copyright ElkArte Forum contributors |
||
| 10 | * @license BSD http://opensource.org/licenses/BSD-3-Clause |
||
| 11 | * |
||
| 12 | * This file contains code covered by: |
||
| 13 | * copyright: 2011 Simple Machines (http://www.simplemachines.org) |
||
| 14 | * license: BSD, See included LICENSE.TXT for terms and conditions. |
||
| 15 | * |
||
| 16 | * @version 1.1.1 |
||
| 17 | * |
||
| 18 | */ |
||
| 19 | |||
| 20 | // Bootstrap the system |
||
| 21 | require_once(dirname(__FILE__) . '/bootstrap.php'); |
||
| 22 | new Bootstrap(false); |
||
| 23 | |||
| 24 | // Turn on output buffering if it isn't already on (via php.ini for example) |
||
| 25 | if (!ob_get_level()) |
||
| 26 | ob_start(); |
||
| 27 | |||
| 28 | // Before we get carried away, are we doing a scheduled task? If so save CPU cycles by jumping out! |
||
| 29 | if (isset($_GET['scheduled'])) |
||
| 30 | { |
||
| 31 | // Don't make people wait on us if we can help it. |
||
| 32 | if (function_exists('fastcgi_finish_request')) |
||
| 33 | fastcgi_finish_request(); |
||
| 34 | |||
| 35 | $controller = new ScheduledTasks_Controller(); |
||
| 36 | $controller->action_autotask(); |
||
| 37 | } |
||
| 38 | |||
| 39 | // Check if compressed output is enabled, supported, and not already being done. |
||
| 40 | if (!empty($modSettings['enableCompressedOutput']) && !headers_sent()) |
||
| 41 | { |
||
| 42 | // If zlib is being used, turn off output compression. |
||
| 43 | if (detectServer()->outPutCompressionEnabled()) |
||
| 44 | $modSettings['enableCompressedOutput'] = 0; |
||
| 45 | else |
||
| 46 | { |
||
| 47 | @ob_end_clean(); |
||
|
0 ignored issues
–
show
|
|||
| 48 | ob_start('ob_gzhandler'); |
||
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | // Register error & exception handlers. |
||
| 53 | new ElkArte\Errors\ErrorHandler; |
||
| 54 | |||
| 55 | // Start the session. (assuming it hasn't already been.) |
||
| 56 | loadSession(); |
||
| 57 | |||
| 58 | // Restore post data if we are revalidating OpenID. |
||
| 59 | if (isset($_GET['openid_restore_post']) && !empty($_SESSION['openid']['saved_data'][$_GET['openid_restore_post']]['post']) && empty($_POST)) |
||
| 60 | { |
||
| 61 | $_POST = $_SESSION['openid']['saved_data'][$_GET['openid_restore_post']]['post']; |
||
| 62 | unset($_SESSION['openid']['saved_data'][$_GET['openid_restore_post']]); |
||
| 63 | } |
||
| 64 | |||
| 65 | // Pre-dispatch |
||
| 66 | elk_main(); |
||
| 67 | |||
| 68 | // Call obExit specially; we're coming from the main area ;). |
||
| 69 | obExit(null, null, true); |
||
| 70 | |||
| 71 | /** |
||
| 72 | * The main dispatcher. |
||
| 73 | * This delegates to each area. |
||
| 74 | */ |
||
| 75 | function elk_main() |
||
| 76 | { |
||
| 77 | global $modSettings, $context; |
||
| 78 | |||
| 79 | // A safer way to work with our form globals |
||
| 80 | // @todo Use a DIC |
||
| 81 | $_req = HttpReq::instance(); |
||
| 82 | |||
| 83 | // What shall we do? |
||
| 84 | $dispatcher = new Site_Dispatcher($_req); |
||
| 85 | |||
| 86 | if ($dispatcher->needSecurity()) |
||
| 87 | { |
||
| 88 | // We should set our security headers now. |
||
| 89 | frameOptionsHeader(); |
||
| 90 | securityOptionsHeader(); |
||
| 91 | |||
| 92 | // Load the user's cookie (or set as guest) and load their settings. |
||
| 93 | loadUserSettings(); |
||
| 94 | |||
| 95 | // Load the current board's information. |
||
| 96 | loadBoard(); |
||
| 97 | |||
| 98 | // Load the current user's permissions. |
||
| 99 | loadPermissions(); |
||
| 100 | |||
| 101 | // Load the current theme. (note that ?theme=1 will also work, may be used for guest theming.) |
||
| 102 | if ($dispatcher->needTheme()) |
||
| 103 | { |
||
| 104 | loadTheme(); |
||
| 105 | |||
| 106 | // Load BadBehavior before we go much further |
||
| 107 | loadBadBehavior(); |
||
| 108 | |||
| 109 | // The parser is not a DIC just yet |
||
| 110 | loadBBCParsers(); |
||
| 111 | } |
||
| 112 | // Otherwise don't require the entire theme to be loaded. |
||
| 113 | else |
||
| 114 | { |
||
| 115 | detectBrowser(); |
||
| 116 | } |
||
| 117 | |||
| 118 | // Check if the user should be disallowed access. |
||
| 119 | is_not_banned(); |
||
| 120 | |||
| 121 | // Do some logging, unless this is an attachment, avatar, toggle of editor buttons, theme option, XML feed etc. |
||
| 122 | if ($dispatcher->trackStats()) |
||
| 123 | { |
||
| 124 | // I see you! |
||
| 125 | writeLog(); |
||
| 126 | |||
| 127 | // Track forum statistics and hits...? |
||
| 128 | if (!empty($modSettings['hitStats'])) |
||
| 129 | trackStats(array('hits' => '+')); |
||
| 130 | } |
||
| 131 | |||
| 132 | // Show where we came from, and go |
||
| 133 | $context['site_action'] = $dispatcher->site_action(); |
||
| 134 | } |
||
| 135 | |||
| 136 | $dispatcher->dispatch(); |
||
| 137 | } |
If you suppress an error, we recommend checking for the error condition explicitly: