return $mailContent;
}
- /**
- * Get an array of the tokens ito be resolved in the template.
- *
- * @param array $html
- *
- * @return array
- */
- protected static function getTokensToResolve(array $html): array {
- $mailing = new CRM_Mailing_BAO_Mailing();
- $mailing->subject = $html['subject'];
- $mailing->body_text = $html['text'];
- $mailing->body_html = $html['html'];
- return $mailing->getTokens();
- }
-
- /**
- * @param array $mailContent
- * @param array $tokens
- * @param bool $escapeSmarty
- *
- * @return array
- * @throws \CRM_Core_Exception
- */
- protected static function resolveDomainTokens(array $mailContent, array $tokens, bool $escapeSmarty): array {
- $domain = CRM_Core_BAO_Domain::getDomain();
- $mailContent['subject'] = CRM_Utils_Token::replaceDomainTokens($mailContent['subject'], $domain, FALSE, $tokens['subject'], $escapeSmarty);
- $mailContent['text'] = CRM_Utils_Token::replaceDomainTokens($mailContent['text'], $domain, FALSE, $tokens['text'], $escapeSmarty);
- $mailContent['html'] = CRM_Utils_Token::replaceDomainTokens($mailContent['html'], $domain, TRUE, $tokens['html'], $escapeSmarty);
- return $mailContent;
- }
-
- /**
- * @param $contactID
- * @param array|null $tokens
- * @param array $mailContent
- * @param bool $escapeSmarty
- *
- * @return array
- */
- protected static function resolveContactTokens($contactID, ?array $tokens, array $mailContent, bool $escapeSmarty): array {
- $contactParams = ['contact_id' => $contactID];
- $returnProperties = [];
-
- if (isset($tokens['subject']['contact'])) {
- foreach ($tokens['subject']['contact'] as $name) {
- $returnProperties[$name] = 1;
- }
- }
-
- if (isset($tokens['text']['contact'])) {
- foreach ($tokens['text']['contact'] as $name) {
- $returnProperties[$name] = 1;
- }
- }
-
- if (isset($tokens['html']['contact'])) {
- foreach ($tokens['html']['contact'] as $name) {
- $returnProperties[$name] = 1;
- }
- }
-
- // @todo CRM-17253 don't resolve contact details if there are no tokens
- // effectively comment out this next (performance-expensive) line
- // but unfortunately testing is a bit think on the ground to that needs to
- // be added.
- [$contact] = CRM_Utils_Token::getTokenDetails($contactParams,
- $returnProperties,
- FALSE, FALSE, NULL,
- CRM_Utils_Token::flattenTokens($tokens),
- // we should consider adding valueName here
- 'CRM_Core_BAO_MessageTemplate'
- );
- $contact = $contact[$contactID];
- $mailContent['subject'] = CRM_Utils_Token::replaceContactTokens($mailContent['subject'], $contact, FALSE, $tokens['subject'], FALSE, $escapeSmarty);
- $mailContent['text'] = CRM_Utils_Token::replaceContactTokens($mailContent['text'], $contact, FALSE, $tokens['text'], FALSE, $escapeSmarty);
- $mailContent['html'] = CRM_Utils_Token::replaceContactTokens($mailContent['html'], $contact, FALSE, $tokens['html'], FALSE, $escapeSmarty);
-
- $contactArray = [$contactID => $contact];
- CRM_Utils_Hook::tokenValues($contactArray,
- [$contactID],
- NULL,
- CRM_Utils_Token::flattenTokens($tokens),
- // we should consider adding valueName here
- 'CRM_Core_BAO_MessageTemplate'
- );
- $contact = $contactArray[$contactID];
-
- $hookTokens = [];
- CRM_Utils_Hook::tokens($hookTokens);
- $categories = array_keys($hookTokens);
- $mailContent['subject'] = CRM_Utils_Token::replaceHookTokens($mailContent['subject'], $contact, $categories, TRUE);
- $mailContent['text'] = CRM_Utils_Token::replaceHookTokens($mailContent['text'], $contact, $categories, TRUE);
- $mailContent['html'] = CRM_Utils_Token::replaceHookTokens($mailContent['html'], $contact, $categories, TRUE);
- return $mailContent;
- }
-
- /**
- * @param array $mailContent
- * @param $tplParams
- *
- * @return array
- */
- protected static function parseThroughSmarty(array $mailContent, $tplParams): array {
- // strip whitespace from ends and turn into a single line
- $mailContent['subject'] = "{strip}{$mailContent['subject']}{/strip}";
-
- // parse the three elements with Smarty
- $smarty = CRM_Core_Smarty::singleton();
- foreach ($tplParams as $name => $value) {
- $smarty->assign($name, $value);
- }
- foreach (['subject', 'text', 'html'] as $elem) {
- $mailContent[$elem] = $smarty->fetch("string:{$mailContent[$elem]}");
- }
- return $mailContent;
- }
-
/**
* Render the message template, resolving tokens and smarty tokens.
*