fix(icons): emit FA5 only and upgrade legacy FA4 icon values
The theme is FA5-only, but aksrt_icon_markup() prefixed bare glyphs with the FA4 style token, so stored icon-picker values rendered FA4 markup, and three runtime strings still carried the FA4 double-fa form (report modal header and submit button, comment report menu item). That left the navigation icon contract failing at 11/12. - aksrt_icon_markup() normalizes bare glyphs, legacy FA4 values and style-only values to "fa fas fa-<glyph>", keeping the FA5 brand family (fa fab) and trailing classes intact. - aksrt_normalize_icon_key() strips the legacy FA4 prefix so stored values resolve against the brand-icon catalog again. - report.js and the comment report item emit FA5 markup. - An icon-picker contract test locks the upgrade behaviour. Verification: 338 widget-system, 12 navigation, 28 admin and 13 front-submit contract tests pass; normalization also exercised against legacy, FA5 and brand inputs.
This commit is contained in:
1 parent
7597972eea
commit
0afead968a
4 files changed
+31
-5
No files matched your search
@@ -88,6 +88,8 @@ if (!function_exists('aksrt_normalize_icon_key')) :
|
||||
*
|
||||
* Examples: 'fa fab fa-github' | 'fa-github' | 'github' | 'weixin' → 'github' | 'wechat'
|
||||
*
|
||||
* Legacy FA4 values (a bare `fa` token followed by `fa-<glyph>`) are stripped too.
|
||||
*
|
||||
* @param string $name Raw icon key or FA class string.
|
||||
* @return string Short key (may be empty).
|
||||
*/
|
||||
@@ -97,8 +99,11 @@ function aksrt_normalize_icon_key(string $name): string {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Strip the FA5 layout/style prefixes and glyph prefix.
|
||||
// Strip the FA5 layout/style prefixes, the glyph prefix and the legacy FA4
|
||||
// double-`fa` form (a bare `fa` token followed by `fa-<glyph>`). The site
|
||||
// ships FA5 only, but stored values may predate it.
|
||||
$name = preg_replace('/^fa\s+(?:fas|far|fab)\s+/i', '', $name);
|
||||
$name = preg_replace('/^fa\s+fa-/i', '', (string) $name);
|
||||
$name = preg_replace('/^(?:fas|far|fab)\s+/i', '', (string) $name);
|
||||
$name = preg_replace('/^fa-/i', '', (string) $name);
|
||||
$name = trim((string) $name, "- \t\n\r\0\x0B");
|
||||
@@ -299,9 +304,12 @@ if (!function_exists('aksrt_icon_markup')) :
|
||||
* Supported values:
|
||||
* - "fa fas fa-star" / "fa fab fa-weixin" — FA5 class string
|
||||
* - "fa-star" — bare glyph, rendered as solid FA5
|
||||
* - legacy FA4 string — double-`fa` form, upgraded to FA5
|
||||
* - "zibsvg-hot" — theme built-in SVG sprite key
|
||||
* - "customsvg-<svg …>" — inline user SVG markup
|
||||
*
|
||||
* Output is always FA5 — the legacy FA4 double-`fa` prefix is never emitted.
|
||||
*
|
||||
* @param string $value Raw stored value.
|
||||
* @param array|string $extra_classes Extra classes for the rendered element.
|
||||
* @return string Safe HTML, empty string for empty values.
|
||||
@@ -343,7 +351,13 @@ function aksrt_icon_markup(string $value, $extra_classes = []): string {
|
||||
return '<svg class="' . esc_attr($class) . '" aria-hidden="true"><use xlink:href="#icon-' . $key . '"></use></svg>';
|
||||
}
|
||||
|
||||
if (!str_contains($value, 'fa ') && str_contains($value, 'fa-')) {
|
||||
// 本站统一 FA5 输出:遗留 FA4 双 fa 前缀、裸字形 "fa-xxx" 与缺少 fa 前缀的
|
||||
// "fas/far/fab fa-xxx" 均归一为 "fa fas fa-xxx"(末尾附加类名原样保留)。
|
||||
if (preg_match('/^fa\s+fa-/i', $value)) {
|
||||
$value = preg_replace('/^fa\s+/i', 'fa fas ', $value, 1);
|
||||
} elseif (preg_match('/^fa-/i', $value)) {
|
||||
$value = 'fa fas ' . $value;
|
||||
} elseif (preg_match('/^(?:fas|far|fab)\s+fa-/i', $value)) {
|
||||
$value = 'fa ' . $value;
|
||||
}
|
||||
return '<i class="' . esc_attr($value . $extra) . '" aria-hidden="true"></i>';
|
||||
|
||||
@@ -178,7 +178,7 @@ if (!function_exists('aksrt_get_comment_report_html')) :
|
||||
'target_avatar' => get_avatar_url((int) $comment->user_id > 0 ? (int) $comment->user_id : 0, ['size' => 40]) ?: '',
|
||||
]);
|
||||
|
||||
return '<li><a class="comment-report-link" href="javascript:;" data-aksrt-report="' . esc_attr((string) $report_payload) . '"><i class="fa fa-exclamation-triangle mr10 fa-fw c-red" aria-hidden="true"></i>' . esc_html__('举报', 'aksrt') . '</a></li>';
|
||||
return '<li><a class="comment-report-link" href="javascript:;" data-aksrt-report="' . esc_attr((string) $report_payload) . '"><i class="fa fas fa-exclamation-triangle mr10 fa-fw c-red" aria-hidden="true"></i>' . esc_html__('举报', 'aksrt') . '</a></li>';
|
||||
}
|
||||
endif;
|
||||
|
||||
|
||||
Reference in new issue
Block a user