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>
93 lines
4.3 KiB
PHP
93 lines
4.3 KiB
PHP
<?php
|
|
/**
|
|
* Render the author bar across the four reference time branches and report the
|
|
* time `<span>` text/title. Fixed clock so the expectations are deterministic.
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
define('ABSPATH', dirname(__DIR__, 2) . DIRECTORY_SEPARATOR);
|
|
|
|
// 固定时钟:2026-11-03 12:00:00(站点时区)。
|
|
$GLOBALS['NOW'] = strtotime('2026-11-03 12:00:00');
|
|
$GLOBALS['STATUS'] = 'publish';
|
|
$GLOBALS['SOURCE'] = 'modified';
|
|
$GLOBALS['PUBLISHED'] = strtotime('2026-10-29 08:00:00');
|
|
$GLOBALS['MODIFIED'] = strtotime('2026-10-29 08:00:00');
|
|
$GLOBALS['TIME_AGO'] = false;
|
|
|
|
function __($text): string { return (string) $text; }
|
|
function esc_html($value): string { return htmlspecialchars((string) $value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); }
|
|
function esc_attr($value): string { return esc_html($value); }
|
|
function esc_url($value): string { return (string) $value; }
|
|
function esc_url_raw($value): string { return (string) $value; }
|
|
function wp_kses_post($value): string { return (string) $value; }
|
|
|
|
function get_the_author_meta($key) { return $key === 'ID' ? 7 : '张三'; }
|
|
function get_the_author(): string { return '张三'; }
|
|
function jio_get_user_home_url($id): string { return '/u/' . (int) $id; }
|
|
function get_author_posts_url($id): string { return '/author/' . (int) $id; }
|
|
function get_post_status($post = null): string { return $GLOBALS['STATUS']; }
|
|
function get_the_time($format) { return format_time((int) $GLOBALS['PUBLISHED'], $format); }
|
|
function get_the_modified_time($format) { return format_time((int) $GLOBALS['MODIFIED'], $format); }
|
|
function current_time($type) { return $type === 'timestamp' ? (int) $GLOBALS['NOW'] : date('Y-m-d H:i:s', (int) $GLOBALS['NOW']); }
|
|
function format_time(int $timestamp, $format) {
|
|
return $format === 'U' ? (string) $timestamp : date((string) $format, $timestamp);
|
|
}
|
|
|
|
/** 与生产同一套相对时间规则,但以固定 NOW 为基准。 */
|
|
function jio_time_ago(string $date): string {
|
|
$time = (int) strtotime($date);
|
|
$diff = (int) $GLOBALS['NOW'] - $time;
|
|
$days = (int) floor($diff / 86400);
|
|
return $days > 0 ? $days . '天前' : '刚刚';
|
|
}
|
|
|
|
function human_time_diff($from, $to = 0): string { return 'x'; }
|
|
function get_the_ID(): int { return 42; }
|
|
function get_current_user_id(): int { return 0; }
|
|
function jio_get_user_description($id): string { return '作者简介'; }
|
|
function jio_get_user_name(array $args): string { return '<a class="display-name">张三</a>'; }
|
|
function jio_get_user_follow($class, $id): string { return ''; }
|
|
function jio_get_rewards_button($id, $class, $post_id): string { return ''; }
|
|
function jio_get_avatar_html($id, $size, array $args): string { return '<img>'; }
|
|
function get_avatar($id, $size, $default, $alt, array $args): string { return '<img>'; }
|
|
function jio_render_rewards_template_for_user($author_id, $post_id): void {}
|
|
function jio_get_post_author_city_badge_html($author_id, $class): string { return ''; }
|
|
|
|
class JioSettingsStub {
|
|
public static function get_post_list_style_settings(): array {
|
|
return ['post_time_source' => (string) $GLOBALS['SOURCE']];
|
|
}
|
|
}
|
|
class_alias('JioSettingsStub', 'Jio\\Settings\\Settings');
|
|
|
|
$cases = [
|
|
'date_updated' => ['publish', 'date', '2026-10-29 08:00:00', '2026-11-02 09:00:00'],
|
|
'modified_clean' => ['publish', 'modified', '2026-10-29 08:00:00', '2026-10-29 08:00:00'],
|
|
'modified_updated' => ['publish', 'modified', '2026-10-29 08:00:00', '2026-11-02 09:00:00'],
|
|
'draft' => ['draft', 'modified', '2026-10-29 08:00:00', '2026-11-02 09:00:00'],
|
|
];
|
|
|
|
$out = [];
|
|
foreach ($cases as $name => [$status, $source, $published, $modified]) {
|
|
$GLOBALS['STATUS'] = $status;
|
|
$GLOBALS['SOURCE'] = $source;
|
|
$GLOBALS['PUBLISHED'] = strtotime($published);
|
|
$GLOBALS['MODIFIED'] = strtotime($modified);
|
|
|
|
ob_start();
|
|
$args = ['show_time' => true, 'meta_html' => ''];
|
|
include ABSPATH . 'templates/parts/single-author-bar.php';
|
|
$html = (string) ob_get_clean();
|
|
|
|
$text = '';
|
|
$title = '';
|
|
if (preg_match('/<span data-toggle="tooltip" data-placement="bottom" title="([^"]*)">([^<]*)<\/span>/', $html, $m)) {
|
|
$title = html_entity_decode($m[1], ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
|
$text = html_entity_decode($m[2], ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
|
}
|
|
$out[$name] = ['text' => $text, 'title' => $title];
|
|
}
|
|
|
|
echo json_encode($out, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR);
|