summaryrefslogtreecommitdiff
path: root/php
diff options
context:
space:
mode:
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;
+}
+
?>