1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\BlackBar; |
4
|
|
|
|
5
|
|
|
class Controller |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @var Application |
9
|
|
|
*/ |
10
|
|
|
protected $app; |
11
|
|
|
|
12
|
|
|
public function __construct(Application $app) |
13
|
|
|
{ |
14
|
|
|
$this->app = $app; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @action admin_enqueue_scripts |
19
|
|
|
* @action wp_enqueue_scripts |
20
|
|
|
*/ |
21
|
|
|
public function enqueueAssets(): void |
22
|
|
|
{ |
23
|
|
|
wp_enqueue_script(Application::ID, $this->app->url('assets/main.js')); |
24
|
|
|
wp_enqueue_style(Application::ID, $this->app->url('assets/main.css'), ['dashicons']); |
25
|
|
|
wp_enqueue_style(Application::ID.'-syntax', $this->app->url('assets/syntax.css')); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param string $classes |
30
|
|
|
* @action admin_body_class |
31
|
|
|
*/ |
32
|
|
|
public function filterBodyClasses($classes): string |
33
|
|
|
{ |
34
|
|
|
return trim((string) $classes.' '.Application::ID); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @action all |
39
|
|
|
*/ |
40
|
|
|
public function initActions(): void |
41
|
|
|
{ |
42
|
|
|
if (!class_exists('Debug_Bar_Slow_Actions')) { |
43
|
|
|
$this->app->actions->startTimer(); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @action all |
49
|
|
|
*/ |
50
|
|
|
public function initConsole(): void |
51
|
|
|
{ |
52
|
|
|
if (Application::CONSOLE_HOOK !== func_get_arg(0)) { |
53
|
|
|
return; |
54
|
|
|
} |
55
|
|
|
$args = array_pad(func_get_args(), 4, ''); |
56
|
|
|
$args = array_combine(['hook', 'message', 'errno', 'location'], $args); |
57
|
|
|
$args = array_map('sanitize_text_field', $args); |
58
|
|
|
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 4); |
59
|
|
|
$entry = array_pop($backtrace); // get the fourth backtrace entry |
60
|
|
|
if (empty(trim($args['location'])) && array_key_exists('file', $entry)) { |
61
|
|
|
$path = explode(ABSPATH, $entry['file']); |
62
|
|
|
$args['location'] = sprintf('%s:%s', array_pop($path), $entry['line']); |
63
|
|
|
} |
64
|
|
|
$this->app->console->store($args['message'], $args['errno'], $args['location']); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @action all |
69
|
|
|
*/ |
70
|
|
|
public function initProfiler(): void |
71
|
|
|
{ |
72
|
|
|
if (Application::PROFILER_HOOK === func_get_arg(0)) { |
73
|
|
|
$this->app->profiler->trace(func_get_arg(1)); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @action plugins_loaded |
79
|
|
|
*/ |
80
|
|
|
public function registerLanguages(): void |
81
|
|
|
{ |
82
|
|
|
load_plugin_textdomain(Application::ID, false, |
83
|
|
|
plugin_basename($this->app->path()).'/languages/' |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @action admin_footer |
89
|
|
|
* @action wp_footer |
90
|
|
|
*/ |
91
|
|
|
public function renderBar(): void |
92
|
|
|
{ |
93
|
|
|
apply_filters('debug', 'Profiler Stopped'); |
94
|
|
|
$this->app->render('debug-bar', [ |
95
|
|
|
'modules' => [ // order is intentional |
96
|
|
|
$this->app->console, |
97
|
|
|
$this->app->profiler, |
98
|
|
|
$this->app->queries, |
99
|
|
|
$this->app->actions, |
100
|
|
|
$this->app->templates, |
101
|
|
|
$this->app->globals, |
102
|
|
|
], |
103
|
|
|
]); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|