From 9a72b27233b271c2e800ae48e3f4690fe3c009a6 Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Sun, 10 Jul 2022 21:15:10 -0500 Subject: [PATCH] Rearrange bulk download index pages --- .gitignore | 2 +- config/apache/standardebooks.org.conf | 1 + config/apache/standardebooks.test.conf | 1 + lib/Library.php | 17 +++--- www/bulk-downloads/authors/index.php | 33 ---------- www/bulk-downloads/collection.php | 77 ++++++++++++++++++++++++ www/bulk-downloads/collections/index.php | 33 ---------- www/bulk-downloads/index.php | 21 ------- www/bulk-downloads/months/index.php | 65 -------------------- www/bulk-downloads/subjects/index.php | 33 ---------- 10 files changed, 89 insertions(+), 194 deletions(-) delete mode 100644 www/bulk-downloads/authors/index.php create mode 100644 www/bulk-downloads/collection.php delete mode 100644 www/bulk-downloads/collections/index.php delete mode 100644 www/bulk-downloads/months/index.php delete mode 100644 www/bulk-downloads/subjects/index.php diff --git a/.gitignore b/.gitignore index 2adb13f9..a3ecc298 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,4 @@ composer.lock www/manual/* !www/manual/index.php config/php/fpm/standardebooks.org-secrets.ini -www/bulk-downloads/**/*.zip +www/bulk-downloads/*/ diff --git a/config/apache/standardebooks.org.conf b/config/apache/standardebooks.org.conf index bdb3b132..0571cfb4 100644 --- a/config/apache/standardebooks.org.conf +++ b/config/apache/standardebooks.org.conf @@ -281,6 +281,7 @@ Define webroot /standardebooks.org/web # Rewrite rules for bulk downloads RewriteRule ^/bulk-downloads/(.+\.zip)$ /bulk-downloads/download.php?path=$1 + RewriteRule ^/bulk-downloads/([^/\.]+)$ /bulk-downloads/collection.php?name=$1 # Enable mod_authn_dbd DBDriver mysql diff --git a/config/apache/standardebooks.test.conf b/config/apache/standardebooks.test.conf index 0cf5e487..d1ccf9a6 100644 --- a/config/apache/standardebooks.test.conf +++ b/config/apache/standardebooks.test.conf @@ -263,6 +263,7 @@ Define webroot /standardebooks.org/web # Rewrite rules for bulk downloads RewriteRule ^/bulk-downloads/(.+\.zip)$ /bulk-downloads/download.php?path=$1 + RewriteRule ^/bulk-downloads/([^/\.]+)$ /bulk-downloads/collection.php?name=$1 # Enable mod_authn_dbd DBDriver mysql diff --git a/lib/Library.php b/lib/Library.php index 817ef5b9..737cc2cc 100644 --- a/lib/Library.php +++ b/lib/Library.php @@ -322,7 +322,8 @@ class Library{ * @return array>> */ public static function RebuildBulkDownloadsCache(): array{ - $years = []; + $collator = collator_create( 'en_US' ); // Used for sorting letters with diacritics like in author names + $months = []; $subjects = []; $collections = []; $authors = []; @@ -340,14 +341,14 @@ class Library{ $year = $date->format('Y'); $month = $date->format('F'); - if(!isset($years[$year])){ - $years[$year] = []; + if(!isset($months[$year])){ + $months[$year] = []; } - $years[$year][$month] = $obj; + $months[$year][$month] = $obj; } - apcu_store('bulk-downloads-years', $years, 43200); // 12 hours + apcu_store('bulk-downloads-months', $months, 43200); // 12 hours // Generate bulk downloads by subject foreach(glob(WEB_ROOT . '/bulk-downloads/subjects/*/', GLOB_NOSORT) as $dir){ @@ -361,7 +362,7 @@ class Library{ foreach(glob(WEB_ROOT . '/bulk-downloads/collections/*/', GLOB_NOSORT) as $dir){ $collections[] = self::FillBulkDownloadObject($dir, 'collections', '/collections'); } - usort($collections, function($a, $b){ return $a->LabelSort <=> $b->LabelSort; }); + usort($authors, function($a, $b) use($collator){ return $collator->compare($a->LabelSort, $b->LabelSort); }); apcu_store('bulk-downloads-collections', $collections, 43200); // 12 hours @@ -369,11 +370,11 @@ class Library{ foreach(glob(WEB_ROOT . '/bulk-downloads/authors/*/', GLOB_NOSORT) as $dir){ $authors[] = self::FillBulkDownloadObject($dir, 'authors', '/ebooks'); } - usort($authors, function($a, $b){ return $a->LabelSort <=> $b->LabelSort; }); + usort($authors, function($a, $b) use($collator){ return $collator->compare($a->LabelSort, $b->LabelSort); }); apcu_store('bulk-downloads-authors', $authors, 43200); // 12 hours - return ['years' => $years, 'subjects' => $subjects, 'collections' => $collections, 'authors' => $authors]; + return ['months' => $months, 'subjects' => $subjects, 'collections' => $collections, 'authors' => $authors]; } public static function RebuildCache(): void{ diff --git a/www/bulk-downloads/authors/index.php b/www/bulk-downloads/authors/index.php deleted file mode 100644 index 6eb6ec5b..00000000 --- a/www/bulk-downloads/authors/index.php +++ /dev/null @@ -1,33 +0,0 @@ -Benefits->CanBulkDownload){ - $canDownload = true; -} - -$authors = []; - -try{ - $authors = apcu_fetch('bulk-downloads-authors'); -} -catch(Safe\Exceptions\ApcuException $ex){ - $result = Library::RebuildBulkDownloadsCache(); - $authors = $result['authors']; -} - -?> 'Downloads by Author', 'highlight' => '', 'description' => 'Download zip files containing all of the Standard Ebooks by a given author.']) ?> -
-
-

Downloads by Author

- -

Patrons circle members can download zip files containing all of the ebooks that were released in a given month of Standard Ebooks history. You can join the Patrons Circle with a small donation in support of our continuing mission to create free, beautiful digital literature.

- -

These zip files contain each ebook in every format we offer, and are updated once daily with the latest versions of each ebook. Read about which file format to download.

- 'Author', 'collections' => $authors]); ?> -
-
- diff --git a/www/bulk-downloads/collection.php b/www/bulk-downloads/collection.php new file mode 100644 index 00000000..2e88b714 --- /dev/null +++ b/www/bulk-downloads/collection.php @@ -0,0 +1,77 @@ +Benefits->CanBulkDownload){ + $canDownload = true; +} + +$collection = []; + +try{ + $collection = apcu_fetch('bulk-downloads-' . $name); +} +catch(Safe\Exceptions\ApcuException $ex){ + $result = Library::RebuildBulkDownloadsCache(); + $collection = $result[$name]; +} + +$title = preg_replace('/s$/', '', ucfirst($name)); + +?> 'Downloads by ' . $title, 'highlight' => '', 'description' => 'Download zip files containing all of the Standard Ebooks in a given collection.']) ?> +
+
+

