From 9c9dbcfd66a6f15af4c543aa3d6e7ffa2a01b8b4 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 29 Oct 2024 11:37:29 +0000 Subject: [PATCH 1/3] enable using announcements to add content to alerts If an announcement has a location of 'alerts' then include that at the top of all alerts. The HTML version either uses "Read more" or the `button_text` property for the link. Announcements are added at the top of the alerts. Part of #1825 --- scripts/alertmailer.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/scripts/alertmailer.php b/scripts/alertmailer.php index 03faba7b63..f252ab051e 100644 --- a/scripts/alertmailer.php +++ b/scripts/alertmailer.php @@ -13,6 +13,20 @@ function mlog($message) { ini_set('memory_limit', -1); include_once INCLUDESPATH . 'easyparliament/member.php'; +$announcement_manager = new \MySociety\TheyWorkForYou\Model\AnnouncementManagement(); +$banner = $announcement_manager->get_random_valid_item('alerts'); + +$text_banner = ''; +$html_banner = ''; +if ($banner) { + $text_banner = $banner->title . "\n\n" . $banner->content . "\n\n" . $banner->url . "\n\n"; + $link_text = "Read more"; + if (property_exists($banner, 'button_text')) { + $link_text = $banner->button_text; + } + $html_banner = '' . $banner->title . "

" . $banner->content . '

' . $link_text . '

'; +} + $global_start = getmicrotime(); $db = new ParlDB(); @@ -211,6 +225,12 @@ function mlog($message) { if ($email != $current['email']) { if ($email_text) { + + if ($banner) { + $email_text = $text_banner . $email_text; + $html_text = $html_banner . $html_text; + } + write_and_send_email($current, $email_text, $html_text, $template); } $current['email'] = $email; @@ -391,6 +411,10 @@ function mlog($message) { } } if ($email_text) { + if ($banner) { + $email_text = $text_banner . $email_text; + $html_text = $html_banner . $html_text; + } write_and_send_email($current, $email_text, $html_text, $template); } From 21459ceec27a588e1523aa57721d1019995b84d1 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 18 Dec 2024 10:24:43 +0000 Subject: [PATCH 2/3] fixup! enable using announcements to add content to alerts --- scripts/alertmailer.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/alertmailer.php b/scripts/alertmailer.php index f252ab051e..fa828aed57 100644 --- a/scripts/alertmailer.php +++ b/scripts/alertmailer.php @@ -19,12 +19,17 @@ function mlog($message) { $text_banner = ''; $html_banner = ''; if ($banner) { - $text_banner = $banner->title . "\n\n" . $banner->content . "\n\n" . $banner->url . "\n\n"; - $link_text = "Read more"; - if (property_exists($banner, 'button_text')) { - $link_text = $banner->button_text; + $text_banner = $banner->title . "\n\n" . $banner->content . "\n\n"; + $html_banner = '

' . $banner->title . "

" . $banner->content . '

'; + + if (property_exists($banner, 'url') && $banner->url) { + $link_text = "Read more"; + if (property_exists($banner, 'button_text')) { + $link_text = $banner->button_text; + } + $text_banner .= $banner->url . "\n\n"; + $html_banner .= '

' . $link_text . '

'; } - $html_banner = '' . $banner->title . "

" . $banner->content . '

' . $link_text . '

'; } $global_start = getmicrotime(); From a3f228cebc2baab03be239c65bb0c68cc2a335b6 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 18 Dec 2024 10:25:04 +0000 Subject: [PATCH 3/3] fixup! enable using announcements to add content to alerts --- scripts/alertmailer.php | 12 +++++++----- .../templates/emails/alert_mailout.html | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/scripts/alertmailer.php b/scripts/alertmailer.php index fa828aed57..ddb5df343b 100644 --- a/scripts/alertmailer.php +++ b/scripts/alertmailer.php @@ -233,10 +233,9 @@ function mlog($message) { if ($banner) { $email_text = $text_banner . $email_text; - $html_text = $html_banner . $html_text; } - write_and_send_email($current, $email_text, $html_text, $template); + write_and_send_email($current, $email_text, $html_text, $template, $html_banner); } $current['email'] = $email; $current['token'] = $alertitem['alert_id'] . '-' . $alertitem['registrationtoken']; @@ -418,9 +417,8 @@ function mlog($message) { if ($email_text) { if ($banner) { $email_text = $text_banner . $email_text; - $html_text = $html_banner . $html_text; } - write_and_send_email($current, $email_text, $html_text, $template); + write_and_send_email($current, $email_text, $html_text, $template, $html_banner); } mlog("\n"); @@ -489,7 +487,7 @@ function sort_by_stuff($a, $b) { return ($a['hpos'] > $b['hpos']) ? 1 : -1; } -function write_and_send_email($current, $text, $html, $template) { +function write_and_send_email($current, $text, $html, $template, $html_banner) { global $globalsuccess, $sentemails, $nomail, $start_time, $domain; $text .= '===================='; @@ -499,8 +497,12 @@ function write_and_send_email($current, $text, $html, $template) { $m = [ 'DATA' => $text, '_HTML_' => $html, + '_BANNER_' => '', 'MANAGE' => "https://$domain/D/" . $current['token'], ]; + if ($html_banner) { + $m['_BANNER_'] = $html_banner; + } if (!$nomail) { $success = send_template_email($d, $m, true, true, $current['lang']); # true = "Precedence: bulk", want bounces mlog("sent ... "); diff --git a/www/includes/easyparliament/templates/emails/alert_mailout.html b/www/includes/easyparliament/templates/emails/alert_mailout.html index 479ce32fa9..25080751ae 100644 --- a/www/includes/easyparliament/templates/emails/alert_mailout.html +++ b/www/includes/easyparliament/templates/emails/alert_mailout.html @@ -103,6 +103,7 @@ + {_BANNER_}

Email alerts