Files
wordpress-theme-aksrt/templates/parts/single-author-bar.php
T
kate522andClaude Opus 5 f6fde18857 fix(single): align author-bar publish time with the reference
The publish time under the author name diverged from the reference in four
ways: it rendered a leading bullet from `.icon-circle`, its tooltip opened
above instead of below, its wording was "2 天发布" (WordPress'
human_time_diff has no 前 and keeps spaces), and it ignored the
「时间显示数据源」 setting entirely.

- markup: drop `.icon-circle` from the time span and the description fallback;
  add `data-placement="bottom"` so the tooltip opens below like the reference
- wording: use jio_time_ago() (which already ends in 前) and append only
  发布 / 更新, yielding "2天前发布"
- branches: mirror zib_get_post_time_tooltip exactly (date source → publish
  time; unpublished → modified time; published-with-update → modified time
  labelled 更新 while the tooltip keeps the publish time; otherwise publish)
- the setting is read from post_time_source via get_post_list_style_settings()

Tests: new author-bar-time suite drives the real template through a stub
harness across all four branches (4/4); widget suite 833/834 with the
pre-existing frontend-lifecycle failure.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-11-03 16:58:05 +08:00

130 lines
5.2 KiB
PHP

<?php
/**
* Article header author bar.
*
* Contract: get_template_part(..., null, $args)
* show_time bool Relative publish/update time (default true)
* meta_html string Prebuilt single-metabox HTML
*
* @package Jio
*/
defined('ABSPATH') || exit;
$args = is_array($args ?? null) ? $args : [];
$show_time = !array_key_exists('show_time', $args) || !empty($args['show_time']);
$meta_html = (string) ($args['meta_html'] ?? '');
$author_id = (int) get_the_author_meta('ID');
$author_name = get_the_author();
$author_url = function_exists('jio_get_user_home_url') ? jio_get_user_home_url($author_id) : get_author_posts_url($author_id);
// 时间显示:完全按参考主题 zib_get_post_time_tooltip 的分支顺序。
// 1) 数据源 date → 发布时间
// 2) 非已发布状态 → 更新时间
// 3) 更新时间 > 发布时间 → 文案用更新时间+「更新」,tooltip 仍为发布时间+「发布」
// 4) 其余 → 发布时间
$time_source = '';
if (class_exists('\Jio\Settings\Settings')) {
$list_settings = \Jio\Settings\Settings::get_post_list_style_settings();
$time_source = (string) ($list_settings['post_time_source'] ?? 'modified');
}
$is_published = (string) get_post_status(get_the_ID()) === 'publish';
$published_mysql = (string) get_the_time('Y-m-d H:i:s');
$modified_mysql = (string) get_the_modified_time('Y-m-d H:i:s');
$has_update = (int) strtotime($modified_mysql) > (int) strtotime($published_mysql);
$published_title = sprintf(__('%s发布', 'jio'), get_the_time('Y年m月d日 H:i'));
$modified_title = sprintf(__('%s更新', 'jio'), get_the_modified_time('Y年m月d日 H:i'));
if ($time_source === 'date') {
// 1) 强制发布时间源。
$time_mysql = $published_mysql;
$rel_label = __('发布', 'jio');
$abs_fmt = $published_title;
} elseif (!$is_published) {
// 2) 草稿/待审等:参考固定展示更新时间。
$time_mysql = $modified_mysql;
$rel_label = __('更新', 'jio');
$abs_fmt = $modified_title;
} elseif ($has_update) {
// 3) 已发布且有更新:文案取更新时间,tooltip 仍标注发布时间。
$time_mysql = $modified_mysql;
$rel_label = __('更新', 'jio');
$abs_fmt = $published_title;
} else {
// 4) 未更新过:发布时间。
$time_mysql = $published_mysql;
$rel_label = __('发布', 'jio');
$abs_fmt = $published_title;
}
// 相对时间本身已含「前」,只拼接「发布 / 更新」。
$time_ago = function_exists('jio_time_ago')
? jio_time_ago($time_mysql)
: human_time_diff((int) strtotime($time_mysql), (int) current_time('timestamp')) . __('前', 'jio');
$time_text = $time_ago . $rel_label;
$description = function_exists('jio_get_user_description')
? jio_get_user_description($author_id)
: trim((string) get_the_author_meta('description'));
$name_html = jio_get_user_name([
'id' => $author_id,
'class' => 'name flex ac flex1',
'name_class' => '',
'vip' => true,
'medal' => true,
'auth' => true,
'level' => true,
'follow' => false,
]);
$follow_html = jio_get_user_follow('px12-sm ml10 follow but c-red', $author_id);
$reward_button = get_current_user_id() !== $author_id && function_exists('jio_get_rewards_button')
? jio_get_rewards_button($author_id, 'ml6 but c-yellow px12-sm', get_the_ID())
: '';
?>
<div class="article-avatar">
<div class="user-info flex ac article-avatar">
<a href="<?php echo esc_url($author_url); ?>">
<span class="avatar-img">
<?php if (function_exists('jio_get_avatar_html')) : ?>
<?php echo jio_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 echo $name_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<div class="px12-sm muted-2-color text-ellipsis">
<?php if ($show_time) : ?>
<span data-toggle="tooltip" data-placement="bottom" title="<?php echo esc_attr($abs_fmt); ?>"><?php echo esc_html($time_text); ?></span>
<?php elseif ($description !== '') : ?>
<span><?php echo esc_html($description); ?></span>
<?php endif; ?>
<?php
$post_city = function_exists('jio_get_post_author_city_badge_html')
? jio_get_post_author_city_badge_html($author_id, 'badg badg-sm')
: '';
if ($post_city !== '') {
echo $post_city; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
?>
</div>
</div>
<div class="flex0 user-action">
<?php echo $follow_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php if ($reward_button !== '') : ?>
<?php echo $reward_button; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php jio_render_rewards_template_for_user($author_id, get_the_ID()); ?>
<?php endif; ?>
</div>
</div>
</div>
<div class="single-meta-row">
<i class="line-form-line" aria-hidden="true"></i>
<?php echo $meta_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</div>
</div>