feat(post-list): align list schema with Zibll paging contract
Replace the post_list.list admin contract with a dedicated schema module using Zibll keys (paging_ajax_s, paging_ajax_ias_s, ajax_trigger, ajax_nomore, list_orderby, post_list_author/time, target_blank). Runtime derives numbered/load_more/infinite from those keys and applies list orderby on main queries without legacy dual-write layers.
This commit is contained in:
1 parent
63efe5b5a8
commit
6a9db98204
9 files changed
+652
-280
No files matched your search
@@ -11,76 +11,105 @@ class AKSRT_Settings_Post_Display {
|
||||
|
||||
public static function get_post_list_style_settings(): array {
|
||||
$settings = AKSRT_Settings::get_all();
|
||||
$card_style = sanitize_key((string) ($settings['post_card_style'] ?? 'standard'));
|
||||
$allowed_styles = ['standard', 'compact', 'large_thumb', 'multi_thumb', 'text', 'thumb_if_has'];
|
||||
$card_style = sanitize_key((string) ($settings['post_card_style'] ?? 'thumb'));
|
||||
$allowed_styles = ['thumb', 'compact', 'large_thumb', 'multi_thumb', 'text', 'thumb_if_has', 'card', 'standard'];
|
||||
|
||||
if (!in_array($card_style, $allowed_styles, true)) {
|
||||
$card_style = 'standard';
|
||||
$card_style = 'thumb';
|
||||
}
|
||||
// historical alias
|
||||
if ($card_style === 'standard') {
|
||||
$card_style = 'thumb';
|
||||
}
|
||||
|
||||
$render_mode_map = [
|
||||
'standard' => 'card',
|
||||
'thumb' => 'card',
|
||||
'compact' => 'list',
|
||||
'large_thumb' => 'list',
|
||||
'multi_thumb' => 'list',
|
||||
'text' => 'list',
|
||||
'thumb_if_has' => 'list',
|
||||
'card' => 'card',
|
||||
];
|
||||
|
||||
$sticky_pages_raw = $settings['sticky_s'] ?? null;
|
||||
if (is_array($sticky_pages_raw)) {
|
||||
$allowed_pages = ['home', 'cat', 'tag', 'topics'];
|
||||
$sticky_pages = array_values(array_intersect(array_map('sanitize_key', $sticky_pages_raw), $allowed_pages));
|
||||
} elseif (!isset($settings['post_sticky_enabled']) || !empty($settings['post_sticky_enabled'])) {
|
||||
$sticky_pages = ['home', 'cat'];
|
||||
} else {
|
||||
$sticky_pages = [];
|
||||
$sticky_pages = ['home', 'cat'];
|
||||
}
|
||||
|
||||
$badge_types_raw = $settings['list_badge_show'] ?? null;
|
||||
if (is_array($badge_types_raw)) {
|
||||
$allowed_types = ['pay', 'cat', 'topics', 'tag'];
|
||||
$badge_types = array_values(array_intersect(array_map('sanitize_key', $badge_types_raw), $allowed_types));
|
||||
} elseif (!isset($settings['post_list_badge_show']) || !empty($settings['post_list_badge_show'])) {
|
||||
$badge_types = ['pay', 'cat', 'topics', 'tag'];
|
||||
} else {
|
||||
$badge_types = [];
|
||||
$badge_types = ['pay', 'cat', 'topics', 'tag'];
|
||||
}
|
||||
|
||||
$show_author = array_key_exists('post_list_author', $settings)
|
||||
? !empty($settings['post_list_author'])
|
||||
: (!isset($settings['post_show_author']) || !empty($settings['post_show_author']));
|
||||
|
||||
$show_date = array_key_exists('post_list_time', $settings)
|
||||
? !empty($settings['post_list_time'])
|
||||
: (!isset($settings['post_show_date']) || !empty($settings['post_show_date']));
|
||||
|
||||
$target_blank = array_key_exists('target_blank', $settings)
|
||||
? !empty($settings['target_blank'])
|
||||
: !empty($settings['post_target_blank']);
|
||||
|
||||
$ajax_trigger = '';
|
||||
if (array_key_exists('ajax_trigger', $settings)) {
|
||||
$ajax_trigger = sanitize_text_field((string) $settings['ajax_trigger']);
|
||||
} elseif (array_key_exists('ajax_trigger_text', $settings)) {
|
||||
$ajax_trigger = sanitize_text_field((string) $settings['ajax_trigger_text']);
|
||||
}
|
||||
|
||||
$ajax_nomore = '';
|
||||
if (array_key_exists('ajax_nomore', $settings)) {
|
||||
$ajax_nomore = sanitize_text_field((string) $settings['ajax_nomore']);
|
||||
} elseif (array_key_exists('ajax_nomore_text', $settings)) {
|
||||
$ajax_nomore = sanitize_text_field((string) $settings['ajax_nomore_text']);
|
||||
}
|
||||
|
||||
return [
|
||||
'card_style' => in_array(sanitize_key((string) ($settings['list_card_style'] ?? '')), ['', 'style3'], true) ? sanitize_key((string) ($settings['list_card_style'] ?? '')) : '',
|
||||
'render_mode' => $render_mode_map[$card_style] ?? 'card',
|
||||
'show_author' => !isset($settings['post_show_author']) || !empty($settings['post_show_author']),
|
||||
'show_date' => !isset($settings['post_show_date']) || !empty($settings['post_show_date']),
|
||||
'show_views' => !isset($settings['post_show_views']) || !empty($settings['post_show_views']),
|
||||
'show_category' => !isset($settings['post_show_category']) || !empty($settings['post_show_category']),
|
||||
'show_comments' => !isset($settings['post_meta_comments']) || !empty($settings['post_meta_comments']),
|
||||
'show_likes' => !isset($settings['post_meta_likes']) || !empty($settings['post_meta_likes']),
|
||||
'badge_types' => $badge_types,
|
||||
'badge_show' => !empty($badge_types),
|
||||
'sticky_pages' => $sticky_pages,
|
||||
'sticky_enabled' => !empty($sticky_pages),
|
||||
'target_blank' => !empty($settings['post_target_blank']),
|
||||
'heading_bold' => !empty($settings['item_heading_bold']),
|
||||
'mobile_meta' => in_array(sanitize_key((string) ($settings['list_meta_show'] ?? 'like')), ['view', 'like', 'comm'], true) ? sanitize_key((string) ($settings['list_meta_show'] ?? 'like')) : 'like',
|
||||
'list_show_type' => in_array(sanitize_key((string) ($settings['list_show_type'] ?? 'separate')), ['separate', 'no_margin'], true) ? sanitize_key((string) ($settings['list_show_type'] ?? 'separate')) : 'separate',
|
||||
'excerpt_length' => max(20, min(500, (int) ($settings['post_excerpt_length'] ?? 120))),
|
||||
'ias_max' => max(0, min(10, (int) ($settings['ias_max'] ?? 3))),
|
||||
'ajax_trigger_text' => sanitize_text_field((string) ($settings['ajax_trigger_text'] ?? '')),
|
||||
'ajax_nomore_text' => sanitize_text_field((string) ($settings['ajax_nomore_text'] ?? '')),
|
||||
'list_orderby' => in_array(sanitize_key((string) ($settings['list_orderby'] ?? 'modified')), ['modified', 'date', 'comments', 'default'], true) ? sanitize_key((string) ($settings['list_orderby'] ?? 'modified')) : 'modified',
|
||||
'columns' => max(1, min(3, (int) ($settings['post_list_columns'] ?? 1))),
|
||||
'per_page' => max(4, min(48, (int) ($settings['post_list_per_page'] ?? 12))),
|
||||
'list_style' => in_array(sanitize_key((string) ($settings['list_list_style'] ?? '')), ['', 'style2'], true) ? sanitize_key((string) ($settings['list_list_style'] ?? '')) : '',
|
||||
'card_style' => in_array(sanitize_key((string) ($settings['list_card_style'] ?? '')), ['', 'style3'], true) ? sanitize_key((string) ($settings['list_card_style'] ?? '')) : '',
|
||||
'render_mode' => $render_mode_map[$card_style] ?? 'card',
|
||||
'show_author' => $show_author,
|
||||
'show_date' => $show_date,
|
||||
'show_views' => !isset($settings['post_show_views']) || !empty($settings['post_show_views']),
|
||||
'show_category' => !isset($settings['post_show_category']) || !empty($settings['post_show_category']),
|
||||
'show_comments' => !isset($settings['post_meta_comments']) || !empty($settings['post_meta_comments']),
|
||||
'show_likes' => !isset($settings['post_meta_likes']) || !empty($settings['post_meta_likes']),
|
||||
'badge_types' => $badge_types,
|
||||
'badge_show' => !empty($badge_types),
|
||||
'sticky_pages' => $sticky_pages,
|
||||
'sticky_enabled' => !empty($sticky_pages),
|
||||
'target_blank' => $target_blank,
|
||||
'heading_bold' => !empty($settings['item_heading_bold']),
|
||||
'mobile_meta' => in_array(sanitize_key((string) ($settings['list_meta_show'] ?? 'like')), ['view', 'like', 'comm'], true) ? sanitize_key((string) ($settings['list_meta_show'] ?? 'like')) : 'like',
|
||||
'list_show_type' => in_array(sanitize_key((string) ($settings['list_show_type'] ?? 'separate')), ['separate', 'no_margin'], true) ? sanitize_key((string) ($settings['list_show_type'] ?? 'separate')) : 'separate',
|
||||
'excerpt_length' => max(20, min(500, (int) ($settings['post_excerpt_length'] ?? 120))),
|
||||
'ias_max' => max(0, min(10, (int) ($settings['ias_max'] ?? 3))),
|
||||
'paging_ajax' => self::is_list_paging_ajax($settings),
|
||||
'paging_ajax_ias' => self::is_list_paging_ajax_ias($settings),
|
||||
'ajax_trigger_text' => $ajax_trigger,
|
||||
'ajax_nomore_text' => $ajax_nomore,
|
||||
'list_orderby' => in_array(sanitize_key((string) ($settings['list_orderby'] ?? 'modified')), ['modified', 'date', 'default'], true) ? sanitize_key((string) ($settings['list_orderby'] ?? 'modified')) : 'modified',
|
||||
'columns' => max(1, min(3, (int) ($settings['post_list_columns'] ?? 1))),
|
||||
'per_page' => max(4, min(48, (int) ($settings['post_list_per_page'] ?? 12))),
|
||||
'list_style' => in_array(sanitize_key((string) ($settings['list_list_style'] ?? '')), ['', 'style2'], true) ? sanitize_key((string) ($settings['list_list_style'] ?? '')) : '',
|
||||
'list_img_position' => in_array(sanitize_key((string) ($settings['list_list_img_position'] ?? 'left')), ['left', 'right'], true) ? sanitize_key((string) ($settings['list_list_img_position'] ?? 'left')) : 'left',
|
||||
'list_scale' => max(50, min(200, (int) ($settings['list_list_scale'] ?? 70))),
|
||||
'card_scale' => max(20, min(200, (int) ($settings['list_card_scale'] ?? 70))),
|
||||
'card_home' => !empty($settings['list_card_home']),
|
||||
'card_cat' => !empty($settings['list_card_cat']),
|
||||
'card_cat_ids' => is_array($settings['list_card_cat'] ?? null) ? array_map('intval', $settings['list_card_cat']) : [],
|
||||
'card_tag' => !empty($settings['list_card_tag']),
|
||||
'card_topics' => !empty($settings['list_card_topics']),
|
||||
'card_author' => !empty($settings['list_card_author']),
|
||||
'list_scale' => max(50, min(200, (int) ($settings['list_list_scale'] ?? 70))),
|
||||
'card_scale' => max(20, min(200, (int) ($settings['list_card_scale'] ?? 70))),
|
||||
'card_home' => !empty($settings['list_card_home']),
|
||||
'card_cat' => !empty($settings['list_card_cat']),
|
||||
'card_cat_ids' => is_array($settings['list_card_cat'] ?? null) ? array_map('intval', $settings['list_card_cat']) : [],
|
||||
'card_tag' => !empty($settings['list_card_tag']),
|
||||
'card_topics' => !empty($settings['list_card_topics']),
|
||||
'card_author' => !empty($settings['list_card_author']),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -290,6 +319,28 @@ class AKSRT_Settings_Post_Display {
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public static function apply_list_orderby($query): void {
|
||||
if (is_admin() || !($query instanceof WP_Query) || !$query->is_main_query()) {
|
||||
return;
|
||||
}
|
||||
if (!$query->is_home() && !$query->is_archive() && !$query->is_search()) {
|
||||
return;
|
||||
}
|
||||
if ($query->get('orderby')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$orderby = sanitize_key((string) (self::get_post_list_style_settings()['list_orderby'] ?? 'modified'));
|
||||
if ($orderby === '' || $orderby === 'default') {
|
||||
return;
|
||||
}
|
||||
if (in_array($orderby, ['date', 'modified'], true)) {
|
||||
$query->set('orderby', $orderby);
|
||||
$query->set('order', 'DESC');
|
||||
}
|
||||
}
|
||||
|
||||
public static function apply_list_per_page($query): void {
|
||||
if (is_admin() || !$query->is_main_query()) {
|
||||
return;
|
||||
@@ -310,13 +361,61 @@ class AKSRT_Settings_Post_Display {
|
||||
}
|
||||
|
||||
public static function get_post_pagination_mode(): string {
|
||||
$mode = (string) AKSRT_Settings::get_value('post_pagination_mode', 'numbered');
|
||||
$settings = AKSRT_Settings::get_all();
|
||||
|
||||
// Zibll: paging_ajax_s '1' = ajax append, '0' = numeric buttons.
|
||||
if (array_key_exists('paging_ajax_s', $settings)) {
|
||||
$ajax = self::is_list_paging_ajax($settings);
|
||||
if (!$ajax) {
|
||||
return 'numbered';
|
||||
}
|
||||
return self::is_list_paging_ajax_ias($settings) ? 'infinite' : 'load_more';
|
||||
}
|
||||
|
||||
// Temporary bridge for installs still holding the previous schema key only.
|
||||
$mode = (string) ($settings['post_pagination_mode'] ?? 'numbered');
|
||||
if ($mode === 'numeric') {
|
||||
$mode = 'numbered';
|
||||
}
|
||||
return in_array($mode, ['numbered', 'load_more', 'infinite'], true) ? $mode : 'numbered';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether list pagination uses AJAX append (Zibll paging_ajax_s).
|
||||
*
|
||||
* @param array<string,mixed>|null $settings
|
||||
*/
|
||||
public static function is_list_paging_ajax(?array $settings = null): bool {
|
||||
$settings = $settings ?? AKSRT_Settings::get_all();
|
||||
if (!array_key_exists('paging_ajax_s', $settings)) {
|
||||
// Fallback from previous 3-mode key.
|
||||
$mode = (string) ($settings['post_pagination_mode'] ?? 'numbered');
|
||||
return in_array($mode, ['load_more', 'infinite', 'ajax'], true);
|
||||
}
|
||||
$raw = $settings['paging_ajax_s'];
|
||||
if (is_bool($raw)) {
|
||||
return $raw;
|
||||
}
|
||||
return (string) $raw === '1' || (string) $raw === 'true';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether AJAX list paging auto-loads on scroll (Zibll paging_ajax_ias_s).
|
||||
*
|
||||
* @param array<string,mixed>|null $settings
|
||||
*/
|
||||
public static function is_list_paging_ajax_ias(?array $settings = null): bool {
|
||||
$settings = $settings ?? AKSRT_Settings::get_all();
|
||||
if (!self::is_list_paging_ajax($settings)) {
|
||||
return false;
|
||||
}
|
||||
if (!array_key_exists('paging_ajax_ias_s', $settings)) {
|
||||
$mode = (string) ($settings['post_pagination_mode'] ?? '');
|
||||
return $mode === 'infinite';
|
||||
}
|
||||
return !empty($settings['paging_ajax_ias_s']);
|
||||
}
|
||||
|
||||
public static function get_comment_pagination_mode(): string {
|
||||
$mode = (string) AKSRT_Settings::get_value('comment_pagination_type', 'numbered');
|
||||
if ($mode === 'page') {
|
||||
|
||||
Reference in new issue
Block a user