Replace Template::Emit...() functions with more generic function

This commit is contained in:
Alex Cabal 2024-12-18 13:14:16 -06:00
parent f449c024ea
commit 806939ca49
40 changed files with 86 additions and 68 deletions

View file

@ -59,7 +59,7 @@ try{
setcookie('download-count', (string)$downloadCount, ['expires' => intval((new DateTimeImmutable('+2 week'))->format(Enums\DateTimeFormat::UnixTimestamp->value)), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => false, 'samesite' => 'Lax']);
}
catch(Exceptions\InvalidFileException | Exceptions\EbookNotFoundException){
Template::Emit404();
Template::ExitWithCode(Enums\HttpCode::NotFound);
}
?><?= Template::Header(['title' => 'Your Download Has Started!', 'downloadUrl' => $downloadUrl]) ?>
<main class="donate">

View file

@ -21,15 +21,15 @@ try{
}
// Editing published `Ebooks` is not supported.
Template::Emit404();
Template::ExitWithCode(Enums\HttpCode::NotFound);
}
catch(Exceptions\EbookNotFoundException){
Template::Emit404();
Template::ExitWithCode(Enums\HttpCode::NotFound);
}
catch(Exceptions\LoginRequiredException){
Template::RedirectToLogin();
}
catch(Exceptions\InvalidPermissionsException){
Template::Emit403();
Template::ExitWithCode(Enums\HttpCode::Forbidden);
}

View file

@ -75,7 +75,7 @@ catch(Exceptions\EbookNotFoundException){
exit();
}
Template::Emit404();
Template::ExitWithCode(Enums\HttpCode::NotFound);
}
?><?= Template::Header(['title' => strip_tags($ebook->TitleWithCreditsHtml) . ' - Free ebook download', 'ogType' => 'book', 'coverUrl' => $ebook->DistCoverUrl, 'highlight' => 'ebooks', 'description' => 'Free epub ebook download of the Standard Ebooks edition of ' . $ebook->Title . ': ' . $ebook->Description, 'canonicalUrl' => SITE_URL . $ebook->Url]) ?>
<main>

View file

@ -21,15 +21,15 @@ try{
}
// POSTing published `Ebooks` is not supported.
Template::Emit404();
Template::ExitWithCode(Enums\HttpCode::NotFound);
}
catch(Exceptions\EbookNotFoundException){
Template::Emit404();
Template::ExitWithCode(Enums\HttpCode::NotFound);
}
catch(Exceptions\LoginRequiredException){
Template::RedirectToLogin();
}
catch(Exceptions\InvalidPermissionsException){
Template::Emit403();
Template::ExitWithCode(Enums\HttpCode::Forbidden);
}

View file

@ -39,7 +39,7 @@ try{
}
}
catch(Exceptions\EbookNotFoundException){
Template::Emit404();
Template::ExitWithCode(Enums\HttpCode::NotFound);
}
?><?= Template::Header(['title' => strip_tags($ebook->TitleWithCreditsHtml) . ' - Free ebook download', 'highlight' => 'ebooks', 'description' => 'Free epub ebook download of the Standard Ebooks edition of ' . $ebook->Title . ': ' . $ebook->Description, 'canonicalUrl' => SITE_URL . $ebook->Url]) ?>
<main>