/** * Check a string (mailing body) for required tokens. * * @param string $str The message * * @return true|array true if all required tokens are found, * else an array of the missing tokens * @access public * @static */ public static function requiredTokens(&$str) { if (self::$_requiredTokens == NULL) { self::$_requiredTokens = array('domain.address' => ts("Domain address - displays your organization's postal address."), 'action.optOutUrl or action.unsubscribeUrl' => array('action.optOut' => ts("'Opt out via email' - displays an email address for recipients to opt out of receiving emails from your organization."), 'action.optOutUrl' => ts("'Opt out via web page' - creates a link for recipients to click if they want to opt out of receiving emails from your organization. Alternatively, you can include the 'Opt out via email' token."), 'action.unsubscribe' => ts("'Unsubscribe via email' - displays an email address for recipients to unsubscribe from the specific mailing list used to send this message."), 'action.unsubscribeUrl' => ts("'Unsubscribe via web page' - creates a link for recipients to unsubscribe from the specific mailing list used to send this message. Alternatively, you can include the 'Unsubscribe via email' token or one of the Opt-out tokens."))); } $missing = array(); foreach (self::$_requiredTokens as $token => $value) { if (!is_array($value)) { if (!preg_match('/(^|[^\\{])' . preg_quote('{' . $token . '}') . '/', $str)) { $missing[$token] = $value; } } else { $present = FALSE; $desc = NULL; foreach ($value as $t => $d) { $desc = $d; if (preg_match('/(^|[^\\{])' . preg_quote('{' . $t . '}') . '/', $str)) { $present = TRUE; } } if (!$present) { $missing[$token] = $desc; } } } if (empty($missing)) { return TRUE; } return $missing; }
/** * @return array */ public static function getRequiredTokens() { if (self::$_requiredTokens == NULL) { self::$_requiredTokens = array('domain.address' => ts("Domain address - displays your organization's postal address."), 'action.optOutUrl or action.unsubscribeUrl' => array('action.optOut' => ts("'Opt out via email' - displays an email address for recipients to opt out of receiving emails from your organization."), 'action.optOutUrl' => ts("'Opt out via web page' - creates a link for recipients to click if they want to opt out of receiving emails from your organization. Alternatively, you can include the 'Opt out via email' token."), 'action.unsubscribe' => ts("'Unsubscribe via email' - displays an email address for recipients to unsubscribe from the specific mailing list used to send this message."), 'action.unsubscribeUrl' => ts("'Unsubscribe via web page' - creates a link for recipients to unsubscribe from the specific mailing list used to send this message. Alternatively, you can include the 'Unsubscribe via email' token or one of the Opt-out tokens."))); } return self::$_requiredTokens; }
/** * Check a string (mailing body) for required tokens. * * @param string $str The message * @return true|array true if all required tokens are found, * else an array of the missing tokens * @access public * @static */ public static function requiredTokens(&$str) { if (self::$_requiredTokens == null) { self::$_requiredTokens = array('domain.address' => ts("Domain address - displays your organization's postal address."), 'action.optOutUrl' => array('action.optOut' => ts("'Opt out via email' - displays an email address for recipients to opt out of receiving emails from your organization."), 'action.optOutUrl' => ts("'Opt out via web page' - creates a link for recipients to click if they want to opt out of receiving emails from your organization. Alternatively, you can include the 'Opt out via email' token."))); } $missing = array(); foreach (self::$_requiredTokens as $token => $value) { if (!is_array($value)) { if (!preg_match('/(^|[^\\{])' . preg_quote('{' . $token . '}') . '/', $str)) { $missing[$token] = $value; } } else { $present = false; $desc = null; foreach ($value as $t => $d) { $desc = $d; if (preg_match('/(^|[^\\{])' . preg_quote('{' . $t . '}') . '/', $str)) { $present = true; } } if (!$present) { $missing[$token] = $desc; } } } if (empty($missing)) { return true; } return $missing; }