web/www/bulk-downloads/get.php

88 lines
2.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?
use function Safe\apcu_fetch;
try{
$collection = null;
$collectionUrlName = HttpInput::Str(GET, 'collection');
$authorUrlName = HttpInput::Str(GET, 'author');
$canDownload = false;
if(Session::$User?->Benefits->CanBulkDownload){
$canDownload = true;
}
if($collectionUrlName !== null){
$collections = [];
// Get all collections and then find the specific one we're looking for.
try{
/** @var array<stdClass> $collections */
$collections = apcu_fetch('bulk-downloads-collections');
}
catch(Safe\Exceptions\ApcuException){
$result = Library::RebuildBulkDownloadsCache();
/** @var array<stdClass> $collections */
$collections = $result['collections'];
}
foreach($collections as $c){
if($c->UrlLabel == $collectionUrlName){
$collection = $c;
break;
}
}
}
if($authorUrlName !== null){
$authors = [];
// Get all authors and then find the specific one we're looking for.
try{
/** @var array<stdClass> $collections */
$collections = apcu_fetch('bulk-downloads-authors');
}
catch(Safe\Exceptions\ApcuException){
$result = Library::RebuildBulkDownloadsCache();
/** @var array<stdClass> $collections */
$collections = $result['authors'];
}
foreach($collections as $c){
if($c->UrlLabel == $authorUrlName){
$collection = $c;
break;
}
}
if($collection === null){
throw new Exceptions\AuthorNotFoundException();
}
}
if($collection === null){
throw new Exceptions\CollectionNotFoundException();
}
}
catch(Exceptions\AuthorNotFoundException){
Template::ExitWithCode(Enums\HttpCode::NotFound);
}
catch(Exceptions\CollectionNotFoundException){
Template::ExitWithCode(Enums\HttpCode::NotFound);
}
?><?= Template::Header(title: 'Download ', description: 'Download zip files containing all of the Standard Ebooks released in a given month.') ?>
<main>
<section class="bulk-downloads">
<h1>Download the <?= $collection->Label ?> Collection</h1>
<? if($canDownload){ ?>
<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>
<? }else{ ?>
<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>
<? } ?>
<?= Template::BulkDownloadTable(label: 'Collection', collections: [$collection]); ?>
</section>
</main>
<?= Template::Footer() ?>