-
Notifications
You must be signed in to change notification settings - Fork 2
/
Panel.php
87 lines (78 loc) · 2.16 KB
/
Panel.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
<?php
/**
* Galahad Query Tracer Panel
* @author Chris Morrell <http://cmorrell.com/>
*/
class Galahad_Query_Tracer_Panel extends Debug_Bar_Panel
{
/**
* Initialize Panel
*/
public function init() {
$this->title(__('Query Tracer', 'galahad-query-tracer'));
}
/**
* Determine whether panel should render
*/
public function prerender() {
$this->set_visible(is_admin());
}
/**
* Render Panel
*/
public function render() {
?>
<style type="text/css">
#galahad-tracer h2 { float: none; border: none; text-align: left; padding: 0; }
#galahad-tracer h3 { margin-left: 15px; font-size: 1.7em; font-weight: bold; }
#galahad-tracer table { max-width: 100%; margin-bottom: 1em; margin-left: 30px; }
#galahad-tracer table, #galahad-tracer th, #galahad-tracer td { border: 1px solid #ccc; border-collapse: collapse; }
#galahad-tracer th { background: #eee; }
#galahad-tracer th, #galahad-tracer td { padding: 5px; }
#galahad-tracer .functions { white-space: nowrap; overflow: auto; }
</style>
<div id="galahad-tracer">
<?php
$data = Galahad_Query_Tracer::instance()->getData();
if (!empty($data)) {
$this->_renderData($data);
} else {
_e('No queries caused by plugins.');
}
?>
</div>
<?php
}
/**
* Render tracer's data
*
* @param array $data
*/
protected function _renderData($data)
{
foreach ($data as $pluginData) {
echo "<h2>{$pluginData['name']}</h2>";
foreach ($pluginData['backtrace'] as $filename => $data) {
$filename = htmlspecialchars($filename);
printf('<h3>%s</h3>
<table>
<tr>
<th>%s</th>
<th>%s</th>
</tr>', htmlspecialchars($filename), __('Line', 'galahad-query-tracer'), __('Query & Function Chain', 'galahad-query-tracer'));
foreach ($data as $query) {
$query['query'] = htmlspecialchars($query['query']);
$functionChain = implode(' → ', $query['function_chain']);
echo "<tr>
<td align=\"center\" valign=\"center\" rowspan=\"2\">{$query['line']}</td>
<td>{$query['query']}</td>
</tr>
<tr>
<td>$functionChain</td>
</tr>";
}
echo '</table>';
}
}
}
}