feat(forum): frontend 1:1 list/tabs/urls/enqueue

Wire Zibll-style board sort tabs, shared topic rows, page-template
URLs, forum asset enqueue on home/plate, home synthesis load-more,
and topic last_reply meta for last-reply ordering. No dual-read.
This commit is contained in:
2026-07-12 08:38:31 +08:00
parent df6b224dd3
commit 780c8cb4f7
23 changed files with 843 additions and 481 deletions
+64 -259
View File
@@ -1,6 +1,6 @@
<?php
/**
* Forum board template.
* Forum board template (legacy taxonomy archive).
*
* @package AKSRT
*/
@@ -14,9 +14,12 @@ $current_user_id = get_current_user_id();
$board = get_queried_object();
$board_id = $board ? (int) $board->term_id : 0;
$paged = max(1, (int) get_query_var('paged', 1));
$forum_sort = isset($_GET['forum_sort']) ? sanitize_key(wp_unslash((string) $_GET['forum_sort'])) : '';
$view = $forum ? $forum->get_board_view($board_id, [
'user_id' => $current_user_id,
'paged' => $paged,
'paged' => $paged,
'orderby' => $forum_sort,
]) : [
'board' => null,
'topics' => [],
@@ -26,6 +29,10 @@ $view = $forum ? $forum->get_board_view($board_id, [
'permissions' => [],
'application' => null,
'board_options' => [],
'tabs' => [],
'active_sort' => 'date',
'top_info' => true,
'compose_url' => function_exists('aksrt_get_forum_compose_url') ? aksrt_get_forum_compose_url() : home_url('/'),
];
$board_data = $view['board'] ?? null;
@@ -33,308 +40,106 @@ $topics = $view['topics'] ?? [];
$sticky_topics = $view['sticky_topics'] ?? [];
$moderators = $view['moderators'] ?? [];
$permissions = $view['permissions'] ?? [];
$application = $view['application'] ?? null;
$board_options = $view['board_options'] ?? [];
$compose_url = add_query_arg('board', $board_id, home_url('/compose/'));
$admin_forum_url = admin_url('admin.php?page=aksrt-theme-admin#/forum/topics');
$tabs = is_array($view['tabs'] ?? null) ? $view['tabs'] : [];
$active_sort = sanitize_key((string) ($view['active_sort'] ?? 'date'));
$top_info = !isset($view['top_info']) || !empty($view['top_info']);
$compose_url = (string) ($view['compose_url'] ?? aksrt_get_forum_compose_url(['board' => $board_id]));
$board_url = !empty($board_data['url']) ? (string) $board_data['url'] : (is_wp_error(get_term_link($board)) ? '' : (string) get_term_link($board));
$nonce = wp_create_nonce('aksrt_public_nonce');
$max_pages = (int) ($view['pagination']['max_pages'] ?? 1);
// Forum settings — names
$forum_settings = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_forum_settings() : [];
$forum_names = $forum_settings['names'] ?? [];
$name_topic = $forum_names['posts'] ?? __('主题', 'aksrt');
$name_reply = $forum_names['comment'] ?? __('回复', 'aksrt');
$name_sticky = __('置顶', 'aksrt');
$name_featured = __('精华', 'aksrt');
?>
<main id="main-content" class="site-main content-shell" tabindex="-1">
<?php if (function_exists('aksrt_breadcrumbs')) { aksrt_breadcrumbs(); } ?>
<div class="aksrt-forum-board container">
<div class="aksrt-forum-board__hero">
<div class="aksrt-forum-board container"
data-board-id="<?php echo esc_attr((string) $board_id); ?>"
data-nonce="<?php echo esc_attr($nonce); ?>"
data-active-sort="<?php echo esc_attr($active_sort); ?>">
<?php if ($top_info) : ?>
<div class="aksrt-forum-board__header">
<div class="aksrt-forum-board__info">
<h1 class="aksrt-forum-board__title"><?php echo esc_html((string) ($board_data['name'] ?? '')); ?></h1>
<h1 class="aksrt-forum-board__title"><?php echo esc_html((string) ($board_data['name'] ?? ($board->name ?? ''))); ?></h1>
<?php if (!empty($board_data['description'])) : ?>
<p class="aksrt-forum-board__desc"><?php echo esc_html((string) $board_data['description']); ?></p>
<?php endif; ?>
<div class="aksrt-forum-board__meta">
<span><i class="fas fa-list-alt"></i> <?php printf(esc_html__('%1$d 个%2$s', 'aksrt'), (int) ($board_data['topic_count'] ?? 0), esc_html($name_topic)); ?></span>
<span><i class="fas fa-shield-alt"></i> <?php printf(esc_html__('%d 位版主', 'aksrt'), count($moderators)); ?></span>
<span><i class="fas fa-comments"></i> <?php printf(esc_html__('%d 条%s', 'aksrt'), (int) ($board_data['reply_count'] ?? 0), esc_html($name_reply)); ?></span>
</div>
</div>
<div class="aksrt-forum-board__actions">
<?php if (!empty($permissions['can_compose'])) : ?>
<a href="<?php echo esc_url($compose_url); ?>" class="aksrt-forum-board__compose-btn">
<i class="fas fa-pen"></i>
<?php esc_html_e('发布新主题', 'aksrt'); ?>
</a>
<?php else : ?>
<a href="<?php echo esc_url(wp_login_url(get_term_link($board))); ?>" class="aksrt-forum-board__compose-btn">
<i class="fas fa-sign-in-alt"></i>
<?php esc_html_e('登录后发帖', 'aksrt'); ?>
</a>
<?php endif; ?>
<?php if (!empty($permissions['can_moderate'])) : ?>
<a href="<?php echo esc_url($admin_forum_url); ?>" class="aksrt-forum-board__manage-btn">
<i class="fas fa-tools"></i>
<?php esc_html_e('进入治理后台', 'aksrt'); ?>
<i class="fas fa-pen"></i> <?php esc_html_e('发布新主题', 'aksrt'); ?>
</a>
<?php endif; ?>
</div>
</div>
<div class="aksrt-forum-board__summary">
<div class="aksrt-forum-board__summary-item">
<span class="aksrt-forum-board__summary-label"><?php echo esc_html($name_topic); ?></span>
<strong><?php echo esc_html(number_format_i18n((int) ($board_data['topic_count'] ?? 0))); ?></strong>
</div>
<div class="aksrt-forum-board__summary-item">
<span class="aksrt-forum-board__summary-label"><?php echo esc_html($name_reply); ?></span>
<strong><?php echo esc_html(number_format_i18n((int) ($board_data['reply_count'] ?? 0))); ?></strong>
</div>
<div class="aksrt-forum-board__summary-item">
<span class="aksrt-forum-board__summary-label"><?php esc_html_e('版主', 'aksrt'); ?></span>
<strong><?php echo esc_html(number_format_i18n(count($moderators))); ?></strong>
</div>
</div>
</div>
<div class="content-layout<?php echo empty($moderators) && empty($application) && empty($permissions['can_moderate']) ? ' content-layout--no-sidebar' : ''; ?> aksrt-forum-board__layout">
<div class="content-layout__primary">
<section class="aksrt-forum-board__governance aksrt-forum-board__governance--inline">
<div class="aksrt-forum-board__governance-card">
<h2 class="aksrt-forum-board__section-title"><?php esc_html_e('权限反馈', 'aksrt'); ?></h2>
<?php if (!is_user_logged_in()) : ?>
<p><?php esc_html_e('登录后可以发帖、申请版主,并在有权限时执行治理动作。', 'aksrt'); ?></p>
<?php elseif (!empty($permissions['can_moderate'])) : ?>
<p><?php esc_html_e('你当前拥有本版块治理权限,可在主题页执行审核、移动版块、可见性调整等操作。', 'aksrt'); ?></p>
<?php elseif ($application) : ?>
<p>
<?php esc_html_e('你的版主申请状态:', 'aksrt'); ?>
<strong><?php echo esc_html((string) ($application['status_label'] ?? '')); ?></strong>
</p>
<?php else : ?>
<p><?php esc_html_e('当前可浏览并发帖,若你熟悉本版块内容,可提交版主申请参与治理。', 'aksrt'); ?></p>
<?php endif; ?>
</div>
<div class="aksrt-forum-board__governance-card">
<h2 class="aksrt-forum-board__section-title"><?php esc_html_e('版主团队', 'aksrt'); ?></h2>
<?php if (!empty($moderators)) : ?>
<div class="aksrt-forum-board__moderators">
<?php foreach ($moderators as $moderator) : ?>
<div class="aksrt-forum-board__moderator">
<?php if (!empty($moderator['avatar_url'])) : ?>
<img src="<?php echo esc_url((string) $moderator['avatar_url']); ?>" alt="" width="36" height="36">
<?php endif; ?>
<span><?php echo esc_html((string) ($moderator['display_name'] ?? '')); ?></span>
</div>
<?php endforeach; ?>
</div>
<?php else : ?>
<p><?php esc_html_e('当前还没有设置版主。', 'aksrt'); ?></p>
<?php endif; ?>
</div>
<?php if (is_user_logged_in() && empty($permissions['can_moderate'])) : ?>
<div class="aksrt-forum-board__governance-card">
<h2 class="aksrt-forum-board__section-title"><?php esc_html_e('申请版主', 'aksrt'); ?></h2>
<?php if ($application) : ?>
<p><?php echo esc_html((string) ($application['status_label'] ?? '')); ?></p>
<?php if (!empty($application['review_note'])) : ?>
<p class="aksrt-forum-board__application-note"><?php echo esc_html((string) $application['review_note']); ?></p>
<?php endif; ?>
<?php else : ?>
<form class="aksrt-forum-board__application-form js-aksrt-moderator-apply-form" data-board-id="<?php echo esc_attr((string) $board_id); ?>">
<label for="aksrt-board-apply-reason"><?php esc_html_e('申请理由', 'aksrt'); ?></label>
<textarea id="aksrt-board-apply-reason" name="reason" rows="3" placeholder="<?php esc_attr_e('说明你熟悉该版块内容、希望承担的治理职责等。', 'aksrt'); ?>" required></textarea>
<div class="aksrt-forum-board__application-actions">
<button type="submit" class="aksrt-forum-board__apply-btn"><?php esc_html_e('提交申请', 'aksrt'); ?></button>
<span class="aksrt-forum-board__application-feedback js-aksrt-action-feedback" aria-live="polite"></span>
</div>
</form>
<?php endif; ?>
</div>
<?php endif; ?>
</section>
<?php endif; ?>
<?php if (!empty($sticky_topics)) : ?>
<div class="aksrt-forum-board__sticky">
<h3><i class="fas fa-thumbtack"></i> <?php esc_html_e('置顶主题', 'aksrt'); ?></h3>
<?php foreach ($sticky_topics as $topic) : ?>
<a href="<?php echo esc_url((string) ($topic['permalink'] ?? '#')); ?>" class="aksrt-forum-board__sticky-item">
<?php
$sticky_label = (string) ($topic['sticky_label'] ?? '');
if ($sticky_label === '') {
$sticky_label = __('置顶', 'aksrt');
}
?>
<span class="aksrt-forum-board__sticky-badge"><?php echo esc_html($sticky_label); ?></span>
<span class="aksrt-forum-board__sticky-badge"><?php echo esc_html((string) ($topic['sticky_label'] ?? __('置顶', 'aksrt'))); ?></span>
<span class="aksrt-forum-board__sticky-title"><?php echo esc_html((string) ($topic['title'] ?? '')); ?></span>
<span class="aksrt-forum-board__sticky-meta">
<?php echo esc_html((string) ($topic['author']['display_name'] ?? '')); ?>
· <?php echo esc_html((string) ($topic['date'] ?? '')); ?>
</span>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>
<div class="aksrt-forum-board__topics">
<?php if (!empty($topics)) : ?>
<?php foreach ($topics as $topic) :
$topic_id = (int) ($topic['id'] ?? 0);
<?php if (!empty($tabs)) : ?>
<nav class="aksrt-forum-board__tabs" aria-label="<?php esc_attr_e('版块栏目', 'aksrt'); ?>">
<?php foreach ($tabs as $tab) :
$sort = sanitize_key((string) ($tab['sort'] ?? 'date'));
$label = (string) ($tab['label'] ?? $sort);
$tab_url = add_query_arg('forum_sort', $sort, $board_url);
$is_active = $sort === $active_sort;
?>
<?php
$item_sticky_level_class = (int) ($topic['sticky_level'] ?? 0) > 0
? ' is-sticky is-sticky-' . (int) ($topic['sticky_level'] ?? 0)
: '';
?>
<article class="aksrt-forum-topic-item<?php echo esc_attr($item_sticky_level_class); ?><?php echo !empty($topic['featured']) ? ' is-featured' : ''; ?>">
<div class="aksrt-forum-topic-item__avatar">
<?php if (!empty($topic['author']['avatar_url'])) : ?>
<img src="<?php echo esc_url((string) $topic['author']['avatar_url']); ?>" alt="" width="40" height="40">
<?php endif; ?>
</div>
<?php if (!empty($topic['cover'])) : ?>
<div class="aksrt-forum-topic-item__cover">
<?php if ($topic['cover']['type'] === 'video') : ?>
<div class="aksrt-forum-topic-item__cover-video">
<img src="<?php echo esc_url((string) ($topic['cover']['poster'] ?: $topic['cover']['url'])); ?>" alt="" loading="lazy">
<span class="aksrt-forum-topic-item__cover-play"><i class="fas fa-play-circle"></i></span>
</div>
<?php elseif ($topic['cover']['type'] === 'slide') : ?>
<div class="aksrt-forum-topic-item__cover-slide">
<img src="<?php echo esc_url((string) ($topic['cover']['images'][0] ?? '')); ?>" alt="" loading="lazy">
<span class="aksrt-forum-topic-item__cover-count"><i class="fas fa-images"></i> <?php echo count($topic['cover']['images']); ?></span>
</div>
<?php else : ?>
<img src="<?php echo esc_url((string) ($topic['cover']['url'] ?? '')); ?>" alt="" loading="lazy">
<?php endif; ?>
</div>
<?php endif; ?>
<div class="aksrt-forum-topic-item__body">
<div class="aksrt-forum-topic-item__title">
<?php
$item_sticky_level = (int) ($topic['sticky_level'] ?? 0);
$item_sticky_label = (string) ($topic['sticky_label'] ?? '');
if ($item_sticky_level > 0 && $item_sticky_label !== '') :
$item_sticky_mod = $item_sticky_level >= 3 ? 'global' : ($item_sticky_level === 2 ? 'super' : 'plate');
?>
<span class="aksrt-forum-topic-item__badge aksrt-forum-topic-item__badge--sticky aksrt-forum-topic-item__badge--sticky-<?php echo esc_attr($item_sticky_mod); ?>"><?php echo esc_html($item_sticky_label); ?></span>
<?php endif; ?>
<?php if (!empty($topic['featured'])) : ?><span class="aksrt-forum-topic-item__badge aksrt-forum-topic-item__badge--featured"><?php esc_html_e('精华', 'aksrt'); ?></span><?php endif; ?>
<?php if (($topic['bbs_type'] ?? 'standard') === 'question') : ?>
<?php $q_status = (int) ($topic['question_status'] ?? 0); ?>
<span class="aksrt-forum-topic-item__badge aksrt-forum-topic-item__badge--question<?php echo $q_status === 1 ? ' aksrt-forum-topic-item__badge--solved' : ''; ?>">
<?php echo $q_status === 1 ? esc_html__('已解决', 'aksrt') : esc_html__('提问', 'aksrt'); ?>
</span>
<?php endif; ?>
<?php if (!empty($topic['locked'])) : ?><i class="fas fa-lock aksrt-forum-topic-item__lock"></i><?php endif; ?>
<?php if (!empty($topic['visibility']['key']) && $topic['visibility']['key'] !== 'public') : ?>
<span class="aksrt-forum-topic-item__badge aksrt-forum-topic-item__badge--muted"><?php echo esc_html((string) ($topic['visibility']['label'] ?? '')); ?></span>
<?php endif; ?>
<a href="<?php echo esc_url((string) ($topic['permalink'] ?? '#')); ?>"><?php echo esc_html((string) ($topic['title'] ?? '')); ?></a>
</div>
<div class="aksrt-forum-topic-item__meta">
<span><?php echo esc_html((string) ($topic['author']['display_name'] ?? '')); ?></span>
<span><?php echo esc_html((string) ($topic['date'] ?? '')); ?></span>
<?php if (!empty($topic['special_topic'])) : ?>
<span><?php echo esc_html((string) $topic['special_topic']); ?></span>
<?php endif; ?>
</div>
</div>
<div class="aksrt-forum-topic-item__stats">
<span title="<?php echo esc_attr($name_reply); ?>"><i class="fas fa-comment"></i> <?php echo esc_html(number_format_i18n((int) ($topic['comment_count'] ?? 0))); ?></span>
<span title="<?php esc_attr_e('浏览', 'aksrt'); ?>"><i class="fas fa-eye"></i> <?php echo esc_html(number_format_i18n((int) ($topic['views'] ?? 0))); ?></span>
</div>
<?php if (!empty($permissions['can_moderate'])) : ?>
<div class="aksrt-forum-topic-item__actions">
<?php
$sticky_level = (int) ($topic['sticky_level'] ?? 0);
// 快捷按钮:无置顶↔版块置顶 切换;超级/全局置顶需进入治理表单调整。
$sticky_next = $sticky_level > 0 ? 0 : 1;
?>
<button
type="button"
class="aksrt-forum-topic-item__action js-aksrt-topic-action"
data-topic-id="<?php echo esc_attr((string) $topic_id); ?>"
data-action="sticky"
data-value="<?php echo esc_attr((string) $sticky_next); ?>"
data-value-type="int"
>
<?php echo $sticky_level > 0 ? esc_html__('取消置顶', 'aksrt') : esc_html__('置顶', 'aksrt'); ?>
</button>
<button
type="button"
class="aksrt-forum-topic-item__action js-aksrt-topic-action"
data-topic-id="<?php echo esc_attr((string) $topic_id); ?>"
data-action="locked"
data-value="<?php echo !empty($topic['locked']) ? '0' : '1'; ?>"
>
<?php echo !empty($topic['locked']) ? esc_html__('解锁', 'aksrt') : esc_html__('锁定', 'aksrt'); ?>
</button>
<a href="<?php echo esc_url((string) ($topic['permalink'] ?? '#') . '#aksrt-topic-moderation'); ?>" class="aksrt-forum-topic-item__action aksrt-forum-topic-item__action--link">
<?php esc_html_e('更多治理', 'aksrt'); ?>
</a>
</div>
<?php endif; ?>
</article>
<a class="aksrt-forum-board__tab js-aksrt-board-sort-tab<?php echo $is_active ? ' is-active' : ''; ?>"
href="<?php echo esc_url($tab_url); ?>"
data-sort="<?php echo esc_attr($sort); ?>">
<?php echo esc_html($label); ?>
</a>
<?php endforeach; ?>
</nav>
<?php endif; ?>
<?php if (($view['pagination']['max_pages'] ?? 1) > 1) : ?>
<div class="aksrt-forum-board__pagination">
<?php
echo paginate_links([
'total' => (int) ($view['pagination']['max_pages'] ?? 1),
'current' => $paged,
'prev_text' => '<i class="fas fa-chevron-left"></i>',
'next_text' => '<i class="fas fa-chevron-right"></i>',
]);
?>
<div class="aksrt-forum-board__topics">
<div class="aksrt-forum-topics__list js-aksrt-board-topic-list">
<?php if (!empty($topics) && $forum) : ?>
<?php foreach ($topics as $topic) { $forum->render_topic_row($topic); } ?>
<?php else : ?>
<div class="aksrt-forum-board__empty aksrt-forum__empty">
<i class="fas fa-comments"></i>
<p><?php esc_html_e('内容空空如也', 'aksrt'); ?></p>
<?php if (!empty($permissions['can_compose'])) : ?>
<a href="<?php echo esc_url($compose_url); ?>"><?php esc_html_e('发布第一个主题', 'aksrt'); ?></a>
<?php endif; ?>
</div>
<?php endif; ?>
<?php else : ?>
<div class="aksrt-forum-board__empty">
<i class="fas fa-comments"></i>
<p><?php esc_html_e('当前版块还没有公开主题。', 'aksrt'); ?></p>
<?php if (!empty($permissions['can_compose'])) : ?>
<a href="<?php echo esc_url($compose_url); ?>"><?php esc_html_e('发布第一个主题', 'aksrt'); ?></a>
<?php endif; ?>
</div>
<?php if ($max_pages > 1) : ?>
<div class="aksrt-forum-board__pagination">
<?php
echo paginate_links([
'total' => $max_pages,
'current' => $paged,
'prev_text' => '<i class="fas fa-chevron-left"></i>',
'next_text' => '<i class="fas fa-chevron-right"></i>',
'add_args' => $active_sort !== '' ? ['forum_sort' => $active_sort] : [],
]);
?>
</div>
<?php endif; ?>
</div>
<aside class="content-layout__sidebar aksrt-forum-board__sidebar">
<div class="aksrt-forum-board__governance-card aksrt-forum-board__governance-card--sidebar">
<h2 class="aksrt-forum-board__section-title"><?php esc_html_e('版块说明', 'aksrt'); ?></h2>
<p><?php echo esc_html((string) ($board_data['description'] ?? __('这里展示版块简介、讨论方向与基础规则。', 'aksrt'))); ?></p>
</div>
<?php if (!empty($moderators)) : ?>
<div class="aksrt-forum-board__governance-card aksrt-forum-board__governance-card--sidebar">
<h2 class="aksrt-forum-board__section-title"><?php esc_html_e('版主团队', 'aksrt'); ?></h2>
<div class="aksrt-forum-board__moderators aksrt-forum-board__moderators--stacked">
<?php foreach ($moderators as $moderator) : ?>
<div class="aksrt-forum-board__moderator">
<?php if (!empty($moderator['avatar_url'])) : ?>
<img src="<?php echo esc_url((string) $moderator['avatar_url']); ?>" alt="" width="36" height="36">
<?php endif; ?>
<span><?php echo esc_html((string) ($moderator['display_name'] ?? '')); ?></span>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
</aside>
</div>
</div>
</main>
+1 -1
View File
@@ -74,7 +74,7 @@ $initial_content = $draft_data ? $draft_data['content'] : '';
?>
</p>
</div>
<a href="<?php echo esc_url(home_url('/forums/')); ?>" class="aksrt-forum-compose__back">
<a href="<?php echo esc_url(aksrt_get_forum_home_url()); ?>" class="aksrt-forum-compose__back">
<i class="fas fa-arrow-left"></i> <?php printf(esc_html__('返回%s', 'aksrt'), esc_html($forum_name)); ?>
</a>
</div>
+1 -1
View File
@@ -97,7 +97,7 @@ if (is_array($cat_moderator_ids)) {
</div>
<div class="aksrt-forum-plate-cat__back">
<a href="<?php echo esc_url(home_url('/forums/')); ?>">
<a href="<?php echo esc_url(aksrt_get_forum_home_url()); ?>">
<i class="fas fa-arrow-left"></i> <?php printf(esc_html__('返回%s', 'aksrt'), esc_html($forum_name)); ?>
</a>
</div>
+93 -117
View File
@@ -13,19 +13,25 @@ $forum = class_exists('AKSRT_Forum') ? AKSRT_Forum::get_instance() : null;
$current_user_id = get_current_user_id();
$plate_id = get_queried_object_id();
$paged = max(1, (int) get_query_var('paged', 1));
$forum_sort = isset($_GET['forum_sort']) ? sanitize_key(wp_unslash((string) $_GET['forum_sort'])) : '';
$view = $forum ? $forum->get_board_view($plate_id, [
'user_id' => $current_user_id,
'paged' => $paged,
'orderby' => $forum_sort,
]) : [
'board' => null,
'topics' => [],
'board' => null,
'topics' => [],
'sticky_topics' => [],
'moderators' => [],
'pagination' => ['page' => 1, 'max_pages' => 1, 'total' => 0],
'permissions' => [],
'application' => null,
'moderators' => [],
'pagination' => ['page' => 1, 'max_pages' => 1, 'total' => 0],
'permissions' => [],
'application' => null,
'board_options' => [],
'tabs' => [],
'active_sort' => 'date',
'top_info' => true,
'compose_url' => function_exists('aksrt_get_forum_compose_url') ? aksrt_get_forum_compose_url() : home_url('/'),
];
$board_data = $view['board'] ?? null;
@@ -34,13 +40,19 @@ $sticky_topics = $view['sticky_topics'] ?? [];
$moderators = $view['moderators'] ?? [];
$permissions = $view['permissions'] ?? [];
$application = $view['application'] ?? null;
$compose_url = add_query_arg('board', $plate_id, home_url('/compose/'));
$tabs = is_array($view['tabs'] ?? null) ? $view['tabs'] : [];
$active_sort = sanitize_key((string) ($view['active_sort'] ?? 'date'));
$top_info = !isset($view['top_info']) || !empty($view['top_info']);
$compose_url = (string) ($view['compose_url'] ?? (function_exists('aksrt_get_forum_compose_url') ? aksrt_get_forum_compose_url(['board' => $plate_id]) : home_url('/')));
$plate_url = !empty($board_data['url']) ? (string) $board_data['url'] : (string) get_permalink($plate_id);
$nonce = wp_create_nonce('aksrt_public_nonce');
$forum_settings = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_forum_settings() : [];
$forum_names = $forum_settings['names'] ?? [];
$name_topic = $forum_names['posts'] ?? __('主题', 'aksrt');
$name_reply = $forum_names['comment'] ?? __('回复', 'aksrt');
$is_followed = $forum && $current_user_id > 0 ? $forum->is_user_following_plate($current_user_id, $plate_id) : false;
$max_pages = (int) ($view['pagination']['max_pages'] ?? 1);
?>
<main id="main-content" class="site-main content-shell" tabindex="-1">
@@ -65,7 +77,12 @@ $is_followed = $forum && $current_user_id > 0 ? $forum->is_user_following_pla
</div>
<?php else : ?>
<div class="aksrt-forum-board container">
<div class="aksrt-forum-board container"
data-plate-id="<?php echo esc_attr((string) $plate_id); ?>"
data-nonce="<?php echo esc_attr($nonce); ?>"
data-active-sort="<?php echo esc_attr($active_sort); ?>">
<?php if ($top_info) : ?>
<div class="aksrt-forum-board__header">
<div class="aksrt-forum-board__info">
<?php if (!empty($board_data['cover_url'])) : ?>
@@ -90,7 +107,7 @@ $is_followed = $forum && $current_user_id > 0 ? $forum->is_user_following_pla
class="aksrt-forum-board__follow-btn js-aksrt-follow-plate"
data-plate-id="<?php echo esc_attr((string) $plate_id); ?>"
data-followed="<?php echo $is_followed ? '1' : '0'; ?>">
<i class="fas <?php echo $is_followed ? 'fa-heart' : 'fa-heart'; ?>"></i>
<i class="fas fa-heart"></i>
<?php echo $is_followed ? esc_html__('已关注', 'aksrt') : esc_html__('关注', 'aksrt'); ?>
</button>
<?php endif; ?>
@@ -125,6 +142,7 @@ $is_followed = $forum && $current_user_id > 0 ? $forum->is_user_following_pla
<?php endif; ?>
</div>
</div>
<?php endif; ?>
<?php if (!empty($board_data['content'])) : ?>
<div class="aksrt-forum-board__content entry-content">
@@ -132,7 +150,72 @@ $is_followed = $forum && $current_user_id > 0 ? $forum->is_user_following_pla
</div>
<?php endif; ?>
<section class="aksrt-forum-board__governance">
<?php if (!empty($sticky_topics)) : ?>
<div class="aksrt-forum-board__sticky">
<h3><i class="fas fa-thumbtack"></i> <?php esc_html_e('置顶主题', 'aksrt'); ?></h3>
<?php foreach ($sticky_topics as $topic) : ?>
<a href="<?php echo esc_url((string) ($topic['permalink'] ?? '#')); ?>" class="aksrt-forum-board__sticky-item">
<?php $sticky_label = (string) ($topic['sticky_label'] ?? __('置顶', 'aksrt')); ?>
<span class="aksrt-forum-board__sticky-badge"><?php echo esc_html($sticky_label); ?></span>
<span class="aksrt-forum-board__sticky-title"><?php echo esc_html((string) ($topic['title'] ?? '')); ?></span>
<span class="aksrt-forum-board__sticky-meta">
<?php echo esc_html((string) ($topic['author']['display_name'] ?? '')); ?>
· <?php echo esc_html((string) ($topic['date'] ?? '')); ?>
</span>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if (!empty($tabs)) : ?>
<nav class="aksrt-forum-board__tabs" aria-label="<?php esc_attr_e('版块栏目', 'aksrt'); ?>">
<?php foreach ($tabs as $tab) :
$sort = sanitize_key((string) ($tab['sort'] ?? 'date'));
$label = (string) ($tab['label'] ?? $sort);
$tab_url = add_query_arg('forum_sort', $sort, $plate_url);
$is_active = $sort === $active_sort;
?>
<a class="aksrt-forum-board__tab js-aksrt-board-sort-tab<?php echo $is_active ? ' is-active' : ''; ?>"
href="<?php echo esc_url($tab_url); ?>"
data-sort="<?php echo esc_attr($sort); ?>"
<?php echo $is_active ? 'aria-current="page"' : ''; ?>>
<?php echo esc_html($label); ?>
</a>
<?php endforeach; ?>
</nav>
<?php endif; ?>
<div class="aksrt-forum-board__topics">
<div class="aksrt-forum-topics__list js-aksrt-board-topic-list">
<?php if (!empty($topics) && $forum) : ?>
<?php foreach ($topics as $topic) { $forum->render_topic_row($topic); } ?>
<?php else : ?>
<div class="aksrt-forum-board__empty aksrt-forum__empty">
<i class="fas fa-comments"></i>
<p><?php esc_html_e('内容空空如也', 'aksrt'); ?></p>
<?php if (!empty($permissions['can_compose'])) : ?>
<a href="<?php echo esc_url($compose_url); ?>"><?php esc_html_e('发布第一个主题', 'aksrt'); ?></a>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<?php if ($max_pages > 1) : ?>
<div class="aksrt-forum-board__pagination">
<?php
echo paginate_links([
'total' => $max_pages,
'current' => $paged,
'prev_text' => '<i class="fas fa-chevron-left"></i>',
'next_text' => '<i class="fas fa-chevron-right"></i>',
'add_args' => $active_sort !== '' ? ['forum_sort' => $active_sort] : [],
]);
?>
</div>
<?php endif; ?>
</div>
<section class="aksrt-forum-board__governance aksrt-forum-board__governance--footer">
<div class="aksrt-forum-board__governance-card">
<h2 class="aksrt-forum-board__section-title"><?php esc_html_e('版主团队', 'aksrt'); ?></h2>
<?php if (!empty($moderators)) : ?>
@@ -197,113 +280,6 @@ $is_followed = $forum && $current_user_id > 0 ? $forum->is_user_following_pla
<?php endif; ?>
</div>
</section>
<?php if (!empty($sticky_topics)) : ?>
<div class="aksrt-forum-board__sticky">
<h3><i class="fas fa-thumbtack"></i> <?php esc_html_e('置顶主题', 'aksrt'); ?></h3>
<?php foreach ($sticky_topics as $topic) : ?>
<a href="<?php echo esc_url((string) ($topic['permalink'] ?? '#')); ?>" class="aksrt-forum-board__sticky-item">
<?php
$sticky_label = (string) ($topic['sticky_label'] ?? __('置顶', 'aksrt'));
?>
<span class="aksrt-forum-board__sticky-badge"><?php echo esc_html($sticky_label); ?></span>
<span class="aksrt-forum-board__sticky-title"><?php echo esc_html((string) ($topic['title'] ?? '')); ?></span>
<span class="aksrt-forum-board__sticky-meta">
<?php echo esc_html((string) ($topic['author']['display_name'] ?? '')); ?>
· <?php echo esc_html((string) ($topic['date'] ?? '')); ?>
</span>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>
<div class="aksrt-forum-board__topics">
<?php if (!empty($topics)) : ?>
<?php foreach ($topics as $topic) : ?>
<?php
$topic_id = (int) ($topic['id'] ?? 0);
$item_sticky_level = (int) ($topic['sticky_level'] ?? 0);
$item_sticky_class = $item_sticky_level > 0
? ' is-sticky is-sticky-' . $item_sticky_level
: '';
?>
<article class="aksrt-forum-topic-item<?php echo esc_attr($item_sticky_class); ?><?php echo !empty($topic['featured']) ? ' is-featured' : ''; ?>">
<div class="aksrt-forum-topic-item__avatar">
<?php if (!empty($topic['author']['avatar_url'])) : ?>
<img src="<?php echo esc_url((string) $topic['author']['avatar_url']); ?>" alt="" width="40" height="40">
<?php endif; ?>
</div>
<div class="aksrt-forum-topic-item__body">
<div class="aksrt-forum-topic-item__title">
<?php if (!empty($topic['featured'])) : ?>
<span class="aksrt-forum-topic-item__badge aksrt-forum-topic-item__badge--featured"><?php esc_html_e('精华', 'aksrt'); ?></span>
<?php endif; ?>
<?php if (($topic['bbs_type'] ?? 'standard') === 'question') : ?>
<?php $q_status = (int) ($topic['question_status'] ?? 0); ?>
<span class="aksrt-forum-topic-item__badge aksrt-forum-topic-item__badge--question<?php echo $q_status === 1 ? ' aksrt-forum-topic-item__badge--solved' : ''; ?>">
<?php echo $q_status === 1 ? esc_html__('已解决', 'aksrt') : esc_html__('提问', 'aksrt'); ?>
</span>
<?php endif; ?>
<a href="<?php echo esc_url((string) ($topic['permalink'] ?? '#')); ?>"><?php echo esc_html((string) ($topic['title'] ?? '')); ?></a>
</div>
<div class="aksrt-forum-topic-item__meta">
<span><?php echo esc_html((string) ($topic['author']['display_name'] ?? '')); ?></span>
<span><?php echo esc_html((string) ($topic['date'] ?? '')); ?></span>
</div>
</div>
<?php if (!empty($topic['cover'])) : ?>
<div class="aksrt-forum-topic-item__cover">
<?php if ($topic['cover']['type'] === 'video') : ?>
<div class="aksrt-forum-topic-item__cover-video">
<?php if (!empty($topic['cover']['poster'])) : ?>
<img src="<?php echo esc_url((string) $topic['cover']['poster']); ?>" alt="" loading="lazy">
<?php endif; ?>
<i class="fas fa-play-circle"></i>
</div>
<?php elseif ($topic['cover']['type'] === 'slide') : ?>
<div class="aksrt-forum-topic-item__cover-slide">
<?php if (!empty($topic['cover']['images'][0])) : ?>
<img src="<?php echo esc_url((string) $topic['cover']['images'][0]); ?>" alt="" loading="lazy">
<?php endif; ?>
<span class="aksrt-forum-topic-item__cover-count"><i class="fas fa-images"></i> <?php echo count($topic['cover']['images']); ?></span>
</div>
<?php else : ?>
<img src="<?php echo esc_url((string) ($topic['cover']['url'] ?? '')); ?>" alt="" loading="lazy">
<?php endif; ?>
</div>
<?php endif; ?>
<div class="aksrt-forum-topic-item__stats">
<span title="<?php echo esc_attr($name_reply); ?>"><i class="fas fa-comment"></i> <?php echo esc_html(number_format_i18n((int) ($topic['comment_count'] ?? 0))); ?></span>
<span title="<?php esc_attr_e('浏览', 'aksrt'); ?>"><i class="fas fa-eye"></i> <?php echo esc_html(number_format_i18n((int) ($topic['views'] ?? 0))); ?></span>
</div>
</article>
<?php endforeach; ?>
<?php if (($view['pagination']['max_pages'] ?? 1) > 1) : ?>
<div class="aksrt-forum-board__pagination">
<?php
echo paginate_links([
'total' => (int) ($view['pagination']['max_pages'] ?? 1),
'current' => $paged,
'prev_text' => '<i class="fas fa-chevron-left"></i>',
'next_text' => '<i class="fas fa-chevron-right"></i>',
]);
?>
</div>
<?php endif; ?>
<?php else : ?>
<div class="aksrt-forum-board__empty">
<i class="fas fa-comments"></i>
<p><?php esc_html_e('当前版块还没有公开主题。', 'aksrt'); ?></p>
<?php if (!empty($permissions['can_compose'])) : ?>
<a href="<?php echo esc_url($compose_url); ?>"><?php esc_html_e('发布第一个主题', 'aksrt'); ?></a>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
+6 -31
View File
@@ -24,7 +24,7 @@ $term_name = $term->name ?? '';
$term_desc = $term->description ?? '';
?>
<main id="main-content" class="site-main container" tabindex="-1">
<main id="main-content" class="site-main content-shell" tabindex="-1">
<div class="aksrt-forum-tag container">
<header class="aksrt-forum-tag__header">
@@ -38,34 +38,9 @@ $term_desc = $term->description ?? '';
<p class="aksrt-forum-tag__count"><?php printf(esc_html__('共 %d 个话题', 'aksrt'), $total); ?></p>
</header>
<?php if (!empty($topics)) : ?>
<div class="aksrt-forum-tag__list">
<?php foreach ($topics as $topic) : ?>
<article class="aksrt-forum-topic-card">
<div class="aksrt-forum-topic-card__body">
<h3 class="aksrt-forum-topic-card__title">
<a href="<?php echo esc_url($topic['permalink']); ?>"><?php echo esc_html($topic['title']); ?></a>
</h3>
<?php if ($topic['excerpt']) : ?>
<p class="aksrt-forum-topic-card__excerpt"><?php echo esc_html(wp_trim_words($topic['excerpt'], 30)); ?></p>
<?php endif; ?>
<div class="aksrt-forum-topic-card__meta">
<span class="aksrt-forum-topic-card__author">
<i class="fas fa-user"></i> <?php echo esc_html($topic['author']); ?>
</span>
<span class="aksrt-forum-topic-card__date">
<i class="fas fa-clock"></i> <?php echo esc_html($topic['date']); ?>
</span>
<span class="aksrt-forum-topic-card__comments">
<i class="fas fa-comment"></i> <?php echo (int) $topic['comment_count']; ?>
</span>
<span class="aksrt-forum-topic-card__views">
<i class="fas fa-eye"></i> <?php echo (int) $topic['views']; ?>
</span>
</div>
</div>
</article>
<?php endforeach; ?>
<?php if (!empty($topics) && $forum) : ?>
<div class="aksrt-forum-topics__list aksrt-forum-tag__list">
<?php foreach ($topics as $topic) { $forum->render_topic_row($topic); } ?>
</div>
<?php if ($max_pages > 1) : ?>
@@ -81,9 +56,9 @@ $term_desc = $term->description ?? '';
</nav>
<?php endif; ?>
<?php else : ?>
<div class="aksrt-forum-tag__empty">
<div class="aksrt-forum-tag__empty aksrt-forum__empty">
<i class="fas fa-comments"></i>
<p><?php esc_html_e('该标签下暂无话题', 'aksrt'); ?></p>
<p><?php esc_html_e('内容空空如也', 'aksrt'); ?></p>
</div>
<?php endif; ?>
</div>
+2 -2
View File
@@ -117,7 +117,7 @@ $comments_enabled = !empty($permissions['can_reply']);
<?php if ($show_breadcrumbs) : ?>
<div class="aksrt-forum-topic__breadcrumb">
<?php if ($bc_show_home) : ?>
<a href="<?php echo esc_url(home_url('/forums/')); ?>"><?php echo esc_html($bc_forum_name); ?></a>
<a href="<?php echo esc_url(aksrt_get_forum_home_url()); ?>"><?php echo esc_html($bc_forum_name); ?></a>
<?php endif; ?>
<?php if ($board) : ?>
<?php if ($bc_show_home) : ?><span class="aksrt-forum-topic__sep">/</span><?php endif; ?>
@@ -157,7 +157,7 @@ $comments_enabled = !empty($permissions['can_reply']);
<div class="aksrt-forum-topic__meta">
<span class="aksrt-forum-topic__board-link-wrap">
<i class="fas fa-layer-group"></i>
<a class="aksrt-forum-topic__board-link" href="<?php echo esc_url((string) ($board['url'] ?? home_url('/forums/'))); ?>"><?php echo esc_html((string) ($board['name'] ?? $bc_forum_name)); ?></a>
<a class="aksrt-forum-topic__board-link" href="<?php echo esc_url((string) ($board['url'] ?? aksrt_get_forum_home_url())); ?>"><?php echo esc_html((string) ($board['name'] ?? $bc_forum_name)); ?></a>
</span>
<span class="aksrt-forum-topic__author">
<?php if (!empty($topic['author']['avatar_url'])) : ?>
+15 -2
View File
@@ -28,11 +28,13 @@ $view = $forum ? $forum->get_home_view($current_user_id) : [
$boards = $view['boards'] ?? [];
$recent_topics = $view['recent_topics'] ?? [];
$synthesis = is_array($view['synthesis'] ?? null) ? $view['synthesis'] : ['items' => $recent_topics, 'max_pages' => 1, 'page' => 1, 'total' => count($recent_topics)];
$synthesis_max = max(1, (int) ($synthesis['max_pages'] ?? 1));
$hot_topics = $view['hot_topics'] ?? [];
$stats = $view['stats'] ?? [];
$permissions = $view['permissions'] ?? [];
$applications = $view['applications'] ?? [];
$compose_url = home_url('/compose/');
$compose_url = aksrt_get_forum_compose_url();
$forum_settings = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_forum_settings() : [];
$forum_names = $forum_settings['names'] ?? [];
@@ -258,10 +260,21 @@ if ($active_tab_type === '') {
if ($forum) { $forum->render_topic_row($topic); }
} ?>
</div>
<?php if ($synthesis_max > 1) : ?>
<div class="aksrt-forum-home__load-more">
<button type="button" class="aksrt-forum-replies__more-btn js-aksrt-home-load-more"
data-page="1" data-max="<?php echo esc_attr((string) $synthesis_max); ?>" data-tab="synthesis">
<i class="fas fa-chevron-down"></i> <?php esc_html_e('加载更多', 'aksrt'); ?>
</button>
</div>
<?php endif; ?>
<?php else : ?>
<div class="aksrt-forum__empty">
<i class="fas fa-feather-alt"></i>
<p><?php esc_html_e('还没有公开主题,欢迎创建第一个讨论。', 'aksrt'); ?></p>
<p><?php esc_html_e('内容空空如也', 'aksrt'); ?></p>
<?php if (!empty($permissions['can_compose'])) : ?>
<a href="<?php echo esc_url($compose_url); ?>"><?php esc_html_e('发布第一个主题', 'aksrt'); ?></a>
<?php endif; ?>
</div>
<?php endif; ?>
<?php endif; ?>
+1 -1
View File
@@ -18,7 +18,7 @@ extract($args, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_ext
<h2 class="uh-forum__section-title-main"><?php esc_html_e('论坛内容', 'aksrt'); ?></h2>
<p class="uh-forum__section-desc"><?php esc_html_e('在用户主页中保留论坛维度,但仍以内容流和身份展示为主。', 'aksrt'); ?></p>
</div>
<a class="uh-forum__section-link" href="<?php echo esc_url(home_url('/forums/')); ?>"><?php esc_html_e('进入社区', 'aksrt'); ?></a>
<a class="uh-forum__section-link" href="<?php echo esc_url(aksrt_get_forum_home_url()); ?>"><?php esc_html_e('进入社区', 'aksrt'); ?></a>
</div>
<?php
$forum_page = max(1, isset($_GET['forum_page']) ? (int) $_GET['forum_page'] : 1);