本文整理汇总了PHP中CRM_Mailing_BAO_Mailing::tokenReplace方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Mailing_BAO_Mailing::tokenReplace方法的具体用法?PHP CRM_Mailing_BAO_Mailing::tokenReplace怎么用?PHP CRM_Mailing_BAO_Mailing::tokenReplace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Mailing_BAO_Mailing
的用法示例。
在下文中一共展示了CRM_Mailing_BAO_Mailing::tokenReplace方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* run this page (figure out the action needed and perform it).
*
* @return void
*/
function run()
{
require_once 'CRM/Mailing/BAO/Mailing.php';
$session =& CRM_Core_Session::singleton();
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject, false, 'text');
$type = CRM_Utils_Request::retrieve('type', 'String', CRM_Core_DAO::$_nullObject, false, 'text');
$options = array();
$session->getVars($options, "CRM_Mailing_Controller_Send_{$qfKey}");
//get the options if control come from search context, CRM-3711
if (empty($options)) {
$session->getVars($options, "CRM_Contact_Controller_Search_{$qfKey}");
}
// FIXME: the below and CRM_Mailing_Form_Test::testMail()
// should be refactored
$fromEmail = null;
$mailing =& new CRM_Mailing_BAO_Mailing();
if (!empty($options)) {
$mailing->id = $options['mailing_id'];
$fromEmail = $options['from_email'];
}
$mailing->find(true);
CRM_Mailing_BAO_Mailing::tokenReplace($mailing);
if (defined('CIVICRM_MAIL_SMARTY')) {
require_once 'CRM/Core/Smarty/resources/String.php';
civicrm_smarty_register_string_resource();
}
// get and format attachments
require_once 'CRM/Core/BAO/File.php';
$attachments =& CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id);
//get details of contact with token value including Custom Field Token Values.CRM-3734
$returnProperties = $mailing->getReturnProperties();
$params = array('contact_id' => $session->get('userID'));
$details = $mailing->getDetails($params, $returnProperties);
$mime =& $mailing->compose(null, null, null, $session->get('userID'), $fromEmail, $fromEmail, true, $details[0][$session->get('userID')], $attachments);
// there doesn't seem to be a way to get to Mail_Mime's text and HTML
// parts, so we steal a peek at Mail_Mime's private properties, render
// them and exit
// note that preview does not display any attachments
$mime->get();
if ($type == 'html') {
header('Content-Type: text/html; charset=utf-8');
print $mime->_htmlbody;
} else {
header('Content-Type: text/plain; charset=utf-8');
print $mime->_txtbody;
}
exit;
}
示例2: run
/**
* Run this page (figure out the action needed and perform it).
*
* @return void
*/
public function run()
{
$session = CRM_Core_Session::singleton();
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject, FALSE, 'text');
$type = CRM_Utils_Request::retrieve('type', 'String', CRM_Core_DAO::$_nullObject, FALSE, 'text');
$options = array();
$session->getVars($options, "CRM_Mailing_Controller_Send_{$qfKey}");
//get the options if control come from search context, CRM-3711
if (empty($options)) {
$session->getVars($options, "CRM_Contact_Controller_Search_{$qfKey}");
}
// FIXME: the below and CRM_Mailing_Form_Test::testMail()
// should be refactored
$fromEmail = NULL;
$mailing = new CRM_Mailing_BAO_Mailing();
if (!empty($options)) {
$mailing->id = $options['mailing_id'];
$fromEmail = CRM_Utils_Array::value('from_email', $options);
}
$mailing->find(TRUE);
CRM_Mailing_BAO_Mailing::tokenReplace($mailing);
// get and format attachments
$attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id);
//get details of contact with token value including Custom Field Token Values.CRM-3734
$returnProperties = $mailing->getReturnProperties();
$params = array('contact_id' => $session->get('userID'));
$details = CRM_Utils_Token::getTokenDetails($params, $returnProperties, TRUE, TRUE, NULL, $mailing->getFlattenedTokens(), get_class($this));
$mime =& $mailing->compose(NULL, NULL, NULL, $session->get('userID'), $fromEmail, $fromEmail, TRUE, $details[0][$session->get('userID')], $attachments);
if ($type == 'html') {
CRM_Utils_System::setHttpHeader('Content-Type', 'text/html; charset=utf-8');
print $mime->getHTMLBody();
} else {
CRM_Utils_System::setHttpHeader('Content-Type', 'text/plain; charset=utf-8');
print $mime->getTXTBody();
}
CRM_Utils_System::civiExit();
}
示例3: deliver
/**
* Send the mailing.
*
* @param object $mailer
* A Mail object to send the messages.
*
* @param array $testParams
*
* @return void
*/
public function deliver(&$mailer, $testParams = NULL)
{
$mailing = new CRM_Mailing_BAO_Mailing();
$mailing->id = $this->mailing_id;
$mailing->find(TRUE);
$mailing->free();
$eq = new CRM_Mailing_Event_BAO_Queue();
$eqTable = CRM_Mailing_Event_BAO_Queue::getTableName();
$emailTable = CRM_Core_BAO_Email::getTableName();
$phoneTable = CRM_Core_DAO_Phone::getTableName();
$contactTable = CRM_Contact_BAO_Contact::getTableName();
$edTable = CRM_Mailing_Event_BAO_Delivered::getTableName();
$ebTable = CRM_Mailing_Event_BAO_Bounce::getTableName();
$query = " SELECT {$eqTable}.id,\n {$emailTable}.email as email,\n {$eqTable}.contact_id,\n {$eqTable}.hash,\n NULL as phone\n FROM {$eqTable}\n INNER JOIN {$emailTable}\n ON {$eqTable}.email_id = {$emailTable}.id\n INNER JOIN {$contactTable}\n ON {$contactTable}.id = {$emailTable}.contact_id\n LEFT JOIN {$edTable}\n ON {$eqTable}.id = {$edTable}.event_queue_id\n LEFT JOIN {$ebTable}\n ON {$eqTable}.id = {$ebTable}.event_queue_id\n WHERE {$eqTable}.job_id = " . $this->id . "\n AND {$edTable}.id IS null\n AND {$ebTable}.id IS null\n AND {$contactTable}.is_opt_out = 0";
if ($mailing->sms_provider_id) {
$query = "\n SELECT {$eqTable}.id,\n {$phoneTable}.phone as phone,\n {$eqTable}.contact_id,\n {$eqTable}.hash,\n NULL as email\n FROM {$eqTable}\n INNER JOIN {$phoneTable}\n ON {$eqTable}.phone_id = {$phoneTable}.id\n INNER JOIN {$contactTable}\n ON {$contactTable}.id = {$phoneTable}.contact_id\n LEFT JOIN {$edTable}\n ON {$eqTable}.id = {$edTable}.event_queue_id\n LEFT JOIN {$ebTable}\n ON {$eqTable}.id = {$ebTable}.event_queue_id\n WHERE {$eqTable}.job_id = " . $this->id . "\n AND {$edTable}.id IS null\n AND {$ebTable}.id IS null\n AND ( {$contactTable}.is_opt_out = 0\n OR {$contactTable}.do_not_sms = 0 )";
}
$eq->query($query);
$config = NULL;
if ($config == NULL) {
$config = CRM_Core_Config::singleton();
}
$job_date = CRM_Utils_Date::isoToMysql($this->scheduled_date);
$fields = array();
if (!empty($testParams)) {
$mailing->subject = ts('[CiviMail Draft]') . ' ' . $mailing->subject;
}
CRM_Mailing_BAO_Mailing::tokenReplace($mailing);
// get and format attachments
$attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id);
if (defined('CIVICRM_MAIL_SMARTY') && CIVICRM_MAIL_SMARTY) {
CRM_Core_Smarty::registerStringResource();
}
// CRM-12376
// This handles the edge case scenario where all the mails
// have been delivered in prior jobs
$isDelivered = TRUE;
// make sure that there's no more than $config->mailerBatchLimit mails processed in a run
while ($eq->fetch()) {
// if ( ( $mailsProcessed % 100 ) == 0 ) {
// CRM_Utils_System::xMemory( "$mailsProcessed: " );
// }
if ($config->mailerBatchLimit > 0 && self::$mailsProcessed >= $config->mailerBatchLimit) {
if (!empty($fields)) {
$this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments);
}
$eq->free();
return FALSE;
}
self::$mailsProcessed++;
$fields[] = array('id' => $eq->id, 'hash' => $eq->hash, 'contact_id' => $eq->contact_id, 'email' => $eq->email, 'phone' => $eq->phone);
if (count($fields) == self::MAX_CONTACTS_TO_PROCESS) {
$isDelivered = $this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments);
if (!$isDelivered) {
$eq->free();
return $isDelivered;
}
$fields = array();
}
}
$eq->free();
if (!empty($fields)) {
$isDelivered = $this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments);
}
return $isDelivered;
}
示例4: civicrm_api3_mailing_preview
/**
* Preview mailing.
*
* @param array $params
* Array per getfields metadata.
*
* @return array
* @throws \API_Exception
*/
function civicrm_api3_mailing_preview($params)
{
civicrm_api3_verify_mandatory($params, 'CRM_Mailing_DAO_Mailing', array('id'), FALSE);
$fromEmail = NULL;
if (!empty($params['from_email'])) {
$fromEmail = $params['from_email'];
}
$session = CRM_Core_Session::singleton();
$mailing = new CRM_Mailing_BAO_Mailing();
$mailing->id = $params['id'];
$mailing->find(TRUE);
CRM_Mailing_BAO_Mailing::tokenReplace($mailing);
// get and format attachments
$attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id);
$returnProperties = $mailing->getReturnProperties();
$contactID = CRM_Utils_Array::value('contact_id', $params);
if (!$contactID) {
$contactID = $session->get('userID');
}
$mailingParams = array('contact_id' => $contactID);
$details = CRM_Utils_Token::getTokenDetails($mailingParams, $returnProperties, TRUE, TRUE, NULL, $mailing->getFlattenedTokens());
$mime =& $mailing->compose(NULL, NULL, NULL, $session->get('userID'), $fromEmail, $fromEmail, TRUE, $details[0][$contactID], $attachments);
return civicrm_api3_create_success(array('id' => $params['id'], 'contact_id' => $contactID, 'subject' => $mime->_headers['Subject'], 'body_html' => $mime->getHTMLBody(), 'body_text' => $mime->getTXTBody()));
}
示例5: run
/**
* run this page (figure out the action needed and perform it).
*
* @return void
*/
function run($id = NULL, $contact_id = NULL, $print = TRUE)
{
if (is_numeric($id)) {
$this->_mailingID = $id;
} else {
$print = TRUE;
$this->_mailingID = CRM_Utils_Request::retrieve('id', 'Integer', CRM_Core_DAO::$_nullObject, TRUE);
}
// # CRM-7651
// override contactID from the function level if passed in
if (isset($contactID) && is_numeric($contactID)) {
$this->_contactID = $contactID;
} else {
$session = CRM_Core_Session::singleton();
$this->_contactID = $session->get('userID');
}
$this->_mailing = new CRM_Mailing_BAO_Mailing();
$this->_mailing->id = $this->_mailingID;
if (!$this->_mailing->find(TRUE) || !$this->checkPermission()) {
CRM_Utils_System::permissionDenied();
return;
}
CRM_Mailing_BAO_Mailing::tokenReplace($this->_mailing);
// get and format attachments
$attachments =& CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $this->_mailing->id);
// get contact detail and compose if contact id exists
if (isset($this->_contactID)) {
//get details of contact with token value including Custom Field Token Values.CRM-3734
$returnProperties = $this->_mailing->getReturnProperties();
$params = array('contact_id' => $this->_contactID);
$details = CRM_Utils_Token::getTokenDetails($params, $returnProperties, TRUE, TRUE, NULL, $this->_mailing->getFlattenedTokens(), get_class($this));
$details = $details[0][$this->_contactID];
} else {
$details = array('test');
}
$mime =& $this->_mailing->compose(NULL, NULL, NULL, 0, $this->_mailing->from_email, $this->_mailing->from_email, TRUE, $details, $attachments);
if (isset($this->_mailing->body_html)) {
$header = 'Content-Type: text/html; charset=utf-8';
$content = $mime->getHTMLBody();
} else {
$header = 'Content-Type: text/plain; charset=utf-8';
$content = $mime->getTXTBody();
}
if ($print) {
header($header);
print $content;
CRM_Utils_System::civiExit();
} else {
return $content;
}
}
示例6: run
/**
* Run this page (figure out the action needed and perform it).
*
* @param int $id
* @param int $contactID
* @param bool $print
* @param bool $allowID
*/
public function run($id = NULL, $contactID = NULL, $print = TRUE, $allowID = FALSE)
{
if (is_numeric($id)) {
$this->_mailingID = $id;
} else {
$print = TRUE;
$this->_mailingID = CRM_Utils_Request::retrieve('id', 'String', CRM_Core_DAO::$_nullObject, TRUE);
}
// # CRM-7651
// override contactID from the function level if passed in
if (isset($contactID) && is_numeric($contactID)) {
$this->_contactID = $contactID;
} else {
$session = CRM_Core_Session::singleton();
$this->_contactID = $session->get('userID');
}
// mailing key check
if (Civi::settings()->get('hash_mailing_url')) {
$this->_mailing = new CRM_Mailing_BAO_Mailing();
if (!is_numeric($this->_mailingID)) {
$this->_mailing->hash = $this->_mailingID;
} elseif (is_numeric($this->_mailingID)) {
$this->_mailing->id = $this->_mailingID;
// if mailing is present and associated hash is present
// while 'hash' is not been used for mailing view : throw 'permissionDenied'
if ($this->_mailing->find() && CRM_Core_DAO::getFieldValue('CRM_Mailing_BAO_Mailing', $this->_mailingID, 'hash', 'id') && !$allowID) {
CRM_Utils_System::permissionDenied();
return;
}
}
} else {
$this->_mailing = new CRM_Mailing_BAO_Mailing();
$this->_mailing->id = $this->_mailingID;
}
if (!$this->_mailing->find(TRUE) || !$this->checkPermission()) {
CRM_Utils_System::permissionDenied();
return;
}
CRM_Mailing_BAO_Mailing::tokenReplace($this->_mailing);
// get and format attachments
$attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $this->_mailing->id);
// get contact detail and compose if contact id exists
$returnProperties = $this->_mailing->getReturnProperties();
if (isset($this->_contactID)) {
// get details of contact with token value including Custom Field Token Values.CRM-3734
$params = array('contact_id' => $this->_contactID);
$details = CRM_Utils_Token::getTokenDetails($params, $returnProperties, FALSE, TRUE, NULL, $this->_mailing->getFlattenedTokens(), get_class($this));
$details = $details[0][$this->_contactID];
$contactId = $this->_contactID;
} else {
// get tokens that are not contact specific resolved
$params = array('contact_id' => 0);
$details = CRM_Utils_Token::getAnonymousTokenDetails($params, $returnProperties, TRUE, TRUE, NULL, $this->_mailing->getFlattenedTokens(), get_class($this));
$details = CRM_Utils_Array::value(0, $details[0]);
$contactId = 0;
}
$mime =& $this->_mailing->compose(NULL, NULL, NULL, $contactId, $this->_mailing->from_email, $this->_mailing->from_email, TRUE, $details, $attachments);
$title = NULL;
if (isset($this->_mailing->body_html) && empty($_GET['text'])) {
$header = 'text/html; charset=utf-8';
$content = $mime->getHTMLBody();
if (strpos($content, '<head>') === FALSE && strpos($content, '<title>') === FALSE) {
$title = '<head><title>' . $this->_mailing->subject . '</title></head>';
}
} else {
$header = 'text/plain; charset=utf-8';
$content = $mime->getTXTBody();
}
CRM_Utils_System::setTitle($this->_mailing->subject);
if (CRM_Utils_Array::value('snippet', $_GET) === 'json') {
CRM_Core_Page_AJAX::returnJsonResponse($content);
}
if ($print) {
CRM_Utils_System::setHttpHeader('Content-Type', $header);
print $title;
print $content;
CRM_Utils_System::civiExit();
} else {
return $content;
}
}
示例7: deliver
/**
* Send the mailing
*
* @param object $mailer A Mail object to send the messages
* @return void
* @access public
*/
public function deliver(&$mailer, $testParams = null)
{
require_once 'CRM/Mailing/BAO/Mailing.php';
$mailing =& new CRM_Mailing_BAO_Mailing();
$mailing->id = $this->mailing_id;
$mailing->find(true);
$eq =& new CRM_Mailing_Event_BAO_Queue();
$eqTable = CRM_Mailing_Event_BAO_Queue::getTableName();
$emailTable = CRM_Core_BAO_Email::getTableName();
$contactTable = CRM_Contact_BAO_Contact::getTableName();
$edTable = CRM_Mailing_Event_BAO_Delivered::getTableName();
$ebTable = CRM_Mailing_Event_BAO_Bounce::getTableName();
$query = " SELECT {$eqTable}.id,\n {$emailTable}.email as email,\n {$eqTable}.contact_id,\n {$eqTable}.hash\n FROM {$eqTable}\n INNER JOIN {$emailTable}\n ON {$eqTable}.email_id = {$emailTable}.id\n LEFT JOIN {$edTable}\n ON {$eqTable}.id = {$edTable}.event_queue_id\n LEFT JOIN {$ebTable}\n ON {$eqTable}.id = {$ebTable}.event_queue_id\n WHERE {$eqTable}.job_id = " . $this->id . "\n AND {$edTable}.id IS null\n AND {$ebTable}.id IS null";
$eq->query($query);
static $config = null;
$mailsProcessed = 0;
if ($config == null) {
$config =& CRM_Core_Config::singleton();
}
$job_date = CRM_Utils_Date::isoToMysql($this->scheduled_date);
$fields = array();
if (!empty($testParams)) {
$mailing->from_name = ts('CiviCRM Test Mailer (%1)', array(1 => $mailing->from_name));
$mailing->subject = ts('Test Mailing:') . ' ' . $mailing->subject;
}
CRM_Mailing_BAO_Mailing::tokenReplace($mailing);
// get and format attachments
require_once 'CRM/Core/BAO/File.php';
$attachments =& CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id);
if (defined('CIVICRM_MAIL_SMARTY')) {
require_once 'CRM/Core/Smarty/resources/String.php';
civicrm_smarty_register_string_resource();
}
// make sure that there's no more than $config->mailerBatchLimit mails processed in a run
while ($eq->fetch()) {
// if ( ( $mailsProcessed % 100 ) == 0 ) {
// CRM_Utils_System::xMemory( "$mailsProcessed: " );
// }
if ($config->mailerBatchLimit > 0 && $mailsProcessed >= $config->mailerBatchLimit) {
$this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments);
return false;
}
$mailsProcessed++;
$fields[] = array('id' => $eq->id, 'hash' => $eq->hash, 'contact_id' => $eq->contact_id, 'email' => $eq->email);
if (count($fields) == self::MAX_CONTACTS_TO_PROCESS) {
$isDelivered = $this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments);
if (!$isDelivered) {
return $isDelivered;
}
$fields = array();
}
}
$isDelivered = $this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments);
return $isDelivered;
}
示例8: run
/**
* run this page (figure out the action needed and perform it).
*
* @return void
*/
function run($id = null, $print = true)
{
if (is_numeric($id)) {
$this->_mailingID = $id;
} else {
$print = true;
$this->_mailingID = CRM_Utils_Request::retrieve('id', 'Integer', CRM_Core_DAO::$_nullObject, true);
}
$session =& CRM_Core_Session::singleton();
$this->_contactID = $session->get('userID');
require_once 'CRM/Mailing/BAO/Mailing.php';
$this->_mailing = new CRM_Mailing_BAO_Mailing();
$this->_mailing->id = $this->_mailingID;
require_once 'CRM/Core/Error.php';
if (!$this->_mailing->find(true)) {
CRM_Core_Error::statusBounce(ts('You do not have the necessary permission to approve this mailing.'));
}
CRM_Mailing_BAO_Mailing::tokenReplace($this->_mailing);
if (defined('CIVICRM_MAIL_SMARTY')) {
require_once 'CRM/Core/Smarty/resources/String.php';
civicrm_smarty_register_string_resource();
}
// get and format attachments
require_once 'CRM/Core/BAO/File.php';
$attachments =& CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $this->_mailing->id);
//get details of contact with token value including Custom Field Token Values.CRM-3734
$returnProperties = $this->_mailing->getReturnProperties();
$params = array('contact_id' => $this->_contactID);
$details = $this->_mailing->getDetails($params, $returnProperties);
$mime =& $this->_mailing->compose(null, null, null, $this->_contactID, $fromEmail, $fromEmail, true, $details[0][$this->_contactID], $attachments);
if (isset($this->_mailing->body_html)) {
$header = 'Content-Type: text/html; charset=utf-8';
$content = $mime->getHTMLBody();
} else {
$header = 'Content-Type: text/plain; charset=utf-8';
$content = $mime->getTXTBody();
}
if ($print) {
header($header);
print $content;
CRM_Utils_System::civiExit();
} else {
return $content;
}
}