Fake-Werbung (Admin-Joke): Skyscraper-Banner
- API: fake_ads (public), fake_ads_all/create/toggle/delete (admin-only via requireAdminApi) - admin.php: Karte zum Anlegen/Aktivieren/Loeschen von Fake-Anzeigen - play.html: linke/rechte Skyscraper-Platzhalter, pollen aktive Ads und rotieren (nur Desktop) - Reiner Joke, keine echten Werbenetzwerke Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
997ab41afd
commit
1d3feeb2fe
3 changed files with 150 additions and 1 deletions
48
api.php
48
api.php
|
|
@ -356,6 +356,14 @@ function performResolveRound(PDO $pdo, string $code, int $now): array
|
|||
return loadRoom($pdo, $code);
|
||||
}
|
||||
|
||||
function requireAdminApi(PDO $pdo, $authUserId): void
|
||||
{
|
||||
if (!$authUserId) respond(['error' => 'Bitte erst einloggen.'], 401);
|
||||
$st = $pdo->prepare('SELECT role FROM gtl_users WHERE id = ?');
|
||||
$st->execute([$authUserId]);
|
||||
if ($st->fetchColumn() !== 'admin') respond(['error' => 'Keine Berechtigung.'], 403);
|
||||
}
|
||||
|
||||
$cfg = require __DIR__ . '/config.php';
|
||||
|
||||
try {
|
||||
|
|
@ -870,6 +878,46 @@ try {
|
|||
respond(['ok' => true]);
|
||||
break;
|
||||
|
||||
// ── Fake-Werbung (Admin-Joke) ─────────────────────────────────
|
||||
case 'fake_ads':
|
||||
// Öffentlich: aktive Fake-Ads fürs Polling im Frontend
|
||||
$rows = $pdo->query('SELECT id, image_url, target_url FROM gtl_fake_ads WHERE is_active=1 ORDER BY id DESC')->fetchAll();
|
||||
respond(['ok' => true, 'ads' => $rows]);
|
||||
break;
|
||||
|
||||
case 'fake_ads_all':
|
||||
requireAdminApi($pdo, $authUserId);
|
||||
$rows = $pdo->query('SELECT id, image_url, target_url, is_active, created_at FROM gtl_fake_ads ORDER BY id DESC')->fetchAll();
|
||||
respond(['ok' => true, 'ads' => $rows]);
|
||||
break;
|
||||
|
||||
case 'fake_ad_create':
|
||||
requireAdminApi($pdo, $authUserId);
|
||||
$body = input();
|
||||
$img = substr(trim((string) ($body['image_url'] ?? '')), 0, 500);
|
||||
$target= substr(trim((string) ($body['target_url'] ?? '')), 0, 500);
|
||||
if ($img === '') respond(['error' => 'Bild-URL erforderlich.'], 400);
|
||||
$pdo->prepare('INSERT INTO gtl_fake_ads (image_url, target_url, is_active, created_at) VALUES (?,?,1,?)')
|
||||
->execute([$img, $target !== '' ? $target : null, $now]);
|
||||
respond(['ok' => true, 'id' => (int) $pdo->lastInsertId()]);
|
||||
break;
|
||||
|
||||
case 'fake_ad_toggle':
|
||||
requireAdminApi($pdo, $authUserId);
|
||||
$body = input();
|
||||
$id = (int) ($body['id'] ?? 0);
|
||||
$pdo->prepare('UPDATE gtl_fake_ads SET is_active = 1 - is_active WHERE id = ?')->execute([$id]);
|
||||
respond(['ok' => true]);
|
||||
break;
|
||||
|
||||
case 'fake_ad_delete':
|
||||
requireAdminApi($pdo, $authUserId);
|
||||
$body = input();
|
||||
$id = (int) ($body['id'] ?? 0);
|
||||
$pdo->prepare('DELETE FROM gtl_fake_ads WHERE id = ?')->execute([$id]);
|
||||
respond(['ok' => true]);
|
||||
break;
|
||||
|
||||
default:
|
||||
respond(['error' => 'Unbekannte Aktion.'], 400);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue