Tab 重命名: - dashboard → analytics(ID + 标签"数据分析") - "模块" → "模块管理"(导航标签统一) Tab 重排序(功能 → 监控 → 设置): 概览 → 文本服务 → 图像服务 → 智能路由 → 数据分析 → 预算管理 → GEO 优化 → 模块管理 CSS 变量修复: - 添加缺失的 --wpmind-space-7: 28px - 移除 overview.css 中的 fallback 值 涉及文件: settings-page.php, admin-boot.js, admin-analytics.js, AnalyticsModule.php, module.json, admin.css, overview.css Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
201 lines
4.3 KiB
PHP
201 lines
4.3 KiB
PHP
<?php
|
|
/**
|
|
* Analytics Module - 分析面板模块
|
|
*
|
|
* @package WPMind\Modules\Analytics
|
|
* @since 3.3.0
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace WPMind\Modules\Analytics;
|
|
|
|
use WPMind\Core\ModuleInterface;
|
|
|
|
class AnalyticsModule implements ModuleInterface
|
|
{
|
|
/**
|
|
* 模块配置
|
|
*/
|
|
private array $config = [];
|
|
|
|
/**
|
|
* 构造函数
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$config_file = __DIR__ . '/module.json';
|
|
if (file_exists($config_file)) {
|
|
$this->config = json_decode(file_get_contents($config_file), true) ?: [];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取模块 ID
|
|
*/
|
|
public function get_id(): string
|
|
{
|
|
return 'analytics';
|
|
}
|
|
|
|
/**
|
|
* 获取模块名称
|
|
*/
|
|
public function get_name(): string
|
|
{
|
|
return $this->config['name'] ?? 'Analytics';
|
|
}
|
|
|
|
/**
|
|
* 获取模块描述
|
|
*/
|
|
public function get_description(): string
|
|
{
|
|
return $this->config['description'] ?? '分析仪表板';
|
|
}
|
|
|
|
/**
|
|
* 获取模块版本
|
|
*/
|
|
public function get_version(): string
|
|
{
|
|
return $this->config['version'] ?? '1.0.0';
|
|
}
|
|
|
|
/**
|
|
* 获取模块依赖
|
|
*/
|
|
public function get_dependencies(): array
|
|
{
|
|
return $this->config['requires'] ?? [];
|
|
}
|
|
|
|
/**
|
|
* 检查模块依赖是否满足
|
|
*/
|
|
public function check_dependencies(): bool
|
|
{
|
|
$requires = $this->get_dependencies();
|
|
|
|
if (empty($requires)) {
|
|
return true;
|
|
}
|
|
|
|
$module_loader = \WPMind\Core\ModuleLoader::instance();
|
|
|
|
foreach ($requires as $required_module) {
|
|
if (!$module_loader->is_module_enabled($required_module)) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 获取设置标签页
|
|
*/
|
|
public function get_settings_tab(): ?string
|
|
{
|
|
return $this->config['settings_tab'] ?? 'analytics';
|
|
}
|
|
|
|
/**
|
|
* 初始化模块
|
|
*/
|
|
public function init(): void
|
|
{
|
|
// 加载模块类
|
|
$this->load_classes();
|
|
|
|
// 注册设置标签页
|
|
add_filter('wpmind_settings_tabs', [$this, 'register_settings_tab'], 10);
|
|
|
|
// 注册 AJAX 处理器
|
|
add_action('wp_ajax_wpmind_get_analytics', [$this, 'ajax_get_analytics']);
|
|
|
|
// 注册资源加载
|
|
add_action('admin_enqueue_scripts', [$this, 'enqueue_assets']);
|
|
}
|
|
|
|
/**
|
|
* 加载模块类
|
|
*/
|
|
private function load_classes(): void
|
|
{
|
|
require_once __DIR__ . '/includes/AnalyticsManager.php';
|
|
}
|
|
|
|
/**
|
|
* 注册设置标签页
|
|
*/
|
|
public function register_settings_tab(array $tabs): array
|
|
{
|
|
$tab_config = $this->config['settings_tab'] ?? [];
|
|
|
|
$tabs['analytics'] = [
|
|
'label' => $tab_config['label'] ?? __('数据分析', 'wpmind'),
|
|
'icon' => $tab_config['icon'] ?? 'dashicons-chart-area',
|
|
'priority' => $tab_config['priority'] ?? 10,
|
|
'template' => __DIR__ . '/templates/dashboard.php',
|
|
];
|
|
|
|
return $tabs;
|
|
}
|
|
|
|
/**
|
|
* AJAX: 获取分析数据
|
|
*/
|
|
public function ajax_get_analytics(): void
|
|
{
|
|
check_ajax_referer('wpmind_ajax', 'nonce');
|
|
|
|
if (!current_user_can('manage_options')) {
|
|
wp_send_json_error(['message' => __('权限不足', 'wpmind')]);
|
|
}
|
|
|
|
$range = isset($_POST['range']) ? sanitize_text_field($_POST['range']) : '7d';
|
|
|
|
$analytics = AnalyticsManager::instance();
|
|
$data = $analytics->get_analytics_data($range);
|
|
|
|
wp_send_json_success($data);
|
|
}
|
|
|
|
/**
|
|
* 加载模块资源
|
|
*/
|
|
public function enqueue_assets(string $hook): void
|
|
{
|
|
// 只在 WPMind 设置页面加载
|
|
if (strpos($hook, 'wpmind') === false) {
|
|
return;
|
|
}
|
|
|
|
// Chart.js 已在主插件加载,这里只需确保依赖
|
|
}
|
|
|
|
/**
|
|
* 激活模块
|
|
*/
|
|
public function activate(): void
|
|
{
|
|
// 模块激活时的初始化操作
|
|
}
|
|
|
|
/**
|
|
* 停用模块
|
|
*/
|
|
public function deactivate(): void
|
|
{
|
|
// 模块停用时的清理操作
|
|
}
|
|
|
|
/**
|
|
* 卸载模块
|
|
*/
|
|
public function uninstall(): void
|
|
{
|
|
// 模块卸载时删除数据(可选)
|
|
}
|
|
}
|