feat: Website und Hub zweisprachig (Deutsch/Englisch)

Website (rinkplanner.programmschmiede.de) liegt jetzt im Repo unter web/:
Sprachweiche nach Accept-Language (der User-Agent enthält keine Sprache),
/de/ und /en/ als eigene URLs mit hreflang, Cookie für die manuelle Wahl,
Texte in web/i18n.php, Markup in web/template.php. Deployment über
tools/deploy_web.sh (--sync, --check, --all); /index.html leitet weiter.

Hub: optionale englische Oberfläche über den DE/EN-Umschalter, Cookie
RHUB_LANG, Route /language. Alle Texte (Views, Meldungen, Validierung,
API-messages) stehen in hub/app/i18n_strings.php und laufen über t();
Datum und Zahlen folgen der Sprache. Die API behält ihre code-Felder und
antwortet ohne Cookie weiter deutsch.

deploy_hub.sh --check prüft jetzt Schlüsselparität und fehlende t()-Schlüssel.
Doku: docs/website.md neu, docs/hub.md und AGENTS.md ergänzt.
This commit is contained in:
torsten 2026-11-12 22:38:32 +01:00
parent 6c8dc942e8
commit 9819311403
41 changed files with 2801 additions and 326 deletions

View file

@ -90,7 +90,7 @@ function api_handle(string $method, string $path): void
if ($path === '/api/v1/tokens') {
if ($method !== 'POST') {
abort_api(405, 'method_not_allowed', 'Nur POST ist erlaubt.');
abort_api(405, 'method_not_allowed', t('api.post_only'));
}
api_create_token();
return;
@ -100,7 +100,7 @@ function api_handle(string $method, string $path): void
if ($path === '/api/v1/me') {
if ($method !== 'GET') {
abort_api(405, 'method_not_allowed', 'Nur GET ist erlaubt.');
abort_api(405, 'method_not_allowed', t('api.get_only'));
}
json_response([
'id' => (int) $user['id'],
@ -128,7 +128,7 @@ function api_handle(string $method, string $path): void
if ($method === 'POST') {
api_upload($user, null);
}
abort_api(405, 'method_not_allowed', 'Nur GET oder POST ist erlaubt.');
abort_api(405, 'method_not_allowed', t('api.get_or_post'));
}
if (preg_match('#^/api/v1/routines/(\d+)$#', $path, $matches) === 1) {
@ -137,20 +137,20 @@ function api_handle(string $method, string $path): void
}
if (preg_match('#^/api/v1/routines/(\d+)/(download|audio)$#', $path, $matches) === 1) {
if ($method !== 'GET') {
abort_api(405, 'method_not_allowed', 'Nur GET ist erlaubt.');
abort_api(405, 'method_not_allowed', t('api.get_only'));
}
$routine = api_fetch_visible((int) $matches[1], $user);
routine_send_file($routine, (string) $matches[2], $user, true);
}
if (preg_match('#^/api/v1/routines/(\d+)/revisions$#', $path, $matches) === 1) {
if ($method !== 'POST') {
abort_api(405, 'method_not_allowed', 'Nur POST ist erlaubt.');
abort_api(405, 'method_not_allowed', t('api.post_only'));
}
api_upload($user, (int) $matches[1]);
return;
}
abort_api(404, 'not_found', 'Unbekannter API-Pfad.');
abort_api(404, 'not_found', t('api.unknown_path'));
}
function api_create_token(): void
@ -160,7 +160,7 @@ function api_create_token(): void
$password = (string) ($input['password'] ?? '');
$name = trim((string) ($input['name'] ?? 'App'));
if ($login === '' || $password === '') {
abort_api(422, 'invalid_credentials', 'Benutzername und Passwort sind erforderlich.');
abort_api(422, 'invalid_credentials', t('api.credentials_required'));
}
$result = auth_attempt($login, $password);
if (!$result['ok']) {
@ -172,7 +172,7 @@ function api_create_token(): void
}
$user = $result['user'];
if ((int) ($user['must_change_password'] ?? 0) === 1) {
abort_api(403, 'password_change_required', 'Bitte zuerst im Web das Passwort ändern.');
abort_api(403, 'password_change_required', t('api.change_password_web'));
}
$created = token_create((int) $user['id'], $name);
json_response([
@ -191,10 +191,10 @@ function api_fetch_visible(int $id, array $user): array
{
$routine = routine_fetch($id);
if ($routine === null) {
abort_api(404, 'not_found', 'Kür nicht gefunden.');
abort_api(404, 'not_found', t('routine.not_found_short'));
}
if (!routine_can_view($routine, $user)) {
abort_api(403, 'forbidden', 'Diese Kür ist nicht freigegeben.');
abort_api(403, 'forbidden', t('routine.forbidden'));
}
return $routine;
}
@ -207,26 +207,26 @@ function api_routine(int $id, string $method, array $user): void
}
if ($method === 'DELETE') {
if (!routine_can_edit($routine, $user)) {
abort_api(403, 'forbidden', 'Nur der Eigentümer oder ein Admin darf die Kür ändern.');
abort_api(403, 'forbidden', t('api.edit_forbidden'));
}
routine_set_status($id, 'hidden');
json_response(['id' => $id, 'status' => 'hidden']);
}
abort_api(405, 'method_not_allowed', 'Nur GET oder DELETE ist erlaubt.');
abort_api(405, 'method_not_allowed', t('api.get_or_delete'));
}
function api_upload(array $user, ?int $routineId): void
{
if (!api_truthy($_POST['rights'] ?? null)) {
abort_api(422, 'rights_required', 'Bitte bestätigen, dass Kür und Musik geteilt werden dürfen.');
abort_api(422, 'rights_required', t('api.rights_required'));
}
if (!routine_upload_quota_ok((int) $user['id'])) {
abort_api(429, 'upload_limit', 'Stündliches Upload-Limit erreicht.');
abort_api(429, 'upload_limit', t('api.upload_limit'));
}
$package = routine_validate_package($_POST);
if (!$package['ok']) {
json_response([
'error' => ['code' => 'validation_failed', 'message' => 'Die Dateien sind nicht gültig.'],
'error' => ['code' => 'validation_failed', 'message' => t('api.invalid_files')],
'errors' => $package['errors'],
], 422);
}
@ -234,22 +234,22 @@ function api_upload(array $user, ?int $routineId): void
if ($routineId === null) {
$duplicate = routine_duplicate_exists((int) $user['id'], $package);
if ($duplicate !== null) {
abort_api(409, 'duplicate', 'Diese Kür ist bereits im Hub (ID ' . $duplicate . ').');
abort_api(409, 'duplicate', t('api.duplicate', ['id' => $duplicate]));
}
$routineId = routine_create((int) $user['id'], $package);
} else {
$routine = routine_fetch($routineId);
if ($routine === null) {
abort_api(404, 'not_found', 'Kür nicht gefunden.');
abort_api(404, 'not_found', t('routine.not_found_short'));
}
if (!routine_can_edit($routine, $user)) {
abort_api(403, 'forbidden', 'Nur der Eigentümer oder ein Admin darf die Kür ändern.');
abort_api(403, 'forbidden', t('api.edit_forbidden'));
}
routine_add_revision($routineId, (int) $user['id'], $package);
}
$created = routine_fetch($routineId);
if ($created === null) {
abort_api(500, 'server_error', 'Kür konnte nicht geladen werden.');
abort_api(500, 'server_error', t('api.routine_load_failed'));
}
json_response(api_routine_payload($created), 201);
}

View file

@ -157,7 +157,7 @@ function auth_require_admin(): array
{
$user = auth_require_login();
if ($user['role'] !== 'admin') {
abort_page(403, 'Dieser Bereich ist nur für Administratoren.');
abort_page(403, t('auth.admin_only'));
}
return $user;
}
@ -190,7 +190,7 @@ function auth_attempt(string $login, string $password): array
$retry = max(60, (int) $first + $window - time());
return [
'ok' => false,
'error' => 'Zu viele Fehlversuche. Bitte in ' . max(1, (int) ceil($retry / 60)) . ' Minuten erneut versuchen.',
'error' => t('login.error.rate_limited', ['minutes' => max(1, (int) ceil($retry / 60))]),
'retry' => $retry,
];
}
@ -213,10 +213,10 @@ function auth_attempt(string $login, string $password): array
}
if (!$user || !$valid) {
return ['ok' => false, 'error' => 'Benutzername oder Passwort ist falsch.', 'retry' => 0];
return ['ok' => false, 'error' => t('login.error.credentials'), 'retry' => 0];
}
if ($user['status'] !== 'active') {
return ['ok' => false, 'error' => 'Dieses Konto ist deaktiviert.', 'retry' => 0];
return ['ok' => false, 'error' => t('login.error.disabled'), 'retry' => 0];
}
if (password_needs_upgrade((string) $user['password_hash'])) {
db()->prepare('UPDATE users SET password_hash = ? WHERE id = ?')

View file

@ -25,6 +25,7 @@ date_default_timezone_set('UTC');
ini_set('display_errors', '0');
ini_set('log_errors', '1');
require HUB_APP . '/i18n.php';
require HUB_APP . '/util.php';
require HUB_APP . '/db.php';
require HUB_APP . '/auth.php';
@ -42,14 +43,16 @@ if (is_dir($storage) && is_writable($storage)) {
set_exception_handler(static function (Throwable $error): void {
error_log('Hub: ' . $error::class . ': ' . $error->getMessage() . ' in ' . $error->getFile() . ':' . $error->getLine());
if (function_exists('wants_json') && wants_json()) {
json_response(['error' => ['code' => 'server_error', 'message' => 'Interner Fehler.']], 500);
json_response(['error' => ['code' => 'server_error', 'message' => t('api.server_error')]], 500);
return;
}
http_response_code(500);
header('Content-Type: text/html; charset=utf-8');
echo '<!doctype html><meta charset="utf-8"><title>Fehler</title>'
$title = function_exists('t') ? t('page.title_error', ['status' => 500]) : 'Fehler 500';
$hint = function_exists('t') ? t('api.server_error') : 'Interner Fehler.';
echo '<!doctype html><meta charset="utf-8"><title>' . e($title) . '</title>'
. '<body style="font-family:system-ui;background:#050d19;color:#eefaff;padding:2rem">'
. '<h1>Interner Fehler</h1><p>Bitte später erneut versuchen.</p></body>';
. '<h1>' . e($hint) . '</h1></body>';
});
security_headers();

71
hub/app/i18n.php Normal file
View file

@ -0,0 +1,71 @@
<?php
declare(strict_types=1);
/**
* Texte der Hub-Oberfläche (Deutsch und Englisch).
*
* Die Sprache kommt aus dem Cookie RHUB_LANG und wird ausschließlich über den
* DE/EN-Umschalter gesetzt (Route /language). Standard ist Deutsch; der Hub
* ist eine geschlossene Beta und schaltet nicht automatisch um.
*
* t() liefert Text mit eingesetzten Platzhaltern ({name}); die Ausgabe wird
* an der Aufrufstelle mit e() maskiert. In den Texten steht kein HTML.
*/
const HUB_LOCALES = ['de', 'en'];
const HUB_DEFAULT_LOCALE = 'de';
const HUB_LOCALE_COOKIE = 'RHUB_LANG';
function hub_locale(): string
{
static $locale = null;
if ($locale !== null) {
return $locale;
}
$raw = strtolower(substr((string) ($_COOKIE[HUB_LOCALE_COOKIE] ?? ''), 0, 2));
$locale = in_array($raw, HUB_LOCALES, true) ? $raw : HUB_DEFAULT_LOCALE;
return $locale;
}
function hub_locale_set(string $locale): void
{
$locale = strtolower(substr($locale, 0, 2));
if (!in_array($locale, HUB_LOCALES, true)) {
return;
}
if (!headers_sent()) {
setcookie(HUB_LOCALE_COOKIE, $locale, [
'expires' => time() + 365 * 86400,
'path' => '/',
'secure' => is_https(),
'httponly' => false,
'samesite' => 'Lax',
]);
}
$_COOKIE[HUB_LOCALE_COOKIE] = $locale;
}
function hub_strings(): array
{
static $strings = null;
if ($strings === null) {
$strings = require HUB_APP . '/i18n_strings.php';
}
return $strings;
}
/** Text in der aktuellen Sprache; unbekannte Schlüssel geben den Schlüssel zurück. */
function t(string $key, array $args = []): string
{
$strings = hub_strings();
$locale = hub_locale();
$text = $strings[$locale][$key] ?? $strings[HUB_DEFAULT_LOCALE][$key] ?? $key;
if ($args !== []) {
$replace = [];
foreach ($args as $name => $value) {
$replace['{' . $name . '}'] = (string) $value;
}
$text = strtr($text, $replace);
}
return $text;
}

664
hub/app/i18n_strings.php Normal file
View file

@ -0,0 +1,664 @@
<?php
declare(strict_types=1);
/** Textkatalog des Hubs. Beide Sprachen müssen dieselben Schlüssel haben. */
return [
'de' => [
// Rahmen
'app.name' => 'Rinkplanner-Hub',
'nav.routines' => 'Küren',
'nav.upload' => 'Hochladen',
'nav.admin' => 'Verwaltung',
'nav.logout' => 'Abmelden',
'nav.login' => 'Anmelden',
'nav.language' => 'Sprache',
'footer.beta' => 'Geschlossene Beta · Rinkplanner-Hub',
'footer.website' => 'Zur Rinkplanner-Seite',
'flash.secret' => 'Geheimnis',
'page.title_default' => 'Kür-Hub',
'page.title_error' => 'Fehler {status}',
// Seitentitel
'page.login' => 'Anmelden',
'page.register' => 'Registrieren',
'page.dashboard' => 'Küren',
'page.upload' => 'Kür hochladen',
'page.revision' => 'Neue Revision',
'page.account' => 'Konto',
'page.admin_invites' => 'Einladungen',
'page.admin_users' => 'Benutzer',
'page.admin_routines' => 'Alle Küren',
'page.admin_audit' => 'Audit-Log',
// Anmeldung
'login.title' => 'Anmelden',
'login.lede' => 'Der Kür-Hub ist in einer geschlossenen Beta. Zugang gibt es per Einladungscode.',
'login.login_label' => 'Benutzername oder E-Mail',
'login.password' => 'Passwort',
'login.remember' => 'Angemeldet bleiben (30 Tage)',
'login.submit' => 'Anmelden',
'login.no_access' => 'Noch keinen Zugang? Ein Beta-Code kommt von der Hub-Administration.',
// Registrierung
'register.title' => 'Beta-Zugang einlösen',
'register.lede' => 'Ein Einladungscode legt genau ein Konto an. Der Code verliert danach seine Gültigkeit.',
'register.code' => 'Einladungscode',
'register.username' => 'Benutzername',
'register.username_hint' => '3–32 Zeichen, nur Kleinbuchstaben, Ziffern, Punkt, Bindestrich, Unterstrich.',
'register.display_name' => 'Anzeigename',
'register.email' => 'E-Mail (optional)',
'register.email_bound' => 'Diese Einladung ist an {email} gebunden.',
'register.password' => 'Passwort',
'register.password_repeat' => 'Passwort wiederholen',
'register.password_hint' => 'Mindestens 10 Zeichen.',
'register.rights' => 'Ich akzeptiere die Beta-Regeln und teile keine Inhalte, an denen ich keine Rechte habe.',
'register.submit' => 'Konto anlegen',
'register.have_account' => 'Schon ein Konto?',
'register.login_link' => 'Anmelden',
// Übersicht
'dashboard.eyebrow' => 'Viele Schlittschuhe, ein Netz',
'dashboard.hero_title' => 'Küren teilen, Fassungen vergleichen, gemeinsam weiterentwickeln.',
'dashboard.hero_sub' => 'Der Hub sammelt Küren, Musik und Revisionen deines Teams an einem Ort.',
'dashboard.title' => 'Küren',
'dashboard.count' => '{count} {label} im Hub',
'dashboard.one_routine' => 'Kür',
'dashboard.many_routines' => 'Küren',
'dashboard.mine_suffix' => ' (nur deine)',
'dashboard.upload' => 'Kür hochladen',
'dashboard.search_placeholder' => 'Titel, Skater, Musik, Benutzer …',
'dashboard.search' => 'Suchen',
'dashboard.all' => 'Alle',
'dashboard.mine' => 'Meine Küren',
'dashboard.empty' => 'Keine Küren gefunden.',
'dashboard.empty_hint' => 'Suche zurücksetzen oder',
'dashboard.empty_upload' => 'selbst eine Kür hochladen',
'dashboard.empty_first' => 'Der Hub ist noch leer.',
'dashboard.empty_first_action' => 'Erste Kür hochladen',
'badge.hidden' => 'versteckt',
// Tabellen
'table.title' => 'Titel',
'table.skater' => 'Skater',
'table.music' => 'Musik',
'table.revision' => 'Rev.',
'table.size' => 'Größe',
'table.updated' => 'Aktualisiert',
'table.by' => 'Von',
'table.name' => 'Name',
'table.prefix' => 'Prefix',
'table.created' => 'Erstellt',
'table.last_used' => 'Zuletzt',
'table.status' => 'Status',
'table.role' => 'Rolle',
'table.routines' => 'Küren',
'table.registered' => 'Registriert',
'table.last_login' => 'Letzte Anmeldung',
'table.actions' => 'Aktionen',
'table.downloads' => 'Downloads',
'table.email' => 'E-Mail',
'table.note' => 'Notiz',
'table.valid_until' => 'Gültig bis',
'table.from_to' => 'Von / an',
'table.time' => 'Zeit',
'table.actor' => 'Akteur',
'table.action' => 'Aktion',
'table.subject' => 'Objekt',
'table.detail' => 'Detail',
'table.ip' => 'IP',
'pagination.back' => '← Zurück',
'pagination.next' => 'Weiter →',
'pagination.page' => 'Seite {page} von {pages}',
// Kür-Detail
'routine.breadcrumb' => 'Küren',
'routine.breadcrumb_current' => 'Kür',
'routine.revision' => 'Revision {revision}',
'routine.download' => 'Kür herunterladen',
'routine.download_audio' => 'Musik herunterladen',
'routine.owner_bar' => 'Du kannst diese Kür verwalten.',
'routine.new_revision' => 'Neue Revision hochladen',
'routine.hide' => 'Aus dem Hub nehmen',
'routine.publish' => 'Wieder veröffentlichen',
'routine.open_admin' => 'In der Verwaltung öffnen',
'routine.description' => 'Beschreibung',
'routine.music' => 'Musik',
'routine.details' => 'Details',
'routine.category' => 'Kategorie',
'routine.music_title' => 'Musiktitel',
'routine.music_artist' => 'Musik',
'routine.routine_file' => 'Kür-Datei',
'routine.audio_file' => 'Audio-Datei',
'routine.checksums' => 'Prüfsummen',
'routine.checksum_hint' => 'Beim Download prüfen, ob die SHA-256-Summe zur Kür passt.',
// Upload
'upload.title_new' => 'Kür hochladen',
'upload.title_revision' => 'Neue Revision',
'upload.revision_lede' => 'Neue Fassung von „{title}“. Die bisherige Revision bleibt erhalten.',
'upload.lede' => 'Lade die Kür-JSON und – falls die Kür Musik nutzt – die zugehörige Audiodatei hoch. Beide gehören als Paket zusammen.',
'upload.routine_file' => 'Kür-Datei (.json)',
'upload.routine_hint' => 'Aus Rinkplanner gespeicherte Kür, max. {max}.',
'upload.audio_file' => 'Musikdatei (MP3/OGG/WAV/M4A/AAC)',
'upload.audio_hint' => 'Dateiname muss exakt dem Feld „music_file“ der Kür entsprechen.',
'upload.description' => 'Beschreibung (optional)',
'upload.music_title' => 'Musiktitel (optional)',
'upload.artist' => 'Interpret (optional)',
'upload.rights' => 'Ich habe die Rechte an Kür und Musik und darf sie im geschlossenen Beta-Hub teilen.',
'upload.submit_new' => 'Kür veröffentlichen',
'upload.submit_revision' => 'Revision veröffentlichen',
'upload.cancel' => 'Abbrechen',
// Konto
'account.title' => 'Konto',
'account.role_admin' => 'Administrator',
'account.role_user' => 'Beta-Nutzer',
'account.must_change' => 'Bitte ein neues Passwort setzen, bevor du den Hub weiter nutzt.',
'account.change_password' => 'Passwort ändern',
'account.current_password' => 'Aktuelles Passwort',
'account.new_password' => 'Neues Passwort',
'account.repeat_password' => 'Neues Passwort wiederholen',
'account.password_hint' => 'Mindestens 10 Zeichen.',
'account.save_password' => 'Passwort speichern',
'account.tokens' => 'API-Tokens',
'account.tokens_lede' => 'Für die Godot-App. Ein Token ersetzt Benutzername und Passwort im Client und lässt sich jederzeit widerrufen.',
'account.token_placeholder' => 'Name, z. B. Büro-PC',
'account.token_create' => 'Token erzeugen',
'account.token_active' => 'aktiv',
'account.token_revoked' => 'widerrufen',
'account.token_revoke' => 'widerrufen',
'account.no_tokens' => 'Noch kein Token erzeugt.',
// Verwaltung
'admin.title' => 'Verwaltung',
'admin.tab_invites' => 'Einladungen',
'admin.tab_users' => 'Benutzer',
'admin.tab_routines' => 'Küren',
'admin.tab_audit' => 'Audit-Log',
'admin.audit_lede' => 'Die letzten {count} Ereignisse.',
'admin.audit_empty' => 'Noch keine Einträge.',
'admin_invites.lede' => 'Einladungen für die geschlossene Beta.',
'admin_invites.new' => 'Neue Einladung',
'admin_invites.new_lede' => 'Der Code wird nach dem Anlegen genau einmal angezeigt. Er gilt für ein Konto.',
'admin_invites.note' => 'Notiz (intern)',
'admin_invites.note_placeholder' => 'z. B. Verein Nord',
'admin_invites.email' => 'E-Mail binden (optional)',
'admin_invites.email_hint' => 'Nur diese Adresse kann den Code nutzen.',
'admin_invites.days' => 'Gültig (Tage)',
'admin_invites.days_hint' => '0 = unbegrenzt.',
'admin_invites.create' => 'Einladung erzeugen',
'admin_invites.list' => 'Einladungen',
'admin_invites.empty' => 'Noch keine Einladungen.',
'admin_invites.revoke' => 'widerrufen',
'admin_users.lede' => 'Beta-Konten verwalten.',
'admin_users.self' => 'eigenes Konto',
'admin_users.block' => 'sperren',
'admin_users.unblock' => 'entsperren',
'admin_users.reset' => 'Passwort zurücksetzen',
'admin_users.delete' => 'löschen',
'admin_users.delete_confirm' => 'mit allen Küren löschen',
'admin_users.delete_submit' => 'Löschen bestätigen',
'admin_users.role_admin' => 'Admin',
'admin_users.role_user' => 'Nutzer',
'status.active' => 'aktiv',
'status.blocked' => 'gesperrt',
'admin_routines.lede' => '{total} Küren insgesamt, auch versteckte.',
'admin_routines.search_placeholder' => 'Titel, Skater, Benutzer …',
'admin_routines.empty' => 'Keine Küren gefunden.',
'admin_routines.hide' => 'verstecken',
'admin_routines.publish' => 'veröffentlichen',
'admin_routines.delete' => 'löschen',
'admin_routines.delete_confirm' => 'endgültig löschen',
'admin_routines.delete_submit' => 'Löschen bestätigen',
// Status einer Einladung
'invite.status.open' => 'offen',
'invite.status.used' => 'eingelöst',
'invite.status.expired' => 'abgelaufen',
'invite.status.revoked' => 'widerrufen',
// Fehlerseite
'error.label' => 'Fehler {status}',
'error.back' => 'Zurück zur',
'error.back_link' => 'Küren-Übersicht',
// Meldungen
'auth.admin_only' => 'Dieser Bereich ist nur für Administratoren.',
'auth.change_password_first' => 'Bitte zuerst das Passwort ändern.',
'auth.logged_out' => 'Abgemeldet.',
'auth.welcome' => 'Willkommen im Kür-Hub!',
'auth.session_expired' => 'Die Sitzung ist abgelaufen. Bitte die Seite neu laden.',
'page.method_not_allowed' => 'Diese Methode ist nicht erlaubt.',
'page.not_found' => 'Diese Seite gibt es nicht.',
'username.length' => 'Der Benutzername muss 3 bis 32 Zeichen lang sein.',
'username.charset' => 'Nur Kleinbuchstaben, Ziffern, Punkt, Bindestrich und Unterstrich; Anfang und Ende alphanumerisch.',
'username.reserved' => 'Dieser Benutzername ist reserviert.',
'register.invalid_invite' => 'Dieser Einladungscode ist ungültig, abgelaufen oder bereits eingelöst.',
'register.display_name_long' => 'Der Anzeigename darf höchstens 64 Zeichen lang sein.',
'register.email_invalid' => 'Die E-Mail-Adresse ist nicht gültig.',
'register.email_mismatch' => 'Diese Einladung ist an eine andere E-Mail-Adresse gebunden.',
'register.password_mismatch' => 'Die Passwortwiederholung passt nicht.',
'register.rights_required' => 'Bitte die Beta-Regeln akzeptieren.',
'register.invite_taken' => 'Der Einladungscode wurde gerade eingelöst. Bitte einen neuen Code anfordern.',
'register.username_taken' => 'Dieser Benutzername ist schon vergeben.',
'register.email_taken' => 'Diese E-Mail-Adresse ist schon registriert.',
'routine.not_found' => 'Diese Kür gibt es nicht.',
'routine.forbidden' => 'Diese Kür ist nicht freigegeben.',
'routine.edit_forbidden' => 'Nur der Eigentümer oder ein Admin kann diese Kür ändern.',
'upload.quota' => 'Stündliches Upload-Limit erreicht. Bitte später erneut versuchen.',
'upload.rights_confirm' => 'Bitte bestätigen, dass du Kür und Musik teilen darfst.',
'upload.duplicate' => 'Diese Kür ist bereits im Hub.',
'upload.published' => 'Kür veröffentlicht.',
'upload.save_failed' => 'Die Kür konnte nicht gespeichert werden.',
'revision.saved' => 'Neue Revision {revision} gespeichert.',
'revision.save_failed' => 'Die Revision konnte nicht gespeichert werden.',
'routine.published_again' => 'Kür ist wieder sichtbar.',
'routine.hidden_now' => 'Kür wurde aus dem Hub genommen.',
'account.current_wrong' => 'Das aktuelle Passwort ist falsch.',
'account.password_changed' => 'Passwort geändert. Andere Sitzungen wurden abgemeldet.',
'token.created' => 'Neuer API-Token – jetzt kopieren, er wird nicht erneut angezeigt',
'token.revoked' => 'Token widerrufen.',
'token.not_found' => 'Token nicht gefunden.',
'invite.created' => 'Einladung erstellt.',
'invite.created_label' => 'Einladungscode',
'invite.revoked' => 'Einladung widerrufen.',
'invite.revoke_failed' => 'Einladung konnte nicht widerrufen werden.',
'user.not_found' => 'Benutzer nicht gefunden.',
'user.self_change' => 'Das eigene Konto lässt sich hier nicht ändern.',
'user.disabled' => 'Benutzer deaktiviert.',
'user.enabled' => 'Benutzer aktiviert.',
'user.temp_password' => 'Temporäres Passwort für {user}',
'user.must_change' => 'Der Benutzer muss das Passwort bei der nächsten Anmeldung ändern.',
'user.delete_confirm_required' => 'Löschen muss bestätigt werden.',
'user.deleted' => 'Benutzer und zugehörige Küren gelöscht.',
'action.unknown' => 'Unbekannte Aktion.',
'routine.not_found_short' => 'Kür nicht gefunden.',
'admin.status_changed' => 'Status geändert.',
'routine.deleted' => 'Kür endgültig gelöscht.',
// Anmeldung und Passwortregeln
'login.error.rate_limited' => 'Zu viele Fehlversuche. Bitte in {minutes} Minuten erneut versuchen.',
'login.error.credentials' => 'Benutzername oder Passwort ist falsch.',
'login.error.disabled' => 'Dieses Konto ist deaktiviert.',
'password.min' => 'Das Passwort muss mindestens 10 Zeichen lang sein.',
'password.max' => 'Das Passwort darf höchstens 200 Zeichen lang sein.',
'password.same_as_username' => 'Das Passwort darf nicht dem Benutzernamen entsprechen.',
// Upload-Prüfung
'upload.select_routine' => 'Bitte eine Kür-Datei (.json) auswählen.',
'upload.invalid' => 'Ungültiger Upload.',
'upload.routine_too_large' => 'Die Kür-Datei ist zu groß (max. {max}).',
'upload.routine_not_json' => 'Kürdateien müssen im JSON-Format vorliegen (.json).',
'upload.read_failed' => 'Die Kür-Datei konnte nicht gelesen werden.',
'upload.invalid_json' => 'Die Kür-Datei ist kein gültiges JSON.',
'upload.no_json_object' => 'Die Kür-Datei enthält kein JSON-Objekt.',
'upload.not_rinkplanner' => 'Das ist keine Rinkplanner-Kür (format fehlt oder ist falsch).',
'upload.unsupported_version' => 'Diese Kür-Formatversion wird nicht unterstützt.',
'upload.no_sections' => 'Die Kür enthält keine Abschnittsliste.',
'upload.too_many_sections' => 'Die Kür hat zu viele Abschnitte (max. 500).',
'upload.title_required' => 'Die Kür braucht einen Titel.',
'upload.bad_music_name' => 'Die Kür verweist auf einen ungültigen Musikdateinamen.',
'upload.music_missing' => 'Die Kür verweist auf „{name}“. Bitte die passende Audiodatei mit hochladen.',
'upload.music_unexpected' => 'Die Kür verweist auf keine Musikdatei; die Audiodatei passt nicht dazu.',
'upload.audio_invalid' => 'Ungültiger Audio-Upload.',
'upload.audio_too_large' => 'Die Audiodatei ist zu groß (max. {max}).',
'upload.audio_name_mismatch' => 'Die Audiodatei heißt „{actual}“, die Kür verweist aber auf „{expected}“.',
'upload.audio_format' => 'Die Audiodatei ist kein unterstütztes Format (MP3, OGG, WAV, M4A, AAC).',
'upload.file_too_large' => 'Die Datei ist zu groß.',
'upload.interrupted' => 'Der Upload wurde unterbrochen.',
'upload.no_file_chosen' => 'Es wurde keine Datei ausgewählt.',
'upload.store_failed' => 'Die Datei konnte nicht gespeichert werden.',
'upload.unknown_error' => 'Unbekannter Upload-Fehler.',
'routine.no_file_yet' => 'Diese Kür hat noch keine Datei.',
'routine.file_missing' => 'Die Datei fehlt im Speicher.',
'routine.file_unreadable' => 'Die Datei konnte nicht geöffnet werden.',
// API
'api.post_only' => 'Nur POST ist erlaubt.',
'api.get_only' => 'Nur GET ist erlaubt.',
'api.get_or_post' => 'Nur GET oder POST ist erlaubt.',
'api.get_or_delete' => 'Nur GET oder DELETE ist erlaubt.',
'api.unknown_path' => 'Unbekannter API-Pfad.',
'api.bearer_missing' => 'Bearer-Token fehlt.',
'api.token_invalid' => 'Token ist ungültig, abgelaufen oder widerrufen.',
'api.credentials_required' => 'Benutzername und Passwort sind erforderlich.',
'api.change_password_web' => 'Bitte zuerst im Web das Passwort ändern.',
'api.edit_forbidden' => 'Nur der Eigentümer oder ein Admin darf die Kür ändern.',
'api.rights_required' => 'Bitte bestätigen, dass Kür und Musik geteilt werden dürfen.',
'api.upload_limit' => 'Stündliches Upload-Limit erreicht.',
'api.invalid_files' => 'Die Dateien sind nicht gültig.',
'api.duplicate' => 'Diese Kür ist bereits im Hub (ID {id}).',
'api.server_error' => 'Interner Fehler.',
'api.routine_load_failed' => 'Kür konnte nicht geladen werden.',
],
'en' => [
// Frame
'app.name' => 'Rinkplanner Hub',
'nav.routines' => 'Programmes',
'nav.upload' => 'Upload',
'nav.admin' => 'Administration',
'nav.logout' => 'Sign out',
'nav.login' => 'Sign in',
'nav.language' => 'Language',
'footer.beta' => 'Closed beta · Rinkplanner Hub',
'footer.website' => 'To the Rinkplanner website',
'flash.secret' => 'Secret',
'page.title_default' => 'Programme hub',
'page.title_error' => 'Error {status}',
// Page titles
'page.login' => 'Sign in',
'page.register' => 'Register',
'page.dashboard' => 'Programmes',
'page.upload' => 'Upload programme',
'page.revision' => 'New revision',
'page.account' => 'Account',
'page.admin_invites' => 'Invitations',
'page.admin_users' => 'Users',
'page.admin_routines' => 'All programmes',
'page.admin_audit' => 'Audit log',
// Sign in
'login.title' => 'Sign in',
'login.lede' => 'The programme hub is in a closed beta. Access is granted by invitation code.',
'login.login_label' => 'Username or email',
'login.password' => 'Password',
'login.remember' => 'Stay signed in (30 days)',
'login.submit' => 'Sign in',
'login.no_access' => 'No access yet? A beta code comes from the hub administration.',
// Registration
'register.title' => 'Redeem beta access',
'register.lede' => 'An invitation code creates exactly one account. The code expires once it has been used.',
'register.code' => 'Invitation code',
'register.username' => 'Username',
'register.username_hint' => '3–32 characters, lowercase letters, digits, dot, hyphen and underscore only.',
'register.display_name' => 'Display name',
'register.email' => 'Email (optional)',
'register.email_bound' => 'This invitation is bound to {email}.',
'register.password' => 'Password',
'register.password_repeat' => 'Repeat password',
'register.password_hint' => 'At least 10 characters.',
'register.rights' => 'I accept the beta rules and will not share content I have no rights to.',
'register.submit' => 'Create account',
'register.have_account' => 'Already have an account?',
'register.login_link' => 'Sign in',
// Overview
'dashboard.eyebrow' => 'Many skates, one net',
'dashboard.hero_title' => 'Share programmes, compare versions, develop them together.',
'dashboard.hero_sub' => 'The hub collects your team’s programmes, music and revisions in one place.',
'dashboard.title' => 'Programmes',
'dashboard.count' => '{count} {label} in the hub',
'dashboard.one_routine' => 'programme',
'dashboard.many_routines' => 'programmes',
'dashboard.mine_suffix' => ' (yours only)',
'dashboard.upload' => 'Upload programme',
'dashboard.search_placeholder' => 'Title, skater, music, user …',
'dashboard.search' => 'Search',
'dashboard.all' => 'All',
'dashboard.mine' => 'My programmes',
'dashboard.empty' => 'No programmes found.',
'dashboard.empty_hint' => 'Clear the search or',
'dashboard.empty_upload' => 'upload a programme yourself',
'dashboard.empty_first' => 'The hub is still empty.',
'dashboard.empty_first_action' => 'Upload the first programme',
'badge.hidden' => 'hidden',
// Tables
'table.title' => 'Title',
'table.skater' => 'Skater',
'table.music' => 'Music',
'table.revision' => 'Rev.',
'table.size' => 'Size',
'table.updated' => 'Updated',
'table.by' => 'By',
'table.name' => 'Name',
'table.prefix' => 'Prefix',
'table.created' => 'Created',
'table.last_used' => 'Last used',
'table.status' => 'Status',
'table.role' => 'Role',
'table.routines' => 'Programmes',
'table.registered' => 'Registered',
'table.last_login' => 'Last sign-in',
'table.actions' => 'Actions',
'table.downloads' => 'Downloads',
'table.email' => 'Email',
'table.note' => 'Note',
'table.valid_until' => 'Valid until',
'table.from_to' => 'From / to',
'table.time' => 'Time',
'table.actor' => 'Actor',
'table.action' => 'Action',
'table.subject' => 'Subject',
'table.detail' => 'Detail',
'table.ip' => 'IP',
'pagination.back' => '← Back',
'pagination.next' => 'Next →',
'pagination.page' => 'Page {page} of {pages}',
// Programme detail
'routine.breadcrumb' => 'Programmes',
'routine.breadcrumb_current' => 'Programme',
'routine.revision' => 'Revision {revision}',
'routine.download' => 'Download programme',
'routine.download_audio' => 'Download music',
'routine.owner_bar' => 'You can manage this programme.',
'routine.new_revision' => 'Upload new revision',
'routine.hide' => 'Remove from the hub',
'routine.publish' => 'Publish again',
'routine.open_admin' => 'Open in administration',
'routine.description' => 'Description',
'routine.music' => 'Music',
'routine.details' => 'Details',
'routine.category' => 'Category',
'routine.music_title' => 'Music title',
'routine.music_artist' => 'Artist',
'routine.routine_file' => 'Programme file',
'routine.audio_file' => 'Audio file',
'routine.checksums' => 'Checksums',
'routine.checksum_hint' => 'When downloading, check that the SHA-256 checksum matches the programme.',
// Upload
'upload.title_new' => 'Upload programme',
'upload.title_revision' => 'New revision',
'upload.revision_lede' => 'New version of “{title}”. The previous revision is kept.',
'upload.lede' => 'Upload the programme JSON and, if the programme uses music, the matching audio file. They belong together as a package.',
'upload.routine_file' => 'Programme file (.json)',
'upload.routine_hint' => 'A programme saved from Rinkplanner, max. {max}.',
'upload.audio_file' => 'Music file (MP3/OGG/WAV/M4A/AAC)',
'upload.audio_hint' => 'The filename must match the “music_file” field of the programme exactly.',
'upload.description' => 'Description (optional)',
'upload.music_title' => 'Music title (optional)',
'upload.artist' => 'Artist (optional)',
'upload.rights' => 'I hold the rights to the programme and the music and may share them in the closed beta hub.',
'upload.submit_new' => 'Publish programme',
'upload.submit_revision' => 'Publish revision',
'upload.cancel' => 'Cancel',
// Account
'account.title' => 'Account',
'account.role_admin' => 'Administrator',
'account.role_user' => 'Beta user',
'account.must_change' => 'Please set a new password before using the hub further.',
'account.change_password' => 'Change password',
'account.current_password' => 'Current password',
'account.new_password' => 'New password',
'account.repeat_password' => 'Repeat new password',
'account.password_hint' => 'At least 10 characters.',
'account.save_password' => 'Save password',
'account.tokens' => 'API tokens',
'account.tokens_lede' => 'For the Godot app. A token replaces username and password in the client and can be revoked at any time.',
'account.token_placeholder' => 'Name, e.g. office PC',
'account.token_create' => 'Create token',
'account.token_active' => 'active',
'account.token_revoked' => 'revoked',
'account.token_revoke' => 'revoke',
'account.no_tokens' => 'No token created yet.',
// Administration
'admin.title' => 'Administration',
'admin.tab_invites' => 'Invitations',
'admin.tab_users' => 'Users',
'admin.tab_routines' => 'Programmes',
'admin.tab_audit' => 'Audit log',
'admin.audit_lede' => 'The last {count} events.',
'admin.audit_empty' => 'No entries yet.',
'admin_invites.lede' => 'Invitations for the closed beta.',
'admin_invites.new' => 'New invitation',
'admin_invites.new_lede' => 'The code is shown exactly once after it is created. It is valid for one account.',
'admin_invites.note' => 'Note (internal)',
'admin_invites.note_placeholder' => 'e.g. Club North',
'admin_invites.email' => 'Bind email (optional)',
'admin_invites.email_hint' => 'Only this address can use the code.',
'admin_invites.days' => 'Valid (days)',
'admin_invites.days_hint' => '0 = unlimited.',
'admin_invites.create' => 'Create invitation',
'admin_invites.list' => 'Invitations',
'admin_invites.empty' => 'No invitations yet.',
'admin_invites.revoke' => 'revoke',
'admin_users.lede' => 'Manage beta accounts.',
'admin_users.self' => 'own account',
'admin_users.block' => 'block',
'admin_users.unblock' => 'unblock',
'admin_users.reset' => 'Reset password',
'admin_users.delete' => 'delete',
'admin_users.delete_confirm' => 'delete including all programmes',
'admin_users.delete_submit' => 'Confirm deletion',
'admin_users.role_admin' => 'Admin',
'admin_users.role_user' => 'User',
'status.active' => 'active',
'status.blocked' => 'blocked',
'admin_routines.lede' => '{total} programmes in total, including hidden ones.',
'admin_routines.search_placeholder' => 'Title, skater, user …',
'admin_routines.empty' => 'No programmes found.',
'admin_routines.hide' => 'hide',
'admin_routines.publish' => 'publish',
'admin_routines.delete' => 'delete',
'admin_routines.delete_confirm' => 'delete permanently',
'admin_routines.delete_submit' => 'Confirm deletion',
// Invitation status
'invite.status.open' => 'open',
'invite.status.used' => 'redeemed',
'invite.status.expired' => 'expired',
'invite.status.revoked' => 'revoked',
// Error page
'error.label' => 'Error {status}',
'error.back' => 'Back to the',
'error.back_link' => 'programme overview',
// Messages
'auth.admin_only' => 'This area is for administrators only.',
'auth.change_password_first' => 'Please change your password first.',
'auth.logged_out' => 'Signed out.',
'auth.welcome' => 'Welcome to the programme hub!',
'auth.session_expired' => 'The session has expired. Please reload the page.',
'page.method_not_allowed' => 'This method is not allowed.',
'page.not_found' => 'This page does not exist.',
'username.length' => 'The username must be 3 to 32 characters long.',
'username.charset' => 'Lowercase letters, digits, dot, hyphen and underscore only; begin and end with a letter or digit.',
'username.reserved' => 'This username is reserved.',
'register.invalid_invite' => 'This invitation code is invalid, expired or already redeemed.',
'register.display_name_long' => 'The display name may be at most 64 characters long.',
'register.email_invalid' => 'The email address is not valid.',
'register.email_mismatch' => 'This invitation is bound to a different email address.',
'register.password_mismatch' => 'The passwords do not match.',
'register.rights_required' => 'Please accept the beta rules.',
'register.invite_taken' => 'The invitation code was just redeemed. Please request a new one.',
'register.username_taken' => 'This username is already taken.',
'register.email_taken' => 'This email address is already registered.',
'routine.not_found' => 'This programme does not exist.',
'routine.forbidden' => 'This programme is not shared with you.',
'routine.edit_forbidden' => 'Only the owner or an admin can change this programme.',
'upload.quota' => 'Hourly upload limit reached. Please try again later.',
'upload.rights_confirm' => 'Please confirm that you may share the programme and its music.',
'upload.duplicate' => 'This programme is already in the hub.',
'upload.published' => 'Programme published.',
'upload.save_failed' => 'The programme could not be saved.',
'revision.saved' => 'New revision {revision} saved.',
'revision.save_failed' => 'The revision could not be saved.',
'routine.published_again' => 'The programme is visible again.',
'routine.hidden_now' => 'The programme was removed from the hub.',
'account.current_wrong' => 'The current password is wrong.',
'account.password_changed' => 'Password changed. Other sessions were signed out.',
'token.created' => 'New API token – copy it now, it will not be shown again',
'token.revoked' => 'Token revoked.',
'token.not_found' => 'Token not found.',
'invite.created' => 'Invitation created.',
'invite.created_label' => 'Invitation code',
'invite.revoked' => 'Invitation revoked.',
'invite.revoke_failed' => 'The invitation could not be revoked.',
'user.not_found' => 'User not found.',
'user.self_change' => 'Your own account cannot be changed here.',
'user.disabled' => 'User disabled.',
'user.enabled' => 'User enabled.',
'user.temp_password' => 'Temporary password for {user}',
'user.must_change' => 'The user must change the password at the next sign-in.',
'user.delete_confirm_required' => 'Deletion must be confirmed.',
'user.deleted' => 'User and their programmes deleted.',
'action.unknown' => 'Unknown action.',
'routine.not_found_short' => 'Programme not found.',
'admin.status_changed' => 'Status changed.',
'routine.deleted' => 'Programme permanently deleted.',
// Sign-in and password rules
'login.error.rate_limited' => 'Too many failed attempts. Please try again in {minutes} minutes.',
'login.error.credentials' => 'Username or password is incorrect.',
'login.error.disabled' => 'This account is disabled.',
'password.min' => 'The password must be at least 10 characters long.',
'password.max' => 'The password may be at most 200 characters long.',
'password.same_as_username' => 'The password must not be the same as the username.',
// Upload validation
'upload.select_routine' => 'Please choose a programme file (.json).',
'upload.invalid' => 'Invalid upload.',
'upload.routine_too_large' => 'The programme file is too large (max. {max}).',
'upload.routine_not_json' => 'Programme files must be in JSON format (.json).',
'upload.read_failed' => 'The programme file could not be read.',
'upload.invalid_json' => 'The programme file is not valid JSON.',
'upload.no_json_object' => 'The programme file does not contain a JSON object.',
'upload.not_rinkplanner' => 'This is not a Rinkplanner programme (missing or wrong format).',
'upload.unsupported_version' => 'This programme format version is not supported.',
'upload.no_sections' => 'The programme has no section list.',
'upload.too_many_sections' => 'The programme has too many sections (max. 500).',
'upload.title_required' => 'The programme needs a title.',
'upload.bad_music_name' => 'The programme refers to an invalid music filename.',
'upload.music_missing' => 'The programme refers to “{name}”. Please upload the matching audio file as well.',
'upload.music_unexpected' => 'The programme refers to no music file; the audio file does not match.',
'upload.audio_invalid' => 'Invalid audio upload.',
'upload.audio_too_large' => 'The audio file is too large (max. {max}).',
'upload.audio_name_mismatch' => 'The audio file is named “{actual}”, but the programme refers to “{expected}”.',
'upload.audio_format' => 'The audio file is not a supported format (MP3, OGG, WAV, M4A, AAC).',
'upload.file_too_large' => 'The file is too large.',
'upload.interrupted' => 'The upload was interrupted.',
'upload.no_file_chosen' => 'No file was selected.',
'upload.store_failed' => 'The file could not be stored.',
'upload.unknown_error' => 'Unknown upload error.',
'routine.no_file_yet' => 'This programme has no file yet.',
'routine.file_missing' => 'The file is missing from storage.',
'routine.file_unreadable' => 'The file could not be opened.',
// API
'api.post_only' => 'Only POST is allowed.',
'api.get_only' => 'Only GET is allowed.',
'api.get_or_post' => 'Only GET or POST is allowed.',
'api.get_or_delete' => 'Only GET or DELETE is allowed.',
'api.unknown_path' => 'Unknown API path.',
'api.bearer_missing' => 'Bearer token missing.',
'api.token_invalid' => 'Token is invalid, expired or revoked.',
'api.credentials_required' => 'Username and password are required.',
'api.change_password_web' => 'Please change your password in the web interface first.',
'api.edit_forbidden' => 'Only the owner or an admin may change the programme.',
'api.rights_required' => 'Please confirm that the programme and its music may be shared.',
'api.upload_limit' => 'Hourly upload limit reached.',
'api.invalid_files' => 'The files are not valid.',
'api.duplicate' => 'This programme is already in the hub (ID {id}).',
'api.server_error' => 'Internal error.',
'api.routine_load_failed' => 'The programme could not be loaded.',
],
];

View file

@ -106,13 +106,13 @@ function invites_list(): array
function invite_status(array $invite): string
{
if ($invite['revoked_at'] !== null) {
return 'widerrufen';
return 'revoked';
}
if ($invite['used_at'] !== null) {
return 'eingelöst';
return 'used';
}
if ($invite['expires_at'] !== null && $invite['expires_at'] <= utc_now()) {
return 'abgelaufen';
return 'expired';
}
return 'offen';
return 'open';
}

View file

@ -12,7 +12,7 @@ function page_handle(string $method, string $path): void
{
$path = '/' . trim($path, '/');
if (!in_array($method, ['GET', 'POST'], true)) {
abort_page(405, 'Diese Methode ist nicht erlaubt.');
abort_page(405, t('page.method_not_allowed'));
}
if ($path === '/health') {
@ -20,11 +20,20 @@ function page_handle(string $method, string $path): void
return;
}
// Sprachwahl über den DE/EN-Umschalter; muss auch ohne Anmeldung gehen.
if ($path === '/language') {
$lang = strtolower(substr(query_string('lang'), 0, 2));
if (in_array($lang, HUB_LOCALES, true)) {
hub_locale_set($lang);
}
redirect(auth_next_url('/'));
}
$user = auth_user();
if ($user !== null && $user['must_change_password'] === 1
&& !in_array($path, ['/account', '/account/password', '/logout'], true)
&& !in_array($path, ['/account', '/account/password', '/logout', '/language'], true)
) {
flash('info', 'Bitte zuerst das Passwort ändern.');
flash('info', t('auth.change_password_first'));
redirect('/account');
}
@ -41,7 +50,7 @@ function page_handle(string $method, string $path): void
redirect('/');
}
auth_logout();
flash('success', 'Abgemeldet.');
flash('success', t('auth.logged_out'));
redirect('/login');
}
if ($path === '/') {
@ -94,7 +103,7 @@ function page_handle(string $method, string $path): void
}
if ($path === '/admin/audit') {
require_admin_page();
render_page('admin_audit', ['entries' => audit_list(200)], 'Audit-Log');
render_page('admin_audit', ['entries' => audit_list(200)], t('page.admin_audit'));
return;
}
@ -115,7 +124,7 @@ function page_handle(string $method, string $path): void
return;
}
abort_page(404, 'Diese Seite gibt es nicht.');
abort_page(404, t('page.not_found'));
}
function health_check(): void
@ -163,19 +172,19 @@ function page_login(string $method): void
'error' => $error,
'login' => $login,
'next' => $next,
], 'Anmelden');
], t('page.login'));
}
function username_error(string $username): ?string
{
if (mb_strlen($username, 'UTF-8') < 3 || mb_strlen($username, 'UTF-8') > 32) {
return 'Der Benutzername muss 3 bis 32 Zeichen lang sein.';
return t('username.length');
}
if (preg_match('/^[a-z0-9](?:[a-z0-9._-]{1,30}[a-z0-9])$/u', $username) !== 1) {
return 'Nur Kleinbuchstaben, Ziffern, Punkt, Bindestrich und Unterstrich; Anfang und Ende alphanumerisch.';
return t('username.charset');
}
if (in_array($username, HUB_RESERVED_USERNAMES, true)) {
return 'Dieser Benutzername ist reserviert.';
return t('username.reserved');
}
return null;
}
@ -209,7 +218,7 @@ function page_register(string $method): void
$input['email'] = post_string('email');
if ($invite === null) {
$errors[] = 'Dieser Einladungscode ist ungültig, abgelaufen oder bereits eingelöst.';
$errors[] = t('register.invalid_invite');
} elseif (!empty($invite['email']) && $input['email'] === '') {
$input['email'] = (string) $invite['email'];
}
@ -221,15 +230,15 @@ function page_register(string $method): void
$input['display_name'] = $input['username'];
}
if (mb_strlen($input['display_name'], 'UTF-8') > 64) {
$errors[] = 'Der Anzeigename darf höchstens 64 Zeichen lang sein.';
$errors[] = t('register.display_name_long');
}
if ($input['email'] !== '' && filter_var($input['email'], FILTER_VALIDATE_EMAIL) === false) {
$errors[] = 'Die E-Mail-Adresse ist nicht gültig.';
$errors[] = t('register.email_invalid');
}
if ($invite !== null && !empty($invite['email'])
&& strcasecmp((string) $invite['email'], $input['email']) !== 0
) {
$errors[] = 'Diese Einladung ist an eine andere E-Mail-Adresse gebunden.';
$errors[] = t('register.email_mismatch');
}
$password = (string) ($_POST['password'] ?? '');
$repeat = (string) ($_POST['password_repeat'] ?? '');
@ -238,10 +247,10 @@ function page_register(string $method): void
$errors[] = $policy;
}
if ($password !== $repeat) {
$errors[] = 'Die Passwortwiederholung passt nicht.';
$errors[] = t('register.password_mismatch');
}
if (($_POST['rights'] ?? '') !== '1') {
$errors[] = 'Bitte die Beta-Regeln akzeptieren.';
$errors[] = t('register.rights_required');
}
if (!$errors && $invite !== null) {
@ -268,7 +277,7 @@ function page_register(string $method): void
$newId = (int) $pdo->lastInsertId();
if (!invite_consume((int) $invite['id'], $newId)) {
$pdo->rollBack();
$errors[] = 'Der Einladungscode wurde gerade eingelöst. Bitte einen neuen Code anfordern.';
$errors[] = t('register.invite_taken');
} else {
audit('invite.use', 'invite', (int) $invite['id'], $input['username'], $newId);
audit('user.register', 'user', $newId, $input['username'], $newId);
@ -279,9 +288,9 @@ function page_register(string $method): void
$pdo->rollBack();
}
if (str_contains($exception->getMessage(), 'uq_users_username')) {
$errors[] = 'Dieser Benutzername ist schon vergeben.';
$errors[] = t('register.username_taken');
} elseif (str_contains($exception->getMessage(), 'uq_users_email')) {
$errors[] = 'Diese E-Mail-Adresse ist schon registriert.';
$errors[] = t('register.email_taken');
} else {
throw $exception;
}
@ -291,7 +300,7 @@ function page_register(string $method): void
$user = auth_user_by_id($newId);
if ($user !== null) {
auth_login($user);
flash('success', 'Willkommen im Kür-Hub!');
flash('success', t('auth.welcome'));
redirect('/');
}
}
@ -303,7 +312,7 @@ function page_register(string $method): void
'code' => $code,
'errors' => $errors,
'input' => $input,
], 'Registrieren');
], t('page.register'));
}
function page_dashboard(string $method): void
@ -320,7 +329,7 @@ function page_dashboard(string $method): void
'pages' => $result['pages'],
'query' => $query,
'mine' => $mine,
], 'Küren');
], t('page.dashboard'));
}
function page_routine_detail(int $id, string $method): void
@ -328,10 +337,10 @@ function page_routine_detail(int $id, string $method): void
$user = auth_require_login();
$routine = routine_fetch($id);
if ($routine === null) {
abort_page(404, 'Diese Kür gibt es nicht.');
abort_page(404, t('routine.not_found'));
}
if (!routine_can_view($routine, $user)) {
abort_page(403, 'Diese Kür ist nicht freigegeben.');
abort_page(403, t('routine.forbidden'));
}
render_page('routine', [
'routine' => $routine,
@ -345,10 +354,10 @@ function page_routine_file(int $id, string $kind): void
$user = auth_require_login();
$routine = routine_fetch($id);
if ($routine === null) {
abort_page(404, 'Diese Kür gibt es nicht.');
abort_page(404, t('routine.not_found'));
}
if (!routine_can_view($routine, $user)) {
abort_page(403, 'Diese Kür ist nicht freigegeben.');
abort_page(403, t('routine.forbidden'));
}
routine_send_file($routine, $kind);
}
@ -366,10 +375,10 @@ function page_upload(string $method): void
if ($method === 'POST') {
csrf_require();
if (!routine_upload_quota_ok((int) $user['id'])) {
$errors[] = 'Stündliches Upload-Limit erreicht. Bitte später erneut versuchen.';
$errors[] = t('upload.quota');
}
if (($_POST['rights'] ?? '') !== '1') {
$errors[] = 'Bitte bestätigen, dass du Kür und Musik teilen darfst.';
$errors[] = t('upload.rights_confirm');
}
if (!$errors) {
$package = routine_validate_package($_POST);
@ -378,16 +387,16 @@ function page_upload(string $method): void
} else {
$duplicate = routine_duplicate_exists((int) $user['id'], $package);
if ($duplicate !== null) {
flash('info', 'Diese Kür ist bereits im Hub.');
flash('info', t('upload.duplicate'));
redirect('/routines/' . $duplicate);
}
try {
$routineId = routine_create((int) $user['id'], $package);
flash('success', 'Kür veröffentlicht.');
flash('success', t('upload.published'));
redirect('/routines/' . $routineId);
} catch (Throwable $error) {
hub_log('Upload fehlgeschlagen: ' . $error->getMessage());
$errors[] = 'Die Kür konnte nicht gespeichert werden.';
$errors[] = t('upload.save_failed');
}
}
}
@ -400,7 +409,7 @@ function page_upload(string $method): void
'errors' => $errors,
'input' => $input,
'routine' => null,
], 'Kür hochladen');
], t('page.upload'));
}
function page_routine_revise(int $id, string $method): void
@ -408,10 +417,10 @@ function page_routine_revise(int $id, string $method): void
$user = auth_require_login();
$routine = routine_fetch($id);
if ($routine === null) {
abort_page(404, 'Diese Kür gibt es nicht.');
abort_page(404, t('routine.not_found'));
}
if (!routine_can_edit($routine, $user)) {
abort_page(403, 'Nur der Eigentümer oder ein Admin kann diese Kür ändern.');
abort_page(403, t('routine.edit_forbidden'));
}
$errors = [];
$input = [
@ -423,10 +432,10 @@ function page_routine_revise(int $id, string $method): void
if ($method === 'POST') {
csrf_require();
if (!routine_upload_quota_ok((int) $user['id'])) {
$errors[] = 'Stündliches Upload-Limit erreicht. Bitte später erneut versuchen.';
$errors[] = t('upload.quota');
}
if (($_POST['rights'] ?? '') !== '1') {
$errors[] = 'Bitte bestätigen, dass du Kür und Musik teilen darfst.';
$errors[] = t('upload.rights_confirm');
}
if (!$errors) {
$package = routine_validate_package($_POST);
@ -435,11 +444,11 @@ function page_routine_revise(int $id, string $method): void
} else {
try {
$revision = routine_add_revision($id, (int) $user['id'], $package);
flash('success', 'Neue Revision ' . $revision . ' gespeichert.');
flash('success', t('revision.saved', ['revision' => $revision]));
redirect('/routines/' . $id);
} catch (Throwable $error) {
hub_log('Revision fehlgeschlagen: ' . $error->getMessage());
$errors[] = 'Die Revision konnte nicht gespeichert werden.';
$errors[] = t('revision.save_failed');
}
}
}
@ -452,7 +461,7 @@ function page_routine_revise(int $id, string $method): void
'errors' => $errors,
'input' => $input,
'routine' => $routine,
], 'Neue Revision');
], t('page.revision'));
}
function page_routine_status(int $id, string $action, string $method): void
@ -464,14 +473,14 @@ function page_routine_status(int $id, string $action, string $method): void
csrf_require();
$routine = routine_fetch($id);
if ($routine === null) {
abort_page(404, 'Diese Kür gibt es nicht.');
abort_page(404, t('routine.not_found'));
}
if (!routine_can_edit($routine, $user)) {
abort_page(403, 'Nur der Eigentümer oder ein Admin kann diese Kür ändern.');
abort_page(403, t('routine.edit_forbidden'));
}
$status = $action === 'publish' ? 'published' : 'hidden';
routine_set_status($id, $status);
flash('success', $status === 'published' ? 'Kür ist wieder sichtbar.' : 'Kür wurde aus dem Hub genommen.');
flash('success', $status === 'published' ? t('routine.published_again') : t('routine.hidden_now'));
redirect('/routines/' . $id);
}
@ -480,7 +489,7 @@ function page_account(string $method): void
$user = auth_require_login();
render_page('account', [
'tokens' => tokens_list((int) $user['id']),
], 'Konto');
], t('page.account'));
}
function page_account_password(string $method): void
@ -496,14 +505,14 @@ function page_account_password(string $method): void
$errors = [];
if (!password_verify($current, (string) $user['password_hash'])) {
$errors[] = 'Das aktuelle Passwort ist falsch.';
$errors[] = t('account.current_wrong');
}
$policy = password_policy_error($password, (string) $user['username']);
if ($policy !== null) {
$errors[] = $policy;
}
if ($password !== $repeat) {
$errors[] = 'Die Passwortwiederholung passt nicht.';
$errors[] = t('register.password_mismatch');
}
if ($errors) {
foreach ($errors as $error) {
@ -517,7 +526,7 @@ function page_account_password(string $method): void
)->execute([hash_password($password), utc_now(), (int) $user['id']]);
auth_revoke_sessions((int) $user['id']);
audit('user.password_change', 'user', (int) $user['id']);
flash('success', 'Passwort geändert. Andere Sitzungen wurden abgemeldet.');
flash('success', t('account.password_changed'));
redirect('/account');
}
@ -533,7 +542,7 @@ function page_account_token_create(string $method): void
$name = 'App';
}
$created = token_create((int) $user['id'], $name);
flash_secret('Neuer API-Token – jetzt kopieren, er wird nicht erneut angezeigt', $created['token']);
flash_secret(t('token.created'), $created['token']);
redirect('/account');
}
@ -547,9 +556,9 @@ function page_account_token_revoke(string $method): void
$tokenId = (int) post_string('token_id');
if (token_revoke($tokenId, (int) $user['id'])) {
audit('token.revoke', 'token', $tokenId);
flash('success', 'Token widerrufen.');
flash('success', t('token.revoked'));
} else {
flash('error', 'Token nicht gefunden.');
flash('error', t('token.not_found'));
}
redirect('/account');
}
@ -564,7 +573,7 @@ function page_admin_invites(string $method): void
$days = (int) post_string('expires_days', '30');
$errors = [];
if ($email !== '' && filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
$errors[] = 'Die E-Mail-Adresse ist nicht gültig.';
$errors[] = t('register.email_invalid');
}
if ($errors) {
foreach ($errors as $error) {
@ -574,14 +583,14 @@ function page_admin_invites(string $method): void
$code = invite_create($note, $email, $days, (int) $admin['id']);
$publicUrl = rtrim((string) config('app.public_url', ''), '/');
$link = $publicUrl . '/register?code=' . rawurlencode($code);
flash_secret('Einladungscode', $code . ' – Link: ' . $link);
flash('success', 'Einladung erstellt.');
flash_secret(t('invite.created_label'), $code . ' – Link: ' . $link);
flash('success', t('invite.created'));
}
redirect('/admin/invites');
}
render_page('admin_invites', [
'invites' => invites_list(),
], 'Einladungen');
], t('page.admin_invites'));
}
function page_admin_invite_revoke(string $method): void
@ -594,9 +603,9 @@ function page_admin_invite_revoke(string $method): void
$inviteId = (int) post_string('invite_id');
if (invite_revoke($inviteId)) {
audit('invite.revoke', 'invite', $inviteId);
flash('success', 'Einladung widerrufen.');
flash('success', t('invite.revoked'));
} else {
flash('error', 'Einladung konnte nicht widerrufen werden.');
flash('error', t('invite.revoke_failed'));
}
redirect('/admin/invites');
}
@ -608,7 +617,7 @@ function page_admin_users(string $method): void
'SELECT u.*, (SELECT COUNT(*) FROM routines r WHERE r.owner_id = u.id) AS routine_count
FROM users u ORDER BY u.created_at DESC, u.id DESC'
)->fetchAll();
render_page('admin_users', ['users' => $users], 'Benutzer');
render_page('admin_users', ['users' => $users], t('page.admin_users'));
}
function page_admin_user_action(string $method): void
@ -622,11 +631,11 @@ function page_admin_user_action(string $method): void
$action = post_string('action');
$target = auth_user_by_id($targetId);
if ($target === null) {
flash('error', 'Benutzer nicht gefunden.');
flash('error', t('user.not_found'));
redirect('/admin/users');
}
if ($targetId === (int) $admin['id']) {
flash('error', 'Das eigene Konto lässt sich hier nicht ändern.');
flash('error', t('user.self_change'));
redirect('/admin/users');
}
@ -634,11 +643,11 @@ function page_admin_user_action(string $method): void
db()->prepare("UPDATE users SET status = 'disabled' WHERE id = ?")->execute([$targetId]);
auth_revoke_sessions($targetId);
audit('user.disable', 'user', $targetId, (string) $target['username']);
flash('success', 'Benutzer deaktiviert.');
flash('success', t('user.disabled'));
} elseif ($action === 'enable') {
db()->prepare("UPDATE users SET status = 'active' WHERE id = ?")->execute([$targetId]);
audit('user.enable', 'user', $targetId, (string) $target['username']);
flash('success', 'Benutzer aktiviert.');
flash('success', t('user.enabled'));
} elseif ($action === 'reset') {
$alphabet = HUB_INVITE_ALPHABET;
$temp = '';
@ -650,11 +659,11 @@ function page_admin_user_action(string $method): void
)->execute([hash_password($temp), utc_now(), $targetId]);
auth_revoke_sessions($targetId);
audit('user.password_reset', 'user', $targetId, (string) $target['username']);
flash_secret('Temporäres Passwort für ' . $target['username'], $temp);
flash('info', 'Der Benutzer muss das Passwort bei der nächsten Anmeldung ändern.');
flash_secret(t('user.temp_password', ['user' => $target['username']]), $temp);
flash('info', t('user.must_change'));
} elseif ($action === 'delete') {
if (($_POST['confirm'] ?? '') !== '1') {
flash('error', 'Löschen muss bestätigt werden.');
flash('error', t('user.delete_confirm_required'));
redirect('/admin/users');
}
$stmt = db()->prepare('SELECT id FROM routines WHERE owner_id = ?');
@ -666,9 +675,9 @@ function page_admin_user_action(string $method): void
->execute([utc_now(), $targetId]);
audit('user.delete', 'user', $targetId, (string) $target['username']);
db()->prepare('DELETE FROM users WHERE id = ?')->execute([$targetId]);
flash('success', 'Benutzer und zugehörige Küren gelöscht.');
flash('success', t('user.deleted'));
} else {
flash('error', 'Unbekannte Aktion.');
flash('error', t('action.unknown'));
}
redirect('/admin/users');
}
@ -685,7 +694,7 @@ function page_admin_routines(string $method): void
'page' => $result['page'],
'pages' => $result['pages'],
'query' => $query,
], 'Alle Küren');
], t('page.admin_routines'));
}
function page_admin_routine_action(string $method): void
@ -699,21 +708,21 @@ function page_admin_routine_action(string $method): void
$action = post_string('action');
$routine = routine_fetch($routineId);
if ($routine === null) {
flash('error', 'Kür nicht gefunden.');
flash('error', t('routine.not_found_short'));
redirect('/admin/routines');
}
if ($action === 'hide' || $action === 'publish') {
routine_set_status($routineId, $action === 'publish' ? 'published' : 'hidden');
flash('success', 'Status geändert.');
flash('success', t('admin.status_changed'));
} elseif ($action === 'delete') {
if (($_POST['confirm'] ?? '') !== '1') {
flash('error', 'Löschen muss bestätigt werden.');
flash('error', t('user.delete_confirm_required'));
redirect('/admin/routines');
}
routine_delete($routineId);
flash('success', 'Kür endgültig gelöscht.');
flash('success', t('routine.deleted'));
} else {
flash('error', 'Unbekannte Aktion.');
flash('error', t('action.unknown'));
}
redirect('/admin/routines');
}

