Merge reset.css into core.css, and add settings page for specifying dark mode preferences

This commit is contained in:
Alex Cabal 2021-01-02 16:53:01 -06:00
parent 27d081b644
commit 11224136d1
9 changed files with 272 additions and 196 deletions

23
www/settings/index.php Normal file
View file

@ -0,0 +1,23 @@
<?
require_once('Core.php');
$colorScheme = $_COOKIE['color-scheme'] ?? 'auto';
?><?= Template::Header(['title' => 'Website Settings', 'description' => 'Adjust your settings for viewing the Standard Ebooks website.']) ?>
<main>
<h1>Website Settings</h1>
<form action="/settings" method="post">
<label class="select">
<span>Color scheme</span>
<span>
<select name="color-scheme">
<option value="auto"<? if($colorScheme == 'auto'){ ?> selected="selected"<? } ?>>Automatic</option>
<option value="light"<? if($colorScheme == 'light'){ ?> selected="selected"<? } ?>>Light</option>
<option value="dark"<? if($colorScheme == 'dark'){ ?> selected="selected"<? } ?>>Dark</option>
</select>
</span>
</label>
<button>Apply</button>
</form>
</main>
<?= Template::Footer() ?>

21
www/settings/post.php Normal file
View file

@ -0,0 +1,21 @@
<?
require_once('Core.php');
$colorScheme = $_POST['color-scheme'] ?? 'auto';
if($colorScheme !== 'dark' && $colorScheme !== 'light' && $colorScheme !== 'auto'){
$colorScheme = 'auto';
}
if($colorScheme == 'auto'){
// Delete the cookie; auto is the default
setcookie('color-scheme', null, ['expires' => 0, 'path' => '/', 'secure' => true, 'httponly' => true]);
}
else{
setcookie('color-scheme', $colorScheme, ['expires' => strtotime('+10 years'), 'path' => '/', 'secure' => true, 'httponly' => true]);
}
// HTTP 303, See other
http_response_code(303);
header('Location: /settings');
?>