refactor(icons): converge every icon render on aksrt_icon_markup

aksrt_get_comment_icon(), aksrt_renderer_svg_icon() and the widget
renderer's private icon_markup() all delegate to the unified helper,
and the duplicated 24px empty-state SVGs in user-center/user-home now
come from one aksrt_empty_state_svgs(). Contract tests follow the
delegation (sprite <use> markup asserted in the helper).
This commit is contained in:
2026-09-06 12:59:44 +08:00
parent d599bbccd9
commit e4745d501e
8 changed files with 228 additions and 23 deletions
+4 -3
View File
@@ -274,10 +274,11 @@ if (!function_exists('aksrt_user_center_empty_svgs')) {
* @return array{post:string,comment:string,favorite:string}
*/
function aksrt_user_center_empty_svgs(): array {
$all = aksrt_empty_state_svgs();
return [
'post' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><path d="M14 2v6h6"/></svg>',
'comment' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>',
'favorite' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></svg>',
'post' => $all['post'],
'comment' => $all['comment'],
'favorite' => $all['favorite'],
];
}
}
+6 -4
View File
@@ -75,6 +75,8 @@ if (!function_exists('aksrt_get_user_home_page_context')) {
$display_tabs = $is_mobile ? $enabled_tabs_mobile : $enabled_tabs_pc;
$default_tab = !empty($display_tabs) ? $display_tabs[0] : $enabled_tabs[0];
$empty_svgs = aksrt_empty_state_svgs();
$follow_count = 0;
if (class_exists('\AKSRT\User\Follow')) {
$follow_count = (int) \AKSRT\User\Follow::get_instance()->get_follower_count($user_id);
@@ -133,10 +135,10 @@ if (!function_exists('aksrt_get_user_home_page_context')) {
'favorites_page' => 1,
'follow_sub' => 'followers',
'follow_page' => 1,
'svg_empty_post' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><path d="M14 2v6h6"/><path d="M9 13h6M9 17h6M9 9h1"/></svg>',
'svg_empty_comment' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>',
'svg_empty_favorite' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></svg>',
'svg_empty_follow' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"/></svg>',
'svg_empty_post' => $empty_svgs['post'],
'svg_empty_comment' => $empty_svgs['comment'],
'svg_empty_favorite' => $empty_svgs['favorite'],
'svg_empty_follow' => $empty_svgs['follow'],
];
}
}
+1 -1
View File
@@ -20,6 +20,6 @@ if (!function_exists('aksrt_get_comment_icon')) :
* @return string
*/
function aksrt_get_comment_icon(string $name, string $class = 'icon'): string {
return '<svg class="' . esc_attr($class) . '" aria-hidden="true"><use xlink:href="#icon-' . esc_attr($name) . '"></use></svg>';
return aksrt_icon_markup('zibsvg-' . $name, $class);
}
endif;
+1 -1
View File
@@ -241,7 +241,7 @@ if (!function_exists('aksrt_renderer_meta_number')) {
if (!function_exists('aksrt_renderer_svg_icon')) {
function aksrt_renderer_svg_icon(string $name): string {
return '<svg class="icon" aria-hidden="true"><use xlink:href="#icon-' . esc_attr($name) . '"></use></svg>';
return aksrt_icon_markup('zibsvg-' . $name);
}
}