当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Utils_Token::replaceContactTokens方法代码示例

本文整理汇总了PHP中CRM_Utils_Token::replaceContactTokens方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_Token::replaceContactTokens方法的具体用法?PHP CRM_Utils_Token::replaceContactTokens怎么用?PHP CRM_Utils_Token::replaceContactTokens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRM_Utils_Token的用法示例。


在下文中一共展示了CRM_Utils_Token::replaceContactTokens方法的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);
     }
 }
开发者ID:konadave,项目名称:civicrm-core,代码行数:21,代码来源:TokenCompatSubscriber.php

示例2: _testDocumentContent

 /**
  *  Assert the content of document
  *
  * @param array $formValues
  * @param array $type
  */
 public function _testDocumentContent($formValues, $type)
 {
     $html = array();
     $form = new CRM_Contact_Form_Task_PDFLetterCommon();
     list($formValues, $categories, $html_message, $messageToken, $returnProperties) = $form->processMessageTemplate($formValues);
     list($html_message, $zip) = CRM_Utils_PDF_Document::unzipDoc($formValues['document_file_path'], $formValues['document_type']);
     foreach ($this->_contactIds as $item => $contactId) {
         $params = array('contact_id' => $contactId);
         list($contact) = CRM_Utils_Token::getTokenDetails($params, $returnProperties, FALSE, FALSE, NULL, $messageToken, 'CRM_Contact_Form_Task_PDFLetterCommon');
         $html[] = CRM_Utils_Token::replaceContactTokens($html_message, $contact[$contactId], TRUE, $messageToken);
     }
     $returnContent = CRM_Utils_PDF_Document::printDocuments($formValues['document_file_path'], $html, $type, $zip, TRUE);
     $returnContent = strip_tags($returnContent);
     $this->assertTrue(strpos($returnContent, 'Hello Antonia D`souza') !== 0);
     $this->assertTrue(strpos($returnContent, 'Hello Anthony Collins') !== 0);
 }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:22,代码来源:PrintDocumentTest.php

示例3: generateHTML

 /**
  * generate htmlfor pdf letters
  *
  * @param array $membershipIDs
  * @param array $returnProperties
  * @param bool $skipOnHold
  * @param bool $skipDeceased
  * @param unknown_type $messageToken
  * @param $html_message
  * @param $categories
  *
  * @return unknown
  */
 static function generateHTML($membershipIDs, $returnProperties, $skipOnHold, $skipDeceased, $messageToken, $html_message, $categories)
 {
     $memberships = CRM_Utils_Token::getMembershipTokenDetails($membershipIDs);
     foreach ($membershipIDs as $membershipID) {
         $membership = $memberships[$membershipID];
         // get contact information
         $contactId = $membership['contact_id'];
         $params = array('contact_id' => $contactId);
         //getTokenDetails is much like calling the api contact.get function - but - with some minor
         // special handlings. It preceeds the existence of the api
         list($contacts) = CRM_Utils_Token::getTokenDetails($params, $returnProperties, $skipOnHold, $skipDeceased, NULL, $messageToken, 'CRM_Contribution_Form_Task_PDFLetterCommon');
         $tokenHtml = CRM_Utils_Token::replaceContactTokens($html_message, $contacts[$contactId], TRUE, $messageToken);
         $tokenHtml = CRM_Utils_Token::replaceEntityTokens('membership', $membership, $tokenHtml, $messageToken);
         $tokenHtml = CRM_Utils_Token::replaceHookTokens($tokenHtml, $contacts[$contactId], $categories, TRUE);
         $tokenHtml = CRM_Utils_Token::parseThroughSmarty($tokenHtml, $contacts[$contactId]);
         $html[] = $tokenHtml;
     }
     return $html;
 }
开发者ID:prashantgajare,项目名称:civicrm-core,代码行数:32,代码来源:PDFLetterCommon.php

示例4: 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;
 }
开发者ID:krishgopi,项目名称:uk.co.vedaconsulting.quickbulkemail,代码行数:101,代码来源:QuickBulkEmail.php

示例5: 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];
//.........这里部分代码省略.........
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:101,代码来源:MessageTemplate.php

