forked from SimpleMachines/SMF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
152 lines (117 loc) · 3.89 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
/**
* This is the file where SMF gets initialized. It defines common constants,
* loads the settings in Settings.php, ensures all the directory paths are
* correct, and includes some essential source files.
*
* If this file is included by another file, the initialization is all that will
* happen. But if this file is executed directly (the typical scenario), then it
* will also instantiate and execute an SMF\Forum object.
*
*
* Simple Machines Forum (SMF)
*
* @package SMF
* @author Simple Machines https://www.simplemachines.org
* @copyright 2024 Simple Machines and individual contributors
* @license https://www.simplemachines.org/about/smf/license.php BSD
*
* @version 3.0 Alpha 2
*/
declare(strict_types=1);
/********************************************************
* Initialize things that are common to all entry points.
* (i.e. index.php, SSI.php, cron.php, proxy.php)
********************************************************/
/*
* 1. Define some constants we need.
*/
if (!defined('SMF')) {
define('SMF', 1);
}
if (!defined('SMF_VERSION')) {
define('SMF_VERSION', '3.0 Alpha 2');
}
if (!defined('SMF_FULL_VERSION')) {
define('SMF_FULL_VERSION', 'SMF ' . SMF_VERSION);
}
if (!defined('SMF_SOFTWARE_YEAR')) {
define('SMF_SOFTWARE_YEAR', '2024');
}
if (!defined('JQUERY_VERSION')) {
define('JQUERY_VERSION', '3.6.3');
}
if (!defined('POSTGRE_TITLE')) {
define('POSTGRE_TITLE', 'PostgreSQL');
}
if (!defined('MYSQL_TITLE')) {
define('MYSQL_TITLE', 'MySQL');
}
if (!defined('SMF_USER_AGENT')) {
define('SMF_USER_AGENT', 'Mozilla/5.0 (' . php_uname('s') . ' ' . php_uname('m') . ') AppleWebKit/605.1.15 (KHTML, like Gecko) SMF/' . strtr(SMF_VERSION, ' ', '.'));
}
if (!defined('TIME_START')) {
define('TIME_START', microtime(true));
}
if (!defined('SMF_SETTINGS_FILE')) {
define('SMF_SETTINGS_FILE', __DIR__ . '/Settings.php');
}
if (!defined('SMF_SETTINGS_BACKUP_FILE')) {
define('SMF_SETTINGS_BACKUP_FILE', dirname(SMF_SETTINGS_FILE) . '/' . pathinfo(SMF_SETTINGS_FILE, PATHINFO_FILENAME) . '_bak.php');
}
/*
* 2. Load the Settings.php file.
*/
if (!is_file(SMF_SETTINGS_FILE) || !is_readable(SMF_SETTINGS_FILE)) {
die('File not readable: ' . basename(SMF_SETTINGS_FILE));
}
// Don't load it twice.
if (in_array(SMF_SETTINGS_FILE, get_included_files())) {
return;
}
// If anything goes wrong loading Settings.php, make sure the admin knows it.
if (SMF === 1) {
error_reporting(E_ALL);
ob_start();
}
// This is wrapped in a closure to keep the global namespace clean.
call_user_func(function () {
require_once SMF_SETTINGS_FILE;
// Ensure $sourcedir is valid.
$sourcedir = rtrim($sourcedir, '\\/');
if ((empty($sourcedir) || !is_dir(realpath($sourcedir)))) {
$boarddir = rtrim($boarddir, '\\/');
if (empty($boarddir) || !is_dir(realpath($boarddir))) {
$boarddir = __DIR__;
}
if (is_dir($boarddir . '/Sources')) {
$sourcedir = $boarddir . '/Sources';
}
}
// We need this class, or nothing works.
if (!is_file($sourcedir . '/Config.php') || !is_readable($sourcedir . '/Config.php')) {
die('File not readable: (Sources)/Config.php');
}
// Pass all the settings to SMF\Config.
require_once $sourcedir . '/Config.php';
SMF\Config::set(get_defined_vars());
// Ensure $db_last_error is set, too.
SMF\Config::getDbLastError();
});
// Devs want all error messages, but others don't.
if (SMF === 1) {
error_reporting(!empty(SMF\Config::$db_show_debug) ? E_ALL : E_ALL & ~E_DEPRECATED);
}
/*
* 3. Load some other essential includes.
*/
require_once SMF\Config::$sourcedir . '/Autoloader.php';
// Ensure we don't trip over disabled internal functions
require_once SMF\Config::$sourcedir . '/Subs-Compat.php';
/*********************************************************************
* From this point forward, do stuff specific to normal forum loading.
*********************************************************************/
if (SMF === 1) {
(new SMF\Forum())->execute();
}
?>