-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.php
137 lines (109 loc) · 4.77 KB
/
debug.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/**
* Bel-CMS [Content management system]
* @version 4.0.0 [PHP8.3]
* @link https://bel-cms.dev
* @link https://determe.be
* @license MIT License
* @copyright 2015-2025 Bel-CMS
* @author as Stive - [email protected]
*/
if (!defined('CHECK_INDEX')):
header($_SERVER['SERVER_PROTOCOL'] . ' 403 Direct access forbidden');
exit('<!doctype html><html><head><meta charset="utf-8"><title>BEL-CMS : Error 403 Forbidden</title><style>h1{margin: 20px auto;text-align:center;color: red;}p{text-align:center;font-weight:bold;</style></head><body><h1>HTTP Error 403 : Forbidden</h1><p>You don\'t permission to access / on this server.</p></body></html>');
endif;
function debug ($data, $exitAfter = true, $collapse = false)
{
$recursive = function($data, $level=0) use (&$recursive, $collapse) {
global $argv;
$isTerminal = isset($argv);
if (!$isTerminal && $level == 0 && !defined("DUMP_DEBUG_SCRIPT")) {
define("DUMP_DEBUG_SCRIPT", true);
echo '<script language="Javascript">function toggleDisplay(id) {';
echo 'var state = document.getElementById("container"+id).style.display;';
echo 'document.getElementById("container"+id).style.display = state == "inline" ? "none" : "inline";';
echo 'document.getElementById("plus"+id).style.display = state == "inline" ? "inline" : "none";';
echo '}</script>'."\n";
}
$type = !is_string($data) && is_callable($data) ? "Callable" : ucfirst(gettype($data));
$type_data = null;
$type_color = null;
$type_length = null;
switch ($type) {
case "String":
$type_color = "green";
$type_length = strlen($data);
$type_data = "\"" . htmlentities($data) . "\""; break;
case "Double":
case "Float":
$type = "Float";
$type_color = "#0099c5";
$type_length = strlen($data);
$type_data = htmlentities($data); break;
case "Integer":
$type_color = "red";
$type_length = strlen($data);
$type_data = htmlentities($data); break;
case "Boolean":
$type_color = "#92008d";
$type_length = strlen($data);
$type_data = $data ? "TRUE" : "FALSE"; break;
case "NULL":
$type_length = 0; break;
case "Array":
$type_length = count($data);
}
if (in_array($type, array("Object", "Array"))) {
$notEmpty = false;
foreach($data as $key => $value) {
if (!$notEmpty) {
$notEmpty = true;
if ($isTerminal) {
echo $type . ($type_length !== null ? "(" . $type_length . ")" : "")."\n";
} else {
$id = substr(md5(rand().":".$key.":".$level), 0, 8);
echo "<a href=\"javascript:toggleDisplay('". $id ."');\" style=\"text-decoration:none\">";
echo "<span style='color:red;font-weight:bold;text-align:left;'>" . $type . ($type_length !== null ? "(" . $type_length . ")" : "") . "</span>";
echo "</a>";
echo "<span id=\"plus". $id ."\" style=\"" . ($collapse ? "inline" : "none") . ";\"> ⤵</span>";
echo "<div id=\"container". $id ."\" style=\"display: " . ($collapse ? "" : "inline") . ";\">";
echo "<br />";
}
for ($i=0; $i <= $level; $i++) {
echo $isTerminal ? "| " : "<span style='color:red'>|</span> ";
}
echo $isTerminal ? "\n" : "<br />";
}
for ($i=0; $i <= $level; $i++) {
echo $isTerminal ? "| " : "<span style='color:red'>|</span> ";
}
echo $isTerminal ? "[" . $key . "] => " : "<span style='width:width:250px; float; display: inline-block;color:blue;font-weight:bold;'><i style='width:100px; display: inline-table'>[" . $key . "]</i><span style='width:25px;float:right; padding:0 10px;'> => </span></span>";
call_user_func($recursive, $value, $level+1);
}
if ($notEmpty) {
for ($i=0; $i <= $level; $i++) {
echo $isTerminal ? "| " : "<span style='color:red'>|</span> ";
}
if (!$isTerminal) {
echo "</div>";
}
} else {
echo $isTerminal ?
$type . ($type_length !== null ? "(" . $type_length . ")" : "") . " " :
"<span style='color:#666666;width:75px;display: inline-block;'>" . $type . ($type_length !== null ? "(" . $type_length . ")" : "") . "</span> ";
}
} else {
echo $isTerminal ?
$type . ($type_length !== null ? "(" . $type_length . ")" : "") . " " :
"<span style='color:#666666;width:80px;display: inline-block;text-align:right;'>" . $type . ($type_length !== null ? "(" . $type_length . ")" : "") . "</span> ";
if ($type_data != null) {
print_r($isTerminal ? $type_data : "<span style='color:" . $type_color . "; width:100px;'><i style='width: 100px;';>" . $type_data . "</i></span>");
}
}
echo $isTerminal ? "\n" : "<br />";
};
call_user_func($recursive, $data);
if ($exitAfter == true) {
die();
}
}