CRM_Utils_Hook::hooks - Prettify
[civicrm-core.git] / CRM / Utils / Token.php
index 63d6cbf82306a953209cad9ac2062056492aac6d..5a51668ccafd08db1596acc7d4546f58692c0659 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2016                                |
+ | Copyright CiviCRM LLC (c) 2004-2017                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2016
+ * @copyright CiviCRM LLC (c) 2004-2017
  */
 
 /**
@@ -753,6 +753,9 @@ class CRM_Utils_Token {
           $value = CRM_Core_PseudoConstant::getLabel('CRM_Contact_BAO_Contact', $token, $value);
         }
       }
+      elseif ($value && CRM_Utils_String::endsWith($token, '_date')) {
+        $value = CRM_Utils_Date::customFormat($value);
+      }
     }
 
     if (!$html) {
@@ -1311,7 +1314,7 @@ class CRM_Utils_Token {
    * @return array
    *   contactDetails with hooks swapped out
    */
-  public function getAnonymousTokenDetails($contactIDs = array(
+  public static function getAnonymousTokenDetails($contactIDs = array(
       0,
     ),
                                            $returnProperties = NULL,
@@ -1406,15 +1409,24 @@ class CRM_Utils_Token {
    */
   public static function getMembershipTokenDetails($membershipIDs) {
     $memberships = civicrm_api3('membership', 'get', array(
-        'options' => array('limit' => 200000),
-        'membership_id' => array('IN' => (array) $membershipIDs),
-      ));
+      'options' => array('limit' => 0),
+      'membership_id' => array('IN' => (array) $membershipIDs),
+    ));
     return $memberships['values'];
   }
 
   /**
    * 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.
+   *
+   * @TODO Remove that inconsistency in usage.
+   *
+   * ::replaceContactTokens() may need to be called after this method, to
+   * replace tokens supplied from this method.
+   *
    * @param string $tokenString
    * @param array $contactDetails
    * @param int $contactId
@@ -1798,6 +1810,9 @@ class CRM_Utils_Token {
       default:
         if (in_array($token, self::$_tokens[$entity])) {
           $value = $membership[$token];
+          if (CRM_Utils_String::endsWith($token, '_date')) {
+            $value = CRM_Utils_Date::customFormat($value);
+          }
         }
         else {
           // ie unchanged