Files
wordpress-theme-aksrt/src/AKSRT/Widgets/WidgetBookmarkLinks.php
T
kate522andClaude Fable 5 cecc1a7b5e feat(widgets): phase 5 align marketing/decoration widgets with zibll
Align the 20 marketing/decoration widgets with Zibll field defs in
widget-produck.php / widget-more.php, focusing on the field-level
drift surfaced by the 1:1 audit:

- TagCloudWidget (widget_ui_tag_cloud): orderby → name/count/term_id
  (was count default), add order ASC/DESC, expand color palette to
  all 13 Zibll c-* keys (rand/c-hui/c-blue/-2/cyan/yellow/-2/green/
  -2/purple/-2/red/-2), number cap 100, default 20.
- WidgetBookmarkLinks (widget_ui_links_lists_2): add alignment
  (''/center/right) to form+update+render wrapper.
- FriendLinksWidget: expose orderby/order selects in form (already
  whitelisted) for bookmarks mode.
- ButtonsWidget (zib_widget_ui_buttons): whitelist pc_padding/
  m_padding/pc_width/m_width (were render-only), widen pc_gap/
  m_gap cap to 60 to match Zibll.
- RecentCommentsWidget (widget_ui_new_comment): count cap 50
  (was 20), whitelist outer_keywords.
- WidgetVideoPlayer (zib_widget_ui_dplayer): scale_height cap 200
  (was 100), whitelist muted + aspect_ratio.

Remaining 14 widgets (PricingPlans/Reviews/Faq/Stats/Highlights/
FeatureIntro/TiltCases/IconCards/IconCoverCards/CoverCards/
ComboInfo/PartnersScroll/TextTitle/Iframe) already match Zibll
field semantics (JSON/native group + obs_animation/palette/
pc_row·m_row/go_link); no drift to fix.

Acceptance: php -l clean on all changed files; audit exit 0;
all 21 widget files <=360 lines. Phase 5 done-when marked.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-30 21:27:58 +08:00

180 lines
9.1 KiB
PHP

