Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-12172 #797

Merged
merged 1 commit into from
May 19, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 34 additions & 16 deletions CRM/Utils/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public static function &token_replace($type, $var, $value, &$str, $escapeSmarty
* @static
*/
private static function tokenRegex($token_type) {
return '/(?<!\{|\\\\)\{' . $token_type . '\.([\w]+(\-[\w\s]+)?)\}(?!\})/e';
return '/(?<!\{|\\\\)\{' . $token_type . '\.([\w]+(\-[\w\s]+)?)\}(?!\})/';
}

/**
Expand Down Expand Up @@ -236,9 +236,11 @@ public static function &replaceDomainTokens(
return $str;
}

$str = preg_replace(
$str = preg_replace_callback(
self::tokenRegex($key),
'self::getDomainTokenReplacement(\'\\1\',$domain,$html)',
function ($matches) use(&$domain, $html, $escapeSmarty) {
return CRM_Utils_Token::getDomainTokenReplacement($matches[1], $domain, $html, $escapeSmarty);
},
$str
);
return $str;
Expand Down Expand Up @@ -399,9 +401,12 @@ public static function &replaceMailingTokens(
return $str;
}

$str = preg_replace(
$str = preg_replace_callback(
self::tokenRegex($key),
'self::getMailingTokenReplacement(\'\\1\',$mailing,$escapeSmarty)', $str
function ($matches) use(&$mailing, $escapeSmarty) {
return CRM_Utils_Token::getMailingTokenReplacement($matches[1], $mailing, $escapeSmarty);
},
$str
);
return $str;
}
Expand Down Expand Up @@ -519,8 +524,11 @@ public static function &replaceActionTokens(
return $str;
}

$str = preg_replace(self::tokenRegex($key),
'self::getActionTokenReplacement(\'\\1\',$addresses,$urls,$escapeSmarty)',
$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;
Expand Down Expand Up @@ -604,9 +612,11 @@ public static function &replaceContactTokens(
return $str;
}

$str = preg_replace(
$str = preg_replace_callback(
self::tokenRegex($key),
'self::getContactTokenReplacement(\'\\1\', $contact, $html, $returnBlankToken, $escapeSmarty)',
function ($matches) use(&$contact, $key, $html, $escapeSmarty) {
return CRM_Utils_Token::getHookTokenReplacement($matches[1], $contact, $key, $html, $escapeSmarty);
},
$str
);

Expand Down Expand Up @@ -692,9 +702,11 @@ public static function &replaceHookTokens(
$escapeSmarty = FALSE
) {
foreach ($categories as $key) {
$str = preg_replace(
$str = preg_replace_callback(
self::tokenRegex($key),
'self::getHookTokenReplacement(\'\\1\', $contact, $key, $html, $escapeSmarty)',
function ($matches) use(&$contact, $key, $html, $escapeSmarty) {
return CRM_Utils_Token::getHookTokenReplacement($matches[1], $contact, $key, $html, $escapeSmarty);
},
$str
);
}
Expand Down Expand Up @@ -1236,8 +1248,12 @@ public static function &replaceUserTokens($str, $knownTokens = NULL, $escapeSmar
return $str;
}

$str = preg_replace(self::tokenRegex($key),
'self::getUserTokenReplacement(\'\\1\',$escapeSmarty)', $str
$str = preg_replace_callback(
self::tokenRegex($key),
function ($matches) use($escapeSmarty) {
return CRM_Utils_Token::getUserTokenReplacement($matches[1], $escapeSmarty);
},
$str
);
return $str;
}
Expand Down Expand Up @@ -1286,8 +1302,11 @@ public static function &replaceContributionTokens($str, &$contribution, $html =
return $str;
}

$str = preg_replace(self::tokenRegex($key),
'self::getContributionTokenReplacement(\'\\1\', $contribution, $html, $escapeSmarty)',
$str = preg_replace_callback(
self::tokenRegex($key),
function ($matches) use(&$contribution, $html, $escapeSmarty) {
return CRM_Utils_Token::getContributionTokenReplacement($matches[1], $contribution, $html, $escapeSmarty);
},
$str
);

Expand Down Expand Up @@ -1332,4 +1351,3 @@ function getPermissionEmails($permissionName) {}

function getRoleEmails($roleName) {}
}