Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/elementor/modules/system-info/reporters/server.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
namespace Elementor\Modules\System_Info\Reporters;
3
+
4
+
use Elementor\Api;
5
+
use Elementor\Utils;
6
+
7
+
if ( ! defined( 'ABSPATH' ) ) {
8
+
exit; // Exit if accessed directly.
9
+
}
10
+
11
+
/**
12
+
* Elementor server environment report.
13
+
*
14
+
* Elementor system report handler class responsible for generating a report for
15
+
* the server environment.
16
+
*
17
+
* @since 1.0.0
18
+
*/
19
+
class Server extends Base {
20
+
21
+
const KEY_PATH_WP_CONTENT_DIR = 'wp_content';
22
+
const KEY_PATH_UPLOADS_DIR = 'uploads';
23
+
const KEY_PATH_ELEMENTOR_UPLOADS_DIR = 'elementor_uploads';
24
+
const KEY_PATH_HTACCESS_FILE = '.htaccess';
25
+
26
+
/**
27
+
* Get server environment reporter title.
28
+
*
29
+
* Retrieve server environment reporter title.
30
+
*
31
+
* @since 1.0.0
32
+
* @access public
33
+
*
34
+
* @return string Reporter title.
35
+
*/
36
+
public function get_title() {
37
+
return 'Server Environment';
38
+
}
39
+
40
+
/**
41
+
* Get server environment report fields.
42
+
*
43
+
* Retrieve the required fields for the server environment report.
44
+
*
45
+
* @since 1.0.0
46
+
* @access public
47
+
*
48
+
* @return array Required report fields with field ID and field label.
49
+
*/
50
+
public function get_fields() {
51
+
return [
52
+
'os' => 'Operating System',
53
+
'software' => 'Software',
54
+
'mysql_version' => 'MySQL version',
55
+
'php_version' => 'PHP Version',
56
+
'php_memory_limit' => 'PHP Memory Limit',
57
+
'php_max_input_vars' => 'PHP Max Input Vars',
58
+
'php_max_post_size' => 'PHP Max Post Size',
59
+
'gd_installed' => 'GD Installed',
60
+
'zip_installed' => 'ZIP Installed',
61
+
'write_permissions' => 'Write Permissions',
62
+
'elementor_library' => 'Elementor Library',
63
+
];
64
+
}
65
+
66
+
/**
67
+
* Get server operating system.
68
+
*
69
+
* Retrieve the server operating system.
70
+
*
71
+
* @since 1.0.0
72
+
* @access public
73
+
*
74
+
* @return array {
75
+
* Report data.
76
+
*
77
+
* @type string $value Server operating system.
78
+
* }
79
+
*/
80
+
public function get_os() {
81
+
return [
82
+
'value' => PHP_OS,
83
+
];
84
+
}
85
+
86
+
/**
87
+
* Get server software.
88
+
*
89
+
* Retrieve the server software.
90
+
*
91
+
* @since 1.0.0
92
+
* @access public
93
+
*
94
+
* @return array {
95
+
* Report data.
96
+
*
97
+
* @type string $value Server software.
98
+
* }
99
+
*/
100
+
public function get_software() {
101
+
return [
102
+
'value' => Utils::get_super_global_value( $_SERVER, 'SERVER_SOFTWARE' ),
103
+
];
104
+
}
105
+
106
+
/**
107
+
* Get PHP version.
108
+
*
109
+
* Retrieve the PHP version.
110
+
*
111
+
* @since 1.0.0
112
+
* @access public
113
+
*
114
+
* @return array {
115
+
* Report data.
116
+
*
117
+
* @type string $value PHP version.
118
+
* @type string $recommendation Minimum PHP version recommendation.
119
+
* @type bool $warning Whether to display a warning.
120
+
* }
121
+
*/
122
+
public function get_php_version() {
123
+
$result = [
124
+
'value' => PHP_VERSION,
125
+
];
126
+
$recommended_php_version = '7.4';
127
+
128
+
if ( version_compare( $result['value'], $recommended_php_version, '<' ) ) {
129
+
$result['recommendation'] = sprintf(
130
+
/* translators: %s: Recommended PHP version. */
131
+
esc_html__( 'We recommend using PHP version %s or higher.', 'elementor' ),
132
+
$recommended_php_version
133
+
);
134
+
135
+
$result['warning'] = true;
136
+
}
137
+
138
+
return $result;
139
+
}
140
+
141
+
/**
142
+
* Get PHP memory limit.
143
+
*
144
+
* Retrieve the PHP memory limit.
145
+
*
146
+
* @return array {
147
+
* Report data.
148
+
*
149
+
* @type string $value PHP memory limit.
150
+
* @type string $recommendation Recommendation memory limit.
151
+
* @type bool $warning Whether to display a warning. True if the limit
152
+
* is below the recommended 128M, False otherwise.
153
+
* }
154
+
*/
155
+
public function get_php_memory_limit() {
156
+
$result = [
157
+
'value' => (string) ini_get( 'memory_limit' ),
158
+
];
159
+
160
+
$min_recommended_memory = '128M';
161
+
$preferred_memory = '256M';
162
+
163
+
$memory_limit_bytes = wp_convert_hr_to_bytes( $result['value'] );
164
+
165
+
$min_recommended_bytes = wp_convert_hr_to_bytes( $min_recommended_memory );
166
+
167
+
if ( $memory_limit_bytes < $min_recommended_bytes ) {
168
+
$result['recommendation'] = sprintf(
169
+
/* translators: 1: Minimum recommended_memory, 2: Preferred memory, 3: WordPress wp-config memory documentation. */
170
+
__( 'We recommend setting memory to at least %1$s. (%2$s or higher is preferred) For more information, read about <a href="%3$s">how to increase memory allocated to PHP</a>.', 'elementor' ),
171
+
$min_recommended_memory,
172
+
$preferred_memory,
173
+
'https://go.elementor.com/wordpress-wp-config-memory/'
174
+
);
175
+
176
+
$result['warning'] = true;
177
+
}
178
+
179
+
return $result;
180
+
}
181
+
182
+
/**
183
+
* Get PHP `max_input_vars`.
184
+
*
185
+
* Retrieve the value of `max_input_vars` from `php.ini` configuration file.
186
+
*
187
+
* @since 1.0.0
188
+
* @access public
189
+
*
190
+
* @return array {
191
+
* Report data.
192
+
*
193
+
* @type string $value PHP `max_input_vars`.
194
+
* }
195
+
*/
196
+
public function get_php_max_input_vars() {
197
+
return [
198
+
'value' => ini_get( 'max_input_vars' ),
199
+
];
200
+
}
201
+
202
+
/**
203
+
* Get PHP `post_max_size`.
204
+
*
205
+
* Retrieve the value of `post_max_size` from `php.ini` configuration file.
206
+
*
207
+
* @since 1.0.0
208
+
* @access public
209
+
*
210
+
* @return array {
211
+
* Report data.
212
+
*
213
+
* @type string $value PHP `post_max_size`.
214
+
* }
215
+
*/
216
+
public function get_php_max_post_size() {
217
+
return [
218
+
'value' => ini_get( 'post_max_size' ),
219
+
];
220
+
}
221
+
222
+
/**
223
+
* Get GD installed.
224
+
*
225
+
* Whether the GD extension is installed.
226
+
*
227
+
* @since 1.0.0
228
+
* @access public
229
+
*
230
+
* @return array {
231
+
* Report data.
232
+
*
233
+
* @type string $value Yes if the GD extension is installed, No otherwise.
234
+
* @type bool $warning Whether to display a warning. True if the GD extension is installed, False otherwise.
235
+
* }
236
+
*/
237
+
public function get_gd_installed() {
238
+
$gd_installed = extension_loaded( 'gd' );
239
+
240
+
return [
241
+
'value' => $gd_installed ? 'Yes' : 'No',
242
+
'warning' => ! $gd_installed,
243
+
];
244
+
}
245
+
246
+
/**
247
+
* Get ZIP installed.
248
+
*
249
+
* Whether the ZIP extension is installed.
250
+
*
251
+
* @since 2.1.0
252
+
* @access public
253
+
*
254
+
* @return array {
255
+
* Report data.
256
+
*
257
+
* @type string $value Yes if the ZIP extension is installed, No otherwise.
258
+
* @type bool $warning Whether to display a warning. True if the ZIP extension is installed, False otherwise.
259
+
* }
260
+
*/
261
+
public function get_zip_installed() {
262
+
$zip_installed = extension_loaded( 'zip' );
263
+
264
+
return [
265
+
'value' => $zip_installed ? 'Yes' : 'No',
266
+
'warning' => ! $zip_installed,
267
+
];
268
+
}
269
+
270
+
/**
271
+
* Get MySQL version.
272
+
*
273
+
* Retrieve the MySQL version.
274
+
*
275
+
* @since 1.0.0
276
+
* @access public
277
+
*
278
+
* @return array {
279
+
* Report data.
280
+
*
281
+
* @type string $value MySQL version.
282
+
* }
283
+
*/
284
+
public function get_mysql_version() {
285
+
global $wpdb;
286
+
287
+
$db_server_version = $wpdb->get_results( "SHOW VARIABLES WHERE `Variable_name` IN ( 'version_comment', 'innodb_version' )", OBJECT_K );
288
+
289
+
$db_server_version_string = $db_server_version['version_comment']->Value . ' v';
290
+
291
+
// On some hosts, `innodb_version` is empty, in PHP 8.1.
292
+
if ( isset( $db_server_version['innodb_version'] ) ) {
293
+
$db_server_version_string .= $db_server_version['innodb_version']->Value;
294
+
} else {
295
+
$db_server_version_string .= $wpdb->get_var( 'SELECT VERSION() AS version' );
296
+
}
297
+
298
+
return [
299
+
'value' => $db_server_version_string,
300
+
];
301
+
}
302
+
303
+
/**
304
+
* Get write permissions.
305
+
* Check whether the required paths for have writing permissions.
306
+
*
307
+
* @since 1.9.0
308
+
* @access public
309
+
*
310
+
* @return array {
311
+
* Report data.
312
+
*
313
+
* @type string $value Writing permissions status.
314
+
* @type bool $warning Whether to display a warning. True if some required
315
+
* folders don't have writing permissions, False otherwise.
316
+
* }
317
+
*/
318
+
public function get_write_permissions(): array {
319
+
$paths_to_check = [
320
+
static::KEY_PATH_HTACCESS_FILE => $this->get_system_path( static::KEY_PATH_HTACCESS_FILE ),
321
+
static::KEY_PATH_UPLOADS_DIR => $this->get_system_path( static::KEY_PATH_UPLOADS_DIR ),
322
+
static::KEY_PATH_ELEMENTOR_UPLOADS_DIR => $this->get_system_path( static::KEY_PATH_ELEMENTOR_UPLOADS_DIR ),
323
+
];
324
+
325
+
$paths_permissions = $this->get_paths_permissions( $paths_to_check );
326
+
327
+
$write_problems = [];
328
+
329
+
if ( ! $paths_permissions[ static::KEY_PATH_UPLOADS_DIR ]['write'] ) {
330
+
$write_problems[] = 'WordPress uploads directory';
331
+
}
332
+
333
+
if ( $paths_permissions[ self::KEY_PATH_ELEMENTOR_UPLOADS_DIR ]['exists'] && ! $paths_permissions[ self::KEY_PATH_ELEMENTOR_UPLOADS_DIR ]['write'] ) {
334
+
$write_problems[] = 'Elementor uploads directory';
335
+
}
336
+
337
+
if ( $paths_permissions[ self::KEY_PATH_HTACCESS_FILE ]['exists'] && ! $paths_permissions[ self::KEY_PATH_HTACCESS_FILE ]['write'] ) {
338
+
$write_problems[] = '.htaccess file';
339
+
}
340
+
341
+
if ( $write_problems ) {
342
+
$value = 'There are some writing permissions issues with the following directories/files:' . "\n\t\t - ";
343
+
344
+
$value .= implode( "\n\t\t - ", $write_problems );
345
+
} else {
346
+
$value = 'All right';
347
+
}
348
+
349
+
return [
350
+
'value' => $value,
351
+
'warning' => (bool) $write_problems,
352
+
];
353
+
}
354
+
355
+
/**
356
+
* Check for elementor library connectivity.
357
+
*
358
+
* Check whether the remote elementor library is reachable.
359
+
*
360
+
* @since 1.0.0
361
+
* @access public
362
+
*
363
+
* @return array {
364
+
* Report data.
365
+
*
366
+
* @type string $value The status of elementor library connectivity.
367
+
* @type bool $warning Whether to display a warning. True if elementor
368
+
* * library is not reachable, False otherwise.
369
+
* }
370
+
*/
371
+
public function get_elementor_library() {
372
+
$response = wp_remote_get(
373
+
Api::$api_info_url, [
374
+
'timeout' => 5,
375
+
'body' => [
376
+
// Which API version is used
377
+
'api_version' => ELEMENTOR_VERSION,
378
+
// Which language to return
379
+
'site_lang' => get_bloginfo( 'language' ),
380
+
],
381
+
]
382
+
);
383
+
384
+
if ( is_wp_error( $response ) ) {
385
+
return [
386
+
'value' => 'Not connected (' . $response->get_error_message() . ')',
387
+
'warning' => true,
388
+
];
389
+
}
390
+
391
+
$http_response_code = wp_remote_retrieve_response_code( $response );
392
+
393
+
if ( 200 !== (int) $http_response_code ) {
394
+
$error_msg = 'HTTP Error (' . $http_response_code . ')';
395
+
396
+
return [
397
+
'value' => 'Not connected (' . $error_msg . ')',
398
+
'warning' => true,
399
+
];
400
+
}
401
+
402
+
$info_data = json_decode( wp_remote_retrieve_body( $response ), true );
403
+
404
+
if ( empty( $info_data ) ) {
405
+
return [
406
+
'value' => 'Not connected (Returns invalid JSON)',
407
+
'warning' => true,
408
+
];
409
+
}
410
+
411
+
return [
412
+
'value' => 'Connected',
413
+
];
414
+
}
415
+
416
+
/**
417
+
* @param $paths [] Paths to check permissions.
418
+
* @return array []{exists: bool, read: bool, write: bool, execute: bool}
419
+
*/
420
+
public function get_paths_permissions( $paths ): array {
421
+
$permissions = [];
422
+
423
+
foreach ( $paths as $key_path => $path ) {
424
+
$permissions[ $key_path ] = $this->get_path_permissions( $path );
425
+
}
426
+
427
+
return $permissions;
428
+
}
429
+
430
+
/**
431
+
* Get path by path key.
432
+
*
433
+
* @param $path_key
434
+
* @return string
435
+
*/
436
+
public function get_system_path( $path_key ): string {
437
+
switch ( $path_key ) {
438
+
case static::KEY_PATH_WP_CONTENT_DIR:
439
+
return WP_CONTENT_DIR;
440
+
441
+
case static::KEY_PATH_HTACCESS_FILE:
442
+
return file_exists( ABSPATH . '/.htaccess' ) ? ABSPATH . '/.htaccess' : '';
443
+
444
+
case static::KEY_PATH_UPLOADS_DIR:
445
+
return wp_upload_dir()['basedir'] ?? '';
446
+
447
+
case static::KEY_PATH_ELEMENTOR_UPLOADS_DIR:
448
+
if ( empty( wp_upload_dir()['basedir'] ) ) {
449
+
return '';
450
+
}
451
+
452
+
$elementor_uploads_dir = wp_upload_dir()['basedir'] . '/elementor';
453
+
454
+
return is_dir( $elementor_uploads_dir ) ? $elementor_uploads_dir : '';
455
+
456
+
default:
457
+
return '';
458
+
}
459
+
}
460
+
461
+
/**
462
+
* Check the permissions of a path.
463
+
*
464
+
* @param $path
465
+
* @return array{exists: bool, read: bool, write: bool, execute: bool}
466
+
*/
467
+
public function get_path_permissions( $path ): array {
468
+
if ( empty( $path ) ) {
469
+
return [
470
+
'exists' => false,
471
+
'read' => false,
472
+
'write' => false,
473
+
'execute' => false,
474
+
];
475
+
}
476
+
477
+
return [
478
+
'exists' => true,
479
+
'read' => is_readable( $path ),
480
+
'write' => is_writeable( $path ),
481
+
'execute' => is_executable( $path ),
482
+
];
483
+
}
484
+
}
485
+