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:
1 parent
df6b224dd3
commit
780c8cb4f7
23 files changed
+843
-481
No files matched your search
+93
-117
@@ -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; ?>
|
||||
|
||||
Reference in new issue
Block a user