wpbridge/templates/admin/partials/defaults-config.php
feibisi 76c0053f71 feat: 实现方案 B 管理界面和 FAIR 协议支持
任务 #43 - 重构管理界面为项目优先:
- 新增"项目"Tab,显示已安装插件/主题列表
- 子 Tab 结构:插件 / 主题 / 默认规则
- 支持为每个项目配置更新源(默认/禁用/自定义)
- 支持批量操作(设置源/重置/禁用)
- 支持搜索过滤
- 默认规则配置界面(全局/插件/主题)

任务 #44 - 添加 FAIR 源类型支持:
- 新增 FairProtocol 类:DID 解析、ED25519 签名验证
- 新增 FairSourceAdapter 类:FAIR 源更新检查和下载
- 支持 did:fair: 格式的 DID 标识符
- 支持 sodium 扩展和 paragonie/sodium_compat 回退
- 包签名验证和文件哈希校验

新增文件:
- includes/FAIR/FairProtocol.php
- includes/FAIR/FairSourceAdapter.php
- templates/admin/tabs/projects.php
- templates/admin/partials/project-list-plugins.php
- templates/admin/partials/project-list-themes.php
- templates/admin/partials/defaults-config.php

修改文件:
- includes/Admin/AdminPage.php - 添加项目配置 AJAX 处理
- templates/admin/main.php - 添加"项目"Tab
- assets/css/admin.css - 项目列表样式
- assets/js/admin.js - 项目管理 JavaScript

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 23:38:32 +08:00

138 lines
7.7 KiB
PHP

