Files
wordpress-theme-aksrt/src/Admin/GlobalControllerPart1.php
T
kate522 6f2adfaef1 feat(float): rebuild right floating buttons 1:1 with reference theme
- Storage: aksrt_floating_buttons now uses reference float_btn shape
  (fixed 8 sortable types, more-buttons group); single source of
  defaults/sanitize in AKSRT\Settings\FloatButtons
- Admin SPA: CSF-parity page split into components/floating/*
- Frontend: aksrt_float_right() on wp_footer mirrors zib_float_right()
  (wp_is_mobile, PC tooltip, toggle-theme, ontop/scrollTopTo, qrcode,
  wechat/qq, pay_vip, add, more)
- CSS: floating-buttons.css rewritten from reference rules; legacy float
  rules removed from main/part/shell/overlay-primitives
- Remove dead code: reorder route/API, get_floating_buttons_items,
  floatingSchema, floatActionsId, float-theme-toggle bindings,
  common/floating.css, aksrt-runtime-win.php, .aksrt-float-btn
2026-09-26 20:44:50 +08:00

110 lines
4.3 KiB
PHP

<?php
/**
* @package AKSRT
*/
namespace AKSRT\Admin;
defined('ABSPATH') || exit;
trait GlobalControllerPart1 {
public function rest_reorder_footer_tabbar(\WP_REST_Request $request): \WP_REST_Response {
$params = $this->get_json_params($request);
$ordered_ids = $params['ids'] ?? [];
if (!is_array($ordered_ids)) {
return new \WP_REST_Response(['code' => 'error', 'message' => __('参数错误', 'aksrt')], 400);
}
if (count($ordered_ids) > 5) {
return new \WP_REST_Response(['code' => 'error', 'message' => __('Footer tabbar supports at most 5 items.', 'aksrt')], 400);
}
$tabbar = get_option('aksrt_footer_tabbar', []);
$items = $tabbar['items'] ?? [];
$order_map = array_flip($ordered_ids);
usort($items, function ($a, $b) use ($order_map) {
$idx_a = $order_map[($a['id'] ?? '')] ?? 999;
$idx_b = $order_map[($b['id'] ?? '')] ?? 999;
return $idx_a <=> $idx_b;
});
foreach ($items as $index => &$item) {
$item['sort_order'] = $index;
}
$tabbar['items'] = $items;
update_option('aksrt_footer_tabbar', $tabbar);
return rest_ensure_response(['code' => 'success', 'message' => __('Order saved.', 'aksrt')]);
}
private function sanitize_tabbar_item(array $item): array {
$valid_types = ['home', 'category', 'link', 'user', 'auth', 'search', 'add'];
$type = sanitize_text_field($item['type'] ?? 'link');
if (!in_array($type, $valid_types, true)) {
$type = 'link';
}
$badge_mode = sanitize_text_field($item['badge_mode'] ?? 'static');
if (!in_array($badge_mode, ['static', 'dynamic'], true)) {
$badge_mode = 'static';
}
$add_items = [];
if (!empty($item['add_items']) && is_array($item['add_items'])) {
foreach ($item['add_items'] as $sub_item) {
$label = sanitize_text_field($sub_item['label'] ?? '');
$icon = aksrt_sanitize_icon_value((string) ($sub_item['icon'] ?? 'fa fas fa-pen'));
$url = esc_url_raw($sub_item['url'] ?? '');
if ($label === '') {
continue;
}
$add_items[] = [
'id' => sanitize_text_field($sub_item['id'] ?? uniqid('add_')),
'label' => $label,
'icon' => $icon,
'url' => $url,
];
}
}
return [
'id' => sanitize_text_field($item['id'] ?? uniqid('tab_')),
'type' => $type,
'icon' => aksrt_sanitize_icon_value((string) ($item['icon'] ?? '')),
'text' => sanitize_text_field($item['text'] ?? ''),
'link' => esc_url_raw($item['link'] ?? ''),
'badge' => sanitize_text_field($item['badge'] ?? ''),
'badge_mode' => $badge_mode,
'category_id' => absint($item['category_id'] ?? 0),
'search_default_type' => (function() use ($item) {
$v = $item['search_default_type'] ?? 'post';
return in_array($v, ['post', 'category', 'tag'], true) ? $v : 'post';
})(),
'new_window' => !empty($item['new_window']),
'add_items' => $add_items,
'enabled' => !empty($item['enabled']),
'sort_order' => (int) ($item['sort_order'] ?? 0),
'ontop' => !empty($item['ontop']),
];
}
public function rest_handle_floating_buttons(\WP_REST_Request $request): \WP_REST_Response {
if ($request->get_method() === 'GET') {
return rest_ensure_response(['code' => 'success', 'data' => \AKSRT\Settings\FloatButtons::get()]);
}
$settings = \AKSRT\Settings\FloatButtons::sanitize($this->get_json_params($request));
update_option(\AKSRT\Settings\FloatButtons::OPTION, $settings);
\AKSRT\Settings\Settings::flush_settings_cache();
return rest_ensure_response([
'code' => 'success',
'message' => __('Floating button settings saved.', 'aksrt'),
'data' => $settings,
]);
}
}