Completed
Push — 97-fix/system-info-section ( 7fb1eb...d62b43 )
by Rajan
01:54
created

SystemInfoPage::el_print_current_plugins()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 0
dl 0
loc 13
ccs 0
cts 9
cp 0
crap 12
rs 9.8333
c 0
b 0
f 0
1
<?php namespace EmailLog\Core\UI\Page;
2
3
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
4
5
/**
6
 * System Info Page.
7
 * This page is displayed about ststem info.
8
 *
9
 * @since 2.0.0
10
 */
11
class SystemInfoPage extends BasePage {
12
	const PAGE_SLUG = 'system_infos';
13
14
	/**
15
	 * Capability to manage system info.
16
	 *
17
	 * @since 2.3.0
18
	 */
19
	const CAPABILITY = 'manage_system_infos';
20
21
	/**
22
	 * Specify additional hooks.
23
	 *
24
	 * @inheritdoc
25
	 */
26
	public function load() {
27
		parent::load();
28
29
		$this->messages = array(
0 ignored issues
show
Bug introduced by
The property messages does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
30
			'info_message' => __( 'Please include this information when posting support requests.', 'email-log' ),
31
		);
32
33
		$this->actions     = array( 'download_sysinfo' );
0 ignored issues
show
Bug introduced by
The property actions does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
34
		add_action( 'el_download_sysinfo', array( $this, 'generate_sysinfo_download' ) );
35
36
		add_action( 'admin_init', array( $this, 'request_handler' ) );
37
		add_filter( 'el_action_nonce_check', array( $this, 'verify_nonce' ), 10, 2 );
38
	}
39
40
	/**
41
	 * Check for nonce before executing the action.
42
	 *
43
	 * @param bool   $result The current result.
44
	 * @param string $action Action name.
45
	 *
46
	 * @return bool True if nonce is verified, False otherwise.
47
	 */
48
	public function verify_nonce( $result, $action ) {
49
		/**
50
		 * List of actions for page.
51
		 *
52
		 * @param array    $actions Actions.
53
		 * @param BasePage $page    Page objects.
54
		 *
55
		 * @since 2.3.0
56
		 */
57
		$page_actions = apply_filters( 'el_page_actions', $this->actions, $this );
58
59
		if ( in_array( $action, $page_actions, true ) ) {
60
			if ( check_admin_referer( 'el-{self::PAGE_SLUG}', 'el-{self::PAGE_SLUG}-nonce' ) ) {
61
				return true;
62
			}
63
		}
64
65
		return $result;
66
	}
67
68
	/**
69
	 * Register page.
70
	 */
71
	public function register_page() {
72
73
		$this->page = add_submenu_page(
74
			LogListPage::PAGE_SLUG,
75
			__( 'System Info', 'email-log' ),
76
			__( 'System Info', 'email-log' ),
77
			'manage_options',
78
			self::PAGE_SLUG,
79
			array( $this, 'render_page' )
80
		);
81
82
		add_action( "load-{$this->page}", array( $this, 'render_help_tab' ) );
83
	}
84
85
	/**
86
	 * Get current theme name.
87
	 *
88
	 * @return string Current theme name.
89
	 */
90
	protected function el_get_current_theme_name() {
91
		if ( get_bloginfo( 'version' ) < '3.4' ) {
92
			$theme_data = get_theme_data( get_stylesheet_directory() . '/style.css' );
93
94
			return $theme_data['Name'] . ' ' . $theme_data['Version'];
95
		} else {
96
			$theme_data = wp_get_theme();
97
98
			return $theme_data->Name . ' ' . $theme_data->Version;
99
		}
100
	}
101
102
	/**
103
	 * Try to identity the hosting provider.
104
	 *
105
	 * @return string Web host name if identified, empty string otherwise.
106
	 */
107
	protected function el_identify_host() {
108
		$host = '';
109
		if ( defined( 'WPE_APIKEY' ) ) {
110
			$host = 'WP Engine';
111
		} elseif ( defined( 'PAGELYBIN' ) ) {
112
			$host = 'Pagely';
113
		}
114
115
		return $host;
116
	}
117
118
	/**
119
	 * Print plugins that are currently active.
120
	 */
121
	protected function el_print_current_plugins() {
122
		$plugins        = get_plugins();
123
		$active_plugins = get_option( 'active_plugins', array() );
124
125
		foreach ( $plugins as $plugin_path => $plugin ) {
126
			// If the plugin isn't active, don't show it.
127
			if ( ! in_array( $plugin_path, $active_plugins ) ) {
128
				continue;
129
			}
130
131
			echo $plugin['Name'] . ': ' . $plugin['Version'] . "\n";
132
		}
133
	}
134
135
	/**
136
	 * Print network active plugins.
137
	 */
138
	protected function el_print_network_active_plugins() {
139
		$plugins        = wp_get_active_network_plugins();
140
		$active_plugins = get_site_option( 'active_sitewide_plugins', array() );
141
142
		foreach ( $plugins as $plugin_path ) {
143
			$plugin_base = plugin_basename( $plugin_path );
144
145
			// If the plugin isn't active, don't show it.
146
			if ( ! array_key_exists( $plugin_base, $active_plugins ) ) {
147
				continue;
148
			}
149
150
			$plugin = get_plugin_data( $plugin_path );
151
152
			echo $plugin['Name'] . ' :' . $plugin['Version'] . "\n";
153
		}
154
	}
155
156
	protected function el_plugin_version() {
157
		$plugin_path = WP_PLUGIN_DIR . '/email-log/email-log.php';
158
		$plugin_data = get_plugin_data( $plugin_path );
159
		echo $plugin_data['Version'];
160
	}
161
162
	/**
163
	 * Render the page.
164
	 */
165
	public function render_page() {
166
		global $wpdb;
167
		?>
168
		<form method = "post">
169
		<div class="updated">
170
			<p><strong><?php echo $this->messages['info_message']; ?></strong></p>
171
		</div>
172
173
		<?php if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) { ?>
174
			<div class="notice notice-warning">
175
				<p><strong>
176
					<?php printf( __( 'SAVEQUERIES is <a href="%s" target="_blank">enabled</a>. This puts additional load on the memory and will restrict the number of items that can be deleted.', 'bulk-delete' ), 'https://codex.wordpress.org/Editing_wp-config.php#Save_queries_for_analysis' ); ?>
177
				</strong></p>
178
			</div>
179
		<?php } ?>
180
181
		<?php if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) { ?>
182
			<div class="notice notice-warning">
183
				<p><strong>
184
					<?php printf( __( 'DISABLE_WP_CRON is <a href="%s" target="_blank">enabled</a>. This prevents scheduler from running.', 'bulk-delete' ), 'https://codex.wordpress.org/Editing_wp-config.php#Disable_Cron_and_Cron_Timeout' ); ?>
185
				</strong></p>
186
			</div>
187
		<?php } ?>
