mirror of
https://github.com/standardebooks/web.git
synced 2025-07-13 10:02:02 -04:00
Improve tag and collection browsing and pagination
This commit is contained in:
parent
cfa54122d6
commit
6f86a1899b
4 changed files with 32 additions and 11 deletions
|
@ -5,7 +5,7 @@ class Collection{
|
||||||
|
|
||||||
public function __construct(string $name){
|
public function __construct(string $name){
|
||||||
$this->Name = $name;
|
$this->Name = $name;
|
||||||
$this->Url = '/collections/' . strtolower(str_replace(' ', '-', Formatter::ToPlainText($this->Name))) . '/';
|
$this->Url = '/collections/' . strtolower(str_replace(' ', '-', Formatter::ToPlainText(Formatter::RemoveDiacritics($this->Name)))) . '/';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -521,7 +521,7 @@ class Ebook{
|
||||||
|
|
||||||
public function IsInCollection(string $collection): bool{
|
public function IsInCollection(string $collection): bool{
|
||||||
foreach($this->Collections as $c){
|
foreach($this->Collections as $c){
|
||||||
if(strtolower($c->Name) == strtolower($collection)){
|
if(strtolower(Formatter::RemoveDiacritics($c->Name)) == strtolower(Formatter::RemoveDiacritics($collection))){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,9 +72,11 @@ catch(\Exception $ex){
|
||||||
<p><?= $ebook->ContributorsHtml ?></p>
|
<p><?= $ebook->ContributorsHtml ?></p>
|
||||||
<? } ?>
|
<? } ?>
|
||||||
<? if(sizeof($ebook->Collections) > 0){ ?>
|
<? if(sizeof($ebook->Collections) > 0){ ?>
|
||||||
<? foreach($ebook->Collections as $collection){ ?>
|
<p>Part of the
|
||||||
<p>Part of the <a href="<?= $collection->Url ?>"><?= Formatter::ToPlainText($collection->Name) ?> collection</a>.</p>
|
<? for($i = 0; $i < sizeof($ebook->Collections); $i++){ ?>
|
||||||
<? } ?>
|
<a href="<?= $ebook->Collections[$i]->Url ?>"><?= Formatter::ToPlainText(preg_replace('/^The /ius', '', (string)$ebook->Collections[$i]->Name) ?? '') ?></a><? if(sizeof($ebook->Collections) > 2){ ?><? if($i == sizeof($ebook->Collections) - 2){ ?>, and <? }elseif($i != sizeof($ebook->Collections) - 1){ ?>, <? } ?><? }elseif($i == sizeof($ebook->Collections) - 2){ ?> and <? } ?>
|
||||||
|
<? } ?>
|
||||||
|
collection<? if(sizeof($ebook->Collections) > 1){ ?>s<? } ?></a>.</p>
|
||||||
<? } ?>
|
<? } ?>
|
||||||
<ul class="tags"><? foreach($ebook->Tags as $tag){ ?><li><a href="<?= $tag->Url ?>"><?= Formatter::ToPlainText($tag->Name) ?></a></li><? } ?></ul>
|
<ul class="tags"><? foreach($ebook->Tags as $tag){ ?><li><a href="<?= $tag->Url ?>"><?= Formatter::ToPlainText($tag->Name) ?></a></li><? } ?></ul>
|
||||||
</aside>
|
</aside>
|
||||||
|
|
|
@ -28,15 +28,22 @@ try{
|
||||||
$tag = strtolower(str_replace('-', ' ', $tag));
|
$tag = strtolower(str_replace('-', ' ', $tag));
|
||||||
$ebooks = Library::GetEbooksByTag($tag);
|
$ebooks = Library::GetEbooksByTag($tag);
|
||||||
$pageTitle = 'Browse ebooks tagged “' . Formatter::ToPlainText($tag) . '”';
|
$pageTitle = 'Browse ebooks tagged “' . Formatter::ToPlainText($tag) . '”';
|
||||||
$pageDescription = 'A list of ebooks tagged “' . Formatter::ToPlainText($tag) . '”';
|
$pageDescription = 'Page ' . $page . ' of ebooks tagged “' . Formatter::ToPlainText($tag) . '”';
|
||||||
$pageHeader = 'Ebooks tagged “' . Formatter::ToPlainText($tag) . '”';
|
$pageHeader = 'Ebooks tagged “' . Formatter::ToPlainText($tag) . '”';
|
||||||
|
|
||||||
|
$pages = ceil(sizeof($ebooks) / EBOOKS_PER_PAGE);
|
||||||
|
|
||||||
|
$totalEbooks = sizeof($ebooks);
|
||||||
|
|
||||||
|
$ebooks = array_slice($ebooks, ($page - 1) * EBOOKS_PER_PAGE, EBOOKS_PER_PAGE);
|
||||||
}
|
}
|
||||||
elseif($collection !== null){
|
elseif($collection !== null){
|
||||||
$collection = strtolower(str_replace('-', ' ', $collection));
|
$collection = strtolower(str_replace('-', ' ', Formatter::RemoveDiacritics($collection)));
|
||||||
$ebooks = Library::GetEbooksByCollection($collection);
|
$ebooks = Library::GetEbooksByCollection($collection);
|
||||||
$pageTitle = 'Browse ebooks in the ' . Formatter::ToPlainText(ucwords($collection)) . ' collection';
|
$collectionName = ucwords(preg_replace('/^The /ius', '', $collection) ?? '');
|
||||||
$pageDescription = 'A list of ebooks in the ' . Formatter::ToPlainText(ucwords($collection)) . ' collection';
|
$pageTitle = 'Browse ebooks in the ' . Formatter::ToPlainText($collectionName) . ' collection';
|
||||||
$pageHeader = 'Ebooks in the ' . Formatter::ToPlainText(ucwords($collection)) . ' collection';
|
$pageDescription = 'A list of ebooks in the ' . Formatter::ToPlainText($collectionName) . ' collection';
|
||||||
|
$pageHeader = 'Ebooks in the ' . Formatter::ToPlainText($collectionName) . ' collection';
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$pageTitle = 'Browse Standard Ebooks';
|
$pageTitle = 'Browse Standard Ebooks';
|
||||||
|
@ -74,7 +81,7 @@ catch(\Exception $ex){
|
||||||
<? }else{ ?>
|
<? }else{ ?>
|
||||||
<?= Template::EbookGrid(['ebooks' => $ebooks]) ?>
|
<?= Template::EbookGrid(['ebooks' => $ebooks]) ?>
|
||||||
<? } ?>
|
<? } ?>
|
||||||
<? if($query === null){ ?>
|
<? if($query === null && $tag === null && $collection === null){ ?>
|
||||||
<nav>
|
<nav>
|
||||||
<a<? if($page > 1){ ?> href="/ebooks/<? if($page - 1 > 1){ ?>?page=<?= $page - 1 ?><? } ?><? if($sort != SORT_NEWEST){ ?><? if($page - 1 <= 1){ ?>?<? }else{ ?>&<? } ?>sort=<?= $sort ?><? } ?>"<? } ?> rel="previous">Back</a>
|
<a<? if($page > 1){ ?> href="/ebooks/<? if($page - 1 > 1){ ?>?page=<?= $page - 1 ?><? } ?><? if($sort != SORT_NEWEST){ ?><? if($page - 1 <= 1){ ?>?<? }else{ ?>&<? } ?>sort=<?= $sort ?><? } ?>"<? } ?> rel="previous">Back</a>
|
||||||
<ol>
|
<ol>
|
||||||
|
@ -84,6 +91,18 @@ catch(\Exception $ex){
|
||||||
</ol>
|
</ol>
|
||||||
<a<? if($page < ceil($totalEbooks / EBOOKS_PER_PAGE)){ ?> href="/ebooks/?page=<?= $page + 1 ?><? if($sort != SORT_NEWEST){ ?>&sort=<?= $sort ?><? } ?>"<? }else{ ?> class="disabled"<? } ?> rel="next">Next</a>
|
<a<? if($page < ceil($totalEbooks / EBOOKS_PER_PAGE)){ ?> href="/ebooks/?page=<?= $page + 1 ?><? if($sort != SORT_NEWEST){ ?>&sort=<?= $sort ?><? } ?>"<? }else{ ?> class="disabled"<? } ?> rel="next">Next</a>
|
||||||
</nav>
|
</nav>
|
||||||
|
<? }elseif($tag !== null){ ?>
|
||||||
|
<nav>
|
||||||
|
<a<? if($page > 1){ ?> href="/tags/<?= Formatter::ToPlainText(str_replace(' ', '-', $tag)) ?>/<? if($page - 1 > 1){ ?>?page=<?= $page - 1 ?><? } ?>"<? } ?> rel="previous">Back</a>
|
||||||
|
<ol>
|
||||||
|
<? for($i = 1; $i < $pages + 1; $i++){ ?>
|
||||||
|
<li<? if($page == $i){ ?> class="highlighted"<? } ?>><a href="/tags/<?= Formatter::ToPlainText(str_replace(' ', '-', $tag)) ?>/<? if($i - 1 >= 1){ ?>?page=<?= $i ?><? } ?>"><?= $i ?></a></li>
|
||||||
|
<? } ?>
|
||||||
|
</ol>
|
||||||
|
<a<? if($page < ceil($totalEbooks / EBOOKS_PER_PAGE)){ ?> href="/tags/<?= Formatter::ToPlainText(str_replace(' ', '-', $tag)) ?>/?page=<?= $page + 1 ?>"<? }else{ ?> class="disabled"<? } ?> rel="next">Next</a>
|
||||||
|
</nav>
|
||||||
|
<? } ?>
|
||||||
|
<? if($query === null && $tag === null && $collection === null){ ?>
|
||||||
<aside class="sort">
|
<aside class="sort">
|
||||||
<p>Sort by</p>
|
<p>Sort by</p>
|
||||||
<a class="button<? if($sort == SORT_NEWEST){ ?> check<? } ?>" href="/ebooks/">newest</a>
|
<a class="button<? if($sort == SORT_NEWEST){ ?> check<? } ?>" href="/ebooks/">newest</a>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue