diff options
-rw-r--r-- | it.class | 2 | ||||
-rw-r--r-- | it_debug.class | 20 |
2 files changed, 13 insertions, 9 deletions
@@ -258,7 +258,7 @@ static function error($p = array(), $extra = null) if ($toscreen || $sendmail) { - $p['body'] = is_string($p['body']) || !array_key_exists('body', $p) ? $p['body'] : var_export($p['body'], true); + $p['body'] = is_string($p['body']) || !array_key_exists('body', $p) ? $p['body'] : it_debug::dump([$p['body']], ['html' => false, 'short' => true, 'color' => false]); if (strlen($p['body']) > 500000 || it::match('[\x00-\x08\x0E-\x1F]', $p['body'], ['utf8' => false]) !== null) { file_put_contents($datafn = "/tmp/alertdata/error-" . substr(md5($p['body']), 0, 2), $p['body']); # NOPHPLINT diff --git a/it_debug.class b/it_debug.class index eca38ef..b04d7b7 100644 --- a/it_debug.class +++ b/it_debug.class @@ -71,17 +71,21 @@ static function srcline($stackoffs = 0) /** * Backend for functions D(), ED() and EDX() in functions.php * @param Origargs Array containing original arguments do ED() etc + * @param $p['color'] Allow color [true] + * @param $p['html'] Allow html [default based on REMOTE_ADDR] + * @param $p['short'] Omit variable names * @return String representation of dump */ -static function dump($args) +static function dump($args, $p = []) { + $p += ['html' => $_SERVER['REMOTE_ADDR'] ? true : false, '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']) ; - else if ($_SERVER['REMOTE_ADDR']) - list($blue, $noblue, $htmlok) = array("<span style='color:#00c'>", "</span>", 1); - else if (defined('STDOUT') && posix_isatty(STDOUT)) + else if ($p['html']) + list($blue, $noblue) = $p['color'] ? ["<span style='color:#00c'>", "</span>"] : []; + else if (defined('STDOUT') && posix_isatty(STDOUT) && $p['color']) list($blue, $noblue, $red, $nored, $ansiok) = getenv('IT_ED_BRIGHT') ? array("\033[34m", "\033[m", "\033[33m", "\033[m", 1) : array("\033[34m", "\033[m", "\033[31m", "\033[m", 1); $src = it_debug::srcline(1); @@ -139,14 +143,14 @@ static function dump($args) #$item = preg_replace('#\s+var \$_(.|\n)*?;\s*\n#', "", $item); $item = "$red$item$nored"; - if ($htmlok) + if ($p['html']) $item = preg_replace("#(https?:)?//[^\s'\"]+#", "<a href='\$0'>\$0</a>", strtr($item, $htmlspecialchars)); # htmlspecialchars() does not like bad utf8 if (preg_match('/^[\'"]/', $var)) $r .= "$item "; else { - $var = "$blue$var=$noblue"; + $var = $p['short'] ? "" : "$blue$var=$noblue"; $r .= $previtem && preg_match("/\n/", $item . $previtem) ? "\n$var$item " : "$var$item "; $previtem = $item; } @@ -158,10 +162,10 @@ static function dump($args) # not it_html::Q(); we dont wanna load it_html in ultraclassloader debugging $title = htmlspecialchars(it_debug::backtrace(array('skiplevels' => 2)), ENT_COMPAT, "ISO-8859-1"); # skip this func as well as ED()/EDX() - if ($htmlok) + if ($p['html']) return "<pre title='$title' style='color:#c00; text-align:left; background:white; border-bottom:1px solid #ddd; z-index:9999; position:relative; line-height:1'>$r</pre>\n"; else - return $ansiok ? "$r\n" : "\xe2\x96\x88\xe2\x96\x8c" . preg_replace("#\n#", "\n\xe2\x96\x88 ", "$r") . "\n"; + return $ansiok || $p['short'] ? "$r\n" : "\xe2\x96\x88\xe2\x96\x8c" . preg_replace("#\n#", "\n\xe2\x96\x88 ", "$r") . "\n"; } /** |