Add zibll-parity AjaxList/RemoteModal engines and replace order-center prompt() review flow with multi-dim star modal, multi-image upload, auto-praise countdown, and REST review-modal endpoint.
112 lines
3.9 KiB
PHP
112 lines
3.9 KiB
PHP
<?php
|
|
/**
|
|
* Ajax list + remote modal helpers (zibll ajax-next / RefreshModal parity).
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
if (!function_exists('aksrt_get_ajax_null')) {
|
|
/**
|
|
* Empty state for AJAX list replace.
|
|
*/
|
|
function aksrt_get_ajax_null(?string $text = null, $margin = 60, string $img = 'null.svg'): string {
|
|
if (null === $text) {
|
|
$text = __('内容空空如也', 'aksrt');
|
|
}
|
|
if (function_exists('aksrt_get_null')) {
|
|
return aksrt_get_null($text, $margin, $img, 'ajax-item aksrt-ajax-null');
|
|
}
|
|
return '<div class="text-center ajax-item aksrt-ajax-null" style="padding:' . esc_attr((string) $margin) . 'px 0;">'
|
|
. '<p class="muted-3-color">' . esc_html((string) $text) . '</p></div>';
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_get_ajax_next_paginate')) {
|
|
/**
|
|
* Load-more style paginate block (zibll zib_get_ajax_next_paginate 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 '<div class="' . esc_attr($pag_class) . ' hide"><div class="' . esc_attr($next_class) . '"><a href="#"></a></div></div>';
|
|
}
|
|
if ($label === '') {
|
|
$label = __('加载更多', 'aksrt');
|
|
}
|
|
$next = $page + 1;
|
|
$url = $ajax_url !== '' ? $ajax_url : '#';
|
|
// Prefer caller-provided URL already containing next page.
|
|
return '<div class="' . esc_attr($pag_class) . '">'
|
|
. '<div class="' . esc_attr($next_class) . '">'
|
|
. '<a href="' . esc_url($url) . '" class="ajax-next" data-page="' . esc_attr((string) $next) . '">'
|
|
. esc_html($label)
|
|
. '</a></div></div>';
|
|
}
|
|
}
|
|
|
|
if (!function_exists('aksrt_get_remote_modal_link')) {
|
|
/**
|
|
* Build a remote-modal trigger (zibll zib_get_refresh_modal_link subset).
|
|
*
|
|
* @param array{
|
|
* tag?:string,class?:string,text?:string,url?:string,
|
|
* data_class?:string,height?:int,mobile_bottom?:bool,
|
|
* query_arg?:array<string,scalar>
|
|
* } $args
|
|
*/
|
|
function aksrt_get_remote_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']);
|
|
|
|
$attrs = ' class="' . esc_attr(trim($class . ' aksrt-remote-modal-link')) . '"';
|
|
$attrs .= ' data-toggle="AksrtRemoteModal"';
|
|
$attrs .= ' data-remote="' . esc_url($url) . '"';
|
|
$attrs .= ' data-class="' . esc_attr($data_class) . '"';
|
|
if ($height > 0) {
|
|
$attrs .= ' data-height="' . esc_attr((string) $height) . '"';
|
|
}
|
|
if ($mobile) {
|
|
$attrs .= ' mobile-bottom="true"';
|
|
}
|
|
if ($tag === 'a') {
|
|
$attrs .= ' href="' . esc_url($url !== '' ? $url : '#') . '"';
|
|
} else {
|
|
$attrs .= ' type="button"';
|
|
}
|
|
|
|
return '<' . $tag . $attrs . '>' . esc_html($text) . '</' . $tag . '>';
|
|
}
|
|
}
|