diff options
-rw-r--r-- | auto_prepend.php | 7 | ||||
-rw-r--r-- | it_debug.class | 18 |
2 files changed, 19 insertions, 6 deletions
diff --git a/auto_prepend.php b/auto_prepend.php index f05a4c2..4c6a308 100644 --- a/auto_prepend.php +++ b/auto_prepend.php @@ -15,9 +15,7 @@ function D(...$args) */ function ED(...$args) { - if (ob_get_level() == 0 && $_SERVER['REMOTE_ADDR']) - ob_start(); # prevent later 'headers already sent' error - $GLOBALS['debug_noredir'] = 1; + it_debug::setup(); echo it_debug::dump($args); return $args[0]; } @@ -34,8 +32,7 @@ function EDC($var, ...$args) { if ($args) { - if (ob_get_level() == 0 && $_SERVER['REMOTE_ADDR']) - ob_start(); # prevent later 'headers already sent' error + it_debug::setup(); echo it_debug::dump($args); } diff --git a/it_debug.class b/it_debug.class index 8894170..136ea99 100644 --- a/it_debug.class +++ b/it_debug.class @@ -25,6 +25,7 @@ class it_debug { var $level; + static $force_html; /** * Constructor @@ -67,6 +68,21 @@ static function srcline($stackoffs = 0) return $GLOBALS['it_debug::dump source'][$file][$line-1]; } +/** + * Prepare for debug output being echoed + */ +static function setup() +{ + $GLOBALS['debug_noredir'] = 1; + + if (ob_get_level() == 0 && $_SERVER['REMOTE_ADDR']) + ob_start(); # prevent later 'headers already sent' error + + if ($_SERVER['REMOTE_ADDR'] && !EDC('edplain') && !it::match('curl|wget', $_SERVER['HTTP_USER_AGENT'])) + self::$force_html = true; +} + + /** * Backend for functions D(), ED() and EDX() in functions.php @@ -78,7 +94,7 @@ static function srcline($stackoffs = 0) */ static function dump($args, $p = []) { - $p += ['html' => $_SERVER['REMOTE_ADDR'] && !it::match('\.(xml|json|plist|itjs|txt|raw|csv)$', $_SERVER['PHP_SELF']) ? true : false, 'color' => true]; + $p += ['html' => !EDC('edplain') && (self::$force_html || $_SERVER['REMOTE_ADDR']), 'color' => true]; $htmlspecialchars = array("&" => "&", '<' => "<", '>' => ">"); if ((preg_match('/csv|txt|gif|jpg/', $_SERVER['PHP_SELF']) || preg_grep('#text/(calendar|css|javascript|json|plain|rfc822|xml)|application/#', headers_list()) || $GLOBALS['debug_edplain']) && !$GLOBALS['debug_edhtml']) |