PluginProbe
Selection Lite / 1.12
Selection Lite v1.12
trunk 1.0 1.1 1.10 1.11 1.12 1.14 1.15 1.16 1.17 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9
selection-lite / src / Merkulove / Unity / ReporterServer.php

ReporterServer.php in Selection Lite 1.12, at src/Merkulove/Unity/ReporterServer.php

498 lines 14.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Selection Lite
4 * Carefully selected Elementor addons bundle, for building the most awesome websites
5 *
6 * @encoding UTF-8
7 * @version 1.12
8 * @copyright (C) 2018-2024 Merkulove ( https://merkulov.design/ ). All rights reserved.
9 * @license GPLv3
10 * @contributors merkulove, vladcherviakov, phoenixmkua, podolianochka, viktorialev01
11 * @support help@merkulov.design
12 **/
13
14 namespace Merkulove\SelectionLite\Unity;
15
16 use DateTime;
17
18 /** Exit if accessed directly. */
19 if ( ! defined( 'ABSPATH' ) ) {
20 header( 'Status: 403 Forbidden' );
21 header( 'HTTP/1.1 403 Forbidden' );
22 exit;
23 }
24
25 /**
26 * SINGLETON: Used to implement System report handler class responsible for generating a report for the server environment.
27 *
28 * @since 1.0
29 *
30 **/
31 final class ReporterServer {
32
33 /**
34 * The one true ReporterServer.
35 *
36 * @since 1.0
37 * @var ReporterServer
38 **/
39 private static $instance;
40
41 /**
42 * Get server environment reporter title.
43 *
44 * @return string - Report title.
45 **@since 1.0
46 * @access public
47 *
48 */
49 public function get_title() {
50
51 return esc_html__( 'Server Environment', 'selection-lite' );
52
53 }
54
55 /**
56 * Retrieve the required fields for the server environment report.
57 *
58 * @return array - Required report fields with field ID and field label.
59 **@since 1.0
60 * @access public
61 *
62 */
63 public function get_fields() {
64
65 $tabs = Plugin::get_tabs();
66 $status_tab = $tabs['status'];
67 $server_checks = $status_tab['reports']['server'];
68
69 $checks = [];
70 $checks = $this->add_check( $checks, $server_checks, 'os', esc_html__( 'Operating System', 'selection-lite' ) );
71 $checks = $this->add_check( $checks, $server_checks, 'software', esc_html__( 'Software', 'selection-lite' ) );
72 $checks = $this->add_check( $checks, $server_checks, 'mysql_version', esc_html__( 'MySQL version', 'selection-lite' ) );
73 $checks = $this->add_check( $checks, $server_checks, 'php_version', esc_html__( 'PHP Version', 'selection-lite' ) );
74 $checks = $this->add_check( $checks, $server_checks, 'write_permissions', esc_html__( 'Write Permissions', 'selection-lite' ) );
75 $checks = $this->add_check( $checks, $server_checks, 'zip_installed', esc_html__( 'ZIP Installed', 'selection-lite' ) );
76 $checks = $this->add_check( $checks, $server_checks, 'elementor_installed', esc_html__( 'Elementor Installed', 'selection-lite' ) );
77 $checks = $this->add_check( $checks, $server_checks, 'allow_url_fopen', esc_html__( 'allow_url_fopen', 'selection-lite' ) );
78 $checks = $this->add_check( $checks, $server_checks, 'dom_installed', esc_html__( 'DOM Installed', 'selection-lite' ) );
79 $checks = $this->add_check( $checks, $server_checks, 'xml_installed', esc_html__( 'XML Installed', 'selection-lite' ) );
80 $checks = $this->add_check( $checks, $server_checks, 'bcmath_installed', esc_html__( 'BCMath Installed', 'selection-lite' ) );
81 $checks = $this->add_check( $checks, $server_checks, 'mbstring_installed', esc_html__( 'mbstring Installed', 'selection-lite' ) );
82 $checks = $this->add_check( $checks, $server_checks, 'server_time', esc_html__( 'Server Time Sync', 'selection-lite' ) );
83
84 return $checks;
85
86 }
87
88 /**
89 * Add server check if it's enabled.
90 *
91 * @param array $checks - List of enabled server checks.
92 * @param array $server_checks - List of server checks from settings.
93 * @param string $key - name of check.
94 * @param string $label - Label for result.
95 *
96 * @return array - Required report fields with field ID and field label.
97 * @since 1.0
98 * @access public
99 *
100 */
101 private function add_check( $checks, $server_checks, $key, $label ) {
102
103 if ( isset( $server_checks[ $key ] ) && $server_checks[ $key ] ) {
104 $checks[ $key ] = $label;
105 }
106
107 return $checks;
108
109 }
110
111 /**
112 * Get allow_url_fopen enabled.
113 *
114 * @return array {
115 * Report data.
116 *
117 * @type string $value YES if the allow_url_fopen is enabled, NO otherwise.
118 * @type bool $warning Whether to display a warning. True if the allow_url_fopen is enabled, False otherwise.
119 * }
120 **@since 1.0
121 * @access public
122 *
123 */
124 public function get_allow_url_fopen() {
125
126 $allow_url_fopen = ini_get( 'allow_url_fopen' );
127
128 return [
129 'value' => $allow_url_fopen ? '<i class="material-icons mdc-system-yes">check_circle</i>' . esc_html__( 'YES', 'selection-lite' ) : '<i class="material-icons mdc-system-no">error</i>' . esc_html__( 'NO', 'selection-lite' ),
130 'warning' => ! $allow_url_fopen,
131 'recommendation' => esc_html__( 'You must enable allow_url_fopen option in PHP. Contact the support service of your hosting provider. They know what to do.', 'selection-lite' )
132 ];
133
134 }
135
136 /**
137 * Get server operating system.
138 * Retrieve the server operating system.
139 *
140 * @return array {
141 * Report data.
142 *
143 * @type string $value Server operating system.
144 * }
145 **@since 1.0
146 * @access public
147 *
148 */
149 public function get_os() {
150 return [
151 'value' => PHP_OS,
152 ];
153 }
154
155 /**
156 * Get server software.
157 * Retrieve the server software.
158 *
159 * @return array {
160 * Report data.
161 *
162 * @type string $value Server software.
163 * }
164 **@since 1.0
165 * @access public
166 *
167 */
168 public function get_software() {
169 return [
170 'value' => $_SERVER['SERVER_SOFTWARE'],
171 ];
172 }
173
174 /**
175 * Get PHP version.
176 * Retrieve the PHP version.
177 *
178 * @return array {
179 * Report data.
180 *
181 * @type string $value PHP version.
182 * @type string $recommendation Minimum PHP version recommendation.
183 * @type bool $warning Whether to display a warning.
184 * }
185 **@since 1.0
186 * @access public
187 *
188 */
189 public function get_php_version() {
190 $result = [
191 'value' => PHP_VERSION,
192 ];
193
194 if ( version_compare( $result['value'], '7.4', '<' ) ) {
195 $result['recommendation'] = esc_html__( 'We recommend to use php 7.4 or higher', 'selection-lite' );
196
197 $result['warning'] = true;
198 }
199
200 return $result;
201 }
202
203 /**
204 * Get ZIP installed.
205 * Whether the ZIP extension is installed.
206 *
207 * @return array {
208 * Report data.
209 *
210 * @type string $value Yes if the ZIP extension is installed, NO otherwise.
211 * @type bool $warning Whether to display a warning. True if the ZIP extension is installed, False otherwise.
212 * }
213 **@since 1.0
214 * @access public
215 *
216 */
217 public function get_zip_installed() {
218 $zip_installed = extension_loaded( 'zip' );
219
220 return [
221 'value' => $zip_installed ? '<i class="material-icons mdc-system-yes">check_circle</i>' . esc_html__( 'YES', 'selection-lite' ) : '<i class="material-icons mdc-system-no">error</i>' . esc_html__( 'NO', 'selection-lite' ),
222 'warning' => ! $zip_installed,
223 ];
224 }
225
226 /**
227 * Get Elementor installed.
228 * Whether the Elementor builder is installed.
229 *
230 * @return array Report data.
231 * @type string $value YES if the Elementor builder is installed, NO otherwise.
232 * @type bool $warning Whether to display a warning.
233 **@since 1.0
234 * @access public
235 *
236 */
237 public function get_elementor_installed() {
238
239 /** Check if Elementor installed and activated. */
240 $elementor_installed = did_action( 'elementor/loaded' );
241
242 return [
243 'value' => $elementor_installed ? '<i class="material-icons mdc-system-yes">check_circle</i>' . esc_html__( 'YES', 'selection-lite' ) : '<i class="material-icons mdc-system-no">error</i>' . esc_html__( 'NO', 'selection-lite' ),
244 'warning' => ! $elementor_installed,
245 'recommendation' => esc_html__( 'You need install and activate Elementor builder. Go to Elementor site (elementor.com) for details.', 'selection-lite' )
246 ];
247
248 }
249
250 /**
251 * Get DOM installed.
252 * Whether the DOM extension is installed.
253 *
254 * @return array {
255 * Report data.
256 *
257 * @type string $value YES if the DOM extension is installed, NO otherwise.
258 * @type bool $warning Whether to display a warning. True if the DOM extension is installed, False otherwise.
259 * }
260 **@since 1.0
261 * @access public
262 *
263 */
264 public function get_dom_installed() {
265
266 $dom_installed = extension_loaded( 'dom' );
267
268 return [
269 'value' => $dom_installed ? '<i class="material-icons mdc-system-yes">check_circle</i>' . esc_html__( 'YES', 'selection-lite' ) : '<i class="material-icons mdc-system-no">error</i>' . esc_html__( 'NO', 'selection-lite' ),
270 'warning' => ! $dom_installed,
271 'recommendation' => esc_html__( ' You must enable DOM extension (Document Object Model) in PHP. It\'s used for HTML processing. Contact the support service of your hosting provider. They know what to do.', 'selection-lite' )
272 ];
273
274 }
275
276 /**
277 * Get XML installed.
278 * Whether the XML extension is installed.
279 *
280 * @return array {
281 * Report data.
282 *
283 * @type string $value YES if the XML extension is installed, NO otherwise.
284 * @type bool $warning Whether to display a warning. True if the XML extension is installed, False otherwise.
285 * }
286 **@since 1.0
287 * @access public
288 *
289 */
290 public function get_xml_installed() {
291
292 $xml_installed = extension_loaded( 'xml' );
293
294 return [
295 'value' => $xml_installed ? '<i class="material-icons mdc-system-yes">check_circle</i>' . esc_html__( 'YES', 'selection-lite' ) : '<i class="material-icons mdc-system-no">error</i>' . esc_html__( 'NO', 'selection-lite' ),
296 'warning' => ! $xml_installed,
297 'recommendation' => esc_html__( 'You must enable XML extension in PHP. It\'s used for XML processing. Contact the support service of your hosting provider. They know what to do.', 'selection-lite' )
298 ];
299
300 }
301
302 /**
303 * Get BCMath installed.
304 * Whether the BCMath extension is installed.
305 *
306 * @return array {
307 * Report data.
308 *
309 * @type string $value YES if the BCMath extension is installed, NO otherwise.
310 * @type bool $warning Whether to display a warning. True if the BCMath extension is installed, False otherwise.
311 * }
312 **@since 1.0
313 * @access public
314 *
315 */
316 public function get_bcmath_installed() {
317
318 $bcmath_installed = extension_loaded( 'bcmath' );
319
320 return [
321 'value' => $bcmath_installed ? '<i class="material-icons mdc-system-yes">check_circle</i>' . esc_html__( 'YES', 'selection-lite' ) : '<i class="material-icons mdc-system-no">error</i>' . esc_html__( 'NO', 'selection-lite' ),
322 'warning' => ! $bcmath_installed,
323 'recommendation' => esc_html__( 'You must enable BCMath extension (Arbitrary Precision Mathematics) in PHP. Contact the support service of your hosting provider. They know what to do.', 'selection-lite' )
324 ];
325
326 }
327
328 /**
329 * Get mbstring installed.
330 * Whether the mbstring extension is installed.
331 *
332 * @return array {
333 * Report data.
334 *
335 * @type string $value YES if the mbstring extension is installed, NO otherwise.
336 * @type bool $warning Whether to display a warning. True if the mbstring extension is installed, False otherwise.
337 * }
338 **@since 1.0
339 * @access public
340 *
341 */
342 public function get_mbstring_installed() {
343
344 $mbstring_installed = extension_loaded( 'mbstring' );
345
346 return [
347 'value' => $mbstring_installed ? '<i class="material-icons mdc-system-yes">check_circle</i>' . esc_html__( 'YES', 'selection-lite' ) : '<i class="material-icons mdc-system-no">error</i>' . esc_html__( 'NO', 'selection-lite' ),
348 'warning' => ! $mbstring_installed,
349 'recommendation' => esc_html__( 'You must enable mbstring extension (Multibyte String) in PHP. Contact the support service of your hosting provider. They know what to do.', 'selection-lite' )
350 ];
351 }
352
353 /**
354 * Get MySQL version.
355 * Retrieve the MySQL version.
356 *
357 * @return array {
358 * Report data.
359 *
360 * @type string $value MySQL version.
361 * }
362 */
363 public function get_mysql_version(): array {
364 global $wpdb;
365
366 return [
367 'value' => $wpdb->db_version(),
368 ];
369 }
370
371 /**
372 * Get write permissions.
373 * Check whether the required folders has writing permissions.
374 *
375 * @return array {
376 * Report data.
377 *
378 * @type string $value Writing permissions status.
379 * @type bool $warning Whether to display a warning. True if some required
380 * folders don't have writing permissions, False otherwise.
381 * }
382 **@since 1.0
383 * @access public
384 *
385 */
386 public function get_write_permissions() {
387
388 global $wp_filesystem;
389
390 // If the WP_Filesystem class is not initialized, initialize it
391 if ( ! $wp_filesystem ) {
392 require_once( ABSPATH . 'wp-admin/includes/file.php' );
393 WP_Filesystem();
394 }
395
396 $paths_to_check = [
397 ABSPATH => esc_html__( 'WordPress root directory', 'selection-lite' )
398 ];
399
400 $write_problems = [];
401
402 $wp_upload_dir = wp_upload_dir();
403
404 if ( $wp_upload_dir['error'] ) {
405 $write_problems[] = esc_html__( 'WordPress root uploads directory', 'selection-lite' );
406 }
407
408 $htaccess_file = ABSPATH . '/.htaccess';
409
410 if ( file_exists( $htaccess_file ) ) {
411 $paths_to_check[ $htaccess_file ] = esc_html__( '.htaccess file', 'selection-lite' );
412 }
413
414 foreach ( $paths_to_check as $dir => $description ) {
415
416 if ( ! $wp_filesystem || ! $wp_filesystem->is_writable( $dir ) ) {
417 $write_problems[] = $description;
418 }
419 }
420
421 if ( $write_problems ) {
422
423 $value = '<i class="material-icons mdc-system-no">error</i>' . esc_html__( 'There are some writing permissions issues with the following directories/files:', 'selection-lite' ) . "<br> &nbsp;&nbsp;&nbsp;&nbsp;– ";
424 $value .= implode( "<br> &nbsp;&nbsp;&nbsp;&nbsp;– ", $write_problems );
425
426 } else {
427
428 $value = '<i class="material-icons mdc-system-yes">check_circle</i>' . esc_html__( 'All right', 'selection-lite' );
429
430 }
431
432 return [
433 'value' => $value,
434 'warning' => (bool) $write_problems,
435 ];
436
437 }
438
439 /**
440 * Get report.
441 * Retrieve the report with all it's containing fields.
442 *
443 * @return array {
444 * Report fields.
445 *
446 * @type string $name Field name.
447 * @type string $label Field label.
448 * }
449 **@since 1.0
450 * @access public
451 *
452 */
453 public function get_report() {
454
455 $result = [];
456
457 foreach ( $this->get_fields() as $field_name => $field_label ) {
458
459 $method = 'get_' . $field_name;
460
461 $reporter_field = [
462 "name" => $field_name,
463 'label' => $field_label,
464 ];
465
466 /** @noinspection SlowArrayOperationsInLoopInspection */
467 $reporter_field = array_merge( $reporter_field, $this->$method() );
468 $result[ $field_name ] = $reporter_field;
469
470 }
471
472 return $result;
473
474 }
475
476 /**
477 * Main ReporterServer Instance.
478 *
479 * Insures that only one instance of ReporterServer exists in memory at any one time.
480 *
481 * @static
482 * @return ReporterServer
483 **@since 1.0
484 */
485 public static function get_instance() {
486
487 if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) {
488
489 self::$instance = new self;
490
491 }
492
493 return self::$instance;
494
495 }
496
497 } // End Class ReporterServer.
498