<?php
/**
* 默认规则配置部分模板
*
* @package WPBridge
* @since 0.6.0
* @var array $all_sources 所有可用源
* @var SourceRegistry $source_registry 源注册表
* @var DefaultsManager $defaults_manager 默认规则管理器
*/
// 防止直接访问
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use WPBridge\Core\DefaultsManager;
// 获取当前默认规则
$defaults = $defaults_manager->get_all();
$global_sources = $defaults['global']['source_order'] ?? [];
$plugin_sources = $defaults['plugin']['source_order'] ?? [];
$theme_sources = $defaults['theme']['source_order'] ?? [];
?>
<div class="wpbridge-defaults-config">
<div class="wpbridge-section">
<h3 class="wpbridge-section-title">
<span class="dashicons dashicons-admin-settings"></span>
<?php esc_html_e( '默认更新源配置', 'wpbridge' ); ?>
</h3>
<p class="wpbridge-section-desc">
<?php esc_html_e( '配置插件和主题的默认更新源顺序。当项目未单独配置时,将按此顺序查找更新。', 'wpbridge' ); ?>
</p>
</div>
<form method="post" id="wpbridge-defaults-form">
<?php wp_nonce_field( 'wpbridge_action', 'wpbridge_nonce' ); ?>
<input type="hidden" name="wpbridge_action" value="save_defaults">
<!-- 全局默认 -->
<div class="wpbridge-config-card">
<div class="wpbridge-config-card-header">
<h4><?php esc_html_e( '全局默认', 'wpbridge' ); ?></h4>
<span class="wpbridge-config-card-desc"><?php esc_html_e( '适用于所有未单独配置的项目', 'wpbridge' ); ?></span>
</div>
<div class="wpbridge-config-card-body">
<div class="wpbridge-source-order" id="wpbridge-global-sources" data-scope="global">
<?php foreach ( $all_sources as $source ) :
$priority = $global_sources[ $source['source_key'] ] ?? $source['default_priority'];
?>
<div class="wpbridge-source-order-item" data-source-key="<?php echo esc_attr( $source['source_key'] ); ?>">
<span class="wpbridge-drag-handle dashicons dashicons-menu"></span>
<span class="wpbridge-source-order-name"><?php echo esc_html( $source['name'] ); ?></span>
<span class="wpbridge-source-order-type wpbridge-badge"><?php echo esc_html( $source['type'] ); ?></span>
<label class="wpbridge-toggle wpbridge-toggle-sm">
<input type="checkbox" name="global_sources[<?php echo esc_attr( $source['source_key'] ); ?>]"
value="1" <?php checked( isset( $global_sources[ $source['source_key'] ] ) || empty( $global_sources ) ); ?>>
<span class="wpbridge-toggle-track"></span>
</label>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
<!-- 插件默认 -->
<div class="wpbridge-config-card">
<div class="wpbridge-config-card-header">
<h4><?php esc_html_e( '插件默认', 'wpbridge' ); ?></h4>
<span class="wpbridge-config-card-desc"><?php esc_html_e( '覆盖全局默认,仅适用于插件', 'wpbridge' ); ?></span>
</div>
<div class="wpbridge-config-card-body">
<label class="wpbridge-checkbox">
<input type="checkbox" name="plugin_override" id="plugin_override"
<?php checked( ! empty( $plugin_sources ) ); ?>>
<span><?php esc_html_e( '为插件使用单独的默认源配置', 'wpbridge' ); ?></span>
</label>
<div class="wpbridge-source-order wpbridge-source-order-override" id="wpbridge-plugin-sources" data-scope="plugin"
style="<?php echo empty( $plugin_sources ) ? 'display:none;' : ''; ?>">
<?php foreach ( $all_sources as $source ) :
$priority = $plugin_sources[ $source['source_key'] ] ?? $source['default_priority'];
?>
<div class="wpbridge-source-order-item" data-source-key="<?php echo esc_attr( $source['source_key'] ); ?>">
<span class="wpbridge-drag-handle dashicons dashicons-menu"></span>
<span class="wpbridge-source-order-name"><?php echo esc_html( $source['name'] ); ?></span>
<span class="wpbridge-source-order-type wpbridge-badge"><?php echo esc_html( $source['type'] ); ?></span>
<label class="wpbridge-toggle wpbridge-toggle-sm">
<input type="checkbox" name="plugin_sources[<?php echo esc_attr( $source['source_key'] ); ?>]"
value="1" <?php checked( isset( $plugin_sources[ $source['source_key'] ] ) ); ?>>
<span class="wpbridge-toggle-track"></span>
</label>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
<!-- 主题默认 -->
<div class="wpbridge-config-card">
<div class="wpbridge-config-card-header">
<h4><?php esc_html_e( '主题默认', 'wpbridge' ); ?></h4>
<span class="wpbridge-config-card-desc"><?php esc_html_e( '覆盖全局默认,仅适用于主题', 'wpbridge' ); ?></span>
</div>
<div class="wpbridge-config-card-body">
<label class="wpbridge-checkbox">
<input type="checkbox" name="theme_override" id="theme_override"
<?php checked( ! empty( $theme_sources ) ); ?>>
<span><?php esc_html_e( '为主题使用单独的默认源配置', 'wpbridge' ); ?></span>
</label>
<div class="wpbridge-source-order wpbridge-source-order-override" id="wpbridge-theme-sources" data-scope="theme"
style="<?php echo empty( $theme_sources ) ? 'display:none;' : ''; ?>">
<?php foreach ( $all_sources as $source ) :
$priority = $theme_sources[ $source['source_key'] ] ?? $source['default_priority'];
?>
<div class="wpbridge-source-order-item" data-source-key="<?php echo esc_attr( $source['source_key'] ); ?>">
<span class="wpbridge-drag-handle dashicons dashicons-menu"></span>
<span class="wpbridge-source-order-name"><?php echo esc_html( $source['name'] ); ?></span>
<span class="wpbridge-source-order-type wpbridge-badge"><?php echo esc_html( $source['type'] ); ?></span>
<label class="wpbridge-toggle wpbridge-toggle-sm">
<input type="checkbox" name="theme_sources[<?php echo esc_attr( $source['source_key'] ); ?>]"
value="1" <?php checked( isset( $theme_sources[ $source['source_key'] ] ) ); ?>>
<span class="wpbridge-toggle-track"></span>
</label>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
<div class="wpbridge-form-actions">
<button type="submit" class="wpbridge-btn wpbridge-btn-primary">
<span class="dashicons dashicons-saved"></span>
<?php esc_html_e( '保存默认规则', 'wpbridge' ); ?>
</button>
</div>
</form>
</div>