Skip to content

Commit 1eeb60c

Browse files
Merge pull request #241 from JLG-WOCFR-DEV/codex/update-column_http_status-to-return-badges
Add HTTP status badges and legend
2 parents b6acc02 + 324a505 commit 1eeb60c

File tree

5 files changed

+179
-5
lines changed

5 files changed

+179
-5
lines changed

liens-morts-detector-jlg/assets/css/blc-admin-styles.css

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,79 @@
3838
color: #50575e;
3939
}
4040

41+
/* Styles pour les badges de statut HTTP */
42+
.blc-status {
43+
display: inline-flex;
44+
align-items: center;
45+
padding: 0.1rem 0.55rem;
46+
border-radius: 999px;
47+
font-size: 12px;
48+
line-height: 1.4;
49+
font-weight: 600;
50+
letter-spacing: 0.02em;
51+
background-color: #374151;
52+
color: #f9fafb;
53+
font-variant-numeric: tabular-nums;
54+
text-transform: none;
55+
}
56+
57+
.blc-status--2xx {
58+
background-color: #0f5132;
59+
color: #f8fafc;
60+
}
61+
62+
.blc-status--3xx {
63+
background-color: #92400e;
64+
color: #fef3c7;
65+
}
66+
67+
.blc-status--4xx,
68+
.blc-status--5xx {
69+
background-color: #7f1d1d;
70+
color: #fef2f2;
71+
}
72+
73+
.blc-status--unknown {
74+
background-color: #4b5563;
75+
color: #f9fafb;
76+
}
77+
78+
/* Styles pour la légende des statuts HTTP */
79+
.blc-status-legend {
80+
margin: 16px 0;
81+
padding: 12px 16px;
82+
border: 1px solid #d0d1d4;
83+
border-radius: 6px;
84+
background-color: #f6f7f7;
85+
}
86+
87+
.blc-status-legend__title {
88+
margin: 0 0 8px;
89+
font-weight: 600;
90+
color: #1d2327;
91+
}
92+
93+
.blc-status-legend__list {
94+
margin: 0;
95+
padding: 0;
96+
list-style: none;
97+
display: flex;
98+
flex-wrap: wrap;
99+
gap: 8px 20px;
100+
}
101+
102+
.blc-status-legend__item {
103+
display: inline-flex;
104+
align-items: center;
105+
gap: 8px;
106+
color: #1d2327;
107+
font-size: 13px;
108+
}
109+
110+
.blc-status-legend__item span:last-child {
111+
line-height: 1.3;
112+
}
113+
41114
@media (max-width: 782px) {
42115
.blc-stats-box {
43116
flex-direction: column;

liens-morts-detector-jlg/includes/blc-admin-pages.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,31 @@ function blc_dashboard_links_page() {
225225
<?php if ($broken_links_count === 0): ?>
226226
<p><?php esc_html_e('✅ Aucun lien mort trouvé. Bravo !', 'liens-morts-detector-jlg'); ?></p>
227227
<?php else: ?>
228+
<div class="blc-status-legend" role="note">
229+
<p class="blc-status-legend__title"><?php esc_html_e('Légende des statuts HTTP', 'liens-morts-detector-jlg'); ?></p>
230+
<ul class="blc-status-legend__list">
231+
<li class="blc-status-legend__item">
232+
<span class="blc-status blc-status--2xx">200</span>
233+
<span><?php esc_html_e('Disponible (2xx)', 'liens-morts-detector-jlg'); ?></span>
234+
</li>
235+
<li class="blc-status-legend__item">
236+
<span class="blc-status blc-status--3xx">302</span>
237+
<span><?php esc_html_e('Redirection (3xx)', 'liens-morts-detector-jlg'); ?></span>
238+
</li>
239+
<li class="blc-status-legend__item">
240+
<span class="blc-status blc-status--4xx">404</span>
241+
<span><?php esc_html_e('Erreur client (4xx)', 'liens-morts-detector-jlg'); ?></span>
242+
</li>
243+
<li class="blc-status-legend__item">
244+
<span class="blc-status blc-status--5xx">502</span>
245+
<span><?php esc_html_e('Erreur serveur (5xx)', 'liens-morts-detector-jlg'); ?></span>
246+
</li>
247+
<li class="blc-status-legend__item">
248+
<span class="blc-status blc-status--unknown">?</span>
249+
<span><?php esc_html_e('Statut inconnu ou indisponible', 'liens-morts-detector-jlg'); ?></span>
250+
</li>
251+
</ul>
252+
</div>
228253
<form method="get" class="blc-links-filter-form" aria-labelledby="blc-links-filter-heading">
229254
<h2 id="blc-links-filter-heading" class="screen-reader-text"><?php esc_html_e('Filtres de la liste des liens cassés', 'liens-morts-detector-jlg'); ?></h2>
230255
<?php

liens-morts-detector-jlg/includes/class-blc-images-list-table.php

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,49 @@ protected function column_http_status($item) {
147147
return esc_html__('', 'liens-morts-detector-jlg');
148148
}
149149

150+
$classes = ['blc-status'];
151+
$label = (string) $raw_status;
152+
150153
if (is_numeric($raw_status)) {
151-
$raw_status = (int) $raw_status;
154+
$status_code = (int) $raw_status;
155+
$label = (string) $status_code;
156+
157+
if ($status_code >= 200 && $status_code < 300) {
158+
$classes[] = 'blc-status--2xx';
159+
} elseif ($status_code >= 300 && $status_code < 400) {
160+
$classes[] = 'blc-status--3xx';
161+
} elseif ($status_code >= 400 && $status_code < 500) {
162+
$classes[] = 'blc-status--4xx';
163+
} elseif ($status_code >= 500 && $status_code < 600) {
164+
$classes[] = 'blc-status--5xx';
165+
} else {
166+
$classes[] = 'blc-status--unknown';
167+
}
168+
169+
$classes[] = 'blc-status--' . $status_code;
170+
} else {
171+
$classes[] = 'blc-status--unknown';
172+
$classes[] = 'blc-status--' . strtolower((string) $raw_status);
152173
}
153174

154-
return esc_html((string) $raw_status);
175+
$sanitized_classes = array_map(
176+
static function ($class) {
177+
if (function_exists('sanitize_html_class')) {
178+
return sanitize_html_class($class);
179+
}
180+
181+
return preg_replace('/[^A-Za-z0-9_-]/', '', (string) $class);
182+
},
183+
$classes
184+
);
185+
186+
$class_attribute = implode(' ', array_filter(array_unique($sanitized_classes)));
187+
188+
return sprintf(
189+
'<span class="%s">%s</span>',
190+
esc_attr($class_attribute),
191+
esc_html($label)
192+
);
155193
}
156194

157195
protected function column_last_checked_at($item) {

liens-morts-detector-jlg/includes/class-blc-links-list-table.php

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,49 @@ protected function column_http_status($item) {
325325
return esc_html__('', 'liens-morts-detector-jlg');
326326
}
327327

328+
$classes = ['blc-status'];
329+
$label = (string) $raw_status;
330+
328331
if (is_numeric($raw_status)) {
329-
$raw_status = (int) $raw_status;
332+
$status_code = (int) $raw_status;
333+
$label = (string) $status_code;
334+
335+
if ($status_code >= 200 && $status_code < 300) {
336+
$classes[] = 'blc-status--2xx';
337+
} elseif ($status_code >= 300 && $status_code < 400) {
338+
$classes[] = 'blc-status--3xx';
339+
} elseif ($status_code >= 400 && $status_code < 500) {
340+
$classes[] = 'blc-status--4xx';
341+
} elseif ($status_code >= 500 && $status_code < 600) {
342+
$classes[] = 'blc-status--5xx';
343+
} else {
344+
$classes[] = 'blc-status--unknown';
345+
}
346+
347+
$classes[] = 'blc-status--' . $status_code;
348+
} else {
349+
$classes[] = 'blc-status--unknown';
350+
$classes[] = 'blc-status--' . strtolower((string) $raw_status);
330351
}
331352

332-
return esc_html((string) $raw_status);
353+
$sanitized_classes = array_map(
354+
static function ($class) {
355+
if (function_exists('sanitize_html_class')) {
356+
return sanitize_html_class($class);
357+
}
358+
359+
return preg_replace('/[^A-Za-z0-9_-]/', '', (string) $class);
360+
},
361+
$classes
362+
);
363+
364+
$class_attribute = implode(' ', array_filter(array_unique($sanitized_classes)));
365+
366+
return sprintf(
367+
'<span class="%s">%s</span>',
368+
esc_attr($class_attribute),
369+
esc_html($label)
370+
);
333371
}
334372

335373
protected function column_last_checked_at($item) {

tests/AdminListTablesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public function row_actions($actions, $always_visible = false)
179179
'url' => 'https://example.com',
180180
];
181181

182-
$this->assertSame('410', $table->renderHttpStatus($item));
182+
$this->assertSame('<span class="blc-status blc-status--4xx blc-status--410">410</span>', $table->renderHttpStatus($item));
183183
$this->assertSame('1970-01-01 00:00', $table->renderLastChecked($item));
184184

185185
$empty = [

0 commit comments

Comments
 (0)