From 4fce9b63aee89c04ea0d833992e72ab75585f630 Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Fri, 2 Aug 2013 20:52:58 -0400 Subject: Major config.php cleanup and a few minor misc fixes. --- inc/display.php | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'inc/display.php') diff --git a/inc/display.php b/inc/display.php index 5da2f302..7c2665e1 100644 --- a/inc/display.php +++ b/inc/display.php @@ -319,31 +319,31 @@ class Post { // Delete if (hasPermission($config['mod']['delete'], $board['uri'], $this->mod)) - $built .= ' ' . secure_link_confirm($config['mod']['link_delete'], 'Delete', 'Are you sure you want to delete this?', $board['uri'] . '/delete/' . $this->id); + $built .= ' ' . secure_link_confirm($config['mod']['link_delete'], 'Delete', 'Are you sure you want to delete this?', $board['dir'] . 'delete/' . $this->id); // Delete all posts by IP if (hasPermission($config['mod']['deletebyip'], $board['uri'], $this->mod)) - $built .= ' ' . secure_link_confirm($config['mod']['link_deletebyip'], 'Delete all posts by IP', 'Are you sure you want to delete all posts by this IP address?', $board['uri'] . '/deletebyip/' . $this->id); + $built .= ' ' . secure_link_confirm($config['mod']['link_deletebyip'], 'Delete all posts by IP', 'Are you sure you want to delete all posts by this IP address?', $board['dir'] . 'deletebyip/' . $this->id); // Delete all posts by IP (global) if (hasPermission($config['mod']['deletebyip_global'], $board['uri'], $this->mod)) - $built .= ' ' . secure_link_confirm($config['mod']['link_deletebyip_global'], 'Delete all posts by IP across all boards', 'Are you sure you want to delete all posts by this IP address, across all boards?', $board['uri'] . '/deletebyip/' . $this->id . '/global'); + $built .= ' ' . secure_link_confirm($config['mod']['link_deletebyip_global'], 'Delete all posts by IP across all boards', 'Are you sure you want to delete all posts by this IP address, across all boards?', $board['dir'] . 'deletebyip/' . $this->id . '/global'); // Ban if (hasPermission($config['mod']['ban'], $board['uri'], $this->mod)) - $built .= ' ' . $config['mod']['link_ban'] . ''; + $built .= ' ' . $config['mod']['link_ban'] . ''; // Ban & Delete if (hasPermission($config['mod']['bandelete'], $board['uri'], $this->mod)) - $built .= ' ' . $config['mod']['link_bandelete'] . ''; + $built .= ' ' . $config['mod']['link_bandelete'] . ''; // Delete file (keep post) if (!empty($this->file) && hasPermission($config['mod']['deletefile'], $board['uri'], $this->mod)) - $built .= ' ' . secure_link_confirm($config['mod']['link_deletefile'], _('Delete file'), _('Are you sure you want to delete this file?'), $board['uri'] . '/deletefile/' . $this->id); + $built .= ' ' . secure_link_confirm($config['mod']['link_deletefile'], _('Delete file'), _('Are you sure you want to delete this file?'), $board['dir'] . 'deletefile/' . $this->id); // Edit post if (hasPermission($config['mod']['editpost'], $board['uri'], $this->mod)) - $built .= ' ' . $config['mod']['link_editpost'] . ''; + $built .= ' ' . $config['mod']['link_editpost'] . ''; if (!empty($built)) $built = '' . $built . ''; @@ -420,54 +420,54 @@ class Thread { // Mod controls (on posts) // Delete if (hasPermission($config['mod']['delete'], $board['uri'], $this->mod)) - $built .= ' ' . secure_link_confirm($config['mod']['link_delete'], _('Delete'), _('Are you sure you want to delete this?'), $board['uri'] . '/delete/' . $this->id); + $built .= ' ' . secure_link_confirm($config['mod']['link_delete'], _('Delete'), _('Are you sure you want to delete this?'), $board['dir'] . 'delete/' . $this->id); // Delete all posts by IP if (hasPermission($config['mod']['deletebyip'], $board['uri'], $this->mod)) - $built .= ' ' . secure_link_confirm($config['mod']['link_deletebyip'], _('Delete all posts by IP'), _('Are you sure you want to delete all posts by this IP address?'), $board['uri'] . '/deletebyip/' . $this->id); + $built .= ' ' . secure_link_confirm($config['mod']['link_deletebyip'], _('Delete all posts by IP'), _('Are you sure you want to delete all posts by this IP address?'), $board['dir'] . 'deletebyip/' . $this->id); // Delete all posts by IP (global) if (hasPermission($config['mod']['deletebyip_global'], $board['uri'], $this->mod)) - $built .= ' ' . secure_link_confirm($config['mod']['link_deletebyip_global'], _('Delete all posts by IP across all boards'), _('Are you sure you want to delete all posts by this IP address, across all boards?'), $board['uri'] . '/deletebyip/' . $this->id . '/global'); + $built .= ' ' . secure_link_confirm($config['mod']['link_deletebyip_global'], _('Delete all posts by IP across all boards'), _('Are you sure you want to delete all posts by this IP address, across all boards?'), $board['dir'] . 'deletebyip/' . $this->id . '/global'); // Ban if (hasPermission($config['mod']['ban'], $board['uri'], $this->mod)) - $built .= ' ' . $config['mod']['link_ban'] . ''; + $built .= ' ' . $config['mod']['link_ban'] . ''; // Ban & Delete if (hasPermission($config['mod']['bandelete'], $board['uri'], $this->mod)) - $built .= ' ' . $config['mod']['link_bandelete'] . ''; + $built .= ' ' . $config['mod']['link_bandelete'] . ''; // Delete file (keep post) if (!empty($this->file) && $this->file != 'deleted' && hasPermission($config['mod']['deletefile'], $board['uri'], $this->mod)) - $built .= ' ' . secure_link_confirm($config['mod']['link_deletefile'], _('Delete file'), _('Are you sure you want to delete this file?'), $board['uri'] . '/deletefile/' . $this->id); + $built .= ' ' . secure_link_confirm($config['mod']['link_deletefile'], _('Delete file'), _('Are you sure you want to delete this file?'), $board['dir'] . 'deletefile/' . $this->id); // Sticky if (hasPermission($config['mod']['sticky'], $board['uri'], $this->mod)) if ($this->sticky) - $built .= ' ' . $config['mod']['link_desticky'] . ''; + $built .= ' ' . $config['mod']['link_desticky'] . ''; else - $built .= ' ' . $config['mod']['link_sticky'] . ''; + $built .= ' ' . $config['mod']['link_sticky'] . ''; if (hasPermission($config['mod']['bumplock'], $board['uri'], $this->mod)) if ($this->bumplocked) - $built .= ' ' . $config['mod']['link_bumpunlock'] . ''; + $built .= ' ' . $config['mod']['link_bumpunlock'] . ''; else - $built .= ' ' . $config['mod']['link_bumplock'] . ''; + $built .= ' ' . $config['mod']['link_bumplock'] . ''; // Lock if (hasPermission($config['mod']['lock'], $board['uri'], $this->mod)) if ($this->locked) - $built .= ' ' . $config['mod']['link_unlock'] . ''; + $built .= ' ' . $config['mod']['link_unlock'] . ''; else - $built .= ' ' . $config['mod']['link_lock'] . ''; + $built .= ' ' . $config['mod']['link_lock'] . ''; if (hasPermission($config['mod']['move'], $board['uri'], $this->mod)) - $built .= ' ' . $config['mod']['link_move'] . ''; + $built .= ' ' . $config['mod']['link_move'] . ''; // Edit post if (hasPermission($config['mod']['editpost'], $board['uri'], $this->mod)) - $built .= ' ' . $config['mod']['link_editpost'] . ''; + $built .= ' ' . $config['mod']['link_editpost'] . ''; if (!empty($built)) $built = '' . $built . ''; -- cgit v1.3 From 1d37e81adeea9b2a1bc1028f2bf45b47ac045ec4 Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Sat, 3 Aug 2013 00:22:28 -0400 Subject: Better error handling/displaying with $config['debug'] and $config['verbose_errors'] --- inc/config.php | 2 +- inc/display.php | 22 +++++++++++----------- inc/functions.php | 16 ++++++++++++++-- inc/image.php | 10 +++++----- templates/error.html | 18 ++++++++++++++++++ 5 files changed, 49 insertions(+), 19 deletions(-) create mode 100644 templates/error.html (limited to 'inc/display.php') diff --git a/inc/config.php b/inc/config.php index 337d92cb..8d1c05d7 100644 --- a/inc/config.php +++ b/inc/config.php @@ -42,7 +42,7 @@ // Shows some extra information at the bottom of pages. Good for development/debugging. $config['debug'] = false; - // For development purposes. All this does is turn 'display_errors' on. + // For development purposes. Displays (and "dies" on) all errors and warnings. Turn on with the above. $config['verbose_errors'] = true; // Directory where temporary files will be created. diff --git a/inc/display.php b/inc/display.php index 7c2665e1..4972d563 100644 --- a/inc/display.php +++ b/inc/display.php @@ -57,7 +57,7 @@ function createBoardlist($mod=false) { ); } -function error($message, $priority = true) { +function error($message, $priority = true, $debug_stuff = false) { global $board, $mod, $config; if ($config['syslog'] && $priority !== false) { @@ -71,16 +71,16 @@ function error($message, $priority = true) { } die(Element('page.html', array( - 'config'=>$config, - 'title'=>_('Error'), - 'subtitle'=>_('An error has occured.'), - 'body'=>'
' . - '

' . _($message) . '

' . - (isset($board) ? - "

"._("Go back").".

" : '') . - '
' + '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) + )) ))); } diff --git a/inc/functions.php b/inc/functions.php index f000dc3c..b6bdd809 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -155,10 +155,22 @@ function loadConfig() { } if ($config['verbose_errors']) { + set_error_handler(function($errno, $errstr, $errfile, $errline) { + if (error_reporting() == 0) + return false; // Looks like this warning was suppressed by the @ operator. + error(utf8tohtml($errstr), true, array( + 'file' => $errfile, + 'line' => $errline, + 'errno' => $errno, + 'error' => $errstr, + 'backtrace' => array_slice(debug_backtrace(), 1) + )); + }); error_reporting(E_ALL); - ini_set('display_errors', 1); + ini_set('display_errors', true); + ini_set('html_errors', false); } - + // Keep the original address to properly comply with other board configurations if (!isset($__ip)) $__ip = $_SERVER['REMOTE_ADDR']; diff --git a/inc/image.php b/inc/image.php index 141973ee..4fc9d018 100644 --- a/inc/image.php +++ b/inc/image.php @@ -287,16 +287,16 @@ class ImageConvert extends ImageBase { if (trim($error = shell_exec("gifsicle --unoptimize -O2 --resize {$this->width}x{$this->height} < " . escapeshellarg($this->src . '') . " \"#0-{$config['thumb_keep_animation_frames']}\" > " . escapeshellarg($this->temp) . '2>&1 &&echo $?') !== '0') || !file_exists($this->temp)) - error($error); + error('Failed to resize image!', null, $error); } else { - if (trim($error = shell_exec('convert ' . sprintf($config['convert_args'], '', $this->width, $this->height) . ' ' . + if (trim($error = shell_exec('aconvert ' . sprintf($config['convert_args'], '', $this->width, $this->height) . ' ' . escapeshellarg($this->src) . ' ' . escapeshellarg($this->temp) . ' 2>&1 &&echo $?')) !== '0' || !file_exists($this->temp)) - error($error); + error('Failed to resize image!', null, $error); } } else { - if (trim($error = shell_exec('convert ' . sprintf($config['convert_args'], '-flatten', $this->width, $this->height) . ' ' . + if (trim($error = shell_exec('aconvert ' . sprintf($config['convert_args'], '-flatten', $this->width, $this->height) . ' ' . escapeshellarg($this->src . '[0]') . " " . escapeshellarg($this->temp) . ' 2>&1 &&echo $?')) !== '0' || !file_exists($this->temp)) - error($error); + error('Failed to resize image!', null, $error); } } } diff --git a/templates/error.html b/templates/error.html new file mode 100644 index 00000000..3b8eb693 --- /dev/null +++ b/templates/error.html @@ -0,0 +1,18 @@ +
+

{{ message }}

+ {% if board %} +

+ + {% trans 'Go back' %} + +

+ {% endif %} +
+{% if debug and config.debug %} +
+

{% trans 'Error information' %}

+
+		{{ debug }}
+	
+
+{% endif %} \ No newline at end of file -- cgit v1.3 From 056a6001aceddcf707974577d3566b1a166f01ec Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Sat, 3 Aug 2013 02:01:52 -0400 Subject: Erorr handling update --- inc/database.php | 12 ++++++------ inc/display.php | 6 +++++- inc/functions.php | 25 +++++++++++++------------ mod.php | 2 +- 4 files changed, 25 insertions(+), 20 deletions(-) (limited to 'inc/display.php') diff --git a/inc/database.php b/inc/database.php index 95dfc775..24959d0c 100644 --- a/inc/database.php +++ b/inc/database.php @@ -121,14 +121,14 @@ function query($query) { return $pdo->query($query); } -function db_error($PDOStatement=null) { - global $pdo; +function db_error($PDOStatement = null) { + global $pdo, $db_error; if (isset($PDOStatement)) { - $err = $PDOStatement->errorInfo(); - return $err[2]; + $db_error = $PDOStatement->errorInfo(); + return $db_error[2]; } - $err = $pdo->errorInfo(); - return $err[2]; + $db_error = $pdo->errorInfo(); + return $db_error[2]; } diff --git a/inc/display.php b/inc/display.php index 4972d563..dddb6559 100644 --- a/inc/display.php +++ b/inc/display.php @@ -58,7 +58,7 @@ function createBoardlist($mod=false) { } function error($message, $priority = true, $debug_stuff = false) { - global $board, $mod, $config; + 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. @@ -70,6 +70,10 @@ function error($message, $priority = true, $debug_stuff = false) { die('Error: ' . $message . "\n"); } + if ($config['debug'] && isset($db_error)) { + $debug_stuff = array_combine(array('SQLSTATE', 'Error code', 'Error message'), $db_error); + } + die(Element('page.html', array( 'config' => $config, 'title' => _('Error'), diff --git a/inc/functions.php b/inc/functions.php index b6bdd809..6c903663 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -155,19 +155,9 @@ function loadConfig() { } if ($config['verbose_errors']) { - set_error_handler(function($errno, $errstr, $errfile, $errline) { - if (error_reporting() == 0) - return false; // Looks like this warning was suppressed by the @ operator. - error(utf8tohtml($errstr), true, array( - 'file' => $errfile, - 'line' => $errline, - 'errno' => $errno, - 'error' => $errstr, - 'backtrace' => array_slice(debug_backtrace(), 1) - )); - }); + set_error_handler('verbose_error_handler'); error_reporting(E_ALL); - ini_set('display_errors', true); + ini_set('display_errors', false); ini_set('html_errors', false); } @@ -244,6 +234,17 @@ function _syslog($priority, $message) { } } +function verbose_error_handler($errno, $errstr, $errfile, $errline) { + if (error_reporting() == 0) + return false; // Looks like this warning was suppressed by the @ operator. + error(utf8tohtml($errstr), true, array( + 'file' => $errfile . ':' . $errline, + 'errno' => $errno, + 'error' => $errstr, + 'backtrace' => array_slice(debug_backtrace(), 1) + )); +} + function create_antibot($board, $thread = null) { require_once dirname(__FILE__) . '/anti-bot.php'; diff --git a/mod.php b/mod.php index ee05c349..bdc89b87 100644 --- a/mod.php +++ b/mod.php @@ -23,7 +23,7 @@ $query = isset($_SERVER['QUERY_STRING']) ? urldecode($_SERVER['QUERY_STRING']) : $pages = array( '' => ':?/', // redirect to dashboard '/' => 'dashboard', // dashboard - '/confirm/(.+)' => 'confirm', // confirm action (if javascript didn't work) + '/confir(m/(.+)' => 'confirm', // confirm action (if javascript didn't work) '/logout' => 'logout', // logout '/users' => 'users', // manage users -- cgit v1.3