From af8f97ad3c39ffe85bbd1ebbe706461aa70e675b Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 21 Jul 2026 08:36:00 +0800 Subject: [PATCH] feat(widgets): BookmarkLinks via aksrt_links_box bigcard/popover Delegate render to shared links helper for card/bigcard/image/simple styles, popover data attrs, empty admin guidance. --- src/AKSRT/Widgets/WidgetBookmarkLinks.php | 67 +++++++++++------------ 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/src/AKSRT/Widgets/WidgetBookmarkLinks.php b/src/AKSRT/Widgets/WidgetBookmarkLinks.php index e3d900e0..ad69399c 100644 --- a/src/AKSRT/Widgets/WidgetBookmarkLinks.php +++ b/src/AKSRT/Widgets/WidgetBookmarkLinks.php @@ -1,6 +1,6 @@ esc_html__('WordPress 链接(书签)列表,适合友链/导航。', 'aksrt'), + 'description' => esc_html__('WordPress 链接(书签)列表:card / bigcard / image / simple。', 'aksrt'), 'classname' => 'widget_aksrt_bookmark_links', ] ); @@ -30,12 +30,12 @@ class WidgetBookmarkLinks extends \WP_Widget { } $order = strtoupper((string) ($instance['links_order'] ?? 'ASC')) === 'DESC' ? 'DESC' : 'ASC'; $type = sanitize_key((string) ($instance['type'] ?? 'card')); - if (!in_array($type, ['card', 'image', 'simple'], true)) { + if (!in_array($type, ['card', 'bigcard', 'image', 'simple'], true)) { $type = 'card'; } $go_link = !empty($instance['go_link']); $blank = !isset($instance['blank']) || !empty($instance['blank']); - $nofollow = !empty($instance['nofollow']); + $nofollow = !isset($instance['nofollow']) || !empty($instance['nofollow']); $show_box = !empty($instance['show_box']); $bm_args = [ @@ -49,6 +49,13 @@ class WidgetBookmarkLinks extends \WP_Widget { } $bookmarks = get_bookmarks($bm_args); if (!$bookmarks) { + 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 + : '

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

'; + echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + } return; } @@ -58,37 +65,22 @@ class WidgetBookmarkLinks extends \WP_Widget { echo $args['before_title'] . esc_html($title) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } - $wrap = 'aksrt-bookmark-links style-' . $type . ($show_box ? ' has-box' : ''); + $wrap = 'aksrt-bookmark-links links-box style-' . $type . ($show_box ? ' has-box' : ''); echo '
'; - foreach ($bookmarks as $b) { - $url = (string) $b->link_url; - if ($url !== '' && $go_link && function_exists('aksrt_go_link')) { - $url = aksrt_go_link($url, true); + if (function_exists('aksrt_links_box')) { + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + echo aksrt_links_box($bookmarks, $type, $nofollow, $go_link, $blank); + } else { + // Minimal fallback. + foreach ($bookmarks as $b) { + $url = (string) $b->link_url; + if ($url !== '' && $go_link && function_exists('aksrt_go_link')) { + $url = aksrt_go_link($url, true); + } + echo ''; + echo esc_html((string) $b->link_name); + echo ''; } - $rel = []; - if ($nofollow) { - $rel[] = 'nofollow'; - } - if ($blank) { - $rel[] = 'noopener'; - $rel[] = 'noreferrer'; - } - $rel_attr = $rel ? ' rel="' . esc_attr(implode(' ', $rel)) . '"' : ''; - $tgt = $blank ? ' target="_blank"' : ''; - $img = (string) $b->link_image; - $name = (string) $b->link_name; - $desc = (string) $b->link_description; - - echo ''; - if ($type !== 'simple' && $img !== '') { - echo ''; - } - echo ''; - echo '' . esc_html($name) . ''; - if ($type === 'card' && $desc !== '') { - echo '' . esc_html($desc) . ''; - } - echo ''; } echo '
'; @@ -116,6 +108,7 @@ class WidgetBookmarkLinks extends \WP_Widget {