Completed
Branch development (ad897a)
by Elk
06:53 queued 29s
created
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
// Bootstrap the system
20
use ElkArte\Controller\ScheduledTasks;
21
use ElkArte\EventManager;
22
use ElkArte\HttpReq;
23
use ElkArte\User;
24
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
Security Best Practice introduced by
It seems like you do not handle an error condition for ob_end_clean(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

57
		/** @scrutinizer ignore-unhandled */ @ob_end_clean();

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
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
// Restore post data if we are revalidating OpenID.
69
if (isset($_GET['openid_restore_post']) && !empty($_SESSION['openid']['saved_data'][$_GET['openid_restore_post']]['post']) && empty($_POST))
70
{
71
	$_POST = $_SESSION['openid']['saved_data'][$_GET['openid_restore_post']]['post'];
72
	unset($_SESSION['openid']['saved_data'][$_GET['openid_restore_post']]);
73
}
74
75
// Pre-dispatch
76
elk_main();
77
78
// Call obExit specially; we're coming from the main area ;).
79
obExit(null, null, true);
80
81
/**
82
 * The main dispatcher.
83
 * This delegates to each area.
84
 */
85
function elk_main()
86
{
87
	global $modSettings, $context;
88
89
	// A safer way to work with our form globals
90
	// @todo Use dependency injection
91
	$_req = HttpReq::instance();
92
93
	// What shall we do?
94
	$dispatcher = new ElkArte\SiteDispatcher($_req);
95
96
	if ($dispatcher->needSecurity())
97
	{
98
		// We should set our security headers now.
99
		frameOptionsHeader();
100
		securityOptionsHeader();
101
102
		// Load the user's cookie (or set as guest) and load their settings.
103
		User::load(true);
104
		$dispatcher->setUser(User::$info);
105
106
		// Load the current board's information.
107
		loadBoard();
108
109
		// Load the current user's permissions.
110
		loadPermissions();
111
112
		// Load the current theme.  (note that ?theme=1 will also work, may be used for guest theming.)
113
		if ($dispatcher->needTheme())
114
		{
115
			new ElkArte\Themes\ThemeLoader();
116
117
			// Load BadBehavior before we go much further
118
			loadBadBehavior();
119
120
			// The parser is not an object just yet
121
			loadBBCParsers();
122
		}
123
		// Otherwise don't require the entire theme to be loaded.
124
		else
125
		{
126
			detectBrowser();
127
		}
128
129
		// Check if the user should be disallowed access.
130
		is_not_banned();
131
132
		// Do some logging, unless this is an attachment, avatar, toggle of editor buttons, theme option, XML feed etc.
133
		if ($dispatcher->trackStats())
134
		{
135
			// I see you!
136
			writeLog();
137
138
			// Track forum statistics and hits...?
139
			if (!empty($modSettings['hitStats']))
140
			{
141
				trackStats(array('hits' => '+'));
142
			}
143
		}
144
145
		// Show where we came from, and go
146
		$context['site_action'] = $dispatcher->site_action();
147
	}
148
149
	$dispatcher->dispatch();
150
}
151