feat(widgets): user-card guest/login depth, main posts, term aggregation
1:1 zibll user widget guest shell + checkin/actions, main post list styles, term aggregation cards, and ranking by check-in days.
This commit is contained in:
1 parent
be4f23fd6f
commit
7a91eb7321
7 files changed
+884
-126
No files matched your search
@@ -29,6 +29,13 @@ class WidgetUserRanking extends \WP_Widget {
|
||||
echo $args['before_widget'];
|
||||
echo $args['before_title'] . esc_html($title) . $args['after_title'];
|
||||
|
||||
if (!empty($instance['checkin_btn']) && is_user_logged_in() && function_exists('aksrt_header_user_checkin_btn')) {
|
||||
$cbtn = aksrt_header_user_checkin_btn(get_current_user_id());
|
||||
if ($cbtn !== '') {
|
||||
echo '<div class="aksrt-user-ranking__checkin mb10">' . $cbtn . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
}
|
||||
|
||||
echo '<ul class="aksrt-user-ranking">';
|
||||
$rank = 0;
|
||||
foreach ($users as $user) {
|
||||
@@ -110,6 +117,58 @@ class WidgetUserRanking extends \WP_Widget {
|
||||
}
|
||||
break;
|
||||
|
||||
case 'checkin_all_day':
|
||||
global $wpdb;
|
||||
$rows = $wpdb->get_results($wpdb->prepare(
|
||||
"SELECT user_id, meta_value as val FROM {$wpdb->usermeta}
|
||||
WHERE meta_key IN ('aksrt_checkin_all_day','checkin_all_day')
|
||||
ORDER BY CAST(meta_value AS UNSIGNED) DESC
|
||||
LIMIT %d",
|
||||
$count * 2
|
||||
), ARRAY_A);
|
||||
$seen = [];
|
||||
foreach ((array) $rows as $row) {
|
||||
$uid = (int) $row['user_id'];
|
||||
if (isset($seen[$uid])) continue;
|
||||
$seen[$uid] = true;
|
||||
$user = get_userdata($uid);
|
||||
if ($user) {
|
||||
$users[] = [
|
||||
'id' => $uid,
|
||||
'name' => $user->display_name,
|
||||
'value' => number_format_i18n((int) $row['val']) . ' 天',
|
||||
];
|
||||
}
|
||||
if (count($users) >= $count) break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'checkin_continuous_day':
|
||||
global $wpdb;
|
||||
$rows = $wpdb->get_results($wpdb->prepare(
|
||||
"SELECT user_id, meta_value as val FROM {$wpdb->usermeta}
|
||||
WHERE meta_key IN ('aksrt_checkin_continuous_day','checkin_continuous_day')
|
||||
ORDER BY CAST(meta_value AS UNSIGNED) DESC
|
||||
LIMIT %d",
|
||||
$count * 2
|
||||
), ARRAY_A);
|
||||
$seen = [];
|
||||
foreach ((array) $rows as $row) {
|
||||
$uid = (int) $row['user_id'];
|
||||
if (isset($seen[$uid])) continue;
|
||||
$seen[$uid] = true;
|
||||
$user = get_userdata($uid);
|
||||
if ($user) {
|
||||
$users[] = [
|
||||
'id' => $uid,
|
||||
'name' => $user->display_name,
|
||||
'value' => number_format_i18n((int) $row['val']) . ' 天',
|
||||
];
|
||||
}
|
||||
if (count($users) >= $count) break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'followers':
|
||||
if (class_exists('\AKSRT\User\Follow')) {
|
||||
global $wpdb;
|
||||
@@ -157,6 +216,8 @@ class WidgetUserRanking extends \WP_Widget {
|
||||
<option value="credits" <?php selected($rank_by, 'credits'); ?>><?php esc_html_e('积分', 'aksrt'); ?></option>
|
||||
<option value="posts" <?php selected($rank_by, 'posts'); ?>><?php esc_html_e('文章数', 'aksrt'); ?></option>
|
||||
<option value="followers" <?php selected($rank_by, 'followers'); ?>><?php esc_html_e('粉丝数', 'aksrt'); ?></option>
|
||||
<option value="checkin_all_day" <?php selected($rank_by, 'checkin_all_day'); ?>><?php esc_html_e('累计签到', 'aksrt'); ?></option>
|
||||
<option value="checkin_continuous_day" <?php selected($rank_by, 'checkin_continuous_day'); ?>><?php esc_html_e('连续签到', 'aksrt'); ?></option>
|
||||
</select>
|
||||
</p>
|
||||
<p>
|
||||
@@ -169,15 +230,22 @@ class WidgetUserRanking extends \WP_Widget {
|
||||
<?php esc_html_e('显示头像', 'aksrt'); ?>
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label>
|
||||
<input type="checkbox" name="<?php echo esc_attr($this->get_field_name('checkin_btn')); ?>" value="1" <?php checked(!empty($instance['checkin_btn'])); ?>>
|
||||
<?php esc_html_e('顶部显示签到按钮', 'aksrt'); ?>
|
||||
</label>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function update($new_instance, $old_instance): array {
|
||||
$instance = [];
|
||||
$instance['title'] = sanitize_text_field($new_instance['title'] ?? '');
|
||||
$instance['rank_by'] = in_array($new_instance['rank_by'] ?? '', ['credits', 'posts', 'followers'], true) ? $new_instance['rank_by'] : 'credits';
|
||||
$instance['rank_by'] = in_array($new_instance['rank_by'] ?? '', ['credits', 'posts', 'followers', 'checkin_all_day', 'checkin_continuous_day'], true) ? $new_instance['rank_by'] : 'credits';
|
||||
$instance['count'] = max(1, min(20, (int) ($new_instance['count'] ?? 5)));
|
||||
$instance['show_avatar'] = !empty($new_instance['show_avatar']);
|
||||
$instance['checkin_btn'] = !empty($new_instance['checkin_btn']);
|
||||
return $instance;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user