From 0ed064c8f0a6c0392ac92b01949daedb78df6e01 Mon Sep 17 00:00:00 2001 From: Mike Colagrosso Date: Sat, 3 Feb 2024 13:34:04 -0700 Subject: [PATCH] Move single collection view to collections/get.php --- config/apache/standardebooks.org.conf | 2 +- config/apache/standardebooks.test.conf | 2 +- www/collections/get.php | 57 +++++++ www/ebooks/index.php | 197 +++++++++---------------- 4 files changed, 130 insertions(+), 128 deletions(-) create mode 100644 www/collections/get.php diff --git a/config/apache/standardebooks.org.conf b/config/apache/standardebooks.org.conf index 4393baa7..1dbf3732 100644 --- a/config/apache/standardebooks.org.conf +++ b/config/apache/standardebooks.org.conf @@ -254,7 +254,7 @@ Define webroot /standardebooks.org/web RewriteRule ^/ebooks/([^\./]+?)/downloads$ /bulk-downloads/get.php?author=$1 [QSA] RewriteRule ^/ebooks/([^\./]+?)/feeds$ /feeds/get.php?author=$1 [QSA] RewriteRule ^/subjects/([^\./]+?)$ /ebooks/index.php?tags[]=$1 [QSA] - RewriteRule ^/collections/([^\./]+?)$ /ebooks/index.php?collection=$1 [QSA] + RewriteRule ^/collections/([^\./]+?)$ /collections/get.php?collection=$1 [QSA] RewriteRule ^/collections/([^/]+?)/downloads$ /bulk-downloads/get.php?collection=$1 RewriteRule ^/collections/([^/]+?)/feeds$ /feeds/get.php?collection=$1 diff --git a/config/apache/standardebooks.test.conf b/config/apache/standardebooks.test.conf index a8043ec9..f07999cc 100644 --- a/config/apache/standardebooks.test.conf +++ b/config/apache/standardebooks.test.conf @@ -236,7 +236,7 @@ Define webroot /standardebooks.org/web RewriteRule ^/ebooks/([^\./]+?)/downloads$ /bulk-downloads/get.php?author=$1 [QSA] RewriteRule ^/ebooks/([^\./]+?)/feeds$ /feeds/get.php?author=$1 [QSA] RewriteRule ^/subjects/([^\./]+?)$ /ebooks/index.php?tags[]=$1 [QSA] - RewriteRule ^/collections/([^\./]+?)$ /ebooks/index.php?collection=$1 [QSA] + RewriteRule ^/collections/([^\./]+?)$ /collections/get.php?collection=$1 [QSA] RewriteRule ^/collections/([^/]+?)/downloads$ /bulk-downloads/get.php?collection=$1 RewriteRule ^/collections/([^/]+?)/feeds$ /feeds/get.php?collection=$1 diff --git a/www/collections/get.php b/www/collections/get.php new file mode 100644 index 00000000..7abb19af --- /dev/null +++ b/www/collections/get.php @@ -0,0 +1,57 @@ + 0){ + foreach($ebooks[0]->Collections as $c){ + if($collection == Formatter::MakeUrlSafe($c->Name)){ + $collectionObject = $c; + } + } + } + + if($collectionObject === null){ + throw new Exceptions\CollectionNotFoundException(); + } + + $collectionName = preg_replace('/^The /ius', '', $collectionObject->Name); + $collectionType = $collectionObject->Type ?? 'collection'; + + $pageTitle = 'Browse free ebooks in the ' . Formatter::EscapeHtml($collectionName) . ' ' . $collectionType; + $pageDescription = 'A list of free ebooks in the ' . Formatter::EscapeHtml($collectionName) . ' ' . $collectionType; + $pageHeader = 'Free Ebooks in the ' . Formatter::EscapeHtml($collectionName) . ' ' . ucfirst($collectionType); + + $feedUrl = '/collections/' . Formatter::EscapeHtml($collection); + $feedTitle = 'Standard Ebooks - Ebooks in the ' . Formatter::EscapeHtml($collectionName) . ' ' . $collectionType; +} +catch(Exceptions\CollectionNotFoundException){ + Template::Emit404(); +} +?> $pageTitle, 'feedUrl' => $feedUrl, 'feedTitle' => $feedTitle, 'highlight' => 'ebooks', 'description' => $pageDescription]) ?> +
+

+ + + + + +

+ Download collection + Collection feeds +

+ +

No ebooks matched your filters. You can try different filters, or browse all of our ebooks.

+ + $ebooks, 'view' => VIEW_GRID, 'collection' => $collectionObject]) ?> + + +

We also have bulk ebook downloads and a list of collections available, as well as ebook catalog feeds for use directly in your ereader app or RSS reader.

