From 6b7e714b59e28bc138681662006941274c3261af Mon Sep 17 00:00:00 2001 From: Jonas Kohl Date: Mon, 16 Sep 2024 19:32:09 +0200 Subject: A lot more stuff --- src/application/i18n.php | 26 +- src/application/messages/de.msg | 20 +- src/application/messages/strings.mst | 173 ++++++++- src/application/mystic/forum/Database.php | 7 + src/application/views/alert_error.php | 9 +- src/application/views/alert_info.php | 9 + src/application/views/alert_success.php | 9 + src/application/views/form_register.php | 2 +- src/application/views/template_end.php | 2 +- src/application/views/template_start.php | 3 +- src/application/views/view_post.php | 26 +- src/application/views/view_topic_start.php | 54 +++ src/application/views/view_user.php | 8 +- src/composer.json | 3 +- src/composer.lock | 558 ++++++++++++++++++++++++++++- src/index.php | 286 +++++++++++---- src/themes/default/theme.css | 10 - src/themes/default/theme.json | 12 + src/themes/flat/theme.json | 11 + src/themes/slate/theme.css | 15 - src/themes/slate/theme.json | 20 ++ src/ui/dist/css/bootstrap.min.css | 2 +- src/ui/site.css | 41 ++- src/ui/slate.min.css | 2 +- 24 files changed, 1190 insertions(+), 118 deletions(-) create mode 100644 src/application/views/alert_info.php create mode 100644 src/application/views/alert_success.php delete mode 100644 src/themes/default/theme.css create mode 100644 src/themes/default/theme.json create mode 100644 src/themes/flat/theme.json delete mode 100644 src/themes/slate/theme.css create mode 100644 src/themes/slate/theme.json (limited to 'src') diff --git a/src/application/i18n.php b/src/application/i18n.php index f5b755d..cdc61e1 100644 --- a/src/application/i18n.php +++ b/src/application/i18n.php @@ -9,7 +9,8 @@ const MESSAGE_DIR = __DIR__ . "/messages"; $__i18n_msg_store = []; $__i18n_msg_store_plural = []; $__i18n_msg_metadata = []; -$__i18n_current_locale = null; +/** @var string $__i18n_current_locale */ +$__i18n_current_locale = "en"; const _I18N_MSGID = 0; const _I18N_MSGSTR = 1; @@ -200,7 +201,7 @@ function i18n_get_plural(string $msgid_singular, string $msgid_plural, int $coun $ctx->def("n", $count); $parser = new Parser(new Scanner($expression)); $index = $parser->reduce($ctx); - $index = max(0, min(count($msgs), $index)); + $index = max(0, min(count($msgs) - 1, $index)); $msg = $msgs[$index]; } @@ -212,6 +213,27 @@ function i18n_get_plural(string $msgid_singular, string $msgid_plural, int $coun ); } +function i18n_get_current_locale(): string { + global $__i18n_current_locale; + return $__i18n_current_locale; +} + +function i18n_get_available_locales(): array { + global $__i18n_msg_store; + return [ + "en", + ...array_keys($__i18n_msg_store), + ]; +} + +function i18n_get_message_store(string $locale): array { + global $__i18n_msg_store, $__i18n_msg_store_plural; + return [ + $__i18n_msg_store[$locale] ?? (object)[], + $__i18n_msg_store_plural[$locale] ?? (object)[], + ]; +} + function __(string $msgid, array $params = [], ?string $context = null): string { return i18n_get($msgid, $params, $context); } diff --git a/src/application/messages/de.msg b/src/application/messages/de.msg index c797241..a7f401d 100644 --- a/src/application/messages/de.msg +++ b/src/application/messages/de.msg @@ -10,8 +10,17 @@ metadata({ : "Register" = "Registrieren" -: "Failed to connect to database!" -= "Fehler bei Datenbankverbindung" +: "Error" += "Fehler" + +: "Failed to connect to database:\n%details%" += "Fehler bei der Datenbankverbindung:\n%details%" + +: "Attachment" += "Anhang" + +: "Download" += "Herunterladen" : "Username or password incorrect!" = "Nutzername oder Passwort falsch!" @@ -116,8 +125,8 @@ metadata({ : "No attachment exists with this id" = "Kein Anhang exsitier mit dieser ID" -: "Attachment is not an image" -= "Anhang ist kein Bild" +: "Attachment is neither an image nor a video" += "Anhang ist weder Bild noch Video" : "Delete post" = "Beitrag löschen" @@ -275,3 +284,6 @@ metadata({ - "%n% Datei ausgewählt" - "%n% Dateien ausgewählt" - "Keine Datei ausgewählt" + +: "Created this topic" += "Hat dieses Thema erstellt" diff --git a/src/application/messages/strings.mst b/src/application/messages/strings.mst index 6f6ec38..51ab91d 100644 --- a/src/application/messages/strings.mst +++ b/src/application/messages/strings.mst @@ -1,10 +1,25 @@ +metadata({ + "plural": { + "indexMapping": "ifelse(n = 0, 2, ifelse(n = 1, 0, 1))" + } +}) + : "Log in" = "" : "Register" = "" -: "Failed to connect to database!" +: "Error" += "" + +: "Failed to connect to database:\n%details%" += "" + +: "Attachment" += "" + +: "Download" = "" : "Username or password incorrect!" @@ -104,8 +119,162 @@ : "No attachment exists with this id" = "" -: "Attachment is not an image" +: "Attachment is neither an image nor a video" = "" : "Delete post" = "" + +: "Username:" += "" + +: "Display name:" += "" + +: "Choose password:" += "" + +: "Repeat password:" += "" + +: "Email address:" += "" + +: "CAPTCHA:" += "" + +: "New CAPTCHA" += "" + +: "Register now" += "" + +: "Already have an account? %link%Sign in now%/link%" += "" + +: "Don't have an account? %link%Register now%/link%" += "" + +: "Edit post" += "" + +: "Message:" += "" + +: "Cancel" += "" + +: "Save changes" += "" + +: "Permission denied" += "" + +: "Close" += "" + +: "Edit title" += "" + +: "Reply" += "" + +: "Delete topic" += "" + +: "(deleted)" += "" + +: "Started by %user% on %date%" += "" + +: "Welcome, %user%!" += "" + +: "This post has been deleted" += "" + +: "Profile picture" += "" + +: "Permalink" += "" + +: "Reply to post" += "" + +: "(edited)" += "" + +: "You" += "" + +: "Reply to this topic" += "" + +: "Attachments: (max. %max_attachment_count% files, max. %max_attachment_size% MiB each)" += "" + +: "Post reply" += "" + +: "Topic title:" += "" + +: "Create topic" += "" + +: "Member since %join_date%" += "" + +: "Your posts" += "" + +: "%display_name%'s posts" += "" + +: "unknown" += "" + +: "posted on %post_date% in %topic%" += "" + +: "Show all posts" += "" + +: "This user has not posted anything yet" += "" + +: "Edit profile" += "" + +: "Profile picture:" += "" + +: "Keep current profile picture" += "" + +: "No profile picture" += "" + +: "Remove profile picture" += "" + +: "Upload new profile picture" += "" + +:... +- "Select file" +- "Select files" +=... +- "" + +:... +- "%n% file selected" +- "%n% files selected" +- "No files selected" +=... +- "" + +: "Created this topic" += "" diff --git a/src/application/mystic/forum/Database.php b/src/application/mystic/forum/Database.php index 6d633fa..a1e67ea 100644 --- a/src/application/mystic/forum/Database.php +++ b/src/application/mystic/forum/Database.php @@ -47,13 +47,20 @@ class Database { return $buf; } + private static function exception_error_handler($errno, $errstr, $errfile, $errline ) { + throw new \ErrorException(html_entity_decode($errstr), $errno, 0, $errfile, $errline); + } + public function __construct(string $connectionString) { try { + set_error_handler(self::exception_error_handler(...)); $conn = \pg_connect($connectionString); if ($conn !== false) $this->connection = $conn; } catch (\ErrorException $ex) { throw new DatabaseConnectionException($ex->getMessage(), $ex->getCode(), $ex); + } finally { + restore_error_handler(); } } diff --git a/src/application/views/alert_error.php b/src/application/views/alert_error.php index c18546b..acdb295 100644 --- a/src/application/views/alert_error.php +++ b/src/application/views/alert_error.php @@ -1,3 +1,10 @@ +