This commit is contained in:
Alex Cabal 2022-07-10 00:55:24 -05:00
parent d086ea59bd
commit 7f50f00b42
15 changed files with 303 additions and 130 deletions

View file

@ -0,0 +1,57 @@
<?
require_once('Core.php');
use function Safe\apcu_fetch;
$bulkDownloadCollection = null;
$exception = null;
$user = null;
try{
if(isset($_SERVER['PHP_AUTH_USER'])){
$user = User::GetByPatronIdentifier($_SERVER['PHP_AUTH_USER']);
}
}
catch(Exceptions\InvalidUserException $ex){
$exception = new Exceptions\InvalidPatronException();
}
try{
$collection = HttpInput::Str(GET, 'collection', false) ?? '';
$collections = [];
try{
$collections = apcu_fetch('bulk-downloads-collections');
}
catch(Safe\Exceptions\ApcuException $ex){
$result = Library::RebuildBulkDownloadsCache();
$collections = $result['collections'];
}
if(!isset($collections[$collection]) || sizeof($collections[$collection]) == 0){
throw new Exceptions\InvalidCollectionException();
}
$bulkDownloadCollection = $collections[$collection];
}
catch(Exceptions\InvalidCollectionException $ex){
Template::Emit404();
}
?><?= Template::Header(['title' => 'Download ', 'highlight' => '', 'description' => 'Download zip files containing all of the Standard Ebooks released in a given month.']) ?>
<main>
<section class="bulk-downloads">
<h1>Download the <?= $bulkDownloadCollection[0]->Label ?> Collection</h1>
<?= Template::Error(['exception' => $exception]) ?>
<? if($user === null){ ?>
<p><a href="/about#patrons-circle">Patrons circle members</a> can download zip files containing all of the ebooks in a collection. You can <a href="/donate#patrons-circle">join the Patrons Circle</a> with a small donation in support of our continuing mission to create free, beautiful digital literature.</p>
<p>If youre a Patrons Circle member, when prompted enter your email address and leave the password field blank to download this collection.</p>
<? }else{ ?>
<p>Select the ebook format in which youd like to download this collection.</p>
<p>You can also read about <a href="/help/how-to-use-our-ebooks#which-file-to-download">which ebook format to download</a>.</p>
<? } ?>
<?= Template::BulkDownloadTable(['label' => 'Collection', 'collections' => [$bulkDownloadCollection]]); ?>
</section>
</main>
<?= Template::Footer() ?>

View file