188
		<div class="wrap">
189
			<h1><?php _e( 'Email Log  - System Info', 'email-log' ); ?></h1>
190
191
		<textarea wrap="off" style="width:100%;height:500px;font-family:Menlo,Monaco,monospace;white-space:pre;" readonly="readonly" onclick="this.focus();this.select()" id="system-info-textarea" name="email-log-sysinfo" title="<?php _e( 'To copy the system info, click below then press Ctrl + C (PC) or Cmd + C (Mac).', 'bulk-delete' ); ?>">
192
### Begin System Info ###
193
<?php
194
	/**
195
	 * Runs before displaying system info.
196
	 *
197
	 * This action is primarily for adding extra content in System Info.
198
	 */
199
	do_action( 'el_system_info_before' );
200
?>
201
202
Multisite:                <?php echo is_multisite() ? 'Yes' . "\n" : 'No' . "\n" ?>
203
204
SITE_URL:                 <?php echo site_url() . "\n"; ?>
205
HOME_URL:                 <?php echo home_url() . "\n"; ?>
206
Browser:                  <?php echo esc_html( $_SERVER['HTTP_USER_AGENT'] ), "\n"; ?>
207
208
Permalink Structure:      <?php echo get_option( 'permalink_structure' ) . "\n"; ?>
209
Active Theme:             <?php echo $this->el_get_current_theme_name() . "\n"; ?>
210
<?php
211
		$host = $this->el_identify_host();
