Completed
Push — 105-fix/add-tests-for-all-util... ( 4082dd...d72527 )
by Maria Daniel Deepak
03:41 queued 01:57
created

SystemInfoPage::el_plugin_version()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 5
ccs 0
cts 5
cp 0
crap 2
rs 10
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
			?>
214
Host:                     <?php echo $host . "\n\n"; ?>
215
<?php endif; ?>
216
217
		<?php $post_types = get_post_types(); ?>
218
Registered Post types:    <?php echo implode( ', ', $post_types ) . "\n"; ?>
219
		<?php
220
		foreach ( $post_types as $post_type ) {
221
			echo $post_type;
222
			if ( strlen( $post_type ) < 26 ) {
223
				echo str_repeat( ' ', 26 - strlen( $post_type ) );
224
			}
225
			$post_count = wp_count_posts( $post_type );
226
			foreach ( $post_count as $key => $value ) {
227
				echo $key, '=', $value, ', ';
228
			}
229
			echo "\n";
230
		}
231
		?>
232
233
		<?php $taxonomies = get_taxonomies(); ?>
234
Registered Taxonomies:    <?php echo implode( ', ', $taxonomies ) . "\n"; ?>
235
236
Email log Version:        <?php $this->el_plugin_version() . "\n"; ?>
237
WordPress Version:        <?php echo get_bloginfo( 'version' ) . "\n"; ?>
238
PHP Version:              <?php echo PHP_VERSION . "\n"; ?>
239
MySQL Version:            <?php echo $wpdb->db_version() . "\n"; ?>
240
Web Server Info:          <?php echo $_SERVER['SERVER_SOFTWARE'] . "\n"; ?>
241
242
WordPress Memory Limit:   <?php echo WP_MEMORY_LIMIT; ?><?php echo "\n"; ?>
243
WordPress Max Limit:      <?php echo WP_MAX_MEMORY_LIMIT; ?><?php echo "\n"; ?>
244
PHP Memory Limit:         <?php echo ini_get( 'memory_limit' ) . "\n"; ?>
245
246
SAVEQUERIES:              <?php echo defined( 'SAVEQUERIES' ) ? SAVEQUERIES ? 'Enabled' . "\n" : 'Disabled' . "\n" : 'Not set' . "\n"; ?>
247
WP_DEBUG:                 <?php echo defined( 'WP_DEBUG' ) ? WP_DEBUG ? 'Enabled' . "\n" : 'Disabled' . "\n" : 'Not set' . "\n"; ?>
248
WP_SCRIPT_DEBUG:          <?php echo defined( 'WP_SCRIPT_DEBUG' ) ? WP_SCRIPT_DEBUG ? 'Enabled' . "\n" : 'Disabled' . "\n" : 'Not set' . "\n"; ?>
249
250
GMT Offset:               <?php echo esc_html( get_option( 'gmt_offset' ) ), "\n\n"; ?>
251
DISABLE_WP_CRON:          <?php echo defined( 'DISABLE_WP_CRON' ) ? DISABLE_WP_CRON ? 'Yes' . "\n" : 'No' . "\n" : 'Not set' . "\n"; ?>
252
WP_CRON_LOCK_TIMEOUT:     <?php echo defined( 'WP_CRON_LOCK_TIMEOUT' ) ? WP_CRON_LOCK_TIMEOUT : 'Not set', "\n"; ?>
253
EMPTY_TRASH_DAYS:         <?php echo defined( 'EMPTY_TRASH_DAYS' ) ? EMPTY_TRASH_DAYS : 'Not set', "\n"; ?>
254
255
PHP Safe Mode:            <?php echo ini_get( 'safe_mode' ) ? 'Yes' : 'No', "\n"; // phpcs:ignore PHPCompatibility.PHP.DeprecatedIniDirectives.safe_modeDeprecatedRemoved?>
256
PHP Upload Max Size:      <?php echo ini_get( 'upload_max_filesize' ) . "\n"; ?>
257
PHP Post Max Size:        <?php echo ini_get( 'post_max_size' ) . "\n"; ?>
258
PHP Upload Max Filesize:  <?php echo ini_get( 'upload_max_filesize' ) . "\n"; ?>
259
PHP Time Limit:           <?php echo ini_get( 'max_execution_time' ) . "\n"; ?>
260
PHP Max Input Vars:       <?php echo ini_get( 'max_input_vars' ) . "\n"; // phpcs:ignore PHPCompatibility.PHP.NewIniDirectives.max_input_varsFound?>
261
PHP Arg Separator:        <?php echo ini_get( 'arg_separator.output' ) . "\n"; ?>
262
PHP Allow URL File Open:  <?php echo ini_get( 'allow_url_fopen' ) ? 'Yes' : 'No', "\n"; ?>
263
264
WP Table Prefix:          <?php echo $wpdb->prefix, "\n"; ?>
265
266
Session:                  <?php echo isset( $_SESSION ) ? 'Enabled' : 'Disabled'; ?><?php echo "\n"; ?>
267
Session Name:             <?php echo esc_html( ini_get( 'session.name' ) ); ?><?php echo "\n"; ?>
268
Cookie Path:              <?php echo esc_html( ini_get( 'session.cookie_path' ) ); ?><?php echo "\n"; ?>
269
Save Path:                <?php echo esc_html( ini_get( 'session.save_path' ) ); ?><?php echo "\n"; ?>
270
Use Cookies:              <?php echo ini_get( 'session.use_cookies' ) ? 'On' : 'Off'; ?><?php echo "\n"; ?>
271
Use Only Cookies:         <?php echo ini_get( 'session.use_only_cookies' ) ? 'On' : 'Off'; ?><?php echo "\n"; ?>
272
273
DISPLAY ERRORS:           <?php echo ( ini_get( 'display_errors' ) ) ? 'On (' . ini_get( 'display_errors' ) . ')' : 'N/A'; ?><?php echo "\n"; ?>
274
FSOCKOPEN:                <?php echo ( function_exists( 'fsockopen' ) ) ? 'Your server supports fsockopen.' : 'Your server does not support fsockopen.'; ?><?php echo "\n"; ?>
275
cURL:                     <?php echo ( function_exists( 'curl_init' ) ) ? 'Your server supports cURL.' : 'Your server does not support cURL.'; ?><?php echo "\n"; ?>
276
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"; ?>
277
SUHOSIN:                  <?php echo ( extension_loaded( 'suhosin' ) ) ? 'Your server has SUHOSIN installed.' : 'Your server does not have SUHOSIN installed.'; ?><?php echo "\n"; ?>
278
279
ACTIVE PLUGINS:
280
281
		<?php $this->el_print_current_plugins(); ?>
