admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('affgsc_admin_status'),
'pollInterval' => 3000,
'chooseImage' => __('Choose image', 'affgate-slot-catalog'),
'useImage' => __('Use this image', 'affgate-slot-catalog'),
'invalidCasinoImage' => __('Choose a JPEG, PNG, WebP, or AVIF image.', 'affgate-slot-catalog'),
'createPageNonce' => wp_create_nonce('affgsc_create_catalog_page'),
'creatingPage' => __('Creating page…', 'affgate-slot-catalog'),
'pageCreated' => __('Page created and selected.', 'affgate-slot-catalog'),
'pageCreateFailed' => __('The page could not be created.', 'affgate-slot-catalog'),
]);
}
function affgsc_admin_notice(string $type, string $message): void {
$notices = get_option('affgsc_admin_notices', []);
$notices = is_array($notices) ? $notices : [];
$notices[] = ['type' => $type, 'message' => $message];
update_option('affgsc_admin_notices', array_slice($notices, -5), false);
}
function affgsc_admin_pop_notices(): array {
$notices = get_option('affgsc_admin_notices', []);
delete_option('affgsc_admin_notices');
return is_array($notices) ? $notices : [];
}
function affgsc_admin_redirect(): void {
wp_safe_redirect(admin_url('admin.php?page=affgsc-settings-import'));
exit;
}
function affgsc_catalog_page_types(): array {
return [
'catalog' => [
'setting' => 'catalog_page_id',
'title' => 'Slot Catalog',
'default_slug' => 'slot-catalog',
'content' => '[affgsc_games]',
'label' => __('Game catalog and game URL parent', 'affgate-slot-catalog'),
],
'provider' => [
'setting' => 'provider_page_id',
'title' => 'Slot Providers',
'default_slug' => 'slot-providers',
'content' => '[affgsc_providers]',
'label' => __('Provider directory and provider URL parent', 'affgate-slot-catalog'),
],
'type' => [
'setting' => 'type_page_id',
'title' => 'Slot Types',
'default_slug' => 'slot-types',
'content' => '[affgsc_types]',
'label' => __('Type directory and type URL parent', 'affgate-slot-catalog'),
],
'theme' => [
'setting' => 'theme_page_id',
'title' => 'Slot Themes',
'default_slug' => 'slot-themes',
'content' => '[affgsc_themes]',
'label' => __('Theme directory and theme URL parent', 'affgate-slot-catalog'),
],
];
}
function affgsc_render_catalog_page_control(string $kind, array $settings): void {
$types = affgsc_catalog_page_types();
if (!isset($types[$kind])) return;
$config = $types[$kind];
$setting = (string)$config['setting'];
$selected = absint($settings[$setting] ?? 0);
?>
esc_attr('affgsc[' . $safe_setting . ']'),
'id' => esc_attr('affgsc_' . $safe_setting),
'selected' => absint($selected),
'show_option_none' => esc_html__('— Select a page —', 'affgate-slot-catalog'),
'option_none_value' => '0',
'class' => 'regular-text',
'echo' => 0,
]);
echo wp_kses((string)$page_dropdown, [
'select' => ['name' => true, 'id' => true, 'class' => true],
'option' => ['value' => true, 'selected' => true],
]);
?>
0 ? wp_get_attachment_image_url($image_id, 'thumbnail') : '';
$row_id = sanitize_key((string)($casino['id'] ?? ''));
if ($row_id === '') $row_id = sanitize_key(wp_generate_uuid4());
$name_prefix = 'affgsc[casinos][' . $index . ']';
?>
__('You are not allowed to create pages.', 'affgate-slot-catalog')], 403);
}
check_ajax_referer('affgsc_create_catalog_page', 'nonce');
$kind = isset($_POST['kind']) && is_scalar($_POST['kind']) ? sanitize_key(wp_unslash((string)$_POST['kind'])) : '';
$types = affgsc_catalog_page_types();
if (!isset($types[$kind])) {
wp_send_json_error(['message' => __('Invalid page type.', 'affgate-slot-catalog')], 400);
}
$slug = isset($_POST['slug']) && is_scalar($_POST['slug']) ? sanitize_title(wp_unslash((string)$_POST['slug'])) : '';
if ($slug === '') {
wp_send_json_error(['message' => __('Enter a valid page slug.', 'affgate-slot-catalog')], 400);
}
$existing = get_posts([
'post_type' => 'page',
'post_status' => 'any',
'name' => $slug,
'numberposts' => 1,
'fields' => 'ids',
]);
if ($existing) {
wp_send_json_error(['message' => __('A page with this slug already exists. Enter another slug.', 'affgate-slot-catalog')], 409);
}
$config = $types[$kind];
$page_id = wp_insert_post([
'post_type' => 'page',
'post_status' => 'publish',
'post_title' => (string)$config['title'],
'post_name' => $slug,
'post_content' => (string)$config['content'],
], true);
if (is_wp_error($page_id)) {
wp_send_json_error(['message' => $page_id->get_error_message()], 500);
}
$page_id = absint($page_id);
update_post_meta($page_id, '_affgsc_created_catalog_page', '1');
$stored = get_option(AFFGSC_OPT, []);
$stored = is_array($stored) ? $stored : [];
$stored[(string)$config['setting']] = $page_id;
update_option(AFFGSC_OPT, $stored, false);
affgsc_register_content_types();
flush_rewrite_rules(false);
wp_send_json_success([
'id' => $page_id,
'title' => get_the_title($page_id),
'slug' => (string)get_post_field('post_name', $page_id),
'message' => __('Page created and selected.', 'affgate-slot-catalog'),
]);
}
function affgsc_admin_persist_settings(array $raw, bool $show_notice = false): void {
$old = affgsc_settings();
$new = affgsc_sanitize_settings($raw);
update_option(AFFGSC_OPT, $new, false);
if ((string)($old['share_usage_stats'] ?? '0') === '1' && (string)($new['share_usage_stats'] ?? '0') !== '1') {
affgsc_write_stats([]);
delete_option('affgsc_stats_outbox');
}
$connection_requested = (
(string)($new['weekly_sync'] ?? '0') === '1'
|| (string)($new['show_interest_chart'] ?? '0') === '1'
|| (string)($new['show_country_chart'] ?? '0') === '1'
);
if ($connection_requested && affgsc_install_api_secret() === '') {
$connection = affgsc_ensure_installation_secret();
if (empty($connection['ok'])) {
affgsc_admin_notice('error', sprintf(
/* translators: %s: secure connection error message. */
__('Settings were saved, but the secure AffGate connection could not be established: %s', 'affgate-slot-catalog'),
(string)($connection['message'] ?? __('Unknown error', 'affgate-slot-catalog'))
));
}
}
affgsc_schedule_events();
if ((string)($new['show_interest_chart'] ?? '0') === '1' || (string)($new['show_country_chart'] ?? '0') === '1') {
$was_enabled = (string)($old['show_interest_chart'] ?? '0') === '1' || (string)($old['show_country_chart'] ?? '0') === '1';
affgsc_schedule_frequency_refresh($was_enabled ? 30 : 5);
} else {
affgsc_unschedule_hook('affgsc_refresh_frequency_data');
}
foreach (['slot_slug', 'provider_slug', 'type_slug', 'theme_slug', 'catalog_page_id', 'provider_page_id', 'type_page_id', 'theme_page_id', 'public_provider_pages', 'public_type_pages', 'public_theme_pages'] as $rewrite_key) {
if (($old[$rewrite_key] ?? null) !== ($new[$rewrite_key] ?? null)) {
affgsc_register_content_types();
flush_rewrite_rules(false);
break;
}
}
if ($show_notice) {
affgsc_admin_notice('success', __('Settings saved.', 'affgate-slot-catalog'));
}
}
function affgsc_admin_save_settings(): void {
if (!current_user_can(AFFGSC_CAP)) wp_die('Forbidden');
check_admin_referer('affgsc_save_settings');
// The structured settings array is field-by-field sanitized by affgsc_sanitize_settings().
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$raw = isset($_POST['affgsc']) && is_array($_POST['affgsc']) ? wp_unslash($_POST['affgsc']) : [];
$raw = is_array($raw) ? $raw : [];
affgsc_admin_persist_settings($raw, true);
affgsc_admin_redirect();
}
function affgsc_admin_start_import(): void {
if (!current_user_can(AFFGSC_CAP)) wp_die('Forbidden');
check_admin_referer('affgsc_start_import');
if (isset($_POST['affgsc']) && is_array($_POST['affgsc'])) {
// The structured settings array is field-by-field sanitized by affgsc_sanitize_settings().
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$raw = wp_unslash($_POST['affgsc']);
affgsc_admin_persist_settings($raw, false);
}
$state = affgsc_start_import('manual', true);
if (($state['status'] ?? '') === 'error') {
/* translators: %s: import error message. */
affgsc_admin_notice('error', sprintf(__('Import was not started: %s', 'affgate-slot-catalog'), (string)($state['last_error'] ?? __('Unknown error', 'affgate-slot-catalog'))));
} else {
affgsc_admin_notice('success', __('Import started from the latest AffGate manifest.', 'affgate-slot-catalog'));
}
affgsc_admin_redirect();
}
function affgsc_admin_delete_games(): void {
if (!current_user_can(AFFGSC_CAP)) wp_die('Forbidden');
check_admin_referer('affgsc_delete_games');
$ids = get_posts([
'post_type' => AFFGSC_POST_TYPE,
'post_status' => ['publish', 'draft', 'pending', 'private', 'future'],
'posts_per_page' => -1,
'fields' => 'ids',
'no_found_rows' => true,
]);
$deleted = 0;
if (is_array($ids) && $ids) {
foreach (array_map('intval', $ids) as $post_id) {
if ($post_id > 0 && wp_delete_post($post_id, true) instanceof WP_Post) {
$deleted++;
}
}
}
/* translators: %d: number of deleted games. */
affgsc_admin_notice('success', sprintf(__('Deleted %d games.', 'affgate-slot-catalog'), $deleted));
affgsc_admin_redirect();
}
function affgsc_admin_status_payload(): array {
$state = affgsc_state();
$stats = affgsc_stats();
$post_count = wp_count_posts(AFFGSC_POST_TYPE);
$status = (string)($state['status'] ?? 'idle');
$processed = (int)($state['total_imported'] ?? 0) + (int)($state['total_updated'] ?? 0) + (int)($state['total_skipped'] ?? 0);
$expected = max(0, (int)($state['total_expected'] ?? 0));
$percent = $expected > 0 ? min(100, (int)floor(($processed / $expected) * 100)) : 0;
if (in_array($status, ['done', 'error'], true) && $processed > 0) {
$percent = 100;
}
$started = strtotime((string)($state['started_at'] ?? ''));
$eta = '';
if ($status === 'running' && $expected > 0 && $processed > 0 && $started) {
$elapsed = max(1, time() - $started);
$rate = $processed / $elapsed;
$remaining = max(0, $expected - $processed);
if ($rate > 0 && $remaining > 0) {
$seconds = (int)ceil($remaining / $rate);
/* translators: %s: human-readable remaining time. */
$eta = sprintf(__('about %s left', 'affgate-slot-catalog'), human_time_diff(time(), time() + $seconds));
}
}
$current_provider = (string)($state['current_provider'] ?? '');
$current_total = (int)($state['current_provider_total'] ?? 0);
$current_done = (int)($state['current_provider_done'] ?? 0);
if ($expected > 0) {
/* translators: 1: processed game count, 2: total game count. */
$progress_text = sprintf(__('%1$d of %2$d games processed', 'affgate-slot-catalog'), $processed, $expected);
} else {
/* translators: %d: processed game count. */
$progress_text = sprintf(__('%d games processed', 'affgate-slot-catalog'), $processed);
}
if ($current_provider !== '' && $status === 'running') {
if ($current_total > 0) {
/* translators: 1: provider name, 2: processed game count, 3: provider game count. */
$provider_text = sprintf(__('Current provider: %1$s (%2$d/%3$d)', 'affgate-slot-catalog'), $current_provider, $current_done, $current_total);
} else {
/* translators: %s: provider name. */
$provider_text = sprintf(__('Current provider: %s', 'affgate-slot-catalog'), $current_provider);
}
$progress_text .= '. ' . $provider_text;
}
if ($eta !== '') {
$progress_text .= '. ' . $eta;
}
return [
'status' => $status,
'is_running' => $status === 'running',
'imported_slots' => sprintf(
'%s %s / %s %s',
affgsc_format_number_plain((int)($post_count->publish ?? 0)),
__('published', 'affgate-slot-catalog'),
affgsc_format_number_plain((int)($post_count->draft ?? 0)),
__('draft', 'affgate-slot-catalog')
),
'queue' => sprintf('%s %s', affgsc_format_number_plain(count((array)($state['queue'] ?? []))), __('provider files', 'affgate-slot-catalog')),
'current_provider' => $current_provider !== '' ? $current_provider : '-',
'totals' => sprintf(
'%s / %s / %s',
affgsc_format_number_plain((int)($state['total_imported'] ?? 0)),
affgsc_format_number_plain((int)($state['total_updated'] ?? 0)),
affgsc_format_number_plain((int)($state['total_skipped'] ?? 0))
),
'last_error' => (string)($state['last_error'] ?? ''),
'local_stats_pending' => sprintf(
'%s %s, %s %s',
affgsc_format_number_plain(count((array)($stats['games'] ?? []))),
__('games', 'affgate-slot-catalog'),
affgsc_format_number_plain(count((array)($stats['reports'] ?? []))),
__('reports', 'affgate-slot-catalog')
),
'progress_percent' => $percent,
'progress_text' => $progress_text,
'updated_at' => (string)($state['updated_at'] ?? ''),
];
}
function affgsc_ajax_admin_status(): void {
if (!current_user_can(AFFGSC_CAP)) {
wp_send_json_error(['message' => 'Forbidden'], 403);
}
check_ajax_referer('affgsc_admin_status', 'nonce');
$state = affgsc_state();
if ((string)($state['status'] ?? '') === 'running') {
affgsc_kick_import();
}
wp_send_json_success(affgsc_admin_status_payload());
}
function affgsc_admin_sort_url(string $orderby, string $current_orderby, string $current_order): string {
$next_order = ($current_orderby === $orderby && $current_order === 'desc') ? 'asc' : 'desc';
return add_query_arg([
'orderby' => $orderby,
'order' => $next_order,
'stats_paged' => 1,
]);
}
function affgsc_statistics_page(): void {
if (!current_user_can(AFFGSC_CAP)) return;
$periods = [
'all' => ['label' => __('All time', 'affgate-slot-catalog'), 'days' => 0],
'30' => ['label' => __('Last 30 days', 'affgate-slot-catalog'), 'days' => 30],
'90' => ['label' => __('Last 90 days', 'affgate-slot-catalog'), 'days' => 90],
];
$period_key = sanitize_key(affgsc_query_value('period', 'all'));
if (!isset($periods[$period_key])) $period_key = 'all';
$orderby = sanitize_key(affgsc_query_value('orderby', 'launches'));
$allowed_orderby = ['title', 'launches', 'real_play_clicks', 'reports', 'rating_average', 'rating_count'];
if (!in_array($orderby, $allowed_orderby, true)) $orderby = 'launches';
$order = strtolower(affgsc_query_value('order', 'desc')) === 'asc' ? 'asc' : 'desc';
$paged = max(1, absint(affgsc_query_value('stats_paged', '1')));
$per_page = 30;
$rows = affgsc_stats_summary((int)$periods[$period_key]['days'], 0);
usort($rows, static function (array $a, array $b) use ($orderby, $order): int {
if ($orderby === 'title') {
$result = strcasecmp((string)($a['title'] ?? ''), (string)($b['title'] ?? ''));
} else {
$result = ((float)($a[$orderby] ?? 0)) <=> ((float)($b[$orderby] ?? 0));
}
return $order === 'asc' ? $result : -$result;
});
$total_rows = count($rows);
$page_rows = array_slice($rows, ($paged - 1) * $per_page, $per_page);
$total_pages = max(1, (int)ceil($total_rows / $per_page));
?>
1) : ?>
add_query_arg('stats_paged', '%#%'),
'format' => '',
'current' => $paged,
'total' => $total_pages,
])); ?>
0 ? wp_get_attachment_image_url($placeholder_id, 'medium') : '';
$casino_visit_label = (string)($settings['casino_visit_label'] ?? 'Visit');
$casino_visit_label_custom = (string)($settings['casino_visit_label_custom'] ?? '0') === '1';
if (!$casino_visit_label_custom && $casino_visit_label === 'Visit') $casino_visit_label = __('Visit', 'affgate-slot-catalog');
$casino_review_label = (string)($settings['casino_review_label'] ?? 'Review');
$casino_review_label_custom = (string)($settings['casino_review_label_custom'] ?? '0') === '1';
if (!$casino_review_label_custom && $casino_review_label === 'Review') $casino_review_label = __('Review', 'affgate-slot-catalog');
?>
[affgsc_games] —
| | |
provider, type, theme, volatility | | |
ids | 123,456 | |
per_page | 1–120 | |
limit | 1–500 | |
show_filters | true, false | |
layout | grid, list | |
mode | catalog, carousel | |
nav | pagination, load_more, none | |
sort_by | popular, release_date, rating, title | |
filter_position | off, left, top, bottom | |
style_theme | black, white | |
main_color | #166534, 166534 | |
[affgsc_games provider="netent" per_page="24"] —
[affgsc_games provider="netent" mode="carousel" limit="12" show_filters="false"] —
[affgsc_games layout="list" nav="load_more" sort_by="release_date"] —
[affgsc_games ids="123,456" layout="grid" limit="2" nav="none"] —
[affgsc_game id="123"] —
[affgsc_related_provider_games] —
| | |
id | | |
ids | 123,456 | |
filter | provider, type, theme | |
per_page | 1–12 | |
sort_by | popular, release_date, rating, title | |
title | {name}, {provider}, {type}, {theme} | |
[affgsc_related_provider_games filter="theme" per_page="6" sort_by="popular" title="{name}: {theme}"]
[affgsc_interest_chart] —
| | |
id | | |
title | {name}, {provider}, {type}, {theme} | |
view | all, graf1, graf2, graf1,graf2 | |
type | tn1, tn2 | |
country_view | cv1, cv2, cv3 | |
[affgsc_interest_chart title="{name}: {provider}" view="graf2" type="tn2" country_view="cv2"]
[affgsc_casinos] —
| | |
title | {name}, {provider}, {type}, {theme} | |
per_page | 1–50 | |
[affgsc_casinos title="{name}: online casinos" per_page="5"]
[affgsc_providers] —
[affgsc_types] —
[affgsc_themes] —
[affgsc_providers id="12,34,56" limit="3" style_theme="black" main_color="#d97706"]