示例6: replaceGreetingTokens

 /**
  * Replace existing greeting tokens in message/subject.
  */
 public static function replaceGreetingTokens(&$tokenString, $contactDetails = NULL, $contactId = NULL, $className = NULL, $escapeSmarty = FALSE)
 {
     if (!$contactDetails && !$contactId) {
         return;
     }
     // check if there are any tokens
     $greetingTokens = self::getTokens($tokenString);
     if (!empty($greetingTokens)) {
         // first use the existing contact object for token replacement
         if (!empty($contactDetails)) {
             $tokenString = CRM_Utils_Token::replaceContactTokens($tokenString, $contactDetails, TRUE, $greetingTokens, TRUE, $escapeSmarty);
         }
         // check if there are any unevaluated tokens
         $greetingTokens = self::getTokens($tokenString);
         // $greetingTokens not empty, means there are few tokens which are not
         // evaluated, like custom data etc
         // so retrieve it from database
         if (!empty($greetingTokens) && array_key_exists('contact', $greetingTokens)) {
             $greetingsReturnProperties = array_flip(CRM_Utils_Array::value('contact', $greetingTokens));
             $greetingsReturnProperties = array_fill_keys(array_keys($greetingsReturnProperties), 1);
             $contactParams = array('contact_id' => $contactId);
             $greetingDetails = self::getTokenDetails($contactParams, $greetingsReturnProperties, FALSE, FALSE, NULL, $greetingTokens, $className);
             // again replace tokens
             $tokenString = CRM_Utils_Token::replaceContactTokens($tokenString, $greetingDetails, TRUE, $greetingTokens, TRUE, $escapeSmarty);
         }
         // check if there are still any unevaluated tokens
         $remainingTokens = self::getTokens($tokenString);
         // $greetingTokens not empty, there are customized or hook tokens to replace
         if (!empty($remainingTokens)) {
             // Fill the return properties array
             $greetingTokens = $remainingTokens;
             reset($greetingTokens);
             $greetingsReturnProperties = array();
             while (list($key) = each($greetingTokens)) {
                 $props = array_flip(CRM_Utils_Array::value($key, $greetingTokens));
                 $props = array_fill_keys(array_keys($props), 1);
                 $greetingsReturnProperties = $greetingsReturnProperties + $props;
             }
             $contactParams = array('contact_id' => $contactId);
             $greetingDetails = self::getTokenDetails($contactParams, $greetingsReturnProperties, FALSE, FALSE, NULL, $greetingTokens, $className);
             // Prepare variables for calling replaceHookTokens
             $categories = array_keys($greetingTokens);
             list($contact) = $greetingDetails;
             // Replace tokens defined in Hooks.
             $tokenString = CRM_Utils_Token::replaceHookTokens($tokenString, $contact[$contactId], $categories);
         }
     }
 }
开发者ID:rameshrr99,项目名称:civicrm-core,代码行数:51,代码来源:Token.php

示例7: sendSMS

 static function sendSMS(&$contactDetails, &$activityParams, &$smsParams = array(), &$contactIds, $userID = NULL)
 {
     if ($userID == NULL) {
         $session = CRM_Core_Session::singleton();
         $userID = $session->get('userID');
     }
     $text =& $activityParams['text_message'];
     $html =& $activityParams['html_message'];
     // CRM-4575
     // token replacement of addressee/email/postal greetings
     // get the tokens added in subject and message
     $messageToken = CRM_Utils_Token::getTokens($text);
     $messageToken = array_merge($messageToken, CRM_Utils_Token::getTokens($html));
     //create the meta level record first ( sms activity )
     $activityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'SMS', 'name');
     // CRM-6265: save both text and HTML parts in details (if present)
     if ($html and $text) {
         $details = "-ALTERNATIVE ITEM 0-\n{$html}\n-ALTERNATIVE ITEM 1-\n{$text}\n-ALTERNATIVE END-\n";
     } else {
         $details = $html ? $html : $text;
     }
     $activitySubject = $activityParams['activity_subject'];
     $activityParams = array('source_contact_id' => $userID, 'activity_type_id' => $activityTypeID, 'activity_date_time' => date('YmdHis'), 'subject' => $activitySubject, 'details' => $details, 'status_id' => 2);
     $activity = self::create($activityParams);
     $activityID = $activity->id;
     $returnProperties = array();
     if (isset($messageToken['contact'])) {
         foreach ($messageToken['contact'] as $key => $value) {
             $returnProperties[$value] = 1;
         }
     }
     // get token details for contacts, call only if tokens are used
     $details = array();
     if (!empty($returnProperties)) {
         list($details) = CRM_Utils_Token::getTokenDetails($contactIds, $returnProperties, NULL, NULL, FALSE, $messageToken, 'CRM_Activity_BAO_Activity');
     }
     // call token hook
     $tokens = array();
     CRM_Utils_Hook::tokens($tokens);
     $categories = array_keys($tokens);
     $escapeSmarty = $sent = FALSE;
     foreach ($contactDetails as $values) {
         $contactId = $values['contact_id'];
         if (!empty($details) && is_array($details["{$contactId}"])) {
             // unset email from details since it always returns primary email address
             unset($details["{$contactId}"]['email']);
             unset($details["{$contactId}"]['email_id']);
             $values = array_merge($values, $details["{$contactId}"]);
         }
         $tokenText = CRM_Utils_Token::replaceContactTokens($text, $values, FALSE, $messageToken, FALSE, $escapeSmarty);
         $tokenText = CRM_Utils_Token::replaceHookTokens($tokenText, $values, $categories, FALSE, $escapeSmarty);
         $tokenHtml = CRM_Utils_Token::replaceContactTokens($html, $values, TRUE, $messageToken, FALSE, $escapeSmarty);
         $tokenHtml = CRM_Utils_Token::replaceHookTokens($tokenHtml, $values, $categories, TRUE, $escapeSmarty);
         $smsParams['To'] = $values['phone'];
         if (self::sendSMSMessage($contactId, $tokenText, $tokenHtml, $smsParams, $activityID)) {
             // even a single successful delivery should set this falg to true
             $sent = TRUE;
         }
     }
     return array($sent, $activity->id);
 }
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:61,代码来源:Activity.php

