Skip to content

Commit

Permalink
Merge pull request civicrm#797 from dlobo/CRM-12172
Browse files Browse the repository at this point in the history
CRM-12172
  • Loading branch information
kurund committed May 19, 2013
2 parents cdc4a9a + 8bab0eb commit 64071bf
Showing 1 changed file with 34 additions and 16 deletions.
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) {}
}

0 comments on commit 64071bf

Please sign in to comment.