feat: 邮件社交链接支持 Bilibili 和自动补全

- 在邮件设置中添加 Bilibili 社交链接输入框
- 实现社交链接自动补全功能(支持只填写用户名/UID)
- 添加 argon_normalize_social_url() 函数处理链接标准化
- 更新邮件模板基础文件支持 Bilibili 显示
- 支持的平台:Twitter、GitHub、微博、Bilibili、Facebook、Instagram
This commit is contained in:
2026-01-22 13:41:28 +08:00
parent 4543ceb045
commit e01490a0f8
3 changed files with 63 additions and 14 deletions

View File

@@ -65,8 +65,6 @@ function argon_get_email_types() {
<p style="margin: 0 0 8px 0; color: #2d3748; font-size: 14px; font-weight: 600;">审核信息</p> <p style="margin: 0 0 8px 0; color: #2d3748; font-size: 14px; font-weight: 600;">审核信息</p>
<p style="margin: 0 0 4px 0; color: #4a5568; font-size: 13px;">识别结果:<span style="color: #e53e3e; font-weight: 600;">疑似不当内容</span></p> <p style="margin: 0 0 4px 0; color: #4a5568; font-size: 13px;">识别结果:<span style="color: #e53e3e; font-weight: 600;">疑似不当内容</span></p>
<p style="margin: 0 0 4px 0; color: #4a5568; font-size: 13px;">识别理由:{{ai_spam_reason}}</p> <p style="margin: 0 0 4px 0; color: #4a5568; font-size: 13px;">识别理由:{{ai_spam_reason}}</p>
<p style="margin: 0 0 4px 0; color: #718096; font-size: 12px;">AI 模型:{{ai_model}}</p>
<p style="margin: 0 0 4px 0; color: #718096; font-size: 12px;">服务提供商:{{ai_provider}}</p>
<p style="margin: 0; color: #718096; font-size: 12px;">识别码:{{ai_detection_code}}</p> <p style="margin: 0; color: #718096; font-size: 12px;">识别码:{{ai_detection_code}}</p>
</div> </div>
<p style="margin: 0 0 20px 0; color: #525f7f; line-height: 1.6;">如果您认为这是误判,请通过识别码查询详细信息或联系网站管理员申诉。</p> <p style="margin: 0 0 20px 0; color: #525f7f; line-height: 1.6;">如果您认为这是误判,请通过识别码查询详细信息或联系网站管理员申诉。</p>
@@ -80,8 +78,6 @@ function argon_get_email_types() {
'commenter_name' => __('评论者名称', 'argon'), 'commenter_name' => __('评论者名称', 'argon'),
'comment_content' => __('评论内容', 'argon'), 'comment_content' => __('评论内容', 'argon'),
'ai_spam_reason' => __('AI 识别理由', 'argon'), 'ai_spam_reason' => __('AI 识别理由', 'argon'),
'ai_model' => __('AI 模型', 'argon'),
'ai_provider' => __('AI 服务提供商', 'argon'),
'ai_detection_code' => __('AI 识别码', 'argon'), 'ai_detection_code' => __('AI 识别码', 'argon'),
'query_url' => __('查询链接', 'argon'), 'query_url' => __('查询链接', 'argon'),
'unsubscribe_url' => __('退订链接', 'argon'), 'unsubscribe_url' => __('退订链接', 'argon'),
@@ -276,6 +272,7 @@ function argon_get_email_base_template($include_unsubscribe = false) {
'twitter' => 'Twitter', 'twitter' => 'Twitter',
'github' => 'GitHub', 'github' => 'GitHub',
'weibo' => '微博', 'weibo' => '微博',
'bilibili' => 'Bilibili',
'facebook' => 'Facebook', 'facebook' => 'Facebook',
'instagram' => 'Instagram' 'instagram' => 'Instagram'
); );

View File

@@ -8090,3 +8090,50 @@ function argon_spam_detection_trash_comment() {
} }
} }
add_action('wp_ajax_argon_spam_detection_trash_comment', 'argon_spam_detection_trash_comment'); add_action('wp_ajax_argon_spam_detection_trash_comment', 'argon_spam_detection_trash_comment');
// ==========================================================================
// 邮件社交链接自动补全
// ==========================================================================
/**
* 标准化社交链接 URL
* 支持输入完整 URL 或仅用户名/UID自动补全为完整链接
*
* @param string $platform 平台名称 (twitter, github, weibo, bilibili)
* @param string $input 用户输入(完整 URL 或用户名/UID
* @return string 标准化后的完整 URL如果输入为空则返回空字符串
*/
function argon_normalize_social_url($platform, $input) {
$input = trim($input);
// 如果输入为空,直接返回
if (empty($input)) {
return '';
}
// 如果已经是完整 URL直接返回
if (preg_match('/^https?:\/\//i', $input)) {
return esc_url($input);
}
// 根据平台补全 URL
$base_urls = [
'twitter' => 'https://twitter.com/',
'github' => 'https://github.com/',
'weibo' => 'https://weibo.com/',
'bilibili' => 'https://space.bilibili.com/',
'facebook' => 'https://facebook.com/',
'instagram' => 'https://instagram.com/'
];
if (!isset($base_urls[$platform])) {
// 未知平台,返回原始输入
return esc_url($input);
}
// 移除可能的 @ 符号前缀
$username = ltrim($input, '@');
// 构建完整 URL
return esc_url($base_urls[$platform] . $username);
}

