diff --git a/lib/Constants.php b/lib/Constants.php index 650f5653..18bac15f 100644 --- a/lib/Constants.php +++ b/lib/Constants.php @@ -102,3 +102,22 @@ const DONATION_DRIVE_DATES = [ const DONATION_DRIVE_COUNTER_ENABLED = false; const DONATION_DRIVE_COUNTER_START = new DateTimeImmutable('May 2, 2022 00:00:00 America/New_York'); const DONATION_DRIVE_COUNTER_END = new DateTimeImmutable('May 8, 2022 23:59:00 America/New_York'); + +const PD_DAY_YEAR = 2025; +const PD_DAY_DRAFT_PATH = '/standardebooks.org/drafts/' . PD_DAY_YEAR; +const PD_DAY_EBOOKS = [ + 'graham-greene/the-man-within' => ['author' => 'Graham Greene', 'title' => 'The Man Within'], + 'c-s-forester/brown-on-resolution' => ['author' => 'C. S. Forester', 'title' => 'Brown on Resolution'], + 'dashiell-hammett/red-harvest' => ['author' => 'Dashiell Hammett', 'title' => 'Red Harvest'], + 'dashiell-hammett/the-dain-curse' => ['author' => 'Dashiell Hammett', 'title' => 'The Dain Curse'], + 'erich-maria-remarque/all-quiet-on-the-western-front/a-w-wheen' => ['author' => 'Erich Maria Remarque', 'title' => 'All Quiet on the Western Front', 'translator' => 'A. W. Wheen'], + 'ernest-hemingway/a-farewell-to-arms' => ['author' => 'Ernest Heminway', 'title' => 'A Farewell to Arms'], + 'j-b-priestley/the-good-companions' => ['author' => 'J. B. Priestley', 'title' => 'The Good Companions'], + 'john-steinbeck/cup-of-gold' => ['author' => 'John Steinbeck', 'title' => 'Cup of Gold'], + 'oliver-la-farge/laughing-boy' => ['author' => 'Oliver La Farge', 'title' => 'Laughing Boy'], + 'william-faulkner/the-sound-and-the-fury' => ['author' => 'William Faulkner', 'title' => 'The Sound and the Fury'], + 'mahatma-gandhi/the-story-of-my-experiments-with-truth/mahadev-desai' => ['author' => 'Mahatma Gandhi', 'title' => 'The Story of My Experiments with Truth'], + 'arthur-conan-doyle/the-maracot-deep' => ['author' => 'Arthur Conan Doyle', 'title' => 'The Maracot Deep'], + 'sinclair-lewis/dodsworth' => ['author' => 'Sinclair Lewis', 'title' => 'Dodsworth'], + 'thomas-wolfe/look-homeard-angel' => ['author' => 'Thomas Wolfe', 'title' => 'Look Homeward, Angel'] + ]; diff --git a/lib/Ebook.php b/lib/Ebook.php index 1b427f19..9cb53d89 100644 --- a/lib/Ebook.php +++ b/lib/Ebook.php @@ -606,8 +606,13 @@ class Ebook{ $ebookFromFilesystem = new Ebook(); // First, construct a source repo path from our WWW filesystem path. - $ebookFromFilesystem->RepoFilesystemPath = str_replace(EBOOKS_DIST_PATH, '', $wwwFilesystemPath); - $ebookFromFilesystem->RepoFilesystemPath = SITE_ROOT . '/ebooks/' . str_replace('/', '_', $ebookFromFilesystem->RepoFilesystemPath) . '.git'; + if(str_starts_with($wwwFilesystemPath, '/')){ + $ebookFromFilesystem->RepoFilesystemPath = $wwwFilesystemPath; + } + else{ + $ebookFromFilesystem->RepoFilesystemPath = str_replace(EBOOKS_DIST_PATH, '', $wwwFilesystemPath); + $ebookFromFilesystem->RepoFilesystemPath = SITE_ROOT . '/ebooks/' . str_replace('/', '_', $ebookFromFilesystem->RepoFilesystemPath) . '.git'; + } if(!is_dir($ebookFromFilesystem->RepoFilesystemPath)){ // On dev systems we might not have the bare repos, so make an adjustment. try{ @@ -643,8 +648,7 @@ class Ebook{ $ebookFromFilesystem->Identifier = (string)$matches[1]; try{ - // PHP Safe throws an exception from filesize() if the file doesn't exist, but PHP still - // emits a warning. So, just silence the warning. + // PHP Safe throws an exception from filesize() if the file doesn't exist, but PHP still emits a warning. So, just silence the warning. $ebookFromFilesystem->TextSinglePageByteCount = @filesize($ebookFromFilesystem->WwwFilesystemPath . '/text/single-page.xhtml'); } catch(\Exception){ @@ -687,13 +691,18 @@ class Ebook{ } // Fill in the short history of this repo. - $historyEntries = explode("\n", shell_exec('cd ' . escapeshellarg($ebookFromFilesystem->RepoFilesystemPath) . ' && git log -n5 --pretty=format:"%ct %H %s"')); + try{ + $historyEntries = explode("\n", shell_exec('cd ' . escapeshellarg($ebookFromFilesystem->RepoFilesystemPath) . ' && git log -n5 --pretty=format:"%ct %H %s"')); - $gitCommits = []; - foreach($historyEntries as $logLine){ - $gitCommits[] = GitCommit::FromLogLine($logLine); + $gitCommits = []; + foreach($historyEntries as $logLine){ + $gitCommits[] = GitCommit::FromLogLine($logLine); + } + $ebookFromFilesystem->GitCommits = $gitCommits; + } + catch(\Safe\Exceptions\ExecException){ + // Pass. } - $ebookFromFilesystem->GitCommits = $gitCommits; // Now do some heavy XML lifting! try{ diff --git a/www/css/core.css b/www/css/core.css index 9d5af9e3..3c41591c 100644 --- a/www/css/core.css +++ b/www/css/core.css @@ -2936,6 +2936,11 @@ aside button.close:active{ transition: transform .5s; } +article.ebook.public-domain-day-placeholder #read-free p{ + text-align: center; + font-style: italic; +} + article.ebook section#read-online ul li p.has-size{ display: flex; } diff --git a/www/ebooks/ebook.php b/www/ebooks/ebook.php index 93190d90..5e0648eb 100644 --- a/www/ebooks/ebook.php +++ b/www/ebooks/ebook.php @@ -39,6 +39,7 @@ try{ } $identifier = EBOOKS_IDENTIFIER_PREFIX . $urlPath; + $ebook = Ebook::GetByIdentifier($identifier); // Divide our sources into transcriptions and scans. @@ -75,6 +76,12 @@ catch(Exceptions\SeeOtherEbookException $ex){ exit(); } catch(Exceptions\EbookNotFoundException){ + // Are we accessing a placeholder for a Public Domain Day book that is not yet released? + if(array_key_exists($urlPath, PD_DAY_EBOOKS)){ + require('/standardebooks.org/web/www/ebooks/public-domain-day-placeholder.php'); + exit(); + } + Template::Emit404(); } ?> strip_tags($ebook->TitleWithCreditsHtml) . ' - Free ebook download', 'ogType' => 'book', 'coverUrl' => $ebook->DistCoverUrl, 'highlight' => 'ebooks', 'description' => 'Free epub ebook download of the Standard Ebooks edition of ' . $ebook->Title . ': ' . $ebook->Description, 'canonicalUrl' => SITE_URL . $ebook->Url]) ?> diff --git a/www/ebooks/public-domain-day-placeholder.php b/www/ebooks/public-domain-day-placeholder.php new file mode 100644 index 00000000..d64b5d0c --- /dev/null +++ b/www/ebooks/public-domain-day-placeholder.php @@ -0,0 +1,114 @@ +Name = PD_DAY_EBOOKS[$urlPath]['author']; + $ebook->Authors = [$c]; + + if(isset(PD_DAY_EBOOKS[$urlPath]['translator'])){ + $c = new Contributor(); + $c->Name = PD_DAY_EBOOKS[$urlPath]['translator']; + $ebook->Translators = [$c]; + } + + $ebook->Title = PD_DAY_EBOOKS[$urlPath]['title']; + $ebook->WwwFilesystemPath = ''; + $ebook->Identifier = ''; + } + else{ + throw $ex; + } + } +} +catch(Exceptions\EbookNotFoundException){ + Template::Emit404(); +} +?> strip_tags($ebook->TitleWithCreditsHtml) . ' - Free ebook download', 'highlight' => 'ebooks', 'description' => 'Free epub ebook download of the Standard Ebooks edition of ' . $ebook->Title . ': ' . $ebook->Description, 'canonicalUrl' => SITE_URL . $ebook->Url]) ?> +
+
+
+
+

Title) ?>

+ Authors as $author){ ?> + + Name != 'Anonymous'){ ?> +

+ Name) ?> +

+ + +
+ + + + +
+ + Tags) > 0){ ?> + + + +
+

Description

+ + + + + + LongDescription !== null){ ?> + LongDescription ?> + +
+ +
+ GenerateContributorsRdfa() ?> +

Read free

+

This book will enter the public domain in the U.S. on January 1, .

+

We’ve been working hard, and have this ebook prepared and ready for you to download free on January 1. Bookmark this page and come back then to read this ebook for free!

+
+
+
+ diff --git a/www/images/public-domain-day-placeholder-cover-hero.jpg b/www/images/public-domain-day-placeholder-cover-hero.jpg new file mode 100644 index 00000000..61fd8fb2 Binary files /dev/null and b/www/images/public-domain-day-placeholder-cover-hero.jpg differ diff --git a/www/images/public-domain-day-placeholder-cover-hero@2x.jpg b/www/images/public-domain-day-placeholder-cover-hero@2x.jpg new file mode 100644 index 00000000..ea393683 Binary files /dev/null and b/www/images/public-domain-day-placeholder-cover-hero@2x.jpg differ