Files
wordpress-theme-aksrt/src/WidgetSystem/AdminFormController.php
T
kate522andClaude Opus 5 35bb96e82f refactor: rename the theme brand and every identifier from AKSRT to Jio
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>
2026-11-01 20:05:04 +08:00

113 lines
6.0 KiB
PHP

<?php
namespace Jio\WidgetSystem;
defined('ABSPATH') || exit;
/**
* Lazy widget form endpoint and admin-only assets.
*/
final class AdminFormController {
public const AJAX_ACTION = 'jio_widget_form';
private const NONCE_ACTION = 'jio_widget_form';
public static function register_hooks(): void {
add_action('wp_ajax_' . self::AJAX_ACTION, [self::class, 'ajax_form']);
add_action('admin_enqueue_scripts', [self::class, 'enqueue']);
add_action('customize_controls_enqueue_scripts', [self::class, 'enqueue']);
}
public static function enqueue(): void {
$screen = function_exists('get_current_screen') ? get_current_screen() : null;
$is_customizer = current_filter() === 'customize_controls_enqueue_scripts';
if (!$is_customizer && (!$screen || !in_array($screen->id, ['widgets', 'customize'], true))) {
return;
}
wp_enqueue_media();
wp_enqueue_style('wp-color-picker');
wp_enqueue_script('jquery-ui-sortable');
wp_enqueue_style('jio-widget-admin', JIO_URI . '/assets/widgets/admin.css', ['wp-color-picker'], JIO_VERSION);
wp_enqueue_style('jio-widget-preview', JIO_URI . '/assets/widgets/frontend.css', [], JIO_VERSION);
jio_icon_picker_assets(['wp-color-picker']);
wp_enqueue_script('jio-widget-admin-core', JIO_URI . '/assets/widgets/admin-core.js', [], JIO_VERSION, true);
wp_enqueue_script('jio-widget-admin', JIO_URI . '/assets/widgets/admin.js', ['jquery', 'jquery-ui-sortable', 'wp-color-picker', 'jio-widget-admin-core'], JIO_VERSION, true);
wp_enqueue_script('jio-widget-admin-transfer', JIO_URI . '/assets/widgets/admin-transfer.js', ['jquery', 'jio-widget-admin'], JIO_VERSION, true);
wp_localize_script('jio-widget-admin', 'jioWidgetAdmin', [
'ajaxUrl' => admin_url('admin-ajax.php'),
'action' => self::AJAX_ACTION,
'nonce' => wp_create_nonce(self::NONCE_ACTION),
'transferNonce' => wp_create_nonce(TransferController::NONCE),
'i18n' => self::i18n(),
]);
}
/** @return array<string,string> */
private static function i18n(): array {
return [
'loading' => __('正在加载模块配置…', 'jio'),
'error' => __('加载失败,请刷新页面后重试', 'jio'),
'confirmImportReplace' => __('将覆盖当前容器中已有的全部模块,导入内容将替换该侧栏;确定继续?', 'jio'),
'confirmImportAppend' => __('将在当前容器已有模块列表末尾追加导入内容,不会删除原有模块;确定继续?', 'jio'),
'importModeLabel' => __('导入方式', 'jio'),
'importModeReplace' => __('覆盖(替换现有)', 'jio'),
'importModeAppend' => __('追加(保留现有)', 'jio'),
'loadingExport' => __('正在生成 JSON…', 'jio'),
'loadingImport' => __('正在导入…', 'jio'),
'copyDone' => __('已复制', 'jio'),
'copyFail' => __('复制失败,请手动全选复制', 'jio'),
'exportTitle' => __('导出 JSON(可复制)', 'jio'),
'importTitle' => __('导入 JSON(粘贴后确认)', 'jio'),
'importHint' => __('将导出得到的 JSON 粘贴到下方文本框以导入。注意:不同主题版本或非同站的的模块导入后可能会出现错误,此时可以重新配置一下有错误的模块,即可恢复正常', 'jio'),
'exportHint' => __('以下为当前容器模块数据,可直接全选复制保存。', 'jio'),
'close' => __('关闭', 'jio'),
'copy' => __('复制全部', 'jio'),
'submitImport' => __('确认导入', 'jio'),
'reloadPage' => __('刷新页面', 'jio'),
'templateModalTitle' => __('从模板导入', 'jio'),
'templateHint' => __('使用模板可快速配置网站布局,选择对应的模板点击导入即可。', 'jio') . '<div class="jio-wie-remind"><b>' . __('注意事项:', 'jio') . '</b>' . __('1.导入模板必须对容器位置对应,例如不能将侧边栏模板导入到全宽度中!', 'jio') . '<br>' . __('2.导入模板需已经有对应的内容,例如:导入文章相关的模板,那么至少已经有多篇文章和文章分类', 'jio') . '</div>',
'templateLoadingList' => __('正在加载模板列表…', 'jio'),
'templateEmpty' => __('暂无可用模板。', 'jio'),
'templateSubmit' => __('导入所选模板', 'jio'),
'confirmTemplate' => __('确定导入模板「{title}」吗?导入方式:{mode}', 'jio'),
'templatePick' => __('请选择一个模板。', 'jio'),
'exportFailed' => __('导出失败', 'jio'),
'importSuccess' => __('导入成功', 'jio'),
'importFailed' => __('导入失败', 'jio'),
'pasteJsonFirst' => __('请先粘贴 JSON', 'jio'),
'exportModules' => __('导出模块', 'jio'),
'importModules' => __('导入模块', 'jio'),
'importTemplate' => __('模板导入', 'jio'),
'removeModule' => __('移出模块', 'jio'),
'networkError' => __('网络错误,请刷新页面后重试', 'jio'),
];
}
public static function ajax_form(): void {
check_ajax_referer(self::NONCE_ACTION, 'nonce');
if (!current_user_can('edit_theme_options')) {
wp_send_json_error(['message' => __('权限不足。', 'jio')], 403);
}
$id_base = isset($_POST['id_base']) ? sanitize_key(wp_unslash($_POST['id_base'])) : '';
$number = isset($_POST['widget_number']) ? absint($_POST['widget_number']) : 0;
$definition = WidgetRegistry::get_by_id_base($id_base);
if (!$definition || $number < 1) {
wp_send_json_error(['message' => __('无效的小工具实例。', 'jio')], 400);
}
$widget = new SchemaWidget($definition);
$widget->_set($number);
$settings = $widget->get_settings();
$instance = isset($settings[$number]) && is_array($settings[$number]) ? $settings[$number] : [];
$instance = apply_filters('widget_form_callback', $instance, $widget);
if (!is_array($instance)) {
$instance = [];
}
ob_start();
$widget->render_full_form($instance);
$html = (string) ob_get_clean();
wp_send_json_success(['html' => $html]);
}
}