feat: 添加统一 API 系统测试脚本和文档

- 创建 test-unified-api-system.php 测试脚本
- 测试功能包括:函数存在性、数据迁移、API配置、向后兼容等
- 添加阶段性实施计划文档
- 添加新 AI 设置界面草稿
This commit is contained in:
2026-01-26 13:25:49 +08:00
parent 5254ee0d8b
commit 2c25caae23
4 changed files with 852 additions and 0 deletions

View File

@@ -0,0 +1,233 @@
<?php
/**
* 新的 AI 设置页面结构
* 这是一个草稿文件,用于设计新的 AI 设置界面
*/
// 提供商列表
$providers = [
'openai' => 'OpenAI (ChatGPT)',
'anthropic' => 'Anthropic (Claude)',
'deepseek' => 'DeepSeek',
'xiaomi' => __('小米 Mimo', 'argon'),
'qianwen' => __('通义千问', 'argon'),
'wenxin' => __('文心一言', 'argon'),
'doubao' => __('豆包 (火山引擎)', 'argon'),
'kimi' => 'Kimi (Moonshot)',
'zhipu' => __('智谱 AI (GLM)', 'argon'),
'siliconflow' => __('硅基流动 (SiliconFlow)', 'argon')
];
// 获取所有 API
$all_apis = argon_get_all_apis();
$summary_active_api = get_option('argon_ai_summary_active_api', '');
$spam_active_api = get_option('argon_ai_spam_active_api', '');
?>
<!-- ========== AI 功能 ========== -->
<h1 style="color: #5e72e4; margin-top: 50px; font-size: 32px;"><?php _e('AI 功能', 'argon');?></h1>
<p><?php _e('统一管理所有 AI 服务商的 API 配置,并配置 AI 文章摘要和评论审核功能', 'argon');?></p>
<!-- ========== API 管理 ========== -->
<tr><th class="subtitle"><h2 id="ai-api-management"><?php _e('API 管理', 'argon');?></h2></th></tr>
<tr>
<th><label><?php _e('已配置的 API', 'argon');?></label></th>
<td>
<div id="argon-unified-api-list">
<?php if (!empty($all_apis)): ?>
<?php foreach ($all_apis as $api): ?>
<div class="argon-unified-api-item" data-api-id="<?php echo esc_attr($api['id']); ?>" style="padding: 15px; background: #f5f5f5; margin-bottom: 10px; border-radius: 6px; border-left: 4px solid #5e72e4;">
<div style="display: flex; align-items: center; justify-content: space-between;">
<div style="flex: 1;">
<div style="font-size: 16px; font-weight: 600; margin-bottom: 5px;">
<?php echo esc_html($api['name']); ?>
<?php if (!empty($api['model'])): ?>
<span style="color: #666; font-weight: 400; font-size: 14px;">(<?php echo esc_html($api['model']); ?>)</span>
<?php endif; ?>
</div>
<div style="font-size: 13px; color: #666;">
<span style="display: inline-block; padding: 2px 8px; background: #e3f2fd; color: #1976d2; border-radius: 3px; margin-right: 8px;">
<?php echo esc_html($providers[$api['provider']]); ?>
</span>
<?php _e('密钥:', 'argon'); ?> <code><?php echo esc_html(substr($api['api_key'], 0, 12)); ?>...</code>
<?php if (!empty($api['api_endpoint'])): ?>
| <?php _e('端点:', 'argon'); ?> <code><?php echo esc_html($api['api_endpoint']); ?></code>
<?php endif; ?>
</div>
<div style="margin-top: 8px; font-size: 12px; color: #888;">
<?php if ($api['id'] === $summary_active_api): ?>
<span style="display: inline-block; padding: 2px 6px; background: #4caf50; color: #fff; border-radius: 3px; margin-right: 5px;">
<?php _e('文章摘要', 'argon'); ?>
</span>
<?php endif; ?>
<?php if ($api['id'] === $spam_active_api): ?>
<span style="display: inline-block; padding: 2px 6px; background: #ff9800; color: #fff; border-radius: 3px; margin-right: 5px;">
<?php _e('评论审核', 'argon'); ?>
</span>
<?php endif; ?>
</div>
</div>
<div style="display: flex; gap: 5px;">
<button type="button" class="button button-small argon-test-unified-api" data-api-id="<?php echo esc_attr($api['id']); ?>">
<span class="dashicons dashicons-yes-alt" style="margin-top: 3px;"></span>
<?php _e('测试', 'argon'); ?>
</button>
<button type="button" class="button button-small argon-edit-unified-api" data-api-id="<?php echo esc_attr($api['id']); ?>">
<?php _e('编辑', 'argon'); ?>
</button>
<button type="button" class="button button-small argon-delete-unified-api" data-api-id="<?php echo esc_attr($api['id']); ?>" style="color: #b32d2e;">
<?php _e('删除', 'argon'); ?>
</button>
</div>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<p style="color: #666; padding: 20px; background: #f9f9f9; border-radius: 4px; text-align: center;">
<?php _e('暂无配置的 API请点击下方按钮添加', 'argon'); ?>
</p>
<?php endif; ?>
</div>
<button type="button" class="button button-primary" id="argon-add-unified-api-btn" style="margin-top: 15px;">
<span class="dashicons dashicons-plus-alt" style="margin-top: 3px;"></span>
<?php _e('添加新 API', 'argon'); ?>
</button>
<!-- API 配置表单(隐藏) -->
<div id="argon-unified-api-form" style="display:none; margin-top: 20px; padding: 20px; background: #fff; border: 2px solid #5e72e4; border-radius: 6px;">
<h3 style="margin-top: 0;"><?php _e('API 配置', 'argon'); ?></h3>
<input type="hidden" id="argon-unified-api-form-id" value="" />
<p>
<label>
<strong><?php _e('配置名称:', 'argon'); ?></strong> <span style="color: #d32f2f;">*</span><br>
<input type="text" id="argon-unified-api-form-name" class="regular-text" placeholder="<?php _e('例如: 主 OpenAI API', 'argon'); ?>" />
</label>
</p>
<p>
<label>
<strong><?php _e('API 密钥:', 'argon'); ?></strong> <span style="color: #d32f2f;">*</span><br>
<input type="password" id="argon-unified-api-form-key" class="regular-text" placeholder="sk-..." />
<button type="button" class="button" id="argon-toggle-unified-password" style="margin-left: 5px;">
<span class="dashicons dashicons-visibility"></span>
</button>
</label>
</p>
<p>
<label>
<strong><?php _e('提供商:', 'argon'); ?></strong> <span style="color: #d32f2f;">*</span><br>
<select id="argon-unified-api-form-provider" class="regular-text">
<option value=""><?php _e('请选择提供商', 'argon'); ?></option>
<?php foreach ($providers as $key => $name): ?>
<option value="<?php echo esc_attr($key); ?>"><?php echo esc_html($name); ?></option>
<?php endforeach; ?>
</select>
</label>
</p>
<p>
<label>
<strong><?php _e('API 端点:', 'argon'); ?></strong> <small>(<?php _e('可选', 'argon'); ?>)</small><br>
<input type="text" id="argon-unified-api-form-endpoint" class="regular-text" placeholder="<?php _e('留空使用默认端点', 'argon'); ?>" />
</label>
</p>
<p>
<label>
<strong><?php _e('模型:', 'argon'); ?></strong> <small>(<?php _e('可选', 'argon'); ?>)</small><br>
<input type="text" id="argon-unified-api-form-model" class="regular-text" placeholder="<?php _e('留空使用默认模型', 'argon'); ?>" style="width: calc(100% - 120px);" />
<button type="button" class="button" id="argon-refresh-unified-models" style="margin-left: 5px;">
<span class="dashicons dashicons-update"></span> <?php _e('刷新', 'argon'); ?>
</button>
</label>
<div id="argon-unified-models-list" style="display:none; margin-top: 10px; max-height: 200px; overflow-y: auto; border: 1px solid #ddd; padding: 10px; background: #fafafa; border-radius: 4px;">
<p style="margin: 0; color: #666;"><?php _e('加载中...', 'argon'); ?></p>
</div>
</p>
<p>
<button type="button" class="button button-primary" id="argon-save-unified-api">
<?php _e('保存', 'argon'); ?>
</button>
<button type="button" class="button" id="argon-cancel-unified-api">
<?php _e('取消', 'argon'); ?>
</button>
</p>
</div>
<p class="description" style="margin-top: 15px;">
<span class="dashicons dashicons-info" style="color: #2271b1;"></span>
<?php _e('统一管理所有 AI 服务商的 API 配置。不同功能可以使用不同的 API在下方的文章摘要和评论审核设置中选择', 'argon');?>
</p>
</td>
</tr>
<!-- ========== 文章摘要 ========== -->
<tr><th class="subtitle"><h2 id="ai-summary"><?php _e('文章摘要', 'argon');?></h2></th></tr>
<tr>
<th><label><?php _e('启用 AI 摘要', 'argon');?></label></th>
<td>
<select name="argon_ai_summary_enable">
<?php $argon_ai_summary_enable = get_option('argon_ai_summary_enable', 'false'); ?>
<option value="true" <?php if ($argon_ai_summary_enable=='true'){echo 'selected';} ?>><?php _e('启用', 'argon');?></option>
<option value="false" <?php if ($argon_ai_summary_enable=='false'){echo 'selected';} ?>><?php _e('禁用', 'argon');?></option>
</select>
<p class="description"><?php _e('开启后,文章开头会显示 AI 生成的摘要。每篇文章只生成一次,结果会缓存到服务器。', 'argon');?></p>
</td>
</tr>
<tr>
<th><label><?php _e('默认使用 API', 'argon');?></label></th>
<td>
<select name="argon_ai_summary_active_api">
<option value=""><?php _e('请选择 API', 'argon'); ?></option>
<?php foreach ($all_apis as $api): ?>
<option value="<?php echo esc_attr($api['id']); ?>" <?php selected($summary_active_api, $api['id']); ?>>
<?php echo esc_html($api['name']); ?> (<?php echo esc_html($providers[$api['provider']]); ?>)
</option>
<?php endforeach; ?>
</select>
<p class="description"><?php _e('选择用于生成文章摘要的 API 配置', 'argon');?></p>
</td>
</tr>
<!-- 其他文章摘要设置保持不变 -->
<!-- ========== 评论审核 ========== -->
<tr><th class="subtitle"><h2 id="ai-spam-detection"><?php _e('评论审核', 'argon');?></h2></th></tr>
<tr>
<th><label><?php _e('启用 AI 识别', 'argon');?></label></th>
<td>
<?php $argon_comment_spam_detection_enable = get_option('argon_comment_spam_detection_enable', 'false'); ?>
<label>
<input type="checkbox" name="argon_comment_spam_detection_enable" value="true" <?php if ($argon_comment_spam_detection_enable=='true'){echo 'checked';}?>/>
<?php _e('启用 AI 自动识别垃圾评论', 'argon');?>
</label>
<p class="description">
<?php _e('开启后,将使用 AI 自动识别广告、反动、违法等垃圾评论。', 'argon');?>
</p>
</td>
</tr>
<tr>
<th><label><?php _e('默认使用 API', 'argon');?></label></th>
<td>
<select name="argon_ai_spam_active_api">
<option value=""><?php _e('请选择 API', 'argon'); ?></option>
<?php foreach ($all_apis as $api): ?>
<option value="<?php echo esc_attr($api['id']); ?>" <?php selected($spam_active_api, $api['id']); ?>>
<?php echo esc_html($api['name']); ?> (<?php echo esc_html($providers[$api['provider']]); ?>)
</option>
<?php endforeach; ?>
</select>
<p class="description"><?php _e('选择用于垃圾评论检测的 API 配置', 'argon');?></p>
</td>
</tr>
<!-- 其他评论审核设置保持不变 -->