summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUrban Müller2022-02-14 16:58:39 +0100
committerUrban Müller2022-02-14 16:58:39 +0100
commit9f8eb21d144b9c753b96bb65d73e692089b19d74 (patch)
tree646c04dedf05d968ee366a06c9d2498e7151694f
parent485cfaf74d64584f76eab0758b11ab95ccf72fc7 (diff)
downloaditools-9f8eb21d144b9c753b96bb65d73e692089b19d74.tar.gz
itools-9f8eb21d144b9c753b96bb65d73e692089b19d74.tar.bz2
itools-9f8eb21d144b9c753b96bb65d73e692089b19d74.zip
use D() formatting for it::error body
-rw-r--r--it.class2
-rw-r--r--it_debug.class20
2 files changed, 13 insertions, 9 deletions
diff --git a/it.class b/it.class
index 2b582f7..dfefb8d 100644
--- a/it.class
+++ b/it.class
@@ -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("&" => "&amp;", '<' => "&lt;", '>' => "&gt;");
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";
}
/**