From 801b5f524a764c7c13de76ffa531f0982017fdb8 Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Fri, 26 Jan 2024 12:05:27 -0600 Subject: [PATCH] Add special 'query-ebook-url' parameter to /artworks to get covers matching exactly the ebook URL --- lib/Artwork.php | 2 +- www/artworks/index.php | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/Artwork.php b/lib/Artwork.php index f55a91ec..59336174 100644 --- a/lib/Artwork.php +++ b/lib/Artwork.php @@ -501,7 +501,7 @@ class Artwork extends PropertiesBase{ // We don't check if it exists, because the book might not be published yet. // But we do a basic check that the string includes one _. It might not include a dash, for example anonymous_poetry if($this->EbookUrl !== null){ - if(!preg_match('|^https://standardebooks.org/ebooks/|ius', $this->EbookUrl)){ + if(!preg_match('|^https://standardebooks.org/ebooks/[^/]+?/[^/]+?|ius', $this->EbookUrl)){ $error->Add(new Exceptions\EbookNotFoundException('Invalid ebook. Expected S.E. URL.')); } } diff --git a/www/artworks/index.php b/www/artworks/index.php index 23bcb1b4..3b4031d9 100644 --- a/www/artworks/index.php +++ b/www/artworks/index.php @@ -2,6 +2,7 @@ $page = HttpInput::Int(GET, 'page') ?? 1; $perPage = HttpInput::Int(GET, 'per-page') ?? ARTWORK_PER_PAGE; $query = HttpInput::Str(GET, 'query') ?? ''; +$queryEbookUrl = HttpInput::Str(GET, 'query-ebook-url'); $status = HttpInput::Str(GET, 'status') ?? null; $filterArtworkStatus = $status; $sort = HttpInput::Str(GET, 'sort'); @@ -64,7 +65,13 @@ if($isSubmitterView && !in_array($status, array('all', ArtworkStatus::Unverified $filterArtworkStatus = $status; } -$artworks = Library::FilterArtwork($query != '' ? $query : null, $filterArtworkStatus, $sort, $submitterUserId); +if($queryEbookUrl !== null){ + $artworks = Db::Query('SELECT * from Artworks where EbookUrl = ? and Status = ?', [$queryEbookUrl, ArtworkStatus::Approved], 'Artwork'); +} +else{ + $artworks = Library::FilterArtwork($query != '' ? $query : null, $filterArtworkStatus, $sort, $submitterUserId); +} + $pageTitle = 'Browse Artwork'; $pages = ceil(sizeof($artworks) / $perPage); $totalArtworkCount = sizeof($artworks);