Completed
Pull Request — dev/2.3.0 (#145)
by Rajan
23:17 queued 21:45
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
37
	/**
38
	 * Register page.
39
	 */
40
	public function register_page() {
41
42
		$this->page = add_submenu_page(
43
			LogListPage::PAGE_SLUG,
44
			__( 'System Info', 'email-log' ),
45
			__( 'System Info', 'email-log' ),
46
			'manage_options',
47
			self::PAGE_SLUG,
48
			array( $this, 'render_page' )
49
		);
50
51
		add_action( "load-{$this->page}", array( $this, 'render_help_tab' ) );
52
	}
53
54
	/**
55
	 * Get current theme name.
56
	 *
57
	 * @return string Current theme name.
58
	 */
59
	protected function el_get_current_theme_name() {
60
		if ( get_bloginfo( 'version' ) < '3.4' ) {
61
			$theme_data = get_theme_data( get_stylesheet_directory() . '/style.css' );
62
63
			return $theme_data['Name'] . ' ' . $theme_data['Version'];
64
		} else {
65
			$theme_data = wp_get_theme();
66
67
			return $theme_data->Name . ' ' . $theme_data->Version;
68
		}
69
	}
70
71
	/**
72
	 * Try to identity the hosting provider.
73
	 *
74
	 * @return string Web host name if identified, empty string otherwise.
75
	 */
76
	protected function el_identify_host() {
77
		$host = '';
78
		if ( defined( 'WPE_APIKEY' ) ) {
79
			$host = 'WP Engine';
80
		} elseif ( defined( 'PAGELYBIN' ) ) {
81
			$host = 'Pagely';
82
		}
83
84
		return $host;
85
	}
86
87
	/**
88
	 * Print plugins that are currently active.
89
	 */
90
	protected function el_print_current_plugins() {
91
		$plugins        = get_plugins();
92
		$active_plugins = get_option( 'active_plugins', array() );
93
94
		foreach ( $plugins as $plugin_path => $plugin ) {
95
			// If the plugin isn't active, don't show it.
96
			if ( ! in_array( $plugin_path, $active_plugins ) ) {
97
				continue;
98
			}
99
100
			echo $plugin['Name'] . ': ' . $plugin['Version'] . "\n";
101
		}
102
	}
103
104
	/**
105
	 * Print network active plugins.
106
	 */
107
	protected function el_print_network_active_plugins() {
108
		$plugins        = wp_get_active_network_plugins();
109
		$active_plugins = get_site_option( 'active_sitewide_plugins', array() );
110
111
		foreach ( $plugins as $plugin_path ) {
112
			$plugin_base = plugin_basename( $plugin_path );
113
114
			// If the plugin isn't active, don't show it.
115
			if ( ! array_key_exists( $plugin_base, $active_plugins ) ) {
116
				continue;
117
			}
118
119
			$plugin = get_plugin_data( $plugin_path );
120
121
			echo $plugin['Name'] . ' :' . $plugin['Version'] . "\n";
122
		}
123
	}
124
125
	protected function el_plugin_version() {
126
		$plugin_path = WP_PLUGIN_DIR . '/email-log/email-log.php';
127
		$plugin_data = get_plugin_data( $plugin_path );
128
		echo $plugin_data['Version'];
129
	}
130
131
	/**
132
	 * Render the page.
133
	 * //TODO: Convert these sections into tabs.
134
	 */
135
	public function render_page() {
136
		global $wpdb;
137
		?>
138
		<div class="updated">
139
			<p><strong><?php echo $this->messages['info_message']; ?></strong></p>
140
		</div>
141
142
		<?php if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) { ?>
143
			<div class="notice notice-warning">
144
				<p><strong>
145
					<?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' ); ?>
146
				</strong></p>
147
			</div>
148
		<?php } ?>
149
150
		<?php if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) { ?>
151
			<div class="notice notice-warning">
152
				<p><strong>
153
					<?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' ); ?>
154
				</strong></p>
155
			</div>
156
		<?php } ?>
157
		<div class="wrap">
158
			<h1><?php _e( 'Email Log  - System Info', 'email-log' ); ?></h1>
159
160
		<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' ); ?>">
