The public user homepage cover showed a single bottom-right 粉丝 pill, which the reference theme does not render there — it shows 人气值 and 点赞 as a translucent pill group pinned to the cover's top-right corner. - Cover metas: replace 粉丝 with 人气值 (zibsvg-hot) + 点赞 (zibsvg-like), summed over the user's published posts via aksrt_get_user_posts_meta_sum() and abbreviated with aksrt_cut_count(); each is zero-suppressed independently, matching zib_get_author_header_metas() - Titles use the reference strings 人气值 N / 获得N个点赞 via data-toggle="tooltip" - CSS: adopt .single-metabox.cover-meta semantics (one rgba(0,0,0,.3) pill at right:1em/top:1.6em, 14px, 6px item gaps, 3px icon margins) plus the reference's <=480px override; drop the per-stat bottom-right pills - Drop the dead __stats / __stat / __contacts CSS blocks and the unused $tab_counts hero contract arg Follower counts remain in the content tab bar (tab_counts['follow']). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
228 lines
13 KiB
PHP
228 lines
13 KiB
PHP
<?php
|
|
/**
|
|
* Author Hero — shared hero section for author archive and public user homepage.
|
|
*
|
|
* Aligns with legacy(): cover, avatar, name, identity, desc,
|
|
* and header actions. The cover carries the 人气值 / 点赞 meta pills
|
|
* (legacy zib_get_author_header_metas); follower counts stay in the tab bar.
|
|
*
|
|
* Contract: get_template_part(..., null, $args)
|
|
* user WP_User
|
|
* dashboard array from aksrt_get_user_dashboard_view()
|
|
* user_home_settings array
|
|
* is_author_page bool
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
$args = is_array($args ?? null) ? $args : [];
|
|
$user = $args['user'] ?? null;
|
|
$dashboard = is_array($args['dashboard'] ?? null) ? $args['dashboard'] : [];
|
|
$settings = is_array($args['user_home_settings'] ?? null) ? $args['user_home_settings'] : [];
|
|
$is_author = !empty($args['is_author_page']);
|
|
|
|
if (!($user instanceof WP_User)) {
|
|
return;
|
|
}
|
|
|
|
$user_id = (int) $user->ID;
|
|
$home_url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($user) : home_url('/');
|
|
$show_cover = !array_key_exists('cover', $settings) || !empty($settings['cover']);
|
|
$show_follow = !array_key_exists('follow', $settings) || !empty($settings['follow']);
|
|
$show_avatar = !array_key_exists('avatar', $settings) || !empty($settings['avatar']);
|
|
$show_name = !array_key_exists('name', $settings) || !empty($settings['name']);
|
|
$show_desc = !array_key_exists('desc', $settings) || !empty($settings['desc']);
|
|
|
|
$profile_details = is_array($dashboard['profile_details'] ?? null) ? $dashboard['profile_details'] : [];
|
|
// Registration time is always present, so the details dialog always has
|
|
// content and the "更多资料" menu action is always available.
|
|
$registered_time = get_date_from_gmt((string) $user->user_registered, 'Y-m-d H:i:s');
|
|
$last_login_ts = (int) get_user_meta($user_id, 'aksrt_last_login', true);
|
|
$last_login_time = $last_login_ts > 0 ? wp_date('Y-m-d H:i:s', $last_login_ts) : '';
|
|
$has_more_details = $registered_time !== '' || $last_login_time !== '' || !empty($profile_details['website']) || !empty($profile_details['qq']) || !empty($profile_details['wechat']) || !empty($profile_details['github']);
|
|
$signals = $dashboard['profile_signals'] ?? [];
|
|
$show_report = !empty($dashboard['show_report']);
|
|
$bg_url = function_exists('aksrt_get_user_cover_url') ? aksrt_get_user_cover_url($user_id) : '';
|
|
$is_own = !empty($dashboard['is_own_profile']);
|
|
|
|
// 封面右上角数据条(参考主题 zib_get_author_header_metas):人气值 + 点赞,
|
|
// 粉丝数只在内容 tab 上呈现,不进入封面。
|
|
$cover_metas = [];
|
|
if (function_exists('aksrt_get_user_posts_meta_sum') && function_exists('aksrt_cut_count')) {
|
|
$view_n = aksrt_cut_count(aksrt_get_user_posts_meta_sum($user_id, 'aksrt_post_views'));
|
|
$like_n = aksrt_cut_count(aksrt_get_user_posts_meta_sum($user_id, '_aksrt_like_count'));
|
|
if ($view_n !== '' && $view_n !== '0') {
|
|
$cover_metas[] = [
|
|
'count' => $view_n,
|
|
'title' => sprintf(__('人气值 %s', 'aksrt'), $view_n),
|
|
'icon' => 'zibsvg-hot',
|
|
];
|
|
}
|
|
if ($like_n !== '' && $like_n !== '0') {
|
|
$cover_metas[] = [
|
|
'count' => $like_n,
|
|
'title' => sprintf(__('获得%s个点赞', 'aksrt'), $like_n),
|
|
'icon' => 'zibsvg-like',
|
|
];
|
|
}
|
|
}
|
|
|
|
$notification_settings = class_exists('\AKSRT\Settings\Settings')
|
|
? \AKSRT\Settings\Settings::notification_settings()
|
|
: ['enabled' => false, 'icon_show' => []];
|
|
$show_header_notification = !empty($notification_settings['enabled'])
|
|
&& in_array('user_home_header', (array) ($notification_settings['icon_show'] ?? []), true);
|
|
$messages_url = $show_header_notification && function_exists('aksrt_get_messages_page_url') ? aksrt_get_messages_page_url() : '';
|
|
$unread_count = $is_own ? aksrt_get_user_unread_notification_count($user_id) : 0;
|
|
// 封面三点菜单末项:管理员 → 禁封/解封(参考主题 author_header_drop_lists 钩子语义,
|
|
// 禁封权限优先于举报);否则 → 举报用户(保持既有契约)。
|
|
$cover_ban_html = function_exists('aksrt_get_user_cover_menu_action_html')
|
|
? aksrt_get_user_cover_menu_action_html($user_id)
|
|
: '';
|
|
// 已封禁/小黑屋用户不展示举报入口(参考主题 zib_get_report_link 排除语义)。
|
|
$target_ban_restricted = function_exists('aksrt_is_user_ban_restricted') && aksrt_is_user_ban_restricted($user_id);
|
|
$show_cover_report = $cover_ban_html === '' && $show_report && !$is_own && !$target_ban_restricted;
|
|
$show_cover_menu = $has_more_details || $show_cover_report || $cover_ban_html !== '';
|
|
?><div class="aksrt-author-hero<?php echo $show_cover ? '' : ' aksrt-author-hero--no-cover'; ?>">
|
|
<?php if ($show_cover) : ?>
|
|
<div class="aksrt-author-hero__cover">
|
|
<img<?php echo aksrt_get_lazy_attr('lazy_cover', (string) $bg_url, 'aksrt-author-hero__cover-img', aksrt_get_lazy_thumb('lg')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="">
|
|
<div class="aksrt-author-hero__cover-mask"></div>
|
|
<?php if ($cover_metas) : ?>
|
|
<div class="aksrt-author-hero__cover-metas" aria-label="<?php esc_attr_e('主页数据', 'aksrt'); ?>">
|
|
<?php foreach ($cover_metas as $cover_meta) : ?>
|
|
<span class="aksrt-author-hero__cover-meta" data-toggle="tooltip" title="<?php echo esc_attr((string) $cover_meta['title']); ?>">
|
|
<?php echo aksrt_icon_markup((string) $cover_meta['icon']); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- fixed sprite markup. ?>
|
|
<?php echo esc_html((string) $cover_meta['count']); ?>
|
|
</span>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php if ($show_cover_menu) : ?>
|
|
<div class="aksrt-cover-menu aksrt-cover-menu--author" data-aksrt-menu>
|
|
<button type="button" class="aksrt-cover-menu__trigger" aria-haspopup="true" aria-expanded="false" aria-label="<?php esc_attr_e('个人主页操作', 'aksrt'); ?>"><i class="fa fas fa-ellipsis-h" aria-hidden="true"></i></button>
|
|
<div class="aksrt-cover-menu__panel" role="menu" hidden>
|
|
<?php if ($has_more_details) : ?><button type="button" role="menuitem" data-aksrt-profile-details><i class="fa fas fa-address-card" aria-hidden="true"></i><?php esc_html_e('更多资料', 'aksrt'); ?></button><?php endif; ?>
|
|
<?php if ($show_cover_report) : ?>
|
|
<?php
|
|
// 统一举报契约:report.js 弹窗展示被举报对象(头像 + 名称)。
|
|
$report_payload = [
|
|
'target_type' => 'user',
|
|
'target_id' => $user_id,
|
|
'target_name' => $user->display_name,
|
|
'target_avatar' => get_avatar_url($user_id, ['size' => 40]),
|
|
];
|
|
?>
|
|
<?php if (is_user_logged_in()) : ?><button type="button" role="menuitem" data-aksrt-report="<?php echo esc_attr(wp_json_encode($report_payload)); ?>"><i class="fa fas fa-flag" aria-hidden="true"></i><?php esc_html_e('举报用户', 'aksrt'); ?></button>
|
|
<?php else : ?><a role="menuitem" href="<?php echo esc_url(aksrt_get_login_url($home_url)); ?>"><i class="fa fas fa-flag" aria-hidden="true"></i><?php esc_html_e('举报用户', 'aksrt'); ?></a><?php endif; ?>
|
|
<?php endif; ?>
|
|
<?php
|
|
// 禁封/解封入口(user-ban.js 的 [data-aksrt-ban] 委托)。
|
|
echo $cover_ban_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- helper escapes internally.
|
|
?>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="aksrt-author-hero__body">
|
|
<?php if ($show_avatar) : ?>
|
|
<div class="aksrt-author-hero__avatar">
|
|
<?php
|
|
if (function_exists('aksrt_get_avatar_html')) {
|
|
echo aksrt_get_avatar_html($user_id, 120, ['loading' => 'lazy']); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
|
} else {
|
|
echo get_avatar($user_id, 120, '', $user->display_name); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
|
}
|
|
?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="aksrt-author-hero__info">
|
|
<?php if ($show_name) : ?>
|
|
<h1 class="aksrt-author-hero__name">
|
|
<?php if (function_exists('aksrt_get_user_name')) : ?>
|
|
<?php echo aksrt_get_user_name(['id' => $user_id, 'class' => 'aksrt-author-hero__name-inner', 'vip' => true, 'medal' => false, 'auth' => true, 'level' => true, 'follow' => false]); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
|
<?php else : ?>
|
|
<?php echo esc_html($user->display_name); ?>
|
|
<?php endif; ?>
|
|
</h1>
|
|
<?php endif; ?>
|
|
|
|
<?php
|
|
// 治理状态徽章占据身份行元信息位(参考主题 author_header_identity 钩子:
|
|
// 红=违规已封号 / 黄=小黑屋禁封中 / 灰=禁言中,字段与颜色统一管理)。
|
|
$ban_badge = function_exists('aksrt_get_user_ban_identity_badge')
|
|
? aksrt_get_user_ban_identity_badge($user_id)
|
|
: '';
|
|
// legacy parity: the badge overview leads the identity row.
|
|
$city_badge = function_exists('aksrt_get_user_city_badge_html')
|
|
? aksrt_get_user_city_badge_html($user_id, 'user_home', 'badg')
|
|
: '';
|
|
$medal_entry = function_exists('aksrt_render_user_medal_entry')
|
|
? aksrt_render_user_medal_entry($user_id, 'user-home', $is_own)
|
|
: '';
|
|
?>
|
|
<?php if ($ban_badge !== '' || $medal_entry !== '' || $city_badge !== '') : ?>
|
|
<div class="aksrt-author-hero__identity user-identity flex ac hh">
|
|
<?php echo $ban_badge; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- helper escapes internally. ?>
|
|
<?php echo $medal_entry; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
|
<?php echo $city_badge; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php $user_description = function_exists('aksrt_get_user_description') ? aksrt_get_user_description($user_id) : (string) $user->description; ?>
|
|
<?php if ($show_desc && $user_description !== '') : ?>
|
|
<p class="aksrt-author-hero__desc"><?php echo esc_html($user_description); ?></p>
|
|
<?php endif; ?>
|
|
|
|
</div>
|
|
|
|
<div class="aksrt-author-hero__actions">
|
|
<?php if ($is_own) : ?>
|
|
<a href="<?php echo esc_url(aksrt_get_user_center_url()); ?>" class="btn-primary btn-sm">
|
|
<i class="fa fas fa-user" aria-hidden="true"></i>
|
|
<span><?php esc_html_e('用户中心', 'aksrt'); ?></span>
|
|
</a>
|
|
<?php if ($messages_url !== '') : ?>
|
|
<a href="<?php echo esc_url($messages_url); ?>" class="btn-ghost btn-sm btn-icon aksrt-author-hero__message-btn" aria-label="<?php esc_attr_e('消息通知', 'aksrt'); ?>" title="<?php esc_attr_e('消息通知', 'aksrt'); ?>">
|
|
<i class="fa fas fa-bell" aria-hidden="true"></i>
|
|
<?php if ($unread_count > 0) : ?>
|
|
<span class="aksrt-author-hero__action-badge"><?php echo esc_html((string) $unread_count); ?></span>
|
|
<?php endif; ?>
|
|
</a>
|
|
<?php endif; ?>
|
|
<?php else : ?>
|
|
<?php if ($show_follow) : ?>
|
|
<?php echo aksrt_get_user_follow('btn-outline btn-sm aksrt-author-hero__follow-btn', (int) $user_id, null, null, __('登录后关注', 'aksrt')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
|
<?php endif; ?>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($is_author && function_exists('aksrt_render_admin_quick_link')) { aksrt_render_admin_quick_link('page-display/user-home', __('用户主页设置', 'aksrt')); } ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($has_more_details) : ?>
|
|
<div class="aksrt-profile-details-modal" id="aksrt-profile-details-modal" hidden role="dialog" aria-modal="true" aria-labelledby="aksrt-profile-details-title">
|
|
<div class="aksrt-profile-details-modal__backdrop" data-aksrt-modal-close></div>
|
|
<div class="aksrt-profile-details-modal__dialog" tabindex="-1">
|
|
<button type="button" class="aksrt-profile-details-modal__close" data-aksrt-modal-close aria-label="<?php esc_attr_e('关闭', 'aksrt'); ?>">×</button>
|
|
<h2 id="aksrt-profile-details-title"><?php esc_html_e('更多资料', 'aksrt'); ?></h2>
|
|
<dl>
|
|
<?php $verify_state = is_array($dashboard['verify_state'] ?? null) ? $dashboard['verify_state'] : []; ?>
|
|
<?php if (($verify_state['state'] ?? '') !== '' && ($verify_state['label'] ?? '') !== '') : ?><div><dt><?php esc_html_e('认证', 'aksrt'); ?></dt><dd><?php echo esc_html((string) $verify_state['label']); ?></dd></div><?php endif; ?>
|
|
<?php if (!empty($profile_details['gender'])) : ?><div><dt><?php esc_html_e('性别', 'aksrt'); ?></dt><dd><?php echo esc_html($profile_details['gender'] === 'male' ? __('男', 'aksrt') : __('女', 'aksrt')); ?></dd></div><?php endif; ?>
|
|
<?php if (!empty($profile_details['website'])) : ?><div><dt><?php esc_html_e('个人网站', 'aksrt'); ?></dt><dd><a href="<?php echo esc_url($profile_details['website']); ?>" target="_blank" rel="noopener noreferrer"><?php echo esc_html($profile_details['website']); ?></a></dd></div><?php endif; ?>
|
|
<?php if (!empty($profile_details['github'])) : ?><div><dt>GitHub</dt><dd><a href="<?php echo esc_url($profile_details['github']); ?>" target="_blank" rel="noopener noreferrer"><?php echo esc_html($profile_details['github']); ?></a></dd></div><?php endif; ?>
|
|
<?php if (!empty($profile_details['qq'])) : ?><div><dt>QQ</dt><dd><?php echo esc_html($profile_details['qq']); ?></dd></div><?php endif; ?>
|
|
<?php if (!empty($profile_details['wechat'])) : ?><div><dt><?php esc_html_e('微信', 'aksrt'); ?></dt><dd><?php echo esc_html($profile_details['wechat']); ?></dd></div><?php endif; ?>
|
|
<?php if ($registered_time !== '') : ?><div><dt><?php esc_html_e('注册时间', 'aksrt'); ?></dt><dd><?php echo esc_html($registered_time); ?></dd></div><?php endif; ?>
|
|
<?php if ($last_login_time !== '') : ?><div><dt><?php esc_html_e('最后登录', 'aksrt'); ?></dt><dd><?php echo esc_html($last_login_time); ?></dd></div><?php endif; ?>
|
|
</dl>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|