aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apache/sites/nowayforward_human.conf.tpl10
-rw-r--r--views/global/footer.php16
-rw-r--r--views/global/header.php35
-rw-r--r--views/global/router.php54
4 files changed, 111 insertions, 4 deletions
diff --git a/apache/sites/nowayforward_human.conf.tpl b/apache/sites/nowayforward_human.conf.tpl
index ba010c7..2a5f58f 100644
--- a/apache/sites/nowayforward_human.conf.tpl
+++ b/apache/sites/nowayforward_human.conf.tpl
@@ -7,11 +7,13 @@
SetHandler "proxy:unix:${PHP_FPM_SOCKET}|fcgi://localhost/"
</FilesMatch>
- RedirectMatch "^/$" /home/index.php
- RedirectMatch "^/index.html$" /home/index.php
- RedirectMatch "^/index.php$" /home/index.php
-
RewriteEngine On
+
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
+
+ RewriteCond %{REQUEST_URI} !/archives.*
+ RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
+ RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
+ RewriteRule ^(.*)$ /global/router.php
</VirtualHost>
diff --git a/views/global/footer.php b/views/global/footer.php
new file mode 100644
index 0000000..22c4631
--- /dev/null
+++ b/views/global/footer.php
@@ -0,0 +1,16 @@
+ </article>
+</body>
+<script type="text/javascript">
+ function eval_callbacks() {
+ if (authentication_response === null) {
+ setTimeout(eval_callbacks, 50);
+ }
+ else if (authentication_response !== "") {
+ for (callback of authentication_callbacks) {
+ callback(authentication_response);
+ }
+ }
+ }
+ eval_callbacks();
+</script>
+</html>
diff --git a/views/global/header.php b/views/global/header.php
new file mode 100644
index 0000000..a00c528
--- /dev/null
+++ b/views/global/header.php
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="robots" content="index, follow">
+ <meta name="theme-color" content="#2b2b2e">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <link rel="stylesheet" href="/styles.css">
+ <title><?= htmlspecialchars($title ?? "No Way Forward Human");?></title>
+</head>
+<body>
+ <script type="text/javascript" src="/authenticate.js"></script>
+ <header>
+ <nav>
+ <div class="fadeout-left"></div>
+ <a href="/">Home</a>
+ <div class="flex-expand"></div>
+ <a id="login" href="/login">Login</a>
+ <a id="register" href="/register">Register</a>
+ <a id="profile" href="/profile/" hidden>Profile</a>
+ <div class="fadeout-right"></div>
+ </nav>
+ <script type="text/javascript">
+ function updateNavbar(response) {
+ document.getElementById('login').hidden = true;
+ document.getElementById('register').hidden = true;
+
+ const profile = document.getElementById('profile');
+ profile.hidden = false;
+ profile.href += response;
+ }
+ authenticated(updateNavbar);
+ </script>
+ </header>
+ <article>
diff --git a/views/global/router.php b/views/global/router.php
new file mode 100644
index 0000000..8986dfe
--- /dev/null
+++ b/views/global/router.php
@@ -0,0 +1,54 @@
+<?php
+
+$VIEWS_DIR = __DIR__ . '/..';
+$CONTROLLERS_DIR = __DIR__ . '/../../controllers';
+$MODELS_DIR = __DIR__ . '/../../models';
+
+$uri = rtrim($_SERVER['REQUEST_URI'], '/');
+$root = '/' . @explode('/', $uri, 3)[1];
+
+function route_view() {
+ global $root;
+ global $uri;
+
+ switch ($root) {
+ case '/archive': return '/archive';
+ case '/profile': return '/profile';
+ case '/register': return '/register';
+ case '/login': return '/login';
+ }
+
+ switch ($uri) {
+ case '': case '/': case '/home':
+ return '/home';
+
+ case '/authenticate':
+ return '/profile/authenticate.php';
+
+ default:
+ http_response_code(404);
+ return '/404';
+ }
+}
+$view = $VIEWS_DIR . route_view();
+
+require_once '../../models/database.php';
+foreach (glob($MODELS_DIR . '/*.php') as $filename) {
+ require_once $filename;
+}
+
+if (str_ends_with($view, '.php')) {
+ require_once $view;
+}
+else {
+ @include_once "$view/meta.php";
+
+ if (isset($controller)) {
+ require_once "$CONTROLLERS_DIR/$controller.php";
+ require_once "$CONTROLLERS_DIR/meta.php";
+ }
+
+ require_once './header.php';
+ require_once "$view/index.php";
+ require_once './footer.php';
+}