-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathModel_System_Report.php
More file actions
502 lines (428 loc) · 14.7 KB
/
Copy pathModel_System_Report.php
File metadata and controls
502 lines (428 loc) · 14.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
<?php
declare( strict_types=1 );
namespace GFPDF\Model;
use GFPDF\Helper\Helper_Abstract_Model;
use GFPDF\Helper\Helper_Abstract_Options;
use GFPDF\Helper\Helper_Data;
use GFPDF\Helper\Helper_Misc;
use GFPDF\Helper\Helper_Templates;
use GFPDF_Major_Compatibility_Checks;
use GFPDF_Vendor\Psr\Log\LoggerInterface;
/**
* @package Gravity PDF
* @copyright Copyright (c) 2026, Blue Liquid Designs
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
*/
/* Exit if accessed directly */
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Model_System_Report
*
* A general class for System Report
*
* @since 6.0
*/
class Model_System_Report extends Helper_Abstract_Model {
/**
* @var Helper_Abstract_Options
*
* @since 6.0
*/
protected $options;
/**
* @var Helper_Data
*
* @since 6.0
*/
protected $data;
/**
* @var LoggerInterface
*
* @since 6.0
*/
protected $log;
/**
* @var Helper_Misc
*
* @since 6.0
*/
protected $misc;
/**
* @var GFPDF_Major_Compatibility_Checks
*
* @since 6.0
*/
protected $status;
/**
* @var Helper_Templates
*
* @since 6.0
*/
protected $templates;
public function __construct( Helper_Abstract_Options $options, Helper_Data $data, LoggerInterface $log, Helper_Misc $misc, GFPDF_Major_Compatibility_Checks $status, Helper_Templates $templates ) {
$this->options = $options;
$this->data = $data;
$this->log = $log;
$this->misc = $misc;
$this->status = $status;
$this->templates = $templates;
}
/**
* Build Gravity PDF System Report array.
*
* @since 6.0
*/
public function build_gravitypdf_report(): array {
$structure = $this->get_report_structure();
foreach ( $this->get_report_items() as $index => $report ) {
foreach ( $report as $id => $info ) {
$structure[0]['tables'][ $index ]['items'][ $id ] = $info;
}
}
return $structure;
}
/**
* Set up array structure of Gravity PDF System Report
*
* @since 6.0
*/
public function get_report_structure(): array {
$title_export_prefix = 'Gravity PDF - ';
return [
[
'title' => esc_html__( 'Gravity PDF Environment', 'gravity-pdf' ),
'title_export' => 'Gravity PDF Environment',
'tables' => [
[
'title' => esc_html__( 'PHP', 'gravity-pdf' ),
'title_export' => $title_export_prefix . 'PHP',
'items' => [],
],
[
'title' => esc_html__( 'Directories and Permissions', 'gravity-pdf' ),
'title_export' => $title_export_prefix . 'Directories and Permissions',
'items' => [],
],
[
'title' => esc_html__( 'Global Settings', 'gravity-pdf' ),
'title_export' => $title_export_prefix . 'Global Settings',
'items' => [],
],
[
'title' => esc_html__( 'Security Settings', 'gravity-pdf' ),
'title_export' => $title_export_prefix . 'Security Settings',
'items' => [],
],
],
],
];
}
/**
* Move the Gravity PDF plugins from Active Plugins section to Add-Ons
*
* @since 6.0
*/
public function move_gravitypdf_active_plugins_to_gf_addons( array $system_report ): array {
$active_plugins = $system_report[1]['tables'][2]['items'] ?? [];
/* Find any active Gravity PDF plugins and move to GF addons */
foreach ( $active_plugins as $index => $plugin ) {
if ( stripos( $plugin['label'], 'Gravity PDF' ) !== false ) {
$system_report[0]['tables'][1]['items'][] = $plugin;
unset( $system_report[1]['tables'][2]['items'][ $index ] );
}
}
return $system_report;
}
/**
* Get array report structure of Gravity PDF System Report
*
* @return array
* @since 6.0
*/
protected function get_report_items(): array {
$items = [];
$memory = $this->get_memory_limit();
$allow_url_fopen = $this->get_allow_url_fopen();
$temp_folder_protected = $this->check_temp_folder_permission();
$temp_folder_permission = $this->is_temporary_folder_writable();
/* PHP */
$items[0] = [
'memory' => [
'label' => esc_html__( 'WP Memory', 'gravity-pdf' ),
'label_export' => 'WP Memory',
'value' => $memory['value'],
'value_export' => $memory['value_export'],
],
'allow_url_fopen' => [
'label' => 'allow_url_fopen',
'value' => $allow_url_fopen['value'],
'value_export' => $allow_url_fopen['value_export'],
],
'default_charset' => [
'label' => esc_html__( 'Default Charset', 'gravity-pdf' ),
'label_export' => 'Default Charset',
'value' => ini_get( 'default_charset' ),
],
'internal_encoding' => [
'label' => esc_html__( 'Internal Encoding', 'gravity-pdf' ),
'label_export' => 'Internal Encoding',
'value' => ini_get( 'internal_encoding' ) ?: ini_get( 'default_charset' ), //phpcs:ignore Universal.Operators.DisallowShortTernary.Found
],
];
/* Directory and Permissions */
$items[1] = [
'pdf_working_directory' => [
'label' => esc_html__( 'PDF Working Directory', 'gravity-pdf' ),
'label_export' => 'PDF Working Directory',
'value' => $this->templates->get_template_path(),
],
'pdf_working_directory_url' => [
'label' => esc_html__( 'PDF Working Directory URL', 'gravity-pdf' ),
'label_export' => 'PDF Working Directory URL',
'value' => $this->templates->get_template_url(),
],
'font_folder_location' => [
'label' => esc_html__( 'Font Folder location', 'gravity-pdf' ),
'label_export' => 'Font Folder location',
'value' => $this->data->template_font_location,
],
'temp_folder_location' => [
'label' => esc_html__( 'Temporary Folder location', 'gravity-pdf' ),
'label_export' => 'Temporary Folder location',
'value' => $this->data->template_tmp_location,
],
'temp_folder_permission' => [
'label' => esc_html__( 'Temporary Folder permissions', 'gravity-pdf' ),
'label_export' => 'Temporary Folder permissions',
'value' => $temp_folder_permission['value'],
'value_export' => $temp_folder_permission['value_export'],
],
'temp_folder_protected' => [
'label' => esc_html__( 'Temporary Folder protected', 'gravity-pdf' ),
'label_export' => 'Temporary Folder protected',
'value' => $temp_folder_protected['value'],
'value_export' => $temp_folder_protected['value_export'],
],
'mpdf_temp_folder_location' => [
'label' => esc_html__( 'mPDF Temporary location', 'gravity-pdf' ),
'label_export' => 'mPDF Temporary location',
'value' => $this->data->mpdf_tmp_location,
],
];
/* Check if outdated core template overrides and display warning */
$template_status = $this->check_core_template_override_versions();
if ( ! empty( $template_status ) ) {
$items[1]['outdated_templates'] = [
'label' => esc_html__( 'Outdated Templates', 'gravity-pdf' ),
'label_export' => 'Outdated Templates',
'value' => $template_status['value'],
'value_export' => $template_status['value_export'],
];
}
/* Global Settings */
$is_canonical_release = is_file( plugin_dir_path( GPDF_PLUGIN_FILE ) . 'gravity-pdf-updater.php' );
$is_not_canonical_release_message = wp_kses(
sprintf(
/* translators: 1: Opening <a> tag, 2: Closing </a> tag */
__( 'In order to get updates direct from GravityPDF.com %1$syou need to perform a one-time download of the plugin%2$s.', 'gravity-pdf' ),
'<a href="https://gravitypdf.com/news/installing-and-upgrading-to-the-canonical-version-of-gravity-pdf/">',
'</a>',
),
[ 'a' => [ 'href' => true ] ]
);
$items[2] = [
'canonical_release' => [
'label' => esc_html__( 'Canonical Release', 'gravity-pdf' ),
'label_export' => 'Canonical Release',
'value' => $is_canonical_release ? $this->getController()->view->get_icon( true ) : $this->getController()->view->get_icon( false ) . $is_not_canonical_release_message,
'value_export' => $is_canonical_release ? 'Yes' : 'No',
],
'pdf_entry_list_action' => [
'label' => esc_html__( 'PDF Entry List Action', 'gravity-pdf' ),
'label_export' => 'PDF Entry List Action',
'value' => $this->options->get_option( 'default_action', 'View' ) === 'View' ? esc_html__( 'View', 'gravity-pdf' ) : esc_html__( 'Download', 'gravity-pdf' ),
'value_export' => $this->options->get_option( 'default_action', 'View' ),
],
'background_processing_enabled' => [
'label' => esc_html__( 'Background Processing', 'gravity-pdf' ),
'label_export' => 'Background Processing',
'value' => $this->options->get_option( 'background_processing', 'No' ) === 'Yes' ? $this->getController()->view->get_icon( true ) : esc_html__( 'Off', 'gravity-pdf' ),
'value_export' => $this->options->get_option( 'background_processing', 'No' ),
],
'debug_mode_enabled' => [
'label' => esc_html__( 'Debug Mode', 'gravity-pdf' ),
'label_export' => 'Debug Mode',
'value' => $this->options->get_option( 'debug_mode', 'No' ) === 'Yes' ? $this->getController()->view->get_icon( true ) : esc_html__( 'Off', 'gravity-pdf' ),
'value_export' => $this->options->get_option( 'debug_mode', 'No' ),
],
];
/* Security Settings */
$items[3] = [
'user_restrictions' => [
'label' => esc_html__( 'User Restrictions', 'gravity-pdf' ),
'label_export' => 'User Restrictions',
'value' => implode( ', ', $this->options->get_option( 'admin_capabilities', [ 'gravityforms_view_entries' ] ) ),
],
'logged_out_timeout' => [
'label' => esc_html__( 'Logged Out Timeout', 'gravity-pdf' ),
'label_export' => 'Logged Out Timeout',
'value' => $this->options->get_option( 'logged_out_timeout', '20' ) . ' ' . esc_html__( 'minute(s)', 'gravity-pdf' ),
'value_export' => $this->options->get_option( 'logged_out_timeout', '20' ) . ' minutes(s)',
],
];
return apply_filters( 'gfpdf_system_status_report_items', $items );
}
/**
* Returns text and dashicon for Memory Limit
*
* @since 6.0
*/
protected function get_memory_limit(): array {
$memory = $this->status->get_ram( $this->data->memory_limit );
return [
'value' => $this->getController()->view->memory_limit_markup( $memory ),
'value_export' => $memory === -1 ? 'Unlimited' : $memory . 'MB',
];
}
/**
* @since 6.0
*/
protected function get_allow_url_fopen(): array {
$allow_url_fopen = $this->data->allow_url_fopen;
$icon = $this->getController()->view->get_allow_url_fopen( $allow_url_fopen );
$text = $allow_url_fopen ? 'Yes' : 'No';
return [
'value' => $icon,
'value_export' => $text,
];
}
/**
* Returns the mark up once the temp folder test is completed.
*
* @since 6.0
*/
protected function check_temp_folder_permission(): array {
$permission = $this->test_public_tmp_directory_access();
return [
'value' => $this->getController()->view->get_temp_folder_protected( $permission ),
'value_export' => $permission ? 'Yes' : 'No',
];
}
/**
* Check if we can publicly access a file in the PDF Temporary folder
*
* @since 6.0
*/
public function test_public_tmp_directory_access(): bool {
$tmp_dir = $this->data->template_tmp_location;
$tmp_test_file = 'public_tmp_directory_test.txt';
$path = $tmp_dir . $tmp_test_file;
/* create our file */
file_put_contents( $path, 'failed-if-read' );
/* verify text file exists */
if ( ! is_file( $path ) ) {
$this->log->error(
'Could not write to PDF temporary directory to test for public access',
[
'path' => $path,
]
);
return true;
}
$site_url = $this->misc->convert_path_to_url( $tmp_dir );
if ( $site_url === false ) {
@unlink( $path ); /* phpcs:ignore */
$this->log->error(
'Could not convert path to URL to test for public access',
[
'path' => $path,
]
);
return true;
}
$response = wp_remote_get( $site_url . $tmp_test_file );
if ( is_wp_error( $response ) ) {
@unlink( $path ); /* phpcs:ignore */
return true;
}
@unlink( $path ); /* phpcs:ignore */
/* if we read the contents of the file over HTTP the directory is publicly accessible */
if ( trim( wp_remote_retrieve_body( $response ) ) !== 'failed-if-read' ) {
return true;
}
return false;
}
/**
* @since 6.0
*/
protected function is_temporary_folder_writable(): array {
$is_writable = wp_is_writable( $this->data->mpdf_tmp_location );
$string = $is_writable ? __( 'Writable', 'gravityforms' ) : __( 'Not writable', 'gravityforms' );
$icon = $this->getController()->view->get_icon( $is_writable );
return [
'value' => $string . $icon,
'value_export' => $is_writable ? 'Writable' : 'Not writable',
];
}
/**
* Display a warning if the Core template overrides are out of date
*
* @since 6.0
*/
protected function check_core_template_override_versions(): array {
$templates = $this->get_template_versions( $this->templates->get_core_pdf_templates() );
$value = '';
$value_export = '';
/* Loop over the Core templates and check if there are any overrides */
foreach ( $templates as $path => $core_version ) {
$template = $this->templates->get_template_info_by_id( basename( $path, '.php' ) );
if ( version_compare( $core_version, $template['version'], '>' ) ) {
$relative_template_path = str_replace( ABSPATH, '/', $template['path'] );
$message = $this->getController()->view->get_template_check_message( $relative_template_path, $template['version'], $core_version );
$value .= $message['value'];
$value_export .= $message['value_export'];
}
}
/* Returns an empty string if all the core template is the latest version */
if ( empty( $value ) ) {
return [];
}
/* Add an upgrade message and link for more information. */
$value .= $this->getController()->view->get_template_upgrade_message();
return [
'value' => $value,
'value_export' => $value_export,
];
}
/**
* Get all the template version numbers
*
* @param array $templates List of template path.
*
* @return array
*
* @since 6.0
*/
protected function get_template_versions( array $templates ): array {
$versions = [];
foreach ( $templates as $path ) {
$versions[ $path ] = $this->templates->get_template_info_by_path( $path )['version'];
}
return $versions;
}
/**
* Prepare array for the system_report format
*
* @since 6.0
*/
protected function prepare_report( array $item ): array {
return [
'label' => $item['label'],
'label_export' => $item['label'],
'value' => $item['value'],
'value_export' => $item['value_export'] ?? $item['value'],
];
}
}