本文整理汇总了PHP中CRM_Utils_Token::replaceSubscribeInviteTokens方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_Token::replaceSubscribeInviteTokens方法的具体用法?PHP CRM_Utils_Token::replaceSubscribeInviteTokens怎么用?PHP CRM_Utils_Token::replaceSubscribeInviteTokens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Utils_Token
的用法示例。
在下文中一共展示了CRM_Utils_Token::replaceSubscribeInviteTokens方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: formRule
//.........这里部分代码省略.........
$verp = array_flip(array('optOut', 'reply', 'unsubscribe', 'resubscribe', 'owner'));
foreach ($verp as $key => $value) {
$verp[$key]++;
}
$urls = array_flip(array('forward', 'optOutUrl', 'unsubscribeUrl', 'resubscribeUrl'));
foreach ($urls as $key => $value) {
$urls[$key]++;
}
// set $header and $footer
foreach (array('header', 'footer') as $part) {
${$part} = array();
if ($params["{$part}_id"]) {
//echo "found<p>";
$component = new CRM_Mailing_BAO_Component();
$component->id = $params["{$part}_id"];
$component->find(TRUE);
${$part}['textFile'] = $component->body_text;
${$part}['htmlFile'] = $component->body_html;
$component->free();
} else {
${$part}['htmlFile'] = ${$part}['textFile'] = '';
}
}
$skipTextFile = $self->get('skipTextFile');
$skipHtmlFile = $self->get('skipHtmlFile');
if (!$params['upload_type']) {
if ((!isset($files['textFile']) || !file_exists($files['textFile']['tmp_name'])) && (!isset($files['htmlFile']) || !file_exists($files['htmlFile']['tmp_name']))) {
if (!($skipTextFile || $skipHtmlFile)) {
$errors['textFile'] = ts('Please provide either a Text or HTML formatted message - or both.');
}
}
} else {
if (empty($params['text_message']) && empty($params['html_message'])) {
$errors['html_message'] = ts('Please provide either a Text or HTML formatted message - or both.');
}
if (!empty($params['saveTemplate']) && empty($params['saveTemplateName'])) {
$errors['saveTemplateName'] = ts('Please provide a Template Name.');
}
}
foreach (array('text', 'html') as $file) {
if (!$params['upload_type'] && !file_exists(CRM_Utils_Array::value('tmp_name', $files[$file . 'File']))) {
continue;
}
if ($params['upload_type'] && !$params[$file . '_message']) {
continue;
}
if (!$params['upload_type']) {
$str = file_get_contents($files[$file . 'File']['tmp_name']);
$name = $files[$file . 'File']['name'];
} else {
$str = $params[$file . '_message'];
$str = $file == 'html' ? str_replace('%7B', '{', str_replace('%7D', '}', $str)) : $str;
$name = $file . ' message';
}
/* append header/footer */
$str = $header[$file . 'File'] . $str . $footer[$file . 'File'];
$dataErrors = array();
/* First look for missing tokens */
if (!CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'disable_mandatory_tokens_check')) {
$err = CRM_Utils_Token::requiredTokens($str);
if ($err !== TRUE) {
foreach ($err as $token => $desc) {
$dataErrors[] = '<li>' . ts('This message is missing a required token - {%1}: %2', array(1 => $token, 2 => $desc)) . '</li>';
}
}
}
/* Do a full token replacement on a dummy verp, the current
* contact and domain, and the first organization. */
// here we make a dummy mailing object so that we
// can retrieve the tokens that we need to replace
// so that we do get an invalid token error
// this is qute hacky and I hope that there might
// be a suggestion from someone on how to
// make it a bit more elegant
$dummy_mail = new CRM_Mailing_BAO_Mailing();
$mess = "body_{$file}";
$dummy_mail->{$mess} = $str;
$tokens = $dummy_mail->getTokens();
$str = CRM_Utils_Token::replaceSubscribeInviteTokens($str);
$str = CRM_Utils_Token::replaceDomainTokens($str, $domain, NULL, $tokens[$file]);
$str = CRM_Utils_Token::replaceMailingTokens($str, $mailing, NULL, $tokens[$file]);
$str = CRM_Utils_Token::replaceOrgTokens($str, $org);
$str = CRM_Utils_Token::replaceActionTokens($str, $verp, $urls, NULL, $tokens[$file]);
$str = CRM_Utils_Token::replaceContactTokens($str, $contact, NULL, $tokens[$file]);
$unmatched = CRM_Utils_Token::unmatchedTokens($str);
if (!empty($unmatched) && 0) {
foreach ($unmatched as $token) {
$dataErrors[] = '<li>' . ts('Invalid token code') . ' {' . $token . '}</li>';
}
}
if (!empty($dataErrors)) {
$errors[$file . 'File'] = ts('The following errors were detected in %1:', array(1 => $name)) . ' <ul>' . implode('', $dataErrors) . '</ul><br /><a href="' . CRM_Utils_System::docURL2('Sample CiviMail Messages', TRUE, NULL, NULL, NULL, "wiki") . '" target="_blank">' . ts('More information on required tokens...') . '</a>';
}
}
$templateName = CRM_Core_BAO_MessageTemplate::getMessageTemplates();
if (!empty($params['saveTemplate']) && in_array(CRM_Utils_Array::value('saveTemplateName', $params), $templateName)) {
$errors['saveTemplate'] = ts('Duplicate Template Name.');
}
return empty($errors) ? TRUE : $errors;
}
示例2: 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]);
}
}
}
示例3: formRule
//.........这里部分代码省略.........
$checkMailings = array();
$checkMailings = array_intersect($fields['includeMailings'], $fields['excludeMailings']);
if (!empty($checkMailings)) {
$errors['excludeMailings'] = ts('Cannot have same mail in Include mailing(s) and Exclude mailing(s).');
}
}
if (!empty($fields['search_id']) && empty($fields['group_id'])) {
$errors['group_id'] = ts('You must select a group to filter on');
}
if (empty($fields['search_id']) && !empty($fields['group_id'])) {
$errors['search_id'] = ts('You must select a search to filter');
}
// End
// Validate message template html/text
// Start
$errors = array();
$template = CRM_Core_Smarty::singleton();
if (isset($fields['html_message'])) {
$htmlMessage = str_replace(array("\n", "\r"), ' ', $fields['html_message']);
$htmlMessage = str_replace("'", "\\'", $htmlMessage);
$template->assign('htmlContent', $htmlMessage);
}
$domain = CRM_Core_BAO_Domain::getDomain();
$session = CRM_Core_Session::singleton();
$values = array('contact_id' => $session->get('userID'), 'version' => 3);
require_once 'api/api.php';
$contact = civicrm_api('contact', 'get', $values);
//CRM-4524
$contact = reset($contact['values']);
$verp = array_flip(array('optOut', 'reply', 'unsubscribe', 'resubscribe', 'owner'));
foreach ($verp as $key => $value) {
$verp[$key]++;
}
$urls = array_flip(array('forward', 'optOutUrl', 'unsubscribeUrl', 'resubscribeUrl'));
foreach ($urls as $key => $value) {
$urls[$key]++;
}
// set $header and $footer
foreach (array('header', 'footer') as $part) {
${$part} = array();
if ($fields["{$part}_id"]) {
//echo "found<p>";
$component = new CRM_Mailing_BAO_Component();
$component->id = $fields["{$part}_id"];
$component->find(TRUE);
${$part}['textFile'] = $component->body_text;
${$part}['htmlFile'] = $component->body_html;
$component->free();
} else {
${$part}['htmlFile'] = ${$part}['textFile'] = '';
}
}
if (!CRM_Utils_Array::value('text_message', $fields) && !CRM_Utils_Array::value('html_message', $fields)) {
$errors['html_message'] = ts('Please provide either a Text or HTML formatted message - or both.');
}
foreach (array('text', 'html') as $file) {
$str = $fields[$file . '_message'];
$str = $file == 'html' ? str_replace('%7B', '{', str_replace('%7D', '}', $str)) : $str;
$name = $file . ' message';
/* append header/footer */
$str = $header[$file . 'File'] . $str . $footer[$file . '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('This message is missing a required token - {%1}: %2', array(1 => $token, 2 => $desc)) . '</li>';
}
}
/* Do a full token replacement on a dummy verp, the current
* contact and domain, and the first organization. */
// here we make a dummy mailing object so that we
// can retrieve the tokens that we need to replace
// so that we do get an invalid token error
// this is qute hacky and I hope that there might
// be a suggestion from someone on how to
// make it a bit more elegant
$dummy_mail = new CRM_Mailing_BAO_Mailing();
$mess = "body_{$file}";
$dummy_mail->{$mess} = $str;
$tokens = $dummy_mail->getTokens();
$str = CRM_Utils_Token::replaceSubscribeInviteTokens($str);
$str = CRM_Utils_Token::replaceDomainTokens($str, $domain, NULL, $tokens[$file]);
$str = CRM_Utils_Token::replaceMailingTokens($str, $mailing, NULL, $tokens[$file]);
$str = CRM_Utils_Token::replaceOrgTokens($str, $org);
$str = CRM_Utils_Token::replaceActionTokens($str, $verp, $urls, NULL, $tokens[$file]);
$str = CRM_Utils_Token::replaceContactTokens($str, $contact, NULL, $tokens[$file]);
$unmatched = CRM_Utils_Token::unmatchedTokens($str);
if (!empty($unmatched) && 0) {
foreach ($unmatched as $token) {
$dataErrors[] = '<li>' . ts('Invalid token code') . ' {' . $token . '}</li>';
}
}
if (!empty($dataErrors)) {
$errors[$file . '_message'] = ts('The following errors were detected in %1:', array(1 => $name)) . ' <ul>' . implode('', $dataErrors) . '</ul><br /><a href="' . CRM_Utils_System::docURL2('Sample CiviMail Messages', TRUE, NULL, NULL, NULL, "wiki") . '" target="_blank">' . ts('More information on required tokens...') . '</a>';
}
}
// End
return empty($errors) ? TRUE : $errors;
}
示例4: formRule
/**
* Function for validation
*
* @param array $params (ref.) an assoc array of name/value pairs
*
* @param $files
* @param $self
*
* @return mixed true or array of errors
* @access public
* @static
*/
static function formRule($params, $files, $self)
{
if (!empty($_POST['_qf_Import_refresh'])) {
return TRUE;
}
$errors = array();
$template = CRM_Core_Smarty::singleton();
$domain = CRM_Core_BAO_Domain::getDomain();
$mailing = new CRM_Mailing_BAO_Mailing();
$mailing->id = $self->_mailingID;
$mailing->find(TRUE);
$session = CRM_Core_Session::singleton();
$values = array('contact_id' => $session->get('userID'), 'version' => 3);
require_once 'api/api.php';
$contact = civicrm_api('contact', 'get', $values);
//CRM-4524
$contact = reset($contact['values']);
$verp = array_flip(array('optOut', 'reply', 'unsubscribe', 'resubscribe', 'owner'));
foreach ($verp as $key => $value) {
$verp[$key]++;
}
$urls = array_flip(array('forward', 'optOutUrl', 'unsubscribeUrl', 'resubscribeUrl'));
foreach ($urls as $key => $value) {
$urls[$key]++;
}
$skipTextFile = $self->get('skipTextFile');
if (!$params['upload_type']) {
if (!isset($files['textFile']) || !file_exists($files['textFile']['tmp_name'])) {
if (!$skipTextFile) {
$errors['textFile'] = ts('Please provide a Text');
}
}
} else {
if (empty($params['text_message'])) {
$errors['text_message'] = ts('Please provide a Text');
} else {
if (!empty($params['text_message'])) {
$messageCheck = CRM_Utils_Array::value('text_message', $params);
if ($messageCheck && strlen($messageCheck) > CRM_SMS_Provider::MAX_SMS_CHAR) {
$errors['text_message'] = ts("You can configure the SMS message body up to %1 characters", array(1 => CRM_SMS_Provider::MAX_SMS_CHAR));
}
}
}
if (!empty($params['saveTemplate']) && empty($params['saveTemplateName'])) {
$errors['saveTemplateName'] = ts('Please provide a Template Name.');
}
}
if ($params['upload_type'] || file_exists(CRM_Utils_Array::value('tmp_name', $files['textFile'])) || !$params['upload_type'] && $params['text_message']) {
if (!$params['upload_type']) {
$str = file_get_contents($files['textFile']['tmp_name']);
$name = $files['textFile']['name'];
} else {
$str = $params['text_message'];
$name = 'text message';
}
$dataErrors = array();
/* Do a full token replacement on a dummy verp, the current
* contact and domain, and the first organization. */
// here we make a dummy mailing object so that we
// can retrieve the tokens that we need to replace
// so that we do get an invalid token error
// this is qute hacky and I hope that there might
// be a suggestion from someone on how to
// make it a bit more elegant
$dummy_mail = new CRM_Mailing_BAO_Mailing();
$mess = "body_text";
$dummy_mail->{$mess} = $str;
$tokens = $dummy_mail->getTokens();
$str = CRM_Utils_Token::replaceSubscribeInviteTokens($str);
$str = CRM_Utils_Token::replaceDomainTokens($str, $domain, NULL, $tokens['text']);
$str = CRM_Utils_Token::replaceMailingTokens($str, $mailing, NULL, $tokens['text']);
$str = CRM_Utils_Token::replaceOrgTokens($str, $org);
$str = CRM_Utils_Token::replaceActionTokens($str, $verp, $urls, NULL, $tokens['text']);
$str = CRM_Utils_Token::replaceContactTokens($str, $contact, NULL, $tokens['text']);
$unmatched = CRM_Utils_Token::unmatchedTokens($str);
$contentCheck = CRM_Utils_String::htmlToText($str);
if (!empty($unmatched) && 0) {
foreach ($unmatched as $token) {
$dataErrors[] = '<li>' . ts('Invalid token code') . ' {' . $token . '}</li>';
}
}
if (strlen($contentCheck) > CRM_SMS_Provider::MAX_SMS_CHAR) {
$dataErrors[] = '<li>' . ts('The body of the SMS cannot exceed %1 characters.', array(1 => CRM_SMS_Provider::MAX_SMS_CHAR)) . '</li>';
}
if (!empty($dataErrors)) {
$errors['textFile'] = ts('The following errors were detected in %1:', array(1 => $name)) . ' <ul>' . implode('', $dataErrors) . '</ul>';
}
}
//.........这里部分代码省略.........
示例5: 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]);
}
}
}