feat(widgets): shared forum topic/plate renderers for list depth
Extract aksrt_render_forum_topic_mini/detail and plate row/card helpers, then wire TopicLists, PlateLists, and BoardList for zibll-aligned DOM, lazy thumbs, and identity-aware topic rows.
This commit is contained in:
@@ -32,6 +32,7 @@ require_once AKSRT_DIR . '/inc/helpers/aksrt-archive.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-archive-filters.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-comments.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-forum.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-forum-widgets.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-slider.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-vip.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-auth-ui.php';
|
||||
|
||||
@@ -0,0 +1,363 @@
|
||||
<?php
|
||||
/**
|
||||
* Shared forum widget renderers (zibll BBS posts/plate mini parity).
|
||||
*
|
||||
* Used by WidgetForumTopicLists, WidgetForumTabTopics, WidgetForumPlateLists,
|
||||
* WidgetForumBoardList, WidgetForumPlateModerator.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
if (!function_exists('aksrt_forum_topic_meta_flags')) :
|
||||
/**
|
||||
* @return array{topping:bool,essence:bool,views:int,replies:int,plate_id:int}
|
||||
*/
|
||||
function aksrt_forum_topic_meta_flags(int $post_id): array {
|
||||
return [
|
||||
'topping' => (string) get_post_meta($post_id, '_aksrt_topping', true) === '1'
|
||||
|| (string) get_post_meta($post_id, '_aksrt_is_top', true) === '1',
|
||||
'essence' => (string) get_post_meta($post_id, '_aksrt_essence', true) === '1',
|
||||
'views' => (int) get_post_meta($post_id, '_aksrt_views', true),
|
||||
'replies' => (int) get_comments_number($post_id),
|
||||
'plate_id' => (int) get_post_meta($post_id, '_aksrt_plate_id', true),
|
||||
];
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_forum_topic_badges_html')) :
|
||||
/**
|
||||
* Topping / essence badges for forum topic rows.
|
||||
*/
|
||||
function aksrt_forum_topic_badges_html(int $post_id, bool $show_topping = true): string {
|
||||
$flags = aksrt_forum_topic_meta_flags($post_id);
|
||||
$html = '';
|
||||
if ($show_topping && !empty($flags['topping'])) {
|
||||
$html .= '<badge class="img-badge left jb-red"><i>' . esc_html__('置顶', 'aksrt') . '</i></badge>';
|
||||
}
|
||||
if (!empty($flags['essence'])) {
|
||||
$html .= '<badge class="img-badge right jb-yellow"><i>' . esc_html__('精华', 'aksrt') . '</i></badge>';
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_render_forum_topic_mini')) :
|
||||
/**
|
||||
* Mini forum topic row (zibll zib_bbs_get_posts_mini_list parity).
|
||||
*
|
||||
* @param int|null $post_id Null = current post in loop.
|
||||
* @param string $class Extra classes on outer element.
|
||||
* @param bool $show_topping Whether to show topping badge.
|
||||
*/
|
||||
function aksrt_render_forum_topic_mini(?int $post_id = null, string $class = 'ajax-item', bool $show_topping = true): string {
|
||||
$post_id = $post_id ?: (int) get_the_ID();
|
||||
if ($post_id <= 0) {
|
||||
return '';
|
||||
}
|
||||
$post = get_post($post_id);
|
||||
if (!$post || $post->post_status !== 'publish') {
|
||||
return '';
|
||||
}
|
||||
|
||||
$author_id = (int) $post->post_author;
|
||||
$flags = aksrt_forum_topic_meta_flags($post_id);
|
||||
$permalink = get_permalink($post_id);
|
||||
$title = get_the_title($post_id);
|
||||
|
||||
$avatar_url = function_exists('aksrt_get_avatar_url')
|
||||
? aksrt_get_avatar_url($author_id, ['size' => 48])
|
||||
: get_avatar_url($author_id, ['size' => 48]);
|
||||
$home = function_exists('aksrt_get_user_home_url')
|
||||
? aksrt_get_user_home_url($author_id)
|
||||
: get_author_posts_url($author_id);
|
||||
|
||||
$name = function_exists('aksrt_get_user_name')
|
||||
? aksrt_get_user_name([
|
||||
'id' => $author_id,
|
||||
'class' => 'flex ac flex1',
|
||||
'follow' => false,
|
||||
'medal' => false,
|
||||
'level' => false,
|
||||
])
|
||||
: '<a href="' . esc_url($home) . '">' . esc_html(get_the_author_meta('display_name', $author_id)) . '</a>';
|
||||
|
||||
// Prefer last reply time when available.
|
||||
$time_raw = (string) get_post_meta($post_id, '_aksrt_last_reply_time', true);
|
||||
if ($time_raw === '' || !strtotime($time_raw)) {
|
||||
$time_raw = (string) $post->post_date;
|
||||
}
|
||||
$time_txt = function_exists('aksrt_time_ago')
|
||||
? aksrt_time_ago($time_raw)
|
||||
: human_time_diff(strtotime($time_raw), current_time('timestamp')) . __('前', 'aksrt');
|
||||
|
||||
$views_txt = function_exists('aksrt_format_number')
|
||||
? aksrt_format_number($flags['views'])
|
||||
: (string) $flags['views'];
|
||||
|
||||
$cls = trim('forum-posts mini aksrt-ftopic-mini relative ' . $class);
|
||||
$html = '<posts class="' . esc_attr($cls) . '">';
|
||||
$html .= aksrt_forum_topic_badges_html($post_id, $show_topping);
|
||||
$html .= '<div class="forum-posts-header flex ac">';
|
||||
$html .= '<a class="avatar-img mr6" href="' . esc_url($home) . '"><img class="avatar aksrt-lazy lazyload" data-src="' . esc_url($avatar_url) . '" src="' . esc_url(get_template_directory_uri() . '/assets/img/placeholder.svg') . '" alt="" loading="lazy" width="28" height="28" /></a>';
|
||||
$html .= '<div class="flex1 min-w0">';
|
||||
$html .= '<div class="forum-title text-ellipsis"><a class="icon-circle" href="' . esc_url($permalink) . '">' . esc_html($title) . '</a></div>';
|
||||
$html .= '<div class="item-meta em09 muted-2-color flex ac flex-wrap">';
|
||||
$html .= '<span class="forum-user-name">' . $name . '</span>';
|
||||
$html .= '<span class="ml6">' . esc_html($time_txt) . '</span>';
|
||||
$html .= '<span class="ml6"><i class="fa fa-eye" aria-hidden="true"></i> ' . esc_html((string) $views_txt) . '</span>';
|
||||
if ($flags['replies'] > 0) {
|
||||
$html .= '<span class="ml6"><i class="fa fa-comment-o" aria-hidden="true"></i> ' . esc_html((string) $flags['replies']) . '</span>';
|
||||
}
|
||||
$html .= '</div></div></div></posts>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_render_forum_topic_detail')) :
|
||||
/**
|
||||
* Detail forum topic row (richer entry meta).
|
||||
*
|
||||
* @param int|null $post_id
|
||||
* @param string $class
|
||||
* @param bool $show_topping
|
||||
*/
|
||||
function aksrt_render_forum_topic_detail(?int $post_id = null, string $class = 'ajax-item', bool $show_topping = true): string {
|
||||
$post_id = $post_id ?: (int) get_the_ID();
|
||||
if ($post_id <= 0) {
|
||||
return '';
|
||||
}
|
||||
$post = get_post($post_id);
|
||||
if (!$post || $post->post_status !== 'publish') {
|
||||
return '';
|
||||
}
|
||||
|
||||
$author_id = (int) $post->post_author;
|
||||
$flags = aksrt_forum_topic_meta_flags($post_id);
|
||||
$permalink = get_permalink($post_id);
|
||||
$title = get_the_title($post_id);
|
||||
$excerpt = wp_trim_words(wp_strip_all_tags((string) $post->post_content), 36, '…');
|
||||
|
||||
$avatar_url = function_exists('aksrt_get_avatar_url')
|
||||
? aksrt_get_avatar_url($author_id, ['size' => 64])
|
||||
: get_avatar_url($author_id, ['size' => 64]);
|
||||
$home = function_exists('aksrt_get_user_home_url')
|
||||
? aksrt_get_user_home_url($author_id)
|
||||
: get_author_posts_url($author_id);
|
||||
|
||||
$name = function_exists('aksrt_get_user_name')
|
||||
? aksrt_get_user_name([
|
||||
'id' => $author_id,
|
||||
'class' => 'flex ac',
|
||||
'follow' => false,
|
||||
'medal' => true,
|
||||
'level' => true,
|
||||
])
|
||||
: '<a href="' . esc_url($home) . '">' . esc_html(get_the_author_meta('display_name', $author_id)) . '</a>';
|
||||
|
||||
$time_raw = (string) get_post_meta($post_id, '_aksrt_last_reply_time', true);
|
||||
if ($time_raw === '' || !strtotime($time_raw)) {
|
||||
$time_raw = (string) $post->post_date;
|
||||
}
|
||||
$time_txt = function_exists('aksrt_time_ago')
|
||||
? aksrt_time_ago($time_raw)
|
||||
: human_time_diff(strtotime($time_raw), current_time('timestamp')) . __('前', 'aksrt');
|
||||
|
||||
$views_txt = function_exists('aksrt_format_number')
|
||||
? aksrt_format_number($flags['views'])
|
||||
: (string) $flags['views'];
|
||||
|
||||
// Optional plate name chip.
|
||||
$plate_chip = '';
|
||||
if ($flags['plate_id'] > 0) {
|
||||
$plate = get_post($flags['plate_id']);
|
||||
if ($plate instanceof WP_Post) {
|
||||
$plate_chip = '<a class="but p2-10 em09 mr6" href="' . esc_url(get_permalink($plate)) . '">' . esc_html(get_the_title($plate)) . '</a>';
|
||||
}
|
||||
}
|
||||
|
||||
$cls = trim('forum-posts detail aksrt-ftopic-detail relative ' . $class);
|
||||
$html = '<posts class="' . esc_attr($cls) . '">';
|
||||
$html .= aksrt_forum_topic_badges_html($post_id, $show_topping);
|
||||
$html .= '<div class="forum-posts-header flex ac">';
|
||||
$html .= '<a class="avatar-img mr10" href="' . esc_url($home) . '"><img class="avatar aksrt-lazy lazyload" data-src="' . esc_url($avatar_url) . '" src="' . esc_url(get_template_directory_uri() . '/assets/img/placeholder.svg') . '" alt="" loading="lazy" width="40" height="40" /></a>';
|
||||
$html .= '<div class="flex1 min-w0">' . $name . '<div class="em09 muted-2-color mt3">' . esc_html($time_txt) . '</div></div>';
|
||||
$html .= '</div>';
|
||||
$html .= '<h2 class="forum-title mt10"><a href="' . esc_url($permalink) . '">' . esc_html($title) . '</a></h2>';
|
||||
if ($excerpt !== '') {
|
||||
$html .= '<div class="forum-excerpt muted-2-color em09 mt6">' . esc_html($excerpt) . '</div>';
|
||||
}
|
||||
$html .= '<div class="item-meta flex ac flex-wrap mt10 em09 muted-2-color">';
|
||||
$html .= $plate_chip;
|
||||
$html .= '<span class="mr10"><i class="fa fa-eye" aria-hidden="true"></i> ' . esc_html((string) $views_txt) . '</span>';
|
||||
$html .= '<span class="mr10"><i class="fa fa-comment-o" aria-hidden="true"></i> ' . esc_html((string) $flags['replies']) . '</span>';
|
||||
$html .= '</div></posts>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_render_plate_thumb_html')) :
|
||||
/**
|
||||
* Shared plate thumb with lazy pattern.
|
||||
*/
|
||||
function aksrt_render_plate_thumb_html(int $plate_id, string $size = 'thumbnail'): string {
|
||||
$thumb = get_the_post_thumbnail_url($plate_id, $size);
|
||||
$icon = (string) get_post_meta($plate_id, '_aksrt_icon', true);
|
||||
$ph = get_template_directory_uri() . '/assets/img/placeholder.svg';
|
||||
if ($thumb) {
|
||||
return '<span class="plate-thumb aksrt-plate-item__thumb"><img class="aksrt-lazy lazyload fit-cover" data-src="' . esc_url($thumb) . '" src="' . esc_url($ph) . '" alt="" loading="lazy" width="48" height="48" /></span>';
|
||||
}
|
||||
if ($icon !== '') {
|
||||
return '<span class="plate-thumb aksrt-plate-item__thumb is-icon"><i class="' . esc_attr($icon) . '" aria-hidden="true"></i></span>';
|
||||
}
|
||||
return '<span class="plate-thumb aksrt-plate-item__thumb is-empty"><i class="fa fa-comments" aria-hidden="true"></i></span>';
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_render_plate_row')) :
|
||||
/**
|
||||
* Plate list row (zibll plate-item flex).
|
||||
*
|
||||
* @param WP_Post|int $plate
|
||||
*/
|
||||
function aksrt_render_plate_row($plate): string {
|
||||
$post = $plate instanceof WP_Post ? $plate : get_post((int) $plate);
|
||||
if (!$post instanceof WP_Post) {
|
||||
return '';
|
||||
}
|
||||
$id = (int) $post->ID;
|
||||
$url = get_permalink($id);
|
||||
$count = (int) get_post_meta($id, '_aksrt_posts_count', true);
|
||||
$follow = (int) get_post_meta($id, '_aksrt_follow_count', true);
|
||||
$desc = $post->post_excerpt !== '' ? $post->post_excerpt : wp_trim_words(wp_strip_all_tags((string) $post->post_content), 18);
|
||||
|
||||
$html = '<a class="plate-item flex aksrt-plate-item ajax-item" href="' . esc_url($url) . '">';
|
||||
$html .= aksrt_render_plate_thumb_html($id, 'thumbnail');
|
||||
$html .= '<div class="item-info flex1 aksrt-plate-item__body">';
|
||||
$html .= '<div class="info-header"><h2 class="forum-title aksrt-plate-item__title">' . esc_html(get_the_title($post)) . '</h2></div>';
|
||||
if ($desc !== '') {
|
||||
$html .= '<div class="muted-2-color em09 mt3 text-ellipsis aksrt-plate-item__desc">' . esc_html($desc) . '</div>';
|
||||
}
|
||||
$html .= '<div class="item-meta em09 muted-2-color mt3 aksrt-plate-item__meta">';
|
||||
$html .= '<span>' . esc_html(sprintf(/* translators: %d topic count */ __('%d 帖', 'aksrt'), $count)) . '</span>';
|
||||
if ($follow > 0) {
|
||||
$html .= '<span class="ml10">' . esc_html(sprintf(/* translators: %d follow count */ __('%d 关注', 'aksrt'), $follow)) . '</span>';
|
||||
}
|
||||
$html .= '</div></div></a>';
|
||||
return $html;
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_render_plate_card')) :
|
||||
/**
|
||||
* Plate card slide item.
|
||||
*
|
||||
* @param WP_Post|int $plate
|
||||
*/
|
||||
function aksrt_render_plate_card($plate): string {
|
||||
$post = $plate instanceof WP_Post ? $plate : get_post((int) $plate);
|
||||
if (!$post instanceof WP_Post) {
|
||||
return '';
|
||||
}
|
||||
$id = (int) $post->ID;
|
||||
$url = get_permalink($id);
|
||||
$thumb = get_the_post_thumbnail_url($id, 'medium');
|
||||
$count = (int) get_post_meta($id, '_aksrt_posts_count', true);
|
||||
$follow = (int) get_post_meta($id, '_aksrt_follow_count', true);
|
||||
$ph = get_template_directory_uri() . '/assets/img/placeholder.svg';
|
||||
|
||||
$html = '<a class="plate-card aksrt-plate-card ajax-item" href="' . esc_url($url) . '">';
|
||||
$html .= '<div class="plate-thumb aksrt-plate-card__cover">';
|
||||
if ($thumb) {
|
||||
$html .= '<img class="aksrt-lazy lazyload fit-cover" data-src="' . esc_url($thumb) . '" src="' . esc_url($ph) . '" alt="" loading="lazy" />';
|
||||
} else {
|
||||
$html .= '<span class="is-empty"><i class="fa fa-comments" aria-hidden="true"></i></span>';
|
||||
}
|
||||
$html .= '</div>';
|
||||
$html .= '<div class="aksrt-plate-card__title forum-title mt10">' . esc_html(get_the_title($post)) . '</div>';
|
||||
$html .= '<div class="aksrt-plate-card__meta muted-2-color em09 mt6">';
|
||||
$html .= '<span>' . esc_html(sprintf(__('%d 帖', 'aksrt'), $count)) . '</span>';
|
||||
$html .= '<span class="ml10">' . esc_html(sprintf(__('%d 关注', 'aksrt'), $follow)) . '</span>';
|
||||
$html .= '</div></a>';
|
||||
return $html;
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_render_moderator_row')) :
|
||||
/**
|
||||
* Moderator identity row with optional follow.
|
||||
*
|
||||
* @param int $user_id
|
||||
* @param string $role author|super|moderator
|
||||
* @param bool $show_avatar
|
||||
* @param string $style list|grid
|
||||
*/
|
||||
function aksrt_render_moderator_row(int $user_id, string $role = 'moderator', bool $show_avatar = true, string $style = 'list'): string {
|
||||
if ($user_id <= 0) {
|
||||
return '';
|
||||
}
|
||||
$user = get_userdata($user_id);
|
||||
if (!$user) {
|
||||
return '';
|
||||
}
|
||||
$avatar = function_exists('aksrt_get_avatar_url')
|
||||
? aksrt_get_avatar_url($user_id, ['size' => 64])
|
||||
: get_avatar_url($user_id, ['size' => 64]);
|
||||
$home = function_exists('aksrt_get_user_home_url')
|
||||
? aksrt_get_user_home_url($user_id)
|
||||
: get_author_posts_url($user_id);
|
||||
$ph = get_template_directory_uri() . '/assets/img/placeholder.svg';
|
||||
|
||||
if ($role === 'author' || $role === 'super') {
|
||||
$role_label = __('超级版主', 'aksrt');
|
||||
} else {
|
||||
$role_label = __('版主', 'aksrt');
|
||||
}
|
||||
|
||||
$name = function_exists('aksrt_get_user_name')
|
||||
? aksrt_get_user_name([
|
||||
'id' => $user_id,
|
||||
'class' => 'flex ac flex1',
|
||||
'follow' => false,
|
||||
'medal' => true,
|
||||
'level' => true,
|
||||
])
|
||||
: '<a href="' . esc_url($home) . '">' . esc_html($user->display_name) . '</a>';
|
||||
|
||||
// Follow control (not for self).
|
||||
$follow_html = '';
|
||||
$cuid = get_current_user_id();
|
||||
if ($cuid > 0 && $cuid !== $user_id && class_exists('\AKSRT\User\Follow')) {
|
||||
$following = \AKSRT\User\Follow::get_instance()->is_following($cuid, $user_id);
|
||||
$label = $following ? __('已关注', 'aksrt') : __('关注', 'aksrt');
|
||||
$follow_html = '<button type="button" class="but hollow c-blue p2-10 em09 ml10 flex0' . ($following ? ' is-following' : '') . '" data-aksrt-follow="' . (int) $user_id . '">' . esc_html($label) . '</button>';
|
||||
}
|
||||
|
||||
if ($style === 'grid') {
|
||||
$html = '<div class="aksrt-plate-mods__item role-' . esc_attr($role) . ' is-grid">';
|
||||
if ($show_avatar) {
|
||||
$html .= '<a href="' . esc_url($home) . '"><img class="aksrt-plate-mods__avatar aksrt-lazy lazyload" data-src="' . esc_url($avatar) . '" src="' . esc_url($ph) . '" alt="" loading="lazy" width="48" height="48" /></a>';
|
||||
}
|
||||
$html .= '<div class="aksrt-plate-mods__name">' . $name . '</div>';
|
||||
$html .= '<div class="aksrt-plate-mods__role muted-2-color em09">' . esc_html($role_label) . '</div>';
|
||||
$html .= $follow_html;
|
||||
$html .= '</div>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
$html = '<div class="aksrt-plate-mods__item role-' . esc_attr($role) . ' flex ac">';
|
||||
if ($show_avatar) {
|
||||
$html .= '<a class="avatar-img mr10" href="' . esc_url($home) . '"><img class="aksrt-plate-mods__avatar aksrt-lazy lazyload" data-src="' . esc_url($avatar) . '" src="' . esc_url($ph) . '" alt="" loading="lazy" width="40" height="40" /></a>';
|
||||
}
|
||||
$html .= '<div class="flex1 min-w0">';
|
||||
$html .= '<div class="aksrt-plate-mods__name">' . $name . '</div>';
|
||||
$html .= '<div class="aksrt-plate-mods__role muted-2-color em09">' . esc_html($role_label) . '</div>';
|
||||
$html .= '</div>';
|
||||
$html .= $follow_html;
|
||||
$html .= '</div>';
|
||||
return $html;
|
||||
}
|
||||
endif;
|
||||
@@ -57,27 +57,44 @@ class WidgetForumBoardList extends \WP_Widget {
|
||||
$plates = get_posts($query_args);
|
||||
if ($plates) {
|
||||
ob_start();
|
||||
echo '<ul class="aksrt-forum-widget__boards style-' . esc_attr($style) . ' ajax-item">';
|
||||
foreach ($plates as $plate) {
|
||||
$icon = (string) get_post_meta($plate->ID, '_aksrt_icon', true);
|
||||
$count = (int) get_post_meta($plate->ID, '_aksrt_posts_count', true);
|
||||
$thumb = get_the_post_thumbnail_url($plate->ID, 'thumbnail');
|
||||
echo '<li class="aksrt-forum-widget__board">';
|
||||
echo '<a href="' . esc_url(get_permalink($plate)) . '">';
|
||||
if ($style === 'mini' && $thumb) {
|
||||
echo '<img class="aksrt-forum-widget__thumb" src="' . esc_url($thumb) . '" alt="" width="28" height="28" loading="lazy" />';
|
||||
} elseif ($icon !== '') {
|
||||
echo '<i class="' . esc_attr($icon) . '"></i> ';
|
||||
if ($style === 'mini' && function_exists('aksrt_render_plate_row')) {
|
||||
// Compact mini still uses shared plate row for consistent DOM/lazy.
|
||||
echo '<div class="plate-lists aksrt-forum-widget__boards style-mini ajax-item">';
|
||||
foreach ($plates as $plate) {
|
||||
echo aksrt_render_plate_row($plate); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
echo '<span class="aksrt-forum-widget__name">' . esc_html(get_the_title($plate)) . '</span>';
|
||||
echo '<span class="aksrt-forum-widget__count">' . esc_html((string) $count) . '</span>';
|
||||
echo '</a></li>';
|
||||
echo '</div>';
|
||||
} elseif (function_exists('aksrt_render_plate_row')) {
|
||||
echo '<div class="plate-lists aksrt-forum-widget__boards style-list ajax-item">';
|
||||
foreach ($plates as $plate) {
|
||||
echo aksrt_render_plate_row($plate); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
echo '</div>';
|
||||
} else {
|
||||
echo '<ul class="aksrt-forum-widget__boards style-' . esc_attr($style) . ' ajax-item">';
|
||||
foreach ($plates as $plate) {
|
||||
$icon = (string) get_post_meta($plate->ID, '_aksrt_icon', true);
|
||||
$count = (int) get_post_meta($plate->ID, '_aksrt_posts_count', true);
|
||||
$thumb = get_the_post_thumbnail_url($plate->ID, 'thumbnail');
|
||||
$ph = get_template_directory_uri() . '/assets/img/placeholder.svg';
|
||||
echo '<li class="aksrt-forum-widget__board">';
|
||||
echo '<a href="' . esc_url(get_permalink($plate)) . '">';
|
||||
if ($style === 'mini' && $thumb) {
|
||||
echo '<img class="aksrt-forum-widget__thumb aksrt-lazy lazyload" data-src="' . esc_url($thumb) . '" src="' . esc_url($ph) . '" alt="" width="28" height="28" loading="lazy" />';
|
||||
} elseif ($icon !== '') {
|
||||
echo '<i class="' . esc_attr($icon) . '"></i> ';
|
||||
}
|
||||
echo '<span class="aksrt-forum-widget__name">' . esc_html(get_the_title($plate)) . '</span>';
|
||||
echo '<span class="aksrt-forum-widget__count">' . esc_html((string) $count) . '</span>';
|
||||
echo '</a></li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
}
|
||||
echo '</ul>';
|
||||
return (string) ob_get_clean();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Taxonomy fallback.
|
||||
$term_args = [
|
||||
'taxonomy' => 'aksrt_forum_board',
|
||||
|
||||
@@ -88,20 +88,27 @@ class WidgetForumPlateLists extends \WP_Widget {
|
||||
return '';
|
||||
}
|
||||
ob_start();
|
||||
$self = new self();
|
||||
if ($style === 'card') {
|
||||
echo '<div class="aksrt-plate-cards ajax-item">';
|
||||
echo '<div class="panel-plate scroll-plate aksrt-plate-cards">';
|
||||
foreach ($plates as $post) {
|
||||
if ($post instanceof \WP_Post) {
|
||||
$self->render_card($post);
|
||||
if (function_exists('aksrt_render_plate_card')) {
|
||||
echo aksrt_render_plate_card($post); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
} else {
|
||||
(new self())->render_card($post);
|
||||
}
|
||||
}
|
||||
}
|
||||
echo '</div>';
|
||||
} else {
|
||||
echo '<div class="aksrt-plate-lists ajax-item">';
|
||||
echo '<div class="plate-lists aksrt-plate-lists">';
|
||||
foreach ($plates as $post) {
|
||||
if ($post instanceof \WP_Post) {
|
||||
$self->render_row($post);
|
||||
if (function_exists('aksrt_render_plate_row')) {
|
||||
echo aksrt_render_plate_row($post); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
} else {
|
||||
(new self())->render_row($post);
|
||||
}
|
||||
}
|
||||
}
|
||||
echo '</div>';
|
||||
@@ -154,42 +161,56 @@ class WidgetForumPlateLists extends \WP_Widget {
|
||||
}
|
||||
|
||||
public function render_row(\WP_Post $post): void {
|
||||
if (function_exists('aksrt_render_plate_row')) {
|
||||
echo aksrt_render_plate_row($post); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
return;
|
||||
}
|
||||
$id = (int) $post->ID;
|
||||
$url = get_permalink($id);
|
||||
$thumb = get_the_post_thumbnail_url($id, 'thumbnail');
|
||||
$icon = (string) get_post_meta($id, '_aksrt_icon', true);
|
||||
$count = (int) get_post_meta($id, '_aksrt_posts_count', true);
|
||||
$desc = $post->post_excerpt !== '' ? $post->post_excerpt : wp_trim_words(wp_strip_all_tags($post->post_content), 18);
|
||||
$ph = get_template_directory_uri() . '/assets/img/placeholder.svg';
|
||||
|
||||
echo '<a class="aksrt-plate-item" href="' . esc_url($url) . '">';
|
||||
echo '<div class="aksrt-plate-item__thumb">';
|
||||
echo '<a class="plate-item flex aksrt-plate-item" href="' . esc_url($url) . '">';
|
||||
echo '<div class="plate-thumb aksrt-plate-item__thumb">';
|
||||
if ($thumb) {
|
||||
echo '<img src="' . esc_url($thumb) . '" alt="" loading="lazy" />';
|
||||
echo '<img class="aksrt-lazy lazyload" data-src="' . esc_url($thumb) . '" src="' . esc_url($ph) . '" alt="" loading="lazy" />';
|
||||
} elseif ($icon !== '') {
|
||||
echo '<i class="' . esc_attr($icon) . '" aria-hidden="true"></i>';
|
||||
} else {
|
||||
echo '<i class="fas fa-comments" aria-hidden="true"></i>';
|
||||
}
|
||||
echo '</div>';
|
||||
echo '<div class="aksrt-plate-item__body">';
|
||||
echo '<div class="aksrt-plate-item__title">' . esc_html(get_the_title($post)) . '</div>';
|
||||
echo '<div class="item-info flex1 aksrt-plate-item__body">';
|
||||
echo '<div class="info-header"><div class="forum-title aksrt-plate-item__title">' . esc_html(get_the_title($post)) . '</div></div>';
|
||||
if ($desc !== '') {
|
||||
echo '<div class="aksrt-plate-item__desc">' . esc_html($desc) . '</div>';
|
||||
echo '<div class="aksrt-plate-item__desc muted-2-color em09">' . esc_html($desc) . '</div>';
|
||||
}
|
||||
echo '<div class="aksrt-plate-item__meta"><span>' . esc_html(sprintf(/* translators: %d topic count */ __('%d 帖', 'aksrt'), $count)) . '</span></div>';
|
||||
echo '</div></a>';
|
||||
}
|
||||
|
||||
public function render_card(\WP_Post $post): void {
|
||||
if (function_exists('aksrt_render_plate_card')) {
|
||||
echo aksrt_render_plate_card($post); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
return;
|
||||
}
|
||||
$id = (int) $post->ID;
|
||||
$url = get_permalink($id);
|
||||
$thumb = get_the_post_thumbnail_url($id, 'medium');
|
||||
$count = (int) get_post_meta($id, '_aksrt_posts_count', true);
|
||||
$follow = (int) get_post_meta($id, '_aksrt_follow_count', true);
|
||||
$ph = get_template_directory_uri() . '/assets/img/placeholder.svg';
|
||||
|
||||
echo '<a class="aksrt-plate-card" href="' . esc_url($url) . '">';
|
||||
echo '<div class="aksrt-plate-card__cover"' . ($thumb ? ' style="background-image:url(' . esc_url($thumb) . ')"' : '') . '></div>';
|
||||
echo '<div class="aksrt-plate-card__title">' . esc_html(get_the_title($post)) . '</div>';
|
||||
echo '<a class="plate-card aksrt-plate-card" href="' . esc_url($url) . '">';
|
||||
echo '<div class="plate-thumb aksrt-plate-card__cover">';
|
||||
if ($thumb) {
|
||||
echo '<img class="aksrt-lazy lazyload fit-cover" data-src="' . esc_url($thumb) . '" src="' . esc_url($ph) . '" alt="" loading="lazy" />';
|
||||
}
|
||||
echo '</div>';
|
||||
echo '<div class="aksrt-plate-card__title forum-title">' . esc_html(get_the_title($post)) . '</div>';
|
||||
echo '<div class="aksrt-plate-card__meta">';
|
||||
echo '<span>' . esc_html(sprintf(__('%d 帖', 'aksrt'), $count)) . '</span>';
|
||||
echo '<span>' . esc_html(sprintf(__('%d 关注', 'aksrt'), $follow)) . '</span>';
|
||||
|
||||
@@ -79,26 +79,25 @@ class WidgetForumTopicLists extends \WP_Widget {
|
||||
if (!$q->have_posts()) {
|
||||
return '';
|
||||
}
|
||||
$list_class = $style === 'detail' ? 'aksrt-ftopic-list is-detail' : 'aksrt-ftopic-list is-mini';
|
||||
ob_start();
|
||||
echo '<ul class="' . esc_attr($list_class) . '">';
|
||||
echo $style === 'detail'
|
||||
? '<div class="forum-posts-lists aksrt-ftopic-list is-detail">'
|
||||
: '<div class="forum-posts-lists aksrt-ftopic-list is-mini">';
|
||||
while ($q->have_posts()) {
|
||||
$q->the_post();
|
||||
$views = (int) get_post_meta(get_the_ID(), '_aksrt_views', true);
|
||||
echo '<li class="aksrt-ftopic-list__item ajax-item">';
|
||||
echo '<a class="aksrt-ftopic-list__link" href="' . esc_url(get_permalink()) . '">' . esc_html(get_the_title()) . '</a>';
|
||||
if ($style === 'detail') {
|
||||
echo '<div class="aksrt-ftopic-list__meta">';
|
||||
echo '<span>' . esc_html(get_the_author()) . '</span>';
|
||||
echo '<span>' . esc_html(get_the_date()) . '</span>';
|
||||
echo '<span><i class="fas fa-eye"></i> ' . esc_html((string) $views) . '</span>';
|
||||
echo '</div>';
|
||||
if ($style === 'detail' && function_exists('aksrt_render_forum_topic_detail')) {
|
||||
echo aksrt_render_forum_topic_detail(null, 'ajax-item', true); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
} elseif (function_exists('aksrt_render_forum_topic_mini')) {
|
||||
echo aksrt_render_forum_topic_mini(null, 'ajax-item', true); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
} else {
|
||||
$views = (int) get_post_meta(get_the_ID(), '_aksrt_views', true);
|
||||
echo '<div class="aksrt-ftopic-list__item ajax-item">';
|
||||
echo '<a class="aksrt-ftopic-list__link" href="' . esc_url(get_permalink()) . '">' . esc_html(get_the_title()) . '</a>';
|
||||
echo '<span class="aksrt-ftopic-list__views">' . esc_html((string) $views) . '</span>';
|
||||
echo '</div>';
|
||||
}
|
||||
echo '</li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
echo '</div>';
|
||||
wp_reset_postdata();
|
||||
return (string) ob_get_clean();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user