PluginProbe
404 Solution / 4.3.0
404 Solution v4.3.0
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / admin / AdminTraceLabels.php

AdminTraceLabels.php in 404 Solution 4.3.0, at includes/admin/AdminTraceLabels.php

100 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) {
4 exit;
5 }
6
7 /**
8 * Translates and classifies pipeline trace labels for admin display.
9 */
10 class ABJ_404_Solution_AdminTraceLabels {
11
12 /**
13 * Translate a known pipeline-trace string for admin display.
14 *
15 * @param string $text English text stored in the trace.
16 * @return string Translated text, or the original text for dynamic values.
17 */
18 public function translate(string $text): string {
19 $map = $this->translationMap();
20
21 if (isset($map[$text])) {
22 return $map[$text];
23 }
24 if (strpos($text, 'Engine: ') === 0) {
25 return sprintf(__('Engine: %s', '404-solution'), substr($text, 8));
26 }
27 if (preg_match('/^Redirected \((\d+)\)$/', $text, $m)) {
28 return sprintf(__('Redirected (%s)', '404-solution'), $m[1]);
29 }
30 if (preg_match('/^Responded with (.+)$/', $text, $m)) {
31 return sprintf(__('Responded with %s', '404-solution'), $m[1]);
32 }
33 if (preg_match('/^Showed 404 page — (.+)$/', $text, $m)) {
34 return sprintf(__('Showed 404 page — %s', '404-solution'), $m[1]);
35 }
36
37 return $text;
38 }
39
40 /** @return array<string, string> */
41 private function translationMap(): array {
42 static $map = null;
43 if ($map === null) {
44 $map = [
45 'Ignore list' => __('Ignore list', '404-solution'),
46 'Redirect lookup' => __('Redirect lookup', '404-solution'),
47 'Redirect lookup (without comments)' => __('Redirect lookup (without comments)', '404-solution'),
48 'Conditions' => __('Conditions', '404-solution'),
49 'Conditions (without comments)' => __('Conditions (without comments)', '404-solution'),
50 'Health check' => __('Health check', '404-solution'),
51 'Health check (without comments)' => __('Health check (without comments)', '404-solution'),
52 'Regex rules' => __('Regex rules', '404-solution'),
53 'Suggestion engines' => __('Suggestion engines', '404-solution'),
54 'Result' => __('Result', '404-solution'),
55 'Not ignored' => __('Not ignored', '404-solution'),
56 'Matched — request ignored' => __('Matched — request ignored', '404-solution'),
57 'Found existing redirect' => __('Found existing redirect', '404-solution'),
58 'No matching redirect' => __('No matching redirect', '404-solution'),
59 'All conditions met' => __('All conditions met', '404-solution'),
60 'Blocked by conditions' => __('Blocked by conditions', '404-solution'),
61 'Destination unreachable — skipped' => __('Destination unreachable — skipped', '404-solution'),
62 'Matched' => __('Matched', '404-solution'),
63 'No match' => __('No match', '404-solution'),
64 'Skipped' => __('Skipped', '404-solution'),
65 'Excluded' => __('Excluded', '404-solution'),
66 'Error' => __('Error', '404-solution'),
67 'No match found' => __('No match found', '404-solution'),
68 'Showed 404 page' => __('Showed 404 page', '404-solution'),
69 'Redirected to external URL' => __('Redirected to external URL', '404-solution'),
70 'No redirect — showed 404 page' => __('No redirect — showed 404 page', '404-solution'),
71 ];
72 }
73 return $map;
74 }
75
76 /**
77 * @param string $outcome
78 * @return string CSS class for the trace outcome badge.
79 */
80 public function outcomeClass(string $outcome): string {
81 $lower = strtolower($outcome);
82 if (strpos($lower, 'blocked') !== false || strpos($lower, 'unreachable') !== false
83 || strpos($lower, 'error') !== false || strpos($lower, 'ignored') !== false
84 || strpos($lower, 'missing') !== false || strpos($lower, 'invalid') !== false) {
85 return 'abj404-trace-outcome-fail';
86 }
87 if (strpos($lower, 'redirected') !== false || strpos($lower, 'responded') !== false
88 || strpos($lower, 'showed 404') !== false || strpos($lower, 'no redirect') !== false) {
89 return 'abj404-trace-outcome-result';
90 }
91 if (strpos($lower, 'found') !== false || strpos($lower, 'matched') !== false
92 || strpos($lower, 'passed') !== false || strpos($lower, 'not ignored') !== false
93 || strpos($lower, 'all conditions met') !== false) {
94 return 'abj404-trace-outcome-pass';
95 }
96
97 return 'abj404-trace-outcome-neutral';
98 }
99 }
100