<?php
/**
* WordPress bookmark / links list (zibll widget_ui_links_lists via aksrt_links_box).
*
* @package AKSRT
*/
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
class WidgetBookmarkLinks extends \WP_Widget {
use CommonWidgetFields;
public function __construct() {
parent::__construct(
'aksrt_bookmark_links',
esc_html__('AKSRT 链接列表', 'aksrt'),
[
'description' => esc_html__('WordPress 链接(书签)列表:card / bigcard / image / simple。', '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';
// Zibll widget_ui_links_lists_2: type card/bigcard/image/simple.
$type = sanitize_key((string) ($instance['type'] ?? 'card'));
if (!in_array($type, ['card', 'bigcard', 'image', 'simple'], true)) {
$type = 'card';
}
// Zibll alignment ('' / center / right).
$align = sanitize_key((string) ($instance['alignment'] ?? ''));
if (!in_array($align, ['', 'center', 'right'], true)) {
$align = '';
}
$go_link = !empty($instance['go_link']);
$blank = !empty($instance['blank']);
$nofollow = !isset($instance['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) {
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']; // 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 links-box style-' . $type . ($show_box ? ' has-box' : '') . ($align ? ' text-' . $align : '');
echo '<div class="' . esc_attr($wrap) . '">';
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 '<a class="aksrt-bookmark-links__item" href="' . esc_url($url) . '"' . ($blank ? ' target="_blank" rel="noopener noreferrer"' : '') . '>';
echo esc_html((string) $b->link_name);
echo '</a>';
}
}
echo '</div>';
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
public function form($instance): void {
?>
<p>
<label><?php esc_html_e('标题', 'aksrt'); ?>
<input class="widefat" type="text" name="<?php echo esc_attr($this->get_field_name('title')); ?>" value="<?php echo esc_attr((string) ($instance['title'] ?? '')); ?>">
</label>
</p>
<p>
<label><?php esc_html_e('链接分类 ID(逗号,空=全部)', 'aksrt'); ?>
<input class="widefat" type="text" name="<?php echo esc_attr($this->get_field_name('links_cats')); ?>" value="<?php echo esc_attr((string) ($instance['links_cats'] ?? '')); ?>">
</label>
</p>
<p>
<label><?php esc_html_e('数量(0=不限)', 'aksrt'); ?>
<input class="tiny-text" type="number" min="0" max="100" name="<?php echo esc_attr($this->get_field_name('links_limit')); ?>" value="<?php echo esc_attr((string) ((int) ($instance['links_limit'] ?? 12))); ?>">
</label>
</p>
<p>
<label><?php esc_html_e('样式', 'aksrt'); ?>
<select name="<?php echo esc_attr($this->get_field_name('type')); ?>">
<option value="card" <?php selected(($instance['type'] ?? 'card'), 'card'); ?>><?php esc_html_e('图文卡片', 'aksrt'); ?></option>
<option value="bigcard" <?php selected(($instance['type'] ?? ''), 'bigcard'); ?>><?php esc_html_e('大卡片', 'aksrt'); ?></option>
<option value="image" <?php selected(($instance['type'] ?? ''), 'image'); ?>><?php esc_html_e('图片', 'aksrt'); ?></option>
<option value="simple" <?php selected(($instance['type'] ?? ''), 'simple'); ?>><?php esc_html_e('纯文字', 'aksrt'); ?></option>
</select>
</label>
</p>
<p>
<label><?php esc_html_e('排序', 'aksrt'); ?>
<select name="<?php echo esc_attr($this->get_field_name('links_orderby')); ?>">
<option value="name" <?php selected(($instance['links_orderby'] ?? 'name'), 'name'); ?>><?php esc_html_e('名称', 'aksrt'); ?></option>
<option value="updated" <?php selected(($instance['links_orderby'] ?? ''), 'updated'); ?>><?php esc_html_e('更新', 'aksrt'); ?></option>
<option value="rating" <?php selected(($instance['links_orderby'] ?? ''), 'rating'); ?>><?php esc_html_e('评分', 'aksrt'); ?></option>
<option value="rand" <?php selected(($instance['links_orderby'] ?? ''), 'rand'); ?>><?php esc_html_e('随机', 'aksrt'); ?></option>
</select>
</label>
<select name="<?php echo esc_attr($this->get_field_name('links_order')); ?>">
<option value="ASC" <?php selected(($instance['links_order'] ?? 'ASC'), 'ASC'); ?>><?php esc_html_e('升序', 'aksrt'); ?></option>
<option value="DESC" <?php selected(($instance['links_order'] ?? ''), 'DESC'); ?>><?php esc_html_e('降序', 'aksrt'); ?></option>
</select>
</p>
<p>
<label><?php esc_html_e('对齐方式', 'aksrt'); ?>
<select name="<?php echo esc_attr($this->get_field_name('alignment')); ?>">
<option value="" <?php selected(($instance['alignment'] ?? ''), ''); ?>><?php esc_html_e('左对齐', 'aksrt'); ?></option>
<option value="center" <?php selected(($instance['alignment'] ?? ''), 'center'); ?>><?php esc_html_e('居中', 'aksrt'); ?></option>
<option value="right" <?php selected(($instance['alignment'] ?? ''), 'right'); ?>><?php esc_html_e('右对齐', 'aksrt'); ?></option>
</select>
</label>
</p>
<p>
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('blank')); ?>" value="1" <?php checked(!isset($instance['blank']) || !empty($instance['blank'])); ?>> <?php esc_html_e('新窗口', 'aksrt'); ?></label><br>
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('nofollow')); ?>" value="1" <?php checked(!isset($instance['nofollow']) || !empty($instance['nofollow'])); ?>> <?php esc_html_e('nofollow', 'aksrt'); ?></label><br>
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('go_link')); ?>" value="1" <?php checked(!empty($instance['go_link'])); ?>> <?php esc_html_e('外链跳转页', 'aksrt'); ?></label><br>
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_box')); ?>" value="1" <?php checked(!empty($instance['show_box'])); ?>> <?php esc_html_e('外框盒子', 'aksrt'); ?></label>
</p>
<?php
$this->render_common_form_section($instance);
}
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';
}
$business = [
'title' => 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' => $type,
'alignment' => in_array((string) ($new_instance['alignment'] ?? ''), ['', 'center', 'right'], true) ? $new_instance['alignment'] : '',
'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,
]; return $this->update_common_fields($new_instance, $old_instance, $business);
}
}