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
@@ -9,10 +9,46 @@ trait AKSRT_Forum_Board_Service_Part_2 {
|
||||
*/
|
||||
public function get_board_view(int $board_id, array $args = []): array {
|
||||
$user_id = (int) ($args['user_id'] ?? get_current_user_id());
|
||||
$page = max(1, (int) ($args['paged'] ?? 1));
|
||||
$page = max(1, (int) ($args['paged'] ?? $args['page'] ?? 1));
|
||||
$orderby = sanitize_key((string) ($args['orderby'] ?? $args['sort'] ?? ''));
|
||||
|
||||
$board_page = class_exists('AKSRT_Settings')
|
||||
? (AKSRT_Settings::get_forum_settings()['board_page'] ?? [])
|
||||
: [];
|
||||
$tabs = is_array($board_page['tabs'] ?? null) ? $board_page['tabs'] : [
|
||||
['label' => '全部', 'sort' => 'date'],
|
||||
['label' => '推荐', 'sort' => 'featured'],
|
||||
['label' => '最新回复', 'sort' => 'last_reply'],
|
||||
['label' => '热门', 'sort' => 'hot'],
|
||||
['label' => '精华', 'sort' => 'essence'],
|
||||
];
|
||||
$allowed_sorts = [];
|
||||
foreach ($tabs as $tab) {
|
||||
$sort = sanitize_key((string) ($tab['sort'] ?? ''));
|
||||
if ($sort !== '') {
|
||||
$allowed_sorts[] = $sort;
|
||||
}
|
||||
}
|
||||
if ($orderby === '' || !in_array($orderby, $allowed_sorts, true)) {
|
||||
$active_index = max(0, (int) ($board_page['tab_active_index'] ?? 0));
|
||||
$orderby = sanitize_key((string) ($tabs[$active_index]['sort'] ?? 'date'));
|
||||
if ($orderby === '') {
|
||||
$orderby = 'date';
|
||||
}
|
||||
}
|
||||
|
||||
$compose_url = function_exists('aksrt_get_forum_compose_url')
|
||||
? aksrt_get_forum_compose_url(['board' => $board_id])
|
||||
: home_url('/');
|
||||
$top_info = !isset($board_page['top_info']) || !empty($board_page['top_info']);
|
||||
|
||||
if ($this->forum->is_plate_cpt_active()) {
|
||||
return $this->get_plate_view_compat($board_id, $user_id, $page);
|
||||
$view = $this->get_plate_view_compat($board_id, $user_id, $page, $orderby);
|
||||
$view['tabs'] = $tabs;
|
||||
$view['active_sort'] = $orderby;
|
||||
$view['top_info'] = $top_info;
|
||||
$view['compose_url'] = $compose_url;
|
||||
return $view;
|
||||
}
|
||||
|
||||
$board = get_term($board_id, 'aksrt_forum_board');
|
||||
@@ -27,6 +63,10 @@ trait AKSRT_Forum_Board_Service_Part_2 {
|
||||
'permissions' => [],
|
||||
'application' => null,
|
||||
'board_options' => [],
|
||||
'tabs' => $tabs,
|
||||
'active_sort' => $orderby,
|
||||
'top_info' => $top_info,
|
||||
'compose_url' => function_exists('aksrt_get_forum_compose_url') ? aksrt_get_forum_compose_url() : home_url('/'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -36,6 +76,7 @@ trait AKSRT_Forum_Board_Service_Part_2 {
|
||||
'limit' => 20,
|
||||
'status' => 'publish',
|
||||
'viewer_user_id' => $user_id,
|
||||
'orderby' => $orderby,
|
||||
]);
|
||||
|
||||
$sticky_topics = $this->forum->get_sticky_topics_for_board($board_id);
|
||||
@@ -75,13 +116,17 @@ trait AKSRT_Forum_Board_Service_Part_2 {
|
||||
],
|
||||
'application' => $user_id > 0 ? $this->forum->get_board_application_for_user($user_id, $board_id) : null,
|
||||
'board_options' => $this->get_boards(),
|
||||
'tabs' => $tabs,
|
||||
'active_sort' => $orderby,
|
||||
'top_info' => $top_info,
|
||||
'compose_url' => $compose_url,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Plate CPT board view (backwards-compatible with get_board_view return shape).
|
||||
*/
|
||||
private function get_plate_view_compat(int $plate_id, int $user_id, int $page): array {
|
||||
private function get_plate_view_compat(int $plate_id, int $user_id, int $page, string $orderby = 'date'): array {
|
||||
$plate = $this->get_plate($plate_id);
|
||||
if (!$plate) {
|
||||
return [
|
||||
@@ -123,6 +168,7 @@ trait AKSRT_Forum_Board_Service_Part_2 {
|
||||
'limit' => 20,
|
||||
'status' => 'publish',
|
||||
'viewer_user_id' => $user_id,
|
||||
'orderby' => $orderby,
|
||||
]);
|
||||
|
||||
$sticky_topics = $this->get_sticky_topics_for_plate($plate_id);
|
||||
|
||||
Reference in new issue
Block a user