diff --git a/README.md b/README.md index bf963add..6ac09274 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ Before submitting design contributions, please discuss them with the Standard Eb - Include in-use ebook slug as a search parameter when searching for artwork by keyword. -- Artwork searching/filtering should be done in pure SQL, no after-sql filtering in PHP. +- Artwork searching/filtering should be done in pure SQL, no after-SQL filtering in PHP. - Allow listing artwork by artist by visiting `/artworks/`, and link instances of artist name to that URL. diff --git a/lib/Artist.php b/lib/Artist.php index 4c18a478..850423e7 100644 --- a/lib/Artist.php +++ b/lib/Artist.php @@ -85,7 +85,7 @@ class Artist extends PropertiesBase{ public static function Get(?int $artistId): Artist{ if($artistId === null){ - throw new Exceptions\InvalidArtistException(); + throw new Exceptions\ArtistNotFoundException(); } $result = Db::Query(' @@ -95,7 +95,7 @@ class Artist extends PropertiesBase{ ', [$artistId], 'Artist'); if(sizeof($result) == 0){ - throw new Exceptions\InvalidArtistException(); + throw new Exceptions\ArtistNotFoundException(); } return $result[0]; diff --git a/lib/Artwork.php b/lib/Artwork.php index 1e931e7a..5074fc48 100644 --- a/lib/Artwork.php +++ b/lib/Artwork.php @@ -135,7 +135,7 @@ class Artwork extends PropertiesBase{ try{ $this->_Submitter = User::Get($this->SubmitterUserId); } - catch(Exceptions\InvalidUserException){ + catch(Exceptions\UserNotFoundException){ // Return null } } @@ -148,7 +148,7 @@ class Artwork extends PropertiesBase{ try{ $this->_Reviewer = User::Get($this->ReviewerUserId); } - catch(Exceptions\InvalidUserException){ + catch(Exceptions\UserNotFoundException){ // Return null } } @@ -486,7 +486,7 @@ class Artwork extends PropertiesBase{ // But we do a basic check that the string includes one _. It might not include a dash, for example anonymous_poetry if($this->EbookWwwFilesystemPath !== null){ if(mb_stripos($this->EbookWwwFilesystemPath, '_') === false){ - $error->Add(new Exceptions\InvalidEbookException('Invalid ebook. Expected file system slug like “c-s-lewis_poetry”.')); + $error->Add(new Exceptions\EbookNotFoundException('Invalid ebook. Expected file system slug like “c-s-lewis_poetry”.')); } } @@ -900,23 +900,23 @@ class Artwork extends PropertiesBase{ $artwork = new Artwork(); $artwork->Artist = new Artist(); - $artwork->Artist->Name = HttpInput::Str(POST, 'artist-name', false); + $artwork->Artist->Name = HttpInput::Str(POST, 'artist-name'); $artwork->Artist->DeathYear = HttpInput::Int(POST, 'artist-year-of-death'); - $artwork->Name = HttpInput::Str(POST, 'artwork-name', false); + $artwork->Name = HttpInput::Str(POST, 'artwork-name'); $artwork->CompletedYear = HttpInput::Int(POST, 'artwork-year'); - $artwork->CompletedYearIsCirca = HttpInput::Bool(POST, 'artwork-year-is-circa', false) ?? false; - $artwork->Tags = HttpInput::Str(POST, 'artwork-tags', false) ?? []; - $artwork->Status = HttpInput::Str(POST, 'artwork-status', false) ?? ArtworkStatus::Unverified; - $artwork->EbookWwwFilesystemPath = HttpInput::Str(POST, 'artwork-ebook-www-filesystem-path', false); - $artwork->IsPublishedInUs = HttpInput::Bool(POST, 'artwork-is-published-in-us', false); + $artwork->CompletedYearIsCirca = HttpInput::Bool(POST, 'artwork-year-is-circa') ?? false; + $artwork->Tags = HttpInput::Str(POST, 'artwork-tags') ?? []; + $artwork->Status = HttpInput::Str(POST, 'artwork-status') ?? ArtworkStatus::Unverified; + $artwork->EbookWwwFilesystemPath = HttpInput::Str(POST, 'artwork-ebook-www-filesystem-path'); + $artwork->IsPublishedInUs = HttpInput::Bool(POST, 'artwork-is-published-in-us') ?? false; $artwork->PublicationYear = HttpInput::Int(POST, 'artwork-publication-year'); - $artwork->PublicationYearPageUrl = HttpInput::Str(POST, 'artwork-publication-year-page-url', false); - $artwork->CopyrightPageUrl = HttpInput::Str(POST, 'artwork-copyright-page-url', false); - $artwork->ArtworkPageUrl = HttpInput::Str(POST, 'artwork-artwork-page-url', false); - $artwork->MuseumUrl = HttpInput::Str(POST, 'artwork-museum-url', false); - $artwork->Exception = HttpInput::Str(POST, 'artwork-exception', false); - $artwork->Notes = HttpInput::Str(POST, 'artwork-notes', false); + $artwork->PublicationYearPageUrl = HttpInput::Str(POST, 'artwork-publication-year-page-url'); + $artwork->CopyrightPageUrl = HttpInput::Str(POST, 'artwork-copyright-page-url'); + $artwork->ArtworkPageUrl = HttpInput::Str(POST, 'artwork-artwork-page-url'); + $artwork->MuseumUrl = HttpInput::Str(POST, 'artwork-museum-url'); + $artwork->Exception = HttpInput::Str(POST, 'artwork-exception'); + $artwork->Notes = HttpInput::Str(POST, 'artwork-notes'); return $artwork; } diff --git a/lib/Ebook.php b/lib/Ebook.php index a287069c..3674196f 100644 --- a/lib/Ebook.php +++ b/lib/Ebook.php @@ -91,20 +91,20 @@ class Ebook{ } catch(Exception){ // We may get an exception from preg_replace if the passed repo wwwFilesystemPath contains invalid UTF-8 characters, whichis a common injection attack vector - throw new Exceptions\InvalidEbookException('Invalid repo filesystem path: ' . $this->RepoFilesystemPath); + throw new Exceptions\EbookNotFoundException('Invalid repo filesystem path: ' . $this->RepoFilesystemPath); } } if(!is_dir($wwwFilesystemPath)){ - throw new Exceptions\InvalidEbookException('Invalid www filesystem path: ' . $wwwFilesystemPath); + throw new Exceptions\EbookNotFoundException('Invalid www filesystem path: ' . $wwwFilesystemPath); } if(!is_dir($this->RepoFilesystemPath)){ - throw new Exceptions\InvalidEbookException('Invalid repo filesystem path: ' . $this->RepoFilesystemPath); + throw new Exceptions\EbookNotFoundException('Invalid repo filesystem path: ' . $this->RepoFilesystemPath); } if(!is_file($wwwFilesystemPath . '/content.opf')){ - throw new Exceptions\InvalidEbookException('Invalid content.opf file: ' . $wwwFilesystemPath . '/content.opf'); + throw new Exceptions\EbookNotFoundException('Invalid content.opf file: ' . $wwwFilesystemPath . '/content.opf'); } $this->WwwFilesystemPath = $wwwFilesystemPath; diff --git a/lib/Exceptions/InvalidArtistException.php b/lib/Exceptions/ArtistNotFoundException.php similarity index 62% rename from lib/Exceptions/InvalidArtistException.php rename to lib/Exceptions/ArtistNotFoundException.php index b4fd38d5..67e0a3d8 100644 --- a/lib/Exceptions/InvalidArtistException.php +++ b/lib/Exceptions/ArtistNotFoundException.php @@ -1,6 +1,6 @@ $default * @return array */ - public static function GetArray(string $variable, array $default = null): ?array{ - return self::GetHttpVar($variable, HTTP_VAR_ARRAY, GET, $default); + public static function GetArray(string $variable): ?array{ + return self::GetHttpVar($variable, HTTP_VAR_ARRAY, GET); } - private static function GetHttpVar(string $variable, int $type, string $set, mixed $default): mixed{ + private static function GetHttpVar(string $variable, int $type, string $set): mixed{ $vars = []; switch($set){ @@ -110,7 +110,7 @@ class HttpInput{ } elseif($type !== HTTP_VAR_ARRAY && is_array($vars[$variable])){ // We asked for not an array, but we got an array - return $default; + return null; } else{ $var = trim($vars[$variable]); @@ -126,7 +126,7 @@ class HttpInput{ return intval($var); } catch(Exception){ - return $default; + return null; } } break; @@ -143,13 +143,13 @@ class HttpInput{ return floatval($var); } catch(Exception){ - return $default; + return null; } } break; } } - return $default; + return null; } } diff --git a/lib/NewsletterSubscription.php b/lib/NewsletterSubscription.php index 2690a997..3b07e083 100644 --- a/lib/NewsletterSubscription.php +++ b/lib/NewsletterSubscription.php @@ -38,7 +38,7 @@ class NewsletterSubscription extends PropertiesBase{ try{ $this->User = User::GetByEmail($this->User->Email); } - catch(Exceptions\InvalidUserException){ + catch(Exceptions\UserNotFoundException){ // User doesn't exist, create the user $this->User->Create(); } @@ -132,7 +132,11 @@ class NewsletterSubscription extends PropertiesBase{ // ORM METHODS // *********** - public static function Get(string $uuid): NewsletterSubscription{ + public static function Get(?string $uuid): NewsletterSubscription{ + if($uuid === null){ + throw new Exceptions\NewsletterSubscriptionNotFoundException(); + } + $result = Db::Query(' SELECT ns.* from NewsletterSubscriptions ns @@ -141,7 +145,7 @@ class NewsletterSubscription extends PropertiesBase{ ', [$uuid], 'NewsletterSubscription'); if(sizeof($result) == 0){ - throw new Exceptions\InvalidNewsletterSubscriptionException(); + throw new Exceptions\NewsletterSubscriptionNotFoundException(); } return $result[0]; diff --git a/lib/Payment.php b/lib/Payment.php index 0882c3a4..0c397e4a 100644 --- a/lib/Payment.php +++ b/lib/Payment.php @@ -39,7 +39,7 @@ class Payment extends PropertiesBase{ where UserId = ? ', [$this->User->Name, $this->User->UserId]); } - catch(Exceptions\InvalidUserException){ + catch(Exceptions\UserNotFoundException){ // User doesn't exist, create it now $this->User->Create(); } diff --git a/lib/Poll.php b/lib/Poll.php index e0e1277d..00c87992 100644 --- a/lib/Poll.php +++ b/lib/Poll.php @@ -100,7 +100,7 @@ class Poll extends PropertiesBase{ public static function Get(?int $pollId): Poll{ if($pollId === null){ - throw new Exceptions\InvalidPollException(); + throw new Exceptions\PollNotFoundException(); } $result = Db::Query(' @@ -110,7 +110,7 @@ class Poll extends PropertiesBase{ ', [$pollId], 'Poll'); if(sizeof($result) == 0){ - throw new Exceptions\InvalidPollException(); + throw new Exceptions\PollNotFoundException(); } return $result[0]; @@ -118,7 +118,7 @@ class Poll extends PropertiesBase{ public static function GetByUrlName(?string $urlName): Poll{ if($urlName === null){ - throw new Exceptions\InvalidPollException(); + throw new Exceptions\PollNotFoundException(); } $result = Db::Query(' @@ -128,7 +128,7 @@ class Poll extends PropertiesBase{ ', [$urlName], 'Poll'); if(sizeof($result) == 0){ - throw new Exceptions\InvalidPollException(); + throw new Exceptions\PollNotFoundException(); } return $result[0]; diff --git a/lib/PollItem.php b/lib/PollItem.php index 6b56387a..9f98dae2 100644 --- a/lib/PollItem.php +++ b/lib/PollItem.php @@ -36,7 +36,7 @@ class PollItem extends PropertiesBase{ public static function Get(?int $pollItemId): PollItem{ if($pollItemId === null ){ - throw new Exceptions\InvalidPollItemException(); + throw new Exceptions\PollItemNotFoundException(); } $result = Db::Query(' @@ -46,7 +46,7 @@ class PollItem extends PropertiesBase{ ', [$pollItemId], 'PollItem'); if(sizeof($result) == 0){ - throw new Exceptions\InvalidPollItemException(); + throw new Exceptions\PollItemNotFoundException(); } return $result[0]; diff --git a/lib/PollVote.php b/lib/PollVote.php index b4cb0203..88a4ca03 100644 --- a/lib/PollVote.php +++ b/lib/PollVote.php @@ -36,7 +36,7 @@ class PollVote extends PropertiesBase{ $error = new Exceptions\ValidationException(); if($this->User === null){ - $error->Add(new Exceptions\InvalidUserException()); + $error->Add(new Exceptions\UserNotFoundException()); } if($this->PollItemId === null){ @@ -44,11 +44,11 @@ class PollVote extends PropertiesBase{ } else{ if($this->PollItem === null){ - $error->Add(new Exceptions\InvalidPollException()); + $error->Add(new Exceptions\PollNotFoundException()); } else{ if($this->PollItem->Poll === null){ - $error->Add(new Exceptions\InvalidPollException()); + $error->Add(new Exceptions\PollNotFoundException()); } else{ if(!$this->PollItem->Poll->IsActive()){ @@ -67,7 +67,7 @@ class PollVote extends PropertiesBase{ $vote = PollVote::Get($this->PollItem->Poll->UrlName, $this->UserId); $error->Add(new Exceptions\PollVoteExistsException($vote)); } - catch(Exceptions\InvalidPollVoteException){ + catch(Exceptions\PollVoteNotFoundException){ // User hasn't voted yet, carry on } @@ -87,7 +87,7 @@ class PollVote extends PropertiesBase{ $this->User = User::GetByEmail($email); $this->UserId = $this->User->UserId; } - catch(Exceptions\InvalidUserException){ + catch(Exceptions\UserNotFoundException){ // Can't validate patron email - do nothing for now, // this will be caught later when we validate the vote during creation. // Save the email in the User object in case we want it later, @@ -109,7 +109,7 @@ class PollVote extends PropertiesBase{ public static function Get(?string $pollUrlName, ?int $userId): PollVote{ if($pollUrlName === null || $userId === null){ - throw new Exceptions\InvalidPollVoteException(); + throw new Exceptions\PollVoteNotFoundException(); } $result = Db::Query(' @@ -124,7 +124,7 @@ class PollVote extends PropertiesBase{ ', [$pollUrlName, $userId], 'PollVote'); if(sizeof($result) == 0){ - throw new Exceptions\InvalidPollVoteException(); + throw new Exceptions\PollVoteNotFoundException(); } return $result[0]; diff --git a/lib/Session.php b/lib/Session.php index e147ea84..8bbd86ec 100644 --- a/lib/Session.php +++ b/lib/Session.php @@ -64,7 +64,7 @@ class Session extends PropertiesBase{ self::SetSessionCookie($this->SessionId); } - catch(Exceptions\InvalidUserException){ + catch(Exceptions\UserNotFoundException){ throw new InvalidLoginException(); } } @@ -95,7 +95,7 @@ class Session extends PropertiesBase{ public static function Get(?string $sessionId): Session{ if($sessionId === null){ - throw new Exceptions\InvalidSessionException(); + throw new Exceptions\SessionNotFoundException(); } $result = Db::Query(' @@ -105,7 +105,7 @@ class Session extends PropertiesBase{ ', [$sessionId], 'Session'); if(sizeof($result) == 0){ - throw new Exceptions\InvalidSessionException(); + throw new Exceptions\SessionNotFoundException(); } return $result[0]; diff --git a/lib/User.php b/lib/User.php index 93046b26..d9828531 100644 --- a/lib/User.php +++ b/lib/User.php @@ -115,7 +115,7 @@ class User extends PropertiesBase{ public static function Get(?int $userId): User{ if($userId === null){ - throw new Exceptions\InvalidUserException(); + throw new Exceptions\UserNotFoundException(); } $result = Db::Query(' @@ -125,7 +125,7 @@ class User extends PropertiesBase{ ', [$userId], 'User'); if(sizeof($result) == 0){ - throw new Exceptions\InvalidUserException(); + throw new Exceptions\UserNotFoundException(); } return $result[0]; @@ -133,7 +133,7 @@ class User extends PropertiesBase{ public static function GetByEmail(?string $email): User{ if($email === null){ - throw new Exceptions\InvalidUserException(); + throw new Exceptions\UserNotFoundException(); } $result = Db::Query(' @@ -143,7 +143,7 @@ class User extends PropertiesBase{ ', [$email], 'User'); if(sizeof($result) == 0){ - throw new Exceptions\InvalidUserException(); + throw new Exceptions\UserNotFoundException(); } return $result[0]; @@ -154,7 +154,7 @@ class User extends PropertiesBase{ // Emails without that row may only be signed up for the newsletter and thus are not "registered" users // The identifier is either an email or a UUID (api key) if($identifier === null){ - throw new Exceptions\InvalidUserException(); + throw new Exceptions\UserNotFoundException(); } $result = Db::Query(' @@ -166,7 +166,7 @@ class User extends PropertiesBase{ ', [$identifier, $identifier], 'User'); if(sizeof($result) == 0){ - throw new Exceptions\InvalidUserException(); + throw new Exceptions\UserNotFoundException(); } if($result[0]->PasswordHash !== null && $password === null){ @@ -175,7 +175,7 @@ class User extends PropertiesBase{ } if($result[0]->PasswordHash !== null && !password_verify($password ?? '', $result[0]->PasswordHash)){ - throw new Exceptions\InvalidUserException(); + throw new Exceptions\UserNotFoundException(); } return $result[0]; diff --git a/www/artworks/edit.php b/www/artworks/edit.php index 7f1f6d76..d99efa7f 100644 --- a/www/artworks/edit.php +++ b/www/artworks/edit.php @@ -13,7 +13,7 @@ try{ } if($artwork === null){ - $artwork = Artwork::GetByUrl(HttpInput::Str(GET, 'artist-url-name', false) ?? '', HttpInput::Str(GET, 'artwork-url-name', false) ?? ''); + $artwork = Artwork::GetByUrl(HttpInput::Str(GET, 'artist-url-name'), HttpInput::Str(GET, 'artwork-url-name')); } if(!$artwork->CanBeEditedBy($GLOBALS['User'])){ diff --git a/www/artworks/get.php b/www/artworks/get.php index a780310c..bed50f80 100644 --- a/www/artworks/get.php +++ b/www/artworks/get.php @@ -3,11 +3,11 @@ use function Safe\session_unset; session_start(); -$saved = HttpInput::Bool(SESSION, 'artwork-saved', false); +$saved = HttpInput::Bool(SESSION, 'artwork-saved') ?? false; $exception = $_SESSION['exception'] ?? null; try{ - $artwork = Artwork::GetByUrl(HttpInput::Str(GET, 'artist-url-name') ?? '', HttpInput::Str(GET, 'artwork-url-name') ?? ''); + $artwork = Artwork::GetByUrl(HttpInput::Str(GET, 'artist-url-name'), HttpInput::Str(GET, 'artwork-url-name')); $isAdminView = $GLOBALS['User']->Benefits->CanReviewArtwork ?? false; // If the artwork is not approved, and we're not an admin or the submitter when they can edit, don't show it. diff --git a/www/artworks/index.php b/www/artworks/index.php index 2e26c5d3..6dde0d13 100644 --- a/www/artworks/index.php +++ b/www/artworks/index.php @@ -1,10 +1,10 @@ CanBeEditedBy($GLOBALS['User'])){ throw new Exceptions\InvalidPermissionsException(); @@ -65,7 +65,7 @@ try{ $artwork->Created = $originalArtwork->Created; $artwork->SubmitterUserId = $originalArtwork->SubmitterUserId; - $newStatus = ArtworkStatus::tryFrom(HttpInput::Str(POST, 'artwork-status', false) ?? ''); + $newStatus = ArtworkStatus::tryFrom(HttpInput::Str(POST, 'artwork-status') ?? ''); if($newStatus !== null){ if($originalArtwork->Status != $newStatus && !$originalArtwork->CanStatusBeChangedBy($GLOBALS['User'])){ throw new Exceptions\InvalidPermissionsException(); @@ -97,13 +97,13 @@ try{ // PATCHing a new artwork if($httpMethod == HTTP_PATCH){ - $artwork = Artwork::GetByUrl(HttpInput::Str(GET, 'artist-url-name', false), HttpInput::Str(GET, 'artwork-url-name', false)); + $artwork = Artwork::GetByUrl(HttpInput::Str(GET, 'artist-url-name'), HttpInput::Str(GET, 'artwork-url-name')); $exceptionRedirectUrl = $artwork->Url; // We can PATCH the status, the ebook www filesystem path, or both. - $newStatus = ArtworkStatus::tryFrom(HttpInput::Str(POST, 'artwork-status', false) ?? ''); + $newStatus = ArtworkStatus::tryFrom(HttpInput::Str(POST, 'artwork-status') ?? ''); if($newStatus !== null){ if($artwork->Status != $newStatus && !$artwork->CanStatusBeChangedBy($GLOBALS['User'])){ throw new Exceptions\InvalidPermissionsException(); @@ -112,7 +112,7 @@ try{ $artwork->ReviewerUserId = $GLOBALS['User']->UserId; } - $newEbookWwwFilesystemPath = HttpInput::Str(POST, 'artwork-ebook-www-filesystem-path', false) ?? null; + $newEbookWwwFilesystemPath = HttpInput::Str(POST, 'artwork-ebook-www-filesystem-path') ?? null; if($artwork->EbookWwwFilesystemPath != $newEbookWwwFilesystemPath && !$artwork->CanEbookWwwFilesysemPathBeChangedBy($GLOBALS['User'])){ throw new Exceptions\InvalidPermissionsException(); } diff --git a/www/bulk-downloads/collection.php b/www/bulk-downloads/collection.php index 90a38a4b..772c97bc 100644 --- a/www/bulk-downloads/collection.php +++ b/www/bulk-downloads/collection.php @@ -3,7 +3,7 @@ use function Safe\apcu_fetch; use function Safe\preg_replace; $canDownload = false; -$class = HttpInput::Str(GET, 'class', false) ?? ''; +$class = HttpInput::Str(GET, 'class'); if($class != 'authors' && $class != 'collections' && $class != 'subjects' && $class != 'months'){ Template::Emit404(); diff --git a/www/bulk-downloads/download.php b/www/bulk-downloads/download.php index 5d90d3b8..a75d545e 100644 --- a/www/bulk-downloads/download.php +++ b/www/bulk-downloads/download.php @@ -1,7 +1,7 @@ AuthorsHtml); $authorUrl = Formatter::EscapeHtml($ebooks[0]->AuthorsUrl); } -catch(Exceptions\InvalidAuthorException){ +catch(Exceptions\AuthorNotFoundException){ Template::Emit404(); } ?> '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]) ?> diff --git a/www/ebooks/ebook.php b/www/ebooks/ebook.php index f7c5a9e9..957d41b3 100644 --- a/www/ebooks/ebook.php +++ b/www/ebooks/ebook.php @@ -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(); } ?> 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]) ?> diff --git a/www/ebooks/index.php b/www/ebooks/index.php index 31ed03f1..decaff5a 100644 --- a/www/ebooks/index.php +++ b/www/ebooks/index.php @@ -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(); } ?> $pageTitle, 'feedUrl' => $feedUrl, 'feedTitle' => $feedTitle, 'highlight' => 'ebooks', 'description' => $pageDescription]) ?> diff --git a/www/feeds/atom/search.php b/www/feeds/atom/search.php index 8fbe3a10..80dcdea4 100644 --- a/www/feeds/atom/search.php +++ b/www/feeds/atom/search.php @@ -4,7 +4,7 @@ use Safe\DateTime; $ebooks = []; try{ - $query = HttpInput::Str(GET, 'query', false) ?? ''; + $query = HttpInput::Str(GET, 'query') ?? ''; if($query !== ''){ $ebooks = Library::Search($query); diff --git a/www/feeds/collection.php b/www/feeds/collection.php index 6de1e069..80f1ceee 100644 --- a/www/feeds/collection.php +++ b/www/feeds/collection.php @@ -4,8 +4,8 @@ use function Safe\glob; use function Safe\preg_replace; use function Safe\usort; -$class = HttpInput::Str(GET, 'class', false) ?? ''; -$type = HttpInput::Str(GET, 'type', false) ?? ''; +$class = HttpInput::Str(GET, 'class') ?? ''; +$type = HttpInput::Str(GET, 'type') ?? ''; if($class != 'authors' && $class != 'collections' && $class != 'subjects'){ Template::Emit404(); diff --git a/www/feeds/download.php b/www/feeds/download.php index 505a5cb7..d0663bbb 100644 --- a/www/feeds/download.php +++ b/www/feeds/download.php @@ -5,7 +5,7 @@ use function Safe\preg_match; // Basic authorization is handled in Core.php. By the time we get here, // a valid user has a session. -$path = HttpInput::Str(GET, 'path', false) ?? ''; +$path = HttpInput::Str(GET, 'path') ?? ''; try{ $path = '/feeds/' . $path; diff --git a/www/feeds/get.php b/www/feeds/get.php index 71772183..f795e969 100644 --- a/www/feeds/get.php +++ b/www/feeds/get.php @@ -1,8 +1,8 @@ $title, 'feedTitle' => $feedTitle, 'feedUrl' => $feedUrl, 'description' => $description]) ?> diff --git a/www/feeds/opds/search.php b/www/feeds/opds/search.php index 6717dc4f..7198f394 100644 --- a/www/feeds/opds/search.php +++ b/www/feeds/opds/search.php @@ -4,7 +4,7 @@ use Safe\DateTime; $ebooks = []; try{ - $query = HttpInput::Str(GET, 'query', false) ?? ''; + $query = HttpInput::Str(GET, 'query') ?? ''; if($query !== ''){ $ebooks = Library::Search($query); diff --git a/www/feeds/rss/search.php b/www/feeds/rss/search.php index b653eb30..7e06ebe5 100644 --- a/www/feeds/rss/search.php +++ b/www/feeds/rss/search.php @@ -4,7 +4,7 @@ use Safe\DateTime; $ebooks = []; try{ - $query = HttpInput::Str(GET, 'query', false) ?? ''; + $query = HttpInput::Str(GET, 'query') ?? ''; if($query !== ''){ $ebooks = Library::Search($query); diff --git a/www/manual/index.php b/www/manual/index.php index 9b645187..e2a8352f 100644 --- a/www/manual/index.php +++ b/www/manual/index.php @@ -7,7 +7,7 @@ use function Safe\sort; $currentManual = Manual::GetLatestVersion(); -$url = HttpInput::Str(GET, 'url', true) ?? ''; +$url = HttpInput::Str(GET, 'url') ?? ''; $url = preg_replace('|^/|ius', '', $url); $url = preg_replace('|\.php$|ius', '', $url); $url = preg_replace('|/$|ius', '', $url); diff --git a/www/newsletter/subscriptions/confirm.php b/www/newsletter/subscriptions/confirm.php index 171baf92..181b4219 100644 --- a/www/newsletter/subscriptions/confirm.php +++ b/www/newsletter/subscriptions/confirm.php @@ -4,7 +4,7 @@ session_start(); $subscription = new NewsletterSubscription(); try{ - $subscription = NewsletterSubscription::Get(HttpInput::Str(GET, 'uuid') ?? ''); + $subscription = NewsletterSubscription::Get(HttpInput::Str(GET, 'uuid')); if(!$subscription->IsConfirmed){ $subscription->Confirm(); @@ -14,6 +14,6 @@ try{ http_response_code(303); header('Location: ' . $subscription->Url); } -catch(Exceptions\InvalidNewsletterSubscriptionException){ +catch(Exceptions\NewsletterSubscriptionNotFoundException){ Template::Emit404(); } diff --git a/www/newsletter/subscriptions/delete.php b/www/newsletter/subscriptions/delete.php index feda432b..a8cd7485 100644 --- a/www/newsletter/subscriptions/delete.php +++ b/www/newsletter/subscriptions/delete.php @@ -9,7 +9,7 @@ try{ throw new Exceptions\InvalidRequestException(); } - $subscription = NewsletterSubscription::Get(HttpInput::Str(GET, 'uuid') ?? ''); + $subscription = NewsletterSubscription::Get(HttpInput::Str(GET, 'uuid')); $subscription->Delete(); if($requestType == REST){ @@ -20,7 +20,7 @@ catch(Exceptions\InvalidRequestException){ http_response_code(405); exit(); } -catch(Exceptions\InvalidNewsletterSubscriptionException){ +catch(Exceptions\NewsletterSubscriptionNotFoundException){ if($requestType == WEB){ Template::Emit404(); } diff --git a/www/newsletter/subscriptions/get.php b/www/newsletter/subscriptions/get.php index 9c336ebc..7290f523 100644 --- a/www/newsletter/subscriptions/get.php +++ b/www/newsletter/subscriptions/get.php @@ -13,7 +13,7 @@ try{ $created = true; } else{ - $subscription = NewsletterSubscription::Get(HttpInput::Str(GET, 'uuid', false) ?? ''); + $subscription = NewsletterSubscription::Get(HttpInput::Str(GET, 'uuid')); if(isset($_SESSION['subscription-created']) && $_SESSION['subscription-created'] == $subscription->UserId){ $created = true; diff --git a/www/newsletter/subscriptions/post.php b/www/newsletter/subscriptions/post.php index a3f841c4..dc5a1e0c 100644 --- a/www/newsletter/subscriptions/post.php +++ b/www/newsletter/subscriptions/post.php @@ -13,7 +13,7 @@ $requestType = HttpInput::RequestType(); $subscription = new NewsletterSubscription(); -if(HttpInput::Str(POST, 'automationtest', false)){ +if(HttpInput::Str(POST, 'automationtest')){ // A bot filled out this form field, which should always be empty. Pretend like we succeeded. if($requestType == WEB){ http_response_code(303); @@ -34,11 +34,11 @@ if(HttpInput::Str(POST, 'automationtest', false)){ try{ $subscription->User = new User(); - $subscription->User->Email = HttpInput::Str(POST, 'email', false); + $subscription->User->Email = HttpInput::Str(POST, 'email'); $subscription->IsSubscribedToNewsletter = HttpInput::Bool(POST, 'issubscribedtonewsletter') ?? false; $subscription->IsSubscribedToSummary = HttpInput::Bool(POST, 'issubscribedtosummary') ?? false; - $captcha = HttpInput::Str(SESSION, 'captcha', false) ?? ''; + $captcha = HttpInput::Str(SESSION, 'captcha') ?? ''; $exception = new Exceptions\ValidationException(); @@ -49,7 +49,7 @@ try{ $exception->Add($ex); } - if($captcha === '' || mb_strtolower($captcha) !== mb_strtolower(HttpInput::Str(POST, 'captcha', false) ?? '')){ + if($captcha === '' || mb_strtolower($captcha) !== mb_strtolower(HttpInput::Str(POST, 'captcha') ?? '')){ $exception->Add(new Exceptions\InvalidCaptchaException()); } diff --git a/www/polls/get.php b/www/polls/get.php index a8ee5734..c4a2c40e 100644 --- a/www/polls/get.php +++ b/www/polls/get.php @@ -5,7 +5,7 @@ $poll = new Poll(); $canVote = true; // Allow non-logged-in users to see the 'vote' button try{ - $poll = Poll::GetByUrlName(HttpInput::Str(GET, 'pollurlname', false)); + $poll = Poll::GetByUrlName(HttpInput::Str(GET, 'pollurlname')); if(!$poll->IsActive() && $poll->End !== null && $poll->End < new DateTime()){ // If the poll ended, redirect to the results diff --git a/www/polls/votes/index.php b/www/polls/votes/index.php index d17eeeba..3e3ebee8 100644 --- a/www/polls/votes/index.php +++ b/www/polls/votes/index.php @@ -2,7 +2,7 @@ $poll = new Poll(); try{ - $poll = Poll::GetByUrlName(HttpInput::Str(GET, 'pollurlname', false)); + $poll = Poll::GetByUrlName(HttpInput::Str(GET, 'pollurlname')); } catch(Exceptions\AppException){ Template::Emit404(); diff --git a/www/polls/votes/new.php b/www/polls/votes/new.php index 133dd0ff..7d0300b6 100644 --- a/www/polls/votes/new.php +++ b/www/polls/votes/new.php @@ -19,7 +19,7 @@ try{ $vote->User = $GLOBALS['User']; } - $poll = Poll::GetByUrlName(HttpInput::Str(GET, 'pollurlname', false)); + $poll = Poll::GetByUrlName(HttpInput::Str(GET, 'pollurlname')); try{ $vote = PollVote::Get($poll->UrlName, $GLOBALS['User']->UserId); @@ -27,7 +27,7 @@ try{ // Vote was found, don't allow another vote throw new Exceptions\PollVoteExistsException($vote); } - catch(Exceptions\InvalidPollVoteException){ + catch(Exceptions\PollVoteNotFoundException){ // Vote was not found, user is OK to vote } @@ -39,7 +39,7 @@ try{ catch(Exceptions\LoginRequiredException){ Template::RedirectToLogin(); } -catch(Exceptions\InvalidPollException){ +catch(Exceptions\PollNotFoundException){ Template::Emit404(); } catch(Exceptions\PollVoteExistsException $ex){ diff --git a/www/polls/votes/post.php b/www/polls/votes/post.php index 9e6f3484..ad8378d5 100644 --- a/www/polls/votes/post.php +++ b/www/polls/votes/post.php @@ -15,7 +15,7 @@ $vote = new PollVote(); try{ $vote->PollItemId = HttpInput::Int(POST, 'pollitemid'); - $vote->Create(HttpInput::Str(POST, 'email', false)); + $vote->Create(HttpInput::Str(POST, 'email')); session_unset(); @@ -38,7 +38,7 @@ catch(Exceptions\AppException $ex){ // Access via form; 303 redirect to the form, which will emit a 422 Unprocessable Entity http_response_code(303); - header('Location: /polls/' . HttpInput::Str(GET, 'pollurlname', false) . '/votes/new'); + header('Location: /polls/' . (HttpInput::Str(GET, 'pollurlname') ?? '') . '/votes/new'); } else{ // Access via REST api; 422 Unprocessable Entity diff --git a/www/sessions/new.php b/www/sessions/new.php index 0fa6e798..be7fe533 100644 --- a/www/sessions/new.php +++ b/www/sessions/new.php @@ -8,8 +8,8 @@ if($GLOBALS['User'] !== null){ exit(); } -$email = HttpInput::Str(SESSION, 'email', false); -$redirect = HttpInput::Str(SESSION, 'redirect', false) ?? HttpInput::Str(GET, 'redirect', false); +$email = HttpInput::Str(SESSION, 'email'); +$redirect = HttpInput::Str(SESSION, 'redirect') ?? HttpInput::Str(GET, 'redirect'); $exception = $_SESSION['exception'] ?? null; $passwordRequired = false; diff --git a/www/sessions/post.php b/www/sessions/post.php index f17b90d6..ca51d714 100644 --- a/www/sessions/post.php +++ b/www/sessions/post.php @@ -12,9 +12,9 @@ session_start(); $requestType = HttpInput::RequestType(); $session = new Session(); -$email = HttpInput::Str(POST, 'email', false); -$password = HttpInput::Str(POST, 'password', false); -$redirect = HttpInput::Str(POST, 'redirect', false); +$email = HttpInput::Str(POST, 'email'); +$password = HttpInput::Str(POST, 'password'); +$redirect = HttpInput::Str(POST, 'redirect'); try{ if($redirect === null){