/** * * getTokenData receives a token from an email * and returns the appropriate data for the token */ private function getTokenData(&$token_a, $html = FALSE, &$contact, &$verp, &$urls, $event_queue_id) { $type = $token_a['type']; $token = $token_a['token']; $data = $token; $useSmarty = defined('CIVICRM_MAIL_SMARTY') && CIVICRM_MAIL_SMARTY ? TRUE : FALSE; if ($type == 'embedded_url') { $embed_data = array(); foreach ($token as $t) { $embed_data[] = $this->getTokenData($t, $html = FALSE, $contact, $verp, $urls, $event_queue_id); } $numSlices = count($embed_data); $url = ''; for ($i = 0; $i < $numSlices; $i++) { $url .= "{$token_a['embed_parts'][$i]}{$embed_data[$i]}"; } if (isset($token_a['embed_parts'][$numSlices])) { $url .= $token_a['embed_parts'][$numSlices]; } // add trailing quote since we've gobbled it up in a previous regex // function getPatterns, line 431 if (preg_match('/^href[ ]*=[ ]*\'/', $url)) { $url .= "'"; } elseif (preg_match('/^href[ ]*=[ ]*\\"/', $url)) { $url .= '"'; } $data = $url; } elseif ($type == 'url') { if ($this->url_tracking) { $data = CRM_Mailing_BAO_TrackableURL::getTrackerURL($token, $this->id, $event_queue_id); if (!empty($html)) { $data = htmlentities($data, ENT_NOQUOTES); } } else { $data = $token; } } elseif ($type == 'contact') { $data = CRM_Utils_Token::getContactTokenReplacement($token, $contact, FALSE, FALSE, $useSmarty); } elseif ($type == 'action') { $data = CRM_Utils_Token::getActionTokenReplacement($token, $verp, $urls, $html); } elseif ($type == 'domain') { $domain = CRM_Core_BAO_Domain::getDomain(); $data = CRM_Utils_Token::getDomainTokenReplacement($token, $domain, $html); } elseif ($type == 'mailing') { if ($token == 'name') { $data = $this->name; } elseif ($token == 'group') { $groups = $this->getGroupNames(); $data = implode(', ', $groups); } } else { $data = CRM_Utils_Array::value("{$type}.{$token}", $contact); } return $data; }
/** * Replace all action tokens in $str * * @param string $str * The string with tokens to be replaced. * @param array $addresses * Assoc. array of VERP event addresses. * @param array $urls * Assoc. array of action URLs. * @param bool $html * Replace tokens with HTML or plain text. * @param array $knownTokens * A list of tokens that are known to exist in the email body. * * @param bool $escapeSmarty * * @return string * The processed string */ public static function &replaceActionTokens($str, &$addresses, &$urls, $html = FALSE, $knownTokens = NULL, $escapeSmarty = FALSE) { $key = 'action'; // here we intersect with the list of pre-configured valid tokens // so that we remove anything we do not recognize // I hope to move this step out of here soon and // then we will just iterate on a list of tokens that are passed to us if (!$knownTokens || empty($knownTokens[$key])) { return $str; } $str = preg_replace_callback(self::tokenRegex($key), function ($matches) use(&$addresses, &$urls, $html, $escapeSmarty) { return CRM_Utils_Token::getActionTokenReplacement($matches[1], $addresses, $urls, $html, $escapeSmarty); }, $str); return $str; }
/** * * getTokenData receives a token from an email * and returns the appropriate data for the token * */ private function getTokenData(&$token_a, $html = false, &$contact, &$verp, &$urls, $event_queue_id) { $type = $token_a['type']; $token = $token_a['token']; $data = $token; $escapeSmarty = defined('CIVICRM_MAIL_SMARTY') ? true : false; if ($type == 'embedded_url') { $embed_data = array(); foreach ($token as $t) { $embed_data[] = $this->getTokenData($t, $html = false, $contact, $verp, $urls, $event_queue_id); } $numSlices = count($embed_data); $url = ''; for ($i = 0; $i < $numSlices; $i++) { $url .= "{$token_a['embed_parts'][$i]}{$embed_data[$i]}"; } if (isset($token_a['embed_parts'][$numSlices])) { $url .= $token_a['embed_parts'][$numSlices]; } // add trailing quote since we've gobbled it up in a previous regex // function getPatterns, line 431 if (preg_match('/^href[ ]*=[ ]*\'/', $url)) { $url .= "'"; } else { if (preg_match('/^href[ ]*=[ ]*\\"/', $url)) { $url .= '"'; } } $data = $url; } else { if ($type == 'url') { if ($this->url_tracking) { $data = CRM_Mailing_BAO_TrackableURL::getTrackerURL($token, $this->id, $event_queue_id); } else { $data = $token; } } else { if ($type == 'contact') { $data = CRM_Utils_Token::getContactTokenReplacement($token, $contact, false, false, $escapeSmarty); } else { if ($type == 'action') { $data = CRM_Utils_Token::getActionTokenReplacement($token, $verp, $urls, $html); } else { if ($type == 'domain') { require_once 'CRM/Core/BAO/Domain.php'; $domain =& CRM_Core_BAO_Domain::getDomain(); $data = CRM_Utils_Token::getDomainTokenReplacement($token, $domain, $html); } else { if ($type == 'mailing') { require_once 'CRM/Mailing/BAO/Mailing.php'; $mailing = new CRM_Mailing_BAO_Mailing(); $mailing->find(true); if ($token == 'name') { $data = $mailing->name; } else { if ($token == 'group') { $groups = $mailing->getGroupNames(); $data = implode(', ', $groups); } } } else { $data = CRM_Utils_Array::value("{$type}.{$token}", $contact); } } } } } } return $data; }