Files
wordpress-theme-aksrt/templates/forum/forum-board.php
T
kate522 aaf458af1c refactor(autoload): migrate theme classes to Composer PSR-4
Move 288 types from global AKSRT_* + inc/classes manual requires into
namespace AKSRT\{Domain} under src/AKSRT/, wire composer.json psr-4,
and slim bootstrap to helpers/modules/hooks only. Split multi-class
widget/gateway files, update admin contract audit paths, and document
the layout in ADR/README.
2026-07-17 13:29:22 +08:00

156 lines
7.2 KiB
PHP

<?php
/**
* Forum board template (legacy taxonomy archive).
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
get_header();
$forum = class_exists('\AKSRT\Forum\Forum') ? \AKSRT\Forum\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));
$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,
'orderby' => $forum_sort,
]) : [
'board' => null,
'topics' => [],
'sticky_topics' => [],
'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;
$topics = $view['topics'] ?? [];
$sticky_topics = $view['sticky_topics'] ?? [];
$moderators = $view['moderators'] ?? [];
$permissions = $view['permissions'] ?? [];
$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 = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_forum_settings() : [];
$forum_names = $forum_settings['names'] ?? [];
$name_topic = $forum_names['posts'] ?? __('主题', 'aksrt');
$name_reply = $forum_names['comment'] ?? __('回复', 'aksrt');
?>
<main id="main-content" class="site-main content-shell content-shell--stream content-shell--forum" tabindex="-1">
<div class="content-wrap container">
<div class="content-layout content-layout--no-sidebar">
<div class="content-layout__primary">
<?php if (function_exists('aksrt_breadcrumbs')) { aksrt_breadcrumbs(); } ?>
<div class="aksrt-forum-board"
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'] ?? ($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-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 endif; ?>
</div>
</div>
<?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">
<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>
</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, $board_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 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>
</div>
</div>
</div>
</div>
</main>
<?php get_footer(); ?>