Completed
Push — 97-fix/system-info-section ( 838da2...b6ef76 )
by
unknown
01:54
created

SystemInfoPage::get_setting_sections()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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