本文整理汇总了PHP中CRM_Utils_Token::replaceDomainTokens方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_Token::replaceDomainTokens方法的具体用法?PHP CRM_Utils_Token::replaceDomainTokens怎么用?PHP CRM_Utils_Token::replaceDomainTokens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Utils_Token
的用法示例。
在下文中一共展示了CRM_Utils_Token::replaceDomainTokens方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onRender
/**
* Apply the various CRM_Utils_Token helpers.
*
* @param TokenRenderEvent $e
*/
public function onRender(TokenRenderEvent $e)
{
$isHtml = $e->message['format'] == 'text/html';
$useSmarty = !empty($e->context['smarty']);
$e->string = \CRM_Utils_Token::replaceDomainTokens($e->string, \CRM_Core_BAO_Domain::getDomain(), $isHtml, $e->message['tokens'], $useSmarty);
if (!empty($e->context['contact'])) {
$e->string = \CRM_Utils_Token::replaceContactTokens($e->string, $e->context['contact'], $isHtml, $e->message['tokens'], FALSE, $useSmarty);
// FIXME: This may depend on $contact being merged with hook values.
$e->string = \CRM_Utils_Token::replaceHookTokens($e->string, $e->context['contact'], $e->context['hookTokenCategories'], $isHtml, $useSmarty);
\CRM_Utils_Token::replaceGreetingTokens($e->string, NULL, $e->context['contact']['contact_id'], NULL, $useSmarty);
}
if ($useSmarty) {
$smarty = \CRM_Core_Smarty::singleton();
$e->string = $smarty->fetch("string:" . $e->string);
}
}
示例2: send_confirm_request
/**
* Ask a contact for subscription confirmation (opt-in)
*
* @param string $email The email address
* @return void
* @access public
*/
public function send_confirm_request($email)
{
$config =& CRM_Core_Config::singleton();
require_once 'CRM/Core/BAO/Domain.php';
$domain =& CRM_Core_BAO_Domain::getDomain();
//get the default domain email address.
list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
require_once 'CRM/Core/BAO/MailSettings.php';
$localpart = CRM_Core_BAO_MailSettings::defaultLocalpart();
$emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
require_once 'CRM/Utils/Verp.php';
$confirm = implode($config->verpSeparator, array($localpart . 'c', $this->contact_id, $this->id, $this->hash)) . "@{$emailDomain}";
require_once 'CRM/Contact/BAO/Group.php';
$group =& new CRM_Contact_BAO_Group();
$group->id = $this->group_id;
$group->find(true);
require_once 'CRM/Mailing/BAO/Component.php';
$component =& new CRM_Mailing_BAO_Component();
$component->is_default = 1;
$component->is_active = 1;
$component->component_type = 'Subscribe';
$component->find(true);
$headers = array('Subject' => $component->subject, 'From' => "\"{$domainEmailName}\" <{$domainEmailAddress}>", 'To' => $email, 'Reply-To' => $confirm, 'Return-Path' => "do-not-reply@{$emailDomain}");
$url = CRM_Utils_System::url('civicrm/mailing/confirm', "reset=1&cid={$this->contact_id}&sid={$this->id}&h={$this->hash}", true);
$html = $component->body_html;
if ($component->body_text) {
$text = $component->body_text;
} else {
$text = CRM_Utils_String::htmlToText($component->body_html);
}
require_once 'CRM/Mailing/BAO/Mailing.php';
$bao =& new CRM_Mailing_BAO_Mailing();
$bao->body_text = $text;
$bao->body_html = $html;
$tokens = $bao->getTokens();
require_once 'CRM/Utils/Token.php';
$html = CRM_Utils_Token::replaceDomainTokens($html, $domain, true, $tokens['html']);
$html = CRM_Utils_Token::replaceSubscribeTokens($html, $group->title, $url, true);
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, false, $tokens['text']);
$text = CRM_Utils_Token::replaceSubscribeTokens($text, $group->title, $url, false);
// render the & entities in text mode, so that the links work
$text = str_replace('&', '&', $text);
// we need to wrap Mail_mime because PEAR is apparently unable to fix
// a six-year-old bug (PEAR bug #30) in Mail_mime::_encodeHeaders()
// this fixes CRM-5466
require_once 'CRM/Utils/Mail/FixedMailMIME.php';
$message =& new CRM_Utils_Mail_FixedMailMIME("\n");
$message->setHTMLBody($html);
$message->setTxtBody($text);
$b =& CRM_Utils_Mail::setMimeParams($message);
$h =& $message->headers($headers);
$mailer =& $config->getMailer();
require_once 'CRM/Mailing/BAO/Mailing.php';
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('CRM_Core_Error', 'nullHandler'));
if (is_object($mailer)) {
$mailer->send($email, $h, $b);
CRM_Core_Error::setCallback();
}
}
示例3: replaceTokens
protected function replaceTokens($input, $contact_id)
{
//get contact
$params = array(array('contact_id', '=', $contact_id, 0, 0));
list($contact, $_) = CRM_Contact_BAO_Query::apiQuery($params);
$contact = reset($contact);
if (!$contact || is_a($contact, 'CRM_Core_Error')) {
throw new API_Exception('Could not find contact with ID: ' . $params['contact_id']);
}
$tokens = CRM_Utils_Token::getTokens($input);
// get replacement text for these tokens
$returnProperties = array('sort_name' => 1, 'email' => 1, 'do_not_email' => 1, 'is_deceased' => 1, 'on_hold' => 1, 'display_name' => 1, 'preferred_mail_format' => 1);
if (isset($tokens['contact'])) {
foreach ($tokens['contact'] as $key => $value) {
$returnProperties[$value] = 1;
}
}
list($details) = CRM_Utils_Token::getTokenDetails(array($contact_id), $returnProperties, false, false, null, $tokens);
$contact = reset($details);
// call token hook
$hookTokens = array();
CRM_Utils_Hook::tokens($hookTokens);
$categories = array_keys($hookTokens);
CRM_Utils_Token::replaceGreetingTokens($input, NULL, $contact['contact_id']);
$input = CRM_Utils_Token::replaceDomainTokens($input, $domain, true, $tokens, true);
$input = CRM_Utils_Token::replaceContactTokens($input, $contact, false, $tokens, false, true);
$input = CRM_Utils_Token::replaceComponentTokens($input, $contact, $tokens, true);
$input = CRM_Utils_Token::replaceHookTokens($input, $contact, $categories, true);
return $input;
}
示例4: confirm
/**
* Confirm a pending subscription
*
* @param int $contact_id The id of the contact
* @param int $subscribe_id The id of the subscription event
* @param string $hash The hash
* @return boolean True on success
* @access public
* @static
*/
function confirm($contact_id, $subscribe_id, $hash)
{
$se =& CRM_Mailing_Event_BAO_Subscribe::verify($contact_id, $subscribe_id, $hash);
if (!$se) {
return false;
}
CRM_Core_DAO::transaction('BEGIN');
$ce =& new CRM_Mailing_Event_BAO_Confirm();
$ce->event_subscribe_id = $se->id;
$ce->time_stamp = date('YmdHis');
$ce->save();
CRM_Contact_BAO_GroupContact::updateGroupMembershipStatus($contact_id, $se->group_id, 'Email', $ce->id);
CRM_Core_DAO::transaction('COMMIT');
$config =& CRM_Core_Config::singleton();
$domain =& CRM_Mailing_Event_BAO_Subscribe::getDomain($subscribe_id);
list($display_name, $email) = CRM_Contact_BAO_Contact::getEmailDetails($se->contact_id);
$group =& new CRM_Contact_DAO_Group();
$group->id = $se->group_id;
$group->find(true);
require_once 'CRM/Mailing/BAO/Component.php';
$component =& new CRM_Mailing_BAO_Component();
$component->domain_id = $domain->id;
$component->is_default = 1;
$component->is_active = 1;
$component->component_type = 'Welcome';
$component->find(true);
$headers = array('Subject' => $component->subject, 'From' => ts('"%1 Administrator" <do-not-reply@%2>', array(1 => $domain->name, 2 => $domain->email_domain)), 'To' => $email, 'Reply-To' => "do-not-reply@{$domain->email_domain}", 'Return-Path' => "do-not-reply@{$domain->email_domain}");
$html = $component->body_html;
require_once 'CRM/Utils/Token.php';
$html = CRM_Utils_Token::replaceDomainTokens($html, $domain, true);
$html = CRM_Utils_Token::replaceWelcomeTokens($html, $group->name, true);
$text = $component->body_text;
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, false);
$text = CRM_Utils_Token::replaceWelcomeTokens($text, $group->name, false);
$message =& new Mail_Mime("\n");
$message->setHTMLBody($html);
$message->setTxtBody($text);
$b = $message->get();
$h = $message->headers($headers);
$mailer =& $config->getMailer();
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('CRM_Mailing_BAO_Mailing', 'catchSMTP'));
$mailer->send($email, $h, $b);
CRM_Core_Error::setCallback();
return true;
}
示例5: send_unsub_response
/**
* Send a reponse email informing the contact of the groups from which he
* has been unsubscribed.
*
* @param string $queue_id The queue event ID
* @param array $groups List of group IDs
* @param bool $is_domain Is this domain-level?
* @param int $job The job ID
* @return void
* @access public
* @static
*/
public static function send_unsub_response($queue_id, $groups, $is_domain = false, $job)
{
$config =& CRM_Core_Config::singleton();
$domain =& CRM_Core_BAO_Domain::getDomain();
$jobTable = CRM_Mailing_BAO_Job::getTableName();
$mailingTable = CRM_Mailing_DAO_Mailing::getTableName();
$contacts = CRM_Contact_DAO_Contact::getTableName();
$email = CRM_Core_DAO_Email::getTableName();
$queue = CRM_Mailing_Event_BAO_Queue::getTableName();
//get the default domain email address.
list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
$dao =& new CRM_Mailing_BAO_Mailing();
$dao->query(" SELECT * FROM {$mailingTable} \n INNER JOIN {$jobTable} ON\n {$jobTable}.mailing_id = {$mailingTable}.id \n WHERE {$jobTable}.id = {$job}");
$dao->fetch();
$component =& new CRM_Mailing_BAO_Component();
if ($is_domain) {
$component->id = $dao->optout_id;
} else {
$component->id = $dao->unsubscribe_id;
}
$component->find(true);
$html = $component->body_html;
if ($component->body_text) {
$text = $component->body_text;
} else {
$text = CRM_Utils_String::htmlToText($component->body_html);
}
$eq =& new CRM_Core_DAO();
$eq->query("SELECT {$contacts}.preferred_mail_format as format,\n {$contacts}.id as contact_id,\n {$email}.email as email,\n {$queue}.hash as hash\n FROM {$contacts}\n INNER JOIN {$queue} ON {$queue}.contact_id = {$contacts}.id\n INNER JOIN {$email} ON {$queue}.email_id = {$email}.id\n WHERE {$queue}.id = " . CRM_Utils_Type::escape($queue_id, 'Integer'));
$eq->fetch();
if ($groups) {
foreach ($groups as $key => $value) {
if (!$value) {
unset($groups[$key]);
}
}
}
$message =& new Mail_Mime("\n");
list($addresses, $urls) = CRM_Mailing_BAO_Mailing::getVerpAndUrls($job, $queue_id, $eq->hash, $eq->email);
$bao =& new CRM_Mailing_BAO_Mailing();
$bao->body_text = $text;
$bao->body_html = $html;
$tokens = $bao->getTokens();
require_once 'CRM/Utils/Token.php';
if ($eq->format == 'HTML' || $eq->format == 'Both') {
$html = CRM_Utils_Token::replaceDomainTokens($html, $domain, true, $tokens['html']);
$html = CRM_Utils_Token::replaceUnsubscribeTokens($html, $domain, $groups, true, $eq->contact_id, $eq->hash);
$html = CRM_Utils_Token::replaceActionTokens($html, $addresses, $urls, true, $tokens['html']);
$html = CRM_Utils_Token::replaceMailingTokens($html, $dao, null, $tokens['html']);
$message->setHTMLBody($html);
}
if (!$html || $eq->format == 'Text' || $eq->format == 'Both') {
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, false, $tokens['text']);
$text = CRM_Utils_Token::replaceUnsubscribeTokens($text, $domain, $groups, false, $eq->contact_id, $eq->hash);
$text = CRM_Utils_Token::replaceActionTokens($text, $addresses, $urls, false, $tokens['text']);
$text = CRM_Utils_Token::replaceMailingTokens($text, $dao, null, $tokens['text']);
$message->setTxtBody($text);
}
require_once 'CRM/Core/BAO/MailSettings.php';
$emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
$headers = array('Subject' => $component->subject, 'From' => "\"{$domainEmailName}\" <do-not-reply@{$emailDomain}>", 'To' => $eq->email, 'Reply-To' => "do-not-reply@{$emailDomain}", 'Return-Path' => "do-not-reply@{$emailDomain}");
$b =& CRM_Utils_Mail::setMimeParams($message);
$h =& $message->headers($headers);
$mailer =& $config->getMailer();
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('CRM_Core_Error', 'nullHandler'));
if (is_object($mailer)) {
$mailer->send($eq->email, $h, $b);
CRM_Core_Error::setCallback();
}
}
示例6: tokenReplace
/**
*
* get mailing object and replaces subscribeInvite,
* domain and mailing tokens
*/
public static function tokenReplace(&$mailing)
{
$domain = CRM_Core_BAO_Domain::getDomain();
foreach (array('text', 'html') as $type) {
$tokens = $mailing->getTokens();
if (isset($mailing->templates[$type])) {
$mailing->templates[$type] = CRM_Utils_Token::replaceSubscribeInviteTokens($mailing->templates[$type]);
$mailing->templates[$type] = CRM_Utils_Token::replaceDomainTokens($mailing->templates[$type], $domain, $type == 'html' ? TRUE : FALSE, $tokens[$type]);
$mailing->templates[$type] = CRM_Utils_Token::replaceMailingTokens($mailing->templates[$type], $mailing, NULL, $tokens[$type]);
}
}
}
示例7: send_confirm_request
/**
* Ask a contact for subscription confirmation (opt-in)
*
* @param string $email
* The email address.
*
* @return void
*/
public function send_confirm_request($email)
{
$config = CRM_Core_Config::singleton();
$domain = CRM_Core_BAO_Domain::getDomain();
//get the default domain email address.
list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
$localpart = CRM_Core_BAO_MailSettings::defaultLocalpart();
$emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
$confirm = implode($config->verpSeparator, array($localpart . 'c', $this->contact_id, $this->id, $this->hash)) . "@{$emailDomain}";
$group = new CRM_Contact_BAO_Group();
$group->id = $this->group_id;
$group->find(TRUE);
$component = new CRM_Mailing_BAO_Component();
$component->is_default = 1;
$component->is_active = 1;
$component->component_type = 'Subscribe';
$component->find(TRUE);
$headers = array('Subject' => $component->subject, 'From' => "\"{$domainEmailName}\" <{$domainEmailAddress}>", 'To' => $email, 'Reply-To' => $confirm, 'Return-Path' => "do-not-reply@{$emailDomain}");
$url = CRM_Utils_System::url('civicrm/mailing/confirm', "reset=1&cid={$this->contact_id}&sid={$this->id}&h={$this->hash}", TRUE);
$html = $component->body_html;
if ($component->body_text) {
$text = $component->body_text;
} else {
$text = CRM_Utils_String::htmlToText($component->body_html);
}
$bao = new CRM_Mailing_BAO_Mailing();
$bao->body_text = $text;
$bao->body_html = $html;
$tokens = $bao->getTokens();
$html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html']);
$html = CRM_Utils_Token::replaceSubscribeTokens($html, $group->title, $url, TRUE);
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, FALSE, $tokens['text']);
$text = CRM_Utils_Token::replaceSubscribeTokens($text, $group->title, $url, FALSE);
// render the & entities in text mode, so that the links work
$text = str_replace('&', '&', $text);
$message = new Mail_mime("\n");
$message->setHTMLBody($html);
$message->setTxtBody($text);
$b = CRM_Utils_Mail::setMimeParams($message);
$h = $message->headers($headers);
CRM_Mailing_BAO_Mailing::addMessageIdHeader($h, 's', $this->contact_id, $this->id, $this->hash);
$mailer = \Civi::service('pear_mail');
if (is_object($mailer)) {
$errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
$mailer->send($email, $h, $b);
unset($errorScope);
}
}
示例8: autoRespond
/**
* Send an automated response
*
* @param object $mailing The mailing object
* @param int $queue_id The queue ID
* @param string $replyto Optional reply-to from the reply
* @return void
* @access private
* @static
*/
private static function autoRespond(&$mailing, $queue_id, $replyto)
{
$config =& CRM_Core_Config::singleton();
$contacts = CRM_Contact_DAO_Contact::getTableName();
$email = CRM_Core_DAO_Email::getTableName();
$queue = CRM_Mailing_Event_DAO_Queue::getTableName();
$eq =& new CRM_Core_DAO();
$eq->query("SELECT {$contacts}.preferred_mail_format as format,\n {$email}.email as email\n FROM {$contacts}\n INNER JOIN {$queue} ON {$queue}.contact_id = {$contacts}.id\n INNER JOIN {$email} ON {$queue}.email_id = {$email}.id\n WHERE {$queue}.id = " . CRM_Utils_Type::escape($queue_id, 'Integer'));
$eq->fetch();
$to = empty($replyto) ? $eq->email : $replyto;
$component =& new CRM_Mailing_BAO_Component();
$component->id = $mailing->reply_id;
$component->find(true);
$message =& new Mail_Mime("\n");
require_once 'CRM/Core/BAO/Domain.php';
$domain =& CRM_Core_BAO_Domain::getDomain();
list($domainEmailName, $_) = CRM_Core_BAO_Domain::getNameAndEmail();
require_once 'CRM/Core/BAO/MailSettings.php';
$emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
$headers = array('Subject' => $component->subject, 'To' => $to, 'From' => "\"{$domainEmailName}\" <do-not-reply@{$emailDomain}>", 'Reply-To' => "do-not-reply@{$emailDomain}", 'Return-Path' => "do-not-reply@{$emailDomain}");
/* TODO: do we need reply tokens? */
$html = $component->body_html;
if ($component->body_text) {
$text = $component->body_text;
} else {
$text = CRM_Utils_String::htmlToText($component->body_html);
}
require_once 'CRM/Mailing/BAO/Mailing.php';
$bao =& new CRM_Mailing_BAO_Mailing();
$bao->body_text = $text;
$bao->body_html = $html;
$tokens = $bao->getTokens();
if ($eq->format == 'HTML' || $eq->format == 'Both') {
require_once 'CRM/Utils/Token.php';
$html = CRM_Utils_Token::replaceDomainTokens($html, $domain, true, $tokens['html']);
$html = CRM_Utils_Token::replaceMailingTokens($html, $mailing, null, $tokens['html']);
$message->setHTMLBody($html);
}
if (!$html || $eq->format == 'Text' || $eq->format == 'Both') {
require_once 'CRM/Utils/Token.php';
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, false, $tokens['text']);
$text = CRM_Utils_Token::replaceMailingTokens($text, $mailing, null, $tokens['text']);
$message->setTxtBody($text);
}
$b =& CRM_Utils_Mail::setMimeParams($message);
$h =& $message->headers($headers);
$mailer =& $config->getMailer();
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('CRM_Core_Error', 'nullHandler'));
if (is_object($mailer)) {
$mailer->send($to, $h, $b);
CRM_Core_Error::setCallback();
}
}
示例9: sendTemplate
/**
* Send an email from the specified template based on an array of params
*
* @param array $params a string-keyed array of function params, see function body for details
*
* @return array of four parameters: a boolean whether the email was sent, and the subject, text and HTML templates
*/
static function sendTemplate($params)
{
$defaults = array('groupName' => NULL, 'valueName' => NULL, 'messageTemplateID' => NULL, 'contactId' => NULL, 'tplParams' => array(), 'from' => NULL, 'toName' => NULL, 'toEmail' => NULL, 'cc' => NULL, 'bcc' => NULL, 'replyTo' => NULL, 'attachments' => NULL, 'isTest' => FALSE, 'PDFFilename' => NULL);
$params = array_merge($defaults, $params);
if ((!$params['groupName'] || !$params['valueName']) && !$params['messageTemplateID']) {
CRM_Core_Error::fatal(ts("Message template's option group and/or option value or ID missing."));
}
if ($params['messageTemplateID']) {
// fetch the three elements from the db based on id
$query = 'SELECT msg_subject subject, msg_text text, msg_html html, pdf_format_id format
FROM civicrm_msg_template mt
WHERE mt.id = %1 AND mt.is_default = 1';
$sqlParams = array(1 => array($params['messageTemplateID'], 'String'));
} else {
// fetch the three elements from the db based on option_group and option_value names
$query = 'SELECT msg_subject subject, msg_text text, msg_html html, pdf_format_id format
FROM civicrm_msg_template mt
JOIN civicrm_option_value ov ON workflow_id = ov.id
JOIN civicrm_option_group og ON ov.option_group_id = og.id
WHERE og.name = %1 AND ov.name = %2 AND mt.is_default = 1';
$sqlParams = array(1 => array($params['groupName'], 'String'), 2 => array($params['valueName'], 'String'));
}
$dao = CRM_Core_DAO::executeQuery($query, $sqlParams);
$dao->fetch();
if (!$dao->N) {
if ($params['messageTemplateID']) {
CRM_Core_Error::fatal(ts('No such message template: id=%1.', array(1 => $params['messageTemplateID'])));
} else {
CRM_Core_Error::fatal(ts('No such message template: option group %1, option value %2.', array(1 => $params['groupName'], 2 => $params['valueName'])));
}
}
$subject = $dao->subject;
$text = $dao->text;
$html = $dao->html;
$format = $dao->format;
$dao->free();
// add the test banner (if requested)
if ($params['isTest']) {
$query = "SELECT msg_subject subject, msg_text text, msg_html html\n FROM civicrm_msg_template mt\n JOIN civicrm_option_value ov ON workflow_id = ov.id\n JOIN civicrm_option_group og ON ov.option_group_id = og.id\n WHERE og.name = 'msg_tpl_workflow_meta' AND ov.name = 'test_preview' AND mt.is_default = 1";
$testDao = CRM_Core_DAO::executeQuery($query);
$testDao->fetch();
$subject = $testDao->subject . $subject;
$text = $testDao->text . $text;
$html = preg_replace('/<body(.*)$/im', "<body\\1\n{$testDao->html}", $html);
$testDao->free();
}
// replace tokens in the three elements (in subject as if it was the text body)
$domain = CRM_Core_BAO_Domain::getDomain();
$hookTokens = array();
$mailing = new CRM_Mailing_BAO_Mailing();
$mailing->body_text = $text;
$mailing->body_html = $html;
$tokens = $mailing->getTokens();
CRM_Utils_Hook::tokens($hookTokens);
$categories = array_keys($hookTokens);
$contactID = CRM_Utils_Array::value('contactId', $params);
if ($contactID) {
$contactParams = array('contact_id' => $contactID);
$returnProperties = array();
if (isset($tokens['text']['contact'])) {
foreach ($tokens['text']['contact'] as $name) {
$returnProperties[$name] = 1;
}
}
if (isset($tokens['html']['contact'])) {
foreach ($tokens['html']['contact'] as $name) {
$returnProperties[$name] = 1;
}
}
list($contact) = CRM_Utils_Token::getTokenDetails($contactParams, $returnProperties, FALSE, FALSE, NULL, CRM_Utils_Token::flattenTokens($tokens), 'CRM_Core_BAO_MessageTemplate');
$contact = $contact[$contactID];
}
$subject = CRM_Utils_Token::replaceDomainTokens($subject, $domain, TRUE, $tokens['text'], TRUE);
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, TRUE, $tokens['text'], TRUE);
$html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html'], TRUE);
if ($contactID) {
$subject = CRM_Utils_Token::replaceContactTokens($subject, $contact, FALSE, $tokens['text'], FALSE, TRUE);
$text = CRM_Utils_Token::replaceContactTokens($text, $contact, FALSE, $tokens['text'], FALSE, TRUE);
$html = CRM_Utils_Token::replaceContactTokens($html, $contact, FALSE, $tokens['html'], FALSE, TRUE);
$contactArray = array($contactID => $contact);
CRM_Utils_Hook::tokenValues($contactArray, array($contactID), NULL, CRM_Utils_Token::flattenTokens($tokens), 'CRM_Core_BAO_MessageTemplate');
$contact = $contactArray[$contactID];
$subject = CRM_Utils_Token::replaceHookTokens($subject, $contact, $categories, TRUE);
$text = CRM_Utils_Token::replaceHookTokens($text, $contact, $categories, TRUE);
$html = CRM_Utils_Token::replaceHookTokens($html, $contact, $categories, TRUE);
}
// strip whitespace from ends and turn into a single line
$subject = "{strip}{$subject}{/strip}";
// parse the three elements with Smarty
$smarty = CRM_Core_Smarty::singleton();
foreach ($params['tplParams'] as $name => $value) {
$smarty->assign($name, $value);
}
//.........这里部分代码省略.........
示例10: sendReminder
static function sendReminder($contactId, $email, $scheduleID, $from, $tokenParams)
{
$schedule = new CRM_Core_DAO_ActionSchedule();
$schedule->id = $scheduleID;
$domain = CRM_Core_BAO_Domain::getDomain();
$result = NULL;
$hookTokens = array();
if ($schedule->find(TRUE)) {
$body_text = $schedule->body_text;
$body_html = $schedule->body_html;
$body_subject = $schedule->subject;
if (!$body_text) {
$body_text = CRM_Utils_String::htmlToText($body_html);
}
$params = array(array('contact_id', '=', $contactId, 0, 0));
list($contact, $_) = CRM_Contact_BAO_Query::apiQuery($params);
//CRM-4524
$contact = reset($contact);
if (!$contact || is_a($contact, 'CRM_Core_Error')) {
return NULL;
}
// merge activity tokens with contact array
$contact = array_merge($contact, $tokenParams);
//CRM-5734
CRM_Utils_Hook::tokenValues($contact, $contactId);
CRM_Utils_Hook::tokens($hookTokens);
$categories = array_keys($hookTokens);
$type = array('html', 'text');
foreach ($type as $key => $value) {
$dummy_mail = new CRM_Mailing_BAO_Mailing();
$bodyType = "body_{$value}";
$dummy_mail->{$bodyType} = ${$bodyType};
$tokens = $dummy_mail->getTokens();
if (${$bodyType}) {
CRM_Utils_Token::replaceGreetingTokens(${$bodyType}, NULL, $contact['contact_id']);
${$bodyType} = CRM_Utils_Token::replaceDomainTokens(${$bodyType}, $domain, TRUE, $tokens[$value], TRUE);
${$bodyType} = CRM_Utils_Token::replaceContactTokens(${$bodyType}, $contact, FALSE, $tokens[$value], FALSE, TRUE);
${$bodyType} = CRM_Utils_Token::replaceComponentTokens(${$bodyType}, $contact, $tokens[$value], TRUE, FALSE);
${$bodyType} = CRM_Utils_Token::replaceHookTokens(${$bodyType}, $contact, $categories, TRUE);
}
}
$html = $body_html;
$text = $body_text;
$smarty = CRM_Core_Smarty::singleton();
foreach (array('text', 'html') as $elem) {
${$elem} = $smarty->fetch("string:{${$elem}}");
}
$matches = array();
preg_match_all('/(?<!\\{|\\\\)\\{(\\w+\\.\\w+)\\}(?!\\})/', $body_subject, $matches, PREG_PATTERN_ORDER);
$subjectToken = NULL;
if ($matches[1]) {
foreach ($matches[1] as $token) {
list($type, $name) = preg_split('/\\./', $token, 2);
if ($name) {
if (!isset($subjectToken['contact'])) {
$subjectToken['contact'] = array();
}
$subjectToken['contact'][] = $name;
}
}
}
$messageSubject = CRM_Utils_Token::replaceContactTokens($body_subject, $contact, FALSE, $subjectToken);
$messageSubject = CRM_Utils_Token::replaceDomainTokens($messageSubject, $domain, TRUE, $tokens[$value]);
$messageSubject = CRM_Utils_Token::replaceComponentTokens($messageSubject, $contact, $tokens[$value], TRUE);
$messageSubject = CRM_Utils_Token::replaceHookTokens($messageSubject, $contact, $categories, TRUE);
$messageSubject = $smarty->fetch("string:{$messageSubject}");
// set up the parameters for CRM_Utils_Mail::send
$mailParams = array('groupName' => 'Scheduled Reminder Sender', 'from' => $from, 'toName' => $contact['display_name'], 'toEmail' => $email, 'subject' => $messageSubject);
if (!$html || $contact['preferred_mail_format'] == 'Text' || $contact['preferred_mail_format'] == 'Both') {
// render the & entities in text mode, so that the links work
$mailParams['text'] = str_replace('&', '&', $text);
}
if ($html && ($contact['preferred_mail_format'] == 'HTML' || $contact['preferred_mail_format'] == 'Both')) {
$mailParams['html'] = $html;
}
$result = CRM_Utils_Mail::send($mailParams);
}
$schedule->free();
return $result;
}
示例11: dataRule
/**
* Function for validation
*
* @param array $params (ref.) an assoc array of name/value pairs
*
* @return mixed true or array of errors
* @access public
* @static
*/
function dataRule(&$params, &$files, &$options)
{
if (CRM_Utils_Array::value('_qf_Import_refresh', $_POST)) {
return true;
}
$errors = array();
require_once 'CRM/Core/BAO/Domain.php';
$domain =& CRM_Core_BAO_Domain::getCurrentDomain();
$mailing = null;
$session =& CRM_Core_Session::singleton();
$values = array('contact_id' => $session->get('userID'));
$contact = array();
$ids = array();
CRM_Contact_BAO_Contact::retrieve($values, $contact, $id);
$verp = array_flip(array('optOut', 'reply', 'unsubscribe', 'owner'));
foreach ($verp as $key => $value) {
$verp[$key]++;
}
$urls = array_flip(array('forward'));
foreach ($urls as $key => $value) {
$urls[$key]++;
}
require_once 'CRM/Mailing/BAO/Component.php';
$header =& new CRM_Mailing_BAO_Component();
$header->id = $params['header_id'];
$header->find(true);
$footer =& new CRM_Mailing_BAO_Component();
$footer->id = $params['footer_id'];
$footer->find(true);
list($headerBody['htmlFile'], $headerBody['textFile']) = array($header->body_html, $header->body_text);
list($footerBody['htmlFile'], $footerBody['textFile']) = array($footer->body_html, $footer->body_text);
require_once 'CRM/Utils/Token.php';
if (!file_exists($files['textFile']['tmp_name'])) {
$errors['textFile'] = ts('Please provide at least the text message.');
}
foreach (array('textFile', 'htmlFile') as $file) {
if (!file_exists($files[$file]['tmp_name'])) {
continue;
}
$str = file_get_contents($files[$file]['tmp_name']);
$name = $files[$file]['name'];
/* append header/footer */
$str = $headerBody[$file] . $str . $footerBody[$file];
$dataErrors = array();
/* First look for missing tokens */
$err = CRM_Utils_Token::requiredTokens($str);
if ($err !== true) {
foreach ($err as $token => $desc) {
$dataErrors[] = '<li>' . ts('Missing required token') . ' {' . $token . "}: {$desc}</li>";
}
}
/* Do a full token replacement on a dummy verp, the current contact
* and domain. */
$str = CRM_Utils_Token::replaceDomainTokens($str, $domain);
$str = CRM_Utils_Token::replaceMailingTokens($str, $mailing);
$str = CRM_Utils_Token::replaceActionTokens($str, $verp, $urls);
$str = CRM_Utils_Token::replaceContactTokens($str, $contact);
$unmatched = CRM_Utils_Token::unmatchedTokens($str);
if (!empty($unmatched)) {
foreach ($unmatched as $token) {
$dataErrors[] = '<li>' . ts('Invalid token code') . ' {' . $token . '}</li>';
}
}
if (!empty($dataErrors)) {
$errors[$file] = ts('The following errors were detected in %1:', array(1 => $name)) . ': <ul>' . implode('', $dataErrors) . '</ul>';
}
}
return empty($errors) ? true : $errors;
}
示例12: autoRespond
/**
* Send an automated response
*
* @param object $mailing The mailing object
* @param int $queue_id The queue ID
* @param string $replyto Optional reply-to from the reply
* @return void
* @access private
* @static
*/
function autoRespond(&$mailing, $queue_id, $replyto)
{
$config =& CRM_Core_Config::singleton();
$contacts = CRM_Contact_DAO_Contact::getTableName();
$email = CRM_Core_DAO_Email::getTableName();
$queue = CRM_Mailing_Event_DAO_Queue::getTableName();
$eq =& new CRM_Core_DAO();
$eq->query("SELECT {$contacts}.preferred_mail_format as format,\n {$email}.email as email\n FROM {$contacts}\n INNER JOIN {$queue} ON {$queue}.contact_id = {$contacts}.id\n INNER JOIN {$email} ON {$queue}.email_id = {$email}.id\n WHERE {$queue}.id = " . CRM_Utils_Type::escape($queue_id, 'Integer'));
$eq->fetch();
$to = empty($replyto) ? $eq->email : $replyto;
$component =& new CRM_Mailing_BAO_Component();
$component->id = $mailing->reply_id;
$component->find(true);
$message =& new Mail_Mime("\n");
require_once 'CRM/Core/BAO/Domain.php';
$domain =& CRM_Core_BAO_Domain::getDomainById($mailing->domain_id);
$headers = array('Subject' => $component->subject, 'To' => $to, 'From' => ts('"%1 Administrator" <%2>', array(1 => $domain->name, 2 => "do-not-reply@{$domain->email_domain}")), 'Reply-To' => "do-not-reply@{$domain->email_domain}", 'Return-Path' => "do-not-reply@{$domain->email_domain}");
/* TODO: do we need reply tokens? */
if ($eq->format == 'HTML' || $eq->format == 'Both') {
$html = $component->body_html;
require_once 'CRM/Utils/Token.php';
$html = CRM_Utils_Token::replaceDomainTokens($html, $domain, true);
$message->setHTMLBody($html);
}
if (!$html || $eq->format == 'Text' || $eq->format == 'Both') {
$text = $component->body_text;
require_once 'CRM/Utils/Token.php';
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, false);
$message->setTxtBody($text);
}
$b = $message->get();
$h = $message->headers($headers);
$mailer =& $config->getMailer();
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('CRM_Mailing_BAO_Mailing', 'catchSMTP'));
$mailer->send($to, $h, $b);
CRM_Core_Error::setCallback();
}
示例13: foreach
/**
* Compose a message
*
* @param int $job_id ID of the Job associated with this message
* @param int $event_queue_id ID of the EventQueue
* @param string $hash Hash of the EventQueue
* @param string $contactId ID of the Contact
* @param string $email Destination address
* @param string $recipient To: of the recipient
* @param boolean $test Is this mailing a test?
* @return object The mail object
* @access public
*/
function &compose($job_id, $event_queue_id, $hash, $contactId, $email, &$recipient, $test = false)
{
if ($test) {
$job_id = 'JOB';
$event_queue_id = 'QUEUE';
$hash = 'HASH';
}
if ($this->_domain == null) {
require_once 'CRM/Core/BAO/Domain.php';
$this->_domain =& CRM_Core_BAO_Domain::getDomainByID($this->domain_id);
}
/**
* Inbound VERP keys:
* reply: user replied to mailing
* bounce: email address bounced
* unsubscribe: contact opts out of all target lists for the mailing
* optOut: contact unsubscribes from the domain
*/
$config =& CRM_Core_Config::singleton();
foreach (array('reply', 'bounce', 'unsubscribe', 'optOut') as $key) {
$verp[$key] = implode($config->verpSeparator, array($key, $job_id, $event_queue_id, $hash)) . '@' . $this->_domain->email_domain;
}
$urls = array('forward' => CRM_Utils_System::url('civicrm/mailing/forward', "reset=1&jid={$job_id}&qid={$event_queue_id}&h={$hash}", true));
$headers = array('Reply-To' => CRM_Utils_Verp::encode($verp['reply'], $email), 'Return-Path' => CRM_Utils_Verp::encode($verp['bounce'], $email), 'From' => "\"{$this->from_name}\" <{$this->from_email}>", 'Subject' => $this->subject);
require_once 'CRM/Utils/Token.php';
if ($this->html == null || $this->text == null) {
$this->getHeaderFooter();
if ($this->body_html) {
$this->html = $this->header->body_html . '<br />' . $this->body_html . '<br />' . $this->footer->body_html;
$this->html = CRM_Utils_Token::replaceDomainTokens($this->html, $this->_domain, true);
$this->html = CRM_Utils_Token::replaceMailingTokens($this->html, $this, true);
}
$this->text = $this->header->body_text . "\n" . $this->body_text . "\n" . $this->footer->body_text;
$this->text = CRM_Utils_Token::replaceDomainTokens($this->text, $this->_domain, false);
$this->text = CRM_Utils_Token::replaceMailingTokens($this->text, $this, true);
}
$html = $this->html;
$text = $this->text;
if ($html && !$test && $this->url_tracking) {
CRM_Mailing_BAO_TrackableURL::scan_and_replace($html, $this->id, $event_queue_id);
CRM_Mailing_BAO_TrackableURL::scan_and_replace($text, $this->id, $event_queue_id);
}
$params = array('contact_id' => $contactId, 'id' => $contactId);
$contact = array();
$ids = array();
CRM_Contact_BAO_Contact::retrieve($params, $contact, $ids);
$message =& new Mail_Mime("\n");
/* Do contact-specific token replacement in text mode, and add to the
* message if necessary */
if ($test || !$html || $contact['preferred_mail_format'] == 'Text' || $contact['preferred_mail_format'] == 'Both') {
$text = CRM_Utils_Token::replaceContactTokens($text, $contact, false);
$text = CRM_Utils_Token::replaceActionTokens($text, $verp, $urls, false);
// render the & entities in text mode, so that the links work
$text = str_replace('&', '&', $text);
$message->setTxtBody($text);
}
/* Do contact-specific token replacement in html mode, and add to the
* message if necessary */
if ($html && ($test || $contact['preferred_mail_format'] == 'HTML' || $contact['preferred_mail_format'] == 'Both')) {
$html = CRM_Utils_Token::replaceContactTokens($html, $contact, true);
$html = CRM_Utils_Token::replaceActionTokens($html, $verp, $urls, true);
if ($this->open_tracking) {
$html .= '<img src="' . $config->userFrameworkResourceURL . "extern/open.php?q={$event_queue_id}\" width='1' height='1' alt='' border='0'>";
}
$message->setHTMLBody($html);
}
$recipient = "\"{$contact['display_name']}\" <{$email}>";
$headers['To'] = $recipient;
$mailMimeParams = array('text_encoding' => '8bit', 'html_encoding' => '8bit', 'head_charset' => 'utf-8', 'text_charset' => 'utf-8', 'html_charset' => 'utf-8');
$message->get($mailMimeParams);
$message->headers($headers);
return $message;
}
示例14: sendTemplate
/**
* Send an email from the specified template based on an array of params.
*
* @param array $params
* A string-keyed array of function params, see function body for details.
*
* @return array
* Array of four parameters: a boolean whether the email was sent, and the subject, text and HTML templates
*/
public static function sendTemplate($params)
{
$defaults = array('groupName' => NULL, 'valueName' => NULL, 'messageTemplateID' => NULL, 'contactId' => NULL, 'tplParams' => array(), 'from' => NULL, 'toName' => NULL, 'toEmail' => NULL, 'cc' => NULL, 'bcc' => NULL, 'replyTo' => NULL, 'attachments' => NULL, 'isTest' => FALSE, 'PDFFilename' => NULL);
$params = array_merge($defaults, $params);
CRM_Utils_Hook::alterMailParams($params, 'messageTemplate');
if ((!$params['groupName'] || !$params['valueName']) && !$params['messageTemplateID']) {
CRM_Core_Error::fatal(ts("Message template's option group and/or option value or ID missing."));
}
if ($params['messageTemplateID']) {
// fetch the three elements from the db based on id
$query = 'SELECT msg_subject subject, msg_text text, msg_html html, pdf_format_id format
FROM civicrm_msg_template mt
WHERE mt.id = %1 AND mt.is_default = 1';
$sqlParams = array(1 => array($params['messageTemplateID'], 'String'));
} else {
// fetch the three elements from the db based on option_group and option_value names
$query = 'SELECT msg_subject subject, msg_text text, msg_html html, pdf_format_id format
FROM civicrm_msg_template mt
JOIN civicrm_option_value ov ON workflow_id = ov.id
JOIN civicrm_option_group og ON ov.option_group_id = og.id
WHERE og.name = %1 AND ov.name = %2 AND mt.is_default = 1';
$sqlParams = array(1 => array($params['groupName'], 'String'), 2 => array($params['valueName'], 'String'));
}
$dao = CRM_Core_DAO::executeQuery($query, $sqlParams);
$dao->fetch();
if (!$dao->N) {
if ($params['messageTemplateID']) {
CRM_Core_Error::fatal(ts('No such message template: id=%1.', array(1 => $params['messageTemplateID'])));
} else {
CRM_Core_Error::fatal(ts('No such message template: option group %1, option value %2.', array(1 => $params['groupName'], 2 => $params['valueName'])));
}
}
$mailContent = array('subject' => $dao->subject, 'text' => $dao->text, 'html' => $dao->html, 'format' => $dao->format);
$dao->free();
CRM_Utils_Hook::alterMailContent($mailContent);
// add the test banner (if requested)
if ($params['isTest']) {
$query = "SELECT msg_subject subject, msg_text text, msg_html html\n FROM civicrm_msg_template mt\n JOIN civicrm_option_value ov ON workflow_id = ov.id\n JOIN civicrm_option_group og ON ov.option_group_id = og.id\n WHERE og.name = 'msg_tpl_workflow_meta' AND ov.name = 'test_preview' AND mt.is_default = 1";
$testDao = CRM_Core_DAO::executeQuery($query);
$testDao->fetch();
$mailContent['subject'] = $testDao->subject . $mailContent['subject'];
$mailContent['text'] = $testDao->text . $mailContent['text'];
$mailContent['html'] = preg_replace('/<body(.*)$/im', "<body\\1\n{$testDao->html}", $mailContent['html']);
$testDao->free();
}
// replace tokens in the three elements (in subject as if it was the text body)
$domain = CRM_Core_BAO_Domain::getDomain();
$hookTokens = array();
$mailing = new CRM_Mailing_BAO_Mailing();
$mailing->subject = $mailContent['subject'];
$mailing->body_text = $mailContent['text'];
$mailing->body_html = $mailContent['html'];
$tokens = $mailing->getTokens();
CRM_Utils_Hook::tokens($hookTokens);
$categories = array_keys($hookTokens);
$contactID = CRM_Utils_Array::value('contactId', $params);
if ($contactID) {
$contactParams = array('contact_id' => $contactID);
$returnProperties = array();
if (isset($tokens['subject']['contact'])) {
foreach ($tokens['subject']['contact'] as $name) {
$returnProperties[$name] = 1;
}
}
if (isset($tokens['text']['contact'])) {
foreach ($tokens['text']['contact'] as $name) {
$returnProperties[$name] = 1;
}
}
if (isset($tokens['html']['contact'])) {
foreach ($tokens['html']['contact'] as $name) {
$returnProperties[$name] = 1;
}
}
// @todo CRM-17253 don't resolve contact details if there are no tokens
// effectively comment out this next (performance-expensive) line
// but unfortunately testing is a bit think on the ground to that needs to
// be added.
list($contact) = CRM_Utils_Token::getTokenDetails($contactParams, $returnProperties, FALSE, FALSE, NULL, CRM_Utils_Token::flattenTokens($tokens), 'CRM_Core_BAO_MessageTemplate');
$contact = $contact[$contactID];
}
$mailContent['subject'] = CRM_Utils_Token::replaceDomainTokens($mailContent['subject'], $domain, FALSE, $tokens['text'], TRUE);
$mailContent['text'] = CRM_Utils_Token::replaceDomainTokens($mailContent['text'], $domain, FALSE, $tokens['text'], TRUE);
$mailContent['html'] = CRM_Utils_Token::replaceDomainTokens($mailContent['html'], $domain, TRUE, $tokens['html'], TRUE);
if ($contactID) {
$mailContent['subject'] = CRM_Utils_Token::replaceContactTokens($mailContent['subject'], $contact, FALSE, $tokens['text'], FALSE, TRUE);
$mailContent['text'] = CRM_Utils_Token::replaceContactTokens($mailContent['text'], $contact, FALSE, $tokens['text'], FALSE, TRUE);
$mailContent['html'] = CRM_Utils_Token::replaceContactTokens($mailContent['html'], $contact, FALSE, $tokens['html'], FALSE, TRUE);
$contactArray = array($contactID => $contact);
CRM_Utils_Hook::tokenValues($contactArray, array($contactID), NULL, CRM_Utils_Token::flattenTokens($tokens), 'CRM_Core_BAO_MessageTemplate');
$contact = $contactArray[$contactID];
//.........这里部分代码省略.........
示例15: tokenReplace
/**
*
* get mailing object and replaces subscribeInvite,
* domain and mailing tokens
*
*/
function tokenReplace(&$mailing)
{
require_once 'CRM/Core/BAO/Domain.php';
$domain =& CRM_Core_BAO_Domain::getDomain();
foreach (array('text', 'html') as $type) {
require_once 'CRM/Utils/Token.php';
$tokens = $mailing->getTokens();
if (isset($mailing->templates[$type])) {
$mailing->templates[$type] = CRM_Utils_Token::replaceSubscribeInviteTokens($mailing->templates[$type]);
$mailing->templates[$type] = CRM_Utils_Token::replaceDomainTokens($mailing->templates[$type], $domain, $type == 'html' ? true : false, $tokens[$type]);
$mailing->templates[$type] = CRM_Utils_Token::replaceMailingTokens($mailing->templates[$type], $mailing, null, $tokens[$type]);
}
}
}