示例8: 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>';
         }
     }
//.........这里部分代码省略.........
开发者ID:prashantgajare,项目名称:civicrm-core,代码行数:101,代码来源:Upload.php

示例9: sendReminder

 /**
  * @param $contactId
  * @param $to
  * @param $scheduleID
  * @param $from
  * @param $tokenParams
  *
  * @return bool|null
  * @throws CRM_Core_Exception
  */
 static function sendReminder($contactId, $to, $scheduleID, $from, $tokenParams)
 {
     $email = $to['email'];
     $phoneNumber = $to['phone'];
     $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;
         $sms_body_text = $schedule->sms_body_text;
         $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('body_html' => 'html', 'body_text' => 'text', 'sms_body_text' => 'text');
         foreach ($type as $bodyType => $value) {
             $dummy_mail = new CRM_Mailing_BAO_Mailing();
             if ($bodyType == 'sms_body_text') {
                 $dummy_mail->body_text = ${$bodyType};
             } else {
                 $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;
         $sms_text = $sms_body_text;
         $smarty = CRM_Core_Smarty::singleton();
         foreach (array('text', 'html', 'sms_text') 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[$type])) {
                         $subjectToken[$type] = array();
                     }
                     $subjectToken[$type][] = $name;
                 }
             }
         }
         $messageSubject = CRM_Utils_Token::replaceContactTokens($body_subject, $contact, FALSE, $subjectToken);
         $messageSubject = CRM_Utils_Token::replaceDomainTokens($messageSubject, $domain, TRUE, $subjectToken);
         $messageSubject = CRM_Utils_Token::replaceComponentTokens($messageSubject, $contact, $subjectToken, TRUE);
         $messageSubject = CRM_Utils_Token::replaceHookTokens($messageSubject, $contact, $categories, TRUE);
         $messageSubject = $smarty->fetch("string:{$messageSubject}");
         if ($schedule->mode == 'SMS' or $schedule->mode == 'User_Preference') {
             $session = CRM_Core_Session::singleton();
             $userID = $session->get('userID') ? $session->get('userID') : $contactId;
             $smsParams = array('To' => $phoneNumber, 'provider_id' => $schedule->sms_provider_id, 'activity_subject' => $messageSubject);
             $activityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'SMS', 'name');
             $activityParams = array('source_contact_id' => $userID, 'activity_type_id' => $activityTypeID, 'activity_date_time' => date('YmdHis'), 'subject' => $messageSubject, 'details' => $sms_text, 'status_id' => CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name'));
             $activity = CRM_Activity_BAO_Activity::create($activityParams);
             CRM_Activity_BAO_Activity::sendSMSMessage($contactId, $sms_text, $html, $smsParams, $activity->id, $userID);
         }
         if ($schedule->mode == 'Email' or $schedule->mode == 'User_Preference') {
             // 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, 'entity' => 'action_schedule', 'entity_id' => $scheduleID);
             if (!$html || $contact['preferred_mail_format'] == 'Text' || $contact['preferred_mail_format'] == 'Both') {
                 // render the &amp; entities in text mode, so that the links work
                 $mailParams['text'] = str_replace('&amp;', '&', $text);
             }
             if ($html && ($contact['preferred_mail_format'] == 'HTML' || $contact['preferred_mail_format'] == 'Both')) {
//.........这里部分代码省略.........
开发者ID:ruchirapingale,项目名称:civicrm-core,代码行数:101,代码来源:ActionSchedule.php

示例10: 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;
 }
开发者ID:CiviCooP,项目名称:org.civicoop.civiruleshttppost,代码行数:30,代码来源:HttpPostAction.php

示例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;
 }
