refactor(icons): replace local brand SVGs with FA5 classes
Unify social/OAuth/contact icons on the global Font Awesome 5.15.4 pack, add aksrt_render_social_links for author hero, enqueue FA on admin SPA, and delete assets/img/icons.
This commit is contained in:
1 parent
e0f1e0a8ad
commit
fe870bfc19
26 files changed
+285
-129
No files matched your search
@@ -115,6 +115,14 @@ class AKSRT_Admin {
|
||||
}
|
||||
}
|
||||
|
||||
// Match frontend FA5 pack so FaIcon / menu glyphs render in the SPA.
|
||||
wp_enqueue_style(
|
||||
'aksrt-font-awesome-5',
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css',
|
||||
[],
|
||||
'5.15.4'
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'aksrt-admin-app',
|
||||
$build_uri . 'index.js',
|
||||
|
||||
@@ -239,7 +239,7 @@ trait AKSRT_OAuth_Part_1 {
|
||||
$result[] = [
|
||||
'name' => $key,
|
||||
'label' => $platform_names[$key] ?? ucfirst($key),
|
||||
'icon' => aksrt_inline_svg($key),
|
||||
'icon' => function_exists('aksrt_brand_icon') ? aksrt_brand_icon((string) $key) : '',
|
||||
'url' => esc_url($url),
|
||||
];
|
||||
}
|
||||
@@ -350,14 +350,14 @@ trait AKSRT_OAuth_Part_1 {
|
||||
if (empty($enabled_providers)) return '';
|
||||
|
||||
$icons = [
|
||||
'github' => aksrt_inline_svg('github'),
|
||||
'gitee' => aksrt_inline_svg('gitee'),
|
||||
'qq' => aksrt_inline_svg('qq'),
|
||||
'google' => aksrt_inline_svg('google'),
|
||||
'weibo' => aksrt_inline_svg('weibo'),
|
||||
'weixin' => aksrt_inline_svg('wechat'),
|
||||
'baidu' => '<span class="oauth-btn__fallback">B</span>',
|
||||
'alipay' => '<span class="oauth-btn__fallback">A</span>',
|
||||
'github' => aksrt_brand_icon('github'),
|
||||
'gitee' => aksrt_brand_icon('gitee'),
|
||||
'qq' => aksrt_brand_icon('qq'),
|
||||
'google' => aksrt_brand_icon('google'),
|
||||
'weibo' => aksrt_brand_icon('weibo'),
|
||||
'weixin' => aksrt_brand_icon('weixin'),
|
||||
'baidu' => aksrt_brand_icon('baidu'),
|
||||
'alipay' => aksrt_brand_icon('alipay'),
|
||||
];
|
||||
|
||||
ob_start();
|
||||
|
||||
@@ -16,14 +16,14 @@ trait AKSRT_OAuth_Part_2 {
|
||||
'baidu' => 'Baidu', 'alipay' => 'Alipay',
|
||||
];
|
||||
$icons = [
|
||||
'github' => aksrt_inline_svg('github'),
|
||||
'gitee' => aksrt_inline_svg('gitee'),
|
||||
'qq' => aksrt_inline_svg('qq'),
|
||||
'google' => aksrt_inline_svg('google'),
|
||||
'weibo' => aksrt_inline_svg('weibo'),
|
||||
'weixin' => aksrt_inline_svg('wechat'),
|
||||
'baidu' => '<span class="oauth-btn__fallback">B</span>',
|
||||
'alipay' => '<span class="oauth-btn__fallback">A</span>',
|
||||
'github' => aksrt_brand_icon('github'),
|
||||
'gitee' => aksrt_brand_icon('gitee'),
|
||||
'qq' => aksrt_brand_icon('qq'),
|
||||
'google' => aksrt_brand_icon('google'),
|
||||
'weibo' => aksrt_brand_icon('weibo'),
|
||||
'weixin' => aksrt_brand_icon('weixin'),
|
||||
'baidu' => aksrt_brand_icon('baidu'),
|
||||
'alipay' => aksrt_brand_icon('alipay'),
|
||||
];
|
||||
|
||||
$bindings = [];
|
||||
|
||||
+237
-67
@@ -1,12 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* AKSRT Theme - SVG Icons Module
|
||||
* AKSRT Theme — Brand / contact icons (Font Awesome 5)
|
||||
*
|
||||
* 本地 SVG 图标读取/缓存、图标 key 映射显示名称、
|
||||
* 联系方式图标下拉选项渲染
|
||||
* Short-key → FA5 class map, escaped <i> markup, contact option labels,
|
||||
* and public social-link renderer. Local SVG inventory removed.
|
||||
*
|
||||
* @package AKSRT
|
||||
* @version 3.1.0
|
||||
* @version 3.4.0
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
@@ -37,37 +37,150 @@ function aksrt_parse_country_list($raw) {
|
||||
endif;
|
||||
|
||||
// ============================================================
|
||||
// 本地 SVG 图标:读取 SVGs 目录并缓存
|
||||
// Brand icon map (FA 5.15.4 free)
|
||||
// ============================================================
|
||||
if (!function_exists('aksrt_inline_svg')) :
|
||||
function aksrt_inline_svg($name) {
|
||||
// 兼容 FA5 旧数据:fab fa-github / fabfa-github / fa-github → github
|
||||
$name = preg_replace('/^(fab|fas|far)[\s-]*/', '', $name);
|
||||
$name = preg_replace('/^fa[\s-]*/', '', $name);
|
||||
$name = preg_replace('/^[\s-]+/', '', $name);
|
||||
$name = trim($name, '- ');
|
||||
static $cache = array();
|
||||
if (isset($cache[$name])) return $cache[$name];
|
||||
$path = AKSRT_DIR . '/assets/img/icons/' . $name . '.svg';
|
||||
if (file_exists($path)) {
|
||||
$svg = file_get_contents($path);
|
||||
// 去除 XML 声明和 DOCTYPE
|
||||
$svg = preg_replace('/^<\?xml.*?\?>\s*/i', '', $svg);
|
||||
$svg = preg_replace('/^<!DOCTYPE[^>]*>\s*/i', '', $svg);
|
||||
// 移除 <svg> 上的固定宽高,让 CSS 控制尺寸
|
||||
$svg = preg_replace('/\swidth="[^"]*"/', '', $svg);
|
||||
$svg = preg_replace('/\sheight="[^"]*"/', '', $svg);
|
||||
// 移除 iconfont 冗余属性
|
||||
$svg = preg_replace('/\sclass="[^"]*"/', '', $svg);
|
||||
$svg = preg_replace('/\st="[^"]*"/', '', $svg);
|
||||
$svg = preg_replace('/\sp-id="[^"]*"/', '', $svg);
|
||||
$svg = preg_replace('/\sxmlns:xlink="[^"]*"/', '', $svg);
|
||||
// 移除路径上的 opacity 属性
|
||||
$svg = preg_replace('/(<(?:path|circle|rect|polygon|line|polyline|ellipse)[^>]*)\sopacity="[^"]*"/', '$1', $svg);
|
||||
$cache[$name] = $svg;
|
||||
return $svg;
|
||||
}
|
||||
return '';
|
||||
|
||||
if (!function_exists('aksrt_brand_icon_map')) :
|
||||
/**
|
||||
* Short key → FA5 class string (allowlisted).
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
function aksrt_brand_icon_map(): array {
|
||||
static $map = null;
|
||||
if ($map !== null) {
|
||||
return $map;
|
||||
}
|
||||
|
||||
// FA5 free has no bilibili/gitee brands — use solid stand-ins.
|
||||
$map = [
|
||||
'github' => 'fab fa-github',
|
||||
'google' => 'fab fa-google',
|
||||
'x' => 'fab fa-twitter',
|
||||
'twitter' => 'fab fa-twitter',
|
||||
'email' => 'fas fa-envelope',
|
||||
'envelope' => 'fas fa-envelope',
|
||||
'wechat' => 'fab fa-weixin',
|
||||
'weixin' => 'fab fa-weixin',
|
||||
'qq' => 'fab fa-qq',
|
||||
'weibo' => 'fab fa-weibo',
|
||||
'telegram' => 'fab fa-telegram-plane',
|
||||
'discord' => 'fab fa-discord',
|
||||
'bilibili' => 'fas fa-tv',
|
||||
'linkedin' => 'fab fa-linkedin-in',
|
||||
'facebook' => 'fab fa-facebook-f',
|
||||
'youtube' => 'fab fa-youtube',
|
||||
'instagram' => 'fab fa-instagram',
|
||||
'web' => 'fas fa-globe',
|
||||
'globe' => 'fas fa-globe',
|
||||
'gitee' => 'fas fa-code-branch',
|
||||
'baidu' => 'fas fa-paw',
|
||||
'alipay' => 'fab fa-alipay',
|
||||
];
|
||||
|
||||
return $map;
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_normalize_icon_key')) :
|
||||
/**
|
||||
* Normalize short key or full FA class string to a short map key.
|
||||
*
|
||||
* Examples: 'fab fa-github' | 'fabfa-github' | 'fa-github' | 'github' | 'weixin' → 'github' | 'wechat'
|
||||
*
|
||||
* @param string $name Raw icon key or FA class string.
|
||||
* @return string Short key (may be empty).
|
||||
*/
|
||||
function aksrt_normalize_icon_key(string $name): string {
|
||||
$name = trim($name);
|
||||
if ($name === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Strip style prefixes: fab/fas/far + optional space or hyphen.
|
||||
$name = preg_replace('/^(fab|fas|far)[\s-]*/i', '', $name);
|
||||
$name = preg_replace('/^fa[\s-]*/i', '', (string) $name);
|
||||
$name = trim((string) $name, "- \t\n\r\0\x0B");
|
||||
$name = strtolower($name);
|
||||
|
||||
// Aliases → canonical keys used by the map / contact options.
|
||||
$aliases = [
|
||||
'weixin' => 'wechat',
|
||||
'weixingzh' => 'wechat',
|
||||
'twitter' => 'x',
|
||||
'envelope' => 'email',
|
||||
'globe' => 'web',
|
||||
];
|
||||
if (isset($aliases[$name])) {
|
||||
return $aliases[$name];
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_brand_icon_class')) :
|
||||
/**
|
||||
* Resolve a short key or FA class string to an allowlisted FA5 class.
|
||||
*
|
||||
* @param string $name Short key or full FA class string.
|
||||
* @return string e.g. 'fab fa-github', or '' if unknown.
|
||||
*/
|
||||
function aksrt_brand_icon_class(string $name): string {
|
||||
$raw = trim($name);
|
||||
if ($raw === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Pass through already-valid full FA class strings (footer contact_more).
|
||||
if (preg_match('/^(fa[sbr]|fa)\s+fa-[\w-]+(?:\s+fa-[\w-]+)*$/i', $raw)) {
|
||||
// Prefer mapped short key when strip matches our catalog (normalizes weixin etc.).
|
||||
$key = aksrt_normalize_icon_key($raw);
|
||||
$map = aksrt_brand_icon_map();
|
||||
if ($key !== '' && isset($map[$key])) {
|
||||
return $map[$key];
|
||||
}
|
||||
// Allowlisted style + glyph only — collapse whitespace, lower style prefix.
|
||||
$parts = preg_split('/\s+/', strtolower($raw));
|
||||
$parts = array_values(array_filter((array) $parts));
|
||||
return implode(' ', $parts);
|
||||
}
|
||||
|
||||
$key = aksrt_normalize_icon_key($raw);
|
||||
if ($key === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
$map = aksrt_brand_icon_map();
|
||||
return $map[$key] ?? '';
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_brand_icon')) :
|
||||
/**
|
||||
* Escaped FA <i> markup for a brand/contact icon.
|
||||
*
|
||||
* @param string $name Short key or FA class string.
|
||||
* @param array|string $extra_classes Optional extra classes.
|
||||
* @return string Safe HTML or empty string when unknown.
|
||||
*/
|
||||
function aksrt_brand_icon(string $name, $extra_classes = []): string {
|
||||
$class = aksrt_brand_icon_class($name);
|
||||
if ($class === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (is_string($extra_classes) && $extra_classes !== '') {
|
||||
$extra_classes = preg_split('/\s+/', $extra_classes) ?: [];
|
||||
}
|
||||
if (is_array($extra_classes) && $extra_classes !== []) {
|
||||
$extra = array_filter(array_map('sanitize_html_class', $extra_classes));
|
||||
if ($extra !== []) {
|
||||
$class .= ' ' . implode(' ', $extra);
|
||||
}
|
||||
}
|
||||
|
||||
return '<i class="' . esc_attr($class) . '" aria-hidden="true"></i>';
|
||||
}
|
||||
endif;
|
||||
|
||||
@@ -76,16 +189,20 @@ endif;
|
||||
// ============================================================
|
||||
if (!function_exists('aksrt_icon_key_to_name')) :
|
||||
function aksrt_icon_key_to_name($key) {
|
||||
$map = array(
|
||||
'github' => 'GitHub', 'google' => 'Google', 'x' => 'X',
|
||||
'email' => '邮箱', 'wechat' => '微信', 'qq' => 'QQ',
|
||||
'weibo' => '微博', 'telegram' => 'Telegram',
|
||||
'discord' => 'Discord', 'bilibili' => 'Bilibili',
|
||||
'linkedin' => 'LinkedIn', 'facebook' => 'Facebook',
|
||||
'youtube' => 'YouTube', 'instagram' => 'Instagram',
|
||||
'web' => '网站',
|
||||
);
|
||||
return isset($map[$key]) ? $map[$key] : ucwords(str_replace('-', ' ', $key));
|
||||
$key = aksrt_normalize_icon_key((string) $key);
|
||||
$map = array(
|
||||
'github' => 'GitHub', 'google' => 'Google', 'x' => 'X',
|
||||
'email' => '邮箱', 'wechat' => '微信', 'qq' => 'QQ',
|
||||
'weibo' => '微博', 'telegram' => 'Telegram',
|
||||
'discord' => 'Discord', 'bilibili' => 'Bilibili',
|
||||
'linkedin' => 'LinkedIn', 'facebook' => 'Facebook',
|
||||
'youtube' => 'YouTube', 'instagram' => 'Instagram',
|
||||
'web' => '网站',
|
||||
'gitee' => 'Gitee',
|
||||
'baidu' => 'Baidu',
|
||||
'alipay' => 'Alipay',
|
||||
);
|
||||
return isset($map[$key]) ? $map[$key] : ucwords(str_replace('-', ' ', $key));
|
||||
}
|
||||
endif;
|
||||
|
||||
@@ -94,28 +211,81 @@ endif;
|
||||
// ============================================================
|
||||
if (!function_exists('aksrt_contact_icon_options')) :
|
||||
function aksrt_contact_icon_options($selected = '') {
|
||||
$icons = array(
|
||||
'github' => 'GitHub',
|
||||
'google' => 'Google',
|
||||
'x' => 'X',
|
||||
'email' => '邮箱',
|
||||
'wechat' => '微信',
|
||||
'qq' => 'QQ',
|
||||
'weibo' => '微博',
|
||||
'telegram' => 'Telegram',
|
||||
'discord' => 'Discord',
|
||||
'bilibili' => 'Bilibili',
|
||||
'linkedin' => 'LinkedIn',
|
||||
'facebook' => 'Facebook',
|
||||
'youtube' => 'YouTube',
|
||||
'instagram' => 'Instagram',
|
||||
'web' => '网站',
|
||||
);
|
||||
$html = '<option value="">—</option>';
|
||||
foreach ($icons as $key => $label) {
|
||||
$sel = $key === $selected ? ' selected' : '';
|
||||
$html .= '<option value="' . esc_attr($key) . '"' . $sel . '>' . esc_html($label) . '</option>';
|
||||
}
|
||||
return $html;
|
||||
$icons = array(
|
||||
'github' => 'GitHub',
|
||||
'google' => 'Google',
|
||||
'x' => 'X',
|
||||
'email' => '邮箱',
|
||||
'wechat' => '微信',
|
||||
'qq' => 'QQ',
|
||||
'weibo' => '微博',
|
||||
'telegram' => 'Telegram',
|
||||
'discord' => 'Discord',
|
||||
'bilibili' => 'Bilibili',
|
||||
'linkedin' => 'LinkedIn',
|
||||
'facebook' => 'Facebook',
|
||||
'youtube' => 'YouTube',
|
||||
'instagram' => 'Instagram',
|
||||
'web' => '网站',
|
||||
);
|
||||
$selected = aksrt_normalize_icon_key((string) $selected);
|
||||
$html = '<option value="">—</option>';
|
||||
foreach ($icons as $key => $label) {
|
||||
$sel = $key === $selected ? ' selected' : '';
|
||||
$html .= '<option value="' . esc_attr($key) . '"' . $sel . '>' . esc_html($label) . '</option>';
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
endif;
|
||||
|
||||
// ============================================================
|
||||
// Public social links (author hero / profile)
|
||||
// ============================================================
|
||||
if (!function_exists('aksrt_render_social_links')) :
|
||||
/**
|
||||
* Echo a list of public contact links with FA icons.
|
||||
*
|
||||
* @param array<int, array{name?:string,url?:string,icon?:string,title?:string,label?:string}> $contacts
|
||||
*/
|
||||
function aksrt_render_social_links(array $contacts): void {
|
||||
$links = [];
|
||||
foreach ($contacts as $contact) {
|
||||
if (!is_array($contact)) {
|
||||
continue;
|
||||
}
|
||||
$url = isset($contact['url']) ? (string) $contact['url'] : '';
|
||||
$icon = isset($contact['icon']) ? (string) $contact['icon'] : '';
|
||||
if ($url === '' || $icon === '') {
|
||||
continue;
|
||||
}
|
||||
$icon_html = aksrt_brand_icon($icon);
|
||||
if ($icon_html === '') {
|
||||
$icon_html = '<i class="fas fa-globe" aria-hidden="true"></i>';
|
||||
}
|
||||
$label = (string) ($contact['name'] ?? $contact['title'] ?? $contact['label'] ?? '');
|
||||
if ($label === '') {
|
||||
$label = aksrt_icon_key_to_name($icon);
|
||||
}
|
||||
$links[] = [
|
||||
'url' => $url,
|
||||
'label' => $label,
|
||||
'icon' => $icon_html,
|
||||
];
|
||||
}
|
||||
|
||||
if ($links === []) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo '<div class="profile-social-links">';
|
||||
foreach ($links as $link) {
|
||||
printf(
|
||||
'<a class="social-icon-link" href="%1$s" target="_blank" rel="noopener noreferrer" title="%2$s" aria-label="%2$s">%3$s</a>',
|
||||
esc_url($link['url']),
|
||||
esc_attr($link['label']),
|
||||
$link['icon'] // pre-escaped via aksrt_brand_icon / fixed globe fallback
|
||||
);
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
endif;
|
||||
@@ -205,7 +205,7 @@ if (!function_exists('aksrt_render_share_dropdown')) :
|
||||
<div class="share-dropdown__grid">
|
||||
<button type="button" class="share-item" data-platform="qq"><i class="fab fa-qq"></i><span>QQ</span></button>
|
||||
<button type="button" class="share-item" data-platform="weibo"><i class="fab fa-weibo"></i><span>微博</span></button>
|
||||
<button type="button" class="share-item" data-platform="twitter"><i class="fab fa-x-twitter"></i><span>X</span></button>
|
||||
<button type="button" class="share-item" data-platform="twitter"><i class="fab fa-twitter"></i><span>X</span></button>
|
||||
<button type="button" class="share-item" data-platform="wechat"><i class="fab fa-weixin"></i><span>微信</span></button>
|
||||
<button type="button" class="share-item" data-platform="copy"><i class="fas fa-link"></i><span><?php esc_html_e('复制链接', 'aksrt'); ?></span></button>
|
||||
<button type="button" class="share-item" data-platform="poster"><i class="fas fa-image"></i><span><?php esc_html_e('海报分享', 'aksrt'); ?></span></button>
|
||||
|
||||
Reference in new issue
Block a user