-
Notifications
You must be signed in to change notification settings - Fork 0
/
apermo-xdebug.php
208 lines (197 loc) · 5.68 KB
/
apermo-xdebug.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
/**
* Apermo Xdebug
*
* @author Christoph Daum
* @copyright 2018 Christoph Daum
* @license GPL-2.0+
* @package apermo-xdebug
*
* @wordpress-plugin
* Plugin Name: Apermo Xdebug
* Plugin URI: https://wordpress.org/plugins/apermo-xdebug/
* Version: 1.2.2
* Description: Indents xDebug messages inside the backend, so that these are no longer partly hidden underneath the admin menu. And it will also give you links to directly search for the error message on Google or Stackoverflow.
* Author: Christoph Daum
* Author URI: https://christoph-daum.de
* Text Domain: apermo-xdebug
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
/**
* Apermo Xdebug
* Copyright (C) 2018, Christoph Daum - [email protected]
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit( 'You shall not pass' );
}
if ( ! is_admin() ) {
return;
}
if ( ! ini_get( 'display_errors' ) ) {
add_action( 'admin_notices', function () {
?>
<div class="notice notice-warning is-dismissible">
<p><strong><?php esc_html_e( 'Apermo Xdebug:', 'apermo-xdebug' ); ?></strong> <?php echo esc_html_x( '"display_errors" is disabled.', 'Will be shown as admin notice if the php.ini setting display_errors is false.', 'apermo-xdebug' ); ?></p>
</div>
<?php
} );
return;
}
if ( ! function_exists( 'xdebug_get_code_coverage' ) ) {
add_action( 'admin_notices', function () {
?>
<div class="notice notice-warning is-dismissible">
<p><strong><?php esc_html_e( 'Apermo Xdebug:', 'apermo-xdebug' ); ?></strong> <?php echo esc_html_x( 'Xdebug is not active.', 'Will be shown as admin notice in case Xdebug wasn\'t automatically detected.', 'apermo-xdebug' ); ?></p>
</div>
<?php
} );
return;
}
/**
* Class ApermoXdebug
*
* Formats Xdebug output inside the WordPress Backend to not interfeer with the Menu.
*/
class ApermoXdebug {
/**
* Store the search engines.
*
* @var $search_urls
*/
private $search_urls;
/**
* ApermoXdebug constructor.
*/
public function __construct() {
add_action( 'admin_head', array( $this, 'print_css' ) );
add_action( 'admin_head', array( $this, 'print_javascript' ) );
$this->search_urls = apply_filters(
'apermo_xdebug_search_urls',
[
'google' => [
'url' => 'https://www.google.com/search?q=\'+search_term+\'',
'label' => __( 'Search on Google', 'apermo-xdebug' ),
],
'stackoverflow' => [
'url' => 'https://www.stackoverflow.com/search?q=\'+search_term+\'',
'label' => __( 'Search on Stackoverflow', 'apermo-xdebug' ),
],
]
);
}
/**
* Outputs <style> for the WordPress Backend.
* Called by hook: admin_head
*/
public function print_css() {
?>
<style id="apermo-xdebug">
.xdebug-error, .xdebug-var-dump {
width: calc( 100vw - 200px );
margin-right: 20px;
margin-bottom: 20px;
position: relative;
z-index: 9991;
margin-left: 180px;
}
.xdebug-error:after, .xdebug-var-dump:after {
display:block;
content: '';
clear:both;
}
/* Had to move this a bit, otherwise links wouldn't be clickable in the Xdebug notice */
#adminmenuwrap {
z-index: 9992;
top: 32px;
}
.folded .xdebug-error,
.folded .xdebug-var-dump {
width: calc( 100vw - 80px );
margin-left: 60px;
}
.xdebug-error .apermo-xdebug-link {
display: inline-block;
color: #333;
background: #eee;
border: 2px solid #333;
padding: 5px;
text-decoration: none;
margin: 10px 0 10px 10px;
}
.xdebug-error .apermo-xdebug-link:first-of-type {
margin-left: 0;
}
@media screen and (max-width: 960px) {
.auto-fold .xdebug-error,
.auto-fold .xdebug-var-dump {
width: calc( 100vw - 80px );
margin-left: 60px;
}
}
@media screen and (max-width: 782px) {
.auto-fold .xdebug-error,
.auto-fold .xdebug-var-dump {
margin-right: 10px;
margin-left: 10px;
width: calc( 100vw - 20px );
}
}
</style>
<?php
}
/**
* Outputs <javascript> for the WordPress Backend.
* Called by hook: admin_head
*/
public function print_javascript() {
?>
<script type="text/javascript">
jQuery(document).ready(function ($) {
setTimeout(function () {
if ( ! $('.xdebug-error, .xdebug-var-dump').length ) {
$( '#apermo-xdebug').remove();
}
},500);
const wp_path = '<?php echo esc_url( get_home_path() ); ?>';
$('.xdebug-error').each(function () {
var regex = new RegExp( wp_path, 'g' ),
search_term = encodeURI (
$(this).find('tr:first-of-type th').html()
.replace( regex, '/' )
.replace(/<\/?[^>]+(>|$)/g, '')
.replace( '( ! )', '' )
.trim()
);
var $th = $(this).find('tr:first-of-type th');
$th.append('<br>');
<?php
foreach ( $this->search_urls as $search_url ) {
?>
$th.append('<a href="<?php echo $search_url['url']; ?>" class="apermo-xdebug-link" target="_blank"><?php echo esc_html( $search_url['label'] ); ?></a>');
<?php
}
?>
});
});
</script>
<?php
}
}
// Run boy, run!
add_action( 'plugins_loaded', function () {
new ApermoXdebug();
} );