feat(single): identity chips, comment 神评, reward open from author bar
Share VIP/verify/level/badge chrome via aksrt-identity helpers on author bar, author card, and comments; mark hot comments; open reward modal from author actions; admin threshold for 神评; task list go-to actions.
This commit is contained in:
1 parent
a0748c08fe
commit
defb64fd89
9 files changed
+166
-26
No files matched your search
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* Shared identity chrome: VIP / verify / level / badges for author bar & comments.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
if (!function_exists('aksrt_get_user_identity_signals')) {
|
||||
/**
|
||||
* @return list<array{type:string,label:string,icon:string,tone:string,title?:string}>
|
||||
*/
|
||||
function aksrt_get_user_identity_signals(int $user_id): array {
|
||||
if ($user_id <= 0) {
|
||||
return [];
|
||||
}
|
||||
if (class_exists('AKSRT_User_Home')) {
|
||||
$signals = AKSRT_User_Home::get_instance()->get_profile_signals($user_id);
|
||||
return is_array($signals) ? array_values($signals) : [];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_render_user_identity_chips')) {
|
||||
/**
|
||||
* Render compact identity chips (verify / level / badges).
|
||||
*
|
||||
* @param int $user_id
|
||||
* @param string $context author|comment|card
|
||||
*/
|
||||
function aksrt_render_user_identity_chips(int $user_id, string $context = 'author'): string {
|
||||
if ($user_id <= 0) {
|
||||
return '';
|
||||
}
|
||||
$html = '';
|
||||
if (function_exists('aksrt_render_vip_badge')) {
|
||||
$vip = aksrt_render_vip_badge($user_id, 'sm');
|
||||
if (is_string($vip) && $vip !== '') {
|
||||
$html .= $vip;
|
||||
}
|
||||
}
|
||||
$signals = aksrt_get_user_identity_signals($user_id);
|
||||
$limit = $context === 'comment' ? 3 : 6;
|
||||
$n = 0;
|
||||
foreach ($signals as $signal) {
|
||||
if ($n >= $limit) {
|
||||
break;
|
||||
}
|
||||
$label = trim((string) ($signal['label'] ?? ''));
|
||||
if ($label === '') {
|
||||
continue;
|
||||
}
|
||||
$tone = sanitize_html_class((string) ($signal['tone'] ?? 'info'));
|
||||
$icon = sanitize_html_class((string) ($signal['icon'] ?? 'check'));
|
||||
// Font Awesome: map short names to fa-* if needed.
|
||||
if ($icon !== '' && !str_contains($icon, 'fa-')) {
|
||||
$icon = 'fa-' . $icon;
|
||||
}
|
||||
$title = (string) ($signal['title'] ?? $label);
|
||||
$html .= '<span class="badg badg-sm ml3 aksrt-identity-chip aksrt-identity-chip--' . esc_attr($tone) . ' aksrt-identity-chip--' . esc_attr($context) . '" title="' . esc_attr($title) . '">';
|
||||
if ($icon !== '') {
|
||||
$html .= '<i class="fa ' . esc_attr($icon) . '" aria-hidden="true"></i> ';
|
||||
}
|
||||
$html .= esc_html($label) . '</span>';
|
||||
$n++;
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_is_blog_comment_hot')) {
|
||||
/**
|
||||
* "神评" for ordinary post comments when likes cross threshold.
|
||||
*/
|
||||
function aksrt_is_blog_comment_hot($comment): bool {
|
||||
$comment_id = $comment instanceof WP_Comment ? (int) $comment->comment_ID : (int) $comment;
|
||||
if ($comment_id <= 0) {
|
||||
return false;
|
||||
}
|
||||
if ('1' === (string) get_comment_meta($comment_id, '_aksrt_comment_hot', true)) {
|
||||
return true;
|
||||
}
|
||||
$threshold = 10;
|
||||
if (class_exists('AKSRT_Settings') && method_exists('AKSRT_Settings', 'get_comment_display_settings')) {
|
||||
$display = AKSRT_Settings::get_comment_display_settings();
|
||||
if (isset($display['hot_threshold'])) {
|
||||
$threshold = max(1, (int) $display['hot_threshold']);
|
||||
}
|
||||
}
|
||||
$all = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_all() : [];
|
||||
if (isset($all['comment_hot_threshold'])) {
|
||||
$threshold = max(1, (int) $all['comment_hot_threshold']);
|
||||
}
|
||||
$likes = function_exists('aksrt_get_comment_likes') ? aksrt_get_comment_likes($comment_id) : (int) get_comment_meta($comment_id, 'aksrt_comment_likes', true);
|
||||
if ($likes < $threshold) {
|
||||
return false;
|
||||
}
|
||||
update_comment_meta($comment_id, '_aksrt_comment_hot', '1');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user