feat(widgets): partners/iframe/combo/text/user + forum plate widgets
Close major zibll widget-more and bbs plate gaps: partners marquee, super embed, combo info cards, text title, user lists, and plate list/info/moderator sidebars with batch3 CSS registration.
This commit is contained in:
1 parent
6a202f3eab
commit
81bf3193a4
11 files changed
+2026
No files matched your search
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/**
|
||||
* Current plate moderators (zibll zib_bbs_widget_ui_plate_moderator).
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
namespace AKSRT\Widgets;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class WidgetForumPlateModerator extends \WP_Widget {
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct(
|
||||
'aksrt_forum_plate_moderator',
|
||||
esc_html__('论坛 - 版主列表', 'aksrt'),
|
||||
[
|
||||
'description' => esc_html__('显示当前版块的版主与超级版主。', 'aksrt'),
|
||||
'classname' => 'widget_aksrt_forum_plate_moderator',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function widget($args, $instance): void {
|
||||
$plate = $this->resolve_current_plate();
|
||||
if (!$plate) {
|
||||
return;
|
||||
}
|
||||
|
||||
$id = (int) $plate->ID;
|
||||
$author_id = (int) $plate->post_author;
|
||||
$mods = get_post_meta($id, '_aksrt_moderators', true);
|
||||
if (!is_array($mods)) {
|
||||
$mods = [];
|
||||
}
|
||||
$mods = array_values(array_unique(array_filter(array_map('intval', $mods))));
|
||||
|
||||
$people = [];
|
||||
if ($author_id > 0) {
|
||||
$people[] = ['id' => $author_id, 'role' => 'author'];
|
||||
}
|
||||
foreach ($mods as $mid) {
|
||||
if ($mid === $author_id) {
|
||||
continue;
|
||||
}
|
||||
$people[] = ['id' => $mid, 'role' => 'moderator'];
|
||||
}
|
||||
if (!$people) {
|
||||
return;
|
||||
}
|
||||
|
||||
$title_text = (string) ($instance['title_text'] ?? __('版主', 'aksrt'));
|
||||
|
||||
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
|
||||
echo '<div class="aksrt-plate-mods">';
|
||||
if ($title_text !== '') {
|
||||
echo '<div class="aksrt-plate-mods__head"><div class="title-theme">' . esc_html($title_text) . '</div></div>';
|
||||
}
|
||||
echo '<div class="aksrt-plate-mods__list">';
|
||||
foreach ($people as $row) {
|
||||
$uid = (int) $row['id'];
|
||||
$user = get_userdata($uid);
|
||||
if (!$user) {
|
||||
continue;
|
||||
}
|
||||
$avatar = function_exists('aksrt_get_avatar_url')
|
||||
? aksrt_get_avatar_url($uid, ['size' => 64])
|
||||
: get_avatar_url($uid, ['size' => 64]);
|
||||
$home = function_exists('aksrt_get_user_home_url')
|
||||
? aksrt_get_user_home_url($uid)
|
||||
: get_author_posts_url($uid);
|
||||
$role_label = $row['role'] === 'author'
|
||||
? __('超级版主', 'aksrt')
|
||||
: __('版主', 'aksrt');
|
||||
echo '<a class="aksrt-plate-mods__item" href="' . esc_url($home) . '">';
|
||||
echo '<img src="' . esc_url($avatar) . '" alt="" class="aksrt-plate-mods__avatar" loading="lazy" width="40" height="40" />';
|
||||
echo '<span class="aksrt-plate-mods__name">' . esc_html($user->display_name) . '</span>';
|
||||
echo '<span class="aksrt-plate-mods__role">' . esc_html($role_label) . '</span>';
|
||||
echo '</a>';
|
||||
}
|
||||
echo '</div></div>';
|
||||
|
||||
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
|
||||
private function resolve_current_plate(): ?\WP_Post {
|
||||
if (is_singular('aksrt_forum_plate')) {
|
||||
$p = get_queried_object();
|
||||
return $p instanceof \WP_Post ? $p : null;
|
||||
}
|
||||
if (is_singular('aksrt_forum_topic')) {
|
||||
$topic_id = (int) get_queried_object_id();
|
||||
$plate_id = (int) get_post_meta($topic_id, '_aksrt_plate_id', true);
|
||||
if ($plate_id <= 0) {
|
||||
$boards = get_the_terms($topic_id, 'aksrt_forum_board');
|
||||
if (!is_wp_error($boards) && !empty($boards[0])) {
|
||||
$linked = (int) get_term_meta((int) $boards[0]->term_id, '_aksrt_plate_id', true);
|
||||
if ($linked > 0) {
|
||||
$plate_id = $linked;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($plate_id > 0) {
|
||||
$p = get_post($plate_id);
|
||||
if ($p instanceof \WP_Post && $p->post_type === 'aksrt_forum_plate') {
|
||||
return $p;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function form($instance): void {
|
||||
?>
|
||||
<p>
|
||||
<label><?php esc_html_e('标题文案', 'aksrt'); ?>
|
||||
<input class="widefat" type="text" name="<?php echo esc_attr($this->get_field_name('title_text')); ?>" value="<?php echo esc_attr((string) ($instance['title_text'] ?? __('版主', 'aksrt'))); ?>">
|
||||
</label>
|
||||
</p>
|
||||
<p class="description"><?php esc_html_e('仅在版块/帖子页显示。', 'aksrt'); ?></p>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function update($new_instance, $old_instance): array {
|
||||
return [
|
||||
'title_text' => sanitize_text_field((string) ($new_instance['title_text'] ?? '')),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user