161
### Begin System Info ###
162
<?php
163
	/**
164
	 * Runs before displaying system info.
165
	 *
166
	 * This action is primarily for adding extra content in System Info.
167
	 */
168
	do_action( 'el_system_info_before' );
169
?>
170
171
Multisite:                <?php echo is_multisite() ? 'Yes' . "\n" : 'No' . "\n" ?>
172
173
SITE_URL:                 <?php echo site_url() . "\n"; ?>
174
HOME_URL:                 <?php echo home_url() . "\n"; ?>
175
Browser:                  <?php echo esc_html( $_SERVER['HTTP_USER_AGENT'] ), "\n"; ?>
176
177
Permalink Structure:      <?php echo get_option( 'permalink_structure' ) . "\n"; ?>
178
Active Theme:             <?php echo $this->el_get_current_theme_name() . "\n"; ?>
179
<?php
180
		$host = $this->el_identify_host();
181
		if ( '' !== $host ) : ?>
182
Host:                     <?php echo $host . "\n\n"; ?>
183
<?php endif; ?>
184
185
<?php $post_types = get_post_types(); ?>
186
Registered Post types:    <?php echo implode( ', ', $post_types ) . "\n"; ?>
187
<?php
188
		foreach ( $post_types as $post_type ) {
189
			echo $post_type;
190
			if ( strlen( $post_type ) < 26 ) {
191
				echo str_repeat( ' ', 26 - strlen( $post_type ) );
192
			}
193
			$post_count = wp_count_posts( $post_type );
194
			foreach ( $post_count as $key => $value ) {
195
				echo $key, '=', $value, ', ';
196
			}
197
			echo "\n";
198
		}
