aboutsummaryrefslogtreecommitdiff
path: root/views
diff options
context:
space:
mode:
Diffstat (limited to 'views')
-rw-r--r--views/404/index.php1
-rw-r--r--views/404/meta.php3
-rw-r--r--views/archive/index.php29
-rw-r--r--views/archive/meta.php5
-rw-r--r--views/authenticate.js2
-rw-r--r--views/footer.php16
-rw-r--r--views/header.php36
-rw-r--r--views/home/index.php26
-rw-r--r--views/home/meta.php3
-rw-r--r--views/login/index.php19
-rw-r--r--views/login/meta.php4
-rw-r--r--views/meta.php19
-rw-r--r--views/profile/authenticate.php10
-rw-r--r--views/profile/index.php12
-rw-r--r--views/profile/meta.php4
-rw-r--r--views/register/index.php16
-rw-r--r--views/register/meta.php4
17 files changed, 73 insertions, 136 deletions
diff --git a/views/404/index.php b/views/404/index.php
new file mode 100644
index 0000000..72d5267
--- /dev/null
+++ b/views/404/index.php
@@ -0,0 +1 @@
+<h1>Error 404: Page not found!</h1>
diff --git a/views/404/meta.php b/views/404/meta.php
new file mode 100644
index 0000000..0d1676e
--- /dev/null
+++ b/views/404/meta.php
@@ -0,0 +1,3 @@
+<?php
+
+$title = 'Page not found!';
diff --git a/views/archive/index.php b/views/archive/index.php
index 64d6a77..4195eb2 100644
--- a/views/archive/index.php
+++ b/views/archive/index.php
@@ -1,16 +1,21 @@
<?php
- $title = $_GET["page_url"] . ' archive';
- include '../meta.php';
-
+ $exists = null;
$page = null;
- runController('archive');
+
+ try {
+ $page = Database\Webpage::fromDB($url);
+ $page->incrementVisits();
+ }
+ catch(Exception $e) {
+ $exists = Controller\doesWebsiteExist($url);
+ }
?>
<?php if ($page !== null): ?>
<iframe src="<?= "/archives/{$page->WID}" ?>" scrolling="no"></iframe>
- <form action="/sample_archive/index.php" method="POST">
- <input type="hidden" name="page_url" value="<?= $_GET["page_url"] ?>">
+ <form action="#" method="POST">
+ <input type="hidden" name="page_url" value="<?= $url ?>">
<input type="submit" value="Archive Now!">
</form>
<!-- Button to add to list -->
@@ -39,16 +44,16 @@
</section>
<?php endforeach; ?>
-<?php elseif(!doesWebsiteExist($_GET["page_url"])): ?>
- <h2>"<?= $_GET["page_url"] ?>" Does not exist!</h2>
+<?php elseif(!$exists): ?>
+ <h2>"<?= $url ?>" Does not exist!</h2>
<p>Submit another request or check the spelling of the site and try again</p>
- <a href="/home/index.php">Go back!</a>
+ <a href="/">Go back!</a>
<?php else: ?>
- <h2>"<?= $_GET["page_url"] ?>" hasn't been archived yet!</h2>
- <form action="/sample_archive/index.php" method="POST">
- <input type="hidden" name="page_url" value="<?= $_GET["page_url"] ?>">
+ <h2>"<?= $url ?>" hasn't been archived yet!</h2>
+ <form action="#" method="POST">
+ <input type="hidden" name="page_url" value="<?= $url ?>">
<input type="submit" value="Archive Now!">
</form>
diff --git a/views/archive/meta.php b/views/archive/meta.php
new file mode 100644
index 0000000..001d07c
--- /dev/null
+++ b/views/archive/meta.php
@@ -0,0 +1,5 @@
+<?php
+
+$url = $_GET['url'];
+$title = $url . ' archive';
+$controller = 'archive';
diff --git a/views/authenticate.js b/views/authenticate.js
index 5e1371a..8b158ce 100644
--- a/views/authenticate.js
+++ b/views/authenticate.js
@@ -8,7 +8,7 @@ function requestAuthentication() {
authentication_response = (request.status == 200) ? request.responseText : "";
}
- request.open("POST", "/profile/authenticate.php", true);
+ request.open("POST", "/authenticate", true);
request.setRequestHeader("Authorization", sessionStorage.getItem("token"));
request.send(null);
}
diff --git a/views/footer.php b/views/footer.php
deleted file mode 100644
index 22c4631..0000000
--- a/views/footer.php
+++ /dev/null
@@ -1,16 +0,0 @@
- </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/header.php b/views/header.php
deleted file mode 100644
index 3835dfb..0000000
--- a/views/header.php
+++ /dev/null
@@ -1,36 +0,0 @@
-<!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/index.php">Home</a>
- <a href="/sample_archive/index.php">Sample Archive</a>
- <div class="flex-expand"></div>
- <a id="login" href="/login/index.php">Login</a>
- <a id="register" href="/register/index.php">Register</a>
- <a id="profile" href="/profile/index.php" 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 += '?user=' + response;
- }
- authenticated(updateNavbar);
- </script>
- </header>
- <article>
diff --git a/views/home/index.php b/views/home/index.php
index f567744..abc872b 100644
--- a/views/home/index.php
+++ b/views/home/index.php
@@ -1,12 +1,8 @@
-<?php
- $title = 'Home';
- include '../meta.php';
-?>
-
<section class="highlight separate-margin">
<h2>Explore the archives or add a new page</h2>
- <form action="/archive/index.php" method="GET" class="font-125 flex-row width-100 center-margin">
- <input type="text" name="page_url" placeholder="Enter a URL" class="flex-expand">
+
+ <form action="/archive" method="GET" class="font-125 flex-row width-100 center-margin">
+ <input type="text" name="url" placeholder="Enter a URL" class="flex-expand">
<input type="submit" value="Search">
</form>
</section>
@@ -16,7 +12,7 @@
<h1>Most popular archives</h1>
<?php foreach(Database\Webpage::mostVisited(10) as $page): ?>
- <section class="card" onclick="open_archive('<?= $page->URL ?>')">
+ <section class="card" onclick="goto_archive('<?= $page->URL ?>')">
<section class="quickinfo">
<a href="<?= $page->URL ?>"><?= $page->URL ?></a>
<span class="float-right"><?= $page->Date ?></span>
@@ -29,16 +25,20 @@
<strong>Visits: <?= $page->Visits ?></strong>
<strong><!-- Archives count --></strong>
</section>
+ <script type="text/javascript">
+ function open_archive(url) {
+ window.location.href = '/archive/' + url;
+ }
+ </script>
</section>
<?php endforeach; ?>
+
<h1>...</h1>
<div class="card-blank-afterspace"></div>
<script type="text/javascript">
-function open_archive(url) {
- window.location.href = '/archive/index.php?page_url=' + url;
-}
+ function goto_archive(uri) {
+ window.location.href = '/archive/?url=' + uri;
+ }
</script>
-
-<?php end_page(); ?>
diff --git a/views/home/meta.php b/views/home/meta.php
new file mode 100644
index 0000000..4d1a472
--- /dev/null
+++ b/views/home/meta.php
@@ -0,0 +1,3 @@
+<?php
+
+$title = "Home";
diff --git a/views/login/index.php b/views/login/index.php
index e538319..1013874 100644
--- a/views/login/index.php
+++ b/views/login/index.php
@@ -1,16 +1,7 @@
-<?php
- $title = 'Login to your account';
- include '../meta.php';
-
- $status = null;
- $token = null;
- runController('login');
-?>
-
-<?php if ($status !== null): ?>
- <?php if ($status !== ""): ?>
+<?php if (isset($user_status)): ?>
+ <?php if ($user_status !== ""): ?>
<p>
- Fail: <?= $status ?>
+ Fail: <?= $user_status ?>
</p>
<?php else: ?>
<p>
@@ -18,12 +9,12 @@
</p>
<script type="text/javascript">
sessionStorage.setItem("token", "<?= $token ?>");
- window.location.href = "/home/index.php";
+ window.location.href = "/";
</script>
<?php endif; ?>
<?php endif; ?>
-<form action="./index.php" method="POST">
+<form action="#" method="POST">
<input type="text" name="username" placeholder="Username" minlength="1" pattern="[A-Za-z][A-Za-z_0-9]*">
<input type="password" name="password" placeholder="Password" minlength="4">
<input type="submit" value="Login">
diff --git a/views/login/meta.php b/views/login/meta.php
new file mode 100644
index 0000000..06be3e8
--- /dev/null
+++ b/views/login/meta.php
@@ -0,0 +1,4 @@
+<?php
+
+$title = 'Login to your account';
+$controller = 'login';
diff --git a/views/meta.php b/views/meta.php
deleted file mode 100644
index 4aa7b8f..0000000
--- a/views/meta.php
+++ /dev/null
@@ -1,19 +0,0 @@
-<?php
-
-if (isset($title)) {
- include_once "../header.php";
-}
-
-function end_page() {
- include_once "../footer.php";
-}
-
-include_once "../../models/database.php";
-foreach (glob("../../models/*.php") as $filename) {
- include_once $filename;
-}
-
-function runController(string $name) {
- include_once "../../controllers/$name.php";
- include_once '../../controllers/meta.php';
-}
diff --git a/views/profile/authenticate.php b/views/profile/authenticate.php
index 540d4a3..afe1ca7 100644
--- a/views/profile/authenticate.php
+++ b/views/profile/authenticate.php
@@ -8,17 +8,15 @@ if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
exit;
}
-include '../meta.php';
+try {
+ $headers = apache_request_headers();
+ $user = Database\Cookie::fromDB($headers["Authorization"]);
-$user = null;
-runController('user');
-
-if ($user !== null) {
http_response_code(200);
header('Content-Type: text/plain');
echo $user->Username;
}
-else {
+catch(Exception $e) {
http_response_code(401);
header('Content-Type: text/plain');
echo 'Bad token!';
diff --git a/views/profile/index.php b/views/profile/index.php
index 80b0c4a..2334c1b 100644
--- a/views/profile/index.php
+++ b/views/profile/index.php
@@ -1,9 +1,9 @@
<?php
- $title = $_GET["user"] . ' - Profile';
- include '../meta.php';
-
$user = null;
- runController('user');
+ try {
+ $user = Database\User::fromDB($username);
+ }
+ catch(Exception $e) {}
?>
<?php if ($user !== null): ?>
@@ -12,7 +12,5 @@
<?= $user->Role ?>
</section>
<?php else: ?>
- <h2>User "<?= $_GET["user"] ?>" doesn't exist!</h2>
+ <h2>User "<?= $username ?>" doesn't exist!</h2>
<?php endif; ?>
-
-<?php end_page(); ?>
diff --git a/views/profile/meta.php b/views/profile/meta.php
new file mode 100644
index 0000000..52764ef
--- /dev/null
+++ b/views/profile/meta.php
@@ -0,0 +1,4 @@
+<?php
+
+$username = explode('/', $uri, 4)[2];
+$title = "$username's profile";
diff --git a/views/register/index.php b/views/register/index.php
index 1dc7bea..86f4aa7 100644
--- a/views/register/index.php
+++ b/views/register/index.php
@@ -1,15 +1,7 @@
-<?php
- $title = 'Register a new user';
- include '../meta.php';
-
- $status = null;
- runController('register');
-?>
-
-<?php if ($status !== null): ?>
- <?php if ($status !== ""): ?>
+<?php if (isset($user_status)): ?>
+ <?php if ($user_status !== ""): ?>
<p>
- Fail: <?= $status ?>
+ Fail: <?= $user_status ?>
</p>
<?php else: ?>
<p>
@@ -18,7 +10,7 @@
<?php endif; ?>
<?php endif; ?>
-<form action="./index.php" method="POST">
+<form action="#" method="POST">
<input type="text" name="username" placeholder="Username" minlength="1" pattern="[A-Za-z][A-Za-z_0-9]*">
<input type="password" name="password" placeholder="Password" minlength="4">
<input type="submit" value="Register">
diff --git a/views/register/meta.php b/views/register/meta.php
new file mode 100644
index 0000000..0cf11ce
--- /dev/null
+++ b/views/register/meta.php
@@ -0,0 +1,4 @@
+<?php
+
+$title = 'Register a new account';
+$controller = 'register';