System_Status::html()   F
last analyzed

Complexity

Conditions 62
Paths > 20000

Size

Total Lines 530
Code Lines 354

Duplication

Lines 44
Ratio 8.3 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 62
eloc 354
nc 4294967295
nop 0
dl 44
loc 530
rs 2
c 3
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * System Status Page
4
 *
5
 * @package SimpleCalendar/Admin
6
 */
7
namespace SimpleCalendar\Admin\Pages;
8
9
use SimpleCalendar\Abstracts\Admin_Page;
10
11
if ( ! defined( 'ABSPATH' ) ) {
12
	exit;
13
}
14
15
/**
16
 * System status.
17
 *
18
 * Generates reports on current installation, with information for debugging or support purposes.
19
 *
20
 * @since 3.0.0
21
 */
22
class System_Status extends Admin_Page {
23
24
	/**
25
	 * Constructor.
26
	 *
27
	 * @since 3.0.0
28
	 */
29 View Code Duplication
	public function __construct() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
31
		$this->id           = $tab = 'system-status';
32
		$this->option_group = $page = 'tools';
33
		$this->label        = __( 'System Report', 'google-calendar-events' );
34
		$this->description  = '';
35
		$this->sections     = $this->add_sections();
36
		$this->fields       = $this->add_fields();
37
38
		// Disable the submit button for this page.
39
		add_filter( 'simcal_admin_page_' . $page . '_' . $tab . '_submit', function() { return false; } );
40
41
		// Add html.
42
		add_action( 'simcal_admin_page_' . $page . '_' . $tab . '_end', array( $this, 'html' ) );
43
	}
44
45
	/**
46
	 * Output page markup.
47
	 *
48
	 * @since 3.0.0
49
	 */