View File

@@ -4621,17 +4621,21 @@ window.pjaxLoaded = function(){
<?php $social_links = get_option('argon_email_social_links', array()); ?> <?php $social_links = get_option('argon_email_social_links', array()); ?>
<div style="margin-bottom: 8px;"> <div style="margin-bottom: 8px;">
<label style="display: inline-block; width: 80px;">Twitter:</label> <label style="display: inline-block; width: 80px;">Twitter:</label>
<input type="text" name="argon_email_social_twitter" value="<?php echo esc_attr(isset($social_links['twitter']) ? $social_links['twitter'] : ''); ?>" placeholder="https://twitter.com/username" style="width: 300px;" /> <input type="text" name="argon_email_social_twitter" value="<?php echo esc_attr(isset($social_links['twitter']) ? $social_links['twitter'] : ''); ?>" placeholder="username" style="width: 300px;" />
</div> </div>
<div style="margin-bottom: 8px;"> <div style="margin-bottom: 8px;">
<label style="display: inline-block; width: 80px;">GitHub:</label> <label style="display: inline-block; width: 80px;">GitHub:</label>
<input type="text" name="argon_email_social_github" value="<?php echo esc_attr(isset($social_links['github']) ? $social_links['github'] : ''); ?>" placeholder="https://github.com/username" style="width: 300px;" /> <input type="text" name="argon_email_social_github" value="<?php echo esc_attr(isset($social_links['github']) ? $social_links['github'] : ''); ?>" placeholder="username" style="width: 300px;" />
</div> </div>
<div style="margin-bottom: 8px;"> <div style="margin-bottom: 8px;">
<label style="display: inline-block; width: 80px;"><?php _e('微博', 'argon');?>:</label> <label style="display: inline-block; width: 80px;"><?php _e('微博', 'argon');?>:</label>
<input type="text" name="argon_email_social_weibo" value="<?php echo esc_attr(isset($social_links['weibo']) ? $social_links['weibo'] : ''); ?>" placeholder="https://weibo.com/username" style="width: 300px;" /> <input type="text" name="argon_email_social_weibo" value="<?php echo esc_attr(isset($social_links['weibo']) ? $social_links['weibo'] : ''); ?>" placeholder="username" style="width: 300px;" />
</div> </div>
<p class="description"><?php _e('邮件页脚显示的社交链接,留空则不显示', 'argon');?></p> <div style="margin-bottom: 8px;">
<label style="display: inline-block; width: 80px;">Bilibili:</label>
<input type="text" name="argon_email_social_bilibili" value="<?php echo esc_attr(isset($social_links['bilibili']) ? $social_links['bilibili'] : ''); ?>" placeholder="UID" style="width: 300px;" />
</div>
<p class="description"><?php _e('邮件页脚显示的社交链接,留空则不显示。支持填写完整 URL 或仅填写用户名/UID将自动补全为完整链接', 'argon');?></p>
</td> </td>
</tr> </tr>
@@ -4669,7 +4673,7 @@ window.pjaxLoaded = function(){
<div style="margin-bottom: 16px;"> <div style="margin-bottom: 16px;">
<label style="display: block; margin-bottom: 4px; font-weight: 500;"><?php _e('邮件主题', 'argon');?></label> <label style="display: block; margin-bottom: 4px; font-weight: 500;"><?php _e('邮件主题', 'argon');?></label>
<input type="text" name="argon_email_template_<?php echo esc_attr($type_key); ?>_subject" <input type="text" name="argon_email_template_<?php echo esc_attr($type_key); ?>_subject"
value="<?php echo esc_attr($config['subject']); ?>" value="<?php echo esc_attr(get_option('argon_email_template_' . $type_key . '_subject', $config['default_subject'])); ?>"
placeholder="<?php echo esc_attr($config['default_subject']); ?>" placeholder="<?php echo esc_attr($config['default_subject']); ?>"
style="width: 100%;" /> style="width: 100%;" />
</div> </div>
@@ -4678,7 +4682,7 @@ window.pjaxLoaded = function(){
<label style="display: block; margin-bottom: 4px; font-weight: 500;"><?php _e('邮件内容', 'argon');?></label> <label style="display: block; margin-bottom: 4px; font-weight: 500;"><?php _e('邮件内容', 'argon');?></label>
<textarea name="argon_email_template_<?php echo esc_attr($type_key); ?>_content" <textarea name="argon_email_template_<?php echo esc_attr($type_key); ?>_content"
rows="12" style="width: 100%; font-family: monospace; font-size: 13px;" rows="12" style="width: 100%; font-family: monospace; font-size: 13px;"
placeholder="<?php echo esc_attr($config['default_content']); ?>"><?php echo esc_textarea(get_option('argon_email_template_' . $type_key . '_content', '')); ?></textarea> placeholder="<?php echo esc_attr($config['default_content']); ?>"><?php echo esc_textarea(get_option('argon_email_template_' . $type_key . '_content', $config['default_content'])); ?></textarea>
</div> </div>
<div style="margin-bottom: 16px;"> <div style="margin-bottom: 16px;">
@@ -6379,11 +6383,12 @@ function argon_update_themeoptions(){
argon_update_option('argon_email_blog_name'); argon_update_option('argon_email_blog_name');
argon_update_option('argon_email_footer_text'); argon_update_option('argon_email_footer_text');
// 保存社交链接为数组 // 保存社交链接为数组(自动补全完整 URL
$social_links = array( $social_links = array(
'twitter' => isset($_POST['argon_email_social_twitter']) ? sanitize_url($_POST['argon_email_social_twitter']) : '', 'twitter' => argon_normalize_social_url('twitter', isset($_POST['argon_email_social_twitter']) ? sanitize_text_field($_POST['argon_email_social_twitter']) : ''),
'github' => isset($_POST['argon_email_social_github']) ? sanitize_url($_POST['argon_email_social_github']) : '', 'github' => argon_normalize_social_url('github', isset($_POST['argon_email_social_github']) ? sanitize_text_field($_POST['argon_email_social_github']) : ''),
'weibo' => isset($_POST['argon_email_social_weibo']) ? sanitize_url($_POST['argon_email_social_weibo']) : '' 'weibo' => argon_normalize_social_url('weibo', isset($_POST['argon_email_social_weibo']) ? sanitize_text_field($_POST['argon_email_social_weibo']) : ''),
'bilibili' => argon_normalize_social_url('bilibili', isset($_POST['argon_email_social_bilibili']) ? sanitize_text_field($_POST['argon_email_social_bilibili']) : '')
); );
update_option('argon_email_social_links', $social_links); update_option('argon_email_social_links', $social_links);