diff options
| author | Benjamin Southall <applemansigloo@gmail.com> | 2016-09-25 16:34:47 +0900 |
|---|---|---|
| committer | Benjamin Southall <applemansigloo@gmail.com> | 2016-09-25 16:34:47 +0900 |
| commit | a3b9c4405c6d4cca2a70dbb400e3ba3f65e7ea04 (patch) | |
| tree | 5a2ebdb801748586e3fde7c12cbeda169b2c3e31 /inc/display.php | |
| parent | 9436524a306c8e3d6d8a6ed195e2a3c56d5cde39 (diff) | |
| parent | a4b619ae5eaab5755dc215a496854dee8f7ce395 (diff) | |
Merged lainchan with vichan master at 25/9/2016 a4b619ae5eaab5755dc215a496854dee8f7ce395 @czaks czaks committed on GitHub 2 days ago
Diffstat (limited to 'inc/display.php')
| -rw-r--r-- | inc/display.php | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/inc/display.php b/inc/display.php index ce39197c..58cb4805 100644 --- a/inc/display.php +++ b/inc/display.php @@ -71,6 +71,64 @@ function createBoardlist($mod=false) { ); } +function error($message, $priority = true, $debug_stuff = false) { + global $board, $mod, $config, $db_error; + + if ($config['syslog'] && $priority !== false) { + // Use LOG_NOTICE instead of LOG_ERR or LOG_WARNING because most error message are not significant. + _syslog($priority !== true ? $priority : LOG_NOTICE, $message); + } + + if (defined('STDIN')) { + // Running from CLI + echo('Error: ' . $message . "\n"); + debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); + die(); + } + + if ($config['debug'] && isset($db_error)) { + $debug_stuff = array_combine(array('SQLSTATE', 'Error code', 'Error message'), $db_error); + } + + if ($config['debug']) { + $debug_stuff['backtrace'] = debug_backtrace(); + } + + if (isset($_POST['json_response'])) { + header('Content-Type: text/json; charset=utf-8'); + die(json_encode(array( + 'error' => $message + ))); + } + else { + header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request'); + } + + $pw = $config['db']['password']; + $debug_callback = function(&$item) use (&$debug_callback, $pw) { + if (is_array($item)) { + $item = array_filter($item, $debug_callback); + } + return ($item !== $pw || !$pw); + }; + + + if ($debug_stuff) + $debug_stuff = array_filter($debug_stuff, $debug_callback); + + die(Element('page.html', array( + 'config' => $config, + 'title' => _('Error'), + 'subtitle' => _('An error has occured.'), + 'body' => Element('error.html', array( + 'config' => $config, + 'message' => $message, + 'mod' => $mod, + 'board' => isset($board) ? $board : false, + 'debug' => is_array($debug_stuff) ? str_replace("\n", ' ', utf8tohtml(print_r($debug_stuff, true))) : utf8tohtml($debug_stuff) + )) + ))); +} function loginForm($error=false, $username=false, $redirect=false) { global $config; |
