mirror of
https://github.com/standardebooks/web.git
synced 2025-07-13 01:52:02 -04:00
Add size warning when single-page download is larger than 1MB
This commit is contained in:
parent
e0c75b8ae0
commit
04759aa17b
5 changed files with 37 additions and 9 deletions
|
@ -1,6 +1,7 @@
|
|||
<?
|
||||
use Safe\DateTime;
|
||||
use function Safe\file_get_contents;
|
||||
use function Safe\filesize;
|
||||
use function Safe\json_encode;
|
||||
use function Safe\glob;
|
||||
use function Safe\preg_match;
|
||||
|
@ -57,6 +58,8 @@ class Ebook{
|
|||
public $Updated;
|
||||
public $TextUrl;
|
||||
public $TextSinglePageUrl;
|
||||
public $TextSinglePageSizeNumber = null;
|
||||
public $TextSinglePageSizeUnit = null;
|
||||
public $TocEntries = null; // A list of non-Roman ToC entries ONLY IF the work has the 'se:is-a-collection' metadata element, null otherwise
|
||||
|
||||
public function __construct(?string $wwwFilesystemPath = null){
|
||||
|
@ -100,10 +103,18 @@ class Ebook{
|
|||
|
||||
$this->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');
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -281,8 +281,8 @@ catch(Exceptions\InvalidEbookException $ex){
|
|||
<li property="schema:encoding" typeof="schema:mediaObject">
|
||||
<meta property="schema:description" content="XHTML"/>
|
||||
<meta property="schema:encodingFormat" content="application/xhtml+xml"/>
|
||||
<p>
|
||||
<a property="schema:contentUrl" href="<?= $ebook->TextSinglePageUrl ?>" class="page">Read on one page</a>
|
||||
<p<? if($ebook->TextSinglePageSizeNumber >= 3 && $ebook->TextSinglePageSizeUnit == 'M'){ ?> class="has-size"<? } ?>>
|
||||
<a property="schema:contentUrl" href="<?= $ebook->TextSinglePageUrl ?>" class="page">Read on one page</a><? if($ebook->TextSinglePageSizeNumber >= 3 && $ebook->TextSinglePageSizeUnit == 'M'){ ?><span><?= $ebook->TextSinglePageSizeNumber ?>MB</span><? } ?>
|
||||
</p>
|
||||
</li>
|
||||
<? } ?>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue