Full-project rename. `git grep -i aksrt` is now empty apart from the
DBMigrator 3.3.0 changelog note that documents the rename itself.
Code identifiers
- PHP namespace AKSRT\ -> Jio\ (composer PSR-4 + 378 declarations)
- global constants AKSRT_* -> JIO_* (VERSION/DIR/URI, PAY_TYPE_*, CAPTCHA_*)
- procedural functions, hooks, options, meta keys, table names,
cookies, query vars, ajax actions and nonces: aksrt_ -> jio_
- text domain aksrt -> jio; Theme Name -> Jio
- JS globals: aksrtData/aksrtAdminData/... -> jioData/jioAdminData/...,
window.AKSRTCaptcha & friends -> window.JioCaptcha, Aksrt* -> Jio*
- Vue components Aks*.vue -> Jio*.vue (15 files renamed + imports)
- CSS classes/data-attrs/custom properties: aksrt- -> jio-
- REST namespace aksrt/v1 -> jio/v1 (incl. payment gateway callbacks)
Storage layer
- DB tables {prefix}aksrt_* -> {prefix}jio_*; SCHEMA_VERSION 3.2.0 -> 3.3.0
so dbDelta creates the new names on install
- widget id_base aksrt_widget_* -> jio_widget_*
- uninstall.php drop list rebuilt from the actual migrator tables
(dropped 3 stale entries, added the 17 missing ones)
Removed
- hardcoded https://api.aksrt.com/version.json default update endpoint;
get_endpoint() now reads the 「更新端点」 setting and do_check() no-ops
when it is empty
Files renamed: inc/helpers/aksrt-*.php -> jio-*.php (54),
assets/admin/src/components/form/Aks*.vue -> Jio*.vue (15).
Build artifacts regenerated: assets/css/build, assets/js/runtime,
assets/admin/build.
Verified: audit-psr4-paths errors=0, audit-admin-contracts errors=0
(warnings=56, unchanged baseline), 813/813 widget-system tests,
44/44 phpunit, php -l clean across all PHP.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
124 lines
5.0 KiB
PHP
124 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace Jio\WidgetSystem;
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
/** Admin AJAX endpoints for per-sidebar export, JSON import and template import. */
|
|
final class TransferController {
|
|
public const NONCE = 'jio_widgets_transfer';
|
|
|
|
public static function register_hooks(): void {
|
|
add_action('wp_ajax_jio_widgets_export_sidebar', [self::class, 'ajax_export']);
|
|
add_action('wp_ajax_jio_widgets_import_sidebar', [self::class, 'ajax_import']);
|
|
add_action('wp_ajax_jio_widgets_list_templates', [self::class, 'ajax_list_templates']);
|
|
add_action('wp_ajax_jio_widgets_import_template', [self::class, 'ajax_import_template']);
|
|
}
|
|
|
|
public static function ajax_export(): void {
|
|
self::authorize();
|
|
$sidebar = self::target_sidebar();
|
|
$json = wp_json_encode(WidgetTransfer::export($sidebar), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
wp_send_json_success(['json_text' => (string) $json, 'sidebar_id' => $sidebar]);
|
|
}
|
|
|
|
public static function ajax_import(): void {
|
|
self::authorize();
|
|
$sidebar = self::target_sidebar();
|
|
$raw = isset($_POST['json']) ? trim((string) wp_unslash($_POST['json'])) : '';
|
|
if ($raw === '') {
|
|
wp_send_json_error(['message' => __('请粘贴 JSON 内容。', 'jio')]);
|
|
}
|
|
if (strlen($raw) > 2 * MB_IN_BYTES) {
|
|
wp_send_json_error(['message' => __('JSON 内容超过 2MB。', 'jio')]);
|
|
}
|
|
$payload = json_decode($raw, true);
|
|
if (!is_array($payload)) {
|
|
wp_send_json_error(['message' => __('JSON 解析失败,请检查格式。', 'jio')]);
|
|
}
|
|
$mode = self::import_mode();
|
|
$result = self::run_import($payload, $sidebar, $mode);
|
|
$message = $mode === 'append'
|
|
/* translators: 1: sidebar name, 2: imported widget count */
|
|
? __('已向侧栏「%1$s」末尾追加 %2$d 个小工具。请刷新页面后查看效果。', 'jio')
|
|
/* translators: 1: sidebar name, 2: imported widget count */
|
|
: __('已覆盖侧栏「%1$s」并导入 %2$d 个小工具。请刷新页面后查看效果。', 'jio');
|
|
self::send_result($sidebar, $mode, $result, $message);
|
|
}
|
|
|
|
public static function ajax_list_templates(): void {
|
|
self::authorize();
|
|
$list = [];
|
|
foreach (WidgetTransfer::templates() as $id => $template) {
|
|
$list[] = [
|
|
'id' => (string) $id,
|
|
'title' => (string) $template['title'],
|
|
'desc' => (string) ($template['desc'] ?? ''),
|
|
'remind' => (string) ($template['remind'] ?? ''),
|
|
'modules' => WidgetTransfer::template_modules((string) $id),
|
|
];
|
|
}
|
|
wp_send_json_success(['templates' => $list]);
|
|
}
|
|
|
|
public static function ajax_import_template(): void {
|
|
self::authorize();
|
|
$sidebar = self::target_sidebar();
|
|
$template = isset($_POST['template_id']) ? sanitize_key(wp_unslash($_POST['template_id'])) : '';
|
|
try {
|
|
$payload = WidgetTransfer::template_payload($template);
|
|
} catch (\InvalidArgumentException $error) {
|
|
wp_send_json_error(['message' => $error->getMessage()]);
|
|
}
|
|
$mode = self::import_mode();
|
|
$result = self::run_import($payload, $sidebar, $mode);
|
|
$message = $mode === 'append'
|
|
/* translators: 1: sidebar name, 2: imported widget count */
|
|
? __('已从模板向侧栏「%1$s」末尾追加 %2$d 个小工具。请刷新页面后查看效果。', 'jio')
|
|
/* translators: 1: sidebar name, 2: imported widget count */
|
|
: __('已用模板覆盖侧栏「%1$s」并导入 %2$d 个小工具。请刷新页面后查看效果。', 'jio');
|
|
self::send_result($sidebar, $mode, $result, $message, ['template_id' => $template]);
|
|
}
|
|
|
|
private static function authorize(): void {
|
|
check_ajax_referer(self::NONCE, 'nonce');
|
|
if (!current_user_can('edit_theme_options')) {
|
|
wp_send_json_error(['message' => __('权限不足', 'jio')], 403);
|
|
}
|
|
}
|
|
|
|
private static function target_sidebar(): string {
|
|
$sidebar = isset($_POST['sidebar_id']) ? sanitize_key(wp_unslash($_POST['sidebar_id'])) : '';
|
|
if ($sidebar === '' || !isset($GLOBALS['wp_registered_sidebars'][$sidebar])) {
|
|
wp_send_json_error(['message' => __('无效的侧栏。', 'jio')]);
|
|
}
|
|
return $sidebar;
|
|
}
|
|
|
|
private static function import_mode(): string {
|
|
$mode = isset($_POST['import_mode']) ? sanitize_key(wp_unslash($_POST['import_mode'])) : 'append';
|
|
return $mode === 'replace' ? 'replace' : 'append';
|
|
}
|
|
|
|
/** @return array{sidebars:int,widgets:int} */
|
|
private static function run_import(array $payload, string $sidebar, string $mode): array {
|
|
try {
|
|
return WidgetTransfer::import($payload, $mode, $sidebar);
|
|
} catch (\InvalidArgumentException $error) {
|
|
wp_send_json_error(['message' => $error->getMessage()]);
|
|
}
|
|
}
|
|
|
|
/** @param array{sidebars:int,widgets:int} $result */
|
|
private static function send_result(string $sidebar, string $mode, array $result, string $message, array $extra = []): void {
|
|
$name = (string) ($GLOBALS['wp_registered_sidebars'][$sidebar]['name'] ?? $sidebar);
|
|
wp_send_json_success(array_merge([
|
|
'imported' => (int) $result['widgets'],
|
|
'sidebar_id' => $sidebar,
|
|
'import_mode' => $mode,
|
|
'warnings' => [],
|
|
'message' => sprintf($message, $name, (int) $result['widgets']),
|
|
], $extra));
|
|
}
|
|
}
|