'; } private static function render_posts_toc(array $i): string { if (!is_singular('post')) { return ''; } return ''; } private static function render_quote(array $i): string { $quotes = RendererHelpers::lines((string) $i['quotes']); $text = $quotes ? $quotes[array_rand($quotes)] : __('保持好奇,持续创造。', 'aksrt'); return '
' . esc_html($text) . '
'; } private static function render_icon_cards(array $i): string { return self::icon_cards($i, false); } private static function render_icon_cover_cards(array $i): string { return self::icon_cards($i, true); } private static function icon_cards(array $instance, bool $cover): string { $pc = max(1, (int) ($instance['pc_row'] ?? 4)); $mobile = max(1, (int) ($instance['m_row'] ?? 2)); $cards = (array) ($instance['cards'] ?? []); $is_row = count($cards) > 1; $row_class = 'col-sm-' . max(1, (int) (12 / $pc)); if ($mobile > 1) $row_class .= ' col-xs-' . max(1, (int) (12 / $mobile)); $items = ''; foreach ($cards as $card) { if (!is_array($card)) { continue; } $icon_size = !$cover && !empty($instance['size']) ? 16 + (int) $instance['size'] : ($cover ? 25 : 0); $class = $cover ? (!empty($instance['show_widget_bg']) ? 'padding-10' : 'zib-widget mb10') : (!empty($instance['show_widget_bg']) ? 'box-body nopw-sm' : 'mb20'); $args = [ 'icon' => $card['icon'] ?? '', 'customize_icon' => $card['customize_icon'] ?? '', 'icon_size' => $icon_size, 'icon_radius' => !empty($card['icon_radius']) || ($cover && !empty($instance['icon_radius4'])), 'icon_color' => $card['icon_color'] ?? '', 'icon_custom_color' => $card['icon_custom_color'] ?? '', 'icon_class' => $card['icon_class'] ?? '', 'title' => $card['title'] ?? '', 'desc' => $card['desc'] ?? '', 'link' => $card['link'] ?? [], 'class' => $class, ]; $item = ''; if ($cover && function_exists('aksrt_icon_cover_card')) { $item = aksrt_icon_cover_card($args); } elseif (!$cover && function_exists('aksrt_icon_card')) { $item = aksrt_icon_card($args); } else { $item = ''; } $items .= $is_row ? '
' . $item . '
' : $item; } if ($items === '') return ''; $inner = $is_row ? '
' . $items . '
' : $items; if ($cover) return '
' . $inner . '
'; return '
' . (!empty($instance['show_widget_bg']) ? '
' : '') . $inner . (!empty($instance['show_widget_bg']) ? '
' : '') . '
'; } private static function render_video(array $i): string { $url = esc_url((string) $i['url']); if ($url === '') { return RendererHelpers::empty_state(__('请配置视频地址', 'aksrt')); } $ratio = (string) $i['ratio']; if (aksrt_is_lazy('lazy_other')) { $video_attr = ' class="lazyload" src="" data-src="' . $url . '"'; $poster_attr = !empty($i['poster']) ? ' data-poster="' . esc_url((string) $i['poster']) . '"' : ''; } else { $video_attr = ' src="' . $url . '"'; $poster_attr = !empty($i['poster']) ? ' poster="' . esc_url((string) $i['poster']) . '"' : ''; } return '
'; } private static function render_embed(array $i): string { if (empty($i['url'])) { return RendererHelpers::empty_state(__('请配置嵌入地址', 'aksrt')); } $src_attr = aksrt_is_lazy('lazy_other') ? ' class="lazyload" src="" data-src="' . esc_url((string) $i['url']) . '"' : ' src="' . esc_url((string) $i['url']) . '"'; return '
'; } private static function render_media_cards(array $i): string { return self::media_grid((array) $i['cards']); } private static function media_grid(array $items, string $class = ''): string { $html = '
'; foreach ($items as $item) { if (is_array($item)) { $html .= RendererHelpers::card_media($item); } } return $html . '
'; } private static function render_partners(array $i): string { $items = ''; foreach ((array) $i['items'] as $item) { if (is_array($item)) { $items .= RendererHelpers::card_media($item, 'aksrt-partner'); } } return '
' . $items . $items . '
'; } private static function render_combo_info(array $i): string { $html = '
'; foreach ((array) $i['items'] as $item) { if (!is_array($item)) { continue; } $tags = ''; foreach (preg_split('/\s*[,,]\s*/', (string) ($item['tags'] ?? '')) ?: [] as $tag) { if ($tag !== '') { $tags .= '' . esc_html($tag) . ''; } } $html .= '
' . RendererHelpers::card_media($item) . ($tags ? '
' . $tags . '
' : '') . '
'; } return $html . '
'; } private static function render_text_title(array $i): string { return '

