From c35c47b79364d95a4536662b1517759079d3d83d Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Fri, 8 Nov 2024 16:41:15 -0600 Subject: [PATCH] Add DateTimeFormat enum --- lib/AtomFeed.php | 4 ++-- lib/Enums/DateTimeFormat.php | 12 ++++++++++++ lib/Session.php | 2 +- templates/AtomFeed.php | 2 +- templates/AtomFeedEntry.php | 4 ++-- templates/OpdsAcquisitionEntry.php | 6 +++--- templates/OpdsAcquisitionFeed.php | 2 +- templates/OpdsNavigationFeed.php | 4 ++-- templates/RssEntry.php | 2 +- templates/RssFeed.php | 2 +- www/ebooks/download.php | 2 +- www/feeds/atom/search.php | 2 +- www/feeds/opds/search.php | 2 +- www/feeds/rss/search.php | 2 +- www/polls/get.php | 6 +++--- www/polls/votes/get.php | 2 +- www/polls/votes/index.php | 4 ++-- www/settings/post.php | 4 ++-- 18 files changed, 38 insertions(+), 26 deletions(-) create mode 100644 lib/Enums/DateTimeFormat.php diff --git a/lib/AtomFeed.php b/lib/AtomFeed.php index 5a33dfd3..f3aa0887 100644 --- a/lib/AtomFeed.php +++ b/lib/AtomFeed.php @@ -54,11 +54,11 @@ class AtomFeed extends Feed{ foreach($this->Entries as $entry){ $obj = new StdClass(); if($entry instanceof Ebook){ - $obj->Updated = $entry->EbookUpdated->format('Y-m-d\TH:i:s\Z'); + $obj->Updated = $entry->EbookUpdated->format(Enums\DateTimeFormat::Iso->value); $obj->Id = SITE_URL . $entry->Url; } else{ - $obj->Updated = $entry->Updated !== null ? $entry->Updated->format('Y-m-d\TH:i:s\Z') : ''; + $obj->Updated = $entry->Updated !== null ? $entry->Updated->format(Enums\DateTimeFormat::Iso->value) : ''; $obj->Id = $entry->Id; } $currentEntries[] = $obj; diff --git a/lib/Enums/DateTimeFormat.php b/lib/Enums/DateTimeFormat.php new file mode 100644 index 00000000..5312e3e2 --- /dev/null +++ b/lib/Enums/DateTimeFormat.php @@ -0,0 +1,12 @@ + intval((new DateTimeImmutable('+1 week'))->format('U')), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => false, 'samesite' => 'Lax']); // Expires in two weeks + setcookie('sessionid', $sessionId, ['expires' => intval((new DateTimeImmutable('+1 week'))->format(Enums\DateTimeFormat::UnixTimestamp->value)), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => false, 'samesite' => 'Lax']); // Expires in two weeks } /** diff --git a/templates/AtomFeed.php b/templates/AtomFeed.php index 7cfed045..b34f9c6f 100644 --- a/templates/AtomFeed.php +++ b/templates/AtomFeed.php @@ -21,7 +21,7 @@ print("\n"); <?= Formatter::EscapeXml($title) ?> /images/logo.png - format('Y-m-d\TH:i:s\Z') ?> + format(Enums\DateTimeFormat::Iso->value) ?> Standard Ebooks diff --git a/templates/AtomFeedEntry.php b/templates/AtomFeedEntry.php index d7d31aad..a6f03073 100644 --- a/templates/AtomFeedEntry.php +++ b/templates/AtomFeedEntry.php @@ -15,8 +15,8 @@ use function Safe\filesize; AuthorsUrl) ?> - Created->format('Y-m-d\TH:i:s\Z') ?> - Updated->format('Y-m-d\TH:i:s\Z') ?> + Created->format(Enums\DateTimeFormat::Iso->value) ?> + Updated->format(Enums\DateTimeFormat::Iso->value) ?> Public domain in the United States. Users located outside of the United States must check their local laws before using this ebook. Original content released to the public domain via the Creative Commons CC0 1.0 Universal Public Domain Dedication. Description) ?> LongDescription) ?> diff --git a/templates/OpdsAcquisitionEntry.php b/templates/OpdsAcquisitionEntry.php index 5e36f508..28621844 100644 --- a/templates/OpdsAcquisitionEntry.php +++ b/templates/OpdsAcquisitionEntry.php @@ -24,9 +24,9 @@ use function Safe\filesize; - EbookCreated->format('Y-m-d\TH:i:s\Z') ?> - EbookCreated->format('Y-m-d\TH:i:s\Z') ?> - EbookUpdated->format('Y-m-d\TH:i:s\Z') ?> + EbookCreated->format(Enums\DateTimeFormat::Iso->value) ?> + EbookCreated->format(Enums\DateTimeFormat::Iso->value) ?> + EbookUpdated->format(Enums\DateTimeFormat::Iso->value) ?> Language) ?> Standard Ebooks Public domain in the United States. Users located outside of the United States must check their local laws before using this ebook. Original content released to the public domain via the Creative Commons CC0 1.0 Universal Public Domain Dedication. diff --git a/templates/OpdsAcquisitionFeed.php b/templates/OpdsAcquisitionFeed.php index 1bcb0bd2..3e9812f6 100644 --- a/templates/OpdsAcquisitionFeed.php +++ b/templates/OpdsAcquisitionFeed.php @@ -36,7 +36,7 @@ print("\n"); /images/logo.png - format('Y-m-d\TH:i:s\Z') ?> + format(Enums\DateTimeFormat::Iso->value) ?> diff --git a/templates/OpdsNavigationFeed.php b/templates/OpdsNavigationFeed.php index fc35a27a..2cc453be 100644 --- a/templates/OpdsNavigationFeed.php +++ b/templates/OpdsNavigationFeed.php @@ -30,7 +30,7 @@ print("\n"); /images/logo.png - format('Y-m-d\TH:i:s\Z') ?> + format(Enums\DateTimeFormat::Iso->value) ?> Standard Ebooks @@ -39,7 +39,7 @@ print("\n"); <?= Formatter::EscapeXml($entry->Title) ?> - Updated !== null){ ?>Updated->format('Y-m-d\TH:i:s\Z') ?> + Updated !== null){ ?>Updated->format(Enums\DateTimeFormat::Iso->value) ?> Id) ?> Description) ?> diff --git a/templates/RssEntry.php b/templates/RssEntry.php index 258ff54d..66ae7a85 100644 --- a/templates/RssEntry.php +++ b/templates/RssEntry.php @@ -10,7 +10,7 @@ use function Safe\preg_replace; <?= Formatter::EscapeXml($entry->Title) ?>, by <?= Formatter::EscapeXml(strip_tags($entry->AuthorsHtml)) ?> Url) ?> Description) ?> - EbookCreated->format('r') ?> + EbookCreated->format(Enums\DateTimeFormat::Rss->value) ?> Identifier)) ?> Tags as $tag){ ?> Name) ?> diff --git a/templates/RssFeed.php b/templates/RssFeed.php index f365e73c..74fff983 100644 --- a/templates/RssFeed.php +++ b/templates/RssFeed.php @@ -18,7 +18,7 @@ print("\n"); en-US https://creativecommons.org/publicdomain/zero/1.0/ - format('r'); ?> + format(Enums\DateTimeFormat::Rss->value); ?> http://blogs.law.harvard.edu/tech/rss