(string) $widget->id, 'id_base' => $definition->id_base(), ]; $content = RendererRegistry::render($definition->renderer(), $instance, $context); if ($content === '' && $definition->slug() !== 'layout_gap') { return; } AssetManager::enqueue_for($definition); if (in_array($definition->slug(), ['post_pay', 'tab_posts', 'slider', 'slider_media_combo', 'icon_cards', 'icon_cover_cards', 'buttons', 'notice'], true)) { echo (string) ($args['before_widget'] ?? ''); if ($definition->slug() !== 'post_pay') echo self::reference_title($instance); echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo (string) ($args['after_widget'] ?? ''); return; } $classes = ['aksrt-widget', 'aksrt-panel-wrap', 'aksrt-widget--' . $definition->slug(), 'aksrt-widget--' . $definition->size()]; if ($definition->size() === 'sidebar' && $definition->slug() !== 'user_card') { $classes[] = 'aksrt-panel'; } $device_class = WidgetVisibility::device_class($instance); if ($device_class !== '') { $classes[] = $device_class; } if (!empty($instance['sidebar_affix'])) { $classes[] = 'aksrt-widget--affix'; } if (!empty($instance['animation_in'])) { $classes[] = 'aksrt-widget--animate'; $classes[] = 'aksrt-widget--animate-' . sanitize_html_class((string) $instance['animation_in']); } if (!empty($instance['animation_repeat'])) { $classes[] = 'aksrt-widget--animate-repeat'; } $style = self::style($instance); echo (string) ($args['before_widget'] ?? '
'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo '
'; if ($definition->size() !== 'sidebar') { echo '
'; } echo self::title($instance); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo '
' . $content . '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped if ($definition->size() !== 'sidebar') { echo '
'; } echo '
'; echo (string) ($args['after_widget'] ?? '
'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } private static function title(array $instance): string { $title = trim((string) ($instance['title'] ?? '')); if ($title === '') { return ''; } $safe_title = wp_kses_post($title); $highlight = trim((string) ($instance['title_highlight'] ?? '')); if ($highlight !== '') { $safe_highlight = esc_html($highlight); $safe_title = str_replace($safe_highlight, '' . $safe_highlight . '', $safe_title); } $html = '

' . nl2br($safe_title) . '

'; if (!empty($instance['subtitle'])) { $html .= '

' . nl2br(wp_kses_post((string) $instance['subtitle'])) . '

'; } $html .= '
'; } private static function reference_title(array $instance): string { $title = trim((string) ($instance['title'] ?? '')); if ($title === '') return ''; $title = wp_kses_post($title); $highlight = trim((string) ($instance['title_highlight'] ?? '')); if ($highlight !== '') $title = str_replace(esc_html($highlight), '' . esc_html($highlight) . '', $title); $subtitle = !empty($instance['subtitle']) ? wp_kses_post((string) $instance['subtitle']) : ''; if (($instance['title_style'] ?? '') === 'big') { $links = ''; foreach (['title_link', 'title_link2', 'title_link3'] as $index => $key) { $link = RendererHelpers::link((array) ($instance[$key] ?? [])); if ($link['url'] && $link['text']) $links .= '' . esc_html($link['text']) . ''; } return '

' . $title . '

' . ($subtitle ? '

' . $subtitle . '

' : '') . ($links ? '
' . $links . '
' : '') . '
'; } $link = RendererHelpers::link((array) ($instance['title_link'] ?? [])); $more = $link['url'] ? '
' . esc_html($link['text'] ?: __('更多', 'aksrt')) . '
' : ''; return '
' . $title . ($subtitle ? '' . $subtitle . '' : '') . $more . '
'; } private static function style(array $instance): string { $properties = []; foreach (['layout_pin_pc' => 'space', 'layout_pin_m' => 'space-m'] as $key => $prefix) { foreach (['top', 'right', 'bottom', 'left'] as $edge) { $value = $instance[$key][$edge] ?? ''; if ($value !== '' && is_numeric($value)) { $properties[] = '--aksrt-widget-' . $prefix . '-' . $edge . ':' . (float) $value . 'px'; } } } foreach (['light', 'dark'] as $mode) { $background = (array) ($instance['layout_bg'][$mode] ?? []); if (!empty($background['color'])) { $properties[] = '--aksrt-widget-bg-' . $mode . ':' . (string) $background['color']; } if (!empty($background['image'])) { $properties[] = '--aksrt-widget-bg-image-' . $mode . ':url(' . esc_url_raw((string) $background['image']) . ')'; } } return implode(';', $properties); } }