@ -14,15 +14,18 @@ if(isset($_SERVER['PHP_AUTH_USER'])){
$years = [];
$subjects = [];
$collections = [];
try{
$years = apcu_fetch('bulk-downloads-years');
$subjects = apcu_fetch('bulk-downloads-subjects');
$collections = apcu_fetch('bulk-downloads-collections');
}
catch(Safe\Exceptions\ApcuException $ex){
$result = Library::RebuildBulkDownloadsCache();
$years = $result['years'];
$subjects = $result['subjects'];
$collections = $result['collections'];
}
?><?= Template::Header(['title' => 'Bulk Ebook Downloads', 'highlight' => '', 'description' => 'Download zip files containing all of the Standard Ebooks released in a given month.']) ?>
@ -35,11 +38,7 @@ catch(Safe\Exceptions\ApcuException $ex){
<img src="/images/the-shop-of-the-bookdealer@2x.jpg" alt="A gentleman in regency-era dress buys books from a bookseller."/>
</picture>
<? if($forbiddenException !== null){ ?>
<ul class="message error">
<li>
<p><?= Formatter::ToPlainText($forbiddenException->getMessage()) ?></p>
</li>
</ul>
<?= Template::Error(['exception' => $forbiddenException]) ?>
<? } ?>
<p><a href="/about#patrons-circle">Patrons circle members</a> can download zip files containing all of the ebooks that were released in a given month of Standard Ebooks history. You can <a href="/donate#patrons-circle">join the Patrons Circle</a> with a small donation in support of our continuing mission to create free, beautiful digital literature.</p>
<p>These zip files contain each ebook in every format we offer, and are updated once daily with the latest versions of each ebook.</p>
@ -47,54 +46,36 @@ catch(Safe\Exceptions\ApcuException $ex){
<section id="downloads-by-subject">
<h2>Downloads by subject</h2>
<table class="download-list">
<thead>
<tr class="mid-header">
<td></td>
<th scope="col">Ebooks</th>
<th scope="col">Updated</th>
<th scope="col" colspan="10">Download</th>
</tr>
</thead>
<tbody>
<? foreach($subjects as $subject => $items){ ?>
<tr>
<td class="row-header"><?= Formatter::ToPlainText($subject) ?></td>
<td class="number"><?= Formatter::ToPlainText(number_format($items[0]->Count)) ?></td>
<td class="number"><?= Formatter::ToPlainText($items[0]->UpdatedString) ?></td>
<?= Template::BulkDownloadTable(['label' => 'Subject', 'collections' => $subjects]); ?>
</section>
<? foreach($items as $item){ ?>
<td class="download"><a href="<?= $item->Url ?>" download=""><?= $item->Type ?></a></td>
<td>(<?= Formatter::ToPlainText($item->Size) ?>)</td>
<? } ?>
</tr>
<? } ?>
</tbody>
</table>
<section id="downloads-by-collection">
<h2>Downloads by collection</h2>
<?= Template::BulkDownloadTable(['label' => 'Collection', 'collections' => $collections]); ?>
</section>
<section id="downloads-by-year">
<h2>Downloads by year</h2>
<h2>Downloads by month</h2>
<table class="download-list">
<tbody>
<? foreach($years as $year => $months){
$yearHeader = Formatter::ToPlainText((string)$year);
$yearHeader = Formatter::ToPlainText($year);
?>
<tr class="year-header">
<th colspan="13" scope="colgroup" id="<?= $yearHeader ?>"><?= Formatter::ToPlainText((string)$year) ?></th>
</tr>
<tr class="mid-header">
<td></td>
<th id="<?= $yearHeader?>-type" scope="col">Month</th>
<th id="<?= $yearHeader ?>-ebooks" scope="col">Ebooks</th>
<th id="<?= $yearHeader ?>-updated" scope="col">Updated</th>
<th id="<?= $yearHeader ?>-download" colspan="10" scope="col">Download</th>
<th id="<?= $yearHeader ?>-download" colspan="10" scope="col">Ebook format</th>
</tr>
<? foreach($months as $month => $items){
$monthHeader = $items[0]->Month;
$monthHeader = Formatter::ToPlainText($month);
?>
<tr>
<th class="row-header" headers="<?= $yearHeader ?>" id="<?= $monthHeader ?>"><?= Formatter::ToPlainText($month) ?></th>
<th class="row-header" headers="<?= $yearHeader ?> <?= $monthHeader ?> <?= $yearHeader ?>-type" id="<?= $monthHeader ?>"><?= Formatter::ToPlainText($month) ?></th>
<td class="number" headers="<?= $yearHeader ?> <?= $monthHeader ?> <?= $yearHeader ?>-ebooks"><?= Formatter::ToPlainText(number_format($items[0]->Count)) ?></td>
<td class="number" headers="<?= $yearHeader ?> <?= $monthHeader ?> <?= $yearHeader ?>-updated"><?= Formatter::ToPlainText($items[0]->UpdatedString) ?></td>
<? foreach($items as $item){ ?>

View file

@ -63,6 +63,7 @@
--light-input-hover: #000;
--light-input-border: #777;
--light-input-outline: #000;
--light-table-row-hover: #dddbd5;
--dark-body-bg: #2c3035;
--dark-body-text: #fff;
@ -74,6 +75,7 @@
--dark-input-border: #aaa;
--dark-input-hover: #118460;
--dark-input-outline: #fff;
--dark-table-row-hover: #373b3f;
--body-text: var(--light-body-text);
--header: var(--light-header);
@ -87,6 +89,7 @@
--input-border: var(--light-input-border);
--input-outline: var(--light-input-outline);
--link-highlight: var(--button);
--table-row-hover: var(--light-table-row-hover);
}
/* Start CSS reset */
@ -676,13 +679,17 @@ ul.message.error li:only-child{
}
.bulk-downloads > p,
.bulk-downloads > section > h2{
.bulk-downloads h2{
width: 100%;
max-width: 40rem;
margin-left: auto;
margin-right: auto;
}
.bulk-downloads h2{
text-align: center;
}
.download-list{
margin: auto;
}
@ -692,9 +699,11 @@ ul.message.error li:only-child{
}
.download-list thead tr.mid-header:first-child > *{
padding-top: 1rem;
padding-top: 2rem;
}
.download-list th.row-header,
.download-list .mid-header th:first-child,
.download-list .mid-header th:last-child{
text-align: left;
}
@ -728,6 +737,7 @@ ul.message.error li:only-child{
.download-list tbody .row-header{
font-weight: bold;
white-space: normal;
}
.download-list tbody tr td,
@ -735,6 +745,7 @@ ul.message.error li:only-child{
border-top: 1px dashed var(--table-border);
}
.download-list tbody tr:first-child > *,
.download-list tbody tr.year-header > *,
.download-list tbody tr.year-header + tr > *,
.download-list tbody tr.mid-header tr > *,
@ -743,11 +754,22 @@ ul.message.error li:only-child{
border: none;
}
.download-list tbody tr:not([class]):hover > *{
background: var(--table-row-hover);
}
.download-list tbody tr:only-child:not([class]):hover > *{
background: unset; /* Don't highlight on hover if there's only one row */
}
h2 + .download-list tr.year-header:first-child th{
padding-top: 2rem;
}
.download-list .year-header th{
padding-top: 4rem;
font-size: 1.4rem;
font-family: "League Spartan", Arial, sans-serif;
margin-top: 4rem;
line-height: 1.2;
letter-spacing: 1px;
text-transform: uppercase;
@ -2278,6 +2300,12 @@ article.step-by-step-guide ol ol{
width: 100%;
}
.download-collection{
display: flex;
justify-content: center;
margin-bottom: 2rem;
}
abbr.acronym{
font-variant: all-small-caps;
}

View file

@ -10,6 +10,7 @@
--input-border: var(--dark-input-border);
--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);
}
main.front-page > section > section figure img{

View file

@ -338,10 +338,14 @@ catch(Exceptions\InvalidEbookException $ex){
<? foreach($transcriptionSources as $source){ ?>
<li>
<p>
<? if($source->Type == SOURCE_PROJECT_GUTENBERG){ ?><a href="<?= Formatter::ToPlainText($source->Url) ?>" class="project-gutenberg">Transcription at Project Gutenberg</a><? } ?>
<? if($source->Type == SOURCE_PROJECT_GUTENBERG_AUSTRALIA){ ?><a href="<?= Formatter::ToPlainText($source->Url) ?>" class="project-gutenberg">Transcription at Project Gutenberg Australia</a><? } ?>
<? if($source->Type == SOURCE_PROJECT_GUTENBERG_CANADA){ ?><a href="<?= Formatter::ToPlainText($source->Url) ?>" class="project-gutenberg">Transcription at Project Gutenberg Canada</a><? } ?>
<? if($source->Type == SOURCE_WIKISOURCE){ ?><a href="<?= Formatter::ToPlainText($source->Url) ?>" class="wikisource">Transcription at Wikisource</a><? } ?>
<? if($source->Type == SOURCE_PROJECT_GUTENBERG){ ?><a href="<?= Formatter::ToPlainText($source->Url) ?>" class="project-gutenberg">Transcription at Project Gutenberg</a>
<? }elseif($source->Type == SOURCE_PROJECT_GUTENBERG_AUSTRALIA){ ?><a href="<?= Formatter::ToPlainText($source->Url) ?>" class="project-gutenberg">Transcription at Project Gutenberg Australia</a>
<? }elseif($source->Type == SOURCE_PROJECT_GUTENBERG_CANADA){ ?><a href="<?= Formatter::ToPlainText($source->Url) ?>" class="project-gutenberg">Transcription at Project Gutenberg Canada</a>
<? }elseif($source->Type == SOURCE_WIKISOURCE){ ?><a href="<?= Formatter::ToPlainText($source->Url) ?>" class="wikisource">Transcription at Wikisource</a>
<? }elseif($source->Type == SOURCE_FADED_PAGE){ ?><a href="<?= Formatter::ToPlainText($source->Url) ?>" class="globe">Transcription at Faded Page</a>
<? }else{?>
<a href="<?= Formatter::ToPlainText($source->Url) ?>" class="globe">Transcription</a>
<? } ?>
</p>
</li>
<? } ?>
@ -355,10 +359,10 @@ catch(Exceptions\InvalidEbookException $ex){
<? foreach($scanSources as $source){ ?>
<li>
<p>
<? if($source->Type == SOURCE_INTERNET_ARCHIVE){ ?><a href="<?= Formatter::ToPlainText($source->Url) ?>" class="internet-archive">Page scans at the Internet Archive</a><? } ?>
<? if($source->Type == SOURCE_HATHI_TRUST){ ?><a href="<?= Formatter::ToPlainText($source->Url) ?>" class="hathitrust">Page scans at HathiTrust</a><? } ?>
<? if($source->Type == SOURCE_GOOGLE_BOOKS){ ?><a href="<?= Formatter::ToPlainText($source->Url) ?>" class="google">Page scans at Google Books</a><? } ?>
<? if($source->Type == SOURCE_FADED_PAGE){ ?><a href="<?= Formatter::ToPlainText($source->Url) ?>" class="globe">Transcription at Faded Page</a><? } ?>
<? if($source->Type == SOURCE_INTERNET_ARCHIVE){ ?><a href="<?= Formatter::ToPlainText($source->Url) ?>" class="internet-archive">Page scans at the Internet Archive</a>
<? }elseif($source->Type == SOURCE_HATHI_TRUST){ ?><a href="<?= Formatter::ToPlainText($source->Url) ?>" class="hathitrust">Page scans at HathiTrust</a>
<? }elseif($source->Type == SOURCE_GOOGLE_BOOKS){ ?><a href="<?= Formatter::ToPlainText($source->Url) ?>" class="google">Page scans at Google Books</a>
<? }else{ ?><a href="<?= Formatter::ToPlainText($source->Url) ?>" class="globe">Page scans</a><? } ?>
</p>
</li>
<? } ?>

View file

@ -135,6 +135,9 @@ catch(Exceptions\InvalidCollectionException $ex){
<? if($collection === null){ ?>
<?= Template::SearchForm(['query' => $query, 'tags' => $tags, 'sort' => $sort, 'view' => $view, 'perPage' => $perPage]) ?>
<? } ?>
<? if($collection !== null && sizeof($ebooks) > 1){ ?>
<p class="download-collection"><a class="button" href="/collections/<?= Formatter::ToPlainText($collection) ?>/download">Download entire collection</a></p>
<? } ?>
<? if(sizeof($ebooks) == 0){ ?>
<p class="no-results">No ebooks matched your filters. You can try different filters, or <a href="/ebooks">browse all of our ebooks</a>.</p>
<? }else{ ?>
@ -151,6 +154,7 @@ catch(Exceptions\InvalidCollectionException $ex){
<a<? if($page < ceil($totalEbooks / $perPage)){ ?> href="/ebooks/?page=<?= $page + 1 ?><? if($queryString != ''){ ?>&amp;<?= $queryString ?><? } ?>" rel="next"<? }else{ ?> aria-disabled="true"<? } ?>>Next</a>
</nav>
<? } ?>
<p class="feeds-alert">We also have <a href="/bulk-downloads">bulk ebook downloads</a> available, as well as <a href="/feeds">ebook catalog feeds</a> for use directly in your ereader app or RSS reader.</p>
<? if(sizeof($ebooks) > 0 && $query == '' && sizeof($tags) == 0 && $collection === null && $page == 1){ ?>
<?= Template::ContributeAlert() ?>