Worktree/icon picker #30

Merged
kate522 merged 7 commits from worktree/icon-picker into main 2026-09-06 05:09:55 +00:00
8 changed files with 228 additions and 23 deletions
Showing only changes of commit e4745d501e - Show all commits
+4 -3
View File
@@ -274,10 +274,11 @@ if (!function_exists('aksrt_user_center_empty_svgs')) {
* @return array{post:string,comment:string,favorite:string} * @return array{post:string,comment:string,favorite:string}
*/ */
function aksrt_user_center_empty_svgs(): array { function aksrt_user_center_empty_svgs(): array {
$all = aksrt_empty_state_svgs();
return [ 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>', 'post' => $all['post'],
'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>', 'comment' => $all['comment'],
'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>', '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; $display_tabs = $is_mobile ? $enabled_tabs_mobile : $enabled_tabs_pc;
$default_tab = !empty($display_tabs) ? $display_tabs[0] : $enabled_tabs[0]; $default_tab = !empty($display_tabs) ? $display_tabs[0] : $enabled_tabs[0];
$empty_svgs = aksrt_empty_state_svgs();
$follow_count = 0; $follow_count = 0;
if (class_exists('\AKSRT\User\Follow')) { if (class_exists('\AKSRT\User\Follow')) {
$follow_count = (int) \AKSRT\User\Follow::get_instance()->get_follower_count($user_id); $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, 'favorites_page' => 1,
'follow_sub' => 'followers', 'follow_sub' => 'followers',
'follow_page' => 1, '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_post' => $empty_svgs['post'],
'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_comment' => $empty_svgs['comment'],
'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_favorite' => $empty_svgs['favorite'],
'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_follow' => $empty_svgs['follow'],
]; ];
} }
} }
+1 -1
View File
@@ -20,6 +20,6 @@ if (!function_exists('aksrt_get_comment_icon')) :
* @return string * @return string
*/ */
function aksrt_get_comment_icon(string $name, string $class = 'icon'): 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; endif;
+1 -1
View File
@@ -241,7 +241,7 @@ if (!function_exists('aksrt_renderer_meta_number')) {
if (!function_exists('aksrt_renderer_svg_icon')) { if (!function_exists('aksrt_renderer_svg_icon')) {
function aksrt_renderer_svg_icon(string $name): string { 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);
} }
} }
+1 -12
View File
@@ -543,17 +543,6 @@ final class GeneralRenderer {
} }
private static function icon_markup(string $icon): string { private static function icon_markup(string $icon): string {
$icon = trim($icon); return aksrt_icon_markup($icon);
if ($icon === '') return '';
if (str_starts_with($icon, 'customsvg-')) {
return wp_kses(substr($icon, 10), [
'svg' => ['class' => true, 'viewbox' => true, 'viewBox' => true, 'width' => true, 'height' => true, 'fill' => true, 'xmlns' => true, 'aria-hidden' => true],
'use' => ['href' => true, 'xlink:href' => true],
'path' => ['d' => true, 'fill' => true, 'stroke' => true, 'stroke-width' => true],
]);
}
if (str_starts_with($icon, 'zibsvg-')) return '<svg class="icon" aria-hidden="true"><use xlink:href="#icon-' . esc_attr(substr($icon, 7)) . '"></use></svg>';
if (!str_contains($icon, 'fa ') && str_contains($icon, 'fa-')) $icon = 'fa ' . $icon;
return '<i class="' . esc_attr($icon) . '" aria-hidden="true"></i>';
} }
} }
+210
View File
@@ -0,0 +1,210 @@
<?php
declare(strict_types=1);
if (!defined('ABSPATH')) {
define('ABSPATH', dirname(__DIR__, 2) . DIRECTORY_SEPARATOR);
}
if (!defined('DAY_IN_SECONDS')) {
define('DAY_IN_SECONDS', 86400);
}
if (!defined('MINUTE_IN_SECONDS')) {
define('MINUTE_IN_SECONDS', 60);
}
set_error_handler(static function (int $severity, string $message, string $file, int $line): bool {
if (!(error_reporting() & $severity)) {
return false;
}
throw new ErrorException($message, 0, $severity, $file, $line);
});
$GLOBALS['aksrt_test_state'] = [];
function aksrt_test_reset_state(): void {
$GLOBALS['aksrt_test_state'] = [
'options' => [],
'sidebars' => [],
'routes' => [],
'query_args' => [],
'current_post' => null,
'current_id' => 0,
'singular' => false,
'pay_meta' => ['pay_type' => 'no', 'price' => 0],
'paid_access' => false,
'logged_in' => false,
];
$GLOBALS['wp_registered_sidebars'] = [];
}
aksrt_test_reset_state();
class WP_Error {
public function __construct(private string $code = '', private string $message = '', private array $data = []) {}
public function get_error_code(): string { return $this->code; }
public function get_error_message(): string { return $this->message; }
public function get_error_data(): array { return $this->data; }
}
class WP_REST_Controller {
public string $namespace = '';
public string $rest_base = '';
public function get_items($request) {}
}
class WP_REST_Server {
public const READABLE = 'GET';
}
class WP_REST_Request {
public function __construct(private array $params = []) {}
public function get_params(): array { return $this->params; }
public function get_param(string $key) { return $this->params[$key] ?? null; }
}
class WP_REST_Response {
public function __construct(private $data) {}
public function get_data() { return $this->data; }
}
class WP_Post {
public int $ID;
public int $post_author;
public function __construct(int $id = 1, int $author = 1) {
$this->ID = $id;
$this->post_author = $author;
}
}
class WP_Query {
public array $posts = [];
public int $max_num_pages = 1;
public int $found_posts = 0;
public function __construct(array $args = []) {
$GLOBALS['aksrt_test_state']['query_args'][] = $args;
}
public function have_posts(): bool { return false; }
public function the_post(): void {}
}
class WP_Widget {
public string $id_base = '';
public string $id = '';
public int $number = 0;
public function __construct(string $id_base = '', string $name = '', array $widget_options = [], array $control_options = []) {
unset($name, $widget_options, $control_options);
$this->id_base = $id_base;
}
public function get_settings(): array {
$value = get_option('widget_' . $this->id_base, []);
return is_array($value) ? $value : [];
}
public function get_field_id(string $field): string { return 'widget-' . $this->id_base . '-' . $this->number . '-' . $field; }
public function get_field_name(string $field): string { return 'widget-' . $this->id_base . '[' . $this->number . '][' . $field . ']'; }
public function _set(int $number): void {
$this->number = $number;
$this->id = $this->id_base . '-' . $number;
}
}
function __($text): string { return (string) $text; }
function esc_html__($text): string { return esc_html((string) $text); }
function esc_attr__($text): string { return esc_attr((string) $text); }
function esc_html_e($text): void { echo esc_html((string) $text); }
function esc_attr_e($text): void { echo esc_attr((string) $text); }
function esc_html($value): string { return htmlspecialchars((string) $value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); }
function esc_attr($value): string { return esc_html((string) $value); }
function esc_textarea($value): string { return esc_html((string) $value); }
function esc_url_raw($value): string {
$value = trim((string) $value);
return preg_match('#^(?:https?://|/)#', $value) ? $value : '';
}
function esc_url($value): string { return esc_attr(esc_url_raw($value)); }
function sanitize_text_field($value): string { return trim(preg_replace('/[\r\n\t]+/', ' ', strip_tags((string) $value)) ?? ''); }
function sanitize_textarea_field($value): string { return trim(strip_tags((string) $value)); }
function sanitize_key($value): string { return preg_replace('/[^a-z0-9_\-]/', '', strtolower((string) $value)) ?? ''; }
function sanitize_html_class($value): string { return preg_replace('/[^A-Za-z0-9_-]/', '', (string) $value) ?? ''; }
function sanitize_hex_color($value): string {
return preg_match('/^#(?:[0-9a-fA-F]{3}){1,2}$/', (string) $value) ? strtolower((string) $value) : '';
}
function sanitize_textarea($value): string { return sanitize_textarea_field($value); }
function wp_kses_post($value): string { return strip_tags((string) $value, '<a><b><strong><em><br><p><span><ul><ol><li>'); }
function wp_json_encode($value): string { return (string) json_encode($value, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); }
function absint($value): int { return abs((int) $value); }
function checked($actual, $expected = true, bool $display = true): string {
$result = $actual == $expected ? 'checked="checked"' : '';
if ($display) echo $result;
return $result;
}
function selected($actual, $expected = true, bool $display = true): string {
$result = $actual == $expected ? 'selected="selected"' : '';
if ($display) echo $result;
return $result;
}
function number_format_i18n($number): string { return number_format((float) $number); }
function wp_trim_words($text, int $count = 55): string {
$words = preg_split('/\s+/', trim((string) $text)) ?: [];
return implode(' ', array_slice($words, 0, $count));
}
function get_option(string $name, $default = false) { return $GLOBALS['aksrt_test_state']['options'][$name] ?? $default; }
function update_option(string $name, $value): bool { $GLOBALS['aksrt_test_state']['options'][$name] = $value; return true; }
function wp_get_sidebars_widgets(): array { return $GLOBALS['aksrt_test_state']['sidebars']; }
function wp_set_sidebars_widgets(array $sidebars): void { $GLOBALS['aksrt_test_state']['sidebars'] = $sidebars; }
function register_rest_route(string $namespace, string $route, array $args): bool {
$GLOBALS['aksrt_test_state']['routes'][$namespace . $route] = $args;
return true;
}
function rest_ensure_response($data): WP_REST_Response { return $data instanceof WP_REST_Response ? $data : new WP_REST_Response($data); }
function is_wp_error($value): bool { return $value instanceof WP_Error; }
function is_singular(): bool { return (bool) $GLOBALS['aksrt_test_state']['singular']; }
function get_queried_object_id(): int { return (int) $GLOBALS['aksrt_test_state']['current_id']; }
function get_post($post = null) {
if ($post instanceof WP_Post) return $post;
return $GLOBALS['aksrt_test_state']['current_post'];
}
function aksrt_get_widget_null(string $message): string { return '<div class="aksrt-widget__empty" role="status">' . esc_html($message) . '</div>'; }
function aksrt_get_pay_meta($post = null): array { unset($post); return $GLOBALS['aksrt_test_state']['pay_meta']; }
function aksrt_has_paid_access($post = null): bool { unset($post); return (bool) $GLOBALS['aksrt_test_state']['paid_access']; }
function aksrt_get_paywall_html(WP_Post $post, array|bool $options = false): string {
unset($post, $options);
$meta = $GLOBALS['aksrt_test_state']['pay_meta'];
if ((string) ($meta['pay_type'] ?? 'no') === 'no') {
return '';
}
if ((bool) $GLOBALS['aksrt_test_state']['paid_access']) {
return '<div data-test-paywall="unlocked">内容已解锁</div>';
}
$state = $GLOBALS['aksrt_test_state']['logged_in'] ? 'member-locked' : 'guest-locked';
return '<div data-test-paywall="' . $state . '">PAYWALL</div>';
}
function aksrt_get_pay_attributes_html($post, string $class): string { unset($post); return '<ul class="' . esc_attr($class) . '"></ul>'; }
function aksrt_get_demo_link_html($post, string $class): string { unset($post); return '<a class="' . esc_attr($class) . '">DEMO</a>'; }
function is_user_logged_in(): bool { return (bool) $GLOBALS['aksrt_test_state']['logged_in']; }
function wp_parse_args($args, array $defaults = []): array {
return array_merge($defaults, is_array($args) ? $args : []);
}
function wp_is_mobile(): bool { return false; }
function wp_strip_all_tags(string $value): string { return trim(strip_tags($value)); }
function wp_kses(string $value, array $allowed_html = [], array $allowed_protocols = []): string {
unset($allowed_html, $allowed_protocols);
// 桩环境信任来源:生产侧的 wp_kses 白名单允许 div/badge 等组合卡标记。
return (string) $value;
}
function aksrt_is_lazy(string $key, bool $default = false): bool { unset($key, $default); return true; }
function aksrt_get_lazy_thumb(string $size = ''): string {
return 'https://example.test/thumbnail' . ($size !== '' ? '-' . sanitize_key($size) : '') . '.svg';
}
function aksrt_get_lazy_attr(string $key, string $src, string $class = '', string $lazy_src = ''): string {
unset($key);
$class = trim($class);
if ($src === '') {
return ' class="' . esc_attr($class) . '" src=""';
}
$lazy_src = $lazy_src !== '' ? $lazy_src : aksrt_get_lazy_thumb();
return ' class="lazyload ' . esc_attr($class) . '" src="' . esc_url($lazy_src) . '" data-src="' . esc_url($src) . '"';
}
require dirname(__DIR__, 2) . '/inc/helpers/aksrt-icons.php';
require dirname(__DIR__, 2) . '/inc/helpers/aksrt-graphic-card.php';
require dirname(__DIR__, 2) . '/vendor/autoload.php';
@@ -184,7 +184,8 @@ test('list, card, media, badge and Mini DOM follow dedicated legacy structures',
assert.ok(commentMeta >= 0 && commentMeta < viewMeta && viewMeta < likeMeta); assert.ok(commentMeta >= 0 && commentMeta < viewMeta && viewMeta < likeMeta);
assert.match(data, /comments_open.*close_comments/s); assert.match(data, /comments_open.*close_comments/s);
assert.match(data, /show_like.*post_type.*=== 'post'/s); assert.match(data, /show_like.*post_type.*=== 'post'/s);
assert.match(data, /<use xlink:href="#icon-/); // The <use> sprite markup lives in the unified helper aksrt_renderer_svg_icon delegates to.
assert.match(read('inc/helpers/aksrt-icons.php'), /<use xlink:href="#icon-/);
}); });
test('post-card CSS owns the exact desktop and 767/640 responsive matrix', () => { test('post-card CSS owns the exact desktop and 767/640 responsive matrix', () => {
@@ -85,7 +85,9 @@ test('vertical notice supports only custom and article sources with Zibll swiper
assert.doesNotMatch(renderer, /aksrt-widget-notice/); assert.doesNotMatch(renderer, /aksrt-widget-notice/);
assert.match(schema, /'id' => 'title'[^\n]+allow_html/); assert.match(schema, /'id' => 'title'[^\n]+allow_html/);
assert.match(renderer, /wp_html_excerpt\([^\n]+160, '\.\.\.'/); assert.match(renderer, /wp_html_excerpt\([^\n]+160, '\.\.\.'/);
assert.match(renderer, /str_starts_with\(\$icon, 'customsvg-'\)/); // Icon value rendering lives in the unified helper the renderer delegates to.
assert.match(renderer, /aksrt_icon_markup\(\$icon\)/);
assert.match(read('inc/helpers/aksrt-icons.php'), /str_starts_with\(\$value, 'customsvg-'\)/);
assert.match(css, /\.swiper-bulletin \.new-swiper\s*\{[^}]*height:\s*2\.4em/s); assert.match(css, /\.swiper-bulletin \.new-swiper\s*\{[^}]*height:\s*2\.4em/s);
assert.match(css, /\.swiper-bulletin \.new-swiper\s*\{[^}]*line-height:\s*2\.4em/s); assert.match(css, /\.swiper-bulletin \.new-swiper\s*\{[^}]*line-height:\s*2\.4em/s);
assert.match(css, /\.bulletin-icon\s*\{[^}]*width:\s*26px[^}]*height:\s*26px[^}]*font-size:\s*18px/s); assert.match(css, /\.bulletin-icon\s*\{[^}]*width:\s*26px[^}]*height:\s*26px[^}]*font-size:\s*18px/s);