-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.php
278 lines (231 loc) · 8.26 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<?php
/**
* Welcome to Wedge.
*
* Wedge (http://wedge.org)
* Copyright © 2010 René-Gilles Deberdt, wedge.org
* Portions are © 2011 Simple Machines.
* License: http://wedge.org/license/
*/
if (defined('WEDGE'))
return;
define('WEDGE_VERSION', '1.0-beta');
define('WEDGE', 5); // Internal snapshot number.
// Get everything started up...
if (version_compare(PHP_VERSION, '5.4') < 0)
exit('You need at least PHP 5.4 on your server to use Wedge!');
error_reporting(E_ALL);
@ini_set('display_errors', '1');
@ini_set('memory_limit', '128M');
$time_start = microtime(true);
// Makes sure that headers can be sent!
ob_start();
define('ROOT_DIR', str_replace('\\', '/', dirname(__FILE__)));
define('APP_DIR', ROOT_DIR . '/core/app');
// Is it our first run..?
if (!file_exists(ROOT_DIR . '/Settings.php'))
{
require_once(ROOT_DIR . '/core/app/OriginalFiles.php');
create_settings_file();
create_generic_folders();
create_main_htaccess();
}
// Load our settings...
require_once(ROOT_DIR . '/Settings.php');
// And important files.
loadSource(array(
'Class-System',
'QueryString',
'Subs',
'Errors',
'Load',
'Security',
));
// Are we installing, or doing something that needs the forum to be down?
if (!empty($maintenance) && $maintenance > 1)
{
if ($maintenance == 2) // Installing
require_once(ROOT_DIR . '/install/install.php');
else // Downtime
show_db_error();
return;
}
// Load paths.
loadConstants();
// Initiate the database connection.
loadDatabase();
// Upgrade if the latest version needs it.
if (empty($we_shot) || $we_shot < WEDGE)
{
loadSource('Upgrade');
upgrade_db();
}
// Load the actions and database settings, and perform operations
// like optimizing or running scheduled tasks.
loadSettings();
// Register an error handler.
set_error_handler('error_handler');
// Start the session, if it hasn't already been.
loadSession();
$action = isset($_GET['action']) ? $_GET['action'] : '';
// Special case: session keep-alive, do nothing.
if ($action === 'keepalive')
exit;
// Allow modifying $action_list/$action_no_log globals easily.
call_hook('action_list');
$context['action'] = $action = isset($action_list[$action]) ? $action : (isset($settings['default_action'], $action_list[$settings['default_action']]) ? $settings['default_action'] : '');
$context['subaction'] = isset($_GET['sa']) ? $_GET['sa'] : null;
// Load the user's cookie (or set as guest) and load their settings.
we::getInstance();
// Check the request for anything hinky.
checkUserBehavior();
// Allow plugins to check for the request as well, and manipulate $action.
call_hook('behavior', array(&$action));
// Last chance to get the board ID if we have a default one. Use the 'behavior' hook to force it.
if (empty($action) && empty($board) && empty($topic))
{
if (isset($_GET['category']) && is_numeric($_GET['category']))
$action = 'boards';
elseif (isset($settings['homepage_type']) && $settings['homepage_type'] == 'board')
$board = (int) $settings['homepage_board'];
}
// Load the current board's information.
loadBoard();
// Load the current user's permissions.
loadPermissions();
// Load the current theme. Note that ?theme=1 will also work, may be used for guest theming.
// Attachments don't require the entire theme to be loaded.
if ($action !== 'dlattach' || empty($settings['allow_guestAccess']) || we::$is_member)
loadTheme();
// Check if the user should be disallowed access.
is_not_banned();
// If we are in a topic and don't have permission to approve it then duck out now.
if (!empty($topic) && $action !== 'feed' && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts'))
if (MID != $board_info['cur_topic_starter'] || we::$is_guest)
fatal_lang_error('not_a_topic', false);
// Do some logging, unless this is an attachment, avatar, toggle of editor buttons, theme option, XML feed etc.
if (!$action || !in_array($action, $action_no_log))
{
// Log this user as online.
writeLog();
// Track forum statistics and hits...?
if (!empty($settings['hitStats']))
trackStats(array('hits' => '+'));
}
// What function shall we execute? (Done this way for memory's sake.)
call_user_func(determine_action($action));
wetem::add('sidebar', 'sidebar_quick_access');
// Just quickly sneak the feed stuff in...
if (!empty($settings['xmlnews_enable']) && !empty($settings['xmlnews_sidebar']) && (!empty($settings['allow_guestAccess']) || we::$is_member) && function_exists('template_sidebar_feed'))
wetem::add('sidebar', 'sidebar_feed');
// I have only one thing to say to you... Bye!
obExit(null, null, true);
// Loads a named file from the app folder. Uses cache if possible.
// $source_name can be a string or an array of strings.
function loadSource($source_name)
{
global $db_show_debug;
static $done = array();
foreach ((array) $source_name as $file)
{
if (isset($done[$file]))
continue;
$dest = APP_DIR . '/' . $file . '.php';
if (defined('WEDGE_INSTALL') || $file === 'Subs-CachePHP' || strpos($file, 'getid3') !== false)
$cache = $dest;
else
{
$cache = ROOT_DIR . '/gz/app/' . str_replace(array('/', '..'), array('_', 'UP'), $file) . '.php';
if (!file_exists($cache) || filemtime($cache) < filemtime($dest))
{
loadSource('Subs-CachePHP');
cache_source_file($dest, $cache);
}
}
require_once($cache);
$done[$file] = true;
}
}
function determine_action($action)
{
global $settings, $board, $topic, $maintenance, $action_list;
// Is the forum in maintenance mode? (doesn't apply to administrators.)
if (!empty($maintenance) && !allowedTo('admin_forum'))
{
// You can only login.... otherwise, you're getting the "maintenance mode" display.
if ($action === 'login2' || $action === 'logout')
{
loadSource($action = ucfirst($action));
return $action;
}
// Welcome. You are unauthorized. Your death will now be implemented.
else
{
loadSource('Subs-Auth');
return 'InMaintenance';
}
}
// If guest access is off, a guest can only do one of the very few following actions.
elseif (empty($settings['allow_guestAccess']) && we::$is_guest && (empty($action) || !in_array($action, array('coppa', 'login', 'login2', 'register', 'register2', 'reminder', 'activate', 'verification'))))
{
loadSource('Subs-Auth');
return 'KickGuest';
}
// The user might need to reagree to the agreement; post2 is here for draft compatibility, and PMs so that you can discuss said agreement.
elseif (!empty($settings['agreement_force']) && (we::$user['activated'] == 6 && !we::$is_admin) && (empty($action) || !in_array($action, array('login', 'login2', 'logout', 'reminder', 'activate', 'post2', 'pm'))))
{
loadSource('Subs-Auth');
return 'Reagree';
}
// Or not...
elseif (empty($action))
{
// Action and board are both empty... Go home!
if (empty($board) && empty($topic))
return index_action();
// Topic is empty, and action is empty.... MessageIndex!
if (empty($topic))
{
loadSource('MessageIndex');
return 'MessageIndex';
}
// Board is not empty... topic is not empty... action is empty.. Display!
else
{
loadSource('Display');
return 'Display';
}
}
// Get the function and file to include - if it's not there, do the board index.
if (!isset($action_list[$action]))
return index_action('fallback_action');
// Otherwise, it was set - so let's go to that action.
$target = (array) $action_list[$action];
if (isset($target[2]))
loadPluginSource($target[2], $target[0]);
else
loadSource($target[0]);
// Remember, if the function is the same as the filename, you may declare it just once.
return isset($target[1]) ? $target[1] : $target[0];
}
function index_action($hook_action = 'default_action')
{
global $settings;
// Some plugins may want to specify default "front page" behavior through the 'default_action' hook, and/or a
// last-minute fallback ('fallback_action'). If they do, they shall return the name of the function they want to call.
foreach (call_hook($hook_action) as $func)
if (!empty($func) && is_callable($func))
return $func;
// Otherwise, if the admin specified a custom homepage, fall back to it.
$ret = 'Home';
if (!empty($settings['homepage_type']))
{
$type = $settings['homepage_type'];
if ($type == 'action' && file_exists(APP_DIR . '/' . $settings['homepage_action'] . '.php'))
$ret = $settings['homepage_action'];
elseif ($type == 'boardlist')
$ret = 'Boards';
}
loadSource($ret);
return $ret;
}