From 9b0f1fe9941e4636253bb9bb77f33b5b759af29b Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Fri, 2 Nov 2007 12:56:28 +0000 Subject: extract source line procurement --- it_debug.class | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/it_debug.class b/it_debug.class index bd81720..3aedda7 100644 --- a/it_debug.class +++ b/it_debug.class @@ -52,6 +52,26 @@ function debug($text, $level = 0) } } +/** + * Get source line of grandparent calling this function + * @param $stacksoffs go up an extra $stacksoffs levels + */ + +function srcline($stackoffs = 0) +{ + $stack = debug_backtrace(); + $line = $stack[1 + $stackoffs]['line']; + $file = $stack[1 + $stackoffs]['file']; + + if (!isset($GLOBALS['it_debug::dump source'][$file])) + $GLOBALS['it_debug::dump source'][$file] = file($file); + + if (!$_SERVER['REMOTE_ADDR'] && substr($GLOBALS['it_debug::dump source'][$file][0], 0, 2) == "#!") + $line++; + + return $GLOBALS['it_debug::dump source'][$file][$line-1]; +} + /** * Backend for functions D(), ED() and EDX() in functions.php @@ -60,13 +80,6 @@ function debug($text, $level = 0) */ function dump($args) { - $stack = debug_backtrace(); - $line = $stack[1]['line']; - $file = $stack[1]['file']; - - if (!$_SERVER['REMOTE_ADDR'] && (substr(file_get_contents($file), 0, 2) == "#!")) - $line++; - if (ereg('(csv|txt|gif|jpg)', $_SERVER['PHP_SELF']) || !ereg('Mozilla', $_SERVER['HTTP_USER_AGENT'])) $plain = 1; else if ($_SERVER['REMOTE_ADDR']) @@ -82,11 +95,7 @@ function dump($args) $nored = "\033[m"; } - if (!isset($GLOBALS['it_debug::dump source'][$file])) - $GLOBALS['it_debug::dump source'][$file] = file($file); - - $src = $GLOBALS['it_debug::dump source'][$file][$line-1]; - + $src = it_debug::srcline(1); list($function, $paramlist) = it::match('\b(D|ED|EDC|EDX)\s*\((.*)', $src); $paramtokens = token_get_all("