212
		if ( '' !== $host ) : ?>
213
Host:                     <?php echo $host . "\n\n"; ?>
214
<?php endif; ?>
215
216
<?php $post_types = get_post_types(); ?>
217
Registered Post types:    <?php echo implode( ', ', $post_types ) . "\n"; ?>
218
<?php
219
		foreach ( $post_types as $post_type ) {
220
			echo $post_type;
221
			if ( strlen( $post_type ) < 26 ) {
222
				echo str_repeat( ' ', 26 - strlen( $post_type ) );
223
			}
224
			$post_count = wp_count_posts( $post_type );
225
			foreach ( $post_count as $key => $value ) {
226
				echo $key, '=', $value, ', ';
227
			}
228
			echo "\n";
229
		}
230
?>
231
232
<?php $taxonomies = get_taxonomies(); ?>
233
Registered Taxonomies:    <?php echo implode( ', ', $taxonomies ) . "\n"; ?>
234
235
Email log Version:        <?php $this->el_plugin_version() . "\n"; ?>
236
WordPress Version:        <?php echo get_bloginfo( 'version' ) . "\n"; ?>
237
PHP Version:              <?php echo PHP_VERSION . "\n"; ?>
238
MySQL Version:            <?php echo $wpdb->db_version() . "\n"; ?>
239
Web Server Info:          <?php echo $_SERVER['SERVER_SOFTWARE'] . "\n"; ?>
240
241
WordPress Memory Limit:   <?php echo WP_MEMORY_LIMIT; ?><?php echo "\n"; ?>
242
WordPress Max Limit:      <?php echo WP_MAX_MEMORY_LIMIT; ?><?php echo "\n"; ?>
243
PHP Memory Limit:         <?php echo ini_get( 'memory_limit' ) . "\n"; ?>
244
245
SAVEQUERIES:              <?php echo defined( 'SAVEQUERIES' ) ? SAVEQUERIES ? 'Enabled' . "\n" : 'Disabled' . "\n" : 'Not set' . "\n" ?>
246
WP_DEBUG:                 <?php echo defined( 'WP_DEBUG' ) ? WP_DEBUG ? 'Enabled' . "\n" : 'Disabled' . "\n" : 'Not set' . "\n" ?>
247
WP_SCRIPT_DEBUG:          <?php echo defined( 'WP_SCRIPT_DEBUG' ) ? WP_SCRIPT_DEBUG ? 'Enabled' . "\n" : 'Disabled' . "\n" : 'Not set' . "\n" ?>
248
249
GMT Offset:               <?php echo esc_html( get_option( 'gmt_offset' ) ), "\n\n"; ?>
250
DISABLE_WP_CRON:          <?php echo defined( 'DISABLE_WP_CRON' ) ? DISABLE_WP_CRON ? 'Yes' . "\n" : 'No' . "\n" : 'Not set' . "\n" ?>
251
WP_CRON_LOCK_TIMEOUT:     <?php echo defined( 'WP_CRON_LOCK_TIMEOUT' ) ? WP_CRON_LOCK_TIMEOUT : 'Not set', "\n" ?>
252
EMPTY_TRASH_DAYS:         <?php echo defined( 'EMPTY_TRASH_DAYS' ) ? EMPTY_TRASH_DAYS : 'Not set', "\n" ?>
253
254
PHP Safe Mode:            <?php echo ini_get( 'safe_mode' ) ? 'Yes' : 'No', "\n"; // phpcs:ignore PHPCompatibility.PHP.DeprecatedIniDirectives.safe_modeDeprecatedRemoved?>
255
PHP Upload Max Size:      <?php echo ini_get( 'upload_max_filesize' ) . "\n"; ?>
256
PHP Post Max Size:        <?php echo ini_get( 'post_max_size' ) . "\n"; ?>
257
PHP Upload Max Filesize:  <?php echo ini_get( 'upload_max_filesize' ) . "\n"; ?>
258
PHP Time Limit:           <?php echo ini_get( 'max_execution_time' ) . "\n"; ?>
259
PHP Max Input Vars:       <?php echo ini_get( 'max_input_vars' ) . "\n"; // phpcs:ignore PHPCompatibility.PHP.NewIniDirectives.max_input_varsFound?>
260
PHP Arg Separator:        <?php echo ini_get( 'arg_separator.output' ) . "\n"; ?>
261
PHP Allow URL File Open:  <?php echo ini_get( 'allow_url_fopen' ) ? 'Yes' : 'No', "\n"; ?>
262
263
WP Table Prefix:          <?php echo $wpdb->prefix, "\n";?>
264
265
Session:                  <?php echo isset( $_SESSION ) ? 'Enabled' : 'Disabled'; ?><?php echo "\n"; ?>
266
Session Name:             <?php echo esc_html( ini_get( 'session.name' ) ); ?><?php echo "\n"; ?>
267
Cookie Path:              <?php echo esc_html( ini_get( 'session.cookie_path' ) ); ?><?php echo "\n"; ?>
268
Save Path:                <?php echo esc_html( ini_get( 'session.save_path' ) ); ?><?php echo "\n"; ?>
269
Use Cookies:              <?php echo ini_get( 'session.use_cookies' ) ? 'On' : 'Off'; ?><?php echo "\n"; ?>
270
Use Only Cookies:         <?php echo ini_get( 'session.use_only_cookies' ) ? 'On' : 'Off'; ?><?php echo "\n"; ?>
271
272
DISPLAY ERRORS:           <?php echo ( ini_get( 'display_errors' ) ) ? 'On (' . ini_get( 'display_errors' ) . ')' : 'N/A'; ?><?php echo "\n"; ?>
273
FSOCKOPEN:                <?php echo ( function_exists( 'fsockopen' ) ) ? 'Your server supports fsockopen.' : 'Your server does not support fsockopen.'; ?><?php echo "\n"; ?>
274
cURL:                     <?php echo ( function_exists( 'curl_init' ) ) ? 'Your server supports cURL.' : 'Your server does not support cURL.'; ?><?php echo "\n"; ?>
275
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"; ?>
276
SUHOSIN:                  <?php echo ( extension_loaded( 'suhosin' ) ) ? 'Your server has SUHOSIN installed.' : 'Your server does not have SUHOSIN installed.'; ?><?php echo "\n"; ?>
277
278
ACTIVE PLUGINS:
279
280
<?php $this->el_print_current_plugins(); ?>
281
282
<?php
283
		if ( is_multisite() ) : ?>
