summaryrefslogtreecommitdiff
path: root/src/application/mystic
diff options
context:
space:
mode:
Diffstat (limited to 'src/application/mystic')
-rw-r--r--src/application/mystic/forum/orm/User.php3
-rw-r--r--src/application/mystic/forum/utils/FileUtils.php33
-rw-r--r--src/application/mystic/forum/utils/RequestUtils.php7
-rw-r--r--src/application/mystic/forum/utils/StringUtils.php4
4 files changed, 44 insertions, 3 deletions
diff --git a/src/application/mystic/forum/orm/User.php b/src/application/mystic/forum/orm/User.php
index 1db1d04..97acbaf 100644
--- a/src/application/mystic/forum/orm/User.php
+++ b/src/application/mystic/forum/orm/User.php
@@ -3,6 +3,7 @@ declare(strict_types=1);
namespace mystic\forum\orm;
+use mystic\forum\attributes\Column;
use mystic\forum\attributes\PrimaryKey;
use mystic\forum\attributes\Table;
use mystic\forum\attributes\Unique;
@@ -22,6 +23,8 @@ class User extends Entity {
public bool $passwordResetRequired;
public string $activationToken;
public bool $activated;
+ #[Column(columnType: "bytea")] public ?string $profilePicture;
+ public ?\DateTimeImmutable $nameLastChanged;
public function hasPermission(int $perm): bool {
if ($this->id === self::SUPERUSER_ID)
diff --git a/src/application/mystic/forum/utils/FileUtils.php b/src/application/mystic/forum/utils/FileUtils.php
new file mode 100644
index 0000000..1910f0c
--- /dev/null
+++ b/src/application/mystic/forum/utils/FileUtils.php
@@ -0,0 +1,33 @@
+<?php
+declare(strict_types=1);
+
+namespace mystic\forum\utils;
+
+final class FileUtils {
+ use StaticClass;
+
+ private const MIME_FILE = __DIR__ . "/../../../assets/mimetypes";
+ public const DEFAULT_MIME_TYPE = "application/octet-stream";
+
+ private static ?array $extToMime = null;
+
+ private static function ensureMimeMapping(): void {
+ if (self::$extToMime !== null)
+ return;
+
+ self::$extToMime = [];
+
+ $hFile = fopen(self::MIME_FILE, "r");
+ while (($ln = fgets($hFile)) !== false) {
+ [$mime, $extensions] = preg_split('/\t+/', $ln, 2);
+ $extensions = explode(" ", strtolower($extensions));
+ foreach ($extensions as $ext)
+ self::$extToMime[$ext] = $mime;
+ }
+ }
+
+ public static function getMimeTypeForExtension(string $extension, string $defaultMimeType = self::DEFAULT_MIME_TYPE): string {
+ self::ensureMimeMapping();
+ return self::$extToMime[strtolower($extension)] ?? $defaultMimeType;
+ }
+}
diff --git a/src/application/mystic/forum/utils/RequestUtils.php b/src/application/mystic/forum/utils/RequestUtils.php
index f6ce3a3..6599052 100644
--- a/src/application/mystic/forum/utils/RequestUtils.php
+++ b/src/application/mystic/forum/utils/RequestUtils.php
@@ -30,9 +30,10 @@ final class RequestUtils {
public static function getRequiredField(string $field): string {
$fieldValue = $_POST[$field] ?? null;
if ($fieldValue === null) {
- http_response_code(400);
- Messaging::error("Missing required field $field");
- exit;
+ //http_response_code(400);
+ //Messaging::error("Missing required field $field");
+ RequestUtils::triggerFormError("Missing required field '$field'");
+ //exit;
}
return $fieldValue;
}
diff --git a/src/application/mystic/forum/utils/StringUtils.php b/src/application/mystic/forum/utils/StringUtils.php
index 7d4bf9d..fd38915 100644
--- a/src/application/mystic/forum/utils/StringUtils.php
+++ b/src/application/mystic/forum/utils/StringUtils.php
@@ -21,4 +21,8 @@ final class StringUtils {
return ltrim($result, '_');
}
+
+ public static function truncate(string $str, int $maxLength, string $ellipsis = "…"): string {
+ return mb_strimwidth($str, 0, $maxLength, $ellipsis);
+ }
}