/
www
/
wwwroot
/
fxdst.com
/
wp-content
/
mu-plugins
/
Upload File
HOME
<?php /** * Plugin Name: FXDST AI Rankings * Description: Bilingual, source-attributed AI rankings with cached upstream data. * Version: 1.0.0 */ if (!defined('ABSPATH')) exit; const FXDST_RANKINGS_VERSION = '1.0.7'; const FXDST_RANKINGS_CRON = 'fxdst_rankings_refresh'; function fxdst_rank_categories() { return array( 'github-ai' => array( 'icon' => 'fa-github', 'zh' => 'GitHub项目榜', 'en' => 'GitHub AI', 'title_zh' => 'GitHub AI 开源项目热度榜', 'title_en' => 'GitHub AI Project Momentum', 'desc_zh' => '基于公开仓库的 Stars、近期活跃度与 AI 主题相关性,发现值得持续关注的开源项目。', 'desc_en' => 'Discover active open-source AI projects ranked by public stars, recent activity, and topic relevance.', 'source' => 'GitHub Search API', 'source_url' => 'https://docs.github.com/en/rest/search/search', ), 'openrouter' => array( 'icon' => 'fa-bar-chart', 'zh' => '模型调用榜', 'en' => 'Model Usage', 'title_zh' => 'OpenRouter 模型调用排行榜', 'title_en' => 'OpenRouter Model Usage Ranking', 'desc_zh' => '按 OpenRouter 公开周榜中的模型请求次数汇总,观察真实路由流量中的模型使用趋势。', 'desc_en' => 'Track model usage trends using aggregated request counts from OpenRouter’s public weekly rankings.', 'source' => 'OpenRouter Rankings', 'source_url' => 'https://openrouter.ai/rankings', ), 'opencode' => array( 'icon' => 'fa-terminal', 'zh' => 'OpenCode榜', 'en' => 'OpenCode', 'title_zh' => 'OpenCode 编程模型使用排行榜', 'title_en' => 'OpenCode Coding Model Usage', 'desc_zh' => '汇总 OpenCode 官方数据页的模型使用序列,呈现编程场景中模型的相对使用热度。', 'desc_en' => 'A relative usage ranking derived from the model series published on OpenCode’s official data page.', 'source' => 'OpenCode Data', 'source_url' => 'https://opencode.ai/data/', ), 'agents' => array( 'icon' => 'fa-cogs', 'zh' => 'Agent评测榜', 'en' => 'Agent Benchmarks', 'title_zh' => 'AI 编程 Agent 能力评测榜', 'title_en' => 'AI Coding Agent Benchmark', 'desc_zh' => '采用 SWE-bench Verified 公开结果,以真实 GitHub 问题的解决率衡量编程 Agent 能力。', 'desc_en' => 'Compare coding agents by their verified resolution rate on real GitHub issues in SWE-bench Verified.', 'source' => 'SWE-bench Verified', 'source_url' => 'https://www.swebench.com/', ), 'open-models' => array( 'icon' => 'fa-cubes', 'zh' => '开源模型榜', 'en' => 'Open Models', 'title_zh' => 'Hugging Face 开源模型热榜', 'title_en' => 'Hugging Face Open Model Trends', 'desc_zh' => '依据 Hugging Face Trending Score、下载量和社区点赞,发现近期活跃的开源模型。', 'desc_en' => 'Find active open models using Hugging Face trending score, downloads, and community likes.', 'source' => 'Hugging Face Hub API', 'source_url' => 'https://huggingface.co/docs/hub/en/api', ), ); } function fxdst_rank_is_request() { return (bool) get_query_var('fxdst_rank_page'); } function fxdst_rank_language() { return get_query_var('fxdst_rank_lang') === 'en' ? 'en' : 'zh'; } function fxdst_rank_url($category = '', $lang = 'zh') { $prefix = $lang === 'en' ? '/en/rankings/' : '/rankings/'; return home_url($prefix . ($category ? trailingslashit($category) : '')); } add_action('init', function () { add_rewrite_rule('^rankings/?$', 'index.php?fxdst_rank_page=hub&fxdst_rank_lang=zh', 'top'); add_rewrite_rule('^rankings/(github-ai|openrouter|opencode|agents|open-models)/?$', 'index.php?fxdst_rank_page=$matches[1]&fxdst_rank_lang=zh', 'top'); add_rewrite_rule('^en/rankings/?$', 'index.php?fxdst_rank_page=hub&fxdst_rank_lang=en', 'top'); add_rewrite_rule('^en/rankings/(github-ai|openrouter|opencode|agents|open-models)/?$', 'index.php?fxdst_rank_page=$matches[1]&fxdst_rank_lang=en', 'top'); if (!wp_next_scheduled(FXDST_RANKINGS_CRON)) { wp_schedule_event(time() + 120, 'fxdst_six_hours', FXDST_RANKINGS_CRON); } }, 8); add_filter('query_vars', function ($vars) { $vars[] = 'fxdst_rank_page'; $vars[] = 'fxdst_rank_lang'; return $vars; }); add_filter('cron_schedules', function ($schedules) { $schedules['fxdst_six_hours'] = array('interval' => 6 * HOUR_IN_SECONDS, 'display' => 'Every six hours'); return $schedules; }); add_action(FXDST_RANKINGS_CRON, 'fxdst_rank_refresh_all'); add_action('wp_enqueue_scripts', function () { if (!fxdst_rank_is_request()) return; wp_enqueue_style('fxdst-ai-rankings', content_url('/mu-plugins/fxdst-ai-rankings.css'), array(), FXDST_RANKINGS_VERSION); }); function fxdst_rank_http_json($url, $timeout = 20) { $response = wp_remote_get($url, array( 'timeout' => $timeout, 'redirection' => 4, 'headers' => array('Accept' => 'application/json', 'User-Agent' => 'FXDST-Rankings/1.0 (+https://www.fxdst.com/rankings/)'), )); if (is_wp_error($response)) return $response; if (wp_remote_retrieve_response_code($response) !== 200) return new WP_Error('upstream_http', 'HTTP ' . wp_remote_retrieve_response_code($response)); $data = json_decode(wp_remote_retrieve_body($response), true); return is_array($data) ? $data : new WP_Error('invalid_json', 'Invalid JSON response'); } function fxdst_rank_http_html($url, $timeout = 25) { $response = wp_remote_get($url, array( 'timeout' => $timeout, 'redirection' => 4, 'headers' => array('Accept' => 'text/html', 'User-Agent' => 'FXDST-Rankings/1.0 (+https://www.fxdst.com/rankings/)'), )); if (is_wp_error($response)) return $response; if (wp_remote_retrieve_response_code($response) !== 200) return new WP_Error('upstream_http', 'HTTP ' . wp_remote_retrieve_response_code($response)); return wp_remote_retrieve_body($response); } function fxdst_rank_number($number) { $number = (float) $number; if ($number >= 1000000000) return round($number / 1000000000, 1) . 'B'; if ($number >= 1000000) return round($number / 1000000, 1) . 'M'; if ($number >= 1000) return round($number / 1000, 1) . 'K'; return number_format_i18n($number); } function fxdst_rank_fetch_github() { $since = gmdate('Y-m-d', time() - 120 * DAY_IN_SECONDS); $topics = array('artificial-intelligence', 'llm', 'ai-agent', 'model-context-protocol'); $merged = array(); foreach ($topics as $topic) { $url = add_query_arg(array('q' => 'topic:' . $topic . ' pushed:>=' . $since, 'sort' => 'stars', 'order' => 'desc', 'per_page' => 20), 'https://api.github.com/search/repositories'); $data = fxdst_rank_http_json($url); if (is_wp_error($data)) continue; foreach (($data['items'] ?? array()) as $repo) { $key = $repo['full_name'] ?? ''; if (!$key) continue; $pushed = isset($repo['pushed_at']) ? strtotime($repo['pushed_at']) : 0; $stars = (int) ($repo['stargazers_count'] ?? 0); $activity = max(0, 120 - floor((time() - $pushed) / DAY_IN_SECONDS)); $score = log(max(2, $stars), 10) * 100 + $activity; if (!isset($merged[$key]) || $score > $merged[$key]['score']) { $merged[$key] = array( 'name' => $repo['name'] ?? $key, 'org' => $repo['owner']['login'] ?? '', 'description' => wp_strip_all_tags($repo['description'] ?? ''), 'metric' => fxdst_rank_number($stars) . ' stars', 'metric_value' => $stars, 'secondary' => isset($repo['language']) && $repo['language'] ? $repo['language'] : 'Open source', 'url' => $repo['html_url'] ?? 'https://github.com/' . $key, 'score' => $score, ); } } } usort($merged, function ($a, $b) { return $b['score'] <=> $a['score']; }); return array_slice(array_values($merged), 0, 20); } function fxdst_rank_fetch_openrouter() { $data = fxdst_rank_http_json('https://openrouter.ai/api/frontend/v1/rankings/models?view=week'); if (is_wp_error($data)) return $data; $models = array(); foreach (($data['data'] ?? array()) as $row) { $slug = $row['model_permaslug'] ?? ''; if (!$slug) continue; if (!isset($models[$slug])) $models[$slug] = array('count' => 0, 'tokens' => 0, 'history' => array()); $models[$slug]['count'] += (int) ($row['count'] ?? 0); $models[$slug]['tokens'] += (int) ($row['total_prompt_tokens'] ?? 0) + (int) ($row['total_completion_tokens'] ?? 0); $point_time = !empty($row['date']) ? strtotime($row['date'] . ' UTC') : false; if ($point_time) $models[$slug]['history'][$point_time] = ($models[$slug]['history'][$point_time] ?? 0) + (int) ($row['count'] ?? 0); } arsort($models); $items = array(); foreach ($models as $slug => $stats) { $parts = explode('/', $slug, 2); ksort($stats['history']); $history = array(); foreach ($stats['history'] as $time => $value) $history[] = array('time' => (int) $time, 'value' => (float) $value); $items[] = array( 'name' => $parts[1] ?? $slug, 'org' => $parts[0] ?? 'OpenRouter', 'description' => '', 'metric' => fxdst_rank_number($stats['count']) . ' requests', 'metric_value' => $stats['count'], 'secondary' => fxdst_rank_number($stats['tokens']) . ' tokens', 'url' => 'https://openrouter.ai/' . $slug, 'score' => $stats['count'], 'history' => $history, ); } usort($items, function ($a, $b) { return $b['score'] <=> $a['score']; }); return array_slice($items, 0, 20); } function fxdst_rank_fetch_opencode() { $html = fxdst_rank_http_html('https://opencode.ai/data/'); if (is_wp_error($html)) return $html; $start = strpos($html, 'usage:$R'); $end = strpos($html, 'leaderboard:$R'); if ($start === false || $end === false || $end <= $start) return new WP_Error('opencode_parse', 'Usage series not found'); $usage = substr($html, $start, $end - $start); preg_match_all('/model:"([^"]+)",value:([0-9.]+)/', $usage, $matches, PREG_SET_ORDER); $scores = array(); foreach ($matches as $match) { $model = $match[1]; if (strtolower($model) === 'other') continue; $scores[$model] = ($scores[$model] ?? 0) + (float) $match[2]; } $history = array(); preg_match_all('/date:"([^"]+)",segments:\$R\[\d+\]=\[([\s\S]*?)\]\}/', $usage, $days, PREG_SET_ORDER); foreach ($days as $day) { $point_time = strtotime($day[1] . ' ' . gmdate('Y') . ' UTC'); if ($point_time && $point_time > time() + 30 * DAY_IN_SECONDS) $point_time = strtotime('-1 year', $point_time); if (!$point_time) continue; preg_match_all('/model:"([^"]+)",value:([0-9.]+)/', $day[2], $segments, PREG_SET_ORDER); foreach ($segments as $segment) { if (strtolower($segment[1]) === 'other') continue; $history[$segment[1]][$point_time] = (float) $segment[2]; } } arsort($scores); $items = array(); foreach (array_slice($scores, 0, 20, true) as $model => $score) { $provider = strpos($model, '/') !== false ? explode('/', $model, 2)[0] : 'OpenCode'; $model_history = array(); if (!empty($history[$model])) { ksort($history[$model]); foreach ($history[$model] as $time => $value) $model_history[] = array('time' => (int) $time, 'value' => (float) $value); } $items[] = array( 'name' => $model, 'org' => $provider, 'description' => '', 'metric' => number_format_i18n($score, 2) . ' usage index', 'metric_value' => $score, 'secondary' => 'OpenCode usage series', 'url' => 'https://opencode.ai/data/', 'score' => $score, 'history' => $model_history, ); } return $items ?: new WP_Error('opencode_empty', 'No model data found'); } function fxdst_rank_fetch_agents() { $html = fxdst_rank_http_html('https://www.swebench.com/', 35); if (is_wp_error($html)) return $html; $marker = '<script type="application/json" id="leaderboard-data">'; $start = strpos($html, $marker); if ($start === false) return new WP_Error('swebench_parse', 'Leaderboard JSON not found'); $start += strlen($marker); $end = strpos($html, '</script>', $start); if ($end === false) return new WP_Error('swebench_parse', 'Leaderboard JSON is incomplete'); $boards = json_decode(html_entity_decode(trim(substr($html, $start, $end - $start)), ENT_QUOTES | ENT_HTML5, 'UTF-8'), true); if (!is_array($boards)) return new WP_Error('swebench_json', 'Leaderboard JSON invalid'); $results = array(); foreach ($boards as $board) { if (strtolower($board['name'] ?? '') === 'verified') { $results = $board['results'] ?? array(); break; } } $clean = array(); foreach ($results as $row) { if (!empty($row['warning']) || !isset($row['resolved'])) continue; $score = (float) $row['resolved']; $clean[] = array( 'name' => $row['name'] ?? ($row['agent'] ?? 'Agent'), 'org' => $row['agent_org'] ?? ($row['model_org'] ?? ($row['agent'] ?? '')), 'description' => '', 'metric' => number_format_i18n($score, 1) . '% resolved', 'metric_value' => $score, 'secondary' => $row['agent'] ?? 'SWE-bench Verified', 'url' => !empty($row['site']) && is_string($row['site']) ? $row['site'] : 'https://www.swebench.com/', 'score' => $score, ); } usort($clean, function ($a, $b) { return $b['score'] <=> $a['score']; }); return array_slice($clean, 0, 20); } function fxdst_rank_fetch_open_models() { $models = fxdst_rank_http_json('https://huggingface.co/api/models?sort=trendingScore&direction=-1&limit=20', 35); if (is_wp_error($models)) { // Mainland servers may not reach huggingface.co reliably. The mirror // exposes the same Hub API payload; links and attribution stay official. $models = fxdst_rank_http_json('https://hf-mirror.com/api/models?sort=trendingScore&direction=-1&limit=20', 20); } if (is_wp_error($models)) return $models; $items = array(); foreach ($models as $model) { $id = $model['modelId'] ?? ($model['id'] ?? ''); if (!$id) continue; $parts = explode('/', $id, 2); $downloads = (int) ($model['downloads'] ?? 0); $likes = (int) ($model['likes'] ?? 0); $trend = (float) ($model['trendingScore'] ?? 0); $items[] = array( 'name' => $parts[1] ?? $id, 'org' => $parts[0] ?? 'Community', 'description' => '', 'metric' => fxdst_rank_number($downloads) . ' downloads', 'metric_value' => $downloads, 'secondary' => fxdst_rank_number($likes) . ' likes', 'url' => 'https://huggingface.co/' . $id, 'score' => $trend ?: ($downloads + $likes * 100), ); } return array_slice($items, 0, 20); } function fxdst_rank_refresh_all() { if (get_transient('fxdst_rankings_refresh_lock')) return false; set_transient('fxdst_rankings_refresh_lock', 1, 10 * MINUTE_IN_SECONDS); $fetchers = array( 'github-ai' => 'fxdst_rank_fetch_github', 'openrouter' => 'fxdst_rank_fetch_openrouter', 'opencode' => 'fxdst_rank_fetch_opencode', 'agents' => 'fxdst_rank_fetch_agents', 'open-models' => 'fxdst_rank_fetch_open_models', ); $result = array(); foreach ($fetchers as $key => $fetcher) { $items = call_user_func($fetcher); if (is_wp_error($items) || empty($items)) { update_option('fxdst_rankings_error_' . $key, array('time' => time(), 'message' => is_wp_error($items) ? $items->get_error_message() : 'No data'), false); error_log('[FXDST Rankings] ' . $key . ': ' . (is_wp_error($items) ? $items->get_error_message() : 'No data')); $result[$key] = false; continue; } $previous = get_option('fxdst_rankings_' . $key, array()); $previous_items = array(); foreach (($previous['items'] ?? array()) as $old_item) $previous_items[($old_item['url'] ?? '') . '|' . ($old_item['name'] ?? '')] = $old_item; foreach ($items as &$item) { $identity = ($item['url'] ?? '') . '|' . ($item['name'] ?? ''); if (count($item['history'] ?? array()) < 2) { $history = $previous_items[$identity]['history'] ?? array(); $history[] = array('time' => time(), 'value' => (float) ($item['metric_value'] ?? $item['score'] ?? 0)); $deduped = array(); foreach ($history as $point) if (isset($point['time'], $point['value'])) $deduped[(int) $point['time']] = (float) $point['value']; ksort($deduped); $item['history'] = array(); foreach (array_slice($deduped, -30, 30, true) as $point_time => $point_value) $item['history'][] = array('time' => $point_time, 'value' => $point_value); } } unset($item); update_option('fxdst_rankings_' . $key, array('items' => array_values($items), 'fetched_at' => time(), 'status' => 'fresh'), false); delete_option('fxdst_rankings_error_' . $key); $result[$key] = count($items); } delete_transient('fxdst_rankings_refresh_lock'); update_option('fxdst_rankings_last_run', time(), false); return $result; } function fxdst_rank_data($category) { $data = get_option('fxdst_rankings_' . $category, array()); return is_array($data) ? $data : array(); } add_action('rest_api_init', function () { register_rest_route('fxdst/v1', '/rankings/(?P<category>[a-z-]+)', array( 'methods' => WP_REST_Server::READABLE, 'permission_callback' => '__return_true', 'callback' => function ($request) { $key = sanitize_key($request['category']); if (!array_key_exists($key, fxdst_rank_categories())) return new WP_Error('invalid_category', 'Unknown ranking category.', array('status' => 404)); $data = fxdst_rank_data($key); return rest_ensure_response(array('category' => $key, 'source' => fxdst_rank_categories()[$key]['source'], 'updated_at' => !empty($data['fetched_at']) ? gmdate('c', $data['fetched_at']) : null, 'items' => $data['items'] ?? array())); }, )); }); function fxdst_rank_meta($page, $lang) { $categories = fxdst_rank_categories(); if ($page === 'hub') { return $lang === 'en' ? array('AI Rankings — Models, Agents & Open-Source Projects | FXDST', 'Live, source-attributed rankings for GitHub AI projects, OpenRouter and OpenCode model usage, coding agents, and Hugging Face open models.') : array('AI排行榜中心:模型调用、Agent评测与开源项目热榜 | 方向舵', '汇总GitHub AI项目、OpenRouter与OpenCode模型调用、SWE-bench Agent评测和Hugging Face开源模型热度,数据每6小时更新。'); } $c = $categories[$page]; return $lang === 'en' ? array($c['title_en'] . ' — Top 20 | FXDST', $c['desc_en'] . ' Updated every six hours with transparent source attribution and methodology.') : array($c['title_zh'] . ' Top 20 | 方向舵', $c['desc_zh'] . ' 榜单每6小时更新,并公开数据来源、统计周期和排名口径。'); } function fxdst_rank_jsonld($page, $lang) { $categories = fxdst_rank_categories(); $is_hub = $page === 'hub'; $canonical = fxdst_rank_url($is_hub ? '' : $page, $lang); $meta = fxdst_rank_meta($page, $lang); $home_label = $lang === 'en' ? 'Home' : '首页'; $rank_label = $lang === 'en' ? 'AI Rankings' : 'AI排行榜'; $crumbs = array( array('@type' => 'ListItem', 'position' => 1, 'name' => $home_label, 'item' => home_url($lang === 'en' ? '/en/' : '/')), array('@type' => 'ListItem', 'position' => 2, 'name' => $rank_label, 'item' => fxdst_rank_url('', $lang)), ); if (!$is_hub) $crumbs[] = array('@type' => 'ListItem', 'position' => 3, 'name' => $lang === 'en' ? $categories[$page]['title_en'] : $categories[$page]['title_zh'], 'item' => $canonical); $graph = array( array('@type' => 'WebPage', '@id' => $canonical . '#webpage', 'url' => $canonical, 'name' => $meta[0], 'description' => $meta[1], 'inLanguage' => $lang === 'en' ? 'en' : 'zh-CN'), array('@type' => 'BreadcrumbList', '@id' => $canonical . '#breadcrumb', 'itemListElement' => $crumbs), ); if (!$is_hub) { $data = fxdst_rank_data($page); $list = array(); foreach (array_slice($data['items'] ?? array(), 0, 20) as $index => $item) { $list[] = array('@type' => 'ListItem', 'position' => $index + 1, 'name' => $item['name'], 'url' => $item['url']); } $graph[] = array('@type' => 'ItemList', '@id' => $canonical . '#ranking', 'name' => $lang === 'en' ? $categories[$page]['title_en'] : $categories[$page]['title_zh'], 'numberOfItems' => count($list), 'itemListOrder' => 'https://schema.org/ItemListOrderDescending', 'itemListElement' => $list); } return array('@context' => 'https://schema.org', '@graph' => $graph); } add_action('wp_head', function () { if (!fxdst_rank_is_request()) return; $page = get_query_var('fxdst_rank_page'); $lang = fxdst_rank_language(); echo '<script type="application/ld+json">' . wp_json_encode(fxdst_rank_jsonld($page, $lang), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . '</script>' . "\n"; }, 3); function fxdst_rank_begin_zh($title, $desc, $canonical, $alternate) { status_header(200); nocache_headers(); ?><!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"><meta name="theme-color" content="#10283a"><title><?php echo esc_html($title); ?></title><meta name="description" content="<?php echo esc_attr($desc); ?>"><meta name="robots" content="index,follow,max-snippet:-1,max-image-preview:large"><link rel="canonical" href="<?php echo esc_url($canonical); ?>"><link rel="alternate" hreflang="zh-CN" href="<?php echo esc_url($canonical); ?>"><link rel="alternate" hreflang="en" href="<?php echo esc_url($alternate); ?>"><link rel="alternate" hreflang="x-default" href="<?php echo esc_url($canonical); ?>"><meta property="og:locale" content="zh_CN"><meta property="og:type" content="website"><meta property="og:title" content="<?php echo esc_attr($title); ?>"><meta property="og:description" content="<?php echo esc_attr($desc); ?>"><meta property="og:url" content="<?php echo esc_url($canonical); ?>"><?php wp_head(); ?></head><body <?php body_class('page-body ' . (function_exists('io_get_option') ? io_get_option('theme_mode') : '')); ?>><div class="page-container"><?php $nav = locate_template('templates/header-nav.php'); if ($nav) include $nav; echo '<div class="main-content page">'; $banner = locate_template('templates/header-banner.php'); if ($banner) include $banner; } function fxdst_rank_begin_en($title, $desc, $canonical, $alternate) { if (function_exists('fxdst_en_begin')) { fxdst_en_begin($title, $desc, $canonical, $alternate, false); return; } fxdst_rank_begin_zh($title, $desc, $canonical, $alternate); } function fxdst_rank_end($lang) { if ($lang === 'en') { ?><footer class="main-footer sticky footer-type-1"><div class="go-up fxdst-floating-actions" aria-label="Quick actions"><a href="mailto:xxf0036@hotmail.com" class="fxdst-float-action" aria-label="Email"><i class="fa fa-envelope-o"></i></a><a href="#" rel="go-top" class="fxdst-float-action" aria-label="Back to top"><i class="fa fa-angle-up"></i></a></div><div class="footer-inner"><div class="footer-text">Copyright © <?php echo date('Y'); ?> FXDST Global <span class="fxdst-footer-links"><a href="/privacy-policy/">Privacy Policy</a><span>/</span><a href="/terms-of-service/">Terms of Service</a></span></div></div></footer></div></div><?php wp_footer(); ?></body></html><?php exit; } get_footer(); exit; } function fxdst_rank_localize_metric($value, $lang) { if ($lang !== 'zh') return $value; return str_replace( array(' stars', ' requests', ' tokens', ' usage index', '% resolved', ' downloads', ' likes', 'OpenCode usage series'), array(' Stars', ' 次请求', ' Tokens', ' 使用指数', '% 解决率', ' 次下载', ' 次点赞', 'OpenCode 使用序列'), (string) $value ); } function fxdst_rank_sparkline($history, $lang) { $history = is_array($history) ? array_values(array_filter($history, function ($point) { return isset($point['time'], $point['value']) && is_numeric($point['value']); })) : array(); if (count($history) < 2) { return '<span class="fxdst-rank-sparkline is-recording" title="' . esc_attr($lang === 'en' ? 'History recording started' : '历史数据已开始记录') . '"><i></i><span>' . esc_html($lang === 'en' ? 'Recording' : '记录中') . '</span></span>'; } $values = array_map(function ($point) { return (float) $point['value']; }, $history); $minimum = min($values); $maximum = max($values); $range = max(0.00001, $maximum - $minimum); $count = count($values); $points = array(); foreach ($values as $index => $value) { $x = $count > 1 ? 2 + ($index / ($count - 1)) * 88 : 46; $y = 25 - (($value - $minimum) / $range) * 21; $points[] = round($x, 1) . ',' . round($y, 1); } $direction = end($values) > reset($values) ? ' is-up' : (end($values) < reset($values) ? ' is-down' : ' is-flat'); $label = $lang === 'en' ? 'Historical metric trend' : '历史指标趋势'; return '<span class="fxdst-rank-sparkline' . $direction . '"><svg viewBox="0 0 92 29" role="img" aria-label="' . esc_attr($label) . '" focusable="false"><polyline points="' . esc_attr(implode(' ', $points)) . '"></polyline><circle cx="' . esc_attr(explode(',', end($points))[0]) . '" cy="' . esc_attr(explode(',', end($points))[1]) . '" r="2.4"></circle></svg></span>'; } function fxdst_rank_item_help($category, $item, $lang, $tooltip_id) { $metric = fxdst_rank_localize_metric($item['metric'] ?? '', $lang); $secondary = fxdst_rank_localize_metric($item['secondary'] ?? '', $lang); $source = fxdst_rank_categories()[$category]['source']; if ($lang === 'en') { $messages = array( 'github-ai' => "The primary metric is {$metric}, sourced from GitHub Search API. The history line is recorded by FXDST every 6 hours and shows Stars movement, not an official GitHub Trending rank.", 'openrouter' => "The primary metric is {$metric}" . ($secondary ? "; the supporting metric is {$secondary}" : '') . ". Data comes from OpenRouter's public weekly ranking, and the line shows the available recorded usage history.", 'opencode' => "The primary metric is {$metric}" . ($secondary ? "; the supporting metric is {$secondary}" : '') . ". Data comes from OpenCode Data, and the line shows the published model-usage history.", 'agents' => "The primary metric is {$metric}, sourced from the SWE-bench public benchmark. It is a benchmark resolution rate, not real-world Agent usage volume.", 'open-models' => "The primary metric is {$metric}" . ($secondary ? "; the supporting metric is {$secondary}" : '') . ". Data comes from the Hugging Face Hub API; the history line records changes observed by FXDST every 6 hours.", ); $label = 'Explain this metric'; $title = 'Metric note'; } else { $messages = array( 'github-ai' => "核心指标为{$metric},数据来自 GitHub Search API。历史曲线由本站每 6 小时记录一次,仅表示 Stars 变化,不等同于 GitHub 官方 Trending 排名。", 'openrouter' => "核心指标为{$metric}" . ($secondary ? ",辅助指标为{$secondary}" : '') . "。数据来自 OpenRouter 公开周榜,曲线表示当前可用周期内的调用变化。", 'opencode' => "核心指标为{$metric}" . ($secondary ? ",辅助指标为{$secondary}" : '') . "。数据来自 OpenCode Data,曲线表示其公开的模型使用历史。", 'agents' => "核心指标为{$metric},数据来自 SWE-bench 公开基准。这是基准任务解决率,不代表 Agent 的真实调用量。", 'open-models' => "核心指标为{$metric}" . ($secondary ? ",辅助指标为{$secondary}" : '') . "。数据来自 Hugging Face Hub API,历史曲线由本站每 6 小时记录观察值。", ); $label = '查看指标说明'; $title = '指标说明'; } $message = $messages[$category] ?? (($lang === 'en' ? 'This metric is sourced from ' : '该指标数据来源:') . $source . '.'); return fxdst_rank_tip_control($tooltip_id, $label, $title, $message, 'is-metric-help'); } function fxdst_rank_tip_control($tooltip_id, $label, $title, $message, $class = '') { $icon = '<svg viewBox="0 0 20 20" aria-hidden="true" focusable="false"><circle cx="10" cy="10" r="7.5"></circle><path d="M10 5.8v5.1"></path><circle class="fxdst-rank-help-dot" cx="10" cy="13.8" r=".85"></circle></svg>'; return '<span class="fxdst-rank-help ' . esc_attr($class) . '"><button type="button" class="fxdst-rank-help-button" aria-label="' . esc_attr($label) . '" aria-describedby="' . esc_attr($tooltip_id) . '">' . $icon . '</button><span class="fxdst-rank-tooltip" id="' . esc_attr($tooltip_id) . '" role="tooltip"><strong>' . esc_html($title) . '</strong><span>' . esc_html($message) . '</span></span></span>'; } function fxdst_rank_entry_help($category, $item, $lang, $tooltip_id) { $name = trim((string) ($item['name'] ?? '')); $org = trim((string) ($item['org'] ?? '')) ?: fxdst_rank_categories()[$category]['source']; $source_description = trim(wp_strip_all_tags((string) ($item['description'] ?? ''))); if ($lang === 'en') { $messages = array( 'github-ai' => $source_description ?: "{$name} is an open-source AI project maintained by {$org}. Its repository link provides the README, releases, license, and contribution activity.", 'openrouter' => "{$name} is a model entry from {$org} appearing in OpenRouter's public routing rankings. Open the name link for its official model page, context limits, pricing, and provider availability.", 'opencode' => "{$name} is a model observed in the OpenCode usage dataset. This row compares its published usage signal with other models in the same OpenCode series.", 'agents' => "{$name} is an Agent or coding system evaluated on SWE-bench Verified. This row represents benchmark performance, not general popularity or production usage.", 'open-models' => "{$name} is a public model published by {$org} on Hugging Face. Open its model card to review intended tasks, files, license, and usage instructions.", ); $label = 'Explain this entry'; $title = 'About this entry'; } else { $messages = array( 'github-ai' => "{$name} 是由 {$org} 维护的开源 AI 项目。点击名称可查看 GitHub 仓库中的 README、版本发布、许可证与贡献活跃度。", 'openrouter' => "{$name} 是 {$org} 在 OpenRouter 公开路由榜单中的模型条目。点击名称可查看模型页面、上下文限制、价格和可用提供商。", 'opencode' => "{$name} 是 OpenCode 使用数据中记录的模型条目。本行用于比较它与同一 OpenCode 数据序列中其他模型的使用信号。", 'agents' => "{$name} 是参与 SWE-bench Verified 评测的 Agent 或编程系统。本行表示基准评测表现,不代表通用热度或真实生产调用量。", 'open-models' => "{$name} 是 {$org} 发布在 Hugging Face 上的公开模型。点击名称可查看模型卡、适用任务、文件、许可证和使用说明。", ); $label = '查看项目或模型说明'; $title = '条目说明'; } return fxdst_rank_tip_control($tooltip_id, $label, $title, $messages[$category] ?? $name, 'is-entry-help'); } function fxdst_rank_crumbs($page, $lang) { $categories = fxdst_rank_categories(); echo '<nav class="fxdst-rank-breadcrumb" aria-label="Breadcrumb"><a href="' . esc_url(home_url($lang === 'en' ? '/en/' : '/')) . '">' . esc_html($lang === 'en' ? 'Home' : '首页') . '</a><i class="fa fa-angle-right" aria-hidden="true"></i>'; if ($page === 'hub') echo '<span>' . esc_html($lang === 'en' ? 'AI Rankings' : 'AI排行榜') . '</span>'; else echo '<a href="' . esc_url(fxdst_rank_url('', $lang)) . '">' . esc_html($lang === 'en' ? 'AI Rankings' : 'AI排行榜') . '</a><i class="fa fa-angle-right" aria-hidden="true"></i><span>' . esc_html($lang === 'en' ? $categories[$page]['title_en'] : $categories[$page]['title_zh']) . '</span>'; echo '</nav>'; } function fxdst_rank_tabs($active, $lang) { echo '<nav class="fxdst-rank-tabs" aria-label="' . esc_attr($lang === 'en' ? 'Ranking categories' : '排行榜分类') . '">'; foreach (fxdst_rank_categories() as $key => $category) { echo '<a class="fxdst-rank-tab' . ($active === $key ? ' is-active' : '') . '" href="' . esc_url(fxdst_rank_url($key, $lang)) . '"><i class="fa ' . esc_attr($category['icon']) . '" aria-hidden="true"></i><span>' . esc_html($category[$lang]) . '</span></a>'; } echo '</nav>'; } function fxdst_rank_list($category, $lang, $limit = 20) { $config = fxdst_rank_categories()[$category]; $data = fxdst_rank_data($category); $items = array_slice($data['items'] ?? array(), 0, $limit); if (!$items) { echo '<div class="fxdst-rank-empty"><i class="fa fa-clock-o" aria-hidden="true"></i><strong>' . esc_html($lang === 'en' ? 'Ranking data is being prepared' : '榜单数据正在准备中') . '</strong><p>' . esc_html($lang === 'en' ? 'The first source refresh will complete shortly.' : '首次数据刷新将在稍后完成。') . '</p></div>'; return; } echo '<ol class="fxdst-rank-list">'; foreach ($items as $index => $item) { $rank = $index + 1; $tooltip_base = 'fxdst-rank-tip-' . sanitize_html_class($category) . '-' . intval($limit) . '-' . intval($rank); echo '<li class="fxdst-rank-row' . ($rank <= 3 ? ' is-podium' : '') . '"><span class="fxdst-rank-position">' . intval($rank) . '</span><div class="fxdst-rank-identity"><div class="fxdst-rank-identity-head"><a href="' . esc_url($item['url']) . '" target="_blank" rel="nofollow noopener noreferrer external"><strong>' . esc_html($item['name']) . '</strong><i class="fa fa-external-link" aria-hidden="true"></i></a>' . fxdst_rank_entry_help($category, $item, $lang, $tooltip_base . '-entry') . '</div><span>' . esc_html($item['org'] ?: $config['source']) . '</span></div><div class="fxdst-rank-context">' . esc_html(fxdst_rank_localize_metric($item['secondary'] ?? '', $lang)) . '</div>' . fxdst_rank_sparkline($item['history'] ?? array(), $lang) . '<span class="fxdst-rank-metric-wrap"><strong class="fxdst-rank-metric">' . esc_html(fxdst_rank_localize_metric($item['metric'], $lang)) . '</strong>' . fxdst_rank_item_help($category, $item, $lang, $tooltip_base . '-metric') . '</span></li>'; } echo '</ol>'; } function fxdst_rank_render($page, $lang) { $categories = fxdst_rank_categories(); $meta = fxdst_rank_meta($page, $lang); $canonical = fxdst_rank_url($page === 'hub' ? '' : $page, $lang); $alternate = fxdst_rank_url($page === 'hub' ? '' : $page, $lang === 'en' ? 'zh' : 'en'); if ($lang === 'en') fxdst_rank_begin_en($meta[0], $meta[1], $canonical, $alternate); else fxdst_rank_begin_zh($meta[0], $meta[1], $canonical, $alternate); echo '<main class="fxdst-rankings"><div class="fxdst-rankings-inner">'; fxdst_rank_crumbs($page, $lang); if ($page === 'hub') { echo '<header class="fxdst-rank-hero"><div><h1>' . esc_html($lang === 'en' ? 'The AI landscape, ranked by evidence' : '用真实数据看清 AI 热度与能力') . '</h1><p>' . esc_html($lang === 'en' ? 'Five source-attributed rankings bring project momentum, model usage, coding-agent performance, and open-model activity into one scan-friendly view.' : '五类排行榜统一呈现项目热度、模型调用、编程 Agent 能力与开源模型活跃度,每项指标都标明来源和口径。') . '</p></div><div class="fxdst-rank-freshness"><i class="fa fa-refresh" aria-hidden="true"></i><strong>' . esc_html($lang === 'en' ? 'Refreshed every 6 hours' : '每 6 小时更新') . '</strong><span>' . esc_html($lang === 'en' ? 'Pages use cached data for fast loading' : '页面读取本地缓存,不阻塞首屏') . '</span></div></header>'; fxdst_rank_tabs('', $lang); echo '<div class="fxdst-rank-hub">'; foreach ($categories as $key => $category) { $data = fxdst_rank_data($key); echo '<section class="fxdst-rank-preview"><header><div><i class="fa ' . esc_attr($category['icon']) . '" aria-hidden="true"></i><h2>' . esc_html($lang === 'en' ? $category['title_en'] : $category['title_zh']) . '</h2></div><a href="' . esc_url(fxdst_rank_url($key, $lang)) . '">' . esc_html($lang === 'en' ? 'View Top 20' : '查看 Top 20') . '<i class="fa fa-angle-right" aria-hidden="true"></i></a></header>'; fxdst_rank_list($key, $lang, 10); echo '<footer><span>' . esc_html($lang === 'en' ? 'Source' : '数据来源') . ' · <a href="' . esc_url($category['source_url']) . '" target="_blank" rel="nofollow noopener noreferrer external">' . esc_html($category['source']) . '</a></span><time datetime="' . esc_attr(!empty($data['fetched_at']) ? gmdate('c', $data['fetched_at']) : '') . '">' . esc_html(!empty($data['fetched_at']) ? ($lang === 'en' ? 'Updated ' : '更新于 ') . wp_date($lang === 'en' ? 'M j, H:i' : 'm月d日 H:i', $data['fetched_at']) : '') . '</time></footer></section>'; } echo '</div>'; } else { $category = $categories[$page]; $data = fxdst_rank_data($page); echo '<header class="fxdst-rank-detail-head"><div class="fxdst-rank-detail-title"><i class="fa ' . esc_attr($category['icon']) . '" aria-hidden="true"></i><div><h1>' . esc_html($lang === 'en' ? $category['title_en'] : $category['title_zh']) . '</h1><p>' . esc_html($lang === 'en' ? $category['desc_en'] : $category['desc_zh']) . '</p></div></div><aside><span>' . esc_html($lang === 'en' ? 'Source' : '数据来源') . '</span><a href="' . esc_url($category['source_url']) . '" target="_blank" rel="nofollow noopener noreferrer external">' . esc_html($category['source']) . '<i class="fa fa-external-link" aria-hidden="true"></i></a><time>' . esc_html(!empty($data['fetched_at']) ? ($lang === 'en' ? 'Updated ' : '更新于 ') . wp_date($lang === 'en' ? 'M j, Y H:i' : 'Y年m月d日 H:i', $data['fetched_at']) : ($lang === 'en' ? 'Waiting for first refresh' : '等待首次刷新')) . '</time></aside></header>'; fxdst_rank_tabs($page, $lang); echo '<section class="fxdst-rank-board"><header><strong>Top 20</strong><span>#</span><span>' . esc_html($lang === 'en' ? 'Project / model / agent' : '项目 / 模型 / Agent') . '</span><span>' . esc_html($lang === 'en' ? 'Context' : '辅助指标') . '</span><span>' . esc_html($lang === 'en' ? 'History' : '历史趋势') . '</span><span>' . esc_html($lang === 'en' ? 'Primary metric' : '核心指标') . '</span></header>'; fxdst_rank_list($page, $lang, 20); echo '</section><section class="fxdst-rank-method"><h2>' . esc_html($lang === 'en' ? 'How to read this ranking' : '如何理解这份榜单') . '</h2><p>' . esc_html($lang === 'en' ? 'This list compares entries only within the same source and metric. It should not be used to compare unlike signals such as stars, request volume, and benchmark resolution rates.' : '榜单只在相同数据源和相同指标内部进行比较,不应把 Stars、调用次数与基准解决率等不同信号直接横向比较。') . '</p><a href="' . esc_url($category['source_url']) . '" target="_blank" rel="nofollow noopener noreferrer external">' . esc_html($lang === 'en' ? 'Review the original source' : '查看原始数据来源') . '<i class="fa fa-angle-right" aria-hidden="true"></i></a></section>'; } echo '</div></main>'; fxdst_rank_end($lang); } add_action('template_redirect', function () { if (!fxdst_rank_is_request()) return; $page = sanitize_key(get_query_var('fxdst_rank_page')); if ($page !== 'hub' && !array_key_exists($page, fxdst_rank_categories())) { status_header(404); return; } fxdst_rank_render($page, fxdst_rank_language()); }, 1); add_action('init', function () { if (!class_exists('WP_Sitemaps_Provider') || !function_exists('wp_sitemaps_register_provider')) return; if (class_exists('FXDST_Rankings_Sitemap_Provider')) return; class FXDST_Rankings_Sitemap_Provider extends WP_Sitemaps_Provider { public function __construct() { $this->name = 'rankings'; $this->object_type = 'rankings'; } public function get_url_list($page_num, $object_subtype = '') { $urls = array(); foreach (array('zh', 'en') as $lang) { $urls[] = array('loc' => fxdst_rank_url('', $lang), 'lastmod' => gmdate('c', (int) get_option('fxdst_rankings_last_run', time()))); foreach (array_keys(fxdst_rank_categories()) as $key) $urls[] = array('loc' => fxdst_rank_url($key, $lang), 'lastmod' => gmdate('c', (int) get_option('fxdst_rankings_last_run', time()))); } return $urls; } public function get_max_num_pages($object_subtype = '') { return 1; } } wp_sitemaps_register_provider('rankings', new FXDST_Rankings_Sitemap_Provider()); }, 25);