diff --git a/scripts/alertmailer.php b/scripts/alertmailer.php index 03faba7b63..ddb5df343b 100644 --- a/scripts/alertmailer.php +++ b/scripts/alertmailer.php @@ -13,6 +13,25 @@ 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"; + $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 .= ''; + } +} + $global_start = getmicrotime(); $db = new ParlDB(); @@ -211,7 +230,12 @@ function mlog($message) { if ($email != $current['email']) { if ($email_text) { - write_and_send_email($current, $email_text, $html_text, $template); + + if ($banner) { + $email_text = $text_banner . $email_text; + } + + write_and_send_email($current, $email_text, $html_text, $template, $html_banner); } $current['email'] = $email; $current['token'] = $alertitem['alert_id'] . '-' . $alertitem['registrationtoken']; @@ -391,7 +415,10 @@ function mlog($message) { } } if ($email_text) { - write_and_send_email($current, $email_text, $html_text, $template); + if ($banner) { + $email_text = $text_banner . $email_text; + } + write_and_send_email($current, $email_text, $html_text, $template, $html_banner); } mlog("\n"); @@ -460,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 .= '===================='; @@ -470,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_}