Merge pull request #5513 from mallezie/contact-select-file-16178
[civicrm-core.git] / CRM / Utils / Token.php
index c92724294a13cd7bc2aca7c578ffc748249fe729..b549e4aa9f1f6ae764e6456ca3b73bb8fd975f0f 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id: $
  *
  */
@@ -90,17 +90,11 @@ class CRM_Utils_Token {
     '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."),
@@ -112,9 +106,24 @@ class CRM_Utils_Token {
         ),
       );
     }
+    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;
@@ -142,7 +151,7 @@ class CRM_Utils_Token {
   }
 
   /**
-   * Wrapper for token matching
+   * Wrapper for token matching.
    *
    * @param string $type
    *   The token type (domain,mailing,contact,action).
@@ -160,7 +169,7 @@ class CRM_Utils_Token {
   }
 
   /**
-   * Wrapper for token replacing
+   * Wrapper for token replacing.
    *
    * @param string $type
    *   The token type.
@@ -201,7 +210,7 @@ class CRM_Utils_Token {
   }
 
   /**
-   * 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.
@@ -592,7 +601,7 @@ class CRM_Utils_Token {
     $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}";
@@ -808,7 +817,7 @@ class CRM_Utils_Token {
   }
 
   /**
-   * 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
@@ -869,7 +878,7 @@ class CRM_Utils_Token {
   }
 
   /**
-   * Replace unsubscribe tokens
+   * Replace unsubscribe tokens.
    *
    * @param string $str
    *   The string with tokens to be replaced.
@@ -915,7 +924,7 @@ class CRM_Utils_Token {
   }
 
   /**
-   * Replace resubscribe tokens
+   * Replace resubscribe tokens.
    *
    * @param string $str
    *   The string with tokens to be replaced.
@@ -1048,7 +1057,7 @@ class CRM_Utils_Token {
   }
 
   /**
-   * Find and replace tokens for each component
+   * Find and replace tokens for each component.
    *
    * @param string $str
    *   The string to search.
@@ -1087,7 +1096,7 @@ class CRM_Utils_Token {
   }
 
   /**
-   * Get array of string tokens
+   * Get array of string tokens.
    *
    * @param string $string
    *   The input string to parse for tokens.
@@ -1390,7 +1399,7 @@ class CRM_Utils_Token {
   }
 
   /**
-   * Get Membership Token Details
+   * Get Membership Token Details.
    * @param array $membershipIDs
    *   Array of membership IDS.
    */
@@ -1577,7 +1586,7 @@ class CRM_Utils_Token {
   }
 
   /**
-   * Store membership tokens on the static _tokens array
+   * Store membership tokens on the static _tokens array.
    */
   protected static function _buildMembershipTokens() {
     $key = 'membership';
@@ -1592,7 +1601,7 @@ class CRM_Utils_Token {
   }
 
   /**
-   * Replace tokens for an entity
+   * Replace tokens for an entity.
    * @param string $entity
    * @param array $entityArray
    *   (e.g. in format from api).
@@ -1620,7 +1629,7 @@ class CRM_Utils_Token {
   }
 
   /**
-   * Replace Contribution tokens in html
+   * Replace Contribution tokens in html.
    *
    * @param string $str
    * @param array $contribution
@@ -1799,6 +1808,7 @@ class CRM_Utils_Token {
 
   /**
    * Formats a token list for the select2 widget
+   *
    * @param $tokens
    * @return array
    */