LuminaWebsite/includes/settings.php
Maaxxs dd7ad2a25b Beitragspunkte: switch for public history, old logo back
Above the history, people with contributions.manage can switch "Verlauf für
alle sichtbar" (default on). Turned off, everyone else sees only the ranking,
without history and without links on the cards. Settings now carry their own
permission and return page, so the same action serves this switch and the
Discord unlink switch in the user list.

The sidebar, login page and mobile top bar show the previous logo again;
the new logo files are removed.

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

54 lines
1.7 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',
];
// 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'],
];
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 Beitragspunkte 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';
}