diff --git a/assets/js/widget-set.js b/assets/js/widget-set.js index 8726220f..5ee91678 100644 --- a/assets/js/widget-set.js +++ b/assets/js/widget-set.js @@ -25,11 +25,15 @@ var orderby = tab.getAttribute('data-orderby') || 'date'; var cat = tab.getAttribute('data-cat') || '0'; var tabCount = tab.getAttribute('data-tab-count') || '0'; + var style = widget.getAttribute('data-style') || 'mini'; + var paginate = widget.getAttribute('data-paginate') || 'none'; var qs = new URLSearchParams({ count: defaultCount, orderby: orderby, cat: cat, tab_count: tabCount, + style: style, + paginate: paginate, }); var url = rest + (rest.indexOf('?') > -1 ? '&' : '?') + qs.toString(); panel.classList.add('is-ajax-loading'); @@ -42,7 +46,8 @@ .then(function (j) { var d = (j && j.data) || j || {}; var html = d.html || ''; - panel.innerHTML = html || '
'; + var pag = d.paginate_html || d.paginateHtml || ''; + panel.innerHTML = (html || '') + (pag || ''); panel.setAttribute('data-loaded', '1'); panel.classList.remove('is-ajax-loading'); }) diff --git a/inc/helpers/aksrt-ajax-list.php b/inc/helpers/aksrt-ajax-list.php index f870ef22..9013a057 100644 --- a/inc/helpers/aksrt-ajax-list.php +++ b/inc/helpers/aksrt-ajax-list.php @@ -109,3 +109,83 @@ if (!function_exists('aksrt_get_remote_modal_link')) { return '<' . $tag . $attrs . '>' . esc_html($text) . '' . $tag . '>'; } } + +if (!function_exists('aksrt_get_ajax_number_paginate')) { + /** + * Numbered AJAX pager (zibll zib_get_ajax_number_paginate subset). + * + * Links use class next-page ajax-next + ajax-replace so ajax-list.js + * replaces .ajax-item rows inside the nearest .ajaxpager. + * + * @param int $count_all Total items. + * @param int $page Current page (1-based). + * @param int $per_page Per page. + * @param string $ajax_url Base REST/URL (page query key replaced). + * @param string $pag_class Wrapper class. + * @param string $next_class Link base class. + * @param string $query_key Page query arg (default page). + */ + function aksrt_get_ajax_number_paginate( + int $count_all, + int $page = 1, + int $per_page = 10, + string $ajax_url = '', + string $pag_class = 'ajax-pag', + string $next_class = 'next-page ajax-next', + string $query_key = 'page' + ): string { + $page = max(1, $page); + $per_page = max(1, $per_page); + $total_pages = (int) ceil(max(0, $count_all) / $per_page); + if ($total_pages < 2 || $count_all <= 0) { + return ''; + } + + $base = $ajax_url !== '' ? $ajax_url : '#'; + // Ensure %#% placeholder for page numbers. + if (strpos($base, '%#%') === false) { + $base = add_query_arg($query_key, '%#%', $base); + } + + $end_size = 1; + $mid_size = 2; + $links = []; + $dots = false; + + // Prev. + if ($page > 1) { + $url = esc_url(str_replace('%#%', (string) ($page - 1), $base)); + $links[] = ''; + } + + for ($n = 1; $n <= $total_pages; $n++) { + $in_window = $n <= $end_size + || $n > $total_pages - $end_size + || ($n >= $page - $mid_size && $n <= $page + $mid_size); + if (!$in_window) { + if ($dots) { + continue; + } + $links[] = '…'; + $dots = true; + continue; + } + $dots = false; + if ($n === $page) { + $links[] = '' . (int) $n . ''; + } else { + $url = esc_url(str_replace('%#%', (string) $n, $base)); + $links[] = '' . (int) $n . ''; + } + } + + // Next. + if ($page < $total_pages) { + $url = esc_url(str_replace('%#%', (string) ($page + 1), $base)); + $links[] = ''; + } + + return '+ +
++ +
+ +
++
@@ -304,9 +402,13 @@ class WidgetMainPosts extends \WP_Widget { $style = 'list'; } $orderby = sanitize_key((string) ($new_instance['orderby'] ?? 'date')); - if (!in_array($orderby, ['date', 'modified', 'views', 'comments', 'likes', 'rand'], true)) { + if (!in_array($orderby, ['date', 'modified', 'views', 'comments', 'likes', 'favorites', 'downloads', 'rand'], true)) { $orderby = 'date'; } + $paginate = sanitize_key((string) ($new_instance['paginate'] ?? 'none')); + if (!in_array($paginate, ['none', 'ajax', 'number'], true)) { + $paginate = 'none'; + } return [ 'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')), 'count' => max(1, min(30, (int) ($new_instance['count'] ?? 6))), @@ -314,7 +416,9 @@ class WidgetMainPosts extends \WP_Widget { 'orderby' => $orderby, 'cat' => max(0, (int) ($new_instance['cat'] ?? 0)), 'limit_day' => max(0, (int) ($new_instance['limit_day'] ?? 0)), - 'paginate' => sanitize_key((string) ($new_instance['paginate'] ?? 'none')) === 'ajax' ? 'ajax' : 'none', + 'topics' => sanitize_text_field((string) ($new_instance['topics'] ?? '')), + 'pay_type' => sanitize_key((string) ($new_instance['pay_type'] ?? '')), + 'paginate' => $paginate, 'show_thumb' => !empty($new_instance['show_thumb']) ? 1 : 0, 'show_meta' => !empty($new_instance['show_meta']) ? 1 : 0, 'show_number' => !empty($new_instance['show_number']) ? 1 : 0, diff --git a/src/AKSRT/Widgets/WidgetProductList.php b/src/AKSRT/Widgets/WidgetProductList.php index 10cceac7..c9c67078 100644 --- a/src/AKSRT/Widgets/WidgetProductList.php +++ b/src/AKSRT/Widgets/WidgetProductList.php @@ -189,14 +189,32 @@ class WidgetProductList extends \WP_Widget { $paginate_html = '