50
	public function html() {
0 ignored issues
show
Coding Style introduced by
html uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
51
52
		?>
53
		<div id="simcal-system-status-report">
54
			<p><?php _e( 'Please copy and paste this information when contacting support:', 'google-calendar-events' ); ?> </p>
55
			<textarea readonly="readonly" onclick="this.select();"></textarea>
56
			<p><?php _e( 'You can also download your information as a text file to attach, or simply view it below.', 'google-calendar-events' ); ?></p>
57
			<p><a href="#" id="simcal-system-status-report-download" class="button button-primary"><?php _e( 'Download System Report', 'google-calendar-events' ); ?></a></p>
58
		</div>
59
		<hr>
60
		<?php
61
62
		global $wpdb;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
63
		$wp_version = get_bloginfo( 'version' );
64
65
		$sections = array();
66
		$panels   = array(
67
			'wordpress' => array(
68
				'label'  => __( 'WordPress Installation', 'google-calendar-events' ),
69
				'export' => 'WordPress Installation',
70
			),
71
			'theme'     => array(
72
				'label'  => __( 'Active Theme', 'google-calendar-events' ),
73
				'export' => 'Active Theme',
74
			),
75
			'plugins'   => array(
76
				'label'  => __( 'Active Plugins', 'google-calendar-events' ),
77
				'export' => 'Active Plugins',
78
			),
79
			'server'    => array(
80
				'label'  => __( 'Server Environment', 'google-calendar-events' ),
81
				'export' => 'Server Environment',
82
			),
83
			'client'    => array(
84
				'label'  => __( 'Client Information', 'google-calendar-events' ),
85
				'export' => 'Client Information',
86
			)
87
		);
88
89
		/**
90
		 * Plugin Information
91
		 * ==================
92
		 */
93
94
		// @todo add report information section for current plugin
95
96
		/**
97
		 * WordPress Installation
98
		 * ======================
99
		 */
100
101
		$debug_mode = $script_debug = __( 'No', 'google-calendar-events' );
102
		if ( defined( 'WP_DEBUG' ) ) {
103
			$debug_mode = true === WP_DEBUG ? __( 'Yes', 'google-calendar-events' ) : $debug_mode;
104
		}
105
		if ( defined( 'SCRIPT_DEBUG' ) ) {
106
			$script_debug = true === SCRIPT_DEBUG ? __( 'Yes', 'google-calendar-events' ) : $script_debug;
107
		}
108
109
		$memory = $this->let_to_num( WP_MEMORY_LIMIT );
110
		$memory_export = size_format( $memory );
111
		if ( $memory < 67108864 ) {
112
			$memory = '<mark class="error">' . sprintf( __( '%1$s - It is recomendend to set memory to at least 64MB. See: <a href="%2$s" target="_blank">Increasing memory allocated to PHP</a>', 'google-calendar-events' ), $memory_export, 'http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP' ) . '</mark>';
113
		} else {
114
			$memory = '<mark class="ok">' . $memory_export . '</mark>';
115
		}
116
117
		$permalinks = get_option( 'permalink_structure' );
118
		$permalinks = empty( $permalinks ) ? '/?' : $permalinks;
119
120
		$is_multisite = is_multisite();
121
122
		$sections['wordpress'] = array(
123
			'name'          => array(
124
				'label'  => __( 'Site Name', 'google-calendar-events' ),
125
				'label_export' => 'Site Name',
126
				'result' => get_bloginfo( 'name' ),
127
			),
128
			'home_url'      => array(
129
				'label'  => __( 'Home URL', 'google-calendar-events' ),
130
				'label_export' => 'Home URL',
131
				'result' => home_url(),
132
			),
133
			'site_url'      => array(
134
				'label'  => __( 'Site URL', 'google-calendar-events' ),
135
				'label_export' => 'Site URL',
136
				'result' => site_url(),
137
			),
138
			'version'       => array(
139
				'label'  => __( 'Version', 'google-calendar-events' ),
140
				'label_export' => 'Version',
141
				'result' => $wp_version,
142
			),
143
			'locale'        => array(
144
				'label'  => __( 'Locale', 'google-calendar-events' ),
145
				'label_export' => 'Locale',
146
				'result' => get_locale(),
147
			),
148
			'wp_timezone'   => array(
149
				'label'  => __( 'Timezone', 'google-calendar-events' ),
150
				'label_export' => 'Timezone',
151
				'result' => simcal_get_wp_timezone(),
152
			),
153
			'multisite'     => array(
154
				'label'  => __( 'Multisite', 'google-calendar-events' ),
155
				'label_export' => 'Multisite',
156
				'result' => $is_multisite ? __( 'Yes', 'google-calendar-events' ) : __( 'No', 'google-calendar-events' ),
157
				'result_export' => $is_multisite ? 'Yes' : 'No'
158
			),
159
			'permalink'     => array(
160
				'label'  => __( 'Permalinks', 'google-calendar-events' ),
161
				'label_export' => 'Permalinks',
162
				'result' => '<code>' . $permalinks . '</code>',
163
				'result_export' => $permalinks,
164
			),
165
			'memory_limit'  => array(
166
				'label'  => 'WP Memory Limit',
167
				'result' => $memory,
168
				'result_export' => $memory_export,
169
			),
170
			'debug_mode'    => array(
171
				'label'  => 'WP Debug Mode',
172
				'result' => $debug_mode,
173
			),
174
			'script_debug' => array(
175
				'label'  => 'Script Debug',
176
				'result' => $script_debug,
177
			),
178
		);
179
180
		/**
181
		 * Active Theme
182
		 * ============
183
		 */
184
185
		include_once ABSPATH . 'wp-admin/includes/theme-install.php';
186
187
		if ( version_compare( $wp_version, '3.4', '<' ) ) {
188
			$active_theme  = get_theme_data( get_stylesheet_directory() . '/style.css' );
189
			$theme_name    = '<a href="' . $active_theme['URI'] . '" target="_blank">' . $active_theme['Name'] . '</a>';
190
			$theme_version = $active_theme['Version'];
191
			$theme_author  = '<a href="' . $active_theme['AuthorURI'] . '" target="_blank">' . $active_theme['Author'] . '</a>';
192
			$theme_export  = $active_theme['Name'] . ' - ' . $theme_version;
193
		} else {
194
			$active_theme  = wp_get_theme();
195
			$theme_name    = '<a href="' . $active_theme->ThemeURI . '" target="_blank">' . $active_theme->Name . '</a>';
196
			$theme_version = $active_theme->Version;
197
			$theme_author  = $active_theme->Author;
198
			$theme_export  = $active_theme->Name . ' - ' . $theme_version;
199
		}
200
201
		$theme_update_version = $theme_version;
202
203
		$api = themes_api( 'theme_information', array(
204
			'slug'   => get_template(),
205
			'fields' => array( 'sections' => false, 'tags' => false ),
206
		) );
207
		if ( $api && ! is_wp_error( $api ) ) {
208
			$theme_update_version = $api->version;
209
		}
210
211 View Code Duplication
		if ( version_compare( $theme_version, $theme_update_version, '<' ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
212
			$theme_version = '<mark class="error">' . $theme_version . ' (' . sprintf( __( '%s is available', 'google-calendar-events' ), esc_html( $theme_update_version ) ) . ')</mark>';
213
		} else {
214
			$theme_version = '<mark class="ok">' . $theme_version . '</mark>';
215
		}
216
217
		$theme  = '<dl>';
218
		$theme .= '<dt>' . __( 'Name', 'google-calendar-events' ) . '</dt>';
219
		$theme .= '<dd>' . $theme_name . '</dd>';
220
		$theme .= '<dt>' . __( 'Author', 'google-calendar-events' ) . '</dt>';
221
		$theme .= '<dd>' . $theme_author . '</dd>';
222
		$theme .= '<dt>' . __( 'Version', 'google-calendar-events' ) . '</dt>';
223
		$theme .= '<dd>' . $theme_version . '</dd>';
224
		$theme .= '</dl>';
225
226
		$is_child_theme = is_child_theme();
227
		$parent_theme = $parent_theme_export = '-';
228
229
		if ( $is_child_theme ) {
230
			if ( version_compare( $wp_version, '3.4', '<' ) ) {
231
232
				$parent_theme = $parent_theme_export = $active_theme['Template'];
233
234
			} else {
235
236
				$parent = wp_get_theme( $active_theme->Template );
237
				$parent_theme  = '<dl>';
238
				$parent_theme .= '<dt>' . __( 'Name', 'google-calendar-events' ) .    '</dt>';
239
				$parent_theme .= '<dd>' . $parent->Name .          '</dd>';
240
				$parent_theme .= '<dt>' . __( 'Author', 'google-calendar-events' ) .  '</dt>';
241
				$parent_theme .= '<dd>' . $parent->Author .        '</dd>';
242
				$parent_theme .= '<dt>' . __( 'Version', 'google-calendar-events' ) . '</dt>';
243
				$parent_theme .= '<dd>' . $parent->Version .       '</dd>';
244
				$parent_theme .= '</dl>';
245
246
				$parent_theme_export = strip_tags( $parent->Name ) . ' - ' .  $parent->Version;
247
			}
248
		}
249
250
		$sections['theme'] = array(
251
			'theme'    => array(
252
				'label'  => __( 'Theme Information', 'google-calendar-events' ),
253
				'label_export' => 'Theme',
254
				'result' => $theme,
255
				'result_export' => $theme_export,
256
			),
257
			'theme_child'   => array(
258
				'label'  => __( 'Child Theme', 'google-calendar-events' ),
259
				'label_export' => 'Child Theme',
260
				'result' => $is_child_theme ? __( 'Yes', 'google-calendar-events' ) : __( 'No', 'google-calendar-events' ),
261
				'result_export' => $is_child_theme ? 'Yes' : 'No',
262
			),
263
			'theme_parent'   => array(
264
				'label'  => __( 'Parent Theme', 'google-calendar-events' ),
265
				'label_export' => 'Parent Theme',
266
				'result' => $parent_theme,
267
				'result_export' => $parent_theme_export,
268
			),
269
		);
270
271
		/**
272
		 * Active Plugins
273
		 * ==============
274
		 */
275
276
		include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
277
278
		$active_plugins = (array) get_option( 'active_plugins', array() );
279
		if ( is_multisite() ) {
280
			$active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
281
		}
282
283
		foreach ( $active_plugins as $plugin ) {
284
285
			$plugin_data = @get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
286
287
			if ( ! empty( $plugin_data['Name'] ) ) {
288
289
				$plugin_name    = $plugin_data['Title'];
290
				$plugin_author  = $plugin_data['Author'];
291
				$plugin_version = $plugin_update_version = $plugin_data['Version'];
292
293
				// Afraid that querying many plugins may risk a timeout.
294
				if ( count( $active_plugins ) <= 10 ) {
295
					$api = plugins_api( 'plugin_information', array(
296
						'slug'   => $plugin_data['Name'],
297
						'fields' => array(
298
							'version' => true,
299
						),
300
					) );
301
					if ( $api && ! is_wp_error( $api ) ) {
302
						if ( ! empty( $api->version ) ) {
303
							$plugin_update_version = $api->version;
304 View Code Duplication
							if ( version_compare( $plugin_version, $plugin_update_version, '<' ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
305
								$plugin_version = '<mark class="error">' . $plugin_version . ' (' . sprintf( __( '%s is available', 'google-calendar-events' ), esc_html( $plugin_update_version ) ) . ')</mark>';
306
							} else {
307
								$plugin_version = '<mark class="ok">' . $plugin_version . '</mark>';
308
							}
309
						}
310
					}
311
				}
312
313
				$plugin  = '<dl>';
314
				$plugin .= '<dt>' . __( 'Author', 'google-calendar-events' ) .  '</dt>';
315
				$plugin .= '<dd>' . $plugin_author .         '</dd>';
316
				$plugin .= '<dt>' . __( 'Version', 'google-calendar-events' ) . '</dt>';
317
				$plugin .= '<dd>' . $plugin_version .        '</dd>';
318
				$plugin .= '</dl>';
319
320
				$sections['plugins'][ sanitize_key( strip_tags( $plugin_name ) ) ] = array(
321
					'label'  => $plugin_name,
322
					'label_export' => strip_tags( $plugin_data['Title'] ),
323
					'result' => $plugin,
324
					'result_export' => $plugin_data['Version'],
325
				);
326
			}
327
		}
328
329
		if ( isset( $sections['plugins'] ) ) {
330
			rsort( $sections['plugins'] );
331
		}
332
333
		/**
334
		 * Server Environment
335
		 * ==================
336
		 */
337
338
		if ( version_compare( PHP_VERSION, '7.0', '<' ) ) {
339
			$php = '<mark>' . PHP_VERSION . ' - ' .
340
			       __( 'WordPress.org recommends upgrading to PHP 7 or higher for better security.', 'google-calendar-events' ) .
341
			       ' <a href="https://wordpress.org/about/requirements/" target="_blank">' . __( 'Read more.', 'google-calendar-events' ) . '</a>' .
342
		           '</mark>';
343
		} else {
344
			$php = '<mark class="ok">' . PHP_VERSION . '</mark>';
345
		}
346
347
		if ( $wpdb->use_mysqli ) {
348
			$mysql = @mysqli_get_server_info( $wpdb->dbh );
349
		} else {
350
			$mysql = '<mark class="error">' . __( 'Cannot connect to MySQL database.', 'google-calendar-events' ) . '</mark>';
351
		}
352
353
		$host = $_SERVER['SERVER_SOFTWARE'];
354
		if ( defined( 'WPE_APIKEY' ) ) {
355
			$host .= ' (WP Engine)';
356
		} elseif ( defined( 'PAGELYBIN' ) ) {
357
			$host .= ' (Pagely)';
358
		}
359
360
		$default_timezone = $server_timezone_export = date_default_timezone_get();
361
		if ( 'UTC' !== $default_timezone ) {
362
			$server_timezone = '<mark class="error">' . sprintf( __( 'Server default timezone is %s - it should be UTC', 'google-calendar-events' ), $default_timezone ) . '</mark>';
363
		} else {
364
			$server_timezone = '<mark class="ok">UTC</mark>';
365
		}
366
367
		// WP Remote POST test.
368
		$response = wp_safe_remote_post( 'https://www.paypal.com/cgi-bin/webscr', array(
369
			'timeout'    => 60,
370
			'body'       => array(
371
				'cmd'    => '_notify-validate',
372
			),
373
		) );
374 View Code Duplication
		if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
375
			$wp_post_export = 'Yes';
376
			$wp_post = '<mark class="ok">' . __( 'Yes', 'google-calendar-events' ) . '</mark>';
377
		} else {
378
			$wp_post_export = 'No';
379
			$wp_post = '<mark class="error">' . __( 'No', 'google-calendar-events' );
380
			if ( is_wp_error( $response ) ) {
381
				$error = ' (' . $response->get_error_message() . ')';
382
				$wp_post .= $error;
383
				$wp_post_export .= $error;
384
			} else {
385
				$error = ' (' . $response['response']['code'] . ')';
386
				$wp_post .= $error;
387
				$wp_post_export .= $error;
388
			}
389
			$wp_post .= '</mark>';
390
		}
391
392
		// WP Remote GET test.
393
		$response = wp_safe_remote_get( get_home_url( '/?p=1' ) );
394 View Code Duplication
		if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
395
			$wp_get_export = 'Yes';
396
			$wp_get = '<mark class="ok">' . __( 'Yes', 'google-calendar-events' ) . '</mark>';
397
		} else {
398
			$wp_get_export = 'No';
399
			$wp_get = '<mark class="error">' . __( 'No', 'google-calendar-events' );
400
			if ( is_wp_error( $response ) ) {
401
				$error = ' (' . $response->get_error_message() . ')';
402
				$wp_get .= $error;
403
				$wp_get_export .= $error;
404
			} else {
405
				$error = ' (' . $response['response']['code'] . ')';
406
				$wp_get .= $error;
407
				$wp_get_export .= $error;
408
			}
409
			$wp_get .= '</mark>';
410
		}
411
412
		$php_memory_limit        = ini_get( 'memory_limit' );
413
		$php_max_upload_filesize = ini_get( 'upload_max_filesize' );
414
		$php_post_max_size       = ini_get( 'post_max_size' );
415
		$php_max_execution_time  = ini_get( 'max_execution_time' );
416
		$php_max_input_vars      = ini_get( 'max_input_vars' );
417
418
		$curl_info = '';
419
420
		if ( function_exists( 'curl_version' ) ) {
421
			$curl_info = curl_version();
422
		}
423
424
		$sections['server'] = array(
425
			'host'                => array(
426
				'label'  => __( 'Web Server', 'google-calendar-events' ),
427
				'label_export' => 'Web Server',
428
				'result' => $host,
429
			),
430
			'php_version'         => array(
431
				'label'  => __( 'PHP Version', 'google-calendar-events' ),
432
				'label_export' => 'PHP Version',
433
				'result' => $php,
434
				'result_export' => PHP_VERSION,
435
			),
436
			'mysql_version'       => array(
437
				'label'  => __( 'MySQL Version', 'google-calendar-events' ),
438
				'label_export' => 'MySQL Version',
439
				'result' => version_compare( $mysql, '5.5', '>' ) ? '<mark class="ok">' . $mysql . '</mark>' : $mysql,
440
				'result_export' => $mysql,
441
			),
442
			'server_timezone'     => array(
443
				'label'  => __( 'Server Timezone', 'google-calendar-events' ),
444
				'label_export' => 'Server Timezone',
445
				'result' => $server_timezone,
446
				'result_export' => $server_timezone_export,
447
			),
448
			'display_errors'      => array(
449
				'label'  => 'Display Errors',
450
				'result' => ( ini_get( 'display_errors' ) ) ? __( 'Yes', 'google-calendar-events' ) . ' (' . ini_get( 'display_errors' ) . ')' : '-',
451
				'result_export' => ( ini_get( 'display_errors' ) ) ? 'Yes' : 'No',
452
			),
453
			'php_memory_limit'    => array(
454
				'label'  => 'Memory Limit',
455
				'result' => $php_memory_limit ? $php_memory_limit : '-',
456
			),
457
			'upload_max_filesize' => array(
458
				'label'  => 'Upload Max Filesize',
459
				'result' => $php_max_upload_filesize ? $php_max_upload_filesize : '-',
460
			),
461
			'post_max_size'       => array(
462
				'label'  => 'Post Max Size',
463
				'result' => $php_post_max_size ? $php_post_max_size : '-',
464
			),
465
			'max_execution_time'  => array(
466
				'label'  => 'Max Execution Time',
467
				'result' => $php_max_execution_time ? $php_max_execution_time : '-',
468
			),
469
			'max_input_vars'      => array(
470
				'label'  => 'Max Input Vars',
471
				'result' => $php_max_input_vars ? $php_max_input_vars : '-',
472
			),
473
			'fsockopen'           => array(
474
				'label'  => 'fsockopen',
475
				'result' => function_exists( 'fsockopen' ) ? __( 'Yes', 'google-calendar-events' ) : __( 'No', 'google-calendar-events' ),
476
				'result_export' => function_exists( 'fsockopen' ) ? 'Yes' : 'No',
477
			),
478
			'curl_init'           => array(
479
				'label'         => 'cURL',
480
				'result'        => ! empty( $curl_info ) ? $curl_info['version'] . ', ' . $curl_info['ssl_version'] : __( 'No version found.', 'google-calendar-events' ),
481
				'result_export' => ! empty( $curl_info ) ? $curl_info['version'] . ', ' . $curl_info['ssl_version'] : 'No version found.',
482
			),
483
			'soap'                => array(
484
				'label'  => 'SOAP',
485
				'result' => class_exists( 'SoapClient' ) ? __( 'Yes', 'google-calendar-events' ) : __( 'No', 'google-calendar-events' ),
486
				'result_export' => class_exists( 'SoapClient' ) ? 'Yes' : 'No',
487
			),
488
			'suhosin'             => array(
489
				'label'  => 'SUHOSIN',
490
				'result' => extension_loaded( 'suhosin' ) ? __( 'Yes', 'google-calendar-events' ) : __( 'No', 'google-calendar-events' ),
491
				'result_export' => extension_loaded( 'suhosin' ) ? 'Yes' : 'No',
492
			),
493
			'wp_remote_post'      => array(
494
				'label'  => 'WP Remote POST',
495
				'result' => $wp_post,
496
				'result_export' => $wp_post_export,
497
			),
498
			'wp_remote_get'       => array(
499
				'label'  => 'WP Remote GET',
500
				'result' => $wp_get,
501
				'result_export' => $wp_get_export,
502
			),
503
		);
504
505
		/**
506
		 * Client Information
507
		 * ==================
508
		 */
509
510
		$user_client = new \SimpleCalendar\Browser();
511
512
		$browser  = '<dl>';
513
		$browser .= '<dt>' . __( 'Name:', 'google-calendar-events' ) .         '</dt>';
514
		$browser .= '<dd>' . $user_client->getBrowser() .   '</dd>';
515
		$browser .= '<dt>' . __( 'Version:', 'google-calendar-events' ) .      '</dt>';
516
		$browser .= '<dd>' . $user_client->getVersion() .   '</dd>';
517
		$browser .= '<dt>' . __( 'User Agent:', 'google-calendar-events' ) .   '</dt>';
518
		$browser .= '<dd>' . $user_client->getUserAgent() . '</dd>';
519
		$browser .= '<dt>' . __( 'Platform:', 'google-calendar-events' ) .     '</dt>';
520
		$browser .= '<dd>' . $user_client->getPlatform() .  '</dd>';
521
		$browser .= '</dl>';
522
523
		$browser_export = $user_client->getBrowser() . ' ' . $user_client->getVersion() . ' (' . $user_client->getPlatform() . ')';
524
525
		$sections['client'] = array(
526
			'user_ip' => array(
527
				'label'  => __( 'IP Address', 'google-calendar-events' ),
528
				'label_export' => 'IP Address',
529
				'result' => $_SERVER['SERVER_ADDR'],
530
			),
531
			'browser' => array(
532
				'label'  => __( 'Browser', 'google-calendar-events' ),
533
				'result' => $browser,
534
				'result_export' => $browser_export,
535
			)
536
		);
537
538
		/**
539
		 * Final Output
540
		 * ============
541
		 */
542
543
		$panels   = apply_filters( 'simcal_system_status_report_panels', $panels );
544
		$sections = apply_filters( 'simcal_system_status_report_sections', $sections );
545
546
		foreach ( $panels as $panel => $v ) :
547
548
			if ( isset( $sections[ $panel ] ) ) :
549
550
				?>
551
				<table class="widefat simcal-system-status-report-panel">
552
					<thead class="<?php echo $panel; ?>">
553
						<tr>
554
							<th colspan="3" data-export="<?php echo $v['export']; ?>"><?php echo $v['label']; ?></th>
555
						</tr>
556
					</thead>
557
					<tbody>
558
						<?php foreach ( $sections[ $panel ] as $row => $cell ) : ?>
559
							<tr>
560
								<?php
561
								$label_export  = isset( $cell['label_export']  ) ? $cell['label_export']  : $cell['label'];
562
								$result_export = isset( $cell['result_export'] ) ? $cell['result_export'] : $cell['result'];
563
								?>
564
								<td class="tooltip"><?php echo isset( $cell['tooltip'] ) ? ' <i class="simcal-icon-help simcal-help-tip" data-tip="' . $cell['tooltip'] . '"></i> ' : ''; ?></td>
565
								<td class="label" data-export="<?php echo trim( $label_export ); ?>"><?php echo $cell['label']; ?></td>
566
								<td class="result" data-export="<?php echo trim( $result_export ); ?>"><?php echo $cell['result']; ?></td>
567
							</tr>
568
						<?php endforeach; ?>
569
					</tbody>
570
				</table>
571
				<?php
572
573
			endif;
574
575
		endforeach;
576
577
		$this->inline_scripts();
578
579
	}
