esc_html__('WordPress 链接(书签)列表,适合友链/导航。', 'aksrt'), 'classname' => 'widget_aksrt_bookmark_links', ] ); } public function widget($args, $instance): void { $limit = max(0, min(100, (int) ($instance['links_limit'] ?? 12))); $orderby = sanitize_key((string) ($instance['links_orderby'] ?? 'name')); if (!in_array($orderby, ['name', 'updated', 'rating', 'rand', 'id'], true)) { $orderby = 'name'; } $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)) { $type = 'card'; } $go_link = !empty($instance['go_link']); $blank = !isset($instance['blank']) || !empty($instance['blank']); $nofollow = !empty($instance['nofollow']); $show_box = !empty($instance['show_box']); $bm_args = [ 'orderby' => $orderby === 'rand' ? 'rand' : $orderby, 'order' => $order, 'limit' => $limit > 0 ? $limit : -1, ]; $cats = trim((string) ($instance['links_cats'] ?? '')); if ($cats !== '' && $cats !== 'all') { $bm_args['category'] = $cats; } $bookmarks = get_bookmarks($bm_args); if (!$bookmarks) { return; } echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $title = apply_filters('widget_title', (string) ($instance['title'] ?? ''), $instance, $this->id_base); if ($title !== '') { 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' : ''); 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); } $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 '
'; echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } public function form($instance): void { ?>




sanitize_text_field((string) ($new_instance['title'] ?? '')), 'links_cats' => sanitize_text_field((string) ($new_instance['links_cats'] ?? '')), 'links_limit' => max(0, min(100, (int) ($new_instance['links_limit'] ?? 12))), 'links_orderby' => sanitize_key((string) ($new_instance['links_orderby'] ?? 'name')), 'links_order' => strtoupper((string) ($new_instance['links_order'] ?? 'ASC')) === 'DESC' ? 'DESC' : 'ASC', 'type' => in_array(($new_instance['type'] ?? ''), ['card', 'image', 'simple'], true) ? $new_instance['type'] : 'card', '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, ]; } }