Don't show download/feed links for an author if all of their books are placeholders

This commit is contained in:
Alex Cabal 2025-01-05 13:19:35 -06:00
parent cce0c328d1
commit d590ce74b9

View file

@ -2,6 +2,7 @@
$ebooks = [];
$author = '';
$authorUrl = '';
$showLinks = false;
try{
$urlPath = trim(str_replace('.', '', HttpInput::Str(GET, 'url-path') ?? ''), '/'); // Contains the portion of the URL (without query string) that comes after `https://standardebooks.org/ebooks/`.
@ -16,6 +17,14 @@ try{
throw new Exceptions\AuthorNotFoundException();
}
// If all of the author's ebooks are placeholders, don't show download/feed links.
foreach($ebooks as $ebook){
if(!$ebook->IsPlaceholder()){
$showLinks = true;
break;
}
}
$author = strip_tags($ebooks[0]->AuthorsHtml);
$authorUrl = $ebooks[0]->AuthorsUrl;
}
@ -25,10 +34,12 @@ catch(Exceptions\AuthorNotFoundException){
?><?= Template::Header(['title' => 'Ebooks by ' . $author, 'feedUrl' => str_replace('/ebooks/', '/authors/', $authorUrl), 'feedTitle' => 'Standard Ebooks - Ebooks by ' . $author, 'highlight' => 'ebooks', 'description' => 'All of the Standard Ebooks ebooks by ' . $author, 'canonicalUrl' => SITE_URL . $authorUrl]) ?>
<main class="ebooks">
<h1 class="is-collection">Ebooks by <?= $ebooks[0]->AuthorsHtml ?></h1>
<? if($showLinks){ ?>
<p class="ebooks-toolbar">
<a class="button" href="<?= Formatter::EscapeHtml($authorUrl) ?>/downloads">Download collection</a>
<a class="button" href="<?= Formatter::EscapeHtml($authorUrl) ?>/feeds">Feeds for this author</a>
</p>
<? } ?>
<?= Template::EbookGrid(['ebooks' => $ebooks, 'view' => Enums\ViewType::Grid]) ?>
<p class="feeds-alert">We also have <a href="/bulk-downloads">bulk ebook downloads</a> and a <a href="/collections">list of collections</a> available, as well as <a href="/feeds">ebook catalog feeds</a> for use directly in your ereader app or RSS reader.</p>
<?= Template::ContributeAlert() ?>