1e51ef7def
- Konzept/, didaktik_geografie/, didaktik_simulation/, v2-modules/, v2-platform/ - 12 code-workspace-Files - STATUS-*.md - viele M/D/R-Änderungen an bereits getrackten Files - .gitignore verstärkt: **/.humaninput/, **/secret_keys.txt Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
92 lines
3.4 KiB
PHP
92 lines
3.4 KiB
PHP
<?php
|
|
/**
|
|
* Weltküche — PHP-Wrapper
|
|
* Lädt sims/weltkueche/game.html, injiziert Session-Kontext + Pfad-Basis.
|
|
*/
|
|
require_once __DIR__ . '/../php/config/app.php';
|
|
require_once __DIR__ . '/../php/lib/Database.php';
|
|
require_once __DIR__ . '/../php/lib/Session.php';
|
|
|
|
if (session_status() === PHP_SESSION_NONE) Session::start();
|
|
|
|
$sessionId = Session::studentId() ?? '';
|
|
$studentName = 'Gast';
|
|
$classId = null;
|
|
$mode = 'free';
|
|
|
|
try {
|
|
$db = Database::get();
|
|
if ($sessionId) {
|
|
$row = $db->fetchOne(
|
|
'SELECT class_id, display_name FROM student_sessions WHERE id = ?',
|
|
[$sessionId]
|
|
);
|
|
if ($row) {
|
|
$studentName = $row['display_name'] ?: 'Schüler*in';
|
|
$classId = (int)$row['class_id'];
|
|
}
|
|
}
|
|
} catch (Exception $e) { /* still als Demo lauffähig */ }
|
|
|
|
$gamePath = __DIR__ . '/../sims/weltkueche/game.html';
|
|
if (!file_exists($gamePath)) {
|
|
http_response_code(503);
|
|
echo '<h1>Weltküche wird gerade vorbereitet.</h1><p><a href="' . cockpit_href() . '">Zurück</a></p>';
|
|
exit;
|
|
}
|
|
$html = file_get_contents($gamePath);
|
|
|
|
// Session-Kontext + Plattform-Basis injizieren.
|
|
// Setzt sowohl die Weltküche-eigenen WK_*-Vars (legacy) als auch das
|
|
// Plattform-Kontext-Objekt __GGS__, ohne das der Live-Client (Heartbeat
|
|
// an das Lehrer-Cockpit) still abbricht.
|
|
$base = BASE_PATH . '/sims/weltkueche/';
|
|
$ggs = [
|
|
'sessionId' => $sessionId,
|
|
'simId' => 'weltkueche',
|
|
'classId' => $classId,
|
|
'baseUrl' => BASE_URL,
|
|
'basePath' => BASE_PATH,
|
|
'apiUrl' => BASE_URL . '/php/api',
|
|
'studentName' => $studentName,
|
|
'mode' => $mode,
|
|
];
|
|
$injection = '<script>'
|
|
. 'window.WK_BASE = ' . json_encode($base) . ';'
|
|
. 'window.WK_SESSION_ID = ' . json_encode($sessionId) . ';'
|
|
. 'window.WK_STUDENT_NAME = ' . json_encode($studentName) . ';'
|
|
. 'window.WK_CLASS_ID = ' . json_encode($classId) . ';'
|
|
. 'window.WK_MODE = ' . json_encode($mode) . ';'
|
|
. 'window.WK_API_BASE = ' . json_encode(BASE_PATH . '/api') . ';'
|
|
. 'window.__GGS__ = ' . json_encode($ggs, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . ';'
|
|
. '</script>';
|
|
|
|
// Asset-Pfade umbiegen (relativ → absolut) — NUR href= und src= Attribute,
|
|
// NICHT in JS-Strings. Sonst entstehen doppelte Pfade in fetch()-Calls,
|
|
// weil das JS bereits window.WK_BASE davor konkateniert.
|
|
$html = preg_replace(
|
|
"/(href|src)=([\"'])assets\//",
|
|
"$1=$2{$base}assets/",
|
|
$html
|
|
);
|
|
|
|
// Injection vor </head>
|
|
$html = str_replace('</head>', $injection . "\n</head>", $html);
|
|
|
|
// Cockpit-Link absolut
|
|
$html = str_replace('href="../../schueler.html"', 'href="' . cockpit_href() . '"', $html);
|
|
|
|
// Live-Heartbeat-Client + Glossar-Tooltip-Standard der Plattform anhängen
|
|
$liveScript = '<script src="' . BASE_PATH . '/assets/js/live-client.js" defer></script>';
|
|
$glossarScript = '<script src="' . BASE_PATH . '/assets/js/glossar-tooltip.js" defer></script>'
|
|
. '<script>window.addEventListener("DOMContentLoaded",function(){'
|
|
. 'if(window.GlossarTooltip)GlossarTooltip.init({apiBase:' . json_encode(BASE_PATH . '/php/api') . ',moduleId:"weltkueche"});'
|
|
. '});</script>';
|
|
$html = str_replace('</body>', $liveScript . "\n" . $glossarScript . "\n</body>", $html);
|
|
|
|
// Cache-Bust für game.html selbst (nicht via HTTP-Header sondern als Direkt-Ausgabe)
|
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
|
header('Content-Type: text/html; charset=UTF-8');
|
|
|
|
echo $html;
|