Neue Seite Einstellungen > Bilder (Titelbild und Logos dorthin verschoben) plus "Bild tauschen" im Live-Bearbeiten-Modus. Gespeichert als JSON in app_settings.site_images (Auto-Migration). Startseite und SPA-Fallback laufen ueber api/public/page.php, das og:image und Favicon serverseitig ins HTML setzt. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PBCD1KUwiqh1kdMwDSwVfD
84 lines
3.3 KiB
PHP
84 lines
3.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Liefert die index.html der React-App aus (SPA-Fallback, siehe hifi/.htaccess) und setzt
|
|
* dabei die im Admin hinterlegten Bilder ein, die schon im HTML stehen muessen: das
|
|
* Link-Vorschaubild (og:image fuer WhatsApp, Facebook & Co. - deren Vorschau fuehrt kein
|
|
* JavaScript aus) und das Favicon. Ohne eigenes Bild oder wenn die Datenbank nicht
|
|
* erreichbar ist, geht die index.html unveraendert raus - die Seite bleibt also immer
|
|
* erreichbar.
|
|
*/
|
|
|
|
require __DIR__ . '/../vendor/autoload.php';
|
|
|
|
use App\Support\SiteImages;
|
|
|
|
$html = @file_get_contents(__DIR__ . '/../../index.html');
|
|
if ($html === false) {
|
|
http_response_code(500);
|
|
exit('index.html fehlt - bitte "npm run build" ausfuehren.');
|
|
}
|
|
|
|
header('Content-Type: text/html; charset=utf-8');
|
|
header('Cache-Control: no-cache');
|
|
|
|
/** Gespeicherte Bilder lesen - eigene Verbindung, da Database::connection() bei Fehlern JSON ausgibt. */
|
|
function hifi_site_images(): array
|
|
{
|
|
try {
|
|
$config = require __DIR__ . '/../config/config.php';
|
|
$db = $config['db'];
|
|
if (empty($db['host']) || empty($db['name'])) {
|
|
return [];
|
|
}
|
|
$pdo = new PDO(
|
|
"mysql:host={$db['host']};dbname={$db['name']};charset={$db['charset']}",
|
|
$db['user'],
|
|
$db['pass'],
|
|
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_TIMEOUT => 3]
|
|
);
|
|
$raw = $pdo->query('SELECT site_images FROM app_settings WHERE id = 1')->fetchColumn();
|
|
return SiteImages::decode($raw);
|
|
} catch (\Throwable $e) {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
/** Absolute URL auf diesem Server (Vorschau-Dienste brauchen eine volle Adresse). */
|
|
function hifi_absolute_url(string $path): string
|
|
{
|
|
$https = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')
|
|
|| strtolower($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '') === 'https';
|
|
$host = (string) ($_SERVER['HTTP_HOST'] ?? '');
|
|
if (!preg_match('/^[A-Za-z0-9.\-]+(:\d+)?$/', $host)) {
|
|
$config = require __DIR__ . '/../config/config.php';
|
|
return rtrim($config['app']['site_url'], '/') . $path;
|
|
}
|
|
return ($https ? 'https://' : 'http://') . $host . $path;
|
|
}
|
|
|
|
$images = hifi_site_images();
|
|
|
|
if (!empty($images['og_image'])) {
|
|
$url = htmlspecialchars(hifi_absolute_url($images['og_image']), ENT_QUOTES);
|
|
// Alle Verweise auf das eingebaute Vorschaubild (og:image, twitter:image, JSON-LD).
|
|
$html = preg_replace('#https?://[^"\s]*/og-image\.jpg#', $url, $html);
|
|
$size = @getimagesize(__DIR__ . '/../uploads/' . basename($images['og_image']));
|
|
if ($size) {
|
|
$html = preg_replace('#(<meta property="og:image:width" content=")\d+#', '${1}' . (int) $size[0], $html);
|
|
$html = preg_replace('#(<meta property="og:image:height" content=")\d+#', '${1}' . (int) $size[1], $html);
|
|
} else {
|
|
$html = preg_replace('#\s*<meta property="og:image:(width|height)" content="\d+" />#', '', $html);
|
|
}
|
|
}
|
|
|
|
if (!empty($images['favicon'])) {
|
|
$type = str_ends_with($images['favicon'], '.png') ? 'image/png' : (str_ends_with($images['favicon'], '.webp') ? 'image/webp' : 'image/jpeg');
|
|
$html = preg_replace(
|
|
'#<link rel="icon" type="image/png" href="[^"]*" />#',
|
|
'<link rel="icon" type="' . $type . '" href="' . htmlspecialchars($images['favicon'], ENT_QUOTES) . '" />',
|
|
$html
|
|
);
|
|
}
|
|
|
|
echo $html;
|