|
|
@@ -2,30 +2,22 @@
|
|
|
|
|
|
class debug
|
|
|
{
|
|
|
-
|
|
|
private static $logs = [];
|
|
|
private static $startTime;
|
|
|
private static $closeTime;
|
|
|
|
|
|
private static function typeFile(string $_string){
|
|
|
switch ($_string) {
|
|
|
- case 'debug':
|
|
|
- return FILE_DEBUG;
|
|
|
- break;
|
|
|
case 'maintenance':
|
|
|
- return FILE_MAINTENANCE;
|
|
|
+ return ".lock-maintenance";
|
|
|
break;
|
|
|
- case 'submit':
|
|
|
- return FILE_DEBUG_SUBMIT;
|
|
|
- break;
|
|
|
- case 'sql':
|
|
|
- return FILE_DEBUG_SQL;
|
|
|
+ case 'debug':
|
|
|
+ return ".active-debug";
|
|
|
break;
|
|
|
default:
|
|
|
- return NULL;
|
|
|
+ return ".active-debug-".$_string;
|
|
|
break;
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public static function addFile(string $_string = NULL)
|
|
|
@@ -38,17 +30,14 @@ class debug
|
|
|
|
|
|
public static function removeFile(string $_string = NULL)
|
|
|
{
|
|
|
- unlink(DOCUMENT_ROOT . self::typeFile($_string));
|
|
|
+ if($_string != NULL){
|
|
|
+ unlink(DOCUMENT_ROOT . self::typeFile($_string));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public static function isFile(string $_string = NULL)
|
|
|
{
|
|
|
- return (file_exists(DOCUMENT_ROOT . self::typeFile($_string))) ? TRUE : FALSE;
|
|
|
- }
|
|
|
-
|
|
|
- public static function isSubmit()
|
|
|
- {
|
|
|
- return (file_exists(DOCUMENT_ROOT . FILE_DEBUG_SUBMIT)) ? TRUE : FALSE;
|
|
|
+ return file_exists(DOCUMENT_ROOT . self::typeFile($_string)) ? TRUE : FALSE;
|
|
|
}
|
|
|
|
|
|
public static function includeDebug()
|
|
|
@@ -64,7 +53,7 @@ class debug
|
|
|
ob_start();
|
|
|
|
|
|
echo "<pre class='debug-dump'>";
|
|
|
- echo "<strong>$label:</strong> ";
|
|
|
+ echo "<strong>" . $label . ":</strong> ";
|
|
|
|
|
|
// Convert array or object to string
|
|
|
if (is_array($var)) {
|
|
|
@@ -176,6 +165,43 @@ class debug
|
|
|
($_exit != NULL) ? exit() : NULL;
|
|
|
}
|
|
|
|
|
|
+ public static function isHtml(string $_string) : bool
|
|
|
+ {
|
|
|
+ $stripped_string = strip_tags($_string);
|
|
|
+ return $_string !== $stripped_string;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function generateHtmlContent($htmlContent)
|
|
|
+ {
|
|
|
+ $id = md5(microtime());
|
|
|
+ return <<<HTML
|
|
|
+ <!DOCTYPE html>
|
|
|
+ <html>
|
|
|
+ <head>
|
|
|
+ <title>Exécution de HTML</title>
|
|
|
+ <style>
|
|
|
+ .isolated-iframe {
|
|
|
+ width: 100%;
|
|
|
+ height: 300px;
|
|
|
+ border: none;
|
|
|
+ }
|
|
|
+ </style>
|
|
|
+ </head>
|
|
|
+ <body>
|
|
|
+ <iframe id="isolatedIframe-$id" class="isolated-iframe"></iframe>
|
|
|
+ <script>
|
|
|
+ var iframe = document.getElementById('isolatedIframe-$id');
|
|
|
+ var doc = iframe.document || iframe.contentDocument || iframe.contentWindow.document;
|
|
|
+ doc.open();
|
|
|
+ doc.write(`{$htmlContent}`);
|
|
|
+ doc.close();
|
|
|
+ </script>
|
|
|
+ </body>
|
|
|
+ </html>
|
|
|
+ HTML;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public static function log($_message, $_mark = NULL)
|
|
|
{
|
|
|
$mark = "<div class='debug-head-console'>";
|
|
|
@@ -184,13 +210,15 @@ class debug
|
|
|
$mark .= "</div>";
|
|
|
if($_message != NULL) {
|
|
|
if(is_array($_message)){
|
|
|
- self::$logs[] = $mark ."<div class='debug-console'>" . self::arrayToString($_message) . "</div>";
|
|
|
+ self::$logs[] = ["data" => $mark ."<div class='debug-console'>" . self::arrayToString($_message) . "</div>", "nl2br" => TRUE];
|
|
|
} elseif(is_object($_message)){
|
|
|
- self::$logs[] = $mark ."<div class='debug-console'>" . self::objectToString($_message) . "</div>";
|
|
|
+ self::$logs[] = ["data" => $mark ."<div class='debug-console'>" . self::objectToString($_message) . "</div>", "nl2br" => TRUE];
|
|
|
+ } elseif(self::isHtml($_message)){
|
|
|
+ self::$logs[] = ["data" => $mark ."<div class='debug-console'>" . self::generateHtmlContent($_message) . "</div>", "nl2br" => FALSE];
|
|
|
} elseif($mark != NULL){
|
|
|
- self::$logs[] = $mark ."<div class='debug-console' style='color:blue;'>" . $_message . "</div>";
|
|
|
+ self::$logs[] = ["data" => $mark ."<div class='debug-console' style='color:blue;'>" . $_message . "</div>", "nl2br" => TRUE];
|
|
|
} else {
|
|
|
- self::$logs[] = $_message;
|
|
|
+ self::$logs[] = ["data" => $_message, "nl2br" => TRUE];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -203,13 +231,15 @@ class debug
|
|
|
$mark .= "</div>";
|
|
|
if($_message != NULL) {
|
|
|
if(is_array($_message)){
|
|
|
- self::setSession($mark ."<div class='debug-console'>" . self::arrayToString($_message) . "</div>");
|
|
|
+ self::setSession(["data" => $mark ."<div class='debug-console'>" . self::arrayToString($_message) . "</div>", "nl2br" => TRUE]);
|
|
|
} elseif(is_object($_message)){
|
|
|
- self::setSession($mark ."<div class='debug-console'>" . self::objectToString($_message) . "</div>");
|
|
|
+ self::setSession(["data" => $mark ."<div class='debug-console'>" . self::objectToString($_message) . "</div>", "nl2br" => TRUE]);
|
|
|
+ } elseif(self::isHtml($_message)){
|
|
|
+ self::setSession(["data" => $mark ."<div class='debug-console'>" . self::generateHtmlContent($_message) . "</div>", "nl2br" => false]);
|
|
|
} elseif($mark != NULL){
|
|
|
- self::setSession($mark ."<div class='debug-console' style='color:blue;'>" . $_message . "</div>");
|
|
|
+ self::setSession(["data" => $mark ."<div class='debug-console' style='color:blue;'>" . $_message . "</div>", "nl2br" => TRUE]);
|
|
|
} else {
|
|
|
- self::setSession($_message);
|
|
|
+ self::setSession(["data" => $_message, "nl2br" => TRUE]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -219,26 +249,36 @@ class debug
|
|
|
echo "<div id='debugger-logs'>";
|
|
|
|
|
|
echo "<div class='debug-renderLogs-header'>";
|
|
|
- echo "PHP ". phpversion() . " | MYSQL " . db::version() . " | " . number_format(self::$closeTime, 4) . " secondes ";
|
|
|
+ echo "PHP <span style=\"font-weight: bold;\">". phpversion() . "</span> | MYSQL <span style=\"font-weight: bold;\">" . db::version() . "</span> | " . number_format(self::$closeTime, 4) . " secondes ";
|
|
|
echo "</div>";
|
|
|
echo "<div class=\"form-check form-switch\" style=\"margin-top: -30px;\">
|
|
|
<div>
|
|
|
<input class=\"form-check-input\" type=\"checkbox\" id=\"checkIsSubmit\" " . core::checkboxSelecter(self::isFile("submit"), 0) . " >
|
|
|
- <label class=\"form-check-label\" for=\"checkIsSubmit\">Intercepter les Submit</label>
|
|
|
+ <label class=\"form-check-label\" for=\"checkIsSubmit\">Intercepter les <span style=\"font-weight: bold;\">Submit</span></label>
|
|
|
</div>
|
|
|
<div>
|
|
|
<input class=\"form-check-input\" type=\"checkbox\" id=\"checkIsSql\" " . core::checkboxSelecter(self::isFile("sql"), 0) . " >
|
|
|
- <label class=\"form-check-label\" for=\"checkIsSql\">Intercepter les requêtes SQL</label>
|
|
|
+ <label class=\"form-check-label\" for=\"checkIsSql\">Intercepter les <span style=\"font-weight: bold;\">requêtes SQL</span></label>
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <input class=\"form-check-input\" type=\"checkbox\" id=\"checkIsEmail\" " . core::checkboxSelecter(self::isFile("email"), 0) . " >
|
|
|
+ <label class=\"form-check-label\" for=\"checkIsEmail\">Intercepter les <span style=\"font-weight: bold;\">Email</span></label>
|
|
|
</div>
|
|
|
</div>";
|
|
|
|
|
|
foreach (self::$logs as $log) {
|
|
|
- echo ($log != NULL) ? "<div class='debug-renderLogs-print'>".nl2br($log)."</div>" : NULL;
|
|
|
+ if($log != NULL){
|
|
|
+ echo "<div class='debug-renderLogs-print'>";
|
|
|
+ echo $log["nl2br"] == TRUE ? nl2br($log["data"]) : $log["data"];
|
|
|
+ echo "</div>";
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if(self::ifSession()){
|
|
|
foreach (self::getSession() as $logSession) {
|
|
|
- echo ($logSession != NULL) ? "<div class='debug-renderLogs-print'>".nl2br($logSession)."</div>" : NULL;
|
|
|
+ echo "<div class='debug-renderLogs-print'>";
|
|
|
+ echo $logSession["nl2br"] == TRUE ? nl2br($logSession["data"]) : $logSession["data"];
|
|
|
+ echo "</div>";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -273,7 +313,7 @@ class debug
|
|
|
}
|
|
|
|
|
|
private static function buildBadge(array $_data){
|
|
|
- $color = empty($_data["color"]) ? "balck" : $_data["color"];
|
|
|
+ $color = empty($_data["color"]) ? "black" : $_data["color"];
|
|
|
$backgroundColor = empty($_data["background-color"]) ? "orangered" : $_data["background-color"];
|
|
|
$class = empty($_data["class"]) ? NULL : $_data["class"];
|
|
|
$link = empty($_data["link"]) ? "#" : $_data["link"];
|