开发者ID:bhirsch,项目名称:voipdrupal-4.7-1.0,代码行数:78,代码来源:Upload.php

示例12: postProcess

 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  *
  * @return void
  */
 static function postProcess(&$form)
 {
     list($formValues, $categories, $html_message, $messageToken, $returnProperties) = self::processMessageTemplate($form);
     // update dates ?
     $receipt_update = isset($formValues['receipt_update']) ? $formValues['receipt_update'] : FALSE;
     $thankyou_update = isset($formValues['thankyou_update']) ? $formValues['thankyou_update'] : FALSE;
     $nowDate = date('YmdHis');
     $receipts = 0;
     $thanks = 0;
     $updateStatus = '';
     // skip some contacts ?
     $skipOnHold = isset($form->skipOnHold) ? $form->skipOnHold : FALSE;
     $skipDeceased = isset($form->skipDeceased) ? $form->skipDeceased : TRUE;
     foreach ($form->getVar('_contributionIds') as $item => $contributionId) {
         // get contact information
         $contactId = civicrm_api("Contribution", "getvalue", array('version' => '3', 'id' => $contributionId, 'return' => 'contact_id'));
         $params = array('contact_id' => $contactId);
         list($contact) = CRM_Utils_Token::getTokenDetails($params, $returnProperties, $skipOnHold, $skipDeceased, NULL, $messageToken, 'CRM_Contribution_Form_Task_PDFLetterCommon');
         if (civicrm_error($contact)) {
             $notSent[] = $contributionId;
             continue;
         }
         // get contribution information
         $params = array('contribution_id' => $contributionId);
         $contribution = CRM_Utils_Token::getContributionTokenDetails($params, $returnProperties, NULL, $messageToken, 'CRM_Contribution_Form_Task_PDFLetterCommon');
         if (civicrm_error($contribution)) {
             $notSent[] = $contributionId;
             continue;
         }
         $tokenHtml = CRM_Utils_Token::replaceContactTokens($html_message, $contact[$contactId], TRUE, $messageToken);
         $tokenHtml = CRM_Utils_Token::replaceContributionTokens($tokenHtml, $contribution[$contributionId], TRUE, $messageToken);
         $tokenHtml = CRM_Utils_Token::replaceHookTokens($tokenHtml, $contact[$contactId], $categories, TRUE);
         if (defined('CIVICRM_MAIL_SMARTY') && CIVICRM_MAIL_SMARTY) {
             $smarty = CRM_Core_Smarty::singleton();
             // also add the tokens to the template
             $smarty->assign_by_ref('contact', $contact);
             $tokenHtml = $smarty->fetch("string:{$tokenHtml}");
         }
         $html[] = $tokenHtml;
         // update dates (do it for each contribution including grouped recurring contribution)
         if ($receipt_update) {
             $result = CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'receipt_date', $nowDate);
             // We can't use CRM_Core_Error::fatal here because the api error elevates the exception level. FIXME. dgg
             if ($result) {
                 $receipts++;
             }
         }
         if ($thankyou_update) {
             $result = CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'thankyou_date', $nowDate);
             // We can't use CRM_Core_Error::fatal here because the api error elevates the exception level. FIXME. dgg
             if ($result) {
                 $thanks++;
             }
         }
     }
     self::createActivities($form, $html_message, $form->_contactIds);
     CRM_Utils_PDF_Utils::html2pdf($html, "CiviLetter.pdf", FALSE, $formValues);
     $form->postProcessHook();
     if ($receipts) {
         $updateStatus = ts('Receipt date has been updated for %1 contributions.', array(1 => $receipts));
     }
     if ($thanks) {
         $updateStatus .= ' ' . ts('Thank-you date has been updated for %1 contributions.', array(1 => $thanks));
     }
     if ($updateStatus) {
         CRM_Core_Session::setStatus($updateStatus);
     }
     CRM_Utils_System::civiExit(1);
 }
