From 18ac0d8a72c9bf73e29577e2b08f8445ff71780a Mon Sep 17 00:00:00 2001 From: Samuele Masetto Date: Fri, 26 Aug 2022 12:18:32 +0200 Subject: [PATCH] add token processor to Resubscribe adn Unsubscribe --- CRM/Mailing/Event/BAO/Resubscribe.php | 17 +++++++++++++++-- CRM/Mailing/Event/BAO/Subscribe.php | 2 +- CRM/Mailing/Event/BAO/Unsubscribe.php | 17 ++++++++++++++--- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/CRM/Mailing/Event/BAO/Resubscribe.php b/CRM/Mailing/Event/BAO/Resubscribe.php index dea877f6a0..4a4db39635 100644 --- a/CRM/Mailing/Event/BAO/Resubscribe.php +++ b/CRM/Mailing/Event/BAO/Resubscribe.php @@ -9,6 +9,8 @@ +--------------------------------------------------------------------+ */ +use Civi\Token\TokenProcessor; + /** * * @package CRM @@ -233,18 +235,29 @@ class CRM_Mailing_Event_BAO_Resubscribe { $bao->body_html = $html; $tokens = $bao->getTokens(); if ($eq->format == 'HTML' || $eq->format == 'Both') { - $html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html']); $html = CRM_Utils_Token::replaceResubscribeTokens($html, $domain, $groups, TRUE, $eq->contact_id, $eq->hash); $html = CRM_Utils_Token::replaceActionTokens($html, $addresses, $urls, TRUE, $tokens['html']); $html = CRM_Utils_Token::replaceMailingTokens($html, $dao, NULL, $tokens['html']); } if (!$html || $eq->format == 'Text' || $eq->format == 'Both') { - $text = CRM_Utils_Token::replaceDomainTokens($text, $domain, TRUE, $tokens['text']); $text = CRM_Utils_Token::replaceResubscribeTokens($text, $domain, $groups, FALSE, $eq->contact_id, $eq->hash); $text = CRM_Utils_Token::replaceActionTokens($text, $addresses, $urls, FALSE, $tokens['text']); $text = CRM_Utils_Token::replaceMailingTokens($text, $dao, NULL, $tokens['text']); } + $tokenProcessor = new TokenProcessor(\Civi::dispatcher(), [ + 'controller' => __CLASS__, + 'smarty' => FALSE, + 'schema' => ['contactId'], + ]); + + $tokenProcessor->addMessage('body_html', $html, 'text/html'); + $tokenProcessor->addMessage('body_text', $text, 'text/plain'); + $tokenProcessor->addRow(['contactId' => $eq->contact_id]); + $tokenProcessor->evaluate(); + $html = $tokenProcessor->getRow(0)->render('body_html'); + $text = $tokenProcessor->getRow(0)->render('body_text'); + $params = [ 'subject' => $component->subject, 'from' => "\"{$domainEmailName}\" <{$domainEmailAddress}>", diff --git a/CRM/Mailing/Event/BAO/Subscribe.php b/CRM/Mailing/Event/BAO/Subscribe.php index 0687dc2df7..3275d40e39 100644 --- a/CRM/Mailing/Event/BAO/Subscribe.php +++ b/CRM/Mailing/Event/BAO/Subscribe.php @@ -228,7 +228,7 @@ SELECT civicrm_email.id as email_id // render the & entities in text mode, so that the links work $text = str_replace('&', '&', $text); - $tokenProcessor = new TokenProcessor(Civi::dispatcher(), [ + $tokenProcessor = new TokenProcessor(\Civi::dispatcher(), [ 'controller' => __CLASS__, 'smarty' => FALSE, 'schema' => ['contactId'], diff --git a/CRM/Mailing/Event/BAO/Unsubscribe.php b/CRM/Mailing/Event/BAO/Unsubscribe.php index 7c393cfec7..17eaf7a3d2 100644 --- a/CRM/Mailing/Event/BAO/Unsubscribe.php +++ b/CRM/Mailing/Event/BAO/Unsubscribe.php @@ -9,6 +9,8 @@ +--------------------------------------------------------------------+ */ +use Civi\Token\TokenProcessor; + /** * * @package CRM @@ -400,19 +402,28 @@ WHERE email = %2 $bao->body_html = $html; $tokens = $bao->getTokens(); if ($eq->format == 'HTML' || $eq->format == 'Both') { - $html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html']); $html = CRM_Utils_Token::replaceUnsubscribeTokens($html, $domain, $groups, TRUE, $eq->contact_id, $eq->hash); $html = CRM_Utils_Token::replaceActionTokens($html, $addresses, $urls, TRUE, $tokens['html']); $html = CRM_Utils_Token::replaceMailingTokens($html, $dao, NULL, $tokens['html']); } if (!$html || $eq->format == 'Text' || $eq->format == 'Both') { - $text = CRM_Utils_Token::replaceDomainTokens($text, $domain, FALSE, $tokens['text']); $text = CRM_Utils_Token::replaceUnsubscribeTokens($text, $domain, $groups, FALSE, $eq->contact_id, $eq->hash); $text = CRM_Utils_Token::replaceActionTokens($text, $addresses, $urls, FALSE, $tokens['text']); $text = CRM_Utils_Token::replaceMailingTokens($text, $dao, NULL, $tokens['text']); } - $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain(); + $tokenProcessor = new TokenProcessor(\Civi::dispatcher(), [ + 'controller' => __CLASS__, + 'smarty' => FALSE, + 'schema' => ['contactId'], + ]); + + $tokenProcessor->addMessage('body_html', $html, 'text/html'); + $tokenProcessor->addMessage('body_text', $text, 'text/plain'); + $tokenProcessor->addRow(['contactId' => $eq->contact_id]); + $tokenProcessor->evaluate(); + $html = $tokenProcessor->getRow(0)->render('body_html'); + $text = $tokenProcessor->getRow(0)->render('body_text'); $params = [ 'subject' => $component->subject, -- 2.25.1