5655af81bf
teacher.html: Menü „Live" → „Ergebnisse" mit Unteransichten Tag·Aktuell·Vergleich·Gesamt (alte Ergebnisse-Ansicht ist jetzt „Gesamt"). Neue Kennzahl Qualität (grafischer richtig/falsch-Balken) in Aktuell + Vergleich + Weltküche-Zeile, Gerichte-Zähler (Fleiß), Labels entschärft („Kritisch" → Stark/Solide/Viele Fehler). Weltküche: korrekte Artikel (der/die/das) für alle 70 Zutaten in production-matrix.json; verdrehten Herkunfts-Satz + Heimat-Banner neu und marktbewusst (Ukraine-Distraktor ehrlich erklärt), „man"-Konstruktionen für Singular/Plural. _scripts.php: renderPage() injizierte Favicon per strrpos ins letzte </head> — das lag in teacher.htmls printBatchTickets-JS-String → SyntaxError zerschoss das ganze Inline-Script auf /teacher. Fix: strpos (erstes </head>). tourismusregion: neue Karte passstrasse in maps-custom.json (Route bergauf 136 Punkte, 41 Bauslots) aus Editor-Export. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
135 lines
5.6 KiB
PHP
135 lines
5.6 KiB
PHP
<?php
|
|
/**
|
|
* Vite Manifest Reader
|
|
* Liest dist/.vite/manifest.json und gibt die korrekten Script-Tags aus.
|
|
* Im Dev-Modus (kein manifest vorhanden) wird direkt auf die TS-Quellen verwiesen.
|
|
*/
|
|
|
|
function viteAssets(string $entry): void {
|
|
$manifestPath = APP_ROOT . '/dist/.vite/manifest.json';
|
|
|
|
// Production: Lese Manifest
|
|
if (file_exists($manifestPath)) {
|
|
$manifest = json_decode(file_get_contents($manifestPath), true);
|
|
$chunk = $manifest[$entry] ?? null;
|
|
if (!$chunk) return;
|
|
|
|
// CSS
|
|
foreach ($chunk['css'] ?? [] as $css) {
|
|
echo '<link rel="stylesheet" href="' . BASE_PATH . '/dist/' . $css . '">' . "\n";
|
|
}
|
|
// Preload imports
|
|
foreach ($chunk['imports'] ?? [] as $importKey) {
|
|
$imp = $manifest[$importKey] ?? null;
|
|
if ($imp) {
|
|
echo '<link rel="modulepreload" crossorigin href="' . BASE_PATH . '/dist/' . $imp['file'] . '">' . "\n";
|
|
}
|
|
}
|
|
// Main entry
|
|
echo '<script type="module" crossorigin src="' . BASE_PATH . '/dist/' . $chunk['file'] . '"></script>' . "\n";
|
|
}
|
|
// Dev fallback: keine Manifest-Datei → direkte TS-Referenz (Vite Dev Server)
|
|
}
|
|
|
|
/** Session-Kontext als JS-Variable injizieren */
|
|
function injectSessionContext(): void {
|
|
$ctx = [
|
|
'sessionId' => Session::studentId(),
|
|
'teacherId' => Session::teacherId(),
|
|
'baseUrl' => BASE_URL,
|
|
'basePath' => BASE_PATH,
|
|
];
|
|
echo '<script>window.__GGS__ = ' . json_encode($ctx, JSON_UNESCAPED_UNICODE) . ';</script>' . "\n";
|
|
}
|
|
|
|
/**
|
|
* Plattform-Live-Client in eine Sim-Render-HTML einfügen.
|
|
*
|
|
* Stellt sicher, dass `window.__GGS__` mit `sessionId`, `simId`, `baseUrl`,
|
|
* `basePath`, `apiUrl` belegt ist (Sim-eigene Werte gewinnen) und lädt
|
|
* danach `assets/js/live-client.js`. Der Live-Client kümmert sich dann um
|
|
* Heartbeat / Pause-Polling / Spectator-Mode.
|
|
*
|
|
* In jedem Sim-Wrapper kurz vor `echo $html` aufrufen:
|
|
* $html = ggs_inject_live($html, 'logistik');
|
|
*/
|
|
function ggs_inject_live(string $html, string $simId): string {
|
|
$bp = BASE_PATH;
|
|
$bu = BASE_URL;
|
|
$sid = Session::studentId() ?? '';
|
|
$ctx = [
|
|
'sessionId' => $sid,
|
|
'simId' => $simId,
|
|
'baseUrl' => $bu,
|
|
'basePath' => $bp,
|
|
'apiUrl' => $bu . '/php/api',
|
|
];
|
|
$ctxJson = json_encode($ctx, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
// Sim-eigene __GGS__-Felder gewinnen — wir ergänzen nur Plattform-Felder.
|
|
$bootstrap = '<script>window.__GGS__=Object.assign(' . $ctxJson . ',window.__GGS__||{});</script>';
|
|
$tag = '<script src="' . htmlspecialchars($bp . '/assets/js/live-client.js', ENT_QUOTES) . '" defer></script>';
|
|
$injection = $bootstrap . "\n" . $tag . "\n";
|
|
|
|
// Sicheres Inject: vor dem letzten </body>. Falls keines, einfach anhängen.
|
|
$pos = strrpos($html, '</body>');
|
|
if ($pos === false) return $html . "\n" . $injection;
|
|
return substr($html, 0, $pos) . $injection . substr($html, $pos);
|
|
}
|
|
|
|
/** Seite rendern: HTML laden, Session-Kontext + Favicon injizieren, ausgeben.
|
|
*
|
|
* Härtung: str_replace('</body>', ...) wäre zerstörerisch, wenn der String
|
|
* '</body>' in einem JavaScript-Literal vorkommt (z.B. teacher.html nutzt
|
|
* w.document.write('<html>…</body></html>') — die Replace würde mitten in
|
|
* den JS-String injizieren und den Parser zerschießen, der Rest des
|
|
* <script>-Blocks landet sichtbar als Text auf der Seite).
|
|
* Lösung: nur das LETZTE Vorkommen ersetzen (echtes Doc-Ende), via strrpos.
|
|
*/
|
|
function renderPage(string $htmlFile): void {
|
|
$html = file_get_contents(APP_ROOT . '/' . $htmlFile);
|
|
|
|
// Favicon-Block (ersetzt alte logo.png Referenz)
|
|
$bp = BASE_PATH;
|
|
$favicon = <<<HTML
|
|
<link rel="icon" type="image/png" href="{$bp}/favicon-96x96.png" sizes="96x96">
|
|
<link rel="icon" type="image/svg+xml" href="{$bp}/favicon.svg">
|
|
<link rel="shortcut icon" href="{$bp}/favicon.ico">
|
|
<link rel="apple-touch-icon" sizes="180x180" href="{$bp}/apple-touch-icon.png">
|
|
<link rel="manifest" href="{$bp}/site.webmanifest">
|
|
HTML;
|
|
|
|
// Alten Favicon-Link entfernen (alle Vorkommen — sind harmlos zu ersetzen, weil im <head>)
|
|
if (preg_match('/<link[^>]*rel=["\']icon["\'][^>]*>/', $html)) {
|
|
$html = preg_replace('/<link[^>]*rel=["\']icon["\'][^>]*>\s*/', '', $html);
|
|
}
|
|
|
|
// Favicon vor dem ERSTEN </head> einfügen (= echter Dokumentkopf).
|
|
// WICHTIG: strpos (erstes), NICHT strrpos (letztes). Seiten wie teacher.html
|
|
// enthalten in Body-Skripten ein w.document.write('<html><head>…</head>…')
|
|
// (z.B. Ticket-Druck-Popup). Dessen </head> ist das LETZTE der Datei — strrpos
|
|
// hätte den mehrzeiligen Favicon-Block mitten in den einfach-gequoteten
|
|
// JS-String injiziert → „Invalid or unexpected token" → gesamtes Inline-Script
|
|
// tot. Das echte Kopf-</head> ist immer das erste.
|
|
$headPos = strpos($html, '</head>');
|
|
if ($headPos !== false) {
|
|
$html = substr($html, 0, $headPos) . $favicon . "\n" . substr($html, $headPos);
|
|
}
|
|
|
|
// Session-Kontext-Script
|
|
$ctx = '<script>window.__GGS__ = ' . json_encode([
|
|
'sessionId' => Session::studentId(),
|
|
'teacherId' => Session::teacherId(),
|
|
'baseUrl' => BASE_URL,
|
|
'basePath' => BASE_PATH,
|
|
], JSON_UNESCAPED_UNICODE) . ';</script>';
|
|
|
|
// Vor LETZTEM </body> einfügen (nicht in JS-Strings injizieren)
|
|
$bodyPos = strrpos($html, '</body>');
|
|
if ($bodyPos !== false) {
|
|
$html = substr($html, 0, $bodyPos) . $ctx . "\n" . substr($html, $bodyPos);
|
|
} else {
|
|
$html .= "\n" . $ctx;
|
|
}
|
|
echo $html;
|
|
}
|