@@ -39,7 +39,7 @@ |
||
39 | 39 | $error_call++; |
40 | 40 | |
41 | 41 | // are we in a loop? |
42 | - if($error_call > 2) |
|
42 | + if ($error_call > 2) |
|
43 | 43 | { |
44 | 44 | if (!isset($db_show_debug) || $db_show_debug === false) |
45 | 45 | $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); |
@@ -15,8 +15,9 @@ discard block |
||
15 | 15 | * @version 2.1 Beta 4 |
16 | 16 | */ |
17 | 17 | |
18 | -if (!defined('SMF')) |
|
18 | +if (!defined('SMF')) { |
|
19 | 19 | die('No direct access...'); |
20 | +} |
|
20 | 21 | |
21 | 22 | /** |
22 | 23 | * Log an error, if the error logging is enabled. |
@@ -41,17 +42,19 @@ discard block |
||
41 | 42 | // are we in a loop? |
42 | 43 | if($error_call > 2) |
43 | 44 | { |
44 | - if (!isset($db_show_debug) || $db_show_debug === false) |
|
45 | - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); |
|
46 | - else |
|
47 | - $backtrace = debug_backtrace(); |
|
45 | + if (!isset($db_show_debug) || $db_show_debug === false) { |
|
46 | + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); |
|
47 | + } else { |
|
48 | + $backtrace = debug_backtrace(); |
|
49 | + } |
|
48 | 50 | var_dump($backtrace); |
49 | 51 | die('Error loop.'); |
50 | 52 | } |
51 | 53 | |
52 | 54 | // Check if error logging is actually on. |
53 | - if (empty($modSettings['enableErrorLogging'])) |
|
54 | - return $error_message; |
|
55 | + if (empty($modSettings['enableErrorLogging'])) { |
|
56 | + return $error_message; |
|
57 | + } |
|
55 | 58 | |
56 | 59 | // Basically, htmlspecialchars it minus &. (for entities!) |
57 | 60 | $error_message = strtr($error_message, array('<' => '<', '>' => '>', '"' => '"')); |
@@ -59,33 +62,39 @@ discard block |
||
59 | 62 | |
60 | 63 | // Add a file and line to the error message? |
61 | 64 | // Don't use the actual txt entries for file and line but instead use %1$s for file and %2$s for line |
62 | - if ($file == null) |
|
63 | - $file = ''; |
|
64 | - else |
|
65 | - // Window style slashes don't play well, lets convert them to the unix style. |
|
65 | + if ($file == null) { |
|
66 | + $file = ''; |
|
67 | + } else { |
|
68 | + // Window style slashes don't play well, lets convert them to the unix style. |
|
66 | 69 | $file = str_replace('\\', '/', $file); |
70 | + } |
|
67 | 71 | |
68 | - if ($line == null) |
|
69 | - $line = 0; |
|
70 | - else |
|
71 | - $line = (int) $line; |
|
72 | + if ($line == null) { |
|
73 | + $line = 0; |
|
74 | + } else { |
|
75 | + $line = (int) $line; |
|
76 | + } |
|
72 | 77 | |
73 | 78 | // Just in case there's no id_member or IP set yet. |
74 | - if (empty($user_info['id'])) |
|
75 | - $user_info['id'] = 0; |
|
76 | - if (empty($user_info['ip'])) |
|
77 | - $user_info['ip'] = ''; |
|
79 | + if (empty($user_info['id'])) { |
|
80 | + $user_info['id'] = 0; |
|
81 | + } |
|
82 | + if (empty($user_info['ip'])) { |
|
83 | + $user_info['ip'] = ''; |
|
84 | + } |
|
78 | 85 | |
79 | 86 | // Find the best query string we can... |
80 | 87 | $query_string = empty($_SERVER['QUERY_STRING']) ? (empty($_SERVER['REQUEST_URL']) ? '' : str_replace($scripturl, '', $_SERVER['REQUEST_URL'])) : $_SERVER['QUERY_STRING']; |
81 | 88 | |
82 | 89 | // Don't log the session hash in the url twice, it's a waste. |
83 | - if (!empty($smcFunc['htmlspecialchars'])) |
|
84 | - $query_string = $smcFunc['htmlspecialchars']((SMF == 'SSI' || SMF == 'BACKGROUND' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string)); |
|
90 | + if (!empty($smcFunc['htmlspecialchars'])) { |
|
91 | + $query_string = $smcFunc['htmlspecialchars']((SMF == 'SSI' || SMF == 'BACKGROUND' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string)); |
|
92 | + } |
|
85 | 93 | |
86 | 94 | // Just so we know what board error messages are from. |
87 | - if (isset($_POST['board']) && !isset($_GET['board'])) |
|
88 | - $query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board']; |
|
95 | + if (isset($_POST['board']) && !isset($_GET['board'])) { |
|
96 | + $query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board']; |
|
97 | + } |
|
89 | 98 | |
90 | 99 | // What types of categories do we have? |
91 | 100 | $known_error_types = array( |
@@ -151,12 +160,14 @@ discard block |
||
151 | 160 | global $txt; |
152 | 161 | |
153 | 162 | // Send the appropriate HTTP status header - set this to 0 or false if you don't want to send one at all |
154 | - if (!empty($status)) |
|
155 | - send_http_status($status); |
|
163 | + if (!empty($status)) { |
|
164 | + send_http_status($status); |
|
165 | + } |
|
156 | 166 | |
157 | 167 | // We don't have $txt yet, but that's okay... |
158 | - if (empty($txt)) |
|
159 | - die($error); |
|
168 | + if (empty($txt)) { |
|
169 | + die($error); |
|
170 | + } |
|
160 | 171 | |
161 | 172 | log_error_online($error, false); |
162 | 173 | setup_fatal_error_context($log ? log_error($error, $log) : $error); |
@@ -183,8 +194,9 @@ discard block |
||
183 | 194 | static $fatal_error_called = false; |
184 | 195 | |
185 | 196 | // Send the status header - set this to 0 or false if you don't want to send one at all |
186 | - if (!empty($status)) |
|
187 | - send_http_status($status); |
|
197 | + if (!empty($status)) { |
|
198 | + send_http_status($status); |
|
199 | + } |
|
188 | 200 | |
189 | 201 | // Try to load a theme if we don't have one. |
190 | 202 | if (empty($context['theme_loaded']) && empty($fatal_error_called)) |
@@ -194,8 +206,9 @@ discard block |
||
194 | 206 | } |
195 | 207 | |
196 | 208 | // If we have no theme stuff we can't have the language file... |
197 | - if (empty($context['theme_loaded'])) |
|
198 | - die($error); |
|
209 | + if (empty($context['theme_loaded'])) { |
|
210 | + die($error); |
|
211 | + } |
|
199 | 212 | |
200 | 213 | $reload_lang_file = true; |
201 | 214 | // Log the error in the forum's language, but don't waste the time if we aren't logging |
@@ -231,8 +244,9 @@ discard block |
||
231 | 244 | global $settings, $modSettings, $db_show_debug; |
232 | 245 | |
233 | 246 | // Ignore errors if we're ignoring them or they are strict notices from PHP 5 (which cannot be solved without breaking PHP 4.) |
234 | - if (error_reporting() == 0 || (defined('E_STRICT') && $error_level == E_STRICT && !empty($modSettings['enableErrorLogging']))) |
|
235 | - return; |
|
247 | + if (error_reporting() == 0 || (defined('E_STRICT') && $error_level == E_STRICT && !empty($modSettings['enableErrorLogging']))) { |
|
248 | + return; |
|
249 | + } |
|
236 | 250 | |
237 | 251 | if (strpos($file, 'eval()') !== false && !empty($settings['current_include_filename'])) |
238 | 252 | { |
@@ -240,19 +254,22 @@ discard block |
||
240 | 254 | $count = count($array); |
241 | 255 | for ($i = 0; $i < $count; $i++) |
242 | 256 | { |
243 | - if ($array[$i]['function'] != 'loadSubTemplate') |
|
244 | - continue; |
|
257 | + if ($array[$i]['function'] != 'loadSubTemplate') { |
|
258 | + continue; |
|
259 | + } |
|
245 | 260 | |
246 | 261 | // This is a bug in PHP, with eval, it seems! |
247 | - if (empty($array[$i]['args'])) |
|
248 | - $i++; |
|
262 | + if (empty($array[$i]['args'])) { |
|
263 | + $i++; |
|
264 | + } |
|
249 | 265 | break; |
250 | 266 | } |
251 | 267 | |
252 | - if (isset($array[$i]) && !empty($array[$i]['args'])) |
|
253 | - $file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)'; |
|
254 | - else |
|
255 | - $file = realpath($settings['current_include_filename']) . ' (eval?)'; |
|
268 | + if (isset($array[$i]) && !empty($array[$i]['args'])) { |
|
269 | + $file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)'; |
|
270 | + } else { |
|
271 | + $file = realpath($settings['current_include_filename']) . ' (eval?)'; |
|
272 | + } |
|
256 | 273 | } |
257 | 274 | |
258 | 275 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -261,8 +278,9 @@ discard block |
||
261 | 278 | if ($error_level % 255 != E_ERROR) |
262 | 279 | { |
263 | 280 | $temporary = ob_get_contents(); |
264 | - if (substr($temporary, -2) == '="') |
|
265 | - echo '"'; |
|
281 | + if (substr($temporary, -2) == '="') { |
|
282 | + echo '"'; |
|
283 | + } |
|
266 | 284 | } |
267 | 285 | |
268 | 286 | // Debugging! This should look like a PHP error message. |
@@ -278,23 +296,27 @@ discard block |
||
278 | 296 | call_integration_hook('integrate_output_error', array($message, $error_type, $error_level, $file, $line)); |
279 | 297 | |
280 | 298 | // Dying on these errors only causes MORE problems (blank pages!) |
281 | - if ($file == 'Unknown') |
|
282 | - return; |
|
299 | + if ($file == 'Unknown') { |
|
300 | + return; |
|
301 | + } |
|
283 | 302 | |
284 | 303 | // If this is an E_ERROR or E_USER_ERROR.... die. Violently so. |
285 | - if ($error_level % 255 == E_ERROR) |
|
286 | - obExit(false); |
|
287 | - else |
|
288 | - return; |
|
304 | + if ($error_level % 255 == E_ERROR) { |
|
305 | + obExit(false); |
|
306 | + } else { |
|
307 | + return; |
|
308 | + } |
|
289 | 309 | |
290 | 310 | // If this is an E_ERROR, E_USER_ERROR, E_WARNING, or E_USER_WARNING.... die. Violently so. |
291 | - if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING) |
|
292 | - fatal_error(allowedTo('admin_forum') ? $message : $error_string, false); |
|
311 | + if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING) { |
|
312 | + fatal_error(allowedTo('admin_forum') ? $message : $error_string, false); |
|
313 | + } |
|
293 | 314 | |
294 | 315 | // We should NEVER get to this point. Any fatal error MUST quit, or very bad things can happen. |
295 | - if ($error_level % 255 == E_ERROR) |
|
296 | - die('No direct access...'); |
|
297 | -} |
|
316 | + if ($error_level % 255 == E_ERROR) { |
|
317 | + die('No direct access...'); |
|
318 | + } |
|
319 | + } |
|
298 | 320 | |
299 | 321 | /** |
300 | 322 | * It is called by {@link fatal_error()} and {@link fatal_lang_error()}. |
@@ -310,24 +332,28 @@ discard block |
||
310 | 332 | |
311 | 333 | // Attempt to prevent a recursive loop. |
312 | 334 | ++$level; |
313 | - if ($level > 1) |
|
314 | - return false; |
|
335 | + if ($level > 1) { |
|
336 | + return false; |
|
337 | + } |
|
315 | 338 | |
316 | 339 | // Maybe they came from dlattach or similar? |
317 | - if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded'])) |
|
318 | - loadTheme(); |
|
340 | + if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded'])) { |
|
341 | + loadTheme(); |
|
342 | + } |
|
319 | 343 | |
320 | 344 | // Don't bother indexing errors mate... |
321 | 345 | $context['robot_no_index'] = true; |
322 | 346 | |
323 | - if (!isset($context['error_title'])) |
|
324 | - $context['error_title'] = $txt['error_occured']; |
|
347 | + if (!isset($context['error_title'])) { |
|
348 | + $context['error_title'] = $txt['error_occured']; |
|
349 | + } |
|
325 | 350 | $context['error_message'] = isset($context['error_message']) ? $context['error_message'] : $error_message; |
326 | 351 | |
327 | 352 | $context['error_code'] = isset($error_code) ? 'id="' . $error_code . '" ' : ''; |
328 | 353 | |
329 | - if (empty($context['page_title'])) |
|
330 | - $context['page_title'] = $context['error_title']; |
|
354 | + if (empty($context['page_title'])) { |
|
355 | + $context['page_title'] = $context['error_title']; |
|
356 | + } |
|
331 | 357 | |
332 | 358 | loadTemplate('Errors'); |
333 | 359 | $context['sub_template'] = 'fatal_error'; |
@@ -335,23 +361,26 @@ discard block |
||
335 | 361 | // If this is SSI, what do they want us to do? |
336 | 362 | if (SMF == 'SSI') |
337 | 363 | { |
338 | - if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) |
|
339 | - $ssi_on_error_method(); |
|
340 | - elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) |
|
341 | - loadSubTemplate('fatal_error'); |
|
364 | + if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) { |
|
365 | + $ssi_on_error_method(); |
|
366 | + } elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) { |
|
367 | + loadSubTemplate('fatal_error'); |
|
368 | + } |
|
342 | 369 | |
343 | 370 | // No layers? |
344 | - if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) |
|
345 | - exit; |
|
371 | + if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) { |
|
372 | + exit; |
|
373 | + } |
|
346 | 374 | } |
347 | 375 | // Alternatively from the cron call? |
348 | 376 | elseif (SMF == 'BACKGROUND') |
349 | 377 | { |
350 | 378 | // We can't rely on even having language files available. |
351 | - if (defined('FROM_CLI') && FROM_CLI) |
|
352 | - echo 'cron error: ', $context['error_message']; |
|
353 | - else |
|
354 | - echo 'An error occurred. More information may be available in your logs.'; |
|
379 | + if (defined('FROM_CLI') && FROM_CLI) { |
|
380 | + echo 'cron error: ', $context['error_message']; |
|
381 | + } else { |
|
382 | + echo 'An error occurred. More information may be available in your logs.'; |
|
383 | + } |
|
355 | 384 | exit; |
356 | 385 | } |
357 | 386 | |
@@ -379,8 +408,8 @@ discard block |
||
379 | 408 | |
380 | 409 | set_fatal_error_headers(); |
381 | 410 | |
382 | - if (!empty($maintenance)) |
|
383 | - echo '<!DOCTYPE html> |
|
411 | + if (!empty($maintenance)) { |
|
412 | + echo '<!DOCTYPE html> |
|
384 | 413 | <html> |
385 | 414 | <head> |
386 | 415 | <meta name="robots" content="noindex"> |
@@ -391,6 +420,7 @@ discard block |
||
391 | 420 | ', $mmessage, ' |
392 | 421 | </body> |
393 | 422 | </html>'; |
423 | + } |
|
394 | 424 | |
395 | 425 | die(); |
396 | 426 | } |
@@ -412,15 +442,17 @@ discard block |
||
412 | 442 | // For our purposes, we're gonna want this on if at all possible. |
413 | 443 | $modSettings['cache_enable'] = '1'; |
414 | 444 | |
415 | - if (($temp = cache_get_data('db_last_error', 600)) !== null) |
|
416 | - $db_last_error = max($db_last_error, $temp); |
|
445 | + if (($temp = cache_get_data('db_last_error', 600)) !== null) { |
|
446 | + $db_last_error = max($db_last_error, $temp); |
|
447 | + } |
|
417 | 448 | |
418 | 449 | if ($db_last_error < time() - 3600 * 24 * 3 && empty($maintenance) && !empty($db_error_send)) |
419 | 450 | { |
420 | 451 | // Avoid writing to the Settings.php file if at all possible; use shared memory instead. |
421 | 452 | cache_put_data('db_last_error', time(), 600); |
422 | - if (($temp = cache_get_data('db_last_error', 600)) === null) |
|
423 | - logLastDatabaseError(); |
|
453 | + if (($temp = cache_get_data('db_last_error', 600)) === null) { |
|
454 | + logLastDatabaseError(); |
|
455 | + } |
|
424 | 456 | |
425 | 457 | // Language files aren't loaded yet :(. |
426 | 458 | $db_error = @$smcFunc['db_error']($db_connection); |
@@ -501,12 +533,14 @@ discard block |
||
501 | 533 | global $smcFunc, $user_info, $modSettings; |
502 | 534 | |
503 | 535 | // Don't bother if Who's Online is disabled. |
504 | - if (empty($modSettings['who_enabled'])) |
|
505 | - return; |
|
536 | + if (empty($modSettings['who_enabled'])) { |
|
537 | + return; |
|
538 | + } |
|
506 | 539 | |
507 | 540 | // Maybe they came from SSI or similar where sessions are not recorded? |
508 | - if (SMF == 'SSI' || SMF == 'BACKGROUND') |
|
509 | - return; |
|
541 | + if (SMF == 'SSI' || SMF == 'BACKGROUND') { |
|
542 | + return; |
|
543 | + } |
|
510 | 544 | |
511 | 545 | $session_id = !empty($user_info['is_guest']) ? 'ip' . $user_info['ip'] : session_id(); |
512 | 546 | |
@@ -532,8 +566,9 @@ discard block |
||
532 | 566 | $url = $smcFunc['json_decode']($url, true); |
533 | 567 | $url['error'] = $error; |
534 | 568 | |
535 | - if (!empty($sprintf)) |
|
536 | - $url['error_params'] = $sprintf; |
|
569 | + if (!empty($sprintf)) { |
|
570 | + $url['error_params'] = $sprintf; |
|
571 | + } |
|
537 | 572 | |
538 | 573 | $smcFunc['db_query']('', ' |
539 | 574 | UPDATE {db_prefix}log_online |
@@ -564,10 +599,11 @@ discard block |
||
564 | 599 | |
565 | 600 | $protocol = preg_match('~HTTP/1\.[01]~i', $_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'; |
566 | 601 | |
567 | - if (!isset($statuses[$code])) |
|
568 | - header($protocol . ' 500 Internal Server Error'); |
|
569 | - else |
|
570 | - header($protocol . ' ' . $code . ' ' . $statuses[$code]); |
|
571 | -} |
|
602 | + if (!isset($statuses[$code])) { |
|
603 | + header($protocol . ' 500 Internal Server Error'); |
|
604 | + } else { |
|
605 | + header($protocol . ' ' . $code . ' ' . $statuses[$code]); |
|
606 | + } |
|
607 | + } |
|
572 | 608 | |
573 | 609 | ?> |
574 | 610 | \ No newline at end of file |