Files
wordpress-theme-aksrt/src/Settings/FloatButtons.php
T
kate522andClaude Opus 5 427968a721 chore(branding): remove leftover upstream theme identifiers
The theme was renamed Zibll/子比 → AKSRT → Jio, but upstream branding
survived the sweeps in CSS classes, the SVG sprite prefix, a persisted
widget field ID, JS events, admin Vue class names, test infrastructure
and docblocks.

Renames:
- zib-widget / zib-widget-wrap / zib-slider → jio-widget-box /
  jio-widget-box-wrap / jio-slider-box (jio-widget is taken by the modern
  widget shell, jio-box-* by the card primitives)
- zib-partners-scroll + zps-* → jio-partners-scroll + jps-*
- zib-combo-info-card + zci-* → jio-combo-info-card + jci-*
- zibsvg- → jiosvg-, including the exported picker helpers and the
  fa-zibsvg- family-prefix guard
- zibpay_type → pay_type; the dual-read fallback in PostQuery collapses
  to a single key
- [zibajax="submit"] dropped (no PHP emitter); zib_ajax.success →
  jio_ajax.success
- aks-* admin Vue classes → jio-*
- zib_palette() → palette()

User-facing vendor traces are gone: the floating "more" button default no
longer ships a zibll.com link or 子比主题 marketing copy, the notice
widget ships no preset promo entries, and the four 官网教程 links are
removed from the post-list admin schema.

Test infrastructure renamed to neutral names (docker-compose.reference.yml,
Caddyfile, article-baseline.json, modern-widgets-contract.test.cjs) with
their DB/volume/env/slug identifiers following.

Kept intentionally, documented in tests/fixtures/README.md: the golden
fixture reference fingerprint (a SHA-256 record of an external directory,
read by validate-widget-golden / generate-widget-golden-fixture /
audit-widget-system), the doesNotMatch guards that prove the old tokens are
gone, and the reference theme's own meta key in the visual fixtures.

No backward-compat or data migration: saved widget configs holding old
icon keys or the old field ID silently lose them, per the project's
rewrite-over-compatibility rule.

Verified: 132/132 node contract tests, php tests/widget-system/run.php
(146 assertions), audit-admin-contracts, audit-psr4-paths and
validate-widget-golden all green; tracked bundles regenerated and in sync.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-11-02 00:06:54 +08:00

219 lines
6.7 KiB
PHP

