feat: 添加 AI 查询页面固定链接支持
- 注册 /ai-query 和 /ai-query/{CODE} 路由
- 支持 URL 路径参数传递识别码
- 更新所有识别码链接为固定链接格式
- 与友链、反馈页面保持一致的实现方式
This commit is contained in:
@@ -8,6 +8,9 @@ if (!file_exists($wp_load_path)) $wp_load_path = $_SERVER['DOCUMENT_ROOT'] . '/w
|
||||
require_once($wp_load_path);
|
||||
|
||||
$query_code = isset($_GET['code']) ? sanitize_text_field($_GET['code']) : '';
|
||||
if (empty($query_code)) {
|
||||
$query_code = get_query_var('code') ? sanitize_text_field(get_query_var('code')) : '';
|
||||
}
|
||||
$result = null;
|
||||
$error = '';
|
||||
|
||||
@@ -276,7 +279,7 @@ html.darkmode .ai-verify-subtitle { color: #aaa; }
|
||||
<a href="<?php echo esc_url($result['post_url']); ?>" class="btn btn-primary">
|
||||
<?php _e('查看原文', 'argon'); ?>
|
||||
</a>
|
||||
<a href="<?php echo esc_url(get_template_directory_uri() . '/ai-summary-query.php'); ?>" class="btn btn-outline-secondary">
|
||||
<a href="<?php echo home_url('/ai-query'); ?>" class="btn btn-outline-secondary">
|
||||
<?php _e('查询其他识别码', 'argon'); ?>
|
||||
</a>
|
||||
</div>
|
||||
@@ -284,7 +287,6 @@ html.darkmode .ai-verify-subtitle { color: #aaa; }
|
||||
<h4 style="font-size: 15px; font-weight: 600; margin: 0 0 12px; color: var(--color-text-deeper);"><?php _e('功能说明', 'argon'); ?></h4>
|
||||
<ul class="ai-help-list">
|
||||
<li><?php _e('每个 AI 生成内容都有唯一的 8 位识别码,用于内容溯源', 'argon'); ?></li>
|
||||
<li><?php _e('识别码显示在文章页面的 AI 摘要底部,点击可直接跳转到本页面', 'argon'); ?></li>
|
||||
<li><?php _e('通过识别码可以查询 AI 内容的生成信息和关联文章', 'argon'); ?></li>
|
||||
<li><?php _e('识别码由数字和大写字母组成,不包含易混淆字符(I、O)', 'argon'); ?></li>
|
||||
</ul>
|
||||
|
||||
@@ -4482,12 +4482,20 @@ function argon_feedback_rewrite() {
|
||||
add_rewrite_rule('^feedback/?$', 'index.php?argon_feedback_view=1', 'top');
|
||||
}
|
||||
|
||||
// AI 查询页面 URL 重写
|
||||
add_action('init', 'argon_ai_query_rewrite');
|
||||
function argon_ai_query_rewrite() {
|
||||
add_rewrite_rule('^ai-query/?$', 'index.php?argon_ai_query=1', 'top');
|
||||
add_rewrite_rule('^ai-query/([A-Z0-9]{8})/?$', 'index.php?argon_ai_query=1&code=$matches[1]', 'top');
|
||||
}
|
||||
|
||||
// 主题激活或更新时刷新重写规则
|
||||
add_action('after_switch_theme', 'argon_flush_rewrite_rules');
|
||||
add_action('upgrader_process_complete', 'argon_flush_rewrite_rules');
|
||||
function argon_flush_rewrite_rules() {
|
||||
argon_friend_links_rewrite();
|
||||
argon_feedback_rewrite();
|
||||
argon_ai_query_rewrite();
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
||||
@@ -4495,6 +4503,7 @@ add_filter('query_vars', 'argon_friend_links_query_vars');
|
||||
function argon_friend_links_query_vars($vars) {
|
||||
$vars[] = 'argon_friend_links';
|
||||
$vars[] = 'argon_feedback_view';
|
||||
$vars[] = 'argon_ai_query';
|
||||
return $vars;
|
||||
}
|
||||
|
||||
@@ -4515,6 +4524,15 @@ function argon_feedback_template() {
|
||||
}
|
||||
}
|
||||
|
||||
// AI 查询页面路由
|
||||
add_action('template_redirect', 'argon_ai_query_template');
|
||||
function argon_ai_query_template() {
|
||||
if (get_query_var('argon_ai_query')) {
|
||||
include(get_template_directory() . '/ai-summary-query.php');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
//隐藏 admin 管理条
|
||||
//show_admin_bar(false);
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ $model_display = !empty($model) ? $model : __('未知模型', 'argon');
|
||||
<span class="ai-summary-model"><?php _e('使用模型', 'argon'); ?>: <?php echo esc_html($model_display); ?></span>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($summary_code)): ?>
|
||||
<span class="ai-summary-code"><?php _e('识别码', 'argon'); ?>: <a href="<?php echo get_template_directory_uri(); ?>/ai-summary-query.php?code=<?php echo esc_attr($summary_code); ?>"><?php echo esc_html($summary_code); ?></a></span>
|
||||
<span class="ai-summary-code"><?php _e('识别码', 'argon'); ?>: <a href="<?php echo home_url('/ai-query/' . esc_attr($summary_code)); ?>"><?php echo esc_html($summary_code); ?></a></span>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
@@ -121,7 +121,7 @@ $model_display = !empty($model) ? $model : __('未知模型', 'argon');
|
||||
footerHTML += '<span class="ai-summary-model"><?php _e('使用模型', 'argon'); ?>: ' + data.data.model + '</span>';
|
||||
}
|
||||
if (data.data.code) {
|
||||
footerHTML += '<span class="ai-summary-code"><?php _e('识别码', 'argon'); ?>: <a href="<?php echo get_template_directory_uri(); ?>/ai-summary-query.php?code=' + data.data.code + '">' + data.data.code + '</a></span>';
|
||||
footerHTML += '<span class="ai-summary-code"><?php _e('识别码', 'argon'); ?>: <a href="<?php echo home_url('/ai-query/'); ?>' + data.data.code + '">' + data.data.code + '</a></span>';
|
||||
}
|
||||
footerDiv.innerHTML = footerHTML;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user