Files
justice/www/html/Game/public/api-quiz-carry-from-disk.php
T
2026-05-02 06:21:45 +00:00

55 lines
1.9 KiB
PHP

<?php
/**
* สาธารณะ — ส่งฟิลด์ quiz_carry จาก quiz-settings.json บนดิสก์ (ใต้ Game/data)
* หน้าเล่น merge ทับคำตอบจาก Node เพื่อให้ธีมแผงคำถามตรงกับที่ Admin บันทึก (PHP merge ลงไฟล์เดียวกับนี้)
* Public — carry fields from on-disk quiz-settings.json; play.js merges over Node so panel theme matches Admin saves.
*/
declare(strict_types=1);
header('Content-Type: application/json; charset=utf-8');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Pragma: no-cache');
header('X-Content-Type-Options: nosniff');
$path = dirname(__DIR__) . '/data/quiz-settings.json';
$raw = @file_get_contents($path);
if ($raw === false || $raw === '') {
echo '{}';
exit;
}
$data = json_decode($raw, true);
if (!is_array($data)) {
echo '{}';
exit;
}
$out = [];
$keys = ['carryMapPanelTheme', 'quizMapPanelTheme', 'carryEmbedCountdownTheme', 'carryChoicePlaqueThemes', 'carryChoicePlaqueTheme', 'carryChoicePlaqueMapScale', 'carryReadMs', 'carryAnswerMs', 'carrySessionLength', 'carryWalkSpeedMultForMapId', 'carryWalkSpeedMult', 'carryQuestions'];
foreach ($keys as $k) {
if (!array_key_exists($k, $data)) {
continue;
}
if ($k === 'carryMapPanelTheme' || $k === 'quizMapPanelTheme' || $k === 'carryEmbedCountdownTheme' || $k === 'carryChoicePlaqueTheme') {
if (is_array($data[$k])) {
$out[$k] = $data[$k];
}
continue;
}
if ($k === 'carryChoicePlaqueThemes') {
if (is_array($data[$k])) {
$out[$k] = $data[$k];
}
continue;
}
if ($k === 'carryQuestions') {
if (is_array($data[$k])) {
$out[$k] = $data[$k];
}
continue;
}
$out[$k] = $data[$k];
}
echo json_encode($out, JSON_UNESCAPED_UNICODE);