CRM_Utils_Token
class CRM_Utils_Token
Class to abstract token replacement.
Properties
static | $_requiredTokens | ||
static | $_tokens |
Methods
No description
Check a string (mailing body) for required tokens.
Wrapper for token matching.
Wrapper for token replacing.
Escape the string so a malicious user cannot inject smarty code into the template.
Replace all the domain-level tokens in $str
No description
Replace all the org-level tokens in $str
Replace all mailing tokens in $str
No description
Replace all action tokens in $str
No description
Replace all the contact-level tokens in $str with information from $contact.
No description
Replace all the hook tokens in $str with information from $contact.
Parse html through Smarty resolving any smarty functions.
No description
unescapeTokens removes any characters that caused the replacement routines to skip token replacement for example {{token}} or {token} will result in {token} in the final email
Replace unsubscribe tokens.
Replace resubscribe tokens.
Replace subscription-confirmation-request tokens
Replace subscription-invitation tokens
Replace welcome/confirmation tokens
Find unprocessed tokens (call this last)
Find and replace tokens for each component.
Get array of string tokens.
Function to determine which values to retrieve to insert into tokens. The heavy resemblance between this function and getTokens appears to be historical rather than intentional and should be reviewed
Gives required details of contacts in an indexed array format so we can iterate in a nice loop and do token evaluation
Call hooks on tokens for anonymous users - contact id is set to 0 - this allows non-contact specific tokens to be rendered
Get Membership Token Details.
Replace existing greeting tokens in message/subject.
No description
Replace all user tokens in $str
No description
No description
Store membership tokens on the static _tokens array.
Replace tokens for an entity.
No description
Generic function for formatting token replacement for an api field
Replace Contribution tokens in html.
We have a situation where we are rendering more than one token in each field because we are combining tokens from more than one contribution when pdf thank you letters are grouped (CRM-14367)
Get replacement strings for any membership tokens (only a small number of tokens are implemnted in the first instance - this is used by the pdfLetter task from membership search
No description
No description
Formats a token list for the select2 widget
Details
at line 95
static array
getRequiredTokens()
at line 120
static bool|array
requiredTokens(string $str)
Check a string (mailing body) for required tokens.
at line 164
static bool
token_match(string $type, string $var, string $str)
Wrapper for token matching.
at line 185
static string
token_replace(string $type, string $var, string $value, string $str, bool $escapeSmarty = FALSE)
Wrapper for token replacing.
at line 219
static string
tokenEscapeSmarty(string $string)
Escape the string so a malicious user cannot inject smarty code into the template.
at line 240
static string
replaceDomainTokens(string $str, object $domain, bool $html = FALSE, null $knownTokens = NULL, bool $escapeSmarty = FALSE)
Replace all the domain-level tokens in $str
at line 272
static mixed|null|string
getDomainTokenReplacement($token, $domain, bool $html = FALSE, bool $escapeSmarty = FALSE)
at line 346
static string
replaceOrgTokens(string $str, object $org, bool $html = FALSE, bool $escapeSmarty = FALSE)
deprecated
deprecated
Replace all the org-level tokens in $str
at line 429
static string
replaceMailingTokens(string $str, object $mailing, bool $html = FALSE, null $knownTokens = NULL, bool $escapeSmarty = FALSE)
Replace all mailing tokens in $str
at line 458
static string
getMailingTokenReplacement($token, $mailing, bool $escapeSmarty = FALSE)
at line 559
static string
replaceActionTokens(string $str, array $addresses, array $urls, bool $html = FALSE, array $knownTokens = NULL, bool $escapeSmarty = FALSE)
Replace all action tokens in $str
at line 595
static mixed|string
getActionTokenReplacement($token, $addresses, $urls, bool $html = FALSE, bool $escapeSmarty = FALSE)
at line 652
static string
replaceContactTokens(string $str, array $contact, bool $html = FALSE, array $knownTokens = NULL, bool $returnBlankToken = FALSE, bool $escapeSmarty = FALSE)
Replace all the contact-level tokens in $str with information from $contact.
at line 700
static bool|mixed|null|string
getContactTokenReplacement($token, $contact, bool $html = FALSE, bool $returnBlankToken = FALSE, bool $escapeSmarty = FALSE)
at line 802
static string
replaceHookTokens(string $str, array $contact, $categories, bool $html = FALSE, bool $escapeSmarty = FALSE)
Replace all the hook tokens in $str with information from $contact.
at line 829
static string
parseThroughSmarty(string $tokenHtml, array $entity, string $entityType = 'contact')
Parse html through Smarty resolving any smarty functions.
at line 848
static mixed|string
getHookTokenReplacement($token, $contact, $category, bool $html = FALSE, bool $escapeSmarty = FALSE)
at line 876
static
unescapeTokens($str)
unescapeTokens removes any characters that caused the replacement routines to skip token replacement for example {{token}} or {token} will result in {token} in the final email
this routine will remove the extra backslashes and braces
at line 898
static string
replaceUnsubscribeTokens(string $str, object $domain, array $groups, bool $html, int $contact_id, string $hash)
Replace unsubscribe tokens.
at line 944
static string
replaceResubscribeTokens(string $str, object $domain, array $groups, bool $html, int $contact_id, string $hash)
Replace resubscribe tokens.
at line 971
static string
replaceSubscribeTokens(string $str, string $group, $url, bool $html)
Replace subscription-confirmation-request tokens
at line 990
static string
replaceSubscribeInviteTokens(string $str)
Replace subscription-invitation tokens
at line 1036
static string
replaceWelcomeTokens(string $str, string $group, bool $html)
Replace welcome/confirmation tokens
at line 1052
static array
unmatchedTokens(string $str)
Find unprocessed tokens (call this last)
at line 1074
static string
replaceComponentTokens(string $str, array $contact, array $components, bool $escapeSmarty = FALSE, bool $returnEmptyToken = TRUE)
Find and replace tokens for each component.
at line 1106
static array
getTokens(string $string)
Get array of string tokens.
at line 1136
static array
getReturnProperties($string)
Function to determine which values to retrieve to insert into tokens. The heavy resemblance between this function and getTokens appears to be historical rather than intentional and should be reviewed
at line 1177
static array
getTokenDetails($contactIDs, array $returnProperties = NULL, bool $skipOnHold = TRUE, bool $skipDeceased = TRUE, array $extraParams = NULL, array $tokens = array(), null $className = NULL, int $jobID = NULL)
Gives required details of contacts in an indexed array format so we can iterate in a nice loop and do token evaluation
at line 1304
static array
getAnonymousTokenDetails(array $contactIDs = array(0), string $returnProperties = NULL, bool $skipOnHold = TRUE, bool $skipDeceased = TRUE, string $extraParams = NULL, array $tokens = array(), string $className = NULL, string $jobID = NULL)
Call hooks on tokens for anonymous users - contact id is set to 0 - this allows non-contact specific tokens to be rendered
at line 1330
static
getMembershipTokenDetails(array $membershipIDs)
Get Membership Token Details.
at line 1356
static
replaceGreetingTokens(string $tokenString, array $contactDetails = NULL, int $contactId = NULL, string $className = NULL, bool $escapeSmarty = FALSE)
Replace existing greeting tokens in message/subject.
This function operates by reference, modifying the first parameter. Other methods for token replacement in this class return the modified string. This leads to inconsistency in how these methods must be applied.
at line 1434
static array
flattenTokens($tokens)
at line 1470
static string
replaceUserTokens(string $str, null $knownTokens = NULL, bool $escapeSmarty = FALSE)
Replace all user tokens in $str
at line 1494
static string
getUserTokenReplacement($token, bool $escapeSmarty = FALSE)
at line 1516
static protected
_buildContributionTokens()
at line 1528
static protected
_buildMembershipTokens()
Store membership tokens on the static _tokens array.
at line 1553
static string
replaceEntityTokens(string $entity, array $entityArray, string $str, array $knownTokens = array(), bool $escapeSmarty = FALSE)
Replace tokens for an entity.
at line 1579
static string
replaceCaseTokens(int $caseId, int $str, array $knownTokens = array(), bool $escapeSmarty = FALSE)
at line 1596
static string
getApiTokenReplacement(string $entity, string $token, array $entityArray)
Generic function for formatting token replacement for an api field
at line 1633
static mixed
replaceContributionTokens(string $str, array $contribution, bool|string $html = FALSE, string $knownTokens = NULL, bool|string $escapeSmarty = FALSE)
Replace Contribution tokens in html.
at line 1676
static string
replaceMultipleContributionTokens(string $separator, string $str, array $contribution, bool|string $html = FALSE, string $knownTokens = NULL, bool|string $escapeSmarty = FALSE)
We have a situation where we are rendering more than one token in each field because we are combining tokens from more than one contribution when pdf thank you letters are grouped (CRM-14367)
The replaceContributionToken doesn't handle receive_date correctly in this scenario because of the formatting it applies (other tokens are OK including date fields)
So we sort this out & then call the main function. Note that we are not escaping smarty on this fields like the main function does - but the fields is already being formatted through a date function
at line 1704
static string
getMembershipTokenReplacement(string $entity, string $token, array $membership)
Get replacement strings for any membership tokens (only a small number of tokens are implemnted in the first instance - this is used by the pdfLetter task from membership search
at line 1755
static mixed|string
getContributionTokenReplacement($token, $contribution, bool $html = FALSE, bool $escapeSmarty = FALSE)
at line 1791
static array
legacyContactTokens()
at line 1806
static array
formatTokensForDisplay($tokens)
Formats a token list for the select2 widget