' . nl2br(esc_html((string) $i['heading'])) . '

' . nl2br(esc_html((string) $i['description'])) . '

'; } private static function render_buttons(array $i): string { $padding_pc = in_array((string) ($i['pc_padding'] ?? 'large'), ['small', 'medium', 'large'], true) ? (string) $i['pc_padding'] : 'large'; $padding_m = in_array((string) ($i['m_padding'] ?? 'medium'), ['small', 'medium', 'large'], true) ? (string) $i['m_padding'] : 'medium'; $align = in_array((string) ($i['align'] ?? 'center'), ['left', 'center', 'right'], true) ? (string) $i['align'] : 'center'; $style = ''; foreach (['pc_width' => '--pc-width', 'm_width' => '--m-width', 'pc_gap' => '--pc-gap', 'm_gap' => '--m-gap'] as $key => $property) { if (!empty($i[$key]) && is_numeric($i[$key])) $style .= $property . ':' . (float) $i[$key] . 'px;'; } $button_class = 'but' . (!empty($i['radius']) ? ' radius' : '') . (!empty($i['hollow']) ? ' hollow' : ''); $buttons = ''; foreach ((array) ($i['items'] ?? []) as $index => $item) { if (!is_array($item) || trim((string) ($item['text'] ?? '')) === '') continue; $link = RendererHelpers::link((array) ($item['link'] ?? [])); $url = $link['url'] !== '' ? $link['url'] : 'javascript:void(0)'; if (!empty($i['go_link']) && $link['url'] !== '' && function_exists('aksrt_go_link')) $url = esc_url(aksrt_go_link($link['url'], true)); $target = $link['target'] === '_blank' ? ' target="_blank" rel="noopener noreferrer"' : ''; $color = sanitize_html_class((string) ($item['color'] ?? '')); $item_class = trim($button_class . ' ' . $color); $icon_left = !empty($item['icon_left']) ? self::icon_markup((string) $item['icon_left']) : ''; $icon_right = !empty($item['icon_right']) ? '' . self::icon_markup((string) $item['icon_right']) . '' : ''; $animation = ''; $attr = ''; if (!empty($i['obs_animation'])) { $animation = ' obs-animate ani-' . sanitize_html_class((string) $i['obs_animation']); $attr = ' data-animation="' . esc_attr((string) $i['obs_animation']) . '" style="--delay:' . (float) $index * 0.15 . 's;"' . (!empty($i['animation_repeat']) ? ' data-animation-repeat="true"' : ''); } $buttons .= '
' . $icon_left . wp_kses_post((string) $item['text']) . $icon_right . '
'; } if ($buttons === '') return ''; return '
' . $buttons . '
'; } private static function render_layout_gap(array $i): string { return ''; } private static function render_tag_cloud(array $i): string { $args = ['taxonomy' => (string) $i['taxonomy'], 'number' => (int) $i['number'], 'hide_empty' => true]; if ($i['orderby'] !== 'rand') { $args['orderby'] = (string) $i['orderby']; $args['order'] = 'DESC'; } $terms = get_terms($args); if (is_wp_error($terms) || !$terms) { return RendererHelpers::empty_state(__('暂无标签', 'aksrt')); } if ($i['orderby'] === 'rand') { shuffle($terms); } $html = '
'; foreach (array_slice($terms, 0, (int) $i['number']) as $term) { $url = get_term_link($term); if (!is_wp_error($url)) { $html .= '' . esc_html($term->name) . (!empty($i['show_count']) ? '' . (int) $term->count . '' : '') . ''; } } return $html . '
'; } private static function render_recent_comments(array $i): string { $comments = get_comments(['status' => 'approve', 'number' => (int) $i['count'], 'user__not_in' => RendererHelpers::ids((string) $i['exclude_users']), 'post__not_in' => RendererHelpers::ids((string) $i['exclude_posts'])]); if (!$comments) { return RendererHelpers::empty_state(__('暂无评论', 'aksrt')); } $html = ''; } private static function render_links(array $i): string { $html = ''; } private static function render_notice(array $i): string { $source = (string) ($i['source'] ?? ''); $lists = (array) ($i['img_ids'] ?? []); $posts_query = false; if ($source === 'posts' && class_exists(PostQuery::class)) { $query_args = array_merge((array) ($i['posts_opts'] ?? []), ['count' => (int) ($i['count'] ?? 8), 'paginate' => '']); $posts_query = PostQuery::build($query_args, 1); $lists = []; if ($posts_query && method_exists($posts_query, 'have_posts')) { while ($posts_query->have_posts()) { $posts_query->the_post(); $subtitle = class_exists('AKSRT\\Core\\PostMetaBox') ? \AKSRT\Core\PostMetaBox::get_meta_value(get_the_ID(), 'subtitle', '') : ''; $title = trim(wp_strip_all_tags(get_the_title())) . trim(wp_strip_all_tags((string) $subtitle)); if (!empty($i['desc_s'])) { $description = class_exists('AKSRT\\Core\\PostMetaBox') ? \AKSRT\Core\PostMetaBox::get_meta_value(get_the_ID(), 'description', '') : ''; if (trim((string) $description) === '') $description = get_the_excerpt(); $title .= ': ' . wp_html_excerpt(wp_strip_all_tags((string) $description), 160, '...'); } $lists[] = ['title' => $title, 'href' => get_permalink()]; } wp_reset_postdata(); } } $msg_icon = ($posts_query && !empty($i['msg_icon'])) ? self::notice_icon((string) $i['msg_icon']) : ''; $slides = ''; $blank = !empty($i['blank']) ? ' target="_blank" rel="noopener noreferrer"' : ''; foreach ($lists as $notice) { if (!is_array($notice) || trim((string) ($notice['title'] ?? '')) === '') continue; $href = !empty($notice['href']) ? esc_url((string) $notice['href']) : 'javascript:void(0);'; $icon = !empty($notice['icon']) ? self::notice_icon((string) $notice['icon']) : ''; $title = wp_kses_post((string) ($notice['title'] ?? '')); $slides .= '
' . $icon . '' . $title . '
'; } $class = 'swiper-bulletin mb20 ' . sanitize_html_class((string) ($i['color'] ?? 'c-blue')) . (!empty($i['radius']) ? ' radius' : ' main-radius') . ($posts_query ? ' has-posts flex ac' : ''); $html = '
' . $slides . '
'; return '
' . $msg_icon . $html . '
'; } private static function notice_icon(string $icon): string { return '' . self::icon_markup($icon) . ''; } private static function icon_markup(string $icon): string { $icon = trim($icon); if ($icon === '') return ''; if (str_starts_with($icon, 'customsvg-')) { return wp_kses(substr($icon, 10), [ 'svg' => ['class' => true, 'viewbox' => true, 'viewBox' => true, 'width' => true, 'height' => true, 'fill' => true, 'xmlns' => true, 'aria-hidden' => true], 'use' => ['href' => true, 'xlink:href' => true], 'path' => ['d' => true, 'fill' => true, 'stroke' => true, 'stroke-width' => true], ]); } if (str_starts_with($icon, 'zibsvg-')) return ''; if (!str_contains($icon, 'fa ') && str_contains($icon, 'fa-')) $icon = 'fa ' . $icon; return ''; } }