From 8cb6fd73154fd0d36fbfaf540774b636e73328ff Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Fri, 7 Aug 2020 15:06:50 -0500 Subject: [PATCH] Don't show AVIF images if they don't exist in the filesystem --- lib/Ebook.php | 16 ++++++++++++---- templates/EbookGrid.php | 2 +- www/ebooks/ebook.php | 4 ++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/Ebook.php b/lib/Ebook.php index 542b9c87..55ad8550 100644 --- a/lib/Ebook.php +++ b/lib/Ebook.php @@ -143,13 +143,21 @@ class Ebook{ } $hash = substr(sha1($this->GitCommits[0]->Timestamp->format('U') . ' ' . $this->GitCommits[0]->Message), 0, 8); $this->CoverImageUrl = '/images/covers/' . $this->UrlSafeIdentifier . '-' . $hash . '-cover.jpg'; - $this->CoverImageAvifUrl = '/images/covers/' . $this->UrlSafeIdentifier . '-' . $hash . '-cover.avif'; + if(file_exists(WEB_ROOT . '/images/covers/' . $this->UrlSafeIdentifier . '-cover.avif')){ + $this->CoverImageAvifUrl = '/images/covers/' . $this->UrlSafeIdentifier . '-' . $hash . '-cover.avif'; + } $this->CoverImage2xUrl = '/images/covers/' . $this->UrlSafeIdentifier . '-' . $hash . '-cover@2x.jpg'; - $this->CoverImage2xAvifUrl = '/images/covers/' . $this->UrlSafeIdentifier . '-' . $hash . '-cover@2x.avif'; + if(file_exists(WEB_ROOT . '/images/covers/' . $this->UrlSafeIdentifier . '-cover@2x.avif')){ + $this->CoverImage2xAvifUrl = '/images/covers/' . $this->UrlSafeIdentifier . '-' . $hash . '-cover@2x.avif'; + } $this->HeroImageUrl = '/images/covers/' . $this->UrlSafeIdentifier . '-' . $hash . '-hero.jpg'; - $this->HeroImageAvifUrl = '/images/covers/' . $this->UrlSafeIdentifier . '-' . $hash . '-hero.avif'; + if(file_exists(WEB_ROOT . '/images/covers/' . $this->UrlSafeIdentifier . '-hero.avif')){ + $this->HeroImageAvifUrl = '/images/covers/' . $this->UrlSafeIdentifier . '-' . $hash . '-hero.avif'; + } $this->HeroImage2xUrl = '/images/covers/' . $this->UrlSafeIdentifier . '-' . $hash . '-hero@2x.jpg'; - $this->HeroImage2xAvifUrl = '/images/covers/' . $this->UrlSafeIdentifier . '-' . $hash . '-hero@2x.avif'; + if(file_exists(WEB_ROOT . '/images/covers/' . $this->UrlSafeIdentifier . '-hero@2x.avif')){ + $this->HeroImage2xAvifUrl = '/images/covers/' . $this->UrlSafeIdentifier . '-' . $hash . '-hero@2x.avif'; + } // Now do some heavy XML lifting! $xml = new SimpleXMLElement(str_replace('xmlns=', 'ns=', $rawMetadata)); diff --git a/templates/EbookGrid.php b/templates/EbookGrid.php index cfbede62..0fda5f74 100644 --- a/templates/EbookGrid.php +++ b/templates/EbookGrid.php @@ -8,7 +8,7 @@ if(!isset($ebooks)){
  • - + CoverImage2xAvifUrl !== null){ ?> The cover for the Standard Ebooks edition of <?= Formatter::ToPlainText(strip_tags($ebook->TitleWithCreditsHtml)) ?> diff --git a/www/ebooks/ebook.php b/www/ebooks/ebook.php index 02d8647a..a122e2ff 100644 --- a/www/ebooks/ebook.php +++ b/www/ebooks/ebook.php @@ -79,7 +79,7 @@ catch(\Exception $ex){ - + HeroImage2xAvifUrl !== null){ ?> The cover for the Standard Ebooks edition of <?= Formatter::ToPlainText(strip_tags($ebook->TitleWithCreditsHtml)) ?> @@ -202,7 +202,7 @@ catch(\Exception $ex){
  • - + CoverImage2xAvifUrl !== null){ ?> The cover for the Standard Ebooks edition of <?= Formatter::ToPlainText(strip_tags($carouselEbook->TitleWithCreditsHtml)) ?>