199
?>
200
201
<?php $taxonomies = get_taxonomies(); ?>
202
Registered Taxonomies:    <?php echo implode( ', ', $taxonomies ) . "\n"; ?>
203
204
Email log Version:        <?php $this->el_plugin_version() . "\n"; ?>
205
WordPress Version:        <?php echo get_bloginfo( 'version' ) . "\n"; ?>
206
PHP Version:              <?php echo PHP_VERSION . "\n"; ?>
207
MySQL Version:            <?php echo $wpdb->db_version() . "\n"; ?>
208
Web Server Info:          <?php echo $_SERVER['SERVER_SOFTWARE'] . "\n"; ?>
209
210
WordPress Memory Limit:   <?php echo WP_MEMORY_LIMIT; ?><?php echo "\n"; ?>
211
WordPress Max Limit:      <?php echo WP_MAX_MEMORY_LIMIT; ?><?php echo "\n"; ?>
212
PHP Memory Limit:         <?php echo ini_get( 'memory_limit' ) . "\n"; ?>
213
214
SAVEQUERIES:              <?php echo defined( 'SAVEQUERIES' ) ? SAVEQUERIES ? 'Enabled' . "\n" : 'Disabled' . "\n" : 'Not set' . "\n" ?>
215
WP_DEBUG:                 <?php echo defined( 'WP_DEBUG' ) ? WP_DEBUG ? 'Enabled' . "\n" : 'Disabled' . "\n" : 'Not set' . "\n" ?>
216
WP_SCRIPT_DEBUG:          <?php echo defined( 'WP_SCRIPT_DEBUG' ) ? WP_SCRIPT_DEBUG ? 'Enabled' . "\n" : 'Disabled' . "\n" : 'Not set' . "\n" ?>
217
218
GMT Offset:               <?php echo esc_html( get_option( 'gmt_offset' ) ), "\n\n"; ?>
219
DISABLE_WP_CRON:          <?php echo defined( 'DISABLE_WP_CRON' ) ? DISABLE_WP_CRON ? 'Yes' . "\n" : 'No' . "\n" : 'Not set' . "\n" ?>
220
WP_CRON_LOCK_TIMEOUT:     <?php echo defined( 'WP_CRON_LOCK_TIMEOUT' ) ? WP_CRON_LOCK_TIMEOUT : 'Not set', "\n" ?>
221
EMPTY_TRASH_DAYS:         <?php echo defined( 'EMPTY_TRASH_DAYS' ) ? EMPTY_TRASH_DAYS : 'Not set', "\n" ?>
222
223
PHP Safe Mode:            <?php echo ini_get( 'safe_mode' ) ? 'Yes' : 'No', "\n"; // phpcs:ignore PHPCompatibility.PHP.DeprecatedIniDirectives.safe_modeDeprecatedRemoved?>
224
PHP Upload Max Size:      <?php echo ini_get( 'upload_max_filesize' ) . "\n"; ?>
225
PHP Post Max Size:        <?php echo ini_get( 'post_max_size' ) . "\n"; ?>
226
PHP Upload Max Filesize:  <?php echo ini_get( 'upload_max_filesize' ) . "\n"; ?>
227
PHP Time Limit:           <?php echo ini_get( 'max_execution_time' ) . "\n"; ?>
228
PHP Max Input Vars:       <?php echo ini_get( 'max_input_vars' ) . "\n"; // phpcs:ignore PHPCompatibility.PHP.NewIniDirectives.max_input_varsFound?>
229
PHP Arg Separator:        <?php echo ini_get( 'arg_separator.output' ) . "\n"; ?>
230
PHP Allow URL File Open:  <?php echo ini_get( 'allow_url_fopen' ) ? 'Yes' : 'No', "\n"; ?>
231
232
WP Table Prefix:          <?php echo $wpdb->prefix, "\n";?>
233
234
Session:                  <?php echo isset( $_SESSION ) ? 'Enabled' : 'Disabled'; ?><?php echo "\n"; ?>
235
Session Name:             <?php echo esc_html( ini_get( 'session.name' ) ); ?><?php echo "\n"; ?>
236
Cookie Path:              <?php echo esc_html( ini_get( 'session.cookie_path' ) ); ?><?php echo "\n"; ?>
237
Save Path:                <?php echo esc_html( ini_get( 'session.save_path' ) ); ?><?php echo "\n"; ?>
238
Use Cookies:              <?php echo ini_get( 'session.use_cookies' ) ? 'On' : 'Off'; ?><?php echo "\n"; ?>
239
Use Only Cookies:         <?php echo ini_get( 'session.use_only_cookies' ) ? 'On' : 'Off'; ?><?php echo "\n"; ?>
240
241
DISPLAY ERRORS:           <?php echo ( ini_get( 'display_errors' ) ) ? 'On (' . ini_get( 'display_errors' ) . ')' : 'N/A'; ?><?php echo "\n"; ?>
242
FSOCKOPEN:                <?php echo ( function_exists( 'fsockopen' ) ) ? 'Your server supports fsockopen.' : 'Your server does not support fsockopen.'; ?><?php echo "\n"; ?>
243
cURL:                     <?php echo ( function_exists( 'curl_init' ) ) ? 'Your server supports cURL.' : 'Your server does not support cURL.'; ?><?php echo "\n"; ?>
244
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"; ?>
245
SUHOSIN:                  <?php echo ( extension_loaded( 'suhosin' ) ) ? 'Your server has SUHOSIN installed.' : 'Your server does not have SUHOSIN installed.'; ?><?php echo "\n"; ?>
246
247
ACTIVE PLUGINS:
248
249
<?php $this->el_print_current_plugins(); ?>
250
251
<?php
252
		if ( is_multisite() ) : ?>
253
NETWORK ACTIVE PLUGINS:
254
255
<?php
256
			$this->el_print_network_active_plugins();
257
		endif;
258
?>
259
260
<?php do_action( 'el_system_info_after' );?>
261
### End System Info ###</textarea>
262
263
		<p class="submit">
264
			<input type="hidden" name="el_action" value="download_sysinfo">
265
			<?php submit_button( 'Download System Info File', 'primary', 'email-log-sysinfo', false ); ?>
266
		</p>
267
268
269
		</div>
270
		<?php
271
272
		$this->render_page_footer();
273
	}
274
275
	/**
276
	 * Generates the System Info Download File.
277
	 *
278
	 * @return void
279
	 */
280
	public function generate_sysinfo_download() {
281
		nocache_headers();
282
283
		header( 'Content-type: text/plain' );
284
		header( 'Content-Disposition: attachment; filename="email-log-system-info.txt"' );
285
286
		echo wp_strip_all_tags( $_POST['email-log-sysinfo'] );
287
		die();
288
	}
289
}
290