LuminaWebsite/includes/settings.php
Maaxxs 0f097dda87 Calendar: raids and events as a monthly view plus member entries with "I'm in"
- calendar.php: raids and events live from the bot API (no duplicate data), recurring events projected forward, agenda list, mobile view with dots
- Optionally public (without login, titles and times only), linked on the homepage
- Members add their own entries (calendar_entries), participants via "I'm in", same protections as comments (filter, approval, report button, rate limit)
- Moderation also covers calendar entries

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-21 22:26:17 +02:00

60 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
/**
* Einstellungen der Website, die die Leitung in der Oberflaeche aendert (Tabelle settings).
* Fehlt ein Eintrag, gilt der Standardwert aus dem Code.
*/
// Einstellungen, die ueber admin/settings_action.php geaendert werden duerfen: Schluessel => Standardwert.
const SETTINGS_DEFAULTS = [
'discord_unlink_allowed' => '1',
'contributions_history_public' => '1',
// Moderation: alle neuen Bilder/Kommentare warten auf Freigabe (z.B. bei einer Spam-Welle)
'moderation_all' => '0',
// Kalender auch ohne Anmeldung sichtbar (nur Titel und Uhrzeit)
'calendar_public' => '0',
];
// Wer eine Einstellung aendern darf und wohin es danach zurueckgeht.
const SETTINGS_ACCESS = [
'discord_unlink_allowed' => ['users.edit', '/admin/users.php'],
'contributions_history_public' => ['contributions.manage', '/contributions.php#verlauf'],
'moderation_all' => ['comments.moderate', '/moderation.php'],
'calendar_public' => ['events.manage', '/calendar.php'],
];
function setting_get(string $key): string
{
static $cache = null;
if ($cache === null) {
$cache = [];
try {
foreach (db()->query('SELECT `key`, value FROM settings')->fetchAll() as $row) {
$cache[$row['key']] = (string) $row['value'];
}
} catch (PDOException $e) {
// Tabelle (noch) nicht vorhanden - Standardwerte verwenden.
}
}
return $cache[$key] ?? (SETTINGS_DEFAULTS[$key] ?? '');
}
function setting_set(string $key, string $value): void
{
db()->prepare('INSERT INTO settings (`key`, value) VALUES (?, ?) ON DUPLICATE KEY UPDATE value = VALUES(value)')
->execute([$key, $value]);
}
/** Ist der Verlauf der Lumipunkte fuer alle sichtbar oder nur fuer contributions.manage? */
function contributions_history_public(): bool
{
return setting_get('contributions_history_public') === '1';
}
/** Duerfen Mitglieder ihre Discord-Verknuepfung selbst loesen? */
function discord_unlink_allowed(): bool
{
return setting_get('discord_unlink_allowed') === '1';
}