diff options
Diffstat (limited to 'src/index.php')
-rw-r--r-- | src/index.php | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/index.php b/src/index.php index 5350680..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; @@ -27,6 +29,7 @@ if (($_SERVER["HTTP_USER_AGENT"] ?? "") === "") { } define("REGISTRATION_ENABLED", isTrue(env("REGISTRATION_ENABLED") ?? "")); +define("DEBUG", isTrue(env("DEBUG") ?? "")); const __ROOT__ = __DIR__; @@ -172,9 +175,11 @@ function render(string $page, array $context = [], array $functions = []): void $loader = new FilesystemLoader([ $templateDir . "/" . $currentTemplate, ]); - $twig = new Environment($loader, [ - // TODO Enable caching - ]); + $twigEnvConfig = []; + if (!DEBUG) { + $twigEnvConfig["cache"] = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "mybb-template-cache"; + } + $twig = new Environment($loader, $twigEnvConfig); $twig->addFunction(new TwigFunction("__", __(...), [ "is_safe" => ["html"] ])); $twig->addFunction(new TwigFunction("___", ___(...), [ "is_safe" => ["html"] ])); @@ -241,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('/<!--##SPOILER_START##-->(.*?)<!--##SPOILER_END##-->/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 { @@ -296,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); @@ -316,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%", [ @@ -334,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"; |