284
NETWORK ACTIVE PLUGINS:
285
286
<?php
287
			$this->el_print_network_active_plugins();
288
		endif;
289
?>
290
291
<?php do_action( 'el_system_info_after' );?>
292
### End System Info ###</textarea>
293
294
		<p class="submit">
295
			<input type="hidden" name="el_action" value="download_sysinfo">
296
			<?php submit_button( 'Download System Info File', 'primary', 'email-log-sysinfo', false ); ?>
297
		</p>
298
299
300
		</div>
301
	</form>
302
		<?php
303
304
		$this->render_page_footer();
305
	}
306
307
	/**
308
	 * Generates the System Info Download File.
309
	 */
310
	public function generate_sysinfo_download() {
311
		nocache_headers();
312
313
		header( 'Content-type: text/plain' );
314
		header( 'Content-Disposition: attachment; filename="email-log-system-info.txt"' );
315
316
		echo wp_strip_all_tags( $_POST['email-log-sysinfo'] );
317
		die();
318
	}
319
320
	/**
321
	 * Handle both POST and GET requests.
322
	 * This method automatically triggers all the actions after checking the nonce.
323
	 */
324
	public function request_handler() {
325
		if ( isset( $_POST['el_action'] ) ) {
326
			$el_action   = sanitize_text_field( $_POST['el_action'] );
327
328
			/**
329
			 * Perform the operation.
330
			 * This hook is for doing the operation. Nonce check has already happened by this point.
331
			 *
332
			 * @since 2.3.0
333
			 */
334
			do_action( 'el_' . $el_action, $_POST );
335
		}
336
	}
337
338
}
339