summaryrefslogtreecommitdiff
path: root/inc/display.php
diff options
context:
space:
mode:
authorMichael Walker <mike@barrucadu.co.uk>2016-09-01 19:01:36 +0100
committerGitHub <noreply@github.com>2016-09-01 19:01:36 +0100
commite5a71d35735b586a4ad9ce085cd42150e191ac75 (patch)
tree5f0396986faff393c528537104d1075e8d303926 /inc/display.php
parent54d37a4c0b0a56b629dd7eb7de59d983d0b96702 (diff)
parent96ed11a536c21cd5dca1fba68a03ab1105ff1a28 (diff)
Merge pull request #76 from lainchan/revert-75-error-overhaul
Revert "Error overhaul"
Diffstat (limited to 'inc/display.php')
-rw-r--r--inc/display.php63
1 files changed, 63 insertions, 0 deletions
diff --git a/inc/display.php b/inc/display.php
index ce39197c..90cf3434 100644
--- a/inc/display.php
+++ b/inc/display.php
@@ -71,6 +71,69 @@ 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();
+ }
+
+ // Return the bad request header, necessary for AJAX posts
+ // czaks: is it really so? the ajax errors only work when this is commented out
+ // better yet use it when ajax is disabled
+ if (!isset ($_POST['json_response'])) {
+ header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
+ }
+
+ // Is there a reason to disable this?
+ if (isset($_POST['json_response'])) {
+ header('Content-Type: text/json; charset=utf-8');
+ die(json_encode(array(
+ 'error' => $message
+ )));
+ }
+
+ $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", '&#10;', utf8tohtml(print_r($debug_stuff, true))) : utf8tohtml($debug_stuff)
+ ))
+ )));
+}
function loginForm($error=false, $username=false, $redirect=false) {
global $config;