' . '

' . esc_html((string) $text) . '

'; } } if (!function_exists('aksrt_get_ajax_next_paginate')) { /** * Load-more style paginate block (legacy subset). * * @param int $count_all Total items. * @param int $page Current page (1-based). * @param int $per_page Per page. * @param string $ajax_url Next page URL (full or REST). * @param string $pag_class Wrapper class. * @param string $next_class Link class. * @param string $label Button label. */ function aksrt_get_ajax_next_paginate( int $count_all, int $page = 1, int $per_page = 10, string $ajax_url = '', string $pag_class = 'text-center theme-pagination ajax-pag', string $next_class = 'next-page ajax-next', string $label = '' ): string { $page = max(1, $page); $per_page = max(1, $per_page); $max = (int) ceil($count_all / $per_page); if ($page >= $max || $count_all <= 0) { return '
'; } if ($label === '') { $label = __('加载更多', 'aksrt'); } $next = $page + 1; $url = $ajax_url !== '' ? $ajax_url : '#'; // Prefer caller-provided URL already containing next page. return '
' . '
' . '' . esc_html($label) . '
'; } } if (!function_exists('aksrt_get_modal_link')) { /** * Build a declarative modal runtime trigger. * * @param array{ * tag?:string,class?:string,text?:string,url?:string, * data_class?:string,height?:int,mobile_bottom?:bool, * query_arg?:array * } $args */ function aksrt_get_modal_link(array $args = []): string { $tag = sanitize_key((string) ($args['tag'] ?? 'a')); if (!in_array($tag, ['a', 'button', 'span'], true)) { $tag = 'a'; } $class = trim((string) ($args['class'] ?? '')); $text = (string) ($args['text'] ?? __('打开', 'aksrt')); $url = (string) ($args['url'] ?? ''); if ($url === '' && !empty($args['query_arg']) && is_array($args['query_arg'])) { // Prefer REST absolute URL if provided via action helper. $url = add_query_arg($args['query_arg'], admin_url('admin-ajax.php')); } $data_class = (string) ($args['data_class'] ?? 'modal-mini full-sm'); $height = isset($args['height']) ? (int) $args['height'] : 0; $mobile = !isset($args['mobile_bottom']) || !empty($args['mobile_bottom']); $cache = !isset($args['cache']) || !empty($args['cache']); $attrs = ' class="' . esc_attr(trim($class . ' aksrt-modal-link')) . '"'; $attrs .= ' data-aksrt-modal="remote"'; $attrs .= ' data-aksrt-modal-url="' . esc_url($url) . '"'; $attrs .= ' data-aksrt-modal-class="' . esc_attr($data_class) . '"'; if (!$cache) { $attrs .= ' data-aksrt-modal-cache="false"'; } if ($height > 0) { $attrs .= ' data-aksrt-modal-height="' . esc_attr((string) $height) . '"'; } if ($mobile) { $attrs .= ' data-aksrt-modal-mobile-bottom="true"'; } if ($tag === 'a') { $attrs .= ' href="' . esc_url($url !== '' ? $url : '#') . '"'; } else { $attrs .= ' type="button"'; } return '<' . $tag . $attrs . '>' . esc_html($text) . ''; } } if (!function_exists('aksrt_get_ajax_number_paginate')) { /** * Numbered AJAX pager (legacy 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 ''; } }