282
283
		<?php
284
		if ( is_multisite() ) :
285
			?>
286
NETWORK ACTIVE PLUGINS:
287
288
			<?php
289
			$this->el_print_network_active_plugins();
290
		endif;
291
		?>
292
293
		<?php do_action( 'el_system_info_after' ); ?>
294
### End System Info ###</textarea>
295
296
		<p class="submit">
297
			<input type="hidden" name="el_action" value="download_sysinfo">
298
			<?php submit_button( 'Download System Info File', 'primary', 'email-log-sysinfo-button', false ); ?>
299
		</p>
300
301
302
		</div>
303
	</form>
304
		<?php
305
306
		$this->render_page_footer();
307
	}
308
309
	/**
310
	 * Generates the System Info Download File.
311
	 */
312
	public function generate_sysinfo_download() {
313
		nocache_headers();
314
315
		header( 'Content-type: text/plain' );
316
		header( 'Content-Disposition: attachment; filename="email-log-system-info.txt"' );
317
318
		echo wp_strip_all_tags( $_POST['email-log-sysinfo'] );
319
		die();
320
	}
321
322
	/**
323
	 * Handle both POST and GET requests.
324
	 * This method automatically triggers all the actions after checking the nonce.
325
	 */
326
	public function request_handler() {
327
		if ( isset( $_POST['el_action'] ) ) {
328
			$el_action = sanitize_text_field( $_POST['el_action'] );
329
330
			/**
331
			 * Perform the operation.
332
			 * This hook is for doing the operation. Nonce check has already happened by this point.
333
			 *
334
			 * @since 2.3.0
335
			 */
336
			do_action( 'el_' . $el_action, $_POST );
337
		}
338
	}
339
340
}
341