From af2be617cd7bffbb43f3f630b2e5f39b4d1a104a Mon Sep 17 00:00:00 2001 From: eclipse Date: Thu, 27 Feb 2025 23:09:20 +0100 Subject: [PATCH] lots of work around newsletter (un)subscription (via double opt-in) --- content/php/confirm.php | 25 +++++++++++++++ content/php/contact.php | 18 +++++++++++ content/php/settings.php | 24 +++++++++++++++ content/php/subscribe.php | 37 +++++++++++++++++++++++ content/php/unsubscribe.php | 18 +++++++++++ pelicanconf.py | 8 ++++- theme/static/css/custom.css | 25 ++++++++++++--- theme/templates/contact.html | 2 +- theme/templates/includes/subscribe.html | 8 +++++ theme/templates/includes/unsubscribe.html | 8 +++++ 10 files changed, 167 insertions(+), 6 deletions(-) create mode 100644 content/php/confirm.php create mode 100644 content/php/contact.php create mode 100644 content/php/settings.php create mode 100644 content/php/subscribe.php create mode 100644 content/php/unsubscribe.php create mode 100644 theme/templates/includes/subscribe.html create mode 100644 theme/templates/includes/unsubscribe.html diff --git a/content/php/confirm.php b/content/php/confirm.php new file mode 100644 index 0000000..fb0dc5e --- /dev/null +++ b/content/php/confirm.php @@ -0,0 +1,25 @@ +post("lists/$mailingList/members", array( + 'address' => $recipientAddress, + 'name' => $recipientName, + 'description' => 'Form Opt In', + 'subscribed' => true + )); */ +} + + +require("settings.php"); + +$c = isset($_GET['c']) ? SanitizeInputs($_GET['c']) : NULL; +$e = isset($_GET['e']) ? SanitizeInputs($_GET['e']) : NULL; + +if (isset($c) && isset($e) && CheckConfirmationHash($e, $c) && AddMemberToDB($e)) { + header('Location: /newsletter/confirmed.html'); +} else { + header('Location: /newsletter/confirm-error.html') +} +?> \ No newline at end of file diff --git a/content/php/contact.php b/content/php/contact.php new file mode 100644 index 0000000..1f54f83 --- /dev/null +++ b/content/php/contact.php @@ -0,0 +1,18 @@ + diff --git a/content/php/settings.php b/content/php/settings.php new file mode 100644 index 0000000..61eca0c --- /dev/null +++ b/content/php/settings.php @@ -0,0 +1,24 @@ + \ No newline at end of file diff --git a/content/php/subscribe.php b/content/php/subscribe.php new file mode 100644 index 0000000..b9a853e --- /dev/null +++ b/content/php/subscribe.php @@ -0,0 +1,37 @@ +Hallo! Bitte bestätige die Anmeldung für meinen Newsletter, indem du auf diesen Link klickst. Viel Spaß mit dem Gedicht!

Bis bald und viele Grüße
Tobias'; + $headers = 'From: newsletter@' . $domain; + $result = mail($to, $subject, $body, $headers); + return $result; +} + + +require("settings.php"); + +if (isset($_POST['email'])) { + $email = SanitizeEmail(trim($_POST['email'])); + echo $email; //DEBUG + $result = SendConfirmationEmail($email); + if $result == TRUE ) { + header('Location: /newsletter/subscribed.html'); + } else { + header('Location: /newsletter/subscribe-error.html') + } +} +?> \ No newline at end of file diff --git a/content/php/unsubscribe.php b/content/php/unsubscribe.php new file mode 100644 index 0000000..5f3c4fa --- /dev/null +++ b/content/php/unsubscribe.php @@ -0,0 +1,18 @@ + \ No newline at end of file diff --git a/pelicanconf.py b/pelicanconf.py index 6220be1..b6b998f 100644 --- a/pelicanconf.py +++ b/pelicanconf.py @@ -20,15 +20,21 @@ THEME = "theme/" PATH = "content" ARTICLE_PATHS = ["posts"] PAGE_PATHS = ["pages"] -STATIC_PATHS = ["images", "favicon"] +STATIC_PATHS = ["images", "favicon", "php"] DIRECT_TEMPLATES = ['index', 'tags'] IGNORE_FILES = ['**/.*', '__pycache__', 'favicon-from-svg.sh', '*.metadata'] EXTRA_PATH_METADATA = { 'favicon/favicon.ico': {'path': 'favicon.ico'}, + 'php/settings.php': {'path': 'settings.php'}, + 'php/subscribe.php': {'path': 'subscribe.php'}, + 'php/confirm.php': {'path': 'confirm.php'}, + 'php/unsubscribes.php': {'path': 'unsubscribe.php'}, + 'php/contact.php': {'path': 'contact.php'} } + PAGE_URL = '{slug}/' PAGE_SAVE_AS = '{slug}/index.html' ARTICLE_SAVE_AS = '{category}/{slug}.html' diff --git a/theme/static/css/custom.css b/theme/static/css/custom.css index 9415b26..367681a 100644 --- a/theme/static/css/custom.css +++ b/theme/static/css/custom.css @@ -27,6 +27,7 @@ Oxygen, Ubuntu, Cantarell, Helvetica, Arial, "Helvetica Neue", sans-serif, var(--pico-font-family-emoji); --card-height: 300px; + --smallest-width: 350px; } /* don't underline links by default */ @@ -238,6 +239,22 @@ a { margin-right: 0; } +/* style newsletter subscription form */ +.newsletter-form { + display: flex; + flex-flow: row wrap; +} + +.newsletter-email { + flex: 1 0 var(--smallest-width); + min-width: var(--smallest-width); +} + +.newsletter-submit { + flex: 0 1 content; +} + + /* Main content */ #main-header h1, #site-footer p { @@ -265,8 +282,8 @@ a { } p { - flex: 0 1 350px; - font-size: 2em; + flex: 0 1 var(--smallest-width); + font-size: 1.5em; } } @@ -348,7 +365,7 @@ a { .klappentext { flex: 0 0 calc(50% - var(--pico-block-spacing-horizontal)); - min-width: 350px; + min-width: var(--smallest-width); } .featured-image { @@ -358,7 +375,7 @@ a { img { max-height: calc(var(--card-height) * 2); - min-width: 350px; + min-width: var(--smallest-width); max-width: 100%; aspect-ratio: auto; padding: var(--pico-spacing); diff --git a/theme/templates/contact.html b/theme/templates/contact.html index 55a057b..dcafa12 100644 --- a/theme/templates/contact.html +++ b/theme/templates/contact.html @@ -1,6 +1,6 @@ {% extends "page.html" %} {% block content_body %} -

+