+ = $pageHeader ?>
+ = Template::DonationCounter() ?>
+ = Template::DonationProgress() ?>
+ if(!DONATION_DRIVE_ON && !DONATION_DRIVE_COUNTER_ON && DONATION_HOLIDAY_ALERT_ON){ ?>
+ = Template::DonationAlert() ?>
+ } ?>
+
+ Download collection
+ Collection feeds
+
+ if(sizeof($ebooks) == 0){ ?>
+ No ebooks matched your filters. You can try different filters, or browse all of our ebooks.
+ }else{ ?>
+ = Template::EbookGrid(['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.
+
+= Template::Footer() ?>
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 @@
use function Safe\preg_replace;
-try{
- $page = HttpInput::Int(GET, 'page') ?? 1;
- $perPage = HttpInput::Int(GET, 'per-page') ?? EBOOKS_PER_PAGE;
- $query = HttpInput::Str(GET, 'query') ?? '';
- $tags = HttpInput::GetArray('tags') ?? [];
- $collection = HttpInput::Str(GET, 'collection');
- $view = HttpInput::Str(GET, 'view');
- $sort = EbookSort::tryFrom(HttpInput::Str(GET, 'sort') ?? '');
- $pages = 0;
- $totalEbooks = 0;
- $collectionObject = null;
- $pageDescription = '';
- $pageTitle = '';
- $pageHeader = '';
- $queryString = '';
- $feedUrl = null;
- $feedTitle = '';
- $collectionName = '';
- $collectionType = '';
+$page = HttpInput::Int(GET, 'page') ?? 1;
+$perPage = HttpInput::Int(GET, 'per-page') ?? EBOOKS_PER_PAGE;
+$query = HttpInput::Str(GET, 'query') ?? '';
+$tags = HttpInput::GetArray('tags') ?? [];
+$view = HttpInput::Str(GET, 'view');
+$sort = EbookSort::tryFrom(HttpInput::Str(GET, 'sort') ?? '');
+$queryString = '';
- if($page <= 0){
- $page = 1;
- }
-
- if($perPage != EBOOKS_PER_PAGE && $perPage != 24 && $perPage != 48){
- $perPage = EBOOKS_PER_PAGE;
- }
-
- // 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 = [];
- }
-
- // Are we looking at a collection?
- if($collection !== null){
- $ebooks = Library::GetEbooksByCollection($collection);
- // Get the *actual* name of the collection, in case there are accent marks (like "Arsène Lupin")
- if(sizeof($ebooks) > 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;
}
-?>= Template::Header(['title' => $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);
+
+?>= Template::Header(['title' => $pageTitle, 'highlight' => 'ebooks', 'description' => $pageDescription]) ?>