View file

@ -47,11 +47,11 @@ function routine_music_name_valid(string $name): bool
function upload_error_message(int $code): string
{
return match ($code) {
UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE => 'Die Datei ist zu groß.',
UPLOAD_ERR_PARTIAL => 'Der Upload wurde unterbrochen.',
UPLOAD_ERR_NO_FILE => 'Es wurde keine Datei ausgewählt.',
UPLOAD_ERR_NO_TMP_DIR, UPLOAD_ERR_CANT_WRITE, UPLOAD_ERR_EXTENSION => 'Die Datei konnte nicht gespeichert werden.',
default => 'Unbekannter Upload-Fehler.',
UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE => t('upload.file_too_large'),
UPLOAD_ERR_PARTIAL => t('upload.interrupted'),
UPLOAD_ERR_NO_FILE => t('upload.no_file_chosen'),
UPLOAD_ERR_NO_TMP_DIR, UPLOAD_ERR_CANT_WRITE, UPLOAD_ERR_EXTENSION => t('upload.store_failed'),
default => t('upload.unknown_error'),
};
}
@ -112,20 +112,20 @@ function routine_validate_package(array $post): array
$routineFile = $_FILES['routine'] ?? null;
if (!is_array($routineFile) || ($routineFile['error'] ?? UPLOAD_ERR_NO_FILE) !== UPLOAD_ERR_OK) {
$errors[] = 'Bitte eine Kür-Datei (.json) auswählen.';
$errors[] = t('upload.select_routine');
return ['ok' => false, 'errors' => $errors];
}
$routineTmp = (string) $routineFile['tmp_name'];
$routineBytes = (int) $routineFile['size'];
if (!is_uploaded_file($routineTmp)) {
return ['ok' => false, 'errors' => ['Ungültiger Upload.']];
return ['ok' => false, 'errors' => [t('upload.invalid')]];
}
if ($routineBytes <= 0 || $routineBytes > $maxRoutine) {
$errors[] = 'Die Kür-Datei ist zu groß (max. ' . human_bytes($maxRoutine) . ').';
$errors[] = t('upload.routine_too_large', ['max' => human_bytes($maxRoutine)]);
}
$routineName = clean_filename((string) ($routineFile['name'] ?? 'kuer.json'));
if (!str_ends_with(strtolower($routineName), '.json')) {
$errors[] = 'Kürdateien müssen im JSON-Format vorliegen (.json).';
$errors[] = t('upload.routine_not_json');
}
if ($errors) {
return ['ok' => false, 'errors' => $errors];
@ -133,28 +133,28 @@ function routine_validate_package(array $post): array
$contents = file_get_contents($routineTmp);
if (!is_string($contents)) {
return ['ok' => false, 'errors' => ['Die Kür-Datei konnte nicht gelesen werden.']];
return ['ok' => false, 'errors' => [t('upload.read_failed')]];
}
try {
$json = json_decode($contents, true, 64, JSON_THROW_ON_ERROR);
} catch (JsonException) {
return ['ok' => false, 'errors' => ['Die Kür-Datei ist kein gültiges JSON.']];
return ['ok' => false, 'errors' => [t('upload.invalid_json')]];
}
if (!is_array($json)) {
return ['ok' => false, 'errors' => ['Die Kür-Datei enthält kein JSON-Objekt.']];
return ['ok' => false, 'errors' => [t('upload.no_json_object')]];
}
if (($json['format'] ?? '') !== 'rinkplanner.routine') {
return ['ok' => false, 'errors' => ['Das ist keine Rinkplanner-Kür (format fehlt oder ist falsch).']];
return ['ok' => false, 'errors' => [t('upload.not_rinkplanner')]];
}
$formatVersion = (int) ($json['format_version'] ?? 0);
if ($formatVersion !== 1) {
return ['ok' => false, 'errors' => ['Diese Kür-Formatversion wird nicht unterstützt.']];
return ['ok' => false, 'errors' => [t('upload.unsupported_version')]];
}
if (!is_array($json['sections'] ?? null)) {
return ['ok' => false, 'errors' => ['Die Kür enthält keine Abschnittsliste.']];
return ['ok' => false, 'errors' => [t('upload.no_sections')]];
}
if (count($json['sections']) > 500) {
return ['ok' => false, 'errors' => ['Die Kür hat zu viele Abschnitte (max. 500).']];
return ['ok' => false, 'errors' => [t('upload.too_many_sections')]];
}
$title = trim((string) ($json['title'] ?? ''));
@ -162,14 +162,14 @@ function routine_validate_package(array $post): array
$title = (string) pathinfo($routineName, PATHINFO_FILENAME);
}
if ($title === '') {
return ['ok' => false, 'errors' => ['Die Kür braucht einen Titel.']];
return ['ok' => false, 'errors' => [t('upload.title_required')]];
}
$title = truncate_text($title, 190);
$skater = truncate_text(trim((string) ($json['skater_name'] ?? '')), 190);
$category = truncate_text(trim((string) ($json['adult_category'] ?? '')), 40);
$musicFile = trim((string) ($json['music_file'] ?? ''));
if ($musicFile !== '' && !routine_music_name_valid($musicFile)) {
return ['ok' => false, 'errors' => ['Die Kür verweist auf einen ungültigen Musikdateinamen.']];
return ['ok' => false, 'errors' => [t('upload.bad_music_name')]];
}
$fileRoutineId = trim((string) ($json['routine_id'] ?? ''));
@ -177,10 +177,10 @@ function routine_validate_package(array $post): array
$audioFile = $_FILES['audio'] ?? null;
$hasAudioUpload = is_array($audioFile) && ($audioFile['error'] ?? UPLOAD_ERR_NO_FILE) !== UPLOAD_ERR_NO_FILE;
if ($musicFile !== '' && !$hasAudioUpload) {
$errors[] = 'Die Kür verweist auf „' . $musicFile . '“. Bitte die passende Audiodatei mit hochladen.';
$errors[] = t('upload.music_missing', ['name' => $musicFile]);
}
if ($musicFile === '' && $hasAudioUpload) {
$errors[] = 'Die Kür verweist auf keine Musikdatei; die Audiodatei passt nicht dazu.';
$errors[] = t('upload.music_unexpected');
}
if ($hasAudioUpload) {
if (($audioFile['error'] ?? UPLOAD_ERR_NO_FILE) !== UPLOAD_ERR_OK) {
@ -190,15 +190,15 @@ function routine_validate_package(array $post): array
$audioBytes = (int) $audioFile['size'];
$audioName = clean_filename((string) ($audioFile['name'] ?? ''));
if (!is_uploaded_file($audioTmp)) {
$errors[] = 'Ungültiger Audio-Upload.';
$errors[] = t('upload.audio_invalid');
} elseif ($audioBytes <= 0 || $audioBytes > $maxAudio) {
$errors[] = 'Die Audiodatei ist zu groß (max. ' . human_bytes($maxAudio) . ').';
$errors[] = t('upload.audio_too_large', ['max' => human_bytes($maxAudio)]);
} elseif ($audioName !== $musicFile) {
$errors[] = 'Die Audiodatei heißt „' . $audioName . '“, die Kür verweist aber auf „' . $musicFile . '“.';
$errors[] = t('upload.audio_name_mismatch', ['actual' => $audioName, 'expected' => $musicFile]);
} else {
$sniffed = audio_sniff($audioTmp);
if ($sniffed === null) {
$errors[] = 'Die Audiodatei ist kein unterstütztes Format (MP3, OGG, WAV, M4A, AAC).';
$errors[] = t('upload.audio_format');
} else {
$audio = [
'tmp' => $audioTmp,
@ -542,9 +542,9 @@ function routine_send_file(array $routine, string $kind, ?array $user = null, bo
$revision = routine_fetch((int) $routine['id']);
if ($revision === null || $revision['revision_id'] === null) {
if ($api) {
abort_api(404, 'no_file', 'Diese Kür hat noch keine Datei.');
abort_api(404, 'no_file', t('routine.no_file_yet'));
}
abort_page(404, 'Diese Kür hat noch keine Datei.');
abort_page(404, t('routine.no_file_yet'));
}
if ($kind === 'audio') {
$path = (string) ($revision['audio_path'] ?? '');
@ -558,16 +558,16 @@ function routine_send_file(array $routine, string $kind, ?array $user = null, bo
$absolute = storage_path($path);
if ($path === '' || !is_file($absolute)) {
if ($api) {
abort_api(404, 'file_missing', 'Die Datei fehlt im Speicher.');
abort_api(404, 'file_missing', t('routine.file_missing'));
}
abort_page(404, 'Die Datei fehlt im Speicher.');
abort_page(404, t('routine.file_missing'));
}
$handle = fopen($absolute, 'rb');
if ($handle === false) {
if ($api) {
abort_api(500, 'file_unreadable', 'Die Datei konnte nicht geöffnet werden.');
abort_api(500, 'file_unreadable', t('routine.file_unreadable'));
}
abort_page(500, 'Die Datei konnte nicht geöffnet werden.');
abort_page(500, t('routine.file_unreadable'));
}
$user ??= auth_user();

View file

@ -99,14 +99,14 @@ function api_require_user(): array
{
$token = bearer_token();
if ($token === '') {
abort_api(401, 'unauthorized', 'Bearer-Token fehlt.');
abort_api(401, 'unauthorized', t('api.bearer_missing'));
}
$user = token_user($token);
if ($user === null) {
abort_api(401, 'invalid_token', 'Token ist ungültig, abgelaufen oder widerrufen.');
abort_api(401, 'invalid_token', t('api.token_invalid'));
}
if ($user['must_change_password'] === 1) {
abort_api(403, 'password_change_required', 'Bitte zuerst im Web das Passwort ändern.');
abort_api(403, 'password_change_required', t('api.change_password_web'));
}
return $user;
}

View file

@ -84,6 +84,9 @@ function url(string $path = '/'): string
return $base . $path;
}
/** Cache-Buster für /assets/: bei Änderungen an hub.css erhöhen. */
const HUB_ASSET_VERSION = '3';
function redirect(string $path, int $status = 303): never
{
header('Location: ' . url($path), true, $status);
@ -141,17 +144,27 @@ function fmt_dt(?string $utc): string
}
try {
$date = new DateTimeImmutable($utc, new DateTimeZone('UTC'));
return $date->setTimezone(new DateTimeZone('Europe/Berlin'))->format('d.m.Y H:i');
$format = hub_locale() === 'en' ? 'Y-m-d H:i' : 'd.m.Y H:i';
return $date->setTimezone(new DateTimeZone('Europe/Berlin'))->format($format);
} catch (Throwable) {
return '–';
}
}
/** Zahl mit den Trennzeichen der aktuellen Sprache. */
function fmt_number(float $value, int $decimals = 1): string
{
if (hub_locale() === 'en') {
return number_format($value, $decimals, '.', ',');
}
return number_format($value, $decimals, ',', '.');
}
function human_bytes(int|float|null $bytes): string
{
$bytes = (float) ($bytes ?? 0);
if ($bytes < 1024) {
return number_format($bytes, 0, ',', '.') . ' B';
return fmt_number($bytes, 0) . ' B';
}
$units = ['KB', 'MB', 'GB'];
$index = -1;
@ -159,7 +172,7 @@ function human_bytes(int|float|null $bytes): string
$bytes /= 1024;
$index++;
} while ($bytes >= 1024 && $index < count($units) - 1);
return number_format($bytes, 1, ',', '.') . ' ' . $units[$index];
return fmt_number($bytes, 1) . ' ' . $units[$index];
}
function truncate_text(string $value, int $length): string
@ -229,7 +242,7 @@ function csrf_valid(): bool
function csrf_require(): void
{
if (!csrf_valid()) {
abort_page(419, 'Die Sitzung ist abgelaufen. Bitte die Seite neu laden.');
abort_page(419, t('auth.session_expired'));
}
}
@ -272,11 +285,11 @@ function render(string $view, array $data = []): string
return (string) ob_get_clean();
}
function render_page(string $view, array $data = [], string $title = 'Kür-Hub'): void
function render_page(string $view, array $data = [], ?string $title = null): void
{
$content = render($view, $data);
echo render('layout', [
'title' => $title,
'title' => $title ?? t('page.title_default'),
'content' => $content,
'user' => auth_user(),
]);
@ -287,7 +300,7 @@ function abort_page(int $status, string $message): never
http_response_code($status);
$content = render('error', ['status' => $status, 'message' => $message]);
echo render('layout', [
'title' => 'Fehler ' . $status,
'title' => t('page.title_error', ['status' => $status]),
'content' => $content,
'user' => auth_user(),
]);
@ -303,13 +316,13 @@ function password_policy_error(string $password, string $username = ''): ?string
{
$length = mb_strlen($password, 'UTF-8');
if ($length < 10) {
return 'Das Passwort muss mindestens 10 Zeichen lang sein.';
return t('password.min');
}
if ($length > 200) {
return 'Das Passwort darf höchstens 200 Zeichen lang sein.';
return t('password.max');
}
if ($username !== '' && mb_strtolower($password) === mb_strtolower($username)) {
return 'Das Passwort darf nicht dem Benutzernamen entsprechen.';
return t('password.same_as_username');
}
return null;
}