Downloads by

+ +

Patrons circle members get convenient access to zip files containing collections of different categories of ebooks. You can join the Patrons Circle with a small donation in support of our continuing mission to create free, beautiful digital literature, and download these collections files too.

+ +

These zip files contain each ebook in every format we offer, and are updated once daily with the latest versions of each ebook. Read about which file format to download.

+ + + + $months){ + $yearHeader = Formatter::ToPlainText($year); + ?> + + + + + + + + + + + $collection){ + $monthHeader = Formatter::ToPlainText($month); + ?> + + + + + + ZipFiles as $item){ ?> + + + + + + + + +
MonthEbooksUpdatedEbook format
EbookCount)) ?>UpdatedString) ?>Type ?>(Size) ?>)
+ + $title, 'collections' => $collection]); ?> + +
+
+ diff --git a/www/bulk-downloads/collections/index.php b/www/bulk-downloads/collections/index.php deleted file mode 100644 index 6abcb417..00000000 --- a/www/bulk-downloads/collections/index.php +++ /dev/null @@ -1,33 +0,0 @@ -Benefits->CanBulkDownload){ - $canDownload = true; -} - -$collections = []; - -try{ - $collections = apcu_fetch('bulk-downloads-collections'); -} -catch(Safe\Exceptions\ApcuException $ex){ - $result = Library::RebuildBulkDownloadsCache(); - $collections = $result['collections']; -} - -?> 'Downloads by Collection', 'highlight' => '', 'description' => 'Download zip files containing all of the Standard Ebooks in a given collection.']) ?> -
-
-

