木漏茶室源码下载中心
整站 PHP 源码:可浏览文件、复制路径、下载单文件或打包 ZIP。
发布版本 v6.25.231
升级后自动生成独立源码包,下载中心只发送这份冻结包
已排除 config.php / 用户数据 / 上传文件 / 升级备份
COMMUNITY DEPLOYMENTS
已经跑起来的木漏茶室
从源码下载中心下载、完成安装并回传验证的站外站点。每个站点只计 1 次部署下载量;已记录站点会实时读取名称、版本、Logo 与在线状态,本机、内网和证书异常站点无法完成回传。
实时检测
2
个站点已部署
木
木漏茶室
mlcs.xnn.lol · v6.25.232
访问 ↗
2026.11.21
在线
木
木漏茶室
mlcs.nbnb.mom · v6.25.231
访问 ↗
2026.11.20
在线
已展示全部 2 个站点。
pages/home.php
25.5 KB · 发布包 v6.25.231
<?php
/**
* 首页:横幅 / 轮播 / 统计 / 板块筛选 / 搜索 / 帖子列表
*/
$me = current_user();
if ($_SERVER['REQUEST_METHOD'] === 'POST' && input('act') === 'set_lang') {
check_csrf();
km_set_language(input('lang', 'zh-CN'));
flash('界面语言已切换');
redirect(page_url('home'));
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && input('act') === 'checkin') {
check_csrf();
if (!$me) {
redirect(page_url('login'));
}
feature_guard('checkin');
list($ok, $msg) = perform_checkin($me);
flash($msg, $ok ? 'ok' : 'err');
redirect(page_url('home'));
}
$checkedToday = $me && (string) ($me['last_checkin'] ?? '') === date('Y-m-d');
$siteName = setting('site_name', '木漏茶室');
$noticeBanner = announcement_latest_active('banner');
$heroKicker = setting('hero_kicker', 'KOMOREBI TEA HOUSE');
$heroTitle = setting('hero_title') !== '' ? setting('hero_title') : $siteName;
$heroSubtitle = setting('hero_subtitle') !== '' ? setting('hero_subtitle') : setting('site_intro', '一室茶香,半窗霜雪。');
$catId = (int) input('cat', 0);
$keyword = trim((string) input('q', ''));
$filter = strtolower(trim((string) input('filter', '')));
if ($filter === '' && input('featured') === '1') {
$filter = 'featured';
}
$allowedFilters = ['all', 'featured', 'top', 'hot', 'friends', 'following', 'newreply', 'newpost'];
if (!in_array($filter, $allowedFilters, true)) {
$filter = 'all';
}
$featured = $filter === 'featured';
$filterParams = $filter !== 'all' && $filter !== 'featured' ? ['filter' => $filter] : [];
if ($filter === 'friends' || $filter === 'following') {
if (!$me) {
flash('登录后才能查看关注 / 好友帖子', 'err');
redirect(page_url('home'));
}
if ($filter === 'friends') { feature_guard('friends'); }
}
$tag = trim((string) input('tag', ''));
$where = ['p.status = 1', post_author_only_filter('p', $me)];
$params = [];
if ($featured) {
$where[] = 'p.is_featured = 1';
}
if ($filter === 'top') {
$where[] = 'p.is_top = 1';
}
if ($filter === 'friends') {
$where[] = 'p.user_id IN (SELECT friend_id FROM ' . DB::table('friends') . ' WHERE user_id = ?)';
$params[] = (int) $me['id'];
}
if ($filter === 'following') {
$where[] = "(p.user_id IN (SELECT target_id FROM " . DB::table('follows') . " WHERE follower_id = ? AND target_type = 'user')
OR p.cat_id IN (SELECT target_id FROM " . DB::table('follows') . " WHERE follower_id = ? AND target_type = 'category'))";
$params[] = (int) $me['id'];
$params[] = (int) $me['id'];
}
if ($me) {
$blockedIds = blocked_user_ids((int) $me['id']);
if ($blockedIds) {
$where[] = 'p.user_id NOT IN (' . implode(',', array_map('intval', $blockedIds)) . ')';
}
}
if ($tag !== '') {
$where[] = '(p.tags = ? OR p.tags LIKE ? OR p.tags LIKE ? OR p.tags LIKE ?)';
$params[] = $tag;
$params[] = $tag . ',%';
$params[] = '%,' . $tag;
$params[] = '%,' . $tag . ',%';
}
if ($filter === 'newreply') {
$where[] = 'EXISTS (SELECT 1 FROM ' . DB::table('comments') . ' rc WHERE rc.post_id = p.id AND rc.status = 1)';
}
if ($catId > 0) {
$where[] = 'p.cat_id = ?';
$params[] = $catId;
}
if ($keyword !== '') {
$where[] = '(p.title LIKE ? OR p.content LIKE ?)';
$params[] = '%' . $keyword . '%';
$params[] = '%' . $keyword . '%';
}
$whereSql = implode(' AND ', $where);
$total = (int) DB::val('SELECT COUNT(*) FROM ' . DB::table('posts') . " p WHERE $whereSql", $params, 0);
$pager = paginate($total, 10);
$orderSql = 'p.is_top DESC, p.top_at DESC, p.id DESC';
if ($filter === 'top') {
$orderSql = 'p.top_at DESC, p.id DESC';
} elseif ($filter === 'hot') {
$orderSql = 'p.views DESC, p.id DESC';
} elseif ($filter === 'newpost') {
$orderSql = 'p.id DESC';
}
$postSelect = 'SELECT p.*, u.nickname, u.username, u.avatar, u.gender, u.verified, u.verify_style, u.verify_title, u.verify_type, u.province, u.city, u.district, u.town, u.village, u.show_location, u.last_ip, c.name AS cat_name';
if ($filter === 'newreply') {
$posts = DB::all(
$postSelect . ',
lc.id AS last_comment_id, lc.content AS last_comment_content, lc.created_at AS last_comment_at,
cu.id AS last_commenter_id, cu.nickname AS last_commenter_nickname, cu.username AS last_commenter_username,
cu.avatar AS last_commenter_avatar, cu.gender AS last_commenter_gender, cu.role AS last_commenter_role,
cu.verified AS last_commenter_verified, cu.verify_style AS last_commenter_verify_style, cu.verify_title AS last_commenter_verify_title
FROM ' . DB::table('posts') . ' p
INNER JOIN (
SELECT c1.* FROM ' . DB::table('comments') . ' c1 WHERE c1.status = 1
INNER JOIN (SELECT post_id, MAX(id) AS mid FROM ' . DB::table('comments') . ' WHERE status = 1 GROUP BY post_id) lm ON lm.mid = c1.id
) lc ON lc.post_id = p.id
LEFT JOIN ' . DB::table('users') . ' u ON u.id = p.user_id
LEFT JOIN ' . DB::table('users') . ' cu ON cu.id = lc.user_id
LEFT JOIN ' . DB::table('categories') . ' c ON c.id = p.cat_id
WHERE ' . $whereSql . '
ORDER BY lc.id DESC
LIMIT ' . $pager['limit'] . ' OFFSET ' . $pager['offset'],
$params
);
} else {
$posts = DB::all(
$postSelect . '
FROM ' . DB::table('posts') . ' p
LEFT JOIN ' . DB::table('users') . ' u ON u.id = p.user_id
LEFT JOIN ' . DB::table('categories') . ' c ON c.id = p.cat_id
WHERE ' . $whereSql . '
ORDER BY ' . $orderSql . '
LIMIT ' . $pager['limit'] . ' OFFSET ' . $pager['offset'],
$params
);
}
$categories = DB::all('SELECT * FROM ' . DB::table('categories') . ' ORDER BY sort ASC, id ASC');
$stats = [
'posts' => DB::count('posts', 'status = 1'),
'users' => DB::count('users', 'status = 1'),
'comments' => (int) DB::val('SELECT COUNT(*) FROM ' . DB::table('comments') . ' c INNER JOIN ' . DB::table('posts') . ' p ON p.id = c.post_id WHERE p.status = 1 AND c.status = 1'),
];
$quoteRows = quote_pool(100);
if (!$quoteRows) {
$fallback = trim((string) setting('daily_quote', ''));
$quoteRows = $fallback !== '' ? [['content' => $fallback, 'source' => 'setting']] : [];
}
$quote = $quoteRows ? $quoteRows[0]['content'] : '';
$slides = DB::all('SELECT * FROM ' . DB::table('carousel') . ' WHERE status = 1 ORDER BY sort ASC, id ASC');
$banner = setting('site_banner', '');
if ($banner === '') {
// 兼容旧版:三端分离时只上传过平板或手机的站点,升级后仍能显示。
$banner = setting('site_banner_tablet', '');
if ($banner === '') {
$banner = setting('site_banner_mobile', '');
}
}
$heroHasImage = true;
$heroImageSrc = base_url('assets/img/home-hero-aurora.jpg');
$heroMobileHeight = (int) setting('site_banner_mobile_height', 196);
$heroMobileHeight = max(196, min(300, $heroMobileHeight));
$liveCity = trim((string) ($me['city'] ?? ''));
$liveRegion = trim((string) ($me['province'] ?? ''));
if ($liveCity === '') {
$loc = ip_location(client_ip());
$liveCity = trim((string) ($loc['city'] ?? ''));
$liveRegion = trim((string) ($loc['region'] ?? $liveRegion));
}
// 节日倒计时:当天优先显示祝福,其他时间显示距下一个节日。
$holidayStatus = site_holiday_status();
$holiday = $holidayStatus['holiday'] ?? null;
$holidayIsToday = !empty($holidayStatus['is_today']);
$holidayTarget = (int) ($holidayStatus['target'] ?? 0);
$holidayLeft = max(0, (int) ($holidayStatus['left'] ?? 0));
$holidayDays = (int) floor($holidayLeft / 86400);
$holidayHours = (int) floor(($holidayLeft % 86400) / 3600);
$holidayMinutes = (int) floor(($holidayLeft % 3600) / 60);
$holidaySeconds = (int) ($holidayLeft % 60);
render_header('', ['stats' => $stats]);
?>
<?= plugin_hook('home_top') ?>
<?php if ($noticeBanner):
$nbBubble = announcement_banner_bubble_key($noticeBanner['banner_bubble'] ?? 'tea');
$nbFontKey = announcement_banner_font_key($noticeBanner['banner_font'] ?? 'default');
$nbWidth = announcement_banner_width($noticeBanner['banner_width'] ?? 100);
$nbFace = announcement_banner_font_face($noticeBanner);
$nbStyle = '--nb-width:' . $nbWidth . '%;font-family:' . announcement_banner_font_stack($noticeBanner);
foreach (['bg1' => '--nb-bg1', 'bg2' => '--nb-bg2'] as $nk => $nvar) {
$hex = announcement_banner_hex($noticeBanner['banner_' . $nk] ?? '');
if ($hex !== '') { $nbStyle .= ';' . $nvar . ':' . $hex; }
}
$nbText = announcement_banner_hex($noticeBanner['banner_text'] ?? '');
if ($nbText !== '') { $nbStyle .= ';--nb-ink:' . $nbText; }
?>
<?php if ($nbFace): ?><style><?= $nbFace ?></style><?php endif; ?>
<section class="notice-marquee notice-bubble-<?= e($nbBubble) ?> notice-font-<?= e($nbFontKey) ?>" id="homeNoticeMarquee" data-id="<?= (int) $noticeBanner['id'] ?>" data-dismiss-key="km_banner_close_<?= (int) $noticeBanner['id'] ?>" data-closable="<?= (int) ($noticeBanner['banner_closable'] ?? 1) ?>" style="<?= e($nbStyle) ?>">
<div class="notice-marquee-viewport">
<div class="notice-marquee-track" style="animation-duration:<?= (int) announcement_banner_speed($noticeBanner['speed']) ?>s;animation-iteration-count:<?= (int) ($noticeBanner['banner_loop'] ?? 1) === 1 ? 'infinite' : '1' ?>;animation-fill-mode:<?= (int) ($noticeBanner['banner_loop'] ?? 1) === 1 ? 'none' : 'forwards' ?>">
<div class="notice-marquee-content"><?= announcement_content_html($noticeBanner) ?></div>
</div>
</div>
<?php if ((int) ($noticeBanner['banner_closable'] ?? 1) === 1): ?>
<button class="notice-marquee-close" type="button" aria-label="关闭滚动公告">×</button>
<?php endif; ?>
</section>
<script>
(function () {
var bar = document.getElementById('homeNoticeMarquee');
if (!bar) return;
var closable = bar.dataset.closable === '1';
try {
if (closable && localStorage.getItem(bar.dataset.dismissKey) === '1') { bar.remove(); return; }
if (!closable) localStorage.removeItem(bar.dataset.dismissKey);
} catch (e) {}
var close = bar.querySelector('.notice-marquee-close');
if (close && closable) close.addEventListener('click', function () {
try { localStorage.setItem(bar.dataset.dismissKey, '1'); } catch (e) {}
bar.remove();
});
})();
</script>
<?php endif; ?>
<?php $heroMobileCompact = $heroMobileHeight < 195; $heroMobileTight = $heroMobileHeight < 172; ?>
<section class="hero hero-aurora has-image<?= $heroMobileCompact ? ' hero-mobile-compact' : '' ?><?= $heroMobileTight ? ' hero-mobile-tight' : '' ?>" style="--hero-mobile-h:<?= $heroMobileHeight ?>">
<div class="hero-bg" aria-hidden="true">
<img src="<?= e($heroImageSrc) ?>" alt="" loading="eager" fetchpriority="high">
<span class="hero-shade"></span>
<span class="hero-aurora-sheen"></span>
</div>
<div class="hero-snow" aria-hidden="true"></div>
<div class="hero-inner">
<div class="hero-copy">
<span class="hero-kicker"><?= e($heroKicker) ?></span>
<h1><?= e($heroTitle) ?></h1>
<p><?= e($heroSubtitle) ?></p>
<?php if ($holiday): ?>
<?php if ($holidayIsToday): ?>
<div class="hero-holiday is-today">
<span class="hh-kicker">今日节日</span>
<strong class="hh-fest"><?= e($holiday['greet']) ?></strong>
<span class="hh-msg"><?= e($holiday['blessing']) ?></span>
</div>
<?php else: ?>
<div class="hero-holiday" id="holidayCountdown" data-target="<?= $holidayTarget ?>">
<span class="hh-kicker">距离</span>
<strong class="hh-name"><?= e($holiday['name']) ?></strong>
<span class="hh-label">还有</span>
<span class="hh-days" id="holidayDays"><?= $holidayDays ?></span><span class="hh-unit">天</span>
<span class="hh-clock" id="holidayClock"><?= sprintf('%02d 时 %02d 分 %02d 秒', $holidayHours, $holidayMinutes, $holidaySeconds) ?></span>
</div>
<?php endif; ?>
<?php endif; ?>
<div class="hero-stats">
<a href="<?= e(page_url('home')) ?>#postList"><b><?= $stats['posts'] ?></b><span><?= e(t('posts', '帖子')) ?></span></a>
<a href="<?= e(page_url('users')) ?>"><b><?= $stats['users'] ?></b><span><?= e(t('members', '茶客')) ?></span></a>
<a href="<?= e(page_url('comments')) ?>"><b><?= $stats['comments'] ?></b><span><?= e(t('comments', '评论')) ?></span></a>
</div>
<div class="hero-live" id="heroLive" data-city="<?= e($liveCity) ?>" data-region="<?= e($liveRegion) ?>">
<div class="hero-live-time" id="heroLiveTime">正在读取时间…</div>
<div class="hero-live-weather" id="heroLiveWeather">正在获取当地天气…</div>
</div>
</div>
</div>
<a class="hero-seal" href="<?= e(page_url('home')) ?>" aria-label="返回首页">
<span class="hero-seal-logo"><?= site_logo_html(setting('site_logo', 'assets/img/logo.svg'), 'hero-site-logo') ?></span>
<span class="hero-seal-text">木漏茶室</span>
</a>
</section>
<section class="hero-quick-actions" aria-label="快捷操作">
<?php if ($me): ?>
<a class="hero-quick-action pu-entry-btn" href="<?= e(page_url('platform_users')) ?>"><span class="pu-entry-dot"></span><?= e(t('platform_users', '平台用户')) ?></a>
<?php if (!$checkedToday && user_feature_enabled($me, 'checkin')): ?>
<form method="post" class="checkin-form">
<?= csrf_field() ?><input type="hidden" name="act" value="checkin">
<button class="hero-quick-action checkin-btn" type="submit"><?= e(t('checkin', '每日签到')) ?></button>
</form>
<?php endif; ?>
<?php else: ?>
<a class="hero-quick-action" href="<?= e(page_url('login')) ?>"><?= e(t('login', '登录')) ?></a>
<?php if (setting('register_open', '1') === '1'): ?>
<a class="hero-quick-action" href="<?= e(page_url('register')) ?>"><?= e(t('register', '注册')) ?></a>
<?php endif; ?>
<?php endif; ?>
<a class="hero-quick-action" href="<?= e(page_url('announcements')) ?>"><?= e(t('announcements', '公告列表')) ?></a>
<button class="hero-quick-action" type="button" onclick="KM.shareSite()"><?= e(t('share_app', '分享应用')) ?></button>
</section>
<?php if ($slides): ?>
<section class="carousel" id="carousel" data-autoplay="<?= max(1, (int) setting('carousel_interval', 5)) * 1000 ?>">
<div class="carousel-track">
<?php foreach ($slides as $i => $s): ?>
<div class="slide <?= $i === 0 ? 'on' : '' ?>">
<?php if ($s['link']): ?><a href="<?= e($s['link']) ?>"><?php endif; ?>
<img src="<?= e(upload_url($s['image'])) ?>" alt="<?= e($s['title']) ?>" loading="<?= $i === 0 ? 'eager' : 'lazy' ?>">
<?php if ($s['title']): ?><span class="slide-cap"><?= e($s['title']) ?></span><?php endif; ?>
<?php if ($s['link']): ?></a><?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<?php if (count($slides) > 1): ?>
<div class="carousel-dots">
<?php foreach ($slides as $i => $s): ?>
<button type="button" class="<?= $i === 0 ? 'on' : '' ?>" data-index="<?= $i ?>" aria-label="第<?= $i + 1 ?>张"></button>
<?php endforeach; ?>
</div>
<button class="carousel-nav prev" type="button" aria-label="上一张">‹</button>
<button class="carousel-nav next" type="button" aria-label="下一张">›</button>
<?php endif; ?>
</section>
<?php endif; ?>
<?php if ($quote !== ''): ?>
<section class="daily-quote" id="dailyQuote" data-interval="<?= (int) quote_interval_seconds() ?>">
<p class="dq-text" id="dqText"><?= e($quote) ?></p>
</section>
<?php if (count($quoteRows) > 1): ?>
<script type="application/json" id="quotePool"><?= json_encode(array_column($quoteRows, 'content'), JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT) ?></script>
<?php endif; ?>
<?php endif; ?>
<?= plugin_hook('home_quote') ?>
<section class="toolbar">
<div class="chips">
<a class="chip <?= $catId === 0 ? 'on' : '' ?>" href="<?= e(page_url('home', $filterParams + ($keyword !== '' ? ['q' => $keyword] : []))) ?>"><?= e(t('all', '全部')) ?></a>
<?php foreach ($categories as $c): ?>
<a class="chip <?= $catId === (int) $c['id'] ? 'on' : '' ?>" href="<?= e(page_url('home', ['cat' => $c['id']] + $filterParams + ($keyword !== '' ? ['q' => $keyword] : []))) ?>"><?= e($c['name']) ?></a>
<?php endforeach; ?>
</div>
<form class="search-box home-search" id="homeSearchForm" method="get" action="<?= e(page_url('home')) ?>">
<?php if ($catId): ?><input type="hidden" name="cat" value="<?= $catId ?>"><?php endif; ?>
<?php if ($filter !== 'all'): ?><input type="hidden" name="filter" value="<?= e($filter) ?>"><?php endif; ?>
<input type="search" id="homeSearchInput" name="q" value="<?= e($keyword) ?>" placeholder="<?= e(t('search_placeholder', '输入关键词,下面的帖子自动筛选')) ?>" autocomplete="off" enterkeyhint="search">
<span class="home-search-status" id="homeSearchStatus" aria-live="polite"></span>
<button type="submit" aria-label="搜索">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"><circle cx="11" cy="11" r="6.5"/><path d="M16 16l4 4"/></svg>
</button>
<button type="button" class="refresh-btn" title="刷新" onclick="location.reload()">⟳</button>
</form>
</section>
<div class="post-filter-row post-filter-tabs">
<a class="chip feat-chip <?= $featured ? 'on' : '' ?>" href="<?= e(page_url('home', $featured ? [] : ['filter' => 'featured'])) ?>">✦ <?= e(t('featured', '精华')) ?></a>
<a class="chip top-chip <?= $filter === 'top' ? 'on' : '' ?>" href="<?= e(page_url('home', $filter === 'top' ? [] : ['filter' => 'top'])) ?>">📌 <?= e(t('top', '置顶')) ?></a>
<a class="chip hot-chip <?= $filter === 'hot' ? 'on' : '' ?>" href="<?= e(page_url('home', $filter === 'hot' ? [] : ['filter' => 'hot'])) ?>">🔥 <?= e(t('hot', '热贴')) ?></a>
<?php if ($me): ?>
<a class="chip follow-chip <?= $filter === 'following' ? 'on' : '' ?>" href="<?= e(page_url('home', $filter === 'following' ? [] : ['filter' => 'following'])) ?>"><?= e(t('following', '关注')) ?></a>
<a class="chip friend-chip <?= $filter === 'friends' ? 'on' : '' ?>" href="<?= e(page_url('home', $filter === 'friends' ? [] : ['filter' => 'friends'])) ?>"><?= e(t('friends', '好友帖子')) ?></a>
<?php endif; ?>
<a class="chip reply-chip <?= $filter === 'newreply' ? 'on' : '' ?>" href="<?= e(page_url('home', $filter === 'newreply' ? [] : ['filter' => 'newreply'])) ?>"><?= e(t('newreply', '新回复')) ?></a>
<a class="chip newpost-chip <?= $filter === 'newpost' ? 'on' : '' ?>" href="<?= e(page_url('home', $filter === 'newpost' ? [] : ['filter' => 'newpost'])) ?>"><?= e(t('newpost', '新帖子')) ?></a>
<span class="filter-hint"><?php
if ($filter === 'top') echo t('filter_top', '只显示被管理员置顶的帖子,按置顶时间从新到旧排列');
elseif ($filter === 'hot') echo t('filter_hot', '按阅读量从高到低排列,每位用户每帖只计 1 次阅读');
elseif ($filter === 'friends') echo t('filter_friends', '只显示好友发布的帖子');
elseif ($filter === 'following') echo t('filter_following', '只显示你关注的用户和板块');
elseif ($filter === 'newreply') echo t('filter_newreply', '按最新评论 / 回复时间排列');
elseif ($filter === 'newpost') echo t('filter_newpost', '按最新发布时间排列');
elseif ($filter === 'featured') echo t('filter_featured', '只显示被管理员加精的帖子');
else echo t('filter_all', '全部帖子 · 可切换热贴、好友帖子、新回复与新帖子');
?></span>
</div>
<p class="search-hint" id="homeSearchHint" <?= $keyword === '' ? 'hidden' : '' ?>><?php if ($keyword !== ''): ?><?= e(t('search_result', '搜索结果')) ?> “<?= e($keyword) ?>” · <?= $total ?> <?= e(t('items', '条')) ?><?php endif; ?></p>
<?php if ($tag !== ''): ?><p class="search-hint"><?= e(t('tags', '标签')) ?> #<?= e($tag) ?> · <?= $total ?> <?= e(t('items', '条')) ?> <a class="link-btn" href="<?= e(page_url('tag', ['t' => $tag])) ?>"><?= e(t('view_post', '查看')) ?></a></p><?php endif; ?>
<section class="post-list" id="postList">
<?php if (!$posts): ?>
<?php if ($keyword !== ''): ?>
<?php empty_state(t('empty_search_posts', '没有找到相关帖子'), t('empty_search_posts_desc', '换个关键词试试')); ?>
<?php else: ?>
<?php empty_state(t('empty_posts', '茶室里还没有帖子'), t('empty_posts_desc', '来写下第一帖吧')); ?>
<?php endif; ?>
<?php else: ?>
<?php foreach ($posts as $p): ?>
<?php
$locked = $p['password'] !== '';
$titleEmpty = !post_has_title($p);
$displayTitle = post_display_title($p, 90);
?>
<article class="post-card v2">
<div class="post-meta v2">
<a class="post-avatar-wrap" href="<?= e(page_url('user', ['id' => $p['user_id']])) ?>">
<?= avatar_html($p) ?>
<?php if ((int) $p['verified'] === 1): ?><span class="avatar-v v-<?= verify_style_of($p) ?>">V</span><?php endif; ?>
</a>
<?php $locText = profile_location_public_text($p); ?>
<div class="post-author">
<div class="post-author-line">
<a class="author" href="<?= e(page_url('user', ['id' => $p['user_id']])) ?>"><?= e(display_name($p)) ?></a><?= verify_badge($p) ?>
</div>
<?php if (profile_location_mode($p) > 0 && $locText !== '' && $locText !== '未设置所在地'): ?><span class="post-loc">📍 <?= e($locText) ?></span><?php endif; ?>
</div>
<span class="dot">·</span>
<span class="time"><?= e(date('Y/m/d H:i:s', strtotime($p['created_at']))) ?></span>
</div>
<div class="post-title-row">
<span class="post-share-spacer"></span>
<h2 class="post-title">
<?php if ((int) $p['is_top'] === 1): ?><span class="tag top">置顶</span><?php endif; ?>
<?php if ((int) $p['is_featured'] === 1): ?><span class="tag feat">精华</span><?php endif; ?>
<?php if ($locked): ?><span class="tag lock" title="密码帖">🔒</span><?php endif; ?>
<a href="<?= e(page_url('post', ['id' => $p['id']])) ?>"<?= $titleEmpty ? ' class="post-title-untitled"' : '' ?>><?= e($displayTitle) ?></a>
<?php if ((int) ($p['is_locked'] ?? 0) === 1): ?><span class="tag locked post-title-locked" title="帖子已锁定">🔒</span><?php endif; ?>
</h2>
<button class="post-share" type="button" title="分享帖子"
onclick="KM.sharePost('<?= e(page_url('post', ['id' => $p['id']])) ?>', '<?= e($displayTitle) ?>')">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6"><circle cx="18" cy="5" r="3"/><circle cx="6" cy="12" r="3"/><circle cx="18" cy="19" r="3"/><path d="M8.6 10.6l6.8-4M8.6 13.4l6.8 4"/></svg>
</button>
</div>
<?php if ($filter === 'newreply' && !empty($p['last_comment_id'])): ?>
<?php
$lastCommenter = [
'id' => (int) ($p['last_commenter_id'] ?? 0),
'nickname' => (string) ($p['last_commenter_nickname'] ?? ''),
'username' => username_visible(['id' => (int) ($p['last_commenter_id'] ?? 0), 'username' => (string) ($p['last_commenter_username'] ?? '')]),
'avatar' => (string) ($p['last_commenter_avatar'] ?? ''),
'gender' => (string) ($p['last_commenter_gender'] ?? 'secret'),
'verified' => (int) ($p['last_commenter_verified'] ?? 0),
'verify_style' => (string) ($p['last_commenter_verify_style'] ?? ''),
'verify_title' => (string) ($p['last_commenter_verify_title'] ?? ''),
];
$lastSnippet = trim(preg_replace('/\s+/u', ' ', strip_tags((string) $p['last_comment_content'])));
if (mb_strlen($lastSnippet) > 90) { $lastSnippet = mb_substr($lastSnippet, 0, 90) . '…'; }
if ($lastSnippet === '') { $lastSnippet = '点击查看最新回复'; }
?>
<div class="latest-reply-box">
<a class="latest-reply-avatar" href="<?= e(page_url('user', ['id' => $lastCommenter['id']])) ?>">
<?= avatar_html($lastCommenter) ?>
<?php if ($lastCommenter['verified'] === 1): ?><span class="avatar-v v-<?= e($lastCommenter['verify_style'] ?: 'blue') ?>">V</span><?php endif; ?>
</a>
<div class="latest-reply-main">
<div class="latest-reply-head">
<span class="latest-reply-label"><?= e(t('latest_reply', '最新回复')) ?></span>
<a class="latest-reply-name" href="<?= e(page_url('user', ['id' => $lastCommenter['id']])) ?>"><?= e(display_name($lastCommenter)) ?></a>
<span class="latest-reply-time"><?= e(date('m/d H:i', strtotime((string) $p['last_comment_at']))) ?></span>
</div>
<a class="latest-reply-snippet" href="<?= e(page_url('post', ['id' => $p['id']]) . '#comments') ?>"><?= e($lastSnippet) ?></a>
</div>
<a class="latest-reply-open" href="<?= e(page_url('post', ['id' => $p['id']]) . '#comments') ?>"><?= e(t('view_post', '查看帖子')) ?></a>
</div>
<?php elseif ($filter === 'hot'): ?>
<div class="hot-read-line"><span>🔥 <?= e(t('views', '阅读量')) ?></span><b><?= (int) $p['views'] ?></b></div>
<?php elseif ($filter === 'newpost'): ?>
<div class="newpost-line"><span><?= e(t('latest_post', '最新发布')) ?></span><a href="<?= e(page_url('post', ['id' => $p['id']])) ?>"><?= e(date('Y/m/d H:i', strtotime($p['created_at']))) ?> · <?= e(t('enter_post', '进入帖子')) ?></a></div>
<?php endif; ?>
</article>
<?php endforeach; ?>
<?php endif; ?>
</section>
<div id="homePager"><?= pager_html($pager, 'home', array_filter(['cat' => $catId ?: null, 'q' => $keyword !== '' ? $keyword : null, 'filter' => $filter !== 'all' ? $filter : null])) ?></div>
<?= plugin_hook('home_bottom') ?>
<?php render_footer(); ?>