refactor(autoload): migrate theme classes to Composer PSR-4
Move 288 types from global AKSRT_* + inc/classes manual requires into
namespace AKSRT\{Domain} under src/AKSRT/, wire composer.json psr-4,
and slim bootstrap to helpers/modules/hooks only. Split multi-class
widget/gateway files, update admin contract audit paths, and document
the layout in ADR/README.
This commit is contained in:
1 parent
8f349b40fb
commit
aaf458af1c
404 files changed
+13602
-7705
No files matched your search
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
namespace AKSRT\Widgets;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class IconCardsWidget extends \WP_Widget {
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct('aksrt_icon_cards', esc_html__('AKSRT 图标卡片', 'aksrt'), [
|
||||
'description' => esc_html__('显示图标+文字卡片网格', 'aksrt'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function widget($args, $instance): void {
|
||||
echo $args['before_widget'];
|
||||
$title = apply_filters('widget_title', $instance['title'] ?? '', $instance, $this->id_base);
|
||||
$cards = isset($instance['cards']) && is_array($instance['cards']) ? $instance['cards'] : [];
|
||||
$columns = max(1, min(4, (int) ($instance['columns'] ?? 2)));
|
||||
|
||||
if ($title) echo $args['before_title'] . esc_html($title) . $args['after_title'];
|
||||
|
||||
if (!empty($cards)) : ?>
|
||||
<div class="widget-icon-cards" style="--ic-columns:<?php echo (int) $columns; ?>;">
|
||||
<?php foreach ($cards as $card) :
|
||||
$card_title = sanitize_text_field($card['title'] ?? '');
|
||||
$card_icon = sanitize_text_field($card['icon'] ?? '');
|
||||
$card_link = esc_url($card['link'] ?? '');
|
||||
$card_desc = sanitize_text_field($card['description'] ?? '');
|
||||
if ($card_title === '') continue;
|
||||
$tag = $card_link !== '' ? 'a' : 'div';
|
||||
$extra = $card_link !== '' ? ' href="' . $card_link . '" target="_blank" rel="noopener"' : '';
|
||||
?>
|
||||
<<?php echo $tag; ?> class="widget-icon-cards__item"<?php echo $extra; ?>>
|
||||
<?php if ($card_icon) : ?>
|
||||
<div class="widget-icon-cards__icon"><i class="<?php echo esc_attr($card_icon); ?>" aria-hidden="true"></i></div>
|
||||
<?php endif; ?>
|
||||
<div class="widget-icon-cards__text">
|
||||
<div class="widget-icon-cards__title"><?php echo esc_html($card_title); ?></div>
|
||||
<?php if ($card_desc) : ?>
|
||||
<div class="widget-icon-cards__desc"><?php echo esc_html($card_desc); ?></div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</<?php echo $tag; ?>>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif;
|
||||
|
||||
echo $args['after_widget'];
|
||||
}
|
||||
|
||||
public function form($instance): void {
|
||||
$cards = isset($instance['cards']) && is_array($instance['cards']) ? $instance['cards'] : [];
|
||||
while (count($cards) < 4) {
|
||||
$cards[] = ['title' => '', 'icon' => '', 'link' => '', 'description' => ''];
|
||||
}
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id('title'); ?>"><?php esc_html_e('标题(可选):', 'aksrt'); ?></label>
|
||||
<input class="widefat" type="text" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr($instance['title'] ?? ''); ?>">
|
||||
</p>
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id('columns'); ?>"><?php esc_html_e('列数:', 'aksrt'); ?></label>
|
||||
<input class="tiny-text" type="number" min="1" max="4" id="<?php echo $this->get_field_id('columns'); ?>" name="<?php echo $this->get_field_name('columns'); ?>" value="<?php echo (int) ($instance['columns'] ?? 2); ?>">
|
||||
</p>
|
||||
<hr>
|
||||
<?php foreach ($cards as $i => $card) : ?>
|
||||
<div style="border:1px solid #ddd;padding:6px;margin-bottom:6px;border-radius:4px;">
|
||||
<p style="margin:0 0 4px;"><input class="widefat" type="text" name="<?php echo $this->get_field_name("cards[{$i}][title]"); ?>" value="<?php echo esc_attr($card['title']); ?>" placeholder="<?php esc_attr_e('标题', 'aksrt'); ?>"></p>
|
||||
<p style="margin:0 0 4px;"><input class="widefat" type="text" name="<?php echo $this->get_field_name("cards[{$i}][icon]"); ?>" value="<?php echo esc_attr($card['icon']); ?>" placeholder="<?php esc_attr_e('图标类名 (如 fas fa-star)', 'aksrt'); ?>"></p>
|
||||
<p style="margin:0 0 4px;"><input class="widefat" type="text" name="<?php echo $this->get_field_name("cards[{$i}][description]"); ?>" value="<?php echo esc_attr($card['description']); ?>" placeholder="<?php esc_attr_e('描述(可选)', 'aksrt'); ?>"></p>
|
||||
<p style="margin:0;"><input class="widefat" type="url" name="<?php echo $this->get_field_name("cards[{$i}][link]"); ?>" value="<?php echo esc_attr($card['link']); ?>" placeholder="<?php esc_attr_e('链接(可选)', 'aksrt'); ?>"></p>
|
||||
</div>
|
||||
<?php endforeach;
|
||||
}
|
||||
|
||||
public function update($new_instance, $old_instance): array {
|
||||
$cards = [];
|
||||
if (isset($new_instance['cards']) && is_array($new_instance['cards'])) {
|
||||
foreach ($new_instance['cards'] as $card) {
|
||||
if (!is_array($card)) continue;
|
||||
$cards[] = [
|
||||
'title' => sanitize_text_field($card['title'] ?? ''),
|
||||
'icon' => sanitize_text_field($card['icon'] ?? ''),
|
||||
'link' => esc_url_raw($card['link'] ?? ''),
|
||||
'description' => sanitize_text_field($card['description'] ?? ''),
|
||||
];
|
||||
}
|
||||
}
|
||||
return [
|
||||
'title' => sanitize_text_field($new_instance['title'] ?? ''),
|
||||
'columns' => max(1, min(4, (int) ($new_instance['columns'] ?? 2))),
|
||||
'cards' => $cards,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user