Merge pull request 'Worktree ux depth batch19 21' (#235) from worktree-ux-depth-batch19-21 into main
Reviewed-on: CYL/wordpress-theme-aksrt#235
This commit is contained in:
@@ -2217,3 +2217,82 @@ a.main-color > .icon-cover-card:hover,
|
||||
width: 100vw;
|
||||
max-width: 100vw;
|
||||
}
|
||||
|
||||
/* ===== Batch19-21: categories tree, hot meta, paid mini, main renderer, lang ===== */
|
||||
|
||||
.aksrt-cat-list.has-thumb .aksrt-cat-list__link,
|
||||
.aksrt-cat-list.is-tree .aksrt-cat-list__link {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
}
|
||||
.aksrt-cat-list__thumb {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
flex: 0 0 auto;
|
||||
background: var(--surface-2, #f3f4f6);
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #999;
|
||||
}
|
||||
.aksrt-cat-list__thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
|
||||
.aksrt-cat-list__text { min-width: 0; flex: 1; display: flex; flex-direction: column; }
|
||||
.aksrt-cat-list__name { font-weight: 600; }
|
||||
.aksrt-cat-list__desc { margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.aksrt-cat-list__children {
|
||||
list-style: none;
|
||||
margin: 6px 0 0 18px;
|
||||
padding: 0;
|
||||
border-left: 2px solid var(--color-line, #e5e7eb);
|
||||
padding-left: 10px;
|
||||
}
|
||||
.aksrt-cat-list .count {
|
||||
margin-left: auto;
|
||||
font-size: 12px;
|
||||
color: var(--muted-2-color, #999);
|
||||
background: var(--surface-2, #f3f4f6);
|
||||
border-radius: 999px;
|
||||
padding: 1px 8px;
|
||||
}
|
||||
|
||||
.aksrt-paid-posts__item.is-mini {
|
||||
position: relative;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.aksrt-paid-posts__item.is-mini .aksrt-paid-posts__price.badge {
|
||||
position: absolute;
|
||||
top: 6px;
|
||||
right: 6px;
|
||||
z-index: 2;
|
||||
background: rgba(239, 68, 68, .92);
|
||||
color: #fff;
|
||||
font-size: 11px;
|
||||
padding: 2px 8px;
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
.aksrt-lang-switch-widget.hide-name .aksrt-lang-switch__toggle span,
|
||||
.aksrt-lang-switch-widget.hide-name .aksrt-lang-switch__item {
|
||||
font-size: 0;
|
||||
}
|
||||
.aksrt-lang-switch-widget.hide-current .aksrt-lang-switch__item.is-active,
|
||||
.aksrt-lang-switch-widget.hide-current .aksrt-lang-switch__flag.is-active {
|
||||
display: none;
|
||||
}
|
||||
.aksrt-lang-switch-widget.style-inline .aksrt-lang-switch--flags {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.aksrt-forum-widget__item.is-top .aksrt-forum-widget__rank {
|
||||
background: var(--theme-color, #f04494);
|
||||
color: #fff;
|
||||
}
|
||||
.tag-cloud.aksrt-tag-cloud a { transition: transform .15s ease; }
|
||||
.tag-cloud.aksrt-tag-cloud a:hover { transform: translateY(-1px); }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* Categories list (zibll-like options depth).
|
||||
* Categories list (zibll widget categories depth).
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
@@ -18,6 +18,7 @@ class CategoriesWidget extends \WP_Widget {
|
||||
[
|
||||
'description' => esc_html__('以列表形式展示文章分类', 'aksrt'),
|
||||
'customize_selective_refresh' => true,
|
||||
'classname' => 'widget_aksrt_categories',
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -37,6 +38,9 @@ class CategoriesWidget extends \WP_Widget {
|
||||
return array_values(array_unique($ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $instance
|
||||
*/
|
||||
public static function render_html(array $instance): string {
|
||||
$count = max(1, min(50, (int) ($instance['count'] ?? 8)));
|
||||
$orderby = sanitize_key((string) ($instance['orderby'] ?? 'count'));
|
||||
@@ -48,12 +52,14 @@ class CategoriesWidget extends \WP_Widget {
|
||||
$hierarchical = !empty($instance['hierarchical']);
|
||||
$parent = max(0, (int) ($instance['parent'] ?? 0));
|
||||
$show_count = !isset($instance['show_count']) || !empty($instance['show_count']);
|
||||
$show_desc = !empty($instance['show_desc']);
|
||||
$show_thumb = !empty($instance['show_thumb']);
|
||||
$exclude = self::parse_ids_static((string) ($instance['exclude'] ?? ''));
|
||||
$include = self::parse_ids_static((string) ($instance['include'] ?? ''));
|
||||
|
||||
$term_args = [
|
||||
'taxonomy' => 'category',
|
||||
'number' => $count,
|
||||
'number' => $hierarchical ? 0 : $count,
|
||||
'orderby' => $orderby,
|
||||
'order' => $order,
|
||||
'hide_empty' => $hide_empty,
|
||||
@@ -61,6 +67,8 @@ class CategoriesWidget extends \WP_Widget {
|
||||
];
|
||||
if ($parent > 0) {
|
||||
$term_args['parent'] = $parent;
|
||||
} elseif ($hierarchical) {
|
||||
$term_args['parent'] = 0;
|
||||
}
|
||||
if ($include) {
|
||||
$term_args['include'] = $include;
|
||||
@@ -79,19 +87,88 @@ class CategoriesWidget extends \WP_Widget {
|
||||
}
|
||||
|
||||
ob_start();
|
||||
echo '<ul class="widget-list aksrt-cat-list ajax-item">';
|
||||
$cls = 'widget-list aksrt-cat-list ajax-item' . ($hierarchical ? ' is-tree' : '') . ($show_thumb ? ' has-thumb' : '');
|
||||
echo '<ul class="' . esc_attr($cls) . '">';
|
||||
$n = 0;
|
||||
foreach ($cats as $cat) {
|
||||
echo '<li>';
|
||||
echo '<a href="' . esc_url(get_category_link($cat->term_id)) . '">' . esc_html($cat->name) . '</a>';
|
||||
if ($show_count) {
|
||||
echo '<span class="count">' . (int) $cat->count . '</span>';
|
||||
if (!$hierarchical && $n >= $count) {
|
||||
break;
|
||||
}
|
||||
echo '</li>';
|
||||
echo self::render_cat_item($cat, $show_count, $show_desc, $show_thumb, $hierarchical ? 0 : -1, $count, $n, $hide_empty, $orderby, $order);
|
||||
$n++;
|
||||
}
|
||||
echo '</ul>';
|
||||
return (string) ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \WP_Term $cat
|
||||
*/
|
||||
private static function render_cat_item($cat, bool $show_count, bool $show_desc, bool $show_thumb, int $depth, int $limit, int &$n, bool $hide_empty, string $orderby, string $order): string {
|
||||
if ($n > 0 && $limit > 0 && $n >= $limit && $depth >= 0) {
|
||||
return '';
|
||||
}
|
||||
$html = '<li class="aksrt-cat-list__item depth-' . max(0, $depth) . '">';
|
||||
$html .= '<a class="aksrt-cat-list__link" href="' . esc_url(get_category_link($cat->term_id)) . '">';
|
||||
if ($show_thumb) {
|
||||
$thumb = '';
|
||||
$img_id = (int) get_term_meta($cat->term_id, 'thumbnail_id', true);
|
||||
if (!$img_id) {
|
||||
$img_id = (int) get_term_meta($cat->term_id, '_aksrt_cover', true);
|
||||
}
|
||||
if ($img_id) {
|
||||
$thumb = (string) (wp_get_attachment_image_url($img_id, 'thumbnail') ?: '');
|
||||
}
|
||||
if ($thumb === '') {
|
||||
$thumb = (string) get_term_meta($cat->term_id, '_aksrt_cover_url', true);
|
||||
}
|
||||
if ($thumb !== '') {
|
||||
$ph = get_template_directory_uri() . '/assets/img/placeholder.svg';
|
||||
$html .= '<span class="aksrt-cat-list__thumb"><img class="aksrt-lazy lazyload" data-src="' . esc_url($thumb) . '" src="' . esc_url($ph) . '" alt="" loading="lazy" width="32" height="32" /></span>';
|
||||
} else {
|
||||
$html .= '<span class="aksrt-cat-list__thumb is-empty"><i class="fa fa-folder-o" aria-hidden="true"></i></span>';
|
||||
}
|
||||
}
|
||||
$html .= '<span class="aksrt-cat-list__text">';
|
||||
$html .= '<span class="aksrt-cat-list__name">' . esc_html($cat->name) . '</span>';
|
||||
if ($show_desc && $cat->description !== '') {
|
||||
$desc = wp_trim_words(wp_strip_all_tags((string) $cat->description), 12, '…');
|
||||
$html .= '<span class="aksrt-cat-list__desc muted-2-color em09">' . esc_html($desc) . '</span>';
|
||||
}
|
||||
$html .= '</span>';
|
||||
if ($show_count) {
|
||||
$html .= '<span class="count">' . (int) $cat->count . '</span>';
|
||||
}
|
||||
$html .= '</a>';
|
||||
|
||||
if ($depth >= 0) {
|
||||
$children = get_categories([
|
||||
'taxonomy' => 'category',
|
||||
'parent' => (int) $cat->term_id,
|
||||
'hide_empty' => $hide_empty,
|
||||
'orderby' => $orderby,
|
||||
'order' => $order,
|
||||
]);
|
||||
if ($children) {
|
||||
$html .= '<ul class="aksrt-cat-list__children">';
|
||||
foreach ($children as $child) {
|
||||
$n++;
|
||||
if ($limit > 0 && $n > $limit) {
|
||||
break;
|
||||
}
|
||||
$html .= self::render_cat_item($child, $show_count, $show_desc, $show_thumb, $depth + 1, $limit, $n, $hide_empty, $orderby, $order);
|
||||
}
|
||||
$html .= '</ul>';
|
||||
}
|
||||
}
|
||||
$html .= '</li>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $args
|
||||
* @param array<string,mixed> $instance
|
||||
*/
|
||||
public function widget($args, $instance): void {
|
||||
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
|
||||
@@ -106,11 +183,9 @@ class CategoriesWidget extends \WP_Widget {
|
||||
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
|
||||
/** @return array<int,int> */
|
||||
private function parse_ids(string $raw): array {
|
||||
return self::parse_ids_static($raw);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $instance
|
||||
*/
|
||||
public function form($instance): void {
|
||||
?>
|
||||
<p>
|
||||
@@ -154,12 +229,19 @@ class CategoriesWidget extends \WP_Widget {
|
||||
</p>
|
||||
<p>
|
||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_count')); ?>" value="1" <?php checked(!isset($instance['show_count']) || !empty($instance['show_count'])); ?>> <?php esc_html_e('显示数量', 'aksrt'); ?></label><br>
|
||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_desc')); ?>" value="1" <?php checked(!empty($instance['show_desc'])); ?>> <?php esc_html_e('显示描述', 'aksrt'); ?></label><br>
|
||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_thumb')); ?>" value="1" <?php checked(!empty($instance['show_thumb'])); ?>> <?php esc_html_e('显示封面', 'aksrt'); ?></label><br>
|
||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('hide_empty')); ?>" value="1" <?php checked(!isset($instance['hide_empty']) || !empty($instance['hide_empty'])); ?>> <?php esc_html_e('隐藏空分类', 'aksrt'); ?></label><br>
|
||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('hierarchical')); ?>" value="1" <?php checked(!empty($instance['hierarchical'])); ?>> <?php esc_html_e('层级', 'aksrt'); ?></label>
|
||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('hierarchical')); ?>" value="1" <?php checked(!empty($instance['hierarchical'])); ?>> <?php esc_html_e('层级树', 'aksrt'); ?></label>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $new_instance
|
||||
* @param array<string,mixed> $old_instance
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public function update($new_instance, $old_instance): array {
|
||||
$orderby = sanitize_key((string) ($new_instance['orderby'] ?? 'count'));
|
||||
if (!in_array($orderby, ['count', 'name', 'id', 'slug'], true)) {
|
||||
@@ -174,6 +256,8 @@ class CategoriesWidget extends \WP_Widget {
|
||||
'include' => sanitize_text_field((string) ($new_instance['include'] ?? '')),
|
||||
'exclude' => sanitize_text_field((string) ($new_instance['exclude'] ?? '')),
|
||||
'show_count' => !empty($new_instance['show_count']) ? 1 : 0,
|
||||
'show_desc' => !empty($new_instance['show_desc']) ? 1 : 0,
|
||||
'show_thumb' => !empty($new_instance['show_thumb']) ? 1 : 0,
|
||||
'hide_empty' => !empty($new_instance['hide_empty']) ? 1 : 0,
|
||||
'hierarchical' => !empty($new_instance['hierarchical']) ? 1 : 0,
|
||||
];
|
||||
|
||||
@@ -71,27 +71,46 @@ class HotPostsWidget extends \WP_Widget {
|
||||
return '';
|
||||
}
|
||||
$show_thumb = !empty($instance['show_thumb']);
|
||||
$order_by = sanitize_key((string) ($instance['order_by'] ?? 'views'));
|
||||
$placeholder = get_template_directory_uri() . '/assets/img/placeholder.svg';
|
||||
ob_start();
|
||||
$index = $start;
|
||||
while ($query->have_posts()) {
|
||||
$query->the_post();
|
||||
$index++;
|
||||
$rank_class = $index <= 3 ? ' rank-top' : '';
|
||||
$views = (int) get_post_meta(get_the_ID(), 'aksrt_post_views', true);
|
||||
$pid = get_the_ID();
|
||||
if ($order_by === 'comments') {
|
||||
$metric = (int) get_comments_number($pid);
|
||||
$metric_icon = 'fa-comment-o';
|
||||
} elseif ($order_by === 'likes') {
|
||||
$metric = function_exists('aksrt_get_post_likes') ? (int) aksrt_get_post_likes($pid) : (int) get_post_meta($pid, '_aksrt_like_count', true);
|
||||
$metric_icon = 'fa-heart';
|
||||
} elseif ($order_by === 'favorites') {
|
||||
$metric = (int) get_post_meta($pid, '_aksrt_favorite_count', true);
|
||||
$metric_icon = 'fa-star';
|
||||
} elseif ($order_by === 'downloads') {
|
||||
$metric = (int) get_post_meta($pid, '_aksrt_res_download_count', true);
|
||||
$metric_icon = 'fa-download';
|
||||
} else {
|
||||
$metric = (int) get_post_meta($pid, 'aksrt_post_views', true);
|
||||
$metric_icon = 'fa-eye';
|
||||
}
|
||||
$metric_txt = function_exists('aksrt_format_number') ? aksrt_format_number($metric) : (string) $metric;
|
||||
?>
|
||||
<div class="hot-post-item ajax-item <?php echo esc_attr($rank_class); ?>">
|
||||
<span class="hot-post-item__rank"><?php echo esc_html((string) $index); ?></span>
|
||||
<?php if ($show_thumb) :
|
||||
$thumb = get_the_post_thumbnail_url(get_the_ID(), 'thumbnail');
|
||||
$thumb = get_the_post_thumbnail_url($pid, 'thumbnail');
|
||||
?>
|
||||
<a class="hot-post-item__thumb<?php echo $thumb ? '' : ' is-empty'; ?>" href="<?php the_permalink(); ?>">
|
||||
<?php if ($thumb) : ?><img src="<?php echo esc_url($thumb); ?>" alt="" loading="lazy" /><?php endif; ?>
|
||||
<?php if ($thumb) : ?><img class="aksrt-lazy lazyload" data-src="<?php echo esc_url($thumb); ?>" src="<?php echo esc_url($placeholder); ?>" alt="" loading="lazy" /><?php endif; ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<div class="hot-post-item__info">
|
||||
<a href="<?php the_permalink(); ?>" class="hot-post-item__title"><?php the_title(); ?></a>
|
||||
<div class="hot-post-item__meta">
|
||||
<span><i class="fas fa-eye" aria-hidden="true"></i> <?php echo esc_html(function_exists('aksrt_format_number') ? aksrt_format_number($views) : (string) $views); ?></span>
|
||||
<span><i class="fa <?php echo esc_attr($metric_icon); ?>" aria-hidden="true"></i> <?php echo esc_html((string) $metric_txt); ?></span>
|
||||
<span class="hot-post-item__time"><?php echo esc_html(human_time_diff(get_the_time('U'), current_time('timestamp')) . __('前', 'aksrt')); ?></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -127,6 +127,11 @@ class TabPostsWidget extends \WP_Widget {
|
||||
$tabs = $this->normalize_tabs($instance['tabs'] ?? 'latest,comments,random');
|
||||
$tabs = array_values(array_filter($tabs, static fn($t) => !empty($t['enabled'])));
|
||||
if (!$tabs) {
|
||||
if (current_user_can('manage_options')) {
|
||||
echo function_exists('aksrt_get_widget_null')
|
||||
? aksrt_get_widget_null(__('请至少启用一个 Tab', 'aksrt')) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
: '<p class="widget-empty">' . esc_html__('请至少启用一个 Tab', 'aksrt') . '</p>';
|
||||
}
|
||||
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -139,7 +139,8 @@ class TagCloudWidget extends \WP_Widget {
|
||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_count')); ?>" value="1" <?php checked(!empty($instance['show_count'])); ?>> <?php esc_html_e('显示数量', 'aksrt'); ?></label><br>
|
||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('blank')); ?>" value="1" <?php checked(!empty($instance['blank'])); ?>> <?php esc_html_e('新窗口', 'aksrt'); ?></label><br>
|
||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('fixed_width')); ?>" value="1" <?php checked(!empty($instance['fixed_width'])); ?>> <?php esc_html_e('固定宽度', 'aksrt'); ?></label><br>
|
||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('hide_empty')); ?>" value="1" <?php checked(!empty($instance['hide_empty'])); ?>> <?php esc_html_e('隐藏空标签', 'aksrt'); ?></label>
|
||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('hide_empty')); ?>" value="1" <?php checked(!empty($instance['hide_empty'])); ?>> <?php esc_html_e('隐藏空标签', 'aksrt'); ?></label><br>
|
||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('scale')); ?>" value="1" <?php checked(!empty($instance['scale'])); ?>> <?php esc_html_e('按数量缩放字号', 'aksrt'); ?></label>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
@@ -155,6 +156,7 @@ class TagCloudWidget extends \WP_Widget {
|
||||
'blank' => !empty($new_instance['blank']) ? 1 : 0,
|
||||
'fixed_width' => !empty($new_instance['fixed_width']) ? 1 : 0,
|
||||
'hide_empty' => !empty($new_instance['hide_empty']) ? 1 : 0,
|
||||
'scale' => !empty($new_instance['scale']) ? 1 : 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ class WidgetForumHotTopics extends \WP_Widget {
|
||||
$items = self::render_items_html($q, ($page - 1) * $count);
|
||||
$html = $items !== '' ? '<ul class="aksrt-forum-widget__list">' . $items . '</ul>' : '';
|
||||
if ($html === '' && $page === 1) {
|
||||
$html = '<p class="aksrt-forum-widget__empty ajax-item">' . esc_html__('暂无话题', 'aksrt') . '</p>';
|
||||
$html = function_exists('aksrt_get_ajax_null') ? aksrt_get_ajax_null(__('暂无话题', 'aksrt')) : '<p class="aksrt-forum-widget__empty ajax-item">' . esc_html__('暂无话题', 'aksrt') . '</p>';
|
||||
}
|
||||
$max_pages = max(1, (int) $q->max_num_pages);
|
||||
$total = (int) $q->found_posts;
|
||||
|
||||
@@ -40,6 +40,7 @@ class WidgetForumRecentTopics extends \WP_Widget {
|
||||
public function form($instance): void {
|
||||
$title = !empty($instance['title']) ? $instance['title'] : __('最新话题', 'aksrt');
|
||||
$count = !empty($instance['count']) ? (int) $instance['count'] : 5;
|
||||
$plate = (int) ($instance['plate'] ?? 0);
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('标题:', 'aksrt'); ?></label>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* Language switcher widget (Polylang / WPML / filter).
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
@@ -9,57 +11,113 @@ defined('ABSPATH') || exit;
|
||||
|
||||
class WidgetLangSwitch extends \WP_Widget {
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct(
|
||||
'aksrt_lang_switch',
|
||||
__('语言切换器', 'aksrt'),
|
||||
['description' => __('在侧栏显示多语言切换按钮。', 'aksrt')]
|
||||
);
|
||||
}
|
||||
public function __construct() {
|
||||
parent::__construct(
|
||||
'aksrt_lang_switch',
|
||||
__('语言切换器', 'aksrt'),
|
||||
[
|
||||
'description' => __('在侧栏显示多语言切换按钮。', 'aksrt'),
|
||||
'classname' => 'widget_aksrt_lang_switch',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function widget($args, $instance): void {
|
||||
$title = !empty($instance['title']) ? $instance['title'] : '';
|
||||
$style = !empty($instance['style']) ? $instance['style'] : 'dropdown';
|
||||
/**
|
||||
* @param array<string,mixed> $args
|
||||
* @param array<string,mixed> $instance
|
||||
*/
|
||||
public function widget($args, $instance): void {
|
||||
$title = !empty($instance['title']) ? (string) $instance['title'] : '';
|
||||
$style = sanitize_key((string) ($instance['style'] ?? 'dropdown'));
|
||||
if (!in_array($style, ['dropdown', 'flags', 'inline'], true)) {
|
||||
$style = 'dropdown';
|
||||
}
|
||||
$show_name = !isset($instance['show_name']) || !empty($instance['show_name']);
|
||||
$hide_current = !empty($instance['hide_current']);
|
||||
|
||||
if (!function_exists('aksrt_has_multilingual') || !aksrt_has_multilingual()) return;
|
||||
if (!function_exists('aksrt_has_multilingual') || !aksrt_has_multilingual()) {
|
||||
if (current_user_can('manage_options')) {
|
||||
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo '<div class="c-red muted-box mb10"><b>' . esc_html__('语言切换:', 'aksrt') . '</b>' .
|
||||
esc_html__('未检测到多语言插件(Polylang/WPML)或可用语言不足。', 'aksrt') . '</div>';
|
||||
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$html = function_exists('aksrt_render_language_switcher') ? aksrt_render_language_switcher($style) : '';
|
||||
if (empty($html)) return;
|
||||
// inline style: treat as flags row without dropdown chrome.
|
||||
$render_style = $style === 'inline' ? 'flags' : $style;
|
||||
$html = function_exists('aksrt_render_language_switcher') ? aksrt_render_language_switcher($render_style) : '';
|
||||
if ($html === '') {
|
||||
if (current_user_can('manage_options')) {
|
||||
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo function_exists('aksrt_get_widget_null')
|
||||
? aksrt_get_widget_null(__('暂无可用语言', 'aksrt')) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
: '<p class="widget-empty">' . esc_html__('暂无可用语言', 'aksrt') . '</p>';
|
||||
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
echo $args['before_widget'];
|
||||
// Optional modifiers via wrapper classes.
|
||||
$wrap = 'aksrt-lang-switch-widget style-' . esc_attr($style);
|
||||
if (!$show_name) {
|
||||
$wrap .= ' hide-name';
|
||||
}
|
||||
if ($hide_current) {
|
||||
$wrap .= ' hide-current';
|
||||
}
|
||||
|
||||
if ($title) {
|
||||
echo $args['before_title'] . esc_html($title) . $args['after_title'];
|
||||
}
|
||||
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
if ($title !== '') {
|
||||
echo $args['before_title'] . esc_html($title) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
echo '<div class="' . esc_attr($wrap) . '">' . $html . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
|
||||
echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
/**
|
||||
* @param array<string,mixed> $instance
|
||||
*/
|
||||
public function form($instance): void {
|
||||
$title = !empty($instance['title']) ? (string) $instance['title'] : '';
|
||||
$style = !empty($instance['style']) ? (string) $instance['style'] : 'dropdown';
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('标题(可选):', 'aksrt'); ?></label>
|
||||
<input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($title); ?>">
|
||||
</p>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($this->get_field_id('style')); ?>"><?php esc_html_e('样式:', 'aksrt'); ?></label>
|
||||
<select class="widefat" id="<?php echo esc_attr($this->get_field_id('style')); ?>" name="<?php echo esc_attr($this->get_field_name('style')); ?>">
|
||||
<option value="dropdown" <?php selected($style, 'dropdown'); ?>><?php esc_html_e('下拉菜单', 'aksrt'); ?></option>
|
||||
<option value="flags" <?php selected($style, 'flags'); ?>><?php esc_html_e('国旗图标', 'aksrt'); ?></option>
|
||||
<option value="inline" <?php selected($style, 'inline'); ?>><?php esc_html_e('横向排列', 'aksrt'); ?></option>
|
||||
</select>
|
||||
</p>
|
||||
<p>
|
||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_name')); ?>" value="1" <?php checked(!isset($instance['show_name']) || !empty($instance['show_name'])); ?>> <?php esc_html_e('显示语言名', 'aksrt'); ?></label><br>
|
||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('hide_current')); ?>" value="1" <?php checked(!empty($instance['hide_current'])); ?>> <?php esc_html_e('隐藏当前语言', 'aksrt'); ?></label>
|
||||
</p>
|
||||
<p><small><?php esc_html_e('需要安装 Polylang 或 WPML 等多语言插件才能生效。', 'aksrt'); ?></small></p>
|
||||
<?php
|
||||
}
|
||||
|
||||
echo $args['after_widget'];
|
||||
}
|
||||
|
||||
public function form($instance): void {
|
||||
$title = !empty($instance['title']) ? $instance['title'] : '';
|
||||
$style = !empty($instance['style']) ? $instance['style'] : 'dropdown';
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('标题(可选):', 'aksrt'); ?></label>
|
||||
<input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($title); ?>">
|
||||
</p>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($this->get_field_id('style')); ?>"><?php esc_html_e('样式:', 'aksrt'); ?></label>
|
||||
<select class="widefat" id="<?php echo esc_attr($this->get_field_id('style')); ?>" name="<?php echo esc_attr($this->get_field_name('style')); ?>">
|
||||
<option value="dropdown" <?php selected($style, 'dropdown'); ?>><?php esc_html_e('下拉菜单', 'aksrt'); ?></option>
|
||||
<option value="flags" <?php selected($style, 'flags'); ?>><?php esc_html_e('国旗图标', 'aksrt'); ?></option>
|
||||
</select>
|
||||
</p>
|
||||
<p><small><?php esc_html_e('需要安装 Polylang 或 WPML 等多语言插件才能生效。', 'aksrt'); ?></small></p>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function update($new_instance, $old_instance): array {
|
||||
$instance = [];
|
||||
$instance['title'] = sanitize_text_field($new_instance['title'] ?? '');
|
||||
$instance['style'] = in_array($new_instance['style'] ?? '', ['dropdown', 'flags'], true) ? $new_instance['style'] : 'dropdown';
|
||||
return $instance;
|
||||
}
|
||||
/**
|
||||
* @param array<string,mixed> $new_instance
|
||||
* @param array<string,mixed> $old_instance
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public function update($new_instance, $old_instance): array {
|
||||
$style = sanitize_key((string) ($new_instance['style'] ?? 'dropdown'));
|
||||
if (!in_array($style, ['dropdown', 'flags', 'inline'], true)) {
|
||||
$style = 'dropdown';
|
||||
}
|
||||
return [
|
||||
'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')),
|
||||
'style' => $style,
|
||||
'show_name' => !empty($new_instance['show_name']) ? 1 : 0,
|
||||
'hide_current' => !empty($new_instance['hide_current']) ? 1 : 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,6 +90,29 @@ class WidgetMainPosts extends \WP_Widget {
|
||||
|
||||
ob_start();
|
||||
// Outer wrapper only on page 1 full render handled by caller for ajax append items.
|
||||
$mode = $style === 'card' ? 'card' : ($style === 'mini' ? 'mini' : 'list');
|
||||
if (function_exists('aksrt_render_post')) {
|
||||
$html = '';
|
||||
$i = $start;
|
||||
while ($q->have_posts()) {
|
||||
$q->the_post();
|
||||
$i++;
|
||||
$html .= aksrt_render_post([
|
||||
'mode' => $mode,
|
||||
'context' => 'widget',
|
||||
'show_thumb' => $show_thumb,
|
||||
'show_meta' => $show_meta,
|
||||
'show_excerpt' => $mode === 'list',
|
||||
'show_number' => $show_number && $mode === 'mini',
|
||||
'number_offset' => $show_number ? $i : 0,
|
||||
'extra_class' => 'ajax-item',
|
||||
]);
|
||||
}
|
||||
wp_reset_postdata();
|
||||
return $html;
|
||||
}
|
||||
|
||||
$placeholder = get_template_directory_uri() . '/assets/img/placeholder.svg';
|
||||
$i = $start;
|
||||
while ($q->have_posts()) {
|
||||
$q->the_post();
|
||||
@@ -101,7 +124,7 @@ class WidgetMainPosts extends \WP_Widget {
|
||||
echo '<a class="aksrt-main-posts__card ajax-item" href="' . esc_url(get_permalink()) . '">';
|
||||
echo '<div class="aksrt-main-posts__thumb' . ($thumb ? '' : ' is-empty') . '">';
|
||||
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($placeholder) . '" alt="" loading="lazy" />';
|
||||
}
|
||||
echo '</div>';
|
||||
echo '<div class="aksrt-main-posts__body">';
|
||||
@@ -122,7 +145,7 @@ class WidgetMainPosts extends \WP_Widget {
|
||||
if ($show_thumb) {
|
||||
echo '<span class="aksrt-main-posts__thumb mini' . ($thumb ? '' : ' is-empty') . '">';
|
||||
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($placeholder) . '" alt="" loading="lazy" />';
|
||||
}
|
||||
echo '</span>';
|
||||
}
|
||||
|
||||
@@ -68,42 +68,59 @@ class WidgetPaidPosts extends \WP_Widget {
|
||||
if (!$q->have_posts()) {
|
||||
return '';
|
||||
}
|
||||
$placeholder = get_template_directory_uri() . '/assets/img/placeholder.svg';
|
||||
ob_start();
|
||||
while ($q->have_posts()) {
|
||||
$q->the_post();
|
||||
$price = (float) get_post_meta(get_the_ID(), '_aksrt_pay_price', true);
|
||||
$credits = (int) get_post_meta(get_the_ID(), '_aksrt_credits_cost', true);
|
||||
$thumb = get_the_post_thumbnail_url(get_the_ID(), 'thumbnail');
|
||||
$pid = get_the_ID();
|
||||
$price = (float) get_post_meta($pid, '_aksrt_pay_price', true);
|
||||
$credits = (int) get_post_meta($pid, '_aksrt_credits_cost', true);
|
||||
$thumb = get_the_post_thumbnail_url($pid, 'thumbnail');
|
||||
if ($price > 0) {
|
||||
$badge = '¥' . number_format($price, 2, '.', '');
|
||||
} elseif ($credits > 0) {
|
||||
$badge = sprintf(__('%d 积分', 'aksrt'), $credits);
|
||||
} else {
|
||||
$badge = __('付费', 'aksrt');
|
||||
}
|
||||
if (function_exists('aksrt_render_post')) {
|
||||
$item = aksrt_render_post([
|
||||
'mode' => 'mini',
|
||||
'context' => 'widget',
|
||||
'show_thumb' => true,
|
||||
'show_meta' => true,
|
||||
'show_excerpt' => false,
|
||||
'extra_class' => 'ajax-item aksrt-paid-posts__mini',
|
||||
]);
|
||||
if ($item !== '') {
|
||||
echo '<div class="aksrt-paid-posts__item is-mini ajax-item">';
|
||||
echo $item; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo '<span class="aksrt-paid-posts__price badge">' . esc_html($badge) . '</span>';
|
||||
echo '</div>';
|
||||
continue;
|
||||
}
|
||||
}
|
||||
echo '<li class="aksrt-paid-posts__item ajax-item">';
|
||||
if ($thumb) {
|
||||
echo '<a class="aksrt-paid-posts__thumb" href="' . esc_url(get_permalink()) . '"><img src="' . esc_url($thumb) . '" alt="" loading="lazy" /></a>';
|
||||
echo '<a class="aksrt-paid-posts__thumb" href="' . esc_url(get_permalink()) . '"><img class="aksrt-lazy lazyload" data-src="' . esc_url($thumb) . '" src="' . esc_url($placeholder) . '" alt="" loading="lazy" /></a>';
|
||||
}
|
||||
echo '<div class="aksrt-paid-posts__body">';
|
||||
echo '<a class="aksrt-paid-posts__title" href="' . esc_url(get_permalink()) . '">' . esc_html(get_the_title()) . '</a>';
|
||||
echo '<div class="aksrt-paid-posts__meta">';
|
||||
if ($price > 0) {
|
||||
echo '<span class="aksrt-paid-posts__price">¥' . esc_html(number_format($price, 2, '.', '')) . '</span>';
|
||||
} elseif ($credits > 0) {
|
||||
echo '<span class="aksrt-paid-posts__price">' . esc_html(sprintf(__('%d 积分', 'aksrt'), $credits)) . '</span>';
|
||||
} else {
|
||||
echo '<span class="aksrt-paid-posts__price">' . esc_html__('付费', 'aksrt') . '</span>';
|
||||
}
|
||||
echo '</div></div></li>';
|
||||
echo '<div class="aksrt-paid-posts__meta"><span class="aksrt-paid-posts__price">' . esc_html($badge) . '</span></div>';
|
||||
echo '</div></li>';
|
||||
}
|
||||
wp_reset_postdata();
|
||||
return (string) ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{html:string,paginate_html:string,has_more:bool,page:int,max_pages:int,total:int}
|
||||
*/
|
||||
public static function query_payload(array $instance, int $page = 1): array {
|
||||
$page = max(1, $page);
|
||||
$paginate = sanitize_key((string) ($instance['paginate'] ?? 'ajax'));
|
||||
$count = max(1, min(20, (int) ($instance['count'] ?? 6)));
|
||||
$q = new \WP_Query(self::build_query_args($instance, $page));
|
||||
$items = self::render_items_html($q);
|
||||
$html = $items !== '' ? '<ul class="aksrt-paid-posts">' . $items . '</ul>' : '';
|
||||
$wrap_tag = (strpos($items, 'posts-mini') !== false || strpos($items, 'aksrt-paid-posts__mini') !== false) ? 'div' : 'ul';
|
||||
$html = $items !== '' ? '<' . $wrap_tag . ' class="aksrt-paid-posts">' . $items . '</' . $wrap_tag . '>' : '';
|
||||
if ($html === '' && $page === 1) {
|
||||
$html = function_exists('aksrt_get_ajax_null')
|
||||
? aksrt_get_ajax_null(__('暂无付费内容', 'aksrt'))
|
||||
|
||||
@@ -15,7 +15,10 @@ class WidgetProductOneline extends WidgetProductList {
|
||||
\WP_Widget::__construct(
|
||||
'aksrt_product_oneline',
|
||||
__('横滑商品', 'aksrt'),
|
||||
['description' => __('AKSRT 单行横滑商品列表(AJAX 同源)。', 'aksrt')]
|
||||
[
|
||||
'description' => __('AKSRT 单行横滑商品(swiper-scroll,同源 product list)。', 'aksrt'),
|
||||
'classname' => 'widget_aksrt_product_oneline',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -29,13 +32,21 @@ class WidgetProductOneline extends WidgetProductList {
|
||||
}
|
||||
|
||||
public function form($instance): void {
|
||||
$instance = wp_parse_args($instance, ['style' => 'oneline', 'paginate' => 'none']);
|
||||
$instance = wp_parse_args($instance, [
|
||||
'title' => __('横滑商品', 'aksrt'),
|
||||
'style' => 'oneline',
|
||||
'paginate' => 'none',
|
||||
'per_page' => 8,
|
||||
]);
|
||||
parent::form($instance);
|
||||
}
|
||||
|
||||
public function update($new_instance, $old_instance): array {
|
||||
$out = parent::update($new_instance, $old_instance);
|
||||
$out['style'] = 'oneline';
|
||||
if (($out['paginate'] ?? '') === '') {
|
||||
$out['paginate'] = 'none';
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user