*/ private static function type_labels(): array { return [ '' => __('随机', 'aksrt'), 'a' => __('动画', 'aksrt'), 'b' => __('漫画', 'aksrt'), 'c' => __('游戏', 'aksrt'), 'd' => __('文学', 'aksrt'), 'e' => __('原创', 'aksrt'), 'f' => __('来自网络', 'aksrt'), 'g' => __('其他', 'aksrt'), 'h' => __('影视', 'aksrt'), 'i' => __('诗词', 'aksrt'), 'j' => __('网易云', 'aksrt'), 'k' => __('哲学', 'aksrt'), 'l' => __('抖机灵', 'aksrt'), ]; } /** * Sanitize stored type to a valid Hitokoto category letter or empty. */ private static function sanitize_type(string $type): string { $type = strtolower(trim($type)); return preg_match('/^[a-l]$/', $type) ? $type : ''; } public function __construct() { parent::__construct( 'aksrt_yiyan', __('一言轮播', 'aksrt'), ['description' => __('显示随机一言/每日语录,支持自动轮播。', 'aksrt')] ); } public function widget($args, $instance): void { $title = !empty($instance['title']) ? $instance['title'] : ''; $count = !empty($instance['count']) ? max(1, min(10, (int) $instance['count'])) : 5; $interval = !empty($instance['interval']) ? max(3, min(30, (int) $instance['interval'])) : 5; $type = self::sanitize_type((string) ($instance['type'] ?? '')); $icon = !empty($instance['icon']) ? $instance['icon'] : 'fas fa-quote-left'; echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped if ($title) { echo $args['before_title'] . esc_html($title) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } if (function_exists('aksrt_render_yiyan_block')) { aksrt_render_yiyan_block([ 'class' => 'aksrt-yiyan', 'type' => $type, 'count' => $count, 'interval' => $interval, 'icon' => $icon, ]); } else { // Fallback if single-render helpers are not loaded. ?>