From 6f86a1899b10a8290630398aa1336d473b7a9c57 Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Tue, 26 Feb 2019 18:28:45 -0600 Subject: [PATCH] Improve tag and collection browsing and pagination --- lib/Collection.php | 2 +- lib/Ebook.php | 2 +- www/ebooks/ebook.php | 8 +++++--- www/ebooks/index.php | 31 +++++++++++++++++++++++++------ 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/lib/Collection.php b/lib/Collection.php index 55e2cfcf..9d684559 100644 --- a/lib/Collection.php +++ b/lib/Collection.php @@ -5,7 +5,7 @@ class Collection{ public function __construct(string $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)))) . '/'; } } ?> diff --git a/lib/Ebook.php b/lib/Ebook.php index 89527915..edfa6a24 100644 --- a/lib/Ebook.php +++ b/lib/Ebook.php @@ -521,7 +521,7 @@ class Ebook{ public function IsInCollection(string $collection): bool{ foreach($this->Collections as $c){ - if(strtolower($c->Name) == strtolower($collection)){ + if(strtolower(Formatter::RemoveDiacritics($c->Name)) == strtolower(Formatter::RemoveDiacritics($collection))){ return true; } } diff --git a/www/ebooks/ebook.php b/www/ebooks/ebook.php index 17e317d4..8f6d7e6f 100644 --- a/www/ebooks/ebook.php +++ b/www/ebooks/ebook.php @@ -72,9 +72,11 @@ catch(\Exception $ex){

ContributorsHtml ?>

Collections) > 0){ ?> - Collections as $collection){ ?> -

Part of the Name) ?> collection.

- +

Part of the + Collections); $i++){ ?> + Collections[$i]->Name) ?? '') ?>Collections) > 2){ ?>Collections) - 2){ ?>, and Collections) - 1){ ?>, Collections) - 2){ ?> and + + collectionCollections) > 1){ ?>s.

diff --git a/www/ebooks/index.php b/www/ebooks/index.php index 246e904a..70ace3a1 100644 --- a/www/ebooks/index.php +++ b/www/ebooks/index.php @@ -28,15 +28,22 @@ try{ $tag = strtolower(str_replace('-', ' ', $tag)); $ebooks = Library::GetEbooksByTag($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) . '”'; + + $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){ - $collection = strtolower(str_replace('-', ' ', $collection)); + $collection = strtolower(str_replace('-', ' ', Formatter::RemoveDiacritics($collection))); $ebooks = Library::GetEbooksByCollection($collection); - $pageTitle = 'Browse ebooks in the ' . Formatter::ToPlainText(ucwords($collection)) . ' collection'; - $pageDescription = 'A list of ebooks in the ' . Formatter::ToPlainText(ucwords($collection)) . ' collection'; - $pageHeader = 'Ebooks in the ' . Formatter::ToPlainText(ucwords($collection)) . ' collection'; + $collectionName = ucwords(preg_replace('/^The /ius', '', $collection) ?? ''); + $pageTitle = 'Browse ebooks in the ' . Formatter::ToPlainText($collectionName) . ' collection'; + $pageDescription = 'A list of ebooks in the ' . Formatter::ToPlainText($collectionName) . ' collection'; + $pageHeader = 'Ebooks in the ' . Formatter::ToPlainText($collectionName) . ' collection'; } else{ $pageTitle = 'Browse Standard Ebooks'; @@ -74,7 +81,7 @@ catch(\Exception $ex){ $ebooks]) ?> - + + + + +