feat(widgets): comments CPT, tag scale, oneline filters + CSS
RecentComments uses aksrt_forum_topic/product + lazy avatars; TagCloud scale works; OnelinePosts topics/pay_type; batch34-36 residual CSS.
This commit is contained in:
@@ -56,10 +56,16 @@ class RecentCommentsWidget extends \WP_Widget {
|
||||
'orderby' => 'comment_date_gmt',
|
||||
'order' => 'DESC',
|
||||
];
|
||||
// Include forum topics when forum is active.
|
||||
if (post_type_exists('forum_topic') || post_type_exists('forum_post')) {
|
||||
// Include forum topics / products when active.
|
||||
if (post_type_exists('aksrt_forum_topic')) {
|
||||
$query['post_type'][] = 'aksrt_forum_topic';
|
||||
} elseif (post_type_exists('forum_topic') || post_type_exists('forum_post')) {
|
||||
// Legacy CPT names.
|
||||
$query['post_type'][] = post_type_exists('forum_topic') ? 'forum_topic' : 'forum_post';
|
||||
}
|
||||
if (post_type_exists('aksrt_product')) {
|
||||
$query['post_type'][] = 'aksrt_product';
|
||||
}
|
||||
if ($post_not_in) {
|
||||
$query['post__not_in'] = $post_not_in;
|
||||
}
|
||||
@@ -126,7 +132,8 @@ class RecentCommentsWidget extends \WP_Widget {
|
||||
$avatar_url = $user_id > 0 && function_exists('aksrt_get_avatar_url')
|
||||
? aksrt_get_avatar_url($user_id, ['size' => 42])
|
||||
: get_avatar_url($comment, ['size' => 42]);
|
||||
$avatar = '<div class="avatar-img"><img class="avatar" src="' . esc_url($avatar_url) . '" alt="" width="36" height="36" loading="lazy" /></div>';
|
||||
$ph = get_template_directory_uri() . '/assets/img/placeholder.svg';
|
||||
$avatar = '<div class="avatar-img"><img class="avatar aksrt-lazy lazyload" data-src="' . esc_url($avatar_url) . '" src="' . esc_url($ph) . '" alt="" width="36" height="36" loading="lazy" /></div>';
|
||||
}
|
||||
|
||||
$like = function_exists('aksrt_get_comment_like_html')
|
||||
|
||||
@@ -52,7 +52,17 @@ class TagCloudWidget extends \WP_Widget {
|
||||
|
||||
$palette = ['c-blue', 'c-yellow', 'c-green', 'c-purple', 'c-red', '', 'c-blue-2', 'c-yellow-2', 'c-green-2', 'c-purple-2', 'c-red-2', ''];
|
||||
$i = random_int(0, 10);
|
||||
$wrap = 'tag-cloud aksrt-tag-cloud author-tag ajax-item' . ($fixed_width ? ' fixed-width' : '');
|
||||
$scale = !empty($instance['scale']);
|
||||
$min_c = null;
|
||||
$max_c = null;
|
||||
if ($scale) {
|
||||
foreach ($tags as $t0) {
|
||||
$c0 = (int) $t0->count;
|
||||
$min_c = $min_c === null ? $c0 : min($min_c, $c0);
|
||||
$max_c = $max_c === null ? $c0 : max($max_c, $c0);
|
||||
}
|
||||
}
|
||||
$wrap = 'zib-widget widget-tag-cloud tag-cloud aksrt-tag-cloud author-tag ajax-item' . ($fixed_width ? ' fixed-width' : '');
|
||||
ob_start();
|
||||
echo '<div class="' . esc_attr($wrap) . '">';
|
||||
foreach ($tags as $tag) {
|
||||
@@ -71,8 +81,15 @@ class TagCloudWidget extends \WP_Widget {
|
||||
$cls .= ' ' . $color;
|
||||
}
|
||||
$tgt = $blank ? ' target="_blank" rel="noopener noreferrer"' : '';
|
||||
$count = $show_count ? '<span class="em09 tag-count"> (' . (int) $tag->count . ')</span>' : '';
|
||||
echo '<a href="' . esc_url($url) . '" class="text-ellipsis ' . esc_attr(trim($cls)) . '"' . $tgt . '>' . esc_html($tag->name) . $count . '</a>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
$count_html = $show_count ? '<span class="em09 tag-count"> (' . (int) $tag->count . ')</span>' : '';
|
||||
$style_attr = '';
|
||||
if ($scale && $max_c !== null && $min_c !== null) {
|
||||
$span = max(1, $max_c - $min_c);
|
||||
$ratio = ((int) $tag->count - $min_c) / $span;
|
||||
$em = round(0.85 + ($ratio * 0.4), 3);
|
||||
$style_attr = ' style="font-size:' . esc_attr((string) $em) . 'em;--tag-scale:' . esc_attr((string) $em) . ';"';
|
||||
}
|
||||
echo '<a href="' . esc_url($url) . '" class="text-ellipsis ' . esc_attr(trim($cls)) . '"' . $tgt . $style_attr . '>' . esc_html($tag->name) . $count_html . '</a>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
echo '</div>';
|
||||
return (string) ob_get_clean();
|
||||
|
||||
@@ -63,6 +63,30 @@ class WidgetOnelinePosts extends \WP_Widget {
|
||||
$query['orderby'] = 'date';
|
||||
$query['order'] = 'DESC';
|
||||
}
|
||||
$topics_raw = trim((string) ($instance['topics'] ?? ''));
|
||||
if ($topics_raw !== '' && taxonomy_exists('topics')) {
|
||||
$topic_ids = array_values(array_filter(array_map('intval', preg_split('/[,,\s]+/', $topics_raw) ?: [])));
|
||||
if ($topic_ids) {
|
||||
$query['tax_query'] = [[
|
||||
'taxonomy' => 'topics',
|
||||
'field' => 'term_id',
|
||||
'terms' => $topic_ids,
|
||||
]];
|
||||
}
|
||||
}
|
||||
$pay_type = sanitize_key((string) ($instance['pay_type'] ?? ''));
|
||||
if ($pay_type !== '' && $pay_type !== '0' && $pay_type !== 'no') {
|
||||
if ($pay_type === 'any' || $pay_type === 'paid') {
|
||||
$query['meta_query'] = [
|
||||
'relation' => 'OR',
|
||||
['key' => '_aksrt_pay_price', 'value' => 0, 'compare' => '>', 'type' => 'NUMERIC'],
|
||||
['key' => '_aksrt_pay_type', 'value' => ['reading', 'download', 'gallery', 'video', 'vip'], 'compare' => 'IN'],
|
||||
['key' => '_aksrt_visibility', 'value' => ['pay', 'credits'], 'compare' => 'IN'],
|
||||
];
|
||||
} else {
|
||||
$query['meta_query'] = [['key' => '_aksrt_pay_type', 'value' => $pay_type]];
|
||||
}
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
@@ -212,6 +236,21 @@ class WidgetOnelinePosts extends \WP_Widget {
|
||||
<input class="tiny-text" type="number" min="0" name="<?php echo esc_attr($this->get_field_name('limit_day')); ?>" value="<?php echo esc_attr((string) ((int) ($instance['limit_day'] ?? 0))); ?>">
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label><?php esc_html_e('专题 topics ID(逗号)', 'aksrt'); ?>
|
||||
<input class="widefat" type="text" name="<?php echo esc_attr($this->get_field_name('topics')); ?>" value="<?php echo esc_attr((string) ($instance['topics'] ?? '')); ?>">
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label><?php esc_html_e('付费类型', 'aksrt'); ?>
|
||||
<select name="<?php echo esc_attr($this->get_field_name('pay_type')); ?>">
|
||||
<option value="" <?php selected(($instance['pay_type'] ?? ''), ''); ?>><?php esc_html_e('不限', 'aksrt'); ?></option>
|
||||
<option value="paid" <?php selected(($instance['pay_type'] ?? ''), 'paid'); ?>><?php esc_html_e('任意付费', 'aksrt'); ?></option>
|
||||
<option value="reading" <?php selected(($instance['pay_type'] ?? ''), 'reading'); ?>><?php esc_html_e('付费阅读', 'aksrt'); ?></option>
|
||||
<option value="download" <?php selected(($instance['pay_type'] ?? ''), 'download'); ?>><?php esc_html_e('付费下载', 'aksrt'); ?></option>
|
||||
</select>
|
||||
</label>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
@@ -236,6 +275,8 @@ class WidgetOnelinePosts extends \WP_Widget {
|
||||
'orderby' => $orderby,
|
||||
'cat' => max(0, (int) ($new_instance['cat'] ?? 0)),
|
||||
'limit_day' => max(0, (int) ($new_instance['limit_day'] ?? 0)),
|
||||
'topics' => sanitize_text_field((string) ($new_instance['topics'] ?? '')),
|
||||
'pay_type' => sanitize_key((string) ($new_instance['pay_type'] ?? '')),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user