580
581
	/**
582
	 * Print inline scripts.
583
	 *
584
	 * @since  3.0.0
585
	 * @access private
586
	 *
587
	 * @return void
588
	 */
589
	private function inline_scripts() {
590
591
		?>
592
		<script type="text/javascript">
593
594
			var report = '';
595
596
			jQuery( '.simcal-system-status-report-panel thead, .simcal-system-status-report-panel tbody' ).each( function() {
597
598
				if ( jQuery( this ).is( 'thead' ) ) {
599
600
					var label = jQuery( this ).find( 'th' ).data( 'export' );
601
					report = report + '\n### ' + jQuery.trim( label ) + ' ###\n\n';
602
603
				} else {
604
605
					jQuery( 'tr', jQuery( this ) ).each( function() {
606
607
						var label       = jQuery( this ).find( 'td:eq(1)' ).data( 'export' );
608
						var the_name    = jQuery.trim( label ).replace( /(<([^>]+)>)/ig, '' ); // Remove HTML
609
						var image       = jQuery( this ).find( 'td:eq(2)' ).find( 'img' ); // Get WP 4.2 emojis
610
						var prefix      = ( undefined === image.attr( 'alt' ) ) ? '' : image.attr( 'alt' ) + ' '; // Remove WP 4.2 emojis
611
						var the_value   = jQuery.trim( prefix + jQuery( this ).find( 'td:eq(2)' ).data( 'export' ) );
612
						var value_array = the_value.split( ', ' );
613
						if ( value_array.length > 1 ) {
614
							var temp_line ='';
615
							jQuery.each( value_array, function( key, line ) {
616
								temp_line = temp_line + line + '\n';
617
							});
618
							the_value = temp_line;
619
						}
620
621
						report = report + '' + the_name.trim() + ': ' + the_value.trim() + '\n';
622
					});
623
624
				}
625
626
			});
627
628
			try {
629
				jQuery( '#simcal-system-status-report textarea' ).val( report ).focus().select();
630
			} catch( e ){
631
				console.log( e );
632
			}
633
634
			function downloadReport( text, name, type ) {
635
				var a = document.getElementById( 'simcal-system-status-report-download' );
636
				var file = new Blob( [text], { type: type } );
637
				a.href = URL.createObjectURL(file);
638
				a.download = name;
639
			}
640
641
			jQuery( '#simcal-system-status-report-download' ).on( 'click', function() {
642
				var file = new Blob( [ report ], { type: 'text/plain' } );
643
				jQuery( this ).attr( 'href', URL.createObjectURL( file ) );
644
				jQuery( this ).attr( 'download', '<?php echo sanitize_title( str_replace( array( 'http://', 'https://' ), '', get_bloginfo( 'url' ) ) . '-system-report-' . date( 'Y-m-d', time() ) ); ?>' );
645
			} );
646
647
		</script>
648
		<?php
649
650
	}
651
652
	/**
653
	 * PHP sizes conversions.
654
	 *
655
	 * This function transforms the php.ini notation for numbers (like '2M') to an integer.
656
	 *
657
	 * @since  3.0.0
658
	 * @access private
659
	 *
660
	 * @param  string $size
661
	 *
662
	 * @return int|double|string
663
	 */
664
	private function let_to_num( $size ) {
665
666
		$l   = substr( $size, -1 );
667
		$ret = substr( $size, 0, -1 );
668
669
		// Note: do not insert break or default in this switch loop.
670
		switch ( strtoupper( $l ) ) {
671
			case 'P':
672
				$ret *= 1024;
673
				// no break
674
			case 'T':
675
				$ret *= 1024;
676
				// no break
677
			case 'G':
678
				$ret *= 1024;
679
				// no break
680
			case 'M':
681
				$ret *= 1024;
682
				// no break
683
			case 'K':
684
				$ret *= 1024;;
685
				// no break
686
		}
687
688
		return $ret;
689
	}
690
691
	/**
692
	 * Add sections.
693
	 *
694
	 * @since  3.0.0
695
	 *
696
	 * @return array
697
	 */
698
	public function add_sections() {
699
		return array();
700
	}
701
702
	/**
703
	 * Add fields.
704
	 *
705
	 * @since  3.0.0
706
	 *
707
	 * @return array
708
	 */
709
	public function add_fields() {
710
		return array();
711
	}
712
713
}
714