开发者ID:archcidburnziso,项目名称:civicrm-core,代码行数:76,代码来源:PDFLetterCommon.php

示例13: postProcess

 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  * @return None
  */
 static function postProcess(&$form)
 {
     $formValues = $form->controller->exportValues($form->getName());
     // process message template
     require_once 'CRM/Core/BAO/MessageTemplates.php';
     if (CRM_Utils_Array::value('saveTemplate', $formValues) || CRM_Utils_Array::value('updateTemplate', $formValues)) {
         $messageTemplate = array('msg_text' => NULL, 'msg_html' => $formValues['html_message'], 'msg_subject' => NULL, 'is_active' => true);
         if ($formValues['saveTemplate']) {
             $messageTemplate['msg_title'] = $formValues['saveTemplateName'];
             CRM_Core_BAO_MessageTemplates::add($messageTemplate);
         }
         if ($formValues['template'] && $formValues['updateTemplate']) {
             $messageTemplate['id'] = $formValues['template'];
             unset($messageTemplate['msg_title']);
             CRM_Core_BAO_MessageTemplates::add($messageTemplate);
         }
     }
     require_once 'dompdf/dompdf_config.inc.php';
     $html = '<html><head><style>body { margin: 56px; }</style></head><body>';
     require_once 'api/v2/Contact.php';
     require_once 'CRM/Utils/Token.php';
     $tokens = array();
     CRM_Utils_Hook::tokens($tokens);
     $categories = array_keys($tokens);
     $html_message = $formValues['html_message'];
     //time being hack to strip '&nbsp;'
     //from particular letter line, CRM-6798
     self::formatMessage($html_message);
     require_once 'CRM/Activity/BAO/Activity.php';
     $messageToken = CRM_Activity_BAO_Activity::getTokens($html_message);
     $returnProperties = array();
     if (isset($messageToken['contact'])) {
         foreach ($messageToken['contact'] as $key => $value) {
             $returnProperties[$value] = 1;
         }
     }
     require_once 'CRM/Mailing/BAO/Mailing.php';
     $mailing = new CRM_Mailing_BAO_Mailing();
     if (defined('CIVICRM_MAIL_SMARTY')) {
         require_once 'CRM/Core/Smarty/resources/String.php';
         civicrm_smarty_register_string_resource();
     }
     $first = TRUE;
     foreach ($form->_contactIds as $item => $contactId) {
         $params = array('contact_id' => $contactId);
         list($contact) = $mailing->getDetails($params, $returnProperties, false);
         if (civicrm_error($contact)) {
             $notSent[] = $contactId;
             continue;
         }
         $tokenHtml = CRM_Utils_Token::replaceContactTokens($html_message, $contact[$contactId], true, $messageToken);
         $tokenHtml = CRM_Utils_Token::replaceHookTokens($tokenHtml, $contact[$contactId], $categories, true);
         if (defined('CIVICRM_MAIL_SMARTY')) {
             $smarty = CRM_Core_Smarty::singleton();
             // also add the contact tokens to the template
             $smarty->assign_by_ref('contact', $contact);
             $tokenHtml = $smarty->fetch("string:{$tokenHtml}");
         }
         if ($first == TRUE) {
             $first = FALSE;
             $html .= $tokenHtml;
         } else {
             $html .= "<div STYLE='page-break-after: always'></div>{$tokenHtml}";
         }
     }
     $html .= '</body></html>';
     require_once 'CRM/Activity/BAO/Activity.php';
     $session = CRM_Core_Session::singleton();
     $userID = $session->get('userID');
     $activityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'Print PDF Letter', 'name');
     $activityParams = array('source_contact_id' => $userID, 'activity_type_id' => $activityTypeID, 'activity_date_time' => date('YmdHis'), 'details' => $html_message);
     if ($form->_activityId) {
         $activityParams += array('id' => $form->_activityId);
     }
     if ($form->_cid) {
         $activity = CRM_Activity_BAO_Activity::create($activityParams);
     } else {
         // create  Print PDF activity for each selected contact. CRM-6886
         $activityIds = array();
         foreach ($form->_contactIds as $contactId) {
             $activityID = CRM_Activity_BAO_Activity::create($activityParams);
             $activityIds[$contactId] = $activityID->id;
         }
     }
     foreach ($form->_contactIds as $contactId) {
         $activityTargetParams = array('activity_id' => empty($activity->id) ? $activityIds[$contactId] : $activity->id, 'target_contact_id' => $contactId);
         CRM_Activity_BAO_Activity::createActivityTarget($activityTargetParams);
     }
     require_once 'CRM/Utils/PDF/Utils.php';
     CRM_Utils_PDF_Utils::html2pdf($html, "CiviLetter.pdf", 'portrait', 'letter');
     // we need to call the hook manually here since we redirect and never
     // go back to CRM/Core/Form.php
     CRM_Utils_Hook::postProcess(get_class($form), $form);
     CRM_Utils_System::civiExit(1);
