Refactor HttpInput::Str and rename some exceptions for consistency

This commit is contained in:
Alex Cabal 2024-01-18 11:15:59 -06:00
parent 2b5f4f55a2
commit ca3fc6dbfd
54 changed files with 163 additions and 159 deletions

View file

@ -4,24 +4,24 @@ $author = '';
$authorUrl = '';
try{
$urlPath = trim(str_replace('.', '', HttpInput::Str(GET, 'url-path', true) ?? ''), '/'); // Contains the portion of the URL (without query string) that comes after https://standardebooks.org/ebooks/
$urlPath = trim(str_replace('.', '', HttpInput::Str(GET, 'url-path') ?? ''), '/'); // Contains the portion of the URL (without query string) that comes after https://standardebooks.org/ebooks/
$wwwFilesystemPath = EBOOKS_DIST_PATH . $urlPath; // Path to the deployed WWW files for this ebook
if($urlPath == '' || mb_stripos($wwwFilesystemPath, EBOOKS_DIST_PATH) !== 0 || !is_dir($wwwFilesystemPath)){
// Ensure the path exists and that the root is in our www directory
throw new Exceptions\InvalidAuthorException();
throw new Exceptions\AuthorNotFoundException();
}
$ebooks = Library::GetEbooksByAuthor($wwwFilesystemPath);
if(sizeof($ebooks) == 0){
throw new Exceptions\InvalidAuthorException();
throw new Exceptions\AuthorNotFoundException();
}
$author = strip_tags($ebooks[0]->AuthorsHtml);
$authorUrl = Formatter::EscapeHtml($ebooks[0]->AuthorsUrl);
}
catch(Exceptions\InvalidAuthorException){
catch(Exceptions\AuthorNotFoundException){
Template::Emit404();
}
?><?= Template::Header(['title' => 'Ebooks by ' . $author, 'feedUrl' => str_replace('/ebooks/', '/authors/', $authorUrl), 'feedTitle' => 'Standard Ebooks - Ebooks by ' . $author, 'highlight' => 'ebooks', 'description' => 'All of the Standard Ebooks ebooks by ' . $author]) ?>

View file

@ -14,12 +14,12 @@ $carousel = [];
$carouselTag = null;
try{
$urlPath = trim(str_replace('.', '', HttpInput::Str(GET, 'url-path', true) ?? ''), '/'); // Contains the portion of the URL (without query string) that comes after https://standardebooks.org/ebooks/
$urlPath = trim(str_replace('.', '', HttpInput::Str(GET, 'url-path') ?? ''), '/'); // Contains the portion of the URL (without query string) that comes after https://standardebooks.org/ebooks/
$wwwFilesystemPath = EBOOKS_DIST_PATH . $urlPath; // Path to the deployed WWW files for this ebook
if($urlPath == '' || mb_stripos($wwwFilesystemPath, EBOOKS_DIST_PATH) !== 0){
// Ensure the path exists and that the root is in our www directory
throw new Exceptions\InvalidEbookException();
throw new Exceptions\EbookNotFoundException();
}
// Were we passed the author and a work but not the translator?
// For example:
@ -104,7 +104,7 @@ catch(Exceptions\SeeOtherEbookException $ex){
header('Location: ' . $ex->Url);
exit();
}
catch(Exceptions\InvalidEbookException){
catch(Exceptions\EbookNotFoundException){
Template::Emit404();
}
?><?= 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]) ?>

View file

@ -4,11 +4,11 @@ use function Safe\preg_replace;
try{
$page = HttpInput::Int(GET, 'page') ?? 1;
$perPage = HttpInput::Int(GET, 'per-page') ?? EBOOKS_PER_PAGE;
$query = HttpInput::Str(GET, 'query', false) ?? '';
$query = HttpInput::Str(GET, 'query') ?? '';
$tags = HttpInput::GetArray('tags') ?? [];
$collection = HttpInput::Str(GET, 'collection', false);
$view = HttpInput::Str(GET, 'view', false);
$sort = HttpInput::Str(GET, 'sort', false);
$collection = HttpInput::Str(GET, 'collection');
$view = HttpInput::Str(GET, 'view');
$sort = HttpInput::Str(GET, 'sort');
$pages = 0;
$totalEbooks = 0;
$collectionObject = null;
@ -71,7 +71,7 @@ try{
$pageHeader = 'Free Ebooks in the ' . Formatter::EscapeHtml($collectionName) . ' ' . ucfirst($collectionType);
}
else{
throw new Exceptions\InvalidCollectionException();
throw new Exceptions\CollectionNotFoundException();
}
}
else{
@ -118,7 +118,7 @@ try{
$feedTitle = 'Standard Ebooks - Ebooks in the ' . Formatter::EscapeHtml($collectionName) . ' ' . $collectionType;
}
}
catch(Exceptions\InvalidCollectionException){
catch(Exceptions\CollectionNotFoundException){
Template::Emit404();
}
?><?= Template::Header(['title' => $pageTitle, 'feedUrl' => $feedUrl, 'feedTitle' => $feedTitle, 'highlight' => 'ebooks', 'description' => $pageDescription]) ?>