Files
wordpress-theme-aksrt/inc/helpers/aksrt-user-card.php
T
kate522andClaude Fable 5 aa098fe870 feat(widgets): phase 4 align user/author/slider widgets 1:1 with zibll
Align the 5 user/author/slider widgets with Zibll CSF widget
definitions in widget-user.php / widget-slider.php and
options-module.php (add_slider / slide / zib_palette):

- WidgetUserCard (widget_ui_user): add Zibll button palettes
  (button_1_class/button_2_class via new palette_opts()/
  sanitize_palette() replicating CFS_Module::zib_palette c/b/jb)
  and button_2 type (home/center) → profile/center URL.
- WidgetAuthorCard (widget_ui_avatar): add show_button +
  button_1/button_2 (class/text/type) rendered only when the
  logged-in viewer is the author (zibll parity); expand orderby
  to modified/like/favorite.
- WidgetUserRanking (zib_widget_ui_user_ranking): rename field
  to Zibll `orderby` (default checkin_all_day) with the exact
  4 dims (checkin_all_day/checkin_continuous_day/points→credits
  /followed-user-count→followers) + `number` (was count); keep
  rank_by/count aliases for legacy instances; reword desc
  options to match Zibll labels.
- WidgetSlider (zib_widget_ui_slider): add direction/speed/
  spacebetween/scale_height+scale/autoplay to form+update+render,
  pass through to aksrt_render_slider (effect/loop/button/
  pagination/pc·m_height/interval already present); widen
  interval min to 0, height default to 400 (zibll pc_height).
- aksrt_user_card_query_posts: support like/favorite orderby
  (meta _aksrt_like_count / _aksrt_favorite_count) so the
  author/user-card more-posts strip honors the expanded orderby.

Acceptance: php -l clean on all changed files; audit exit 0;
all widget files <=383 lines. Phase 4 done-when marked.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-30 21:16:55 +08:00

153 lines
4.8 KiB
PHP

<?php
/**
* Shared user-card / author-card render helpers (zibll zib_get_user_card_box parity).
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
if (!function_exists('aksrt_user_card_query_posts')) :
/**
* Author posts for card strip.
*
* @param array<string,mixed> $args
* @return list<\WP_Post>
*/
function aksrt_user_card_query_posts(array $args): array {
$user_id = (int) ($args['user_id'] ?? 0);
$limit = max(0, min(20, (int) ($args['limit'] ?? 6)));
if ($user_id <= 0 || $limit <= 0) {
return [];
}
$orderby = sanitize_key((string) ($args['orderby'] ?? 'date'));
$post_type = sanitize_key((string) ($args['post_type'] ?? 'post'));
if (!post_type_exists($post_type)) {
$post_type = 'post';
}
$query_args = [
'post_status' => 'publish',
'post_type' => $post_type,
'author' => $user_id,
'posts_per_page' => $limit,
'ignore_sticky_posts' => true,
'no_found_rows' => true,
];
$exclude = (int) ($args['exclude'] ?? 0);
if ($exclude <= 0) {
$exclude = (int) get_the_ID();
}
if ($exclude > 0) {
$query_args['post__not_in'] = [$exclude];
}
switch ($orderby) {
case 'views':
case 'view':
$query_args['meta_key'] = 'aksrt_post_views';
$query_args['orderby'] = 'meta_value_num';
$query_args['order'] = 'DESC';
break;
case 'like':
case 'likes':
$query_args['meta_key'] = '_aksrt_like_count';
$query_args['orderby'] = 'meta_value_num';
$query_args['order'] = 'DESC';
break;
case 'favorite':
case 'favorite_count':
$query_args['meta_key'] = '_aksrt_favorite_count';
$query_args['orderby'] = 'meta_value_num';
$query_args['order'] = 'DESC';
break;
case 'comment_count':
case 'comments':
$query_args['orderby'] = 'comment_count';
$query_args['order'] = 'DESC';
break;
case 'modified':
$query_args['orderby'] = 'modified';
$query_args['order'] = 'DESC';
break;
case 'rand':
case 'random':
$query_args['orderby'] = 'rand';
break;
default:
$query_args['orderby'] = 'date';
$query_args['order'] = 'DESC';
}
$q = new WP_Query($query_args);
$posts = $q->posts;
wp_reset_postdata();
return is_array($posts) ? array_values(array_filter($posts, static fn($p) => $p instanceof WP_Post)) : [];
}
endif;
if (!function_exists('aksrt_render_user_card_posts')) :
/**
* Render more-posts strip (card swiper-scroll or mini list).
*
* @param array<string,mixed> $args
*/
function aksrt_render_user_card_posts(array $args): string {
$style = sanitize_key((string) ($args['post_style'] ?? $args['style'] ?? 'mini'));
if (!in_array($style, ['card', 'mini'], true)) {
$style = 'mini';
}
$posts = aksrt_user_card_query_posts($args);
$show_empty = !empty($args['show_empty']);
if (!$posts) {
if (!$show_empty) {
return '';
}
return '<div class="user-card-posts mt10 muted-2-color em09 text-center">' .
esc_html__('暂无更多文章', 'aksrt') .
'</div>';
}
ob_start();
echo '<div class="user-card-posts mt10">';
if ($style === 'card') {
echo '<div class="swiper-container more-posts swiper-scroll"><div class="swiper-wrapper">';
foreach ($posts as $rp) {
$thumb = get_the_post_thumbnail_url($rp, 'medium');
$title = get_the_title($rp);
$time = function_exists('aksrt_time_ago')
? aksrt_time_ago((string) $rp->post_date)
: human_time_diff((int) get_the_time('U', $rp), (int) current_time('timestamp')) . __('前', 'aksrt');
$views = function_exists('aksrt_get_post_views') ? (int) aksrt_get_post_views($rp->ID) : 0;
echo '<div class="swiper-slide mr10">';
echo '<a class="aksrt-more-post-card" href="' . esc_url(get_permalink($rp)) . '">';
if ($thumb) {
echo '<span class="aksrt-more-post-card__thumb"><img class="fit-cover" src="' . esc_url($thumb) . '" alt="" loading="lazy" decoding="async" /></span>';
}
echo '<span class="aksrt-more-post-card__body">';
echo '<span class="aksrt-more-post-card__title text-ellipsis">' . esc_html($title) . '</span>';
echo '<span class="aksrt-more-post-card__meta muted-2-color em09">';
echo '<item>' . esc_html($time) . '</item>';
if ($views > 0) {
echo '<item class="pull-right"><i class="fa fa-eye" aria-hidden="true"></i> ' . esc_html((string) $views) . '</item>';
}
echo '</span></span></a></div>';
}
echo '</div><div class="swiper-button-prev"></div><div class="swiper-button-next"></div></div>';
} else {
echo '<div class="more-posts-mini">';
foreach ($posts as $rp) {
echo '<div class="item"><a class="icon-circle text-ellipsis" href="' . esc_url(get_permalink($rp)) . '">' .
esc_html(get_the_title($rp)) .
'</a></div>';
}
echo '</div>';
}
echo '</div>';
return (string) ob_get_clean();
}
endif;