-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.php
More file actions
105 lines (93 loc) · 3.7 KB
/
Copy pathplugin.php
File metadata and controls
105 lines (93 loc) · 3.7 KB
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
<?php
class DebugBarPlugin extends Plugin
{
public function afterSiteLoad()
{
register_shutdown_function([(new DebugBarPlugin()), 'renderDebugBar']);
}
public function afterAdminLoad()
{
register_shutdown_function([(new DebugBarPlugin()), 'renderDebugBar']);
}
public function benchmark(): string
{
$timeTaken = round((microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]), 3) . 's';
$memoryUsed = round((memory_get_usage() / 1048576), 2) . ' MB';
return "Time : $timeTaken | Mem Use: $memoryUsed";
}
/**
* (GitHub) Copy this read-only report when creating a bug report for faster resolution
*/
public function form()
{
$report = $this->getDebugReport();
echo '<h3>Report</h3>';
echo '<textarea readonly style="height: auto" rows=25>';
echo json_encode($report, JSON_PRETTY_PRINT);
echo '</textarea>';
}
public function getDebugReport(): array
{
global $site, $pluginsInstalled;
// Remove private information from report
$bluditActivePlugins = [];
if (!empty($pluginsInstalled)) {
foreach ($pluginsInstalled as $pluginName => $pluginObject) {
$bluditActivePlugins[$pluginName]['metadata'] = $pluginObject->metadata;
}
}
$serverInfo = $_SERVER;
// Remove private cookie from report
if (isset($serverInfo['HTTP_COOKIE'])) {
$serverInfo['HTTP_COOKIE'] = '';
}
return [
'bluditVersion' => BLUDIT_VERSION,
'bluditInstallationSize' => Filesystem::bytesToHumanFileSize(Filesystem::getSize(PATH_ROOT)),
'phpVersion' => phpversion(),
'phpUploadMaxFilesize' => ini_get('upload_max_filesize'),
'phpPostMaxSize' => ini_get('post_max_size'),
'phpUploadTempDir' => ini_get('upload_tmp_dir'),
'phpSessionLifetime' => ini_get('session.gc_maxlifetime'),
'bluditActiveTheme' => $site->theme(),
'bluditActivePlugins' => $bluditActivePlugins,
'phpExtensions' => get_loaded_extensions(),
'siteDb' => $site->db,
'phpServerInfo' => $serverInfo,
// Get user constants only
'phpConstants' => get_defined_constants(true)["user"]
];
}
public function renderDebugBar()
{
$includedFiles = array_map(function ($file) {
// Strip application path from filenames
return Text::replace(PATH_ROOT, '', $file);
}, get_included_files());
$includedFilesCount = count($includedFiles);
$includedFilesHtml = '<table id="includedFilesTable">';
foreach ($includedFiles as $file) {
$includedFilesHtml .= "<tr><td>$file</td></tr>";
}
$includedFilesHtml .= '</table>';
// Library: https://sweetalert2.github.io/
echo "
<script src='https://cdn.jsdelivr.net/npm/sweetalert2@10.10.4/dist/sweetalert2.all.min.js' integrity='sha256-ywfdragt7Ymli3R5hoNqyxBQ/1/2fHT2NdBRdeOwi7U=' crossorigin='anonymous'></script>
<script>
function showDebugBarIncludedFiles()
{
Swal.fire({
title: 'Included Files ({$includedFilesCount})',
html: '{$includedFilesHtml}',
confirmButtonText: 'Close',
animation: false
})
}
</script>
<style>" . file_get_contents(__DIR__ . '/css/plugin.css') . "</style>
<div class='sticky-debug-bar'>
<a onClick='showDebugBarIncludedFiles()'>Files Included ({$includedFilesCount})</a> " . $this->benchmark() . " | <a href='" . HTML_PATH_ADMIN_ROOT . "developers' target='_blank'>Developers</a>
</div>
";
}
}