175 lines
7.6 KiB
PHP
175 lines
7.6 KiB
PHP
<?php
|
|
/**
|
|
* Shared author info bar for single post content (Zibll article-avatar / user-info).
|
|
*
|
|
* Contract: get_template_part(..., null, $args)
|
|
* show_actions bool Follow / PM buttons + meta row
|
|
* show_bio bool Append bio after time
|
|
* show_time bool Relative publish/update time (default true)
|
|
* meta_html string Prebuilt Zibll single-metabox HTML
|
|
* meta_items array Legacy text meta items (fallback)
|
|
* extra_class string
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
$args = is_array($args ?? null) ? $args : [];
|
|
$extra_class = (string) ($args['extra_class'] ?? '');
|
|
$show_actions = !empty($args['show_actions']);
|
|
$show_bio = !empty($args['show_bio']);
|
|
$show_time = !array_key_exists('show_time', $args) || !empty($args['show_time']);
|
|
$meta_html = (string) ($args['meta_html'] ?? '');
|
|
$meta_items = is_array($args['meta_items'] ?? null) ? array_values(array_filter($args['meta_items'], static function ($meta_item) {
|
|
if (is_array($meta_item)) {
|
|
return !empty($meta_item['text']);
|
|
}
|
|
return is_string($meta_item) && $meta_item !== '';
|
|
})) : [];
|
|
|
|
$author_id = (int) get_the_author_meta('ID');
|
|
$author_name = get_the_author();
|
|
$author_url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($author_id) : get_author_posts_url($author_id);
|
|
$modified_ts = (int) get_the_modified_time('U');
|
|
$published_ts = (int) get_the_time('U');
|
|
$now = (int) current_time('timestamp');
|
|
$use_modified = $modified_ts > $published_ts;
|
|
$rel_base = $use_modified ? $modified_ts : $published_ts;
|
|
$rel_label = $use_modified ? __('更新', 'aksrt') : __('发布', 'aksrt');
|
|
$abs_fmt = $use_modified
|
|
? sprintf(__('%s更新', 'aksrt'), get_the_modified_time('Y年m月d日 H:i'))
|
|
: sprintf(__('%s发布', 'aksrt'), get_the_time('Y年m月d日 H:i'));
|
|
$time_text = human_time_diff($rel_base, $now) . $rel_label;
|
|
|
|
$classes = trim('article-avatar ' . $extra_class);
|
|
$aksrt_pm_on = class_exists('\AKSRT\Settings\Settings') && !empty(\AKSRT\Settings\Settings::private_message_settings()['enabled']);
|
|
$aksrt_msg_url = function_exists('aksrt_get_messages_page_url') ? aksrt_get_messages_page_url() : '';
|
|
$login_url = function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url(get_permalink());
|
|
$is_self = is_user_logged_in() && get_current_user_id() === $author_id;
|
|
|
|
// Identity: prefer aksrt_get_user_name (Zibll order); fall back to chips.
|
|
$identity_chips = '';
|
|
$name_html = '';
|
|
if (function_exists('aksrt_get_user_name')) {
|
|
$name_html = aksrt_get_user_name([
|
|
'id' => $author_id,
|
|
'class' => 'name flex ac flex1',
|
|
'name_class' => '',
|
|
'vip' => true,
|
|
'medal' => true,
|
|
'auth' => true,
|
|
'level' => true,
|
|
'follow' => false,
|
|
]);
|
|
} elseif (function_exists('aksrt_render_user_identity_chips')) {
|
|
$identity_chips = aksrt_render_user_identity_chips($author_id, 'author');
|
|
}
|
|
?>
|
|
|
|
<div class="<?php echo esc_attr($classes); ?>">
|
|
<div class="user-info flex ac article-avatar">
|
|
<a href="<?php echo esc_url($author_url); ?>">
|
|
<span class="avatar-img">
|
|
<?php if (function_exists('aksrt_get_avatar_html')) : ?>
|
|
<?php echo aksrt_get_avatar_html($author_id, 42, ['class' => 'avatar avatar-id-' . $author_id]); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
|
<?php else : ?>
|
|
<?php echo get_avatar($author_id, 42, '', esc_attr($author_name), ['class' => 'avatar avatar-id-' . $author_id]); ?>
|
|
<?php endif; ?>
|
|
</span>
|
|
</a>
|
|
<div class="user-right flex flex1 ac jsb ml10">
|
|
<div class="flex1">
|
|
<?php if ($name_html !== '') : ?>
|
|
<?php echo $name_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
|
<?php else : ?>
|
|
<span class="name flex ac flex1">
|
|
<a class="display-name text-ellipsis" href="<?php echo esc_url($author_url); ?>"><?php echo esc_html($author_name); ?></a>
|
|
<?php if ($identity_chips !== '') : ?>
|
|
<?php echo $identity_chips; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
|
<?php endif; ?>
|
|
</span>
|
|
<?php endif; ?>
|
|
<div class="px12-sm muted-2-color text-ellipsis">
|
|
<?php if ($show_time) : ?>
|
|
<span class="icon-circle" title="<?php echo esc_attr($abs_fmt); ?>" data-toggle="tooltip"><?php echo esc_html($time_text); ?></span>
|
|
<?php endif; ?>
|
|
<?php
|
|
// Article detail IP 归属地 (extension display: post).
|
|
$post_city = function_exists('aksrt_get_post_author_city_badge_html')
|
|
? aksrt_get_post_author_city_badge_html($author_id, 'badg badg-sm')
|
|
: '';
|
|
if ($post_city !== '') {
|
|
echo $post_city; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
|
}
|
|
?>
|
|
<?php if ($show_bio) : ?>
|
|
<?php $bio = trim((string) get_the_author_meta('description')); ?>
|
|
<?php if ($bio !== '') : ?>
|
|
<span class="icon-circle"><?php echo esc_html($bio); ?></span>
|
|
<?php endif; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<?php if ($show_actions) : ?>
|
|
<div class="flex0 user-action">
|
|
<?php if (!$is_self) : ?>
|
|
<?php if (is_user_logged_in()) : ?>
|
|
<button type="button" class="px12-sm ml10 follow but c-red" data-aksrt-follow="<?php echo (int) $author_id; ?>">
|
|
<i class="fa fa-heart em09" aria-hidden="true"></i> <span><?php esc_html_e('关注', 'aksrt'); ?></span>
|
|
</button>
|
|
<?php if ($aksrt_pm_on && $aksrt_msg_url !== '') : ?>
|
|
<a href="<?php echo esc_url(add_query_arg('msg_type', 'conversation', $aksrt_msg_url)); ?>" class="ml6 but c-blue px12-sm">
|
|
<i class="fa fa-comment em09" aria-hidden="true"></i> <?php esc_html_e('私信', 'aksrt'); ?>
|
|
</a>
|
|
<?php else : ?>
|
|
<?php
|
|
$aksrt_post_settings = class_exists('\AKSRT\Settings\Settings') && method_exists('\AKSRT\Settings\Settings', 'get_post_page_settings')
|
|
? \AKSRT\Settings\Settings::get_post_page_settings()
|
|
: [];
|
|
$rewards_on = !empty($aksrt_post_settings['rewards_enabled'])
|
|
|| !empty($aksrt_post_settings['post_rewards_enabled'])
|
|
|| !empty($aksrt_post_settings['post_rewards_s']);
|
|
?>
|
|
<?php if ($rewards_on) : ?>
|
|
<button type="button" class="ml6 but c-yellow px12-sm" data-aksrt-reward-open>
|
|
<i class="fa fa-gift em09" aria-hidden="true"></i> <?php esc_html_e('赞赏', 'aksrt'); ?>
|
|
</button>
|
|
<?php endif; ?>
|
|
<?php endif; ?>
|
|
<?php else : ?>
|
|
<a href="<?php echo esc_url($login_url); ?>" class="px12-sm ml10 follow but c-red">
|
|
<i class="fa fa-heart em09" aria-hidden="true"></i> <?php esc_html_e('关注', 'aksrt'); ?>
|
|
</a>
|
|
<?php endif; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($show_actions) : ?>
|
|
<div class="relative">
|
|
<i class="line-form-line" aria-hidden="true"></i>
|
|
<?php if ($meta_html !== '') : ?>
|
|
<?php echo $meta_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
|
<?php elseif (!empty($meta_items)) : ?>
|
|
<div class="flex ac single-metabox abs-right">
|
|
<div class="post-metas">
|
|
<?php foreach ($meta_items as $meta_item) : ?>
|
|
<?php
|
|
$meta_text = is_array($meta_item) ? (string) ($meta_item['text'] ?? '') : (string) $meta_item;
|
|
$meta_icon = is_array($meta_item) ? (string) ($meta_item['icon'] ?? '') : '';
|
|
if ($meta_text === '') {
|
|
continue;
|
|
}
|
|
?>
|
|
<span class="item meta-view"><?php if ($meta_icon !== '') : ?><i class="<?php echo esc_attr($meta_icon); ?>" aria-hidden="true"></i> <?php endif; ?><?php echo esc_html($meta_text); ?></span>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|