/** * Replace all the hook tokens in $str with information from * $contact. * * @param string $str * The string with tokens to be replaced. * @param array $contact * Associative array of contact properties (including hook token values). * @param $categories * @param bool $html * Replace tokens with HTML or plain text. * * @param bool $escapeSmarty * * @return string * The processed string */ public static function &replaceHookTokens($str, &$contact, &$categories, $html = FALSE, $escapeSmarty = FALSE) { foreach ($categories as $key) { $str = preg_replace_callback(self::tokenRegex($key), function ($matches) use(&$contact, $key, $html, $escapeSmarty) { return CRM_Utils_Token::getHookTokenReplacement($matches[1], $contact, $key, $html, $escapeSmarty); }, $str); } return $str; }