1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EmailLog\Core\UI\Component; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Shows and generates the System Info file. |
7
|
|
|
* |
8
|
|
|
* This will be moved into a seperate repo as a library. |
9
|
|
|
* |
10
|
|
|
* Greatly inspired (and shares code) from the system info component in Easy Digital Downloads plugin. |
11
|
|
|
* |
12
|
|
|
* @since 2.3.0 |
13
|
|
|
*/ |
14
|
|
|
class SystemInfo { |
15
|
|
|
/** |
16
|
|
|
* Plugin slug. |
17
|
|
|
* |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $plugin_slug = ''; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Config that controls which sections should be displayed. |
24
|
|
|
* |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
protected $config = array(); |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* SystemInfo constructor. |
31
|
|
|
* |
32
|
|
|
* @param string $plugin_slug Slug of the plugin. |
33
|
|
|
* @param array $config (Optional) Configuration options. |
34
|
|
|
* |
35
|
|
|
* @see SystemInfo::get_default_config for the list of default config information. |
36
|
|
|
*/ |
37
|
|
|
public function __construct( $plugin_slug, $config = array() ) { |
38
|
|
|
$this->plugin_slug = $plugin_slug; |
39
|
|
|
$this->config = wp_parse_args( $config, $this->get_default_config() ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Get Default configuration. |
44
|
|
|
* |
45
|
|
|
* @return array Default configuration. |
46
|
|
|
*/ |
47
|
|
|
protected function get_default_config() { |
48
|
|
|
return array( |
49
|
|
|
'show_post_types' => true, |
50
|
|
|
'show_taxonomies' => true, |
51
|
|
|
'show_plugins' => true, |
52
|
|
|
'show_network_plugins' => true, |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Render system info. |
58
|
|
|
* |
59
|
|
|
* PHPCS is disabled for this function since aligned will mess up the system info output. |
60
|
|
|
* phpcs:disable |
61
|
|
|
*/ |
62
|
|
|
public function render() { |
63
|
|
|
global $wpdb; |
64
|
|
|
|
65
|
|
|
?> |
66
|
|
|
<textarea wrap="off" readonly="readonly" name="<?php echo esc_attr( $this->plugin_slug ); ?>-system-info" |
67
|
|
|
style="font-family:Menlo,Monaco,monospace; white-space:pre; width:100%; height:500px;" onclick="this.focus();this.select()" |
68
|
|
|
title="<?php _e( 'To copy the system info, click below then press Ctrl + C (PC) or Cmd + C (Mac).', 'email-log' ); ?>"> |
69
|
|
|
### Begin System Info (Generated <?php echo date( 'Y-m-d H:i:s') ?>) ### |
70
|
|
|
|
71
|
|
|
<?php |
72
|
|
|
/** |
73
|
|
|
* Runs before displaying system info. |
74
|
|
|
* |
75
|
|
|
* This action is primarily for adding extra content in System Info. |
76
|
|
|
* |
77
|
|
|
* @param string $plugin_name Plugin slug. |
78
|
|
|
*/ |
79
|
|
|
do_action( 'system_info_before', $this->plugin_slug ); |
80
|
|
|
$locale = get_locale(); |
81
|
|
|
?> |
82
|
|
|
|
83
|
|
|
-- Site Info |
84
|
|
|
|
85
|
|
|
Site URL: <?php echo site_url() . "\n"; ?> |
86
|
|
|
Home URL: <?php echo home_url() . "\n"; ?> |
87
|
|
|
Multisite: <?php echo is_multisite() ? 'Yes' . "\n" : 'No' . "\n"; ?> |
88
|
|
|
|
89
|
|
|
<?php |
90
|
|
|
$host = $this->identify_host(); |
91
|
|
|
if ( ! empty( $host ) ) : ?> |
92
|
|
|
-- Hosting Provider |
93
|
|
|
|
94
|
|
|
Host: <?php echo $host . "\n"; ?> |
95
|
|
|
<?php endif; ?> |
96
|
|
|
-- User Browser |
97
|
|
|
|
98
|
|
|
Platform: <?php echo php_uname('s') . "\n"; ?> |
99
|
|
|
User Agent String: <?php echo esc_html( $_SERVER['HTTP_USER_AGENT'] ), "\n"; ?> |
100
|
|
|
|
101
|
|
|
-- WordPress Configuration: |
102
|
|
|
|
103
|
|
|
Version: <?php echo get_bloginfo( 'version' ) . "\n"; ?> |
104
|
|
|
Language: <?php ( ! empty( $locale ) ? $locale : 'en_US' ) . "\n"; ?> |
105
|
|
|
Permalink Structure: <?php echo get_option( 'permalink_structure' ) . "\n"; ?> |
|
|
|
|
106
|
|
|
Active Theme: <?php echo $this->get_current_theme_name() . "\n"; ?> |
107
|
|
|
ABSPATH: <?php echo ABSPATH . "\n"; ?> |
108
|
|
|
WP Table Prefix: <?php echo $wpdb->prefix, "\n"; ?> |
109
|
|
|
WP_DEBUG: <?php echo defined( 'WP_DEBUG' ) ? WP_DEBUG ? 'Enabled' . "\n" : 'Disabled' . "\n" : 'Not set' . "\n"; ?> |
110
|
|
|
Memory Limit: <?php echo WP_MEMORY_LIMIT; ?><?php echo "\n"; ?> |
111
|
|
|
Memory Max Limit: <?php echo WP_MAX_MEMORY_LIMIT; ?><?php echo "\n"; ?> |
112
|
|
|
WP_SCRIPT_DEBUG: <?php echo defined( 'WP_SCRIPT_DEBUG' ) ? WP_SCRIPT_DEBUG ? 'Enabled' . "\n" : 'Disabled' . "\n" : 'Not set' . "\n"; ?> |
|
|
|
|
113
|
|
|
GMT Offset: <?php echo esc_html( get_option( 'gmt_offset' ) ), "\n"; ?> |
|
|
|
|
114
|
|
|
DISABLE_WP_CRON: <?php echo defined( 'DISABLE_WP_CRON' ) ? DISABLE_WP_CRON ? 'Yes' . "\n" : 'No' . "\n" : 'Not set' . "\n"; ?> |
115
|
|
|
WP_CRON_LOCK_TIMEOUT: <?php echo defined( 'WP_CRON_LOCK_TIMEOUT' ) ? WP_CRON_LOCK_TIMEOUT : 'Not set', "\n"; ?> |
116
|
|
|
EMPTY_TRASH_DAYS: <?php echo defined( 'EMPTY_TRASH_DAYS' ) ? EMPTY_TRASH_DAYS : 'Not set', "\n"; ?> |
117
|
|
|
|
118
|
|
|
<?php if ( $this->config['show_post_types'] ) : ?> |
119
|
|
|
<?php $post_types = get_post_types(); ?> |
120
|
|
|
Registered Post types: <?php echo implode( ', ', $post_types ) . "\n"; ?> |
121
|
|
|
<?php |
122
|
|
|
foreach ( $post_types as $post_type ) { |
123
|
|
|
echo $post_type; |
124
|
|
|
if ( strlen( $post_type ) < 26 ) { |
125
|
|
|
echo str_repeat( ' ', 26 - strlen( $post_type ) ); |
126
|
|
|
} |
127
|
|
|
$post_count = wp_count_posts( $post_type ); |
128
|
|
|
foreach ( $post_count as $key => $value ) { |
129
|
|
|
echo $key, '=', $value, ', '; |
130
|
|
|
} |
131
|
|
|
echo "\n"; |
132
|
|
|
} |
133
|
|
|
?> |
134
|
|
|
<?php endif; ?> |
135
|
|
|
|
136
|
|
|
<?php if ( $this->config['show_taxonomies'] ) : ?> |
137
|
|
|
<?php $taxonomies = get_taxonomies(); ?> |
138
|
|
|
Registered Taxonomies: <?php echo implode( ', ', $taxonomies ) . "\n"; ?> |
139
|
|
|
<?php endif; ?> |
140
|
|
|
<?php if ( $this->config['show_plugins'] ) : ?> |
141
|
|
|
-- WordPress Active Plugins |
142
|
|
|
|
143
|
|
|
<?php $this->print_current_plugins(); ?> |
144
|
|
|
<?php endif;?> |
145
|
|
|
|
146
|
|
|
<?php if ( $this->config['show_network_plugins'] ) : ?> |
147
|
|
|
<?php if ( is_multisite() ) : ?> |
148
|
|
|
-- Network Active Plugins |
149
|
|
|
|
150
|
|
|
<?php $this->print_network_active_plugins(); ?> |
151
|
|
|
<?php endif;?> |
152
|
|
|
<?php endif;?> |
153
|
|
|
-- Webserver Configuration |
154
|
|
|
|
155
|
|
|
PHP Version: <?php echo PHP_VERSION . "\n"; ?> |
156
|
|
|
MySQL Version: <?php echo $wpdb->db_version() . "\n"; ?> |
157
|
|
|
Web Server Info: <?php echo $_SERVER['SERVER_SOFTWARE'] . "\n"; ?> |
158
|
|
|
|
159
|
|
|
-- PHP Configuration |
160
|
|
|
|
161
|
|
|
PHP Memory Limit: <?php echo ini_get( 'memory_limit' ) . "\n"; ?> |
162
|
|
|
SAVEQUERIES: <?php echo defined( 'SAVEQUERIES' ) ? SAVEQUERIES ? 'Enabled' . "\n" : 'Disabled' . "\n" : 'Not set' . "\n"; ?> |
|
|
|
|
163
|
|
|
PHP Safe Mode: <?php echo ini_get( 'safe_mode' ) ? 'Yes' : 'No', "\n"; // phpcs:ignore PHPCompatibility.PHP.DeprecatedIniDirectives.safe_modeDeprecatedRemoved?> |
164
|
|
|
PHP Upload Max Size: <?php echo ini_get( 'upload_max_filesize' ) . "\n"; ?> |
165
|
|
|
PHP Post Max Size: <?php echo ini_get( 'post_max_size' ) . "\n"; ?> |
166
|
|
|
PHP Upload Max Filesize: <?php echo ini_get( 'upload_max_filesize' ) . "\n"; ?> |
167
|
|
|
PHP Time Limit: <?php echo ini_get( 'max_execution_time' ) . "\n"; ?> |
168
|
|
|
PHP Max Input Vars: <?php echo ini_get( 'max_input_vars' ) . "\n"; // phpcs:ignore PHPCompatibility.PHP.NewIniDirectives.max_input_varsFound?> |
169
|
|
|
Display Errors: <?php echo ( ini_get( 'display_errors' ) ) ? 'On (' . ini_get( 'display_errors' ) . ')' : 'N/A'; ?><?php echo "\n"; ?> |
170
|
|
|
PHP Arg Separator: <?php echo ini_get( 'arg_separator.output' ) . "\n"; ?> |
171
|
|
|
PHP Allow URL File Open: <?php echo ini_get( 'allow_url_fopen' ) ? 'Yes' : 'No', "\n"; ?> |
172
|
|
|
|
173
|
|
|
-- PHP Extensions |
174
|
|
|
|
175
|
|
|
fsockopen: <?php echo ( function_exists( 'fsockopen' ) ) ? 'Your server supports fsockopen.' : 'Your server does not support fsockopen.'; ?><?php echo "\n"; ?> |
176
|
|
|
cURL: <?php echo ( function_exists( 'curl_init' ) ) ? 'Your server supports cURL.' : 'Your server does not support cURL.'; ?><?php echo "\n"; ?> |
177
|
|
|
SOAP Client: <?php echo ( class_exists( 'SoapClient' ) ) ? 'Your server has the SOAP Client enabled.' : 'Your server does not have the SOAP Client enabled.'; ?><?php echo "\n"; ?> |
178
|
|
|
SUHOSIN: <?php echo ( extension_loaded( 'suhosin' ) ) ? 'Your server has SUHOSIN installed.' : 'Your server does not have SUHOSIN installed.'; ?><?php echo "\n"; ?> |
179
|
|
|
|
180
|
|
|
-- Session Configuration |
181
|
|
|
|
182
|
|
|
Session: <?php echo isset( $_SESSION ) ? 'Enabled' : 'Disabled'; ?><?php echo "\n"; ?> |
183
|
|
|
Session Name: <?php echo esc_html( ini_get( 'session.name' ) ); ?><?php echo "\n"; ?> |
184
|
|
|
Cookie Path: <?php echo esc_html( ini_get( 'session.cookie_path' ) ); ?><?php echo "\n"; ?> |
185
|
|
|
Save Path: <?php echo esc_html( ini_get( 'session.save_path' ) ); ?><?php echo "\n"; ?> |
186
|
|
|
Use Cookies: <?php echo ini_get( 'session.use_cookies' ) ? 'On' : 'Off'; ?><?php echo "\n"; ?> |
187
|
|
|
Use Only Cookies: <?php echo ini_get( 'session.use_only_cookies' ) ? 'On' : 'Off'; ?><?php echo "\n"; ?> |
188
|
|
|
|
189
|
|
|
<?php |
190
|
|
|
/** |
191
|
|
|
* Runs after displaying system info. |
192
|
|
|
* |
193
|
|
|
* This action is primarily for adding extra content in System Info. |
194
|
|
|
* |
195
|
|
|
* @param string $plugin_name Plugin slug. |
196
|
|
|
*/ |
197
|
|
|
do_action( 'system_info_after', $this->plugin_slug ); ?> |
198
|
|
|
### End System Info ###</textarea> |
199
|
|
|
<?php |
200
|
|
|
} |
201
|
|
|
// phpcs:enable |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Download System info as a file. |
205
|
|
|
* |
206
|
|
|
* @param string $file_name (Optional)Name of the file. Default is {plugin slug}-system-info.txt. |
207
|
|
|
*/ |
208
|
|
|
public function download_as_file( $file_name = '' ) { |
209
|
|
|
if ( empty( $file_name ) ) { |
210
|
|
|
$file_name = $this->plugin_slug . '-system-info.txt'; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
nocache_headers(); |
214
|
|
|
|
215
|
|
|
header( 'Content-type: text/plain' ); |
216
|
|
|
header( 'Content-Disposition: attachment; filename="' . $file_name . '"' ); |
217
|
|
|
|
218
|
|
|
echo wp_strip_all_tags( $_POST[ $this->plugin_slug . '-system-info'] ); |
219
|
|
|
die(); |
|
|
|
|
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Get current theme name. |
224
|
|
|
* |
225
|
|
|
* @return string Current theme name. |
226
|
|
|
*/ |
227
|
|
|
protected function get_current_theme_name() { |
228
|
|
|
if ( get_bloginfo( 'version' ) < '3.4' ) { |
229
|
|
|
$theme_data = get_theme_data( get_stylesheet_directory() . '/style.css' ); |
|
|
|
|
230
|
|
|
|
231
|
|
|
return $theme_data['Name'] . ' ' . $theme_data['Version']; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
$theme_data = wp_get_theme(); |
235
|
|
|
|
236
|
|
|
return $theme_data->Name . ' ' . $theme_data->Version; |
|
|
|
|
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* Try to identity the hosting provider. |
241
|
|
|
* |
242
|
|
|
* @return string Web host name if identified, empty string otherwise. |
243
|
|
|
*/ |
244
|
|
|
protected function identify_host() { |
245
|
|
|
$host = ''; |
246
|
|
|
|
247
|
|
|
if ( defined( 'WPE_APIKEY' ) ) { |
248
|
|
|
$host = 'WP Engine'; |
249
|
|
|
} elseif ( defined( 'PAGELYBIN' ) ) { |
250
|
|
|
$host = 'Pagely'; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* Filter the identified webhost. |
255
|
|
|
* |
256
|
|
|
* @param string $host Identified web host. |
257
|
|
|
* @param string $plugin_name Plugin slug. |
258
|
|
|
*/ |
259
|
|
|
return apply_filters( 'system_info_host', $host, $this->plugin_slug ); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* Print plugins that are currently active. |
264
|
|
|
*/ |
265
|
|
|
protected function print_current_plugins() { |
266
|
|
|
$plugins = get_plugins(); |
267
|
|
|
$active_plugins = get_option( 'active_plugins', array() ); |
268
|
|
|
|
269
|
|
|
foreach ( $plugins as $plugin_path => $plugin ) { |
270
|
|
|
// If the plugin isn't active, don't show it. |
271
|
|
|
if ( ! in_array( $plugin_path, $active_plugins, true ) ) { |
|
|
|
|
272
|
|
|
continue; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
echo $plugin['Name'] . ': ' . $plugin['Version'] . "\n"; |
276
|
|
|
} |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* Print network active plugins. |
281
|
|
|
*/ |
282
|
|
|
protected function print_network_active_plugins() { |
283
|
|
|
$plugins = wp_get_active_network_plugins(); |
284
|
|
|
$active_plugins = get_site_option( 'active_sitewide_plugins', array() ); |
285
|
|
|
|
286
|
|
|
foreach ( $plugins as $plugin_path ) { |
287
|
|
|
$plugin_base = plugin_basename( $plugin_path ); |
288
|
|
|
|
289
|
|
|
// If the plugin isn't active, don't show it. |
290
|
|
|
if ( ! array_key_exists( $plugin_base, $active_plugins ) ) { |
291
|
|
|
continue; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
$plugin = get_plugin_data( $plugin_path ); |
295
|
|
|
|
296
|
|
|
echo $plugin['Name'] . ' :' . $plugin['Version'] . "\n"; |
297
|
|
|
} |
298
|
|
|
} |
299
|
|
|
} |
300
|
|
|
|