From 04759aa17b93b0e8d55c76cc547d0f9c69171a3b Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Fri, 13 Jan 2023 16:29:52 -0600 Subject: [PATCH] Add size warning when single-page download is larger than 1MB --- lib/Ebook.php | 15 +++++++++++++-- www/css/core.css | 24 +++++++++++++++++++++--- www/css/dark.css | 1 + www/ebooks/ebook.php | 4 ++-- www/ebooks/index.php | 2 -- 5 files changed, 37 insertions(+), 9 deletions(-) diff --git a/lib/Ebook.php b/lib/Ebook.php index 0758cea3..715d8db5 100644 --- a/lib/Ebook.php +++ b/lib/Ebook.php @@ -1,6 +1,7 @@ TextUrl = $this->Url . '/text'; - $tempPath = glob($this->WwwFilesystemPath . '/text/single-page.xhtml'); - if(sizeof($tempPath) > 0){ + try{ + $bytes = filesize($this->WwwFilesystemPath . '/text/single-page.xhtml'); + $sizes = 'BKMGTP'; + $factor = floor((strlen($bytes) - 1) / 3); + $this->TextSinglePageSizeNumber = sprintf('%.1f', $bytes / pow(1024, $factor)); + $this->TextSinglePageSizeUnit = $sizes[$factor] ?? ''; $this->TextSinglePageUrl = $this->Url . '/text/single-page'; } + catch(Exception $ex){ + // Single page file doesn't exist, just pass + } + // Generate the Kindle cover URL. $tempPath = glob($this->WwwFilesystemPath . '/downloads/*_EBOK_portrait.jpg'); diff --git a/www/css/core.css b/www/css/core.css index b720722f..284712e4 100644 --- a/www/css/core.css +++ b/www/css/core.css @@ -64,6 +64,7 @@ --light-input-border: #777; --light-input-outline: #000; --light-table-row-hover: #dddbd5; + --light-warning: #932d2d; --dark-body-bg: #2c3035; --dark-body-text: #fff; @@ -76,6 +77,7 @@ --dark-input-hover: #118460; --dark-input-outline: #fff; --dark-table-row-hover: #373b3f; + --dark-warning: #ec6161; --body-text: var(--light-body-text); --header: var(--light-header); @@ -90,6 +92,7 @@ --input-outline: var(--light-input-outline); --link-highlight: var(--button); --table-row-hover: var(--light-table-row-hover); + --warning: var(--light-warning); } /* Start CSS reset */ @@ -1141,9 +1144,6 @@ article.ebook #more-ebooks li:nth-child(4) img{ height: 180px; } -article.ebook #more-ebooks li:nth-child(3) img{ -} - time{ color: var(--sub-text); margin-right: 15px; @@ -2757,6 +2757,24 @@ aside button.close:active{ transition: transform .5s; } +article.ebook section#read-online ul li p.has-size{ + display: flex; +} + +article.ebook section#read-online ul li p.has-size span{ + color: var(--warning); + border: 1px solid var(--warning); + border-radius: 5px; + padding: .25rem .5rem; + margin-left: .5rem; +} + +article.ebook section#read-online ul li p.has-size span::before{ + content: "\f071"; + font-family: "Fork Awesome"; + margin-right: .25rem; +} + ul.feed p{ margin: 0; } diff --git a/www/css/dark.css b/www/css/dark.css index 8e4f12cc..222084ae 100644 --- a/www/css/dark.css +++ b/www/css/dark.css @@ -11,6 +11,7 @@ --input-outline: var(--dark-input-outline); --link-highlight: var(--button-highlight); /* lighter looks better in dark mode */ --table-row-hover: var(--dark-table-row-hover); + --warning: var(--dark-warning); } main.front-page > section > section figure img{ diff --git a/www/ebooks/ebook.php b/www/ebooks/ebook.php index 7ab1c64b..257b065b 100644 --- a/www/ebooks/ebook.php +++ b/www/ebooks/ebook.php @@ -281,8 +281,8 @@ catch(Exceptions\InvalidEbookException $ex){
  • -

    - Read on one page + TextSinglePageSizeNumber >= 3 && $ebook->TextSinglePageSizeUnit == 'M'){ ?> class="has-size"> + Read on one pageTextSinglePageSizeNumber >= 3 && $ebook->TextSinglePageSizeUnit == 'M'){ ?>TextSinglePageSizeNumber ?>MB

  • diff --git a/www/ebooks/index.php b/www/ebooks/index.php index 0bc96be0..cfb5fddf 100644 --- a/www/ebooks/index.php +++ b/www/ebooks/index.php @@ -56,7 +56,6 @@ try{ // Are we looking at a collection? if($collection !== null){ $ebooks = Library::GetEbooksByCollection($collection); - // Get the *actual* name of the collection, in case there are accent marks (like "Arsène Lupin") if(sizeof($ebooks) > 0){ foreach($ebooks[0]->Collections as $c){ @@ -86,7 +85,6 @@ try{ $ebooks = array_slice($ebooks, ($page - 1) * $perPage, $perPage); } - if($page > 1){ $pageTitle .= ', page ' . $page; }