| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
// allow-no-test-found: covered through Tools page entry-point tests in tests/ViewToolsPageTest.php |
| 8 |
|
| 9 |
/** |
| 10 |
* Collects the read-only environment diagnostics shown on the Tools page. |
| 11 |
*/ |
| 12 |
class ABJ_404_Solution_ToolsDiagnostics { |
| 13 |
|
| 14 |
/** |
| 15 |
* Return diagnostics rows for the Tools page. |
| 16 |
* |
| 17 |
* Rows are structured data only. View_Tools is responsible for rendering |
| 18 |
* any HTML controls attached to a row. |
| 19 |
* |
| 20 |
* @return array<int, array<string, mixed>> |
| 21 |
*/ |
| 22 |
public function getRows(): array { |
| 23 |
$uploadDir = ''; |
| 24 |
if (function_exists('abj404_getUploadsDir')) { |
| 25 |
$uploadDir = (string)abj404_getUploadsDir(); |
| 26 |
} |
| 27 |
$uploadDirReadable = ($uploadDir !== '' && is_dir($uploadDir)); |
| 28 |
$uploadDirWritable = ($uploadDir !== '' && is_writable($uploadDir)); |
| 29 |
|
| 30 |
$pluginVersion = defined('ABJ404_VERSION') ? ABJ404_VERSION : __('Unknown', '404-solution'); |
| 31 |
$rows = array( |
| 32 |
array('label' => __('Plugin Version', '404-solution'), 'value' => $pluginVersion, 'status' => 'info'), |
| 33 |
array('label' => __('WordPress Version', '404-solution'), 'value' => $this->getWordPressVersion(), 'status' => 'info'), |
| 34 |
array('label' => __('PHP Version', '404-solution'), 'value' => PHP_VERSION, 'status' => 'info'), |
| 35 |
array( |
| 36 |
'label' => __('Uploads Directory', '404-solution'), |
| 37 |
'value' => ($uploadDir !== '') ? $uploadDir : __('Not available', '404-solution'), |
| 38 |
'status' => $uploadDirReadable ? 'ok' : 'warn', |
| 39 |
), |
| 40 |
array( |
| 41 |
'label' => __('Uploads Writable', '404-solution'), |
| 42 |
'value' => $uploadDirWritable ? __('Yes', '404-solution') : __('No', '404-solution'), |
| 43 |
'status' => $uploadDirWritable ? 'ok' : 'warn', |
| 44 |
), |
| 45 |
array( |
| 46 |
'label' => __('mbstring Extension', '404-solution'), |
| 47 |
'value' => extension_loaded('mbstring') ? __('Loaded', '404-solution') : __('Missing', '404-solution'), |
| 48 |
'status' => extension_loaded('mbstring') ? 'ok' : 'warn', |
| 49 |
), |
| 50 |
array( |
| 51 |
'label' => __('ZipArchive Support', '404-solution'), |
| 52 |
'value' => class_exists('ZipArchive') ? __('Available', '404-solution') : __('Missing', '404-solution'), |
| 53 |
'status' => class_exists('ZipArchive') ? 'ok' : 'warn', |
| 54 |
), |
| 55 |
array( |
| 56 |
'label' => __('WP_DEBUG', '404-solution'), |
| 57 |
'value' => (defined('WP_DEBUG') && WP_DEBUG) ? __('Enabled', '404-solution') : __('Disabled', '404-solution'), |
| 58 |
'status' => 'info', |
| 59 |
), |
| 60 |
); |
| 61 |
|
| 62 |
$latencyRow = $this->getSimulatedLatencyRow(); |
| 63 |
if ($latencyRow !== null) { |
| 64 |
$rows[] = $latencyRow; |
| 65 |
} |
| 66 |
|
| 67 |
return $rows; |
| 68 |
} |
| 69 |
|
| 70 |
/** @return string */ |
| 71 |
private function getWordPressVersion(): string { |
| 72 |
$wpVersion = get_bloginfo('version'); |
| 73 |
if (!is_string($wpVersion) || trim($wpVersion) === '') { |
| 74 |
return __('Unknown', '404-solution'); |
| 75 |
} |
| 76 |
|
| 77 |
return $wpVersion; |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* @return array<string, mixed>|null |
| 82 |
*/ |
| 83 |
private function getSimulatedLatencyRow(): ?array { |
| 84 |
if (!function_exists('abj404_is_local_debug_host') || |
| 85 |
!function_exists('abj404_get_simulated_db_latency_ms') || |
| 86 |
!abj404_is_local_debug_host()) { |
| 87 |
return null; |
| 88 |
} |
| 89 |
|
| 90 |
$latencyMs = absint(abj404_get_simulated_db_latency_ms()); |
| 91 |
$valueText = ($latencyMs > 0) |
| 92 |
? sprintf(__('ON (%d ms per plugin query)', '404-solution'), $latencyMs) |
| 93 |
: __('OFF', '404-solution'); |
| 94 |
|
| 95 |
return array( |
| 96 |
'label' => __('Simulated DB Latency', '404-solution'), |
| 97 |
'value' => $valueText, |
| 98 |
'status' => ($latencyMs > 0) ? 'warn' : 'info', |
| 99 |
'controls' => array( |
| 100 |
'kind' => 'simulated-db-latency', |
| 101 |
'value_text' => $valueText, |
| 102 |
'urls' => array( |
| 103 |
250 => wp_nonce_url(admin_url('options-general.php?page=' . ABJ404_PP . '&subpage=abj404_tools&abj404_set_sim_db_ms=250'), 'abj404_set_sim_db_ms'), |
| 104 |
500 => wp_nonce_url(admin_url('options-general.php?page=' . ABJ404_PP . '&subpage=abj404_tools&abj404_set_sim_db_ms=500'), 'abj404_set_sim_db_ms'), |
| 105 |
900 => wp_nonce_url(admin_url('options-general.php?page=' . ABJ404_PP . '&subpage=abj404_tools&abj404_set_sim_db_ms=900'), 'abj404_set_sim_db_ms'), |
| 106 |
0 => wp_nonce_url(admin_url('options-general.php?page=' . ABJ404_PP . '&subpage=abj404_tools&abj404_set_sim_db_ms=0'), 'abj404_set_sim_db_ms'), |
| 107 |
), |
| 108 |
'labels' => array( |
| 109 |
250 => __('250ms', '404-solution'), |
| 110 |
500 => __('500ms', '404-solution'), |
| 111 |
900 => __('900ms', '404-solution'), |
| 112 |
0 => __('Disable', '404-solution'), |
| 113 |
), |
| 114 |
), |
| 115 |
); |
| 116 |
} |
| 117 |
} |
| 118 |
|