CRM_Utils_Token
class CRM_Utils_Token
Class to abstract token replacement.
Properties
static | $_requiredTokens | ||
static | $_tokens |
Methods
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
Get all custom field tokens of $entity
Formats a token list for the select2 widget
Details
at line 96
static array
getRequiredTokens()
deprecated
deprecated
at line 121
static bool|array
requiredTokens(string $str)
Check a string (mailing body) for required tokens.
at line 166
static bool
token_match(string $type, string $var, string $str)
Wrapper for token matching.
at line 187
static string
token_replace(string $type, string $var, string $value, string $str, bool $escapeSmarty = FALSE)
Wrapper for token replacing.
at line 221
static string
tokenEscapeSmarty(string $string)
Escape the string so a malicious user cannot inject smarty code into the template.
at line 242
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 274
static mixed|null|string
getDomainTokenReplacement($token, $domain, bool $html = FALSE, bool $escapeSmarty = FALSE)
at line 348
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 431
static string
replaceMailingTokens(string $str, object $mailing, bool $html = FALSE, null $knownTokens = NULL, bool $escapeSmarty = FALSE)
Replace all mailing tokens in $str
at line 460
static string
getMailingTokenReplacement($token, $mailing, bool $escapeSmarty = FALSE)
at line 561
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 597
static mixed|string
getActionTokenReplacement($token, $addresses, $urls, bool $html = FALSE, bool $escapeSmarty = FALSE)
at line 654
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 699
static bool|mixed|null|string
getContactTokenReplacement($token, $contact, bool $html = FALSE, bool $returnBlankToken = FALSE, bool $escapeSmarty = FALSE)
at line 801
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 828
static string
parseThroughSmarty(string $tokenHtml, array $entity, string $entityType = 'contact')
Parse html through Smarty resolving any smarty functions.
at line 847
static mixed|string
getHookTokenReplacement($token, $contact, $category, bool $html = FALSE, bool $escapeSmarty = FALSE)
at line 875
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 897
static string
replaceUnsubscribeTokens(string $str, object $domain, array $groups, bool $html, int $contact_id, string $hash)
Replace unsubscribe tokens.
at line 943
static string
replaceResubscribeTokens(string $str, object $domain, array $groups, bool $html, int $contact_id, string $hash)
Replace resubscribe tokens.
at line 970
static string
replaceSubscribeTokens(string $str, string $group, $url, bool $html)
Replace subscription-confirmation-request tokens
at line 989
static string
replaceSubscribeInviteTokens(string $str)
Replace subscription-invitation tokens
at line 1035
static string
replaceWelcomeTokens(string $str, string $group, bool $html)
Replace welcome/confirmation tokens
at line 1051
static array
unmatchedTokens(string $str)
Find unprocessed tokens (call this last)
at line 1073
static string
replaceComponentTokens(string $str, array $contact, array $components, bool $escapeSmarty = FALSE, bool $returnEmptyToken = TRUE)
Find and replace tokens for each component.
at line 1105
static array
getTokens(string $string)
Get array of string tokens.
at line 1135
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 1176
static array
getTokenDetails(array $contactIDs, array $returnProperties = NULL, bool $skipOnHold = TRUE, bool $skipDeceased = TRUE, array $extraParams = NULL, array $tokens = [], 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 1301
static array
getAnonymousTokenDetails(array $contactIDs = [0], string $returnProperties = NULL, bool $skipOnHold = TRUE, bool $skipDeceased = TRUE, string $extraParams = NULL, array $tokens = [], 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 1327
static
getMembershipTokenDetails(array $membershipIDs)
Get Membership Token Details.
at line 1353
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 1482
static array
flattenTokens($tokens)
at line 1518
static string
replaceUserTokens(string $str, null $knownTokens = NULL, bool $escapeSmarty = FALSE)
Replace all user tokens in $str
at line 1542
static string
getUserTokenReplacement($token, bool $escapeSmarty = FALSE)
at line 1564
static protected
_buildContributionTokens()
at line 1577
static protected
_buildMembershipTokens()
Store membership tokens on the static _tokens array.
at line 1602
static string
replaceEntityTokens(string $entity, array $entityArray, string $str, array $knownTokens = [], bool $escapeSmarty = FALSE)
Replace tokens for an entity.
at line 1628
static string
replaceCaseTokens(int $caseId, int $str, array $knownTokens = [], bool $escapeSmarty = FALSE)
at line 1645
static string
getApiTokenReplacement(string $entity, string $token, array $entityArray)
Generic function for formatting token replacement for an api field
at line 1682
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 1726
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 1754
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 1806
static mixed|string
getContributionTokenReplacement($token, $contribution, bool $html = FALSE, bool $escapeSmarty = FALSE)
at line 1842
static array
legacyContactTokens()
at line 1860
static array
getCustomFieldTokens(string $entity, bool $usedForTokenWidget = FALSE)
Get all custom field tokens of $entity
at line 1876
static array
formatTokensForDisplay($tokens)
Formats a token list for the select2 widget