summaryrefslogtreecommitdiff
path: root/php
diff options
context:
space:
mode:
authorConnor Thomson <blumatrikz@gmail.com>2026-09-20 21:23:09 -0700
committerConnor Thomson <blumatrikz@gmail.com>2026-09-20 21:23:09 -0700
commit070a27baa8f93c3bf191459b88d24d7430a78899 (patch)
tree8c96b12d16e1d219ef410ad0e45b2d886368bc5e /php
parent83cd353b01660f34d6fd894d15a27fb1b3aeab4c (diff)
Some fixes and updates
Diffstat (limited to 'php')
-rwxr-xr-xphp/header.php6
-rwxr-xr-xphp/replace.php6
-rw-r--r--php/user.php12
3 files changed, 23 insertions, 1 deletions
diff --git a/php/header.php b/php/header.php
index 0fd46df..18a043a 100755
--- a/php/header.php
+++ b/php/header.php
@@ -19,15 +19,19 @@
require_once ROOT . '/php/replace.php';
require_once ROOT . '/php/session.php';
+require_once ROOT . '/php/user.php';
$username = get_username();
if ($username === null) {
$account = import(ROOT . '/html/guest.html');
} else {
+ $admin = is_admin() ? import(ROOT . '/html/admin-link.html') : '';
+
$account = replace(ROOT . '/html/account.html', [
'{{username}}' => htmlspecialchars($username, ENT_QUOTES, 'UTF-8'),
- '{{profile}}' => rawurlencode($username)
+ '{{profile}}' => rawurlencode($username),
+ '{{admin}}' => $admin
]);
}
diff --git a/php/replace.php b/php/replace.php
index dcc5fb6..0823370 100755
--- a/php/replace.php
+++ b/php/replace.php
@@ -25,6 +25,12 @@ function replace(string $templatePath, array $replacements = []): string {
foreach ($replacements as $placeholder => $replacementValue) {
$replacementValue = tidy((string)$replacementValue);
+ if ($replacementValue === '') {
+ $pattern = '/^[ \t]*' . preg_quote($placeholder, '/') . '[ \t]*\n?/m';
+
+ $html = preg_replace($pattern, '', $html);
+ }
+
$pattern = '/^([ \t]*)' . preg_quote($placeholder, '/') . '/m';
$html = preg_replace_callback($pattern, function (array $match) use ($replacementValue) {
diff --git a/php/user.php b/php/user.php
index 8a424e5..9521dc5 100644
--- a/php/user.php
+++ b/php/user.php
@@ -19,6 +19,7 @@
require_once ROOT . '/php/session.php';
require_once ROOT . '/php/database.php';
+require_once ROOT . '/php/render.php';
const USER_STATUSES = ['none', 'member', 'mod', 'admin'];
@@ -46,4 +47,15 @@ function is_admin(): bool {
return $user !== null && $user['status'] === 'admin';
}
+function require_admin(): void {
+ if (is_admin()) {
+ return;
+ }
+
+ http_response_code(403);
+
+ render_content(ROOT . '/html/forbidden.html');
+ exit;
+}
+
?>