diff --git a/assets/css/frontend/widget-batch5.css b/assets/css/frontend/widget-batch5.css index 835d1ac8..3fc342b3 100644 --- a/assets/css/frontend/widget-batch5.css +++ b/assets/css/frontend/widget-batch5.css @@ -787,3 +787,99 @@ overflow: hidden; text-overflow: ellipsis; } + +/* ---- batch9: plate info actions / mods grid / board list / term polish ---- */ +.aksrt-plate-info__cover.is-icon { + display: flex; + align-items: center; + justify-content: center; + font-size: 32px; + color: var(--color-primary, #3b82f6); + background: linear-gradient(135deg, #eff6ff, #f5f3ff); +} +.aksrt-plate-info__actions { + display: flex; + flex-wrap: wrap; + gap: 8px; + margin-top: 12px; +} +.aksrt-plate-info__btn { + display: inline-flex; + align-items: center; + gap: 6px; + border: 0; + border-radius: 999px; + padding: 6px 12px; + font-size: 12px; + font-weight: 600; + cursor: pointer; + text-decoration: none; + line-height: 1.2; +} +.aksrt-plate-info__follow { + background: #ef4444; + color: #fff !important; +} +.aksrt-plate-info__follow.is-followed { + background: var(--surface-2, #e5e7eb); + color: inherit !important; +} +.aksrt-plate-info__compose { + background: var(--color-primary, #3b82f6); + color: #fff !important; +} + +.aksrt-plate-mods.style-grid .aksrt-plate-mods__list { + display: grid; + grid-template-columns: repeat(3, minmax(0, 1fr)); + gap: 10px; +} +.aksrt-plate-mods.style-grid .aksrt-plate-mods__item { + flex-direction: column; + text-align: center; + gap: 4px; +} +.aksrt-plate-mods.style-grid .aksrt-plate-mods__name { + font-size: 12px; + width: 100%; +} +.aksrt-plate-mods.style-grid .aksrt-plate-mods__role { + font-size: 10px; +} +.aksrt-plate-mods__item.role-author .aksrt-plate-mods__role, +.aksrt-plate-mods__item.role-super .aksrt-plate-mods__role { + color: #b45309; +} + +.aksrt-forum-widget__boards .aksrt-forum-widget__name { + flex: 1; + min-width: 0; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} +.aksrt-forum-widget__boards .aksrt-forum-widget__count { + margin-left: 8px; + color: var(--muted-2-color, #999); + font-size: 12px; + flex-shrink: 0; +} +.aksrt-forum-widget__boards.style-mini .aksrt-forum-widget__board a { + gap: 8px; +} +.aksrt-forum-widget__thumb { + width: 28px; + height: 28px; + border-radius: 6px; + object-fit: cover; + flex-shrink: 0; + margin-right: 4px; +} + +.aksrt-tag-cloud .c-blue-2 { background: #bfdbfe; color: #1e40af; } +.aksrt-tag-cloud .c-green-2 { background: #bbf7d0; color: #166534; } +.aksrt-tag-cloud .c-yellow-2 { background: #fde68a; color: #92400e; } +.aksrt-tag-cloud .c-purple-2 { background: #ddd6fe; color: #5b21b6; } +.aksrt-tag-cloud .c-red-2 { background: #fecaca; color: #991b1b; } + +.aksrt-home-widget__ajax .ajax-pag { margin-top: 12px; text-align: center; } diff --git a/src/AKSRT/Widgets/WidgetForumBoardList.php b/src/AKSRT/Widgets/WidgetForumBoardList.php index 5cd9d5d0..6127f973 100644 --- a/src/AKSRT/Widgets/WidgetForumBoardList.php +++ b/src/AKSRT/Widgets/WidgetForumBoardList.php @@ -1,5 +1,7 @@ __('显示论坛版块列表及话题数量。', 'aksrt')] - ); - } + public function __construct() { + parent::__construct( + 'aksrt_forum_board_list', + __('论坛 - 版块列表', 'aksrt'), + ['description' => __('显示论坛版块列表及话题数量。', 'aksrt')] + ); + } - public function widget($args, $instance): void { - $title = !empty($instance['title']) ? $instance['title'] : __('版块列表', 'aksrt'); + public static function render_html(array $instance): string { + $limit = max(1, min(50, (int) ($instance['count'] ?? $instance['showposts'] ?? 30))); + $orderby = sanitize_key((string) ($instance['orderby'] ?? 'menu_order')); + $style = sanitize_key((string) ($instance['style'] ?? 'list')); + if (!in_array($style, ['list', 'mini'], true)) { + $style = 'list'; + } - echo $args['before_widget']; - echo $args['before_title'] . esc_html($title) . $args['after_title']; + // Prefer plate CPT (same as plate_lists lite). + if (post_type_exists('aksrt_forum_plate')) { + $query_args = [ + 'post_type' => 'aksrt_forum_plate', + 'post_status' => 'publish', + 'posts_per_page' => $limit, + 'order' => 'ASC', + 'no_found_rows' => true, + ]; + switch ($orderby) { + case 'posts': + $query_args['meta_key'] = '_aksrt_posts_count'; + $query_args['orderby'] = 'meta_value_num'; + $query_args['order'] = 'DESC'; + break; + case 'views': + $query_args['meta_key'] = '_aksrt_views'; + $query_args['orderby'] = 'meta_value_num'; + $query_args['order'] = 'DESC'; + break; + case 'date': + $query_args['orderby'] = 'date'; + $query_args['order'] = 'DESC'; + break; + default: + $query_args['orderby'] = 'menu_order title'; + } + $plates = get_posts($query_args); + if ($plates) { + ob_start(); + echo '
'; + return (string) ob_get_clean(); + } + } - $rendered = false; - if (post_type_exists('aksrt_forum_plate')) { - $plates = get_posts([ - 'post_type' => 'aksrt_forum_plate', - 'post_status' => 'publish', - 'posts_per_page' => 30, - 'orderby' => 'menu_order title', - 'order' => 'ASC', - ]); - if ($plates) { - $rendered = true; - echo ''; - } - } - if (!$rendered) { - $boards = get_terms([ - 'taxonomy' => 'aksrt_forum_board', - 'hide_empty' => true, - 'orderby' => 'meta_value_num', - 'meta_key' => '_aksrt_sort_order', - 'order' => 'ASC', - ]); - if (!is_wp_error($boards) && !empty($boards)) { - echo ''; - } else { - echo ''; - } - } + // Taxonomy fallback. + $term_args = [ + 'taxonomy' => 'aksrt_forum_board', + 'hide_empty' => !isset($instance['hide_empty']) || !empty($instance['hide_empty']), + 'number' => $limit, + 'order' => 'ASC', + ]; + if ($orderby === 'count') { + $term_args['orderby'] = 'count'; + $term_args['order'] = 'DESC'; + } elseif ($orderby === 'name') { + $term_args['orderby'] = 'name'; + } else { + $term_args['orderby'] = 'meta_value_num'; + $term_args['meta_key'] = '_aksrt_sort_order'; + } + $boards = get_terms($term_args); + if (is_wp_error($boards) || empty($boards)) { + return function_exists('aksrt_get_ajax_null') + ? aksrt_get_ajax_null(__('暂无版块', 'aksrt')) + : ''; + } + ob_start(); + echo ''; + return (string) ob_get_clean(); + } - echo $args['after_widget']; - } + public function widget($args, $instance): void { + $title = !empty($instance['title']) ? $instance['title'] : __('版块列表', 'aksrt'); + $html = self::render_html($instance); - public function form($instance): void { - $title = !empty($instance['title']) ? $instance['title'] : __('版块列表', 'aksrt'); - ?> -- - -
- ++ + +
++ +
++ +
++ +
++ +
+ sanitize_text_field($new_instance['title'] ?? ''), + 'count' => max(1, min(50, (int) ($new_instance['count'] ?? 30))), + 'orderby' => $orderby, + 'style' => ($new_instance['style'] ?? '') === 'mini' ? 'mini' : 'list', + 'hide_empty' => !empty($new_instance['hide_empty']) ? 1 : 0, + ]; + } } diff --git a/src/AKSRT/Widgets/WidgetForumPlateInfo.php b/src/AKSRT/Widgets/WidgetForumPlateInfo.php index b0bf8b8b..0a1a2957 100644 --- a/src/AKSRT/Widgets/WidgetForumPlateInfo.php +++ b/src/AKSRT/Widgets/WidgetForumPlateInfo.php @@ -22,41 +22,96 @@ class WidgetForumPlateInfo extends \WP_Widget { ); } - public function widget($args, $instance): void { - $plate = $this->resolve_current_plate(); + /** + * @return array{html:string} + */ + public static function render_payload(array $instance, ?\WP_Post $plate = null): array { + $plate = $plate ?: self::resolve_current_plate_static(); if (!$plate) { - return; + return ['html' => '']; } - echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + $show_follow = !isset($instance['show_follow']) || !empty($instance['show_follow']); + $show_compose = !isset($instance['show_compose']) || !empty($instance['show_compose']); + $show_stats = !isset($instance['show_stats']) || !empty($instance['show_stats']); - $id = (int) $plate->ID; - $url = get_permalink($id); - $thumb = get_the_post_thumbnail_url($id, 'medium'); - $posts = (int) get_post_meta($id, '_aksrt_posts_count', true); - $reply = (int) get_post_meta($id, '_aksrt_reply_count', true); + $id = (int) $plate->ID; + $url = get_permalink($id); + $thumb = get_the_post_thumbnail_url($id, 'medium'); + $posts = (int) get_post_meta($id, '_aksrt_posts_count', true); + $reply = (int) get_post_meta($id, '_aksrt_reply_count', true); $follow = (int) get_post_meta($id, '_aksrt_follow_count', true); - $desc = $plate->post_excerpt !== '' ? $plate->post_excerpt : wp_trim_words(wp_strip_all_tags($plate->post_content), 30); + $views = (int) get_post_meta($id, '_aksrt_views', true); + $desc = $plate->post_excerpt !== '' ? $plate->post_excerpt : wp_trim_words(wp_strip_all_tags($plate->post_content), 30); + $icon = (string) get_post_meta($id, '_aksrt_icon', true); - echo '' . esc_html__('无需配置。仅在版块页或帖子页显示对应版块信息。', 'aksrt') . '
'; + ?> ++ +
+
+
+
+
+
-
+
+
+