对小工具进行了一些修复
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace AKSRT\WidgetSystem\Renderers;
|
||||
|
||||
use AKSRT\WidgetSystem\RendererHelpers;
|
||||
use AKSRT\WidgetSystem\PostQuery;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
@@ -156,15 +157,35 @@ final class GeneralRenderer {
|
||||
}
|
||||
|
||||
private static function render_buttons(array $i): string {
|
||||
$html = '<div class="aksrt-widget-buttons is-' . esc_attr((string) $i['alignment']) . '" style="--aksrt-button-gap:' . (float) $i['gap'] . 'px">';
|
||||
foreach ((array) $i['buttons'] as $button) {
|
||||
$link = RendererHelpers::link((array) ($button['link'] ?? []));
|
||||
if ($link['url'] === '') {
|
||||
continue;
|
||||
}
|
||||
$html .= '<a class="aksrt-widget-button ' . esc_attr((string) ($button['color'] ?? 'jb-blue')) . '" href="' . $link['url'] . '"' . RendererHelpers::link_attrs($link) . '>' . (!empty($button['icon']) ? '<i class="' . esc_attr((string) $button['icon']) . '" aria-hidden="true"></i>' : '') . '<span>' . esc_html((string) ($button['text'] ?? $link['text'])) . '</span></a>';
|
||||
$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;';
|
||||
}
|
||||
return $html . '</div>';
|
||||
$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']) ? '<span class="ml6">' . self::icon_markup((string) $item['icon_right']) . '</span>' : '';
|
||||
$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 .= '<div class="' . trim($animation) . '"' . $attr . '><a class="' . esc_attr($item_class) . '" href="' . $url . '"' . $target . '>' . $icon_left . wp_kses_post((string) $item['text']) . $icon_right . '</a></div>';
|
||||
}
|
||||
if ($buttons === '') return '';
|
||||
return '<div class="widget-buttons mb20 pc-size-' . esc_attr($padding_pc) . ' m-size-' . esc_attr($padding_m) . '"><div class="widget-buttons-wrap flex hh align-' . esc_attr($align) . '" style="' . esc_attr($style) . '">' . $buttons . '</div></div>';
|
||||
}
|
||||
|
||||
private static function render_layout_gap(array $i): string {
|
||||
@@ -218,12 +239,82 @@ final class GeneralRenderer {
|
||||
}
|
||||
|
||||
private static function render_notice(array $i): string {
|
||||
$slides = '';
|
||||
foreach ((array) $i['items'] as $item) {
|
||||
$link = RendererHelpers::link((array) ($item['link'] ?? []));
|
||||
$content = '<strong>' . esc_html((string) ($item['title'] ?? '')) . '</strong><span>' . esc_html((string) ($item['description'] ?? '')) . '</span>';
|
||||
$slides .= '<div class="swiper-slide">' . ($link['url'] ? '<a href="' . $link['url'] . '"' . RendererHelpers::link_attrs($link) . '>' . $content . '</a>' : $content) . '</div>';
|
||||
$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();
|
||||
}
|
||||
} elseif ($source === 'forums' && function_exists('zib_bbs_get_posts_query') && (!function_exists('_pz') || _pz('bbs_s'))) {
|
||||
$query_args = (array) ($i['forums_opts'] ?? []);
|
||||
$query_args['plate'] = $query_args['plate'] ?? 0;
|
||||
$query_args['paged_size'] = (int) ($i['count'] ?? 8);
|
||||
$query_args['paged'] = 1;
|
||||
$query_args['no_found_rows'] = true;
|
||||
$posts_query = zib_bbs_get_posts_query($query_args);
|
||||
$lists = [];
|
||||
if ($posts_query && method_exists($posts_query, 'have_posts')) {
|
||||
while ($posts_query->have_posts()) {
|
||||
$posts_query->the_post();
|
||||
$post_id = get_the_ID();
|
||||
$subtitle = class_exists('AKSRT\\Core\\PostMetaBox') ? \AKSRT\Core\PostMetaBox::get_meta_value($post_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($post_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();
|
||||
}
|
||||
}
|
||||
return '<div class="aksrt-widget-notice"><i class="fa fas fa-bullhorn" aria-hidden="true"></i><div class="new-swiper aksrt-widget-swiper" data-aksrt-swiper="notice" data-direction="vertical" data-loop="true" data-autoplay="1" data-interval="' . ((int) $i['interval'] * 1000) . '"><div class="swiper-wrapper">' . $slides . '</div></div></div>';
|
||||
$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 .= '<div class="swiper-slide notice-slide"><a class="flex ac"' . $blank . ' href="' . $href . '">' . $icon . '<span class="ml6 text-ellipsis"><span class="">' . $title . '</span></span></a></div>';
|
||||
}
|
||||
$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 = '<div class="new-swiper" data-interval="' . ((int) ($i['interval'] ?? 3) * 1000) . '" data-direction="vertical" data-loop="true" data-autoplay="1"><div class="swiper-wrapper">' . $slides . '</div></div>';
|
||||
return '<div class="' . esc_attr($class) . '">' . $msg_icon . $html . '</div>';
|
||||
}
|
||||
|
||||
private static function notice_icon(string $icon): string {
|
||||
return '<span class="relative bulletin-icon flex jc shrink0">' . self::icon_markup($icon) . '</span>';
|
||||
}
|
||||
|
||||
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 '<svg class="icon" aria-hidden="true"><use xlink:href="#icon-' . esc_attr(substr($icon, 7)) . '"></use></svg>';
|
||||
if (!str_contains($icon, 'fa ') && str_contains($icon, 'fa-')) $icon = 'fa ' . $icon;
|
||||
return '<i class="' . esc_attr($icon) . '" aria-hidden="true"></i>';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user