/** * Replace Contribution tokens in html. * * @param string $str * @param array $contribution * @param bool|string $html * @param string $knownTokens * @param bool|string $escapeSmarty * * @return mixed */ public static function replaceContributionTokens($str, &$contribution, $html = FALSE, $knownTokens = NULL, $escapeSmarty = FALSE) { $key = 'contribution'; if (!$knownTokens || !CRM_Utils_Array::value($key, $knownTokens)) { return $str; //early return } self::_buildContributionTokens(); // 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 $str = preg_replace_callback(self::tokenRegex($key), function ($matches) use(&$contribution, $html, $escapeSmarty) { return CRM_Utils_Token::getContributionTokenReplacement($matches[1], $contribution, $html, $escapeSmarty); }, $str); $str = preg_replace('/\\\\|\\{(\\s*)?\\}/', ' ', $str); return $str; }