<?php
/**
* 右侧悬浮按钮:唯一的默认值 + 规范化来源(读取与保存共用)。
*
* 结构对齐参考主题 float_btn(sortable,固定类型,数组顺序即显示顺序)。
*
* @package Jio
*/
namespace Jio\Settings;
defined('ABSPATH') || exit;
class FloatButtons {
public const OPTION = 'jio_floating_buttons';
/** 固定按钮类型(默认显示顺序)。 */
public const TYPES = ['more', 'pay_vip', 'add', 'service_qq', 'service_wechat', 'theme_mode', 'qrcode', 'back_top'];
/**
* 默认配置。
*/
public static function defaults(): array {
$empty_color = ['color' => '', 'bg' => ''];
return [
'style' => 'round',
'position' => 'bottom',
'filter_blur' => ['m_s'],
'scroll_hide' => false,
'scroll_down_hide' => true,
'items' => [
[
'type' => 'more',
'buttons' => [self::gift_more_button()],
],
['type' => 'pay_vip', 'pc_s' => true, 'm_s' => true, 'color' => ['color' => '#f2c97d', 'bg' => 'rgba(62,62,67,0.9)']],
['type' => 'add', 'pc_s' => true, 'm_s' => false, 'color' => $empty_color, 'icon' => 'fa fas fa-pencil-alt'],
['type' => 'service_qq', 'pc_s' => false, 'm_s' => false, 'color' => $empty_color, 'qq' => ''],
['type' => 'service_wechat', 'pc_s' => true, 'm_s' => true, 'color' => $empty_color, 'wechat_img' => ''],
['type' => 'theme_mode', 'pc_s' => false, 'm_s' => false, 'color' => $empty_color],
['type' => 'qrcode', 'pc_s' => true, 'm_s' => false, 'color' => $empty_color, 'desc' => __('在手机上浏览此页面', 'jio')],
['type' => 'back_top', 'pc_s' => true, 'm_s' => true, 'color' => $empty_color],
],
];
}
/**
* 「更多按钮」出厂默认项。
*
* 不预设任何第三方指向:悬浮按钮是站点自身的界面,出厂值只给一个图标按钮,
* 链接与悬浮面板由站点自行配置。
*/
public static function gift_more_button(): array {
return [
'desc' => '',
'icon' => 'jiosvg-gift-color',
'link' => ['url' => '', 'target' => ''],
'hover' => '',
'hover_width' => 200,
'pc_s' => true,
'm_s' => true,
'color' => ['color' => '', 'bg' => 'rgba(255, 111, 6, 0.2)'],
];
}
/**
* 「添加按钮」新增项默认值(参考主题 group 字段默认值)。
*/
public static function new_more_button(): array {
return [
'desc' => '',
'icon' => 'fa fas fa-heart',
'link' => ['url' => '', 'target' => ''],
'hover' => '',
'hover_width' => 200,
'pc_s' => true,
'm_s' => true,
'color' => ['color' => '', 'bg' => ''],
];
}
/**
* 读取已规范化的配置。
*/
public static function get(): array {
$saved = get_option(self::OPTION, []);
if (!is_array($saved) || $saved === []) {
return self::defaults();
}
return self::sanitize($saved);
}
/**
* 规范化完整配置(REST 保存与读取共用)。
*/
public static function sanitize(array $raw): array {
$defaults = self::defaults();
$filter_blur = [];
foreach ((array) ($raw['filter_blur'] ?? []) as $device) {
$device = (string) $device;
if (in_array($device, ['pc_s', 'm_s'], true) && !in_array($device, $filter_blur, true)) {
$filter_blur[] = $device;
}
}
return [
'style' => in_array($raw['style'] ?? '', ['round', 'square'], true) ? $raw['style'] : 'round',
'position' => in_array($raw['position'] ?? '', ['bottom', 'center'], true) ? $raw['position'] : 'bottom',
'filter_blur' => $filter_blur,
'scroll_hide' => !empty($raw['scroll_hide']),
'scroll_down_hide' => !empty($raw['scroll_down_hide']),
'items' => self::sanitize_items((array) ($raw['items'] ?? []), $defaults['items']),
];
}
/**
* 按提交顺序保留已知类型,重复丢弃,缺失类型用默认值补到末尾。
*/
private static function sanitize_items(array $raw_items, array $default_items): array {
$default_map = [];
foreach ($default_items as $item) {
$default_map[$item['type']] = $item;
}
$out = [];
$seen = [];
foreach ($raw_items as $item) {
if (!is_array($item)) {
continue;
}
$type = (string) ($item['type'] ?? '');
if (!isset($default_map[$type]) || isset($seen[$type])) {
continue;
}
$seen[$type] = true;
$out[] = self::sanitize_item($type, $item, $default_map[$type]);
}
foreach ($default_items as $item) {
if (!isset($seen[$item['type']])) {
$out[] = $item;
}
}
return $out;
}
private static function sanitize_item(string $type, array $item, array $default): array {
if ($type === 'more') {
$buttons = [];
foreach ((array) ($item['buttons'] ?? []) as $button) {
if (is_array($button)) {
$buttons[] = self::sanitize_more_button($button);
}
}
// 参考主题:至少保留一个。
if ($buttons === []) {
$buttons[] = self::new_more_button();
}
return ['type' => 'more', 'buttons' => $buttons];
}
$out = [
'type' => $type,
'pc_s' => !empty($item['pc_s']),
'm_s' => !empty($item['m_s']),
'color' => self::sanitize_color_group($item['color'] ?? []),
];
switch ($type) {
case 'add':
$out['icon'] = jio_sanitize_icon_value((string) ($item['icon'] ?? ''));
break;
case 'service_qq':
$out['qq'] = (string) preg_replace('/\D+/', '', (string) ($item['qq'] ?? ''));
break;
case 'service_wechat':
$out['wechat_img'] = esc_url_raw((string) ($item['wechat_img'] ?? ''));
break;
case 'qrcode':
$out['desc'] = sanitize_text_field((string) ($item['desc'] ?? ''));
break;
}
return $out;
}
private static function sanitize_more_button(array $button): array {
$link = is_array($button['link'] ?? null) ? $button['link'] : [];
$target = (string) ($link['target'] ?? '');
return [
'desc' => sanitize_text_field((string) ($button['desc'] ?? '')),
'icon' => jio_sanitize_icon_value((string) ($button['icon'] ?? '')),
'link' => [
'url' => esc_url_raw((string) ($link['url'] ?? '')),
'target' => $target === '_blank' ? '_blank' : '',
],
'hover' => wp_kses_post((string) ($button['hover'] ?? '')),
'hover_width' => max(50, min(500, (int) ($button['hover_width'] ?? 200))),
'pc_s' => !empty($button['pc_s']),
'm_s' => !empty($button['m_s']),
'color' => self::sanitize_color_group($button['color'] ?? []),
];
}
/**
* @param mixed $group
* @return array{color:string,bg:string}
*/
private static function sanitize_color_group($group): array {
$group = is_array($group) ? $group : [];
return [
'color' => \Jio\Core\Color::sanitize($group['color'] ?? '', true),
'bg' => \Jio\Core\Color::sanitize($group['bg'] ?? '', true),
];
}
}