|
1
|
|
|
<?php |
|
2
|
|
|
/** @noinspection PhpDocSignatureInspection */ |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Dumps a var_dump of the passed arguments with <pre> tags surrounding it. |
|
6
|
|
|
* Dies afterwards |
|
7
|
|
|
* |
|
8
|
|
|
* @param mixed ... The data to be displayed |
|
9
|
|
|
*/ |
|
10
|
|
|
function dump() |
|
11
|
|
|
{ |
|
12
|
|
|
$debug_backtrace = current(debug_backtrace()); |
|
13
|
|
|
if (PHP_SAPI == 'cli') { |
|
14
|
|
|
echo 'Dump: ' . $debug_backtrace['file'] . ':' . $debug_backtrace['line'] . "\n"; |
|
15
|
|
|
foreach (func_get_args() as $data) { |
|
16
|
|
|
var_dump($data); |
|
17
|
|
|
} |
|
18
|
|
|
} else { |
|
19
|
|
|
ob_clean(); |
|
20
|
|
|
echo <<<END |
|
21
|
|
|
<!DOCTYPE html> |
|
22
|
|
|
<html> |
|
23
|
|
|
<head> |
|
24
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.0.0/highlight.min.js"></script> |
|
25
|
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.0.0/styles/default.min.css" /> |
|
26
|
|
|
<script>hljs.initHighlightingOnLoad();</script> |
|
27
|
|
|
<style>code.php.hljs{margin: -0.4em 0;}code.active{background-color:#e0e0e0;}code:before{content:attr(data-line);}code.active:before{color:#c00;font-weight:bold;}</style> |
|
28
|
|
|
</head> |
|
29
|
|
|
<body> |
|
30
|
|
|
END; |
|
31
|
|
|
|
|
32
|
|
|
echo '<div>Dump: ' . $debug_backtrace['file'] . ':<b>' . $debug_backtrace['line'] . "</b></div>"; |
|
33
|
|
|
echo '<pre>'; |
|
34
|
|
|
foreach (func_get_args() as $data) { |
|
35
|
|
|
echo "<code>"; |
|
36
|
|
|
var_dump($data); |
|
37
|
|
|
echo "</code>"; |
|
38
|
|
|
} |
|
39
|
|
|
echo '</pre>'; |
|
40
|
|
|
echo <<<END |
|
41
|
|
|
</body> |
|
42
|
|
|
</html> |
|
43
|
|
|
END; |
|
44
|
|
|
} |
|
45
|
|
|
die; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Minify the html for the outputbuffer |
|
50
|
|
|
* |
|
51
|
|
|
* @param $buffer |
|
52
|
|
|
* @return mixed |
|
53
|
|
|
*/ |
|
54
|
|
|
function sanitize_output($buffer) |
|
55
|
|
|
{ |
|
56
|
|
|
if (!isset($_GET['unsanitized'])) { |
|
57
|
|
|
$search = array( |
|
58
|
|
|
'/\>[^\S ]+/s', // strip whitespaces after tags, except space |
|
59
|
|
|
'/[^\S ]+\</s', // strip whitespaces before tags, except space |
|
60
|
|
|
'/(\s)+/s', // shorten multiple whitespace sequences |
|
61
|
|
|
'/<!--(.|\s)*?-->/' // Remove HTML comments |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
|
|
$replace = array( |
|
65
|
|
|
'>', |
|
66
|
|
|
'<', |
|
67
|
|
|
'\\1', |
|
68
|
|
|
'' |
|
69
|
|
|
); |
|
70
|
|
|
|
|
71
|
|
|
$buffer = preg_replace($search, $replace, $buffer); |
|
72
|
|
|
|
|
73
|
|
|
return $buffer; |
|
74
|
|
|
} else { |
|
75
|
|
|
return $buffer; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Convert all values of an array to utf8 |
|
82
|
|
|
* |
|
83
|
|
|
* @param $array |
|
84
|
|
|
* @return array |
|
85
|
|
|
*/ |
|
86
|
|
|
function utf8Convert($array) |
|
87
|
|
|
{ |
|
88
|
|
|
array_walk_recursive($array, function (&$item) { |
|
89
|
|
|
if (!mb_detect_encoding($item, 'utf-8', true)) { |
|
90
|
|
|
$item = utf8_encode($item); |
|
91
|
|
|
} |
|
92
|
|
|
}); |
|
93
|
|
|
|
|
94
|
|
|
return $array; |
|
95
|
|
|
} |