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 | * @package ElkArte Forum |
||
9 | * @copyright ElkArte Forum contributors |
||
10 | * @license BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file) |
||
11 | * |
||
12 | * This file contains code covered by: |
||
13 | * copyright: 2011 Simple Machines (http://www.simplemachines.org) |
||
14 | * |
||
15 | * @version 2.0 dev |
||
16 | * |
||
17 | */ |
||
18 | |||
19 | use ElkArte\Controller\ScheduledTasks; |
||
20 | use ElkArte\EventManager; |
||
21 | use ElkArte\Helper\HttpReq; |
||
22 | use ElkArte\User; |
||
23 | |||
24 | // Bootstrap the system |
||
25 | require_once(dirname(__FILE__) . '/bootstrap.php'); |
||
26 | new Bootstrap(false); |
||
27 | |||
28 | // Turn on output buffering if it isn't already on (via php.ini for example) |
||
29 | if (!ob_get_level()) |
||
30 | { |
||
31 | ob_start(); |
||
32 | } |
||
33 | |||
34 | // Before we get carried away, are we doing a scheduled task? If so save CPU cycles by jumping out! |
||
35 | if (isset($_GET['scheduled'])) |
||
36 | { |
||
37 | // Don't make people wait on us if we can help it. |
||
38 | if (function_exists('fastcgi_finish_request')) |
||
39 | { |
||
40 | fastcgi_finish_request(); |
||
41 | } |
||
42 | |||
43 | $controller = new ScheduledTasks(new EventManager()); |
||
44 | $controller->action_autotask(); |
||
45 | } |
||
46 | |||
47 | // Check if compressed output is enabled, supported, and not already being done. |
||
48 | if (!empty($modSettings['enableCompressedOutput']) && !headers_sent()) |
||
49 | { |
||
50 | // If zlib is being used, turn off output compression. |
||
51 | if (detectServer()->outPutCompressionEnabled()) |
||
52 | { |
||
53 | $modSettings['enableCompressedOutput'] = 0; |
||
54 | } |
||
55 | else |
||
56 | { |
||
57 | @ob_end_clean(); |
||
0 ignored issues
–
show
|
|||
58 | ob_start('ob_gzhandler'); |
||
59 | } |
||
60 | } |
||
61 | |||
62 | // Register error & exception handlers. |
||
63 | new ElkArte\Errors\ErrorHandler(); |
||
64 | |||
65 | // Start the session. (assuming it hasn't already been.) |
||
66 | loadSession(); |
||
67 | |||
68 | // Pre-dispatch |
||
69 | elk_main(); |
||
70 | |||
71 | // Call obExit specially; we're coming from the main area ;). |
||
72 | obExit(null, null, true); |
||
73 | |||
74 | /** |
||
75 | * The main dispatcher. |
||
76 | * This delegates to each area. |
||
77 | */ |
||
78 | function elk_main() |
||
79 | { |
||
80 | global $modSettings, $context; |
||
81 | |||
82 | // What shall we do? |
||
83 | $dispatcher = new ElkArte\SiteDispatcher( HttpReq::instance()); |
||
84 | |||
85 | if ($dispatcher->needSecurity()) |
||
86 | { |
||
87 | // We should set our security headers now. |
||
88 | frameOptionsHeader(); |
||
89 | securityOptionsHeader(); |
||
90 | |||
91 | // Load the user's cookie (or set as guest) and load their settings. |
||
92 | User::load(true); |
||
93 | $dispatcher->setUser(User::$info); |
||
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 | // Do our BadBehavior checking before we go any further |
||
105 | if (runBadBehavior()) |
||
106 | { |
||
107 | // Not much to say, 403 and gone |
||
108 | sleep(10); |
||
109 | \ElkArte\Errors\Errors::instance()->display_403_error(true); |
||
0 ignored issues
–
show
The type
ElkArte\Errors\Errors was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
110 | } |
||
111 | |||
112 | new ElkArte\Themes\ThemeLoader(); |
||
113 | |||
114 | // The parser is not an object just yet |
||
115 | loadBBCParsers(); |
||
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 | { |
||
130 | trackStats(['hits' => '+']); |
||
131 | } |
||
132 | } |
||
133 | |||
134 | // Show where we came from, and go |
||
135 | $context['site_action'] = $dispatcher->site_action(); |
||
136 | } |
||
137 | |||
138 | $dispatcher->dispatch(); |
||
139 | } |
||
140 |
If you suppress an error, we recommend checking for the error condition explicitly: