Basic routing code is now in place

This commit is contained in:
bye 2024-06-27 22:30:56 +01:00
parent cab32ed77e
commit 97cf3b02ac
7 changed files with 173 additions and 1 deletions

View file

@ -1 +1,44 @@
<?php
// Includes
try {
require "config.php";
} catch (Error $e) {
echo "<b>Critical error:</b> " . $e->getMessage() . "<br />This isn't your fault. Please contact the developers.";
exit;
}
// TODO: Init PDO.
// Starts the session
// TODO: write this to use the database to work across more than one server
session_start();
$uri_string = $_SERVER['REQUEST_URI']; // `/foo/bar?bar=foo&foo=bar`
$uri_explode = explode('?', $uri_string);
$path = $uri_explode[0]; // `/foo/bar`
$path_array = explode('/', $path);
// Remove trailing slashes
if (str_ends_with($path, '/') && $path != '/') {
http_response_code(308);
header('Location: '.substr($path,0, -1));
exit;
}
$routes = [
'' => function () { require 'views/home.php'; },
];
//print_r($path_array);
if (array_key_exists($path_array[1], $routes)) {
$res = $routes[$path_array[1]]();
if ($res == 404) {
require "views/404.php";
}
} else {
require "views/404.php";
}

52
styles/base.css Normal file
View file

@ -0,0 +1,52 @@
@import "colours.css";
:root {
color-scheme: light dark;
font-family: "Montserrat", system-ui, sans-serif;
}
body {
margin: 0;
}
header {
display: flex;
align-items: center;
padding: 1rem;
gap: 1rem;
justify-content: space-between;
background: var(--flax);
color: var(--dark-slate-gray);
}
main {
flex: 1;
}
#content {
margin: 1rem;
}
@media screen and (prefers-color-scheme: dark) {
header {
background: var(--dark-slate-gray);
color: var(--flax);
}
}
/* Font things */
.bc-1 {
font-weight: 700;
}
.bc-2 {
font-weight: 600;
}
.bc-3 {
font-weight: 400;
}

13
styles/colours.css Normal file
View file

@ -0,0 +1,13 @@
:root {
/* ByeCorps colour scheme. Use sparsely on this site. */
--byecorps-blue: #1b5652;
--byecorps-white: #e6feff;
/* ByeCorps ID colour scheme. Use on this site. */
--black-bean: #330f0a;
--dark-slate-gray: #394f49;
--fern-green: #65743a;
--flax: #efdd8d;
--mindaro: #f4fdaf;
}

View file

@ -1 +1,25 @@
<?php
http_response_code(404);
?>
<!doctype html>
<html lang="en">
<head>
<?php require "partials/head.php"; ?>
<title>404 ~> ByeCorps ID</title>
</head>
<body>
<?php include "partials/header.php"; ?>
<main>
<div id="content">
<h1>404</h1>
<p>Sorry, but that doesn't exist anymore.</p>
<p><small>(or it never existed)</small></p>
</div>
</main>
<?php include 'partials/footer.php'; ?>
</body>
</html>

17
views/home.php Normal file
View file

@ -0,0 +1,17 @@
<html>
<head>
<?php include 'partials/head.php'; ?>
<title>ByeCorps ID</title>
</head>
<body>
<?php include 'partials/header.php'; ?>
<h1>ByeCorps ID</h1>
<?php include 'partials/footer.php'; ?>
</body>
</html>

12
views/partials/head.php Normal file
View file

@ -0,0 +1,12 @@
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="/styles/base.css">
<?php
if (isset($page_title)) {
echo '<title>' . $page_title . '</title>';
}
?>

View file

@ -1 +1,12 @@
<?php
<header>
<div>
<a href="/" id="sitetitle">
<span class="bc-1">Bye</span><span class="bc-2">Corps</span><span class="bc-3"> ID</span>
</a>
</div>
<div>
Login disabled.
</div>
</header>