+
+ diff --git a/www/ebooks/index.php b/www/ebooks/index.php index f5e1ce5a..1ba89595 100644 --- a/www/ebooks/index.php +++ b/www/ebooks/index.php @@ -1,145 +1,90 @@ 0){ - foreach($ebooks[0]->Collections as $c){ - if($collection == Formatter::MakeUrlSafe($c->Name)){ - $collectionObject = $c; - } - } - } - if($collectionObject !== null){ - $collectionName = preg_replace('/^The /ius', '', $collectionObject->Name); - $collectionType = $collectionObject->Type ?? 'collection'; - - $pageTitle = 'Browse free ebooks in the ' . Formatter::EscapeHtml($collectionName) . ' ' . $collectionType; - $pageDescription = 'A list of free ebooks in the ' . Formatter::EscapeHtml($collectionName) . ' ' . $collectionType; - $pageHeader = 'Free Ebooks in the ' . Formatter::EscapeHtml($collectionName) . ' ' . ucfirst($collectionType); - } - else{ - throw new Exceptions\CollectionNotFoundException(); - } - } - else{ - $ebooks = Library::FilterEbooks($query != '' ? $query : null, $tags, $sort); - $pageTitle = 'Browse Standard Ebooks'; - $pageHeader = 'Browse Ebooks'; - $pages = ceil(sizeof($ebooks) / $perPage); - $totalEbooks = sizeof($ebooks); - $ebooks = array_slice($ebooks, ($page - 1) * $perPage, $perPage); - } - - if($page > 1){ - $pageTitle .= ', page ' . $page; - } - - $pageDescription = 'Page ' . $page . ' of the Standard Ebooks free ebook library'; - - if($collection === null){ - if($query != ''){ - $queryString .= '&query=' . urlencode($query); - } - - foreach($tags as $tag){ - $queryString .= '&tags[]=' . urlencode($tag); - } - - if($view !== null){ - $queryString .= '&view=' . urlencode($view); - } - - if($sort !== null){ - $queryString .= '&sort=' . urlencode($sort->value); - } - - if($perPage !== EBOOKS_PER_PAGE){ - $queryString .= '&per-page=' . urlencode((string)$perPage); - } - } - - $queryString = preg_replace('/^&/ius', '', $queryString); - - if($collection !== null){ - $feedUrl = '/collections/' . Formatter::EscapeHtml($collection); - $feedTitle = 'Standard Ebooks - Ebooks in the ' . Formatter::EscapeHtml($collectionName) . ' ' . $collectionType; - } +if($page <= 0){ + $page = 1; } -catch(Exceptions\CollectionNotFoundException){ - Template::Emit404(); + +if($perPage != EBOOKS_PER_PAGE && $perPage != 24 && $perPage != 48){ + $perPage = EBOOKS_PER_PAGE; } -?> $pageTitle, 'feedUrl' => $feedUrl, 'feedTitle' => $feedTitle, 'highlight' => 'ebooks', 'description' => $pageDescription]) ?> + +// If we're passed string values that are the same as the defaults, +// set them to null so that we can have cleaner query strings in the navigation footer +if($view !== null){ + $view = mb_strtolower($view); +} + +if($view === 'grid'){ + $view = null; +} + +if($sort == EbookSort::Newest){ + $sort = null; +} + +if(sizeof($tags) == 1 && mb_strtolower($tags[0]) == 'all'){ + $tags = []; +} + +$ebooks = Library::FilterEbooks($query != '' ? $query : null, $tags, $sort); +$pageTitle = 'Browse Standard Ebooks'; +$pageHeader = 'Browse Ebooks'; +$pages = ceil(sizeof($ebooks) / $perPage); +$totalEbooks = sizeof($ebooks); +$ebooks = array_slice($ebooks, ($page - 1) * $perPage, $perPage); + +if($page > 1){ + $pageTitle .= ', page ' . $page; +} + +$pageDescription = 'Page ' . $page . ' of the Standard Ebooks free ebook library'; + +if($query != ''){ + $queryString .= '&query=' . urlencode($query); +} + +foreach($tags as $tag){ + $queryString .= '&tags[]=' . urlencode($tag); +} + +if($view !== null){ + $queryString .= '&view=' . urlencode($view); +} + +if($sort !== null){ + $queryString .= '&sort=' . urlencode($sort->value); +} + +if($perPage !== EBOOKS_PER_PAGE){ + $queryString .= '&per-page=' . urlencode((string)$perPage); +} + +$queryString = preg_replace('/^&/ius', '', $queryString); + +?> $pageTitle, 'highlight' => 'ebooks', 'description' => $pageDescription]) ?>
- class="is-collection"> +

- $query, 'tags' => $tags, 'sort' => $sort, 'view' => $view, 'perPage' => $perPage]) ?> - - -

- Download collection - Collection feeds -

-

No ebooks matched your filters. You can try different filters, or browse all of our ebooks.

- $ebooks, 'view' => $view, 'collection' => $collectionObject]) ?> + $ebooks, 'view' => $view]) ?> - 0 && $collection === null){ ?> + 0){ ?>