mirror of
https://github.com/standardebooks/web.git
synced 2025-07-19 12:54:48 -04:00
Add public domain day banner
This commit is contained in:
parent
1b604ca97f
commit
c65035630f
16 changed files with 293 additions and 105 deletions
|
@ -1,17 +1,18 @@
|
|||
<?
|
||||
$colorScheme = $_COOKIE['color-scheme'] ?? 'auto';
|
||||
$colorScheme = Enums\ColorSchemeType::tryFrom(HttpInput::Str(COOKIE, 'color-scheme') ?? Enums\ColorSchemeType::Auto->value);
|
||||
|
||||
?><?= Template::Header(['title' => 'Website Settings', 'description' => 'Adjust your settings for viewing the Standard Ebooks website.']) ?>
|
||||
<main>
|
||||
<h1>Website Settings</h1>
|
||||
<form action="/settings" method="<?= Enums\HttpMethod::Post->value ?>">
|
||||
<input type="hidden" name="_method" value="<?= Enums\HttpMethod::Patch->value ?>" />
|
||||
<label>
|
||||
<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>
|
||||
<option value="<?= Enums\ColorSchemeType::Auto->value ?>"<? if($colorScheme == Enums\ColorSchemeType::Auto){ ?> selected="selected"<? } ?>>Automatic</option>
|
||||
<option value="<?= Enums\ColorSchemeType::Light->value ?>"<? if($colorScheme == Enums\ColorSchemeType::Light){ ?> selected="selected"<? } ?>>Light</option>
|
||||
<option value="<?= Enums\ColorSchemeType::Dark->value ?>"<? if($colorScheme == Enums\ColorSchemeType::Dark){ ?> selected="selected"<? } ?>>Dark</option>
|
||||
</select>
|
||||
</span>
|
||||
</label>
|
||||
|
|
|
@ -1,30 +1,35 @@
|
|||
<?
|
||||
use Safe\DateTimeImmutable;
|
||||
|
||||
$hideDonationAlert = HttpInput::Bool(POST, 'hide-donation-alert');
|
||||
$colorScheme = HttpInput::Str(POST, 'color-scheme');
|
||||
$httpMethod = HttpInput::ValidateRequestMethod([Enums\HttpMethod::Patch]);
|
||||
|
||||
if($hideDonationAlert !== null){
|
||||
setcookie('hide-donation-alert', $hideDonationAlert ? 'true' : 'false', ['expires' => intval((new DateTimeImmutable('+1 month'))->format(Enums\DateTimeFormat::UnixTimestamp->value)), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => true, 'samesite' => 'Lax']);
|
||||
// PATCHing settings.
|
||||
if($httpMethod == Enums\HttpMethod::Patch){
|
||||
$hideDonationAlert = HttpInput::Bool(POST, 'hide-donation-alert');
|
||||
$hidePublicDomainDayBanner = HttpInput::Bool(POST, 'hide-public-domain-day-banner');
|
||||
$colorScheme = Enums\ColorSchemeType::tryFrom(HttpInput::Str(POST, 'color-scheme') ?? '');
|
||||
|
||||
if($hideDonationAlert !== null){
|
||||
setcookie('hide-donation-alert', $hideDonationAlert ? 'true' : 'false', ['expires' => intval((new DateTimeImmutable('+1 month'))->format(Enums\DateTimeFormat::UnixTimestamp->value)), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => true, 'samesite' => 'Lax']);
|
||||
}
|
||||
|
||||
if($hidePublicDomainDayBanner !== null){
|
||||
setcookie('hide-public-domain-day-banner', $hidePublicDomainDayBanner ? 'true' : 'false', ['expires' => intval((new DateTimeImmutable('+1 month'))->format(Enums\DateTimeFormat::UnixTimestamp->value)), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => true, 'samesite' => 'Lax']);
|
||||
}
|
||||
|
||||
if($colorScheme !== null){
|
||||
if($colorScheme == Enums\ColorSchemeType::Auto){
|
||||
// Delete the cookie; auto is the default
|
||||
setcookie('color-scheme', '', ['expires' => 0, 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => true, 'samesite' => 'Lax']);
|
||||
}
|
||||
else{
|
||||
setcookie('color-scheme', $colorScheme->value, ['expires' => intval((new DateTimeImmutable('+1 year'))->format(Enums\DateTimeFormat::UnixTimestamp->value)), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => true, 'samesite' => 'Lax']);
|
||||
}
|
||||
}
|
||||
|
||||
// HTTP 303, See other
|
||||
http_response_code(Enums\HttpCode::SeeOther->value);
|
||||
|
||||
$redirect = $_SERVER['HTTP_REFERER'] ?? '/';
|
||||
header('Location: ' . $redirect);
|
||||
}
|
||||
|
||||
if($colorScheme !== null){
|
||||
if($colorScheme !== 'dark' && $colorScheme !== 'light' && $colorScheme !== 'auto'){
|
||||
$colorScheme = 'auto';
|
||||
}
|
||||
|
||||
if($colorScheme == 'auto'){
|
||||
// Delete the cookie; auto is the default
|
||||
setcookie('color-scheme', '', ['expires' => 0, 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => true, 'samesite' => 'Lax']);
|
||||
}
|
||||
else{
|
||||
setcookie('color-scheme', $colorScheme, ['expires' => intval((new DateTimeImmutable('+1 year'))->format(Enums\DateTimeFormat::UnixTimestamp->value)), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => true, 'samesite' => 'Lax']);
|
||||
}
|
||||
}
|
||||
|
||||
// HTTP 303, See other
|
||||
http_response_code(Enums\HttpCode::SeeOther->value);
|
||||
|
||||
$redirect = $_SERVER['HTTP_REFERER'] ?? '/';
|
||||
header('Location: ' . $redirect);
|
||||
?>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue