summaryrefslogtreecommitdiff
path: root/inc/functions.php
diff options
context:
space:
mode:
authorMichael Walker <mike@barrucadu.co.uk>2016-09-01 18:52:26 +0100
committerGitHub <noreply@github.com>2016-09-01 18:52:26 +0100
commit54d37a4c0b0a56b629dd7eb7de59d983d0b96702 (patch)
treeef5a14451235271be3b1aac4d74503c2048c1541 /inc/functions.php
parentac31e745c13e5343ebd58cb498fe9a561fa3069e (diff)
parentf0a625b238ce09a2e5f905ca64f480f38d8ca668 (diff)
Merge pull request #75 from 0xjove/error-overhaul
Error overhaul
Diffstat (limited to 'inc/functions.php')
-rwxr-xr-xinc/functions.php58
1 files changed, 7 insertions, 51 deletions
diff --git a/inc/functions.php b/inc/functions.php
index ff5d51df..e8beaba2 100755
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -12,7 +12,7 @@ if (realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) {
define('TINYBOARD', null);
$microtime_start = microtime(true);
-
+require_once 'inc/error.php';
require_once 'inc/cache.php';
require_once 'inc/display.php';
require_once 'inc/template.php';
@@ -26,11 +26,10 @@ if (!extension_loaded('gettext')) {
// the user is not currently logged in as a moderator
$mod = false;
-register_shutdown_function('fatal_error_handler');
mb_internal_encoding('UTF-8');
loadConfig();
-function init_locale($locale, $error='error') {
+function init_locale($locale) {
if (extension_loaded('gettext')) {
if (setlocale(LC_ALL, $locale) === false) {
//$error('The specified locale (' . $locale . ') does not exist on your platform!');
@@ -40,7 +39,7 @@ function init_locale($locale, $error='error') {
textdomain('tinyboard');
} else {
if (_setlocale(LC_ALL, $locale) === false) {
- $error('The specified locale (' . $locale . ') does not exist on your platform!');
+ error('The specified locale (' . $locale . ') does not exist on your platform!');
}
_bindtextdomain('tinyboard', './inc/locale');
_bind_textdomain_codeset('tinyboard', 'UTF-8');
@@ -53,8 +52,6 @@ $current_locale = 'en';
function loadConfig() {
global $board, $config, $__ip, $debug, $__version, $microtime_start, $current_locale, $events;
- $error = function_exists('error') ? 'error' : 'basic_error_function_because_the_other_isnt_loaded_yet';
-
$boardsuffix = isset($board['uri']) ? $board['uri'] : '';
if (!isset($_SERVER['REMOTE_ADDR']))
@@ -77,7 +74,7 @@ function loadConfig() {
if ($config['locale'] != $current_locale) {
$current_locale = $config['locale'];
- init_locale($config['locale'], $error);
+ init_locale($config['locale']);
}
}
else {
@@ -118,7 +115,7 @@ function loadConfig() {
}
if (!file_exists('inc/instance-config.php'))
- $error('Tinyboard is not configured! Create inc/instance-config.php.');
+ error('Tinyboard is not configured! Create inc/instance-config.php.');
// Initialize locale as early as possible
@@ -148,7 +145,7 @@ function loadConfig() {
if ($config['locale'] != $current_locale) {
$current_locale = $config['locale'];
- init_locale($config['locale'], $error);
+ init_locale($config['locale']);
}
require 'inc/config.php';
@@ -161,7 +158,7 @@ function loadConfig() {
if ($config['locale'] != $current_locale) {
$current_locale = $config['locale'];
- init_locale($config['locale'], $error);
+ init_locale($config['locale']);
}
if (!isset($config['global_message']))
@@ -271,7 +268,6 @@ function loadConfig() {
$_SERVER['REMOTE_ADDR'] = $m[2];
if ($config['verbose_errors']) {
- set_error_handler('verbose_error_handler');
error_reporting(E_ALL);
ini_set('display_errors', true);
ini_set('html_errors', false);
@@ -332,36 +328,6 @@ function loadConfig() {
}
}
-function basic_error_function_because_the_other_isnt_loaded_yet($message, $priority = true) {
- global $config;
-
- 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);
- }
-
- // Yes, this is horrible.
- die('<!DOCTYPE html><html><head><title>Error</title>' .
- '<style type="text/css">' .
- 'body{text-align:center;font-family:arial, helvetica, sans-serif;font-size:10pt;}' .
- 'p{padding:0;margin:20px 0;}' .
- 'p.c{font-size:11px;}' .
- '</style></head>' .
- '<body><h2>Error</h2>' . $message . '<hr/>' .
- '<p class="c">This alternative error page is being displayed because the other couldn\'t be found or hasn\'t loaded yet.</p></body></html>');
-}
-
-function fatal_error_handler() {
- if ($error = error_get_last()) {
- if ($error['type'] == E_ERROR) {
- if (function_exists('error')) {
- error('Caught fatal error: ' . $error['message'] . ' in <strong>' . $error['file'] . '</strong> on line ' . $error['line'], LOG_ERR);
- } else {
- basic_error_function_because_the_other_isnt_loaded_yet('Caught fatal error: ' . $error['message'] . ' in ' . $error['file'] . ' on line ' . $error['line'], LOG_ERR);
- }
- }
- }
-}
function _syslog($priority, $message) {
if (isset($_SERVER['REMOTE_ADDR'], $_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI'])) {
@@ -372,16 +338,6 @@ 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 define_groups() {
global $config;