Downloads by Collection

- -

Patrons circle members can download zip files containing all of the ebooks that were released in a given month of Standard Ebooks history. You can join the Patrons Circle with a small donation in support of our continuing mission to create free, beautiful digital literature.

- -

These zip files contain each ebook in every format we offer, and are updated once daily with the latest versions of each ebook. Read about which file format to download.

- 'Collection', 'collections' => $collections]); ?> -
-
- diff --git a/www/bulk-downloads/index.php b/www/bulk-downloads/index.php index 1cc0b991..cb969fdd 100644 --- a/www/bulk-downloads/index.php +++ b/www/bulk-downloads/index.php @@ -1,32 +1,11 @@ Benefits->CanBulkDownload){ $canDownload = true; } -$years = []; -$subjects = []; -$collections = []; -$authors = []; - -try{ - $years = apcu_fetch('bulk-downloads-years'); - $subjects = apcu_fetch('bulk-downloads-subjects'); - $collections = apcu_fetch('bulk-downloads-collections'); - $authors = apcu_fetch('bulk-downloads-authors'); -} -catch(Safe\Exceptions\ApcuException $ex){ - $result = Library::RebuildBulkDownloadsCache(); - $years = $result['years']; - $subjects = $result['subjects']; - $collections = $result['collections']; - $authors = $result['authors']; -} - ?> 'Bulk Ebook Downloads', 'highlight' => '', 'description' => 'Download zip files containing all of the Standard Ebooks released in a given month.']) ?>
diff --git a/www/bulk-downloads/months/index.php b/www/bulk-downloads/months/index.php deleted file mode 100644 index 885d8be2..00000000 --- a/www/bulk-downloads/months/index.php +++ /dev/null @@ -1,65 +0,0 @@ -Benefits->CanBulkDownload){ - $canDownload = true; -} - -$years = []; - -try{ - $years = apcu_fetch('bulk-downloads-years'); -} -catch(Safe\Exceptions\ApcuException $ex){ - $result = Library::RebuildBulkDownloadsCache(); - $years = $result['years']; -} - -?> 'Downloads by Month', 'highlight' => '', 'description' => 'Download zip files containing all of the Standard Ebooks released in a given month.']) ?> -
-
-

Downloads by Month

- -

Patrons circle members can download zip files containing all of the ebooks that were released in a given month of Standard Ebooks history. You can join the Patrons Circle with a small donation in support of our continuing mission to create free, beautiful digital literature.

- -

These zip files contain each ebook in every format we offer, and are updated once daily with the latest versions of each ebook. Read about which file format to download.

- - - $months){ - $yearHeader = Formatter::ToPlainText($year); - ?> - - - - - - - - - - - $collection){ - $monthHeader = Formatter::ToPlainText($month); - ?> - - - - - - ZipFiles as $item){ ?> - - - - - - - - -
MonthEbooksUpdatedEbook format
EbookCount)) ?>UpdatedString) ?>Type ?>(Size) ?>)
-
-
- diff --git a/www/bulk-downloads/subjects/index.php b/www/bulk-downloads/subjects/index.php deleted file mode 100644 index 8824f20c..00000000 --- a/www/bulk-downloads/subjects/index.php +++ /dev/null @@ -1,33 +0,0 @@ -Benefits->CanBulkDownload){ - $canDownload = true; -} - -$subjects = []; - -try{ - $subjects = apcu_fetch('bulk-downloads-subjects'); -} -catch(Safe\Exceptions\ApcuException $ex){ - $result = Library::RebuildBulkDownloadsCache(); - $subjects = $result['subjects']; -} - -?> 'Downloads by Subject', 'highlight' => '', 'description' => 'Download zip files containing all of the Standard Ebooks by a given subject.']) ?> -
-
-

Downloads by Subject

- -

Patrons circle members can download zip files containing all of the ebooks that were released in a given month of Standard Ebooks history. You can join the Patrons Circle with a small donation in support of our continuing mission to create free, beautiful digital literature.

- -

These zip files contain each ebook in every format we offer, and are updated once daily with the latest versions of each ebook. Read about which file format to download.

- 'Subject', 'collections' => $subjects]); ?> -
-
-