//.........这里部分代码省略.........
开发者ID:hampelm,项目名称:Ginsberg-CiviDemo,代码行数:101,代码来源:PDFLetterCommon.php

示例14: postProcess

 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  * @return None
  */
 static function postProcess(&$form)
 {
     $formValues = $form->controller->exportValues($form->getName());
     // process message template
     require_once 'CRM/Core/BAO/MessageTemplates.php';
     if (CRM_Utils_Array::value('saveTemplate', $formValues) || CRM_Utils_Array::value('updateTemplate', $formValues)) {
         $messageTemplate = array('msg_text' => NULL, 'msg_html' => $formValues['html_message'], 'msg_subject' => NULL, 'is_active' => true);
         if ($formValues['saveTemplate']) {
             $messageTemplate['msg_title'] = $formValues['saveTemplateName'];
             CRM_Core_BAO_MessageTemplates::add($messageTemplate);
         }
         if ($formValues['template'] && $formValues['updateTemplate']) {
             $messageTemplate['id'] = $formValues['template'];
             unset($messageTemplate['msg_title']);
             CRM_Core_BAO_MessageTemplates::add($messageTemplate);
         }
     }
     require_once 'dompdf/dompdf_config.inc.php';
     $html = '<html><head><style>body { margin: 56px; }</style></head><body>';
     require_once 'api/v2/Contact.php';
     require_once 'CRM/Utils/Token.php';
     $tokens = array();
     CRM_Utils_Hook::tokens($tokens);
     $categories = array_keys($tokens);
     $html_message = $formValues['html_message'];
     require_once 'CRM/Activity/BAO/Activity.php';
     $messageToken = CRM_Activity_BAO_Activity::getTokens($html_message);
     $returnProperties = array();
     if (isset($messageToken['contact'])) {
         foreach ($messageToken['contact'] as $key => $value) {
             $returnProperties[$value] = 1;
         }
     }
     require_once 'CRM/Mailing/BAO/Mailing.php';
     $mailing =& new CRM_Mailing_BAO_Mailing();
     $first = TRUE;
     foreach ($form->_contactIds as $item => $contactId) {
         $params = array('contact_id' => $contactId);
         list($contact) = $mailing->getDetails($params, $returnProperties, false);
         if (civicrm_error($contact)) {
             $notSent[] = $contactId;
             continue;
         }
         $tokenHtml = CRM_Utils_Token::replaceContactTokens($html_message, $contact[$contactId], true, $messageToken);
         $tokenHtml = CRM_Utils_Token::replaceHookTokens($tokenHtml, $contact[$contactId], $categories, true);
         if ($first == TRUE) {
             $first = FALSE;
             $html .= $tokenHtml;
         } else {
             $html .= "<div STYLE='page-break-after: always'></div>{$tokenHtml}";
         }
     }
     $html .= '</body></html>';
     require_once 'CRM/Utils/PDF/Utils.php';
     CRM_Utils_PDF_Utils::html2pdf($html, "CiviLetter.pdf", 'portrait');
     exit(1);
 }
开发者ID:bhirsch,项目名称:civicrm,代码行数:63,代码来源:PDFLetterCommon.php

示例15: 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 &amp; entities in text mode, so that the links work
             $mailParams['text'] = str_replace('&amp;', '&', $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;
 }
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:80,代码来源:ActionSchedule.php


注:本文中的CRM_Utils_Token::replaceContactTokens方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。