Files
wordpress-theme-aksrt/templates/forum/forum-board.php
T

343 lines
21 KiB
PHP

<?php
/**
* Forum board template.
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
get_header();
$forum = class_exists('AKSRT_Forum') ? AKSRT_Forum::get_instance() : null;
$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));
$view = $forum ? $forum->get_board_view($board_id, [
'user_id' => $current_user_id,
'paged' => $paged,
]) : [
'board' => null,
'topics' => [],
'sticky_topics' => [],
'moderators' => [],
'pagination' => ['page' => 1, 'max_pages' => 1, 'total' => 0],
'permissions' => [],
'application' => null,
'board_options' => [],
];
$board_data = $view['board'] ?? null;
$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');
// 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__header">
<div class="aksrt-forum-board__info">
<h1 class="aksrt-forum-board__title"><?php echo esc_html((string) ($board_data['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>
</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'); ?>
</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 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-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
$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>
<?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>
<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>
<?php get_footer(); ?>