From 686fff945e0b4697aa74da404ce90534bb7b121d Mon Sep 17 00:00:00 2001 From: Jonas Kohl Date: Thu, 26 Dec 2024 20:12:34 +0100 Subject: Add async email and topic subscribing --- src/index.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/index.php') diff --git a/src/index.php b/src/index.php index 8036a19..0580523 100644 --- a/src/index.php +++ b/src/index.php @@ -9,6 +9,8 @@ use mystic\forum\orm\Topic; use mystic\forum\orm\TopicLogMessage; use mystic\forum\orm\User; use mystic\forum\orm\UserPermissions; +use mystic\forum\orm\PendingEmail; +use mystic\forum\orm\Subscription; use mystic\forum\utils\RequestUtils; use mystic\forum\utils\StringUtils; use Twig\Environment; @@ -244,11 +246,11 @@ function expandTags(string $contents): string { }, $contents); } -function renderPostSummary(string $contents): string { +function renderPostSummary(string $contents, int $maxLength = 100): string { $contents = renderPost($contents); // remove spoiler contents so they don't appear in summaries $contents = preg_replace('/(.*?)/s', '[ ' . __("Spoiler") . ' ]', $contents); - return htmlentities(html_entity_decode(StringUtils::truncate(strip_tags($contents), 100))); + return htmlentities(html_entity_decode(StringUtils::truncate(strip_tags($contents), $maxLength))); } function renderPost(string $contents): string { @@ -299,6 +301,7 @@ function env(string $key): ?string { require_once __DIR__ . "/vendor/autoload.php"; require_once __DIR__ . "/application/i18n.php"; +require_once __DIR__ . "/application/common.php"; if ($_SERVER["REQUEST_METHOD"] === "GET" && isset($_GET["lang"])) { parse_str($_SERVER["QUERY_STRING"], $query); @@ -319,7 +322,7 @@ i18n_locale($user_locale); $db = null; try { - $db = new Database(Database::getConnectionString("db", getenv("POSTGRES_USER"), getenv("POSTGRES_PASSWORD"), getenv("POSTGRES_DBNAME"))); + $db = get_db(); } catch (DatabaseConnectionException $ex) { msg_error( __("Failed to connect to database:\n%details%", [ @@ -337,6 +340,8 @@ $db->ensureTable(Topic::class); $db->ensureTable(Post::class); $db->ensureTable(Attachment::class); $db->ensureTable(TopicLogMessage::class); +$db->ensureTable(PendingEmail::class); +$db->ensureTable(Subscription::class); $superuser = new User(); $superuser->id = "SUPERUSER"; -- cgit v1.2.3