diff --git a/assets/css/frontend/widget-batch5.css b/assets/css/frontend/widget-batch5.css index ded92c65..61d5b6d6 100644 --- a/assets/css/frontend/widget-batch5.css +++ b/assets/css/frontend/widget-batch5.css @@ -1702,3 +1702,126 @@ .term-aggregation .hide-sm { display: none !important; } .aksrt-oneline-swiper .swiper-slide { max-width: 72%; min-width: 140px; } } + +/* ===== Batch14: recent comments mini + friend links + iframe + cover ===== */ + +.comment-mini-lists.widget-recent-comments, +.comment-mini-lists.zib-widget { + padding: 4px 0; +} +.comment-mini-lists .posts-mini { + display: flex; + align-items: flex-start; + gap: 0; + padding: 10px 0; + border-bottom: 1px solid var(--color-line, rgba(0,0,0,.06)); +} +.comment-mini-lists .posts-mini:last-child { + border-bottom: 0; +} +.comment-mini-lists .avatar-img { + flex: 0 0 auto; + --this-size: 36px; +} +.comment-mini-lists .avatar-img img.avatar { + width: 36px; + height: 36px; + border-radius: 50%; + object-fit: cover; + display: block; +} +.comment-mini-lists .posts-mini-con { + min-width: 0; + flex: 1; +} +.comment-mini-lists .posts-mini-con > p.flex { + display: flex; + justify-content: space-between; + align-items: center; + margin: 0 0 4px; + gap: 8px; +} +.comment-mini-lists .icon-spot:before { + content: "·"; + margin: 0 6px; + opacity: .5; +} +.comment-mini-lists a.muted-color { + color: var(--muted-2-color, #666); + text-decoration: none; + display: -webkit-box; + -webkit-line-clamp: 3; + -webkit-box-orient: vertical; + overflow: hidden; + line-height: 1.5; +} +.comment-mini-lists a.muted-color:hover { + color: var(--theme-color, var(--focus-color, #f04494)); +} + +/* Friend links reuse bookmark-links styles */ +.aksrt-friend-links.links-box { + display: flex; + flex-wrap: wrap; + gap: 10px; +} +.aksrt-friend-links.style-simple { + gap: 6px 12px; +} +.aksrt-friend-links.style-image { + gap: 8px; +} + +/* Iframe lazy shell */ +.wp-block-embed.is-type-video.relative-h, +.aksrt-iframe-embed .relative-h { + position: relative; + overflow: hidden; + border-radius: 8px; + background: #0f172a; +} +.aksrt-iframe-ratio { + position: relative; + width: 100%; + height: 0; +} +.aksrt-iframe-ratio iframe, +.aksrt-iframe-el { + position: absolute; + inset: 0; + width: 100%; + height: 100%; + border: 0; +} + +/* Cover cards row already covered by term-cards col rules — scope shared */ +.widget-graphic-cover .row.gutters-5 { + display: flex; + flex-wrap: wrap; + margin: 0 -4px; +} +.widget-graphic-cover .row.gutters-5 > [class*="col-"] { + padding: 0 4px; + box-sizing: border-box; +} +.widget-graphic-cover .col-sm-12 { width: 100%; } +.widget-graphic-cover .col-sm-6 { width: 50%; } +.widget-graphic-cover .col-sm-4 { width: 33.333%; } +.widget-graphic-cover .col-sm-3 { width: 25%; } +.widget-graphic-cover .col-sm-2 { width: 16.666%; } +@media (max-width: 767px) { + .widget-graphic-cover .col-xs-12 { width: 100%; } + .widget-graphic-cover .col-xs-6 { width: 50%; } + .widget-graphic-cover .col-xs-4 { width: 33.333%; } +} +.widget-graphic-cover .this-font { + font-size: var(--font-size, 18px); + font-weight: var(--font-weight, 600); + color: var(--color, #fff); +} +@media (max-width: 767px) { + .widget-graphic-cover .this-font { + font-size: var(--font-size-sm, 14px); + font-weight: var(--font-weight-sm, 600); + } +} diff --git a/assets/js/core/pagination.js b/assets/js/core/pagination.js index cd415ede..6c63914a 100644 --- a/assets/js/core/pagination.js +++ b/assets/js/core/pagination.js @@ -275,23 +275,49 @@ }); } + function activateLazyEl(el) { + var src = el.dataset.src; + if (!src) return; + var tag = (el.tagName || "").toLowerCase(); + if (tag === "iframe" || tag === "video") { + el.src = src; + el.classList.remove("aksrt-lazy", "lazyload"); + el.classList.add("aksrt-loaded", "lazyloaded"); + return; + } + // img path with optional skeleton + decode + var tempImg = new Image(); + tempImg.onload = function () { + el.src = src; + el.classList.remove("aksrt-lazy", "lazyload"); + el.classList.add("aksrt-loaded", "lazyloaded"); + var skeleton = el.previousElementSibling; + if (skeleton && skeleton.classList.contains("aksrt-skeleton")) { + skeleton.remove(); + } + }; + tempImg.onerror = function () { + el.classList.remove("aksrt-lazy", "lazyload"); + el.classList.add("aksrt-error"); + var skeleton = el.previousElementSibling; + if (skeleton && skeleton.classList.contains("aksrt-skeleton")) { + skeleton.remove(); + } + }; + tempImg.src = src; + } + function initLazyLoad(root) { var scope = root || document; - var lazyImages = scope.querySelectorAll("img.aksrt-lazy"); - if (!lazyImages.length) return; + // Images + iframes/videos that use data-src (zibll lazyload / aksrt-lazy). + var lazyEls = scope.querySelectorAll( + "img.aksrt-lazy, iframe.aksrt-lazy, iframe.lazyload, video.aksrt-lazy, video.lazyload" + ); + if (!lazyEls.length) return; if (!("IntersectionObserver" in window)) { - lazyImages.forEach(function (img) { - var src = img.dataset.src; - if (src) { - img.src = src; - img.classList.remove("aksrt-lazy"); - img.classList.add("aksrt-loaded"); - } - var skeleton = img.previousElementSibling; - if (skeleton && skeleton.classList.contains("aksrt-skeleton")) { - skeleton.remove(); - } + lazyEls.forEach(function (el) { + activateLazyEl(el); }); return; } @@ -299,43 +325,21 @@ var observer = new IntersectionObserver(function (entries) { entries.forEach(function (entry) { if (!entry.isIntersecting) return; - - var img = entry.target; - var src = img.dataset.src; - if (!src) { - observer.unobserve(img); + var el = entry.target; + if (!el.dataset.src) { + observer.unobserve(el); return; } - - var tempImg = new Image(); - tempImg.onload = function () { - img.src = src; - img.classList.remove("aksrt-lazy"); - img.classList.add("aksrt-loaded"); - var skeleton = img.previousElementSibling; - if (skeleton && skeleton.classList.contains("aksrt-skeleton")) { - skeleton.remove(); - } - }; - tempImg.onerror = function () { - img.classList.remove("aksrt-lazy"); - img.classList.add("aksrt-error"); - var skeleton = img.previousElementSibling; - if (skeleton && skeleton.classList.contains("aksrt-skeleton")) { - skeleton.remove(); - } - }; - tempImg.src = src; - - observer.unobserve(img); + activateLazyEl(el); + observer.unobserve(el); }); }, { rootMargin: "200px 0px", threshold: 0.01 }); - lazyImages.forEach(function (img) { - observer.observe(img); + lazyEls.forEach(function (el) { + observer.observe(el); }); } diff --git a/src/AKSRT/Widgets/FriendLinksWidget.php b/src/AKSRT/Widgets/FriendLinksWidget.php index b4b9de51..6818da21 100644 --- a/src/AKSRT/Widgets/FriendLinksWidget.php +++ b/src/AKSRT/Widgets/FriendLinksWidget.php @@ -1,6 +1,6 @@ esc_html__('显示友情链接(设置项或 WordPress 书签)。', 'aksrt'), + 'description' => esc_html__('友情链接:card / bigcard / image / simple(共享 aksrt_links_box)。', 'aksrt'), + 'classname' => 'widget_aksrt_friend_links', ]); } + /** + * @param array $args + * @param array $instance + */ public function widget($args, $instance): void { echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $title = apply_filters('widget_title', (string) ($instance['title'] ?? __('友情链接', 'aksrt')), $instance, $this->id_base); - $show_icon = !empty($instance['show_icon']) || !isset($instance['show_icon']); - $columns = max(1, min(4, (int) ($instance['columns'] ?? 2))); $source = sanitize_key((string) ($instance['source'] ?? 'settings')); $go_link = !empty($instance['go_link']); $limit = max(1, min(100, (int) ($instance['limit'] ?? 24))); + $type = sanitize_key((string) ($instance['type'] ?? 'card')); + if (!in_array($type, ['card', 'bigcard', 'image', 'simple'], true)) { + $type = 'card'; + } + $blank = !isset($instance['blank']) || !empty($instance['blank']); + $nofollow = !isset($instance['nofollow']) || !empty($instance['nofollow']); + $show_box = !empty($instance['show_box']) || !isset($instance['show_box']); if ($title) { echo $args['before_title'] . esc_html($title) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } - $links = $this->resolve_links($source, $instance, $limit); - if (!$links) { + $bookmarks = $this->resolve_bookmarks($source, $instance, $limit); + if (!$bookmarks) { echo function_exists('aksrt_get_widget_null') ? aksrt_get_widget_null(__('暂无友情链接', 'aksrt')) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped : '

' . esc_html__('暂无友情链接', 'aksrt') . '

'; echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped return; } - ?> - - ' . esc_html($name) . ''; + } + } + echo ''; + echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** + * Normalize to get_bookmarks-like objects/arrays for aksrt_links_box. + * * @param array $instance - * @return array> + * @return array */ - private function resolve_links(string $source, array $instance, int $limit): array { + private function resolve_bookmarks(string $source, array $instance, int $limit): array { if ($source === 'bookmarks') { $bm_args = [ 'orderby' => sanitize_key((string) ($instance['orderby'] ?? 'name')) ?: 'name', @@ -76,29 +86,35 @@ class FriendLinksWidget extends \WP_Widget { 'limit' => $limit, ]; $cats = trim((string) ($instance['cats'] ?? '')); - if ($cats !== '') { + if ($cats !== '' && $cats !== 'all') { $bm_args['category'] = $cats; } - $out = []; - foreach (get_bookmarks($bm_args) as $b) { - $out[] = [ - 'name' => (string) $b->link_name, - 'url' => (string) $b->link_url, - 'description' => (string) $b->link_description, - 'icon' => (string) $b->link_image, - ]; - } - return $out; + return get_bookmarks($bm_args) ?: []; } $links = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_friend_links() : []; if (!is_array($links) || !$links) { - // Fallback to WP bookmarks when settings empty. - return $this->resolve_links('bookmarks', $instance, $limit); + return $this->resolve_bookmarks('bookmarks', $instance, $limit); } - return array_slice(array_values($links), 0, $limit); + $out = []; + foreach (array_slice(array_values($links), 0, $limit) as $link) { + if (!is_array($link)) { + continue; + } + $out[] = (object) [ + 'link_name' => (string) ($link['name'] ?? ''), + 'link_url' => (string) ($link['url'] ?? ''), + 'link_description' => (string) ($link['description'] ?? $link['desc'] ?? ''), + 'link_image' => (string) ($link['icon'] ?? $link['image'] ?? ''), + 'link_target' => '_blank', + ]; + } + return $out; } + /** + * @param array $instance + */ public function form($instance): void { ?>

@@ -115,8 +131,13 @@ class FriendLinksWidget extends \WP_Widget {

-

-
- +
+
+
+

$new_instance + * @param array $old_instance + * @return array + */ public function update($new_instance, $old_instance): array { + $type = sanitize_key((string) ($new_instance['type'] ?? 'card')); + if (!in_array($type, ['card', 'bigcard', 'image', 'simple'], true)) { + $type = 'card'; + } return [ 'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')), 'source' => ($new_instance['source'] ?? '') === 'bookmarks' ? 'bookmarks' : 'settings', - 'columns' => max(1, min(4, (int) ($new_instance['columns'] ?? 2))), + 'type' => $type, 'limit' => max(1, min(100, (int) ($new_instance['limit'] ?? 24))), 'cats' => sanitize_text_field((string) ($new_instance['cats'] ?? '')), - 'show_icon' => !empty($new_instance['show_icon']) ? 1 : 0, + 'blank' => !empty($new_instance['blank']) ? 1 : 0, + 'nofollow' => !empty($new_instance['nofollow']) ? 1 : 0, 'go_link' => !empty($new_instance['go_link']) ? 1 : 0, + 'show_box' => !empty($new_instance['show_box']) ? 1 : 0, 'orderby' => sanitize_key((string) ($new_instance['orderby'] ?? 'name')), 'order' => strtoupper((string) ($new_instance['order'] ?? 'ASC')) === 'DESC' ? 'DESC' : 'ASC', + // Keep legacy keys so old instances don't explode. + 'columns' => max(1, min(4, (int) ($new_instance['columns'] ?? 2))), + 'show_icon' => !empty($new_instance['show_icon']) ? 1 : 0, ]; } } diff --git a/src/AKSRT/Widgets/RecentCommentsWidget.php b/src/AKSRT/Widgets/RecentCommentsWidget.php index 2a382d95..34a49134 100644 --- a/src/AKSRT/Widgets/RecentCommentsWidget.php +++ b/src/AKSRT/Widgets/RecentCommentsWidget.php @@ -1,6 +1,6 @@ esc_html__('显示最新评论列表', 'aksrt'), + 'description' => esc_html__('显示最新评论列表(posts-mini + 身份/点赞)。', 'aksrt'), ]); } + /** + * @param array $instance + */ public static function render_html(array $instance): string { $count = max(1, min(20, (int) ($instance['count'] ?? $instance['limit'] ?? 5))); $show_avatar = !isset($instance['show_avatar']) || !empty($instance['show_avatar']); - $outpost = max(0, (int) ($instance['outpost'] ?? 0)); - $outer = sanitize_text_field((string) ($instance['outer'] ?? '')); + // zibll: outpost = post__not_in (multi-ID), outer = author__not_in (multi-ID). + // Also keep optional keyword filter via outer_keywords for legacy installs. + $outpost_raw = (string) ($instance['outpost'] ?? ''); + $outer_raw = (string) ($instance['outer'] ?? ''); + $keywords = sanitize_text_field((string) ($instance['outer_keywords'] ?? '')); + + $post_not_in = array_values(array_filter(array_map('intval', preg_split('/[,,\s]+/', $outpost_raw) ?: []))); + // Heuristic: if outer looks numeric/id-list → author__not_in; else treat as keyword filter (legacy). + $author_not_in = []; + $legacy_keys = []; + if ($outer_raw !== '') { + $parts = array_filter(array_map('trim', preg_split('/[,,\s]+/', $outer_raw) ?: [])); + $all_numeric = $parts && array_reduce($parts, static function ($ok, $p) { + return $ok && ctype_digit((string) $p); + }, true); + if ($all_numeric) { + $author_not_in = array_values(array_filter(array_map('intval', $parts))); + } else { + $legacy_keys = $parts; + } + } + if ($keywords !== '') { + $legacy_keys = array_merge($legacy_keys, array_filter(array_map('trim', preg_split('/[,,]+/', $keywords) ?: []))); + } + $query = [ - 'number' => $count, + 'number' => $count * 2, // over-fetch when filtering keywords. 'status' => 'approve', 'post_status' => 'publish', + 'post_type' => ['post'], + 'orderby' => 'comment_date_gmt', + 'order' => 'DESC', ]; - if ($outpost > 0) { - $query['post__not_in'] = [$outpost]; + // Include forum topics when forum is active. + if (post_type_exists('forum_topic') || post_type_exists('forum_post')) { + $query['post_type'][] = post_type_exists('forum_topic') ? 'forum_topic' : 'forum_post'; } + if ($post_not_in) { + $query['post__not_in'] = $post_not_in; + } + if ($author_not_in) { + $query['author__not_in'] = $author_not_in; + } + $comments = get_comments($query); - if ($outer !== '' && $comments) { - $keys = array_filter(array_map('trim', preg_split('/[,,]/', $outer) ?: [])); - if ($keys) { - $comments = array_values(array_filter($comments, static function ($c) use ($keys) { - $body = (string) $c->comment_content; - foreach ($keys as $k) { - if ($k !== '' && str_contains($body, $k)) { - return false; - } + if ($legacy_keys && $comments) { + $comments = array_values(array_filter($comments, static function ($c) use ($legacy_keys) { + $body = (string) $c->comment_content; + foreach ($legacy_keys as $k) { + if ($k !== '' && str_contains($body, $k)) { + return false; } - return true; - })); - } + } + return true; + })); } + $comments = array_slice($comments ?: [], 0, $count); + if (!$comments) { - return '

' . esc_html__('暂无评论', 'aksrt') . '

'; + return function_exists('aksrt_get_ajax_null') + ? aksrt_get_ajax_null(__('暂无评论', 'aksrt')) + : '

' . esc_html__('暂无评论', 'aksrt') . '

'; } + ob_start(); - echo '
'; + // zibll: .box-body.comment-mini-lists.zib-widget + .posts-mini rows. + echo '
'; foreach ($comments as $comment) { - $post = get_post($comment->comment_post_ID); - if (!$post) { - continue; + $cid = (int) $comment->comment_ID; + $user_id = (int) $comment->user_id; + $link = get_comment_link($comment); + $time = human_time_diff(strtotime((string) $comment->comment_date), current_time('timestamp')); + + // Content: strip imgs/code like zibll noimg filter. + $cont = get_comment_text($cid); + $cont = convert_smilies($cont); + $cont = preg_replace('/\/i', '[' . __('图片', 'aksrt') . ']', $cont); + $cont = preg_replace('/\[code]([\s\S]*?)\[\/code]/i', '[' . __('代码', 'aksrt') . ']', (string) $cont); + $cont = wp_strip_all_tags((string) $cont); + $cont = wp_trim_words($cont, 40, '…'); + + // Name with identity. + if ($user_id > 0 && function_exists('aksrt_get_user_name')) { + $user_name = aksrt_get_user_name([ + 'id' => $user_id, + 'class' => 'inflex ac relative-h', + 'follow' => false, + 'medal' => true, + 'level' => true, + 'auth' => true, + ]); + } elseif ($user_id > 0) { + $home = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($user_id) : get_author_posts_url($user_id); + $user_name = '' . esc_html(get_comment_author($comment)) . ''; + } else { + $user_name = esc_html(get_comment_author($comment)); } - echo '
'; + + $avatar = ''; if ($show_avatar) { - echo '
' . get_avatar($comment, 32) . '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + $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 = '
'; } - echo '
'; - echo '
'; - echo '' . esc_html($comment->comment_author) . ''; - echo '' . esc_html(human_time_diff(strtotime($comment->comment_date), current_time('timestamp'))) . ''; - echo '
'; - echo '

' . esc_html(wp_trim_words($comment->comment_content, 15, '...')) . '

'; - echo '
' . esc_html(get_the_title($post)) . '
'; + + $like = function_exists('aksrt_get_comment_like_html') + ? aksrt_get_comment_like_html($comment, true) + : ''; + + echo '
'; + echo $avatar; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + echo '
'; + echo '

'; + echo ''; + echo $user_name; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + echo '' . esc_html($time) . ''; + echo ''; + if ($like !== '') { + echo '' . $like . ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + } + echo '

'; + echo '' . esc_html($cont) . ''; echo '
'; } echo '
'; return (string) ob_get_clean(); } + /** + * @param array $args + * @param array $instance + */ public function widget($args, $instance): void { echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $title = apply_filters('widget_title', (string) ($instance['title'] ?? __('最新评论', 'aksrt')), $instance, $this->id_base); @@ -85,6 +169,9 @@ class RecentCommentsWidget extends \WP_Widget { echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } + /** + * @param array $instance + */ public function form($instance): void { ?>

@@ -101,24 +188,30 @@ class RecentCommentsWidget extends \WP_Widget {

-

-

$new_instance + * @param array $old_instance + * @return array + */ public function update($new_instance, $old_instance): array { return [ 'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')), 'count' => max(1, min(20, (int) ($new_instance['count'] ?? 5))), 'show_avatar' => !empty($new_instance['show_avatar']) ? 1 : 0, - 'outpost' => max(0, (int) ($new_instance['outpost'] ?? 0)), + 'outpost' => sanitize_text_field((string) ($new_instance['outpost'] ?? '')), 'outer' => sanitize_text_field((string) ($new_instance['outer'] ?? '')), ]; } diff --git a/src/AKSRT/Widgets/WidgetCoverCards.php b/src/AKSRT/Widgets/WidgetCoverCards.php index 61dc1f52..23937c9b 100644 --- a/src/AKSRT/Widgets/WidgetCoverCards.php +++ b/src/AKSRT/Widgets/WidgetCoverCards.php @@ -1,5 +1,7 @@ __('图片背景 + 文字叠加的卡片网格。', 'aksrt')] - ); - } + public function __construct() { + parent::__construct( + 'aksrt_cover_cards', + __('图文封面卡片', 'aksrt'), + ['description' => __('图片/视频封面 + 文字叠加的图文卡片(共享 graphic_card)。', 'aksrt')] + ); + } - public function widget($args, $instance): void { - $title = !empty($instance['title']) ? $instance['title'] : ''; - $items_json = !empty($instance['items']) ? $instance['items'] : '[]'; - $columns = max(1, min(4, (int) ($instance['columns'] ?? 2))); + /** + * @param array $args + * @param array $instance + */ + public function widget($args, $instance): void { + $title = !empty($instance['title']) ? (string) $instance['title'] : ''; + $items = $this->normalize($instance['items'] ?? []); + if (!$items) { + return; + } - $items = json_decode($items_json, true); - if (!is_array($items) || empty($items)) return; + $pc_row = max(1, min(6, (int) ($instance['pc_row'] ?? $instance['columns'] ?? 2))); + $m_row = max(1, min(3, (int) ($instance['m_row'] ?? 1))); + $height_scale = max(30, min(120, (int) ($instance['height_scale'] ?? 70))); + $mask_opacity = max(0, min(80, (int) ($instance['mask_opacity'] ?? 20))); + $font_size_pc = max(12, min(32, (int) ($instance['font_size_pc'] ?? 18))); + $font_size_m = max(11, min(24, (int) ($instance['font_size_m'] ?? 14))); + $font_bold = !empty($instance['font_bold']); + $font_color = sanitize_hex_color((string) ($instance['font_color'] ?? '')) ?: ''; - echo $args['before_widget']; + echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped - if ($title) { - echo $args['before_title'] . esc_html($title) . $args['after_title']; - } + if ($title !== '') { + echo $args['before_title'] . esc_html($title) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + } - echo '
'; + $is_row = count($items) > 1; + $pc_span = max(1, (int) floor(12 / $pc_row)); + $m_span = max(1, (int) floor(12 / $m_row)); + $row_class = 'col-sm-' . $pc_span . ($m_row > 1 ? ' col-xs-' . $m_span : ''); - foreach ($items as $item) { - $image = esc_url($item['image'] ?? ''); - $video = esc_url($item['video'] ?? ''); - $link = esc_url($item['link'] ?? ''); - $card_title = sanitize_text_field($item['title'] ?? ''); - $desc = sanitize_text_field($item['desc'] ?? ''); - $overlay = sanitize_hex_color($item['overlay'] ?? ''); - $text_color = sanitize_hex_color($item['text_color'] ?? ''); - $height = sanitize_text_field($item['height'] ?? ''); + $style = ''; + if ($font_size_pc !== 14) { + $style .= '--font-size:' . $font_size_pc . 'px;'; + } + if ($font_size_m !== 14) { + $style .= '--font-size-sm:' . $font_size_m . 'px;'; + } + if ($font_bold) { + $style .= '--font-weight:bold;--font-weight-sm:bold;'; + } + if ($font_color !== '') { + $style .= '--color:' . $font_color . ';--color-sm:' . $font_color . ';'; + } - $card_style = ''; - if ($height) $card_style .= 'height:' . esc_attr($height) . ';'; + echo '
'; + if ($is_row) { + echo '
'; + } - $overlay_style = ''; - if ($overlay) $overlay_style .= 'background:' . esc_attr($overlay) . ';'; + foreach ($items as $item) { + $hide = sanitize_key((string) ($item['hide'] ?? '')); + if ($hide === 'pc' || $hide === 'm') { + $is_mobile = function_exists('wp_is_mobile') ? wp_is_mobile() : false; + if ((!$is_mobile && $hide === 'pc') || ($is_mobile && $hide === 'm')) { + continue; + } + } + $card_title = (string) ($item['title'] ?? ''); + $more = $card_title !== '' + ? '
' . esc_html($card_title) . '
' + : ''; - $text_style = ''; - if ($text_color) $text_style .= 'color:' . esc_attr($text_color) . ';'; + $card = [ + 'class' => 'noshadow mb10', + 'img' => (string) ($item['image'] ?? ''), + 'video' => (string) ($item['video'] ?? ''), + 'alt' => wp_strip_all_tags($card_title), + 'link' => [ + 'url' => (string) ($item['link'] ?? ''), + 'target' => (string) ($item['target'] ?? ''), + ], + 'lazy' => true, + 'more' => $more, + 'height_scale' => !empty($item['height']) && is_numeric($item['height']) + ? (int) $item['height'] + : $height_scale, + 'mask_opacity' => isset($item['mask']) ? (int) $item['mask'] : $mask_opacity, + ]; - echo '
'; + if ($is_row) { + echo '
'; + } + if (function_exists('aksrt_graphic_card')) { + echo aksrt_graphic_card($card); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + } + if ($is_row) { + echo '
'; + } + } - if ($video) { - echo '
'; - echo ''; - echo '
'; - } elseif ($image) { - echo '
'; - echo '' . esc_attr($card_title) . ''; - echo '
'; - } + if ($is_row) { + echo '
'; + } + echo '
'; - if ($overlay_style) { - echo '
'; - } + echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + } - echo '
'; + /** + * @param mixed $raw + * @return array> + */ + private function normalize($raw): array { + if (is_string($raw)) { + $decoded = json_decode($raw, true); + $raw = is_array($decoded) ? $decoded : []; + } + if (!is_array($raw)) { + return []; + } + $out = []; + foreach ($raw as $row) { + if (!is_array($row)) { + continue; + } + $image = esc_url_raw(trim((string) ($row['image'] ?? ''))); + $video = esc_url_raw(trim((string) ($row['video'] ?? ''))); + if ($image === '' && $video === '') { + continue; + } + $out[] = [ + 'title' => sanitize_text_field((string) ($row['title'] ?? '')), + 'desc' => sanitize_text_field((string) ($row['desc'] ?? '')), + 'image' => $image, + 'video' => $video, + 'link' => esc_url_raw(trim((string) ($row['link'] ?? ''))), + 'target' => sanitize_text_field((string) ($row['target'] ?? '')), + 'hide' => sanitize_key((string) ($row['hide'] ?? '')), + 'height' => isset($row['height']) ? (int) $row['height'] : 0, + 'mask' => isset($row['mask']) ? (int) $row['mask'] : null, + ]; + if (count($out) >= 12) { + break; + } + } + return $out; + } - if ($link) { - echo ''; - } + /** + * @param array $instance + */ + public function form($instance): void { + $items = $this->normalize($instance['items'] ?? []); + $json = wp_json_encode($items, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); + ?> +

+ +

+

+ + +

+

+ + +

+

+ + +

+ ' . esc_html($card_title) . ''; - } - if ($desc) { - echo '

' . esc_html($desc) . '

'; - } - - if ($link) { - echo '
'; - } - - echo '
'; - echo '
'; - } - - echo '
'; - - echo $args['after_widget']; - } - - public function form($instance): void { - $title = !empty($instance['title']) ? $instance['title'] : ''; - $items = !empty($instance['items']) ? $instance['items'] : '[]'; - $columns = !empty($instance['columns']) ? (int) $instance['columns'] : 2; - ?> -

- - -

-

- - -

-

- - - -

- $new_instance + * @param array $old_instance + * @return array + */ + public function update($new_instance, $old_instance): array { + return [ + 'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')), + 'pc_row' => max(1, min(6, (int) ($new_instance['pc_row'] ?? 2))), + 'm_row' => max(1, min(3, (int) ($new_instance['m_row'] ?? 1))), + 'columns' => max(1, min(6, (int) ($new_instance['pc_row'] ?? $new_instance['columns'] ?? 2))), + 'height_scale' => max(30, min(120, (int) ($new_instance['height_scale'] ?? 70))), + 'mask_opacity' => max(0, min(80, (int) ($new_instance['mask_opacity'] ?? 20))), + 'font_size_pc' => max(12, min(32, (int) ($new_instance['font_size_pc'] ?? 18))), + 'font_size_m' => max(11, min(24, (int) ($new_instance['font_size_m'] ?? 14))), + 'font_bold' => !empty($new_instance['font_bold']) ? 1 : 0, + 'font_color' => sanitize_hex_color((string) ($new_instance['font_color'] ?? '')) ?: '', + 'items' => $this->normalize($new_instance['items'] ?? []), + ]; + } } diff --git a/src/AKSRT/Widgets/WidgetIframe.php b/src/AKSRT/Widgets/WidgetIframe.php index eaeeb2cc..cd2d04d9 100644 --- a/src/AKSRT/Widgets/WidgetIframe.php +++ b/src/AKSRT/Widgets/WidgetIframe.php @@ -22,9 +22,19 @@ class WidgetIframe extends \WP_Widget { ); } + /** + * @param array $args + * @param array $instance + */ public function widget($args, $instance): void { $raw = trim((string) ($instance['url'] ?? '')); if ($raw === '') { + if (current_user_can('manage_options')) { + echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + echo '
' . esc_html__('超级嵌入:', 'aksrt') . '' . + esc_html__('请配置 URL 或 iframe 代码', 'aksrt') . '
'; + echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + } return; } $aspect = max(20, min(300, (int) ($instance['aspect'] ?? 55))); @@ -55,9 +65,29 @@ class WidgetIframe extends \WP_Widget { 'title' => true, 'sandbox' => true, 'data-src' => true, + 'framespacing' => true, + 'border' => true, ], ] ); + // Prefer lazy: if iframe has src but no data-src, convert. + if (preg_match('/]*>/i', $iframe_html, $m) + && stripos($m[0], 'data-src=') === false + && preg_match('/\ssrc=["\']([^"\']+)["\']/i', $m[0], $sm) + ) { + $src = $sm[1]; + $tag = preg_replace('/\ssrc=["\'][^"\']*["\']/i', ' src="" data-src="' . esc_url($src) . '"', $m[0], 1); + if (is_string($tag) && stripos($tag, 'lazyload') === false) { + if (preg_match('/\sclass=["\']([^"\']*)["\']/', $tag)) { + $tag = preg_replace('/\sclass=["\']([^"\']*)["\']/', ' class="$1 lazyload aksrt-lazy"', $tag, 1); + } else { + $tag = preg_replace('/^'; + // zibll: class="lazyload" + data-src (not immediate src). + $iframe_html = ''; } - echo '
'; + // zibll shell: mb20 > wp-block-embed is-type-video relative-h radius8 > padding-bottom. + echo '
'; + echo '
'; echo '
'; echo $iframe_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped - echo '
'; + echo '
'; echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } + /** + * @param array $instance + */ public function form($instance): void { $title = (string) ($instance['title'] ?? ''); $url = (string) ($instance['url'] ?? ''); @@ -102,6 +138,11 @@ class WidgetIframe extends \WP_Widget { $new_instance + * @param array $old_instance + * @return array + */ public function update($new_instance, $old_instance): array { return [ 'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')),