forked from stephenharris/Event-Organiser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event-organiser-debug.php
593 lines (513 loc) · 18.1 KB
/
event-organiser-debug.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
<?php
/****** DEBUG PAGE ******/
if ( !class_exists( 'EventOrganiser_Admin_Page' ) ){
require_once( EVENT_ORGANISER_DIR.'classes/class-eventorganiser-admin-page.php' );
}
/**
* @ignore
*/
class EventOrganiser_Debug_Page extends EventOrganiser_Admin_Page
{
function set_constants(){
$this->hook = 'edit.php?post_type=event';
$this->title = __( 'System Info', 'eventorganiser' );
$this->menu = __( 'System Info', 'eventorganiser' );
$this->permissions = 'manage_options';
$this->slug = 'debug';
}
function add_page(){
$this->page = add_submenu_page($this->hook,$this->title, $this->menu, $this->permissions,$this->slug, array($this,'render_page'),10);
add_action('load-' . $this->page, array($this,'page_actions'),9);
add_action('admin_print_scripts-' . $this->page, array($this,'page_styles'),10);
add_action('admin_print_styles-' . $this->page, array($this,'page_scripts'),10);
add_action("admin_footer-" . $this->page, array($this,'footer_scripts') );
if( !defined( "WP_DEBUG" ) || !WP_DEBUG ){
remove_submenu_page('edit.php?post_type=event',$this->slug);
}
}
function page_actions(){
$eo_debugger = new EventOrganiser_Debugger();
$eo_debugger->set_prequiste( 'WordPress', '3.3', '4.0');
//$eo_debugger->set_known_plugin_conflicts();
//$eo_debugger->set_known_theme_conflicts();
$eo_debugger->set_db_tables( 'eo_events', 'eo_venuemeta' );
do_action_ref_array( 'eventorganiser_debugger_setup', array( &$eo_debugger ) );
$this->debugger = $eo_debugger;
if( !empty( $_GET['data'] ) && !empty( $_GET['data']['jqueryv'] ) ){
$eo_debugger->set_jquery_version( $_GET['data']['jqueryv'] );
}
if( !empty( $_GET['eo-download-debug-file'] ) && current_user_can( 'manage_options' ) && wp_verify_nonce( $_GET['eo-download-debug-file'], 'eo-download-debug-file' ) ){
$this->debugger->download_debug_info();
}
wp_enqueue_style('eventorganiser-style' );
}
function display(){
?>
<div class="wrap">
<?php screen_icon( 'edit' );?>
<h2><?php _e('System Info','eventorganiser');?> </h2>
<?php $eo_debugger = $this->debugger; ?>
<p>
<?php
_e( "This page highlights useful information for debugging. If you're reporting a bug, please include this information.", 'eventorganiser' );
echo " ";
_e( "The 'system info' link in under the Events admin tab is only visible to admins and only when <code>WP_DEBUG</code> is set to <code>true</code>.", 'eventorganiser' );
?>
</p>
<p class="description">
<?php
_e( "Most bugs arise from theme or plug-in conflicts. You can check this by disabling all other plug-ins and switching to TwentyTweleve.", 'eventorganiser' );
echo " ";
_e( "To help speed things along, if you report a bug please indicate if you have done so. Once the plug-in or theme has been identified it is often easy to resolve the issue.", 'eventorganiser' );
echo " ";
_e( "Below any <strong>known</strong> plug-in and theme conflicts are highlighted in red.", 'eventorganiser' );
?>
</p>
<?php
printf(
'<p><a href="%s" data-eo-debug="downloadurl" class="button secondary">%s</a></p>',
add_query_arg( 'eo-download-debug-file', wp_create_nonce( 'eo-download-debug-file' ) ),
__( "Download system information file", 'eventorganiser' )
);
?>
<table class="widefat">
<tr>
<th> Site url </th>
<td><?php echo site_url(); ?></td>
</tr>
<tr>
<th> Home url </th>
<td><?php echo home_url(); ?></td>
</tr>
<tr>
<th> Multisite </th>
<td><?php echo is_multisite() ? 'Yes' : 'No' ?></td>
</tr>
<tr>
<th> Permalink </th>
<td>
<?php echo get_option( 'permalink_structure' );?>
</td>
</tr>
<tr>
<th> Event Organsier version </th>
<td><?php echo EVENT_ORGANISER_VER; ?></td>
</tr>
<tr>
<th> WordPress </th>
<td>
<?php $eo_debugger->verbose_prequiste_check( 'WordPress', get_bloginfo( 'version' ) );?>
</td>
</tr>
<tr>
<th> jQuery Version </th>
<td>
<span data-eo-debug="jqueryversion"></span>
</td>
</tr>
<script>
jQuery(document).ready( function($) {
var eventorganiser = eventorganiser || {};
eventorganiser.add_query_arg = function( key, value, uri ) {
var re = new RegExp("([?|&])" + key + "=.*?(&|$)", "i");
separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {
return uri.replace(re, '$1' + key + "=" + value + '$2');
}
else {
return uri + separator + key + "=" + value;
}
}
$('[data-eo-debug="jqueryversion"]').each(function() {
var version = $().jquery;
$(this).text( version);
$('[data-eo-debug="downloadurl"]').each(function(){
var new_url = eventorganiser.add_query_arg( 'data[jqueryv]', version, $(this).attr('href') );
$(this).attr('href',new_url);
});
});
});
</script>
<tr>
<th> PHP Version </th>
<td> <?php echo PHP_VERSION; ?></td>
</tr>
<tr>
<th> MySQL Version </th>
<td>
<?php
global $wpdb;
echo empty( $wpdb->use_mysqli ) ? mysql_get_server_info() : mysqli_get_server_info( $wpdb->dbh );
?></td>
</tr>
<tr>
<th> Web Server </th>
<td> <?php echo $_SERVER['SERVER_SOFTWARE']; ?></td>
</tr>
<tr>
<th> PHP Memory Usage </th>
<th><?php echo $eo_debugger->verbose_memory_check(); ?>
</tr>
<tr>
<th> PHP Post Max Size </th>
<td><?php echo ini_get('post_max_size'); ?></td>
</tr>
<tr>
<th> PHP Upload Max Size </th>
<td><?php echo ini_get('upload_max_filesize'); ?></td>
</tr>
<tr>
<th> PHP FSOCKOPEN Support </th>
<td> <?php echo (function_exists('fsockopen')) ? _e('Yes', 'eventorganiser') . "\n" : _e('No', 'eventorganiser') . "\n"; ?></td>
</tr>
<tr>
<th> PHP cURL Support </th>
<td> <?php echo (function_exists('curl_init')) ? _e('Yes', 'eventorganiser') . "\n" : _e('No', 'eventorganiser') . "\n"; ?></td>
</tr>
<tr>
<th> OpenSSL Support </th>
<td> <?php echo (function_exists('openssl_verify')) ? _e('Yes', 'eventorganiser') . "\n" : _e('No', 'eventorganiser') . "\n"; ?></td>
</tr>
<tr>
<th> Plug-ins </th>
<td>
<?php $eo_debugger->verbose_plugin_check();?>
</td>
</tr>
<tr>
<th> Theme </th>
<td>
<?php $eo_debugger->verbose_theme_check();?>
</td>
</tr>
<tr>
<th> Databse Prefix: </th>
<td><?php global $wpdb; echo $wpdb->prefix; ?></td>
</tr>
<tr>
<th> Database tables </th>
<td>
<?php $eo_debugger->verbose_database_check();?>
</td>
</tr>
<tr>
<th> Database character set </th>
<td>
<?php $eo_debugger->verbose_database_charset_check();?>
</td>
</tr>
<tr>
<th> Debug mode </th>
<td><?php echo defined( 'WP_DEBUG' ) && WP_DEBUG ? 'Enabled' : 'Disabled'; ?></td>
</tr>
<tr>
<th> WP Cron </th>
<td>
<?php
if( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON )
echo 'Disabled';
elseif( defined( 'ALTERNATE_WP_CRON' ) && ALTERNATE_WP_CRON )
echo 'Alternative';
else
echo 'Enabled';
?>
</td>
</tr>
<tr>
<th> Timezone </th>
<td><?php echo eo_get_blog_timezone()->getName(); printf( ' ( %s / %s ) ', get_option( 'gmt_offset' ), get_option( 'timezone_string' ) )?></td>
</tr>
<tr>
<th> Language </th>
<td><?php echo defined( 'WP_LANG' ) && WP_LANG ? WP_LANG : 'en_us'; ?></td>
</tr>
<tr>
<th> Date Format </th>
<td><?php echo get_option( 'date_format' ); ?></td>
</tr>
<tr>
<th> Time Format </th>
<td><?php echo get_option( 'time_format' ); ?></td>
</tr>
</table>
<?php
printf(
'<p class="description"> <span class="eo-debug-warning">*</span> %s </p>',
__( 'Known plug-in & theme conflicts, highlighted in red, may be minor or have a simple resolution. Please contact support.', 'eventorganiser' )
);
?>
</div><!--End .wrap -->
<?php
}
}
$venues_page = new EventOrganiser_Debug_Page();
class EventOrganiser_Debugger{
var $prequiste = array();
var $plugins = array();
var $themes = array();
var $db_tables = array();
var $plugin = 'Event Organiser';
var $ok_class = 'eo-debug-ok';
var $warning_class = 'eo-debug-warning';
var $alert_class = 'eo-debug-alert';
var $jquery_version = false;
function set_plugin( $plugin ){
$this->plugin = $plugin;
}
function set_prequiste( $requirement, $min = false, $max = false ){
$this->prequiste[$requirement] = compact( 'min', 'max' );
}
function set_known_plugin_conflicts( ){
$args = func_get_args();
if( $args ){
$args = array_map( 'strtolower', $args );
$this->plugins = array_merge( $this->plugins, $args );
}
}
function set_known_theme_conflicts( ){
$args = func_get_args();
if( $args ){
$args = array_map( 'strtolower', $args );
$this->themes = array_merge( $this->themes, $args );
}
}
function set_db_tables( ){
$args = func_get_args();
$this->db_tables = array_merge( $this->db_tables, $args );
}
function set_jquery_version( $v ){
$this->jquery_version = $v;
}
function get_memory_usage( $context = false ){
$memory_usage = round( memory_get_usage() / 1024 / 1024, 2);
if( 'percent' == $context )
return $percentage = round( $memory_usage / ini_get( 'memory_limit' ) * 100, 0 );
return $memory_usage;
}
function get_cron_status(){
if( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON )
return 0;
elseif( defined( 'ALTERNATE_WP_CRON' ) && ALTERNATE_WP_CRON )
return 2;
else
return 1;
}
function check_prequiste( $requirement, $v ){
if( !isset( $this->prequiste[$requirement] ) )
return 1;
$versions = $this->prequiste[$requirement];
if( $versions['min'] && version_compare( $versions['min'], $v ) > 0 )
return -1;
if( $versions['max'] && version_compare( $versions['max'], $v ) < 0 )
return 0;
return 1;
}
function verbose_plugin_check(){
$installed = get_plugins();
foreach( $installed as $plugin_slug => $plugin_data ){
if( ! is_plugin_active( $plugin_slug ) )
continue;
$class = in_array( strtolower( $plugin_slug ), $this->plugins ) ? $this->warning_class : '';
printf(
' <span class="%s"> %s %s </span> </br>',
esc_attr( $class ),
$plugin_data['Name'],
$plugin_data['Version']
);
}
}
function verbose_theme_check(){
if( version_compare( '3.4', get_bloginfo( 'version' ) ) <= 0 ){
$theme = wp_get_theme();
$class = in_array( strtolower( $theme->stylesheet ), $this->themes ) ? $this->warning_class : '';
printf(
' <span class="%s"> %s %s </span> </br> %s',
esc_attr( $class ),
$theme->get('Name'),
$theme->get('Version'),
$theme->get('ThemeURI')
);
}else{
$theme_name = get_current_theme();
$class = in_array( strtolower( $theme_name ), $this->themes ) ? $this->warning_class : '';
printf(
' <span class="%s"> %s </span> </br>',
esc_attr( $class ),
$theme_name
);
}
}
function verbose_database_check(){
if( $this->db_tables ){
foreach( $this->db_tables as $db_table ){
$class = $this->table_exists( $db_table ) ? $this->ok_class : $this->warning_class;
printf( '<span class="%s"> %s </span></br>', esc_attr( $class ), esc_attr( $db_table ) );
}
}
}
function table_exists( $table ){
global $wpdb;
return $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->prefix.$table ) ) == $wpdb->prefix.$table;
}
function database_charset_check(){
global $wpdb;
return $wpdb->query( $wpdb->prepare( 'SHOW CHARACTER SET WHERE LOWER( Charset ) = LOWER( %s )', DB_CHARSET ) );
}
function verbose_database_charset_check(){
global $wpdb;
if( $this->database_charset_check() )
$class = '';
else
$class = $this->warning_class;
printf( '<span class="%s"> %s </span></br>', esc_attr( $class ), esc_attr( DB_CHARSET ) );
}
function verbose_prequiste_check( $requirement, $v ){
$versions = $this->prequiste[$requirement];
if( 1 == $this->check_prequiste( $requirement, $v ) ){
printf( '<span class="%s">%s</span>', esc_attr( $this->ok_class ), $v );
}elseif( 0 == $this->check_prequiste( $requirement, $v ) ){
printf(
'<span class="%s">%s</span>. %s',
esc_attr( $this->alert_class ),
$v,
sprintf(
/// TRANSLATORS: [this plugin] has only been tested up to [required plugin] [required plugin version]
__( '%s has only been tested up to %s %s', 'eventorganiser' ), $this->plugin, $requirement, $versions['max'] )
);
}elseif( -1 == $this->check_prequiste( $requirement, $v ) ){
printf(
'<span class="%s">%s</span>. %s',
esc_attr( $this->warning_class ),
$v,
sprintf(
/// TRANSLATORS: [this plugin] requires [required plugin] version [required plugin version] or higher
__( '%s requires %s version %s or higher', 'eventorganiser' ), $this->plugin, $requirement, $versions['min'] )
);
}
}
function verbose_memory_check(){
if( function_exists( 'memory_get_usage' ) ){
$memory_usage = round( memory_get_usage() / 1024 / 1024, 2);
$percentage = round( $memory_usage / ini_get( 'memory_limit' ) * 100, 0 );
printf( '%d / %d <span class="%s">( %s )</span>',
ceil( $memory_usage ),
ini_get( 'memory_limit' ),
$percentage > 90 ? $this->alert_class : $this->ok_class,
$percentage . "%"
);
}else{
printf( ' ? / %d <span class="%s">( %s )</span>',
ini_get( 'memory_limit' ),
$this->alert_class,
__( 'unknown', 'eventorganiser' )
);
}
}
public function download_debug_info(){
global $wpdb;
$installed = get_plugins();
$active_plugins = array();
foreach( $installed as $plugin_slug => $plugin_data ){
if( ! is_plugin_active( $plugin_slug ) )
continue;
$active_plugins[] = $plugin_slug;
};
$theme = wp_get_theme();
$db_tables = array();
if( $this->db_tables ){
foreach( $this->db_tables as $db_table ){
if( $this->table_exists( $db_table ) ){
$db_table = "**".$db_table."**";
}
$db_tables[] = $db_table;
}
}
$options = array();
$options['event-organiser'] = eventorganiser_get_option( false );
/**
* Settings to include in an export.
*
* These options are included in both the settings export on the settings
* page and the also printed in the system information file. By default
* they inlude Event Organiser's options, but others can be added.
*
* The filtered value should be a (2+ dimensional) array, indexed by plugin/
* extension name.
*
* @param array $options Array of user settings, indexed by plug-in/extension.
*/
$options = apply_filters( 'eventorganiser_export_settings', $options );
$filename = 'event-organiser-system-info-'.get_bloginfo( 'name' ).'.md';
$filename = sanitize_file_name( $filename );
header( "Content-type: text/plain" );
header('Content-disposition: attachment; filename=' . $filename );
echo '## Event Organiser Sytem Informaton ##' . "\n";
echo "\n";
echo "\n";
echo '### Site Information ###' . "\n";
echo "\n";
echo 'Site url' . "\t\t\t".site_url()."\n";
echo 'Home url' . "\t\t\t".home_url()."\n";
echo 'Multisite' ."\t\t\t".( is_multisite() ? 'Yes' : 'No' )."\n";
echo 'Permalink' . "\t\t\t" . get_option( 'permalink_structure' ) . "\n";
echo "\n";
echo "\n";
echo '### Versions ###' . "\n";
echo "\n";
echo 'Event Organiser' . "\t\t" . EVENT_ORGANISER_VER . "\n";
if( $this->jquery_version )
echo 'jQuery Version' . "\t\t" . $this->jquery_version . "\n";
echo 'WordPress' . "\t\t\t" . get_bloginfo( 'version' ) ."\n";
echo 'PHP Version' . "\t\t\t" . PHP_VERSION ."\n";
global $wpdb;
$ver = empty( $wpdb->use_mysqli ) ? mysql_get_server_info() : mysqli_get_server_info( $wpdb->dbh );
echo 'MySQL Version' . "\t\t" . $ver ."\n";
echo "\n";
echo "\n";
echo '### Server Information ###' . "\n";
echo "\n";
echo 'Web Server' ."\t\t\t" . $_SERVER['SERVER_SOFTWARE'] ."\n";
echo 'PHP Memory Usage' ."\t" . $this->get_memory_usage( 'percent' ) . '%' ."\n";
echo 'PHP Memory Limit' ."\t" . ini_get( 'memory_limit' ) ."\n";
echo 'PHP Upload Max Size' ."\t" . ini_get('post_max_size') ."\n";
echo 'PHP FSOCKOPEN support' ."\t" . ( function_exists('fsockopen') ? 'Yes' : 'No' ) ."\n";
echo 'PHP cURL support' ."\t" . ( function_exists('curl_init') ? 'Yes' : 'No' ) ."\n";
echo 'PHP openSSL support' ."\t" . ( function_exists('openssl_verify') ? 'Yes' : 'No' ) ."\n";
echo "\n";
echo "\n";
echo '### Plug-ins & Themes ###' . "\n";
echo "\n";
echo 'Active Plug-ins' ."\n\t-\t" . implode( "\n\t-\t", $active_plugins ) . "\n";
echo 'Theme' . "\n\t-\t" . $theme->get('Name').' ('.$theme->get('Version').')' . "\n";
echo "\n";
echo "\n";
echo '### Database ###' . "\n";
echo "\n";
echo "Database Prefix"."\t\t\t" . $wpdb->prefix . "\n";
echo "Database tables"."\t\t\t" . implode( ', ', $db_tables ). "\n";
echo "Database character set"."\t" . ( $this->database_charset_check() ? DB_CHARSET : "**".DB_CHARSET."**" ) . "\n";
echo "\n";
echo "\n";
echo '### Site Settings ###' . "\n";
echo 'Timezone' . "\t\t\t" . eo_get_blog_timezone()->getName() . sprintf( ' ( %s / %s ) ', get_option( 'gmt_offset' ), get_option( 'timezone_string' ) ) . "\n";
echo 'WP Cron' . "\t\t\t" . ( $this->get_cron_status() == 0 ? 'Disabled' : ( $this->get_cron_status() == 1 ? 'Enabled' : 'Alternative ') ) . "\n";
echo 'WP Lang' . "\t\t\t" . ( defined( 'WP_LANG' ) && WP_LANG ? WP_LANG : 'en_us' ) . "\n";
echo 'Date format' . "\t\t" . get_option( 'date_format' ) . "\n";
echo 'Time format' . "\t\t" . get_option( 'time_format' );
echo "\n";
echo "\n";
echo '### Event Organiser Settings ###' . "\n";
foreach( $options['event-organiser'] as $option => $value ){
if( is_array( $value ) )
$value = implode( ', ', $value );
echo "\n\t-\t**".esc_html( $option ).":**\t " . $value;
}
echo "\n";
echo "\n";
echo '### Debug Mode ###' . "\n";
echo "\n";
echo 'Debug mode' . "\t\t\t" . ( defined( 'WP_DEBUG' ) && WP_DEBUG ? 'Enabled' : 'Disabled' ) . "\n";
echo 'Script mode' . "\t\t\t" . ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? 'Enabled' : 'Disabled' ) . "\n";
exit();
}
}