Initial Commit
This commit is contained in:
84
server/debugfunctions.php
Normal file
84
server/debugfunctions.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
function errorhandler($errno, $errstr, $errfile, $errline, $errcontext){
|
||||
$fp = explode(dirname(__DIR__, 1), $errfile);
|
||||
$constants = array(
|
||||
"E_ERROR",
|
||||
"E_WARNING",
|
||||
"E_PARSE",
|
||||
"E_NOTICE",
|
||||
"E_CORE_ERROR",
|
||||
"E_CORE_WARNING",
|
||||
"E_COMPILE_ERROR",
|
||||
"E_COMPILE_WARNING",
|
||||
"E_USER_ERROR",
|
||||
"E_USER_WARNING",
|
||||
"E_USER_NOTICE",
|
||||
"E_STRICT",
|
||||
"E_RECOVERABLE_ERROR",
|
||||
"E_DEPRECATED",
|
||||
"E_USER_DEPRECATED",
|
||||
"E_ALL"
|
||||
);
|
||||
$included = array();
|
||||
foreach ($constants as $constant) {
|
||||
$value = constant($constant);
|
||||
if (($errno & $value) === $value) {
|
||||
$included[] = $constant;
|
||||
}
|
||||
}
|
||||
$description = implode(", ", $included);
|
||||
if(strpos($errstr, "sql")){
|
||||
$GLOBALS['sqlErrors'].="<span>[$description] in <b>".$fp[1]."</b> line <b>$errline</b></span>$errstr<br><br>";
|
||||
} else {
|
||||
$GLOBALS['phpErrors'].="<span>[$description] in <b>".$fp[1]."</b> line <b>$errline</b></span>$errstr<br><br>";
|
||||
}
|
||||
}
|
||||
|
||||
function alert($string){
|
||||
echo("<script>alert('" .((isset($string)) ? addslashes($string) : 'parameter not set') . "');</script>");
|
||||
}
|
||||
|
||||
function debug($var, $mode = null){
|
||||
$bt = debug_backtrace();
|
||||
$file = file($bt[0]['file']);
|
||||
$src = $file[$bt[0]['line']-1];
|
||||
$pat = '#(.*)'.__FUNCTION__.' *?\( *?(.*) *?\)(.*)#i';
|
||||
$varName = preg_replace($pat, '$2', $src);
|
||||
if($mode == null){
|
||||
$mode = "print_r";
|
||||
$varName .= ', "'.$mode.'" ';
|
||||
}
|
||||
switch($mode){
|
||||
case "print_r":
|
||||
ob_start();
|
||||
print_r($var);
|
||||
$result = ob_get_clean();
|
||||
if($result == strip_tags($result)){
|
||||
if(strpos($result, ('(')) !== false)
|
||||
$result = strstr($result, "(");
|
||||
} else {
|
||||
$result = htmlspecialchars($result);
|
||||
}
|
||||
$GLOBALS['debugData'] .= '<b>' . $varName . '</b>:<pre>'.$result.'</pre>';
|
||||
break;
|
||||
case "var_dump":
|
||||
ob_start();
|
||||
var_dump($var);
|
||||
$result = ob_get_clean();
|
||||
$result = ($result != strip_tags($result))? htmlspecialchars($result) : $result;
|
||||
$GLOBALS['debugString'] .= '<b>' . $varName . '</b>:<pre>'.$result.'</pre>';
|
||||
break;
|
||||
case "var_export":
|
||||
ob_start();
|
||||
var_export($var);
|
||||
$result = ob_get_clean();
|
||||
$result = ($result != strip_tags($result))? htmlspecialchars($result) : $result;
|
||||
$GLOBALS['debugString'] .= '<b>' . $varName . '</b>:<pre>'.$result.'</pre>';
|
||||
break;
|
||||
case "alert":
|
||||
$result = print_r($var, true);
|
||||
$GLOBALS['debugString'] .= alert(json_encode($result));
|
||||
break;
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user