+--------------------------------------------------------------------+
| CiviCRM version 4.6 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014 |
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
-*/
+ */
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
* $Id: $
*
*/
'welcome' => array('group'),
);
+
/**
- * Check a string (mailing body) for required tokens.
- *
- * @param string $str
- * The message.
- *
- * @return bool|array
- * true if all required tokens are found,
- * else an array of the missing tokens
+ * @return array
*/
- public static function requiredTokens(&$str) {
+ public static function getRequiredTokens() {
if (self::$_requiredTokens == NULL) {
self::$_requiredTokens = array(
'domain.address' => ts("Domain address - displays your organization's postal address."),
),
);
}
+ return self::$_requiredTokens;
+ }
+
+ /**
+ * Check a string (mailing body) for required tokens.
+ *
+ * @param string $str
+ * The message.
+ *
+ * @return bool|array
+ * true if all required tokens are found,
+ * else an array of the missing tokens
+ */
+ public static function requiredTokens(&$str) {
+ $requiredTokens = self::getRequiredTokens();
$missing = array();
- foreach (self::$_requiredTokens as $token => $value) {
+ foreach ($requiredTokens as $token => $value) {
if (!is_array($value)) {
if (!preg_match('/(^|[^\{])' . preg_quote('{' . $token . '}') . '/', $str)) {
$missing[$token] = $value;
}
/**
- * Wrapper for token matching
+ * Wrapper for token matching.
*
* @param string $type
* The token type (domain,mailing,contact,action).
* @param string $str
* The string to search.
*
- * @return boolean
+ * @return bool
* Was there a match
*/
public static function token_match($type, $var, &$str) {
}
/**
- * Wrapper for token replacing
+ * Wrapper for token replacing.
*
* @param string $type
* The token type.
}
/**
- * Escape the string so a malicious user cannot inject smarty code into the template
+ * Escape the string so a malicious user cannot inject smarty code into the template.
*
* @param string $string
* A string that needs to be escaped from smarty parsing.
* The processed string
*/
public static function &replaceOrgTokens($str, &$org, $html = FALSE, $escapeSmarty = FALSE) {
- self::$_tokens['org'] =
- array_merge(
+ self::$_tokens['org']
+ = array_merge(
array_keys(CRM_Contact_BAO_Contact::importableFields('Organization')),
array('address', 'display_name', 'checksum', 'contact_id')
);
$escapeSmarty = FALSE
) {
/* If the token is an email action, use it. Otherwise, find the
- * appropriate URL */
+ * appropriate URL */
if (!in_array($token, self::$_tokens['action'])) {
$value = "{action.$token}";
if (self::$_tokens[$key] == NULL) {
/* This should come from UF */
- self::$_tokens[$key] =
- array_merge(
+ self::$_tokens[$key]
+ = array_merge(
array_keys(CRM_Contact_BAO_Contact::exportableFields('All')),
array('checksum', 'contact_id')
);
if (self::$_tokens['contact'] == NULL) {
/* This should come from UF */
- self::$_tokens['contact'] =
- array_merge(
+ self::$_tokens['contact']
+ = array_merge(
array_keys(CRM_Contact_BAO_Contact::exportableFields('All')),
array('checksum', 'contact_id')
);
if ($escapeSmarty
&& !($returnBlankToken && $noReplace)
- ) { // $returnBlankToken means the caller wants to do further attempts at processing unreplaced tokens -- so don't escape them yet in this case.
+ ) {
+ // $returnBlankToken means the caller wants to do further attempts at
+ // processing unreplaced tokens -- so don't escape them yet in this case.
$value = self::tokenEscapeSmarty($value);
}
}
/**
- * Parse html through Smarty resolving any smarty functions
+ * Parse html through Smarty resolving any smarty functions.
* @param string $tokenHtml
* @param array $entity
* @param string $entityType
* @param $str ref to the string that will be scanned and modified
* @return void
* this function works directly on the string that is passed
- * @access public
*/
public static function unescapeTokens(&$str) {
$str = preg_replace('/\\\\|\{(\{\w+\.\w+\})\}/', '\\1', $str);
}
/**
- * Replace unsubscribe tokens
+ * Replace unsubscribe tokens.
*
* @param string $str
* The string with tokens to be replaced.
* Replace tokens with html or plain text.
* @param int $contact_id
* The contact ID.
- * @param string hash The security hash of the unsub event
+ * @param string $hash The security hash of the unsub event
*
* @return string
* The processed string
}
/**
- * Replace resubscribe tokens
+ * Replace resubscribe tokens.
*
* @param string $str
* The string with tokens to be replaced.
* Replace tokens with html or plain text.
* @param int $contact_id
* The contact ID.
- * @param string hash The security hash of the resub event
+ * @param string $hash The security hash of the resub event
*
* @return string
* The processed string
}
/**
- * Find and replace tokens for each component
+ * Find and replace tokens for each component.
*
* @param string $str
* The string to search.
}
/**
- * Get array of string tokens
+ * Get array of string tokens.
*
* @param string $string
* The input string to parse for tokens.
*
* @return array
* array of tokens mentioned in field
- * @access public
*/
public static function getTokens($string) {
$matches = array();
* @param $contactIDs
* @param array $returnProperties
* Of required properties.
- * @param bool $skipOnHoldDon 't return on_hold contact info also.
+ * @param bool $skipOnHold Don't return on_hold contact info also.
* Don't return on_hold contact info also.
- * @param bool $skipDeceasedDon 't return deceased contact info.
+ * @param bool $skipDeceased Don't return deceased contact info.
* Don't return deceased contact info.
* @param array $extraParams
* Extra params.
*
* @return array
*/
- static function getTokenDetails(
+ public static function getTokenDetails(
$contactIDs,
$returnProperties = NULL,
$skipOnHold = TRUE,
foreach (array(
'email_greeting',
'postal_greeting',
- 'addressee'
+ 'addressee',
) as $val) {
if (!empty($contactDetails[$contactID][$val])) {
$contactDetails[$contactID][$val] = $contactDetails[$contactID]["{$val}_display"];
* contactDetails with hooks swapped out
*/
public function getAnonymousTokenDetails($contactIDs = array(
- 0
+ 0,
),
$returnProperties = NULL,
$skipOnHold = TRUE,
*
* @return array
*/
- static function getContributionTokenDetails(
+ public static function getContributionTokenDetails(
$contributionIDs,
$returnProperties = NULL,
$extraParams = NULL,
$tokens = array(),
$className = NULL
) {
- //@todo - this function basically replications calling civicrm_api3('contribution', 'get', array('id' => array('IN' => array())
+ //@todo - this function basically replicates calling
+ //civicrm_api3('contribution', 'get', array('id' => array('IN' => array())
if (empty($contributionIDs)) {
// putting a fatal here so we can track if/when this happens
CRM_Core_Error::fatal();
}
/**
- * Get Membership Token Details
+ * Get Membership Token Details.
* @param array $membershipIDs
* Array of membership IDS.
*/
public static function getMembershipTokenDetails($membershipIDs) {
$memberships = civicrm_api3('membership', 'get', array(
'options' => array('limit' => 200000),
- 'membership_id' => array('IN' => (array) $membershipIDs)
+ 'membership_id' => array('IN' => (array) $membershipIDs),
));
return $memberships['values'];
}
// check if there are any unevaluated tokens
$greetingTokens = self::getTokens($tokenString);
- // $greetingTokens not empty, means there are few tokens which are not evaluated, like custom data etc
+ // $greetingTokens not empty, means there are few tokens which are not
+ // evaluated, like custom data etc
// so retrieve it from database
if (!empty($greetingTokens) && array_key_exists('contact', $greetingTokens)) {
$greetingsReturnProperties = array_flip(CRM_Utils_Array::value('contact', $greetingTokens));
foreach (array(
'html',
'text',
- 'subject'
+ 'subject',
) as $prop) {
if (!isset($tokens[$prop])) {
continue;
}
/**
- * Store membership tokens on the static _tokens array
+ * Store membership tokens on the static _tokens array.
*/
protected static function _buildMembershipTokens() {
$key = 'membership';
}
/**
- * Replace tokens for an entity
+ * Replace tokens for an entity.
* @param string $entity
* @param array $entityArray
* (e.g. in format from api).
}
/**
- * Replace Contribution tokens in html
+ * Replace Contribution tokens in html.
*
* @param string $str
* @param array $contribution
try {
$value = civicrm_api3('membership_type', 'getvalue', array(
'id' => $membership['membership_type_id'],
- 'return' => 'minimum_fee'
+ 'return' => 'minimum_fee',
));
}
catch (CiviCRM_API3_Exception $e) {
/**
* Formats a token list for the select2 widget
+ *
* @param $tokens
* @return array
*/
return $output;
}
+
}