本文整理汇总了PHP中EmailTemplate::parse_template方法的典型用法代码示例。如果您正苦于以下问题:PHP EmailTemplate::parse_template方法的具体用法?PHP EmailTemplate::parse_template怎么用?PHP EmailTemplate::parse_template使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EmailTemplate
的用法示例。
在下文中一共展示了EmailTemplate::parse_template方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
function run_action(SugarBean $bean, $params = array())
{
global $sugar_config;
include_once 'modules/EmailTemplates/EmailTemplate.php';
$emailTemp = new EmailTemplate();
$emailTemp->retrieve($params['email_template']);
$object_arr[$bean->module_dir] = $bean->id;
$parsedSiteUrl = parse_url($sugar_config['site_url']);
$host = $parsedSiteUrl['host'];
if (!isset($parsedSiteUrl['port'])) {
$parsedSiteUrl['port'] = 80;
}
$port = $parsedSiteUrl['port'] != 80 ? ":" . $parsedSiteUrl['port'] : '';
$path = !empty($parsedSiteUrl['path']) ? $parsedSiteUrl['path'] : "";
$cleanUrl = "{$parsedSiteUrl['scheme']}://{$host}{$port}{$path}";
$url = $cleanUrl . "/index.php?module={$bean->module_dir}&action=DetailView&record={$bean->id}";
$subject = $emailTemp->parse_template($emailTemp->subject, $object_arr);
$body_html = $emailTemp->parse_template($emailTemp->body_html, $object_arr);
$body_html = str_replace("\$url", $url, $body_html);
$body_plain = $emailTemp->parse_template($emailTemp->body, $object_arr);
$body_plain = str_replace("\$url", $url, $body_plain);
$email = $this->getEmailFromParams($bean, $params);
return $this->sendEmail($email, $subject, $body_html, $body_plain, $bean);
}
示例2: array
$object_arr = array();
if (!empty($focus->parent_id)) {
$object_arr[$focus->parent_type] = $focus->parent_id;
}
if (isset($focus->to_addrs_arr[0]['contact_id'])) {
$object_arr['Contacts'] = $focus->to_addrs_arr[0]['contact_id'];
}
if (empty($object_arr)) {
$object_arr = array('Contacts' => '123');
}
// do not parse email templates if the email is being saved as draft....
if ($focus->type != 'draft' && count($object_arr) > 0) {
require_once $beanFiles['EmailTemplate'];
$focus->name = EmailTemplate::parse_template($focus->name, $object_arr);
$focus->description = EmailTemplate::parse_template($focus->description, $object_arr);
$focus->description_html = EmailTemplate::parse_template($focus->description_html, $object_arr);
}
//// END TEMPLATE PARSING
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//// PREP FOR ATTACHMENTS
if (empty($focus->id)) {
$focus->id = create_guid();
$focus->new_with_id = true;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//// ATTACHMENT HANDLING
$focus->handleAttachments();
//// END ATTACHMENT HANDLING
///////////////////////////////////////////////////////////////////////////////
示例3: email2Send
//.........这里部分代码省略.........
// do not parse email templates if the email is being saved as draft....
$toAddresses = $this->email2ParseAddresses($_REQUEST['sendTo']);
$sea = new SugarEmailAddress();
$object_arr = array();
if (isset($_REQUEST['parent_type']) && !empty($_REQUEST['parent_type']) && isset($_REQUEST['parent_id']) && !empty($_REQUEST['parent_id']) && ($_REQUEST['parent_type'] == 'Accounts' || $_REQUEST['parent_type'] == 'Contacts' || $_REQUEST['parent_type'] == 'Leads' || $_REQUEST['parent_type'] == 'Users' || $_REQUEST['parent_type'] == 'Prospects')) {
if (isset($beanList[$_REQUEST['parent_type']]) && !empty($beanList[$_REQUEST['parent_type']])) {
$className = $beanList[$_REQUEST['parent_type']];
if (isset($beanFiles[$className]) && !empty($beanFiles[$className])) {
if (!class_exists($className)) {
require_once $beanFiles[$className];
}
$bean = new $className();
$bean->retrieve($_REQUEST['parent_id']);
$object_arr[$bean->module_dir] = $bean->id;
}
// if
}
// if
}
foreach ($toAddresses as $addrMeta) {
$addr = $addrMeta['email'];
$beans = $sea->getBeansByEmailAddress($addr);
foreach ($beans as $bean) {
if (!isset($object_arr[$bean->module_dir])) {
$object_arr[$bean->module_dir] = $bean->id;
}
}
}
/* template parsing */
if (empty($object_arr)) {
$object_arr = array('Contacts' => '123');
}
$object_arr['Users'] = $current_user->id;
$this->description_html = EmailTemplate::parse_template($this->description_html, $object_arr);
$this->name = EmailTemplate::parse_template($this->name, $object_arr);
$this->description = EmailTemplate::parse_template($this->description, $object_arr);
$this->description = html_entity_decode($this->description, ENT_COMPAT, 'UTF-8');
if ($this->type != 'draft' && $this->status != 'draft') {
$this->id = create_guid();
$this->date_entered = "";
$this->new_with_id = true;
$this->type = 'out';
$this->status = 'sent';
}
}
if (isset($_REQUEST['parent_type']) && empty($_REQUEST['parent_type']) && isset($_REQUEST['parent_id']) && empty($_REQUEST['parent_id'])) {
$this->parent_id = "";
$this->parent_type = "";
}
// if
$mail->Subject = $this->name;
$mail = $this->handleBody($mail);
$mail->Subject = $this->name;
$this->description_html = from_html($this->description_html);
$this->description_html = $this->decodeDuringSend($this->description_html);
$this->description = $this->decodeDuringSend($this->description);
/* from account */
$replyToAddress = $current_user->emailAddress->getReplyToAddress($current_user);
$replyToName = "";
if (empty($request['fromAccount'])) {
$defaults = $current_user->getPreferredEmail();
$mail->From = $defaults['email'];
$mail->FromName = $defaults['name'];
$replyToName = $mail->FromName;
//$replyToAddress = $current_user->emailAddress->getReplyToAddress($current_user);
} else {
示例4: testparse_template
public function testparse_template()
{
$emailTemplate = new EmailTemplate();
$bean_arr = array('Users' => 1, 'Leads' => 1);
//test with empty string
$result = $emailTemplate->parse_template('', $bean_arr);
$this->assertEquals('', $result);
//test with valid string
$result = $emailTemplate->parse_template('some value', $bean_arr);
$this->assertEquals('some value', $result);
}
示例5: sendEmailTemplate
/**
* Send Email with attachment Report to specified emails
* @param string $attachFileName
* name of report file
* @param string $attachFilePath
* path to report file for read it and attach to email
* @param array $toAddresses
* array with email and names of contacts for send him this email
* array( array('email' => EMAIL_ADDR, 'display' => DISPLAY_NAME) )
* @param string $templateId
* optional argument. Id of Email template
* @param SugarBean $bean
* optional argument, uses for parse template with values of this bean
* @return array
* return array with status send email in this format: array('status' => TRUE_OR_FALSE, 'error' => ERROR_MSG)
*/
public static function sendEmailTemplate($attachFileName, $attachFilePath, $toAddresses, $templateId = '', $bean = NULL)
{
global $locale, $current_user, $app_strings;
$sea = new SugarEmailAddress();
$answer = array('status' => true, 'error' => '');
$email = new Email();
$email->email2init();
$email->type = 'out';
$email->status = 'sent';
$email->id = create_guid();
$email->new_with_id = true;
$emailTemplate = new EmailTemplate();
$emailTemplate->retrieve($templateId);
if (empty($emailTemplate->subject)) {
$emailTemplate->subject = $attachFileName;
//set file name as subject
}
$email->name = $emailTemplate->subject;
$email->description = $emailTemplate->body;
$email->description_html = '<html><body>' . $emailTemplate->body_html . '</body></html>';
$mail = new SugarPHPMailer();
$mail = $email->setMailer($mail, '', '');
if (empty($mail->Host)) {
if ($mail->oe->type == 'system') {
$answer['error'] = $app_strings['LBL_EMAIL_ERROR_PREPEND'] . $app_strings['LBL_EMAIL_INVALID_SYSTEM_OUTBOUND'];
} else {
$answer['error'] = $app_strings['LBL_EMAIL_ERROR_PREPEND'] . $app_strings['LBL_EMAIL_INVALID_PERSONAL_OUTBOUND'];
}
$answer['status'] = false;
return $answer;
}
$object_arr = array();
if ($bean !== NULL) {
$object_arr[$bean->module_dir] = $bean->id;
}
foreach ($toAddresses as $addrMeta) {
$addr = $addrMeta['email'];
$beans = $sea->getBeansByEmailAddress($addr);
foreach ($beans as $bean) {
if (!isset($object_arr[$bean->module_dir])) {
$object_arr[$bean->module_dir] = $bean->id;
}
}
}
$object_arr['Users'] = $current_user->id;
$email->description_html = $email->decodeDuringSend(from_html(EmailTemplate::parse_template($email->description_html, $object_arr)));
$email->description = $email->decodeDuringSend(html_entity_decode(EmailTemplate::parse_template($email->description, $object_arr), ENT_COMPAT, 'UTF-8'));
$email->name = from_html(EmailTemplate::parse_template($email->name, $object_arr));
$mail->Body = $email->description_html;
$mail->AltBody = $email->description;
$mail->Subject = $email->name;
$replyToAddress = $current_user->emailAddress->getReplyToAddress($current_user);
$defaults = $current_user->getPreferredEmail();
$mail->From = $defaults['email'];
$mail->FromName = $defaults['name'];
$mail->Sender = $mail->From;
/* set Return-Path field in header to reduce spam score in emails sent via Sugar's Email module */
$replyToName = $mail->FromName;
$OBCharset = $locale->getPrecedentPreference('default_email_charset');
if (!empty($replyToAddress)) {
$mail->AddReplyTo($replyToAddress, $locale->translateCharsetMIME(trim($replyToName), 'UTF-8', $OBCharset));
} else {
$mail->AddReplyTo($mail->From, $locale->translateCharsetMIME(trim($mail->FromName), 'UTF-8', $OBCharset));
}
foreach ($toAddresses as $addr_arr) {
if (empty($addr_arr['email'])) {
continue;
}
if (empty($addr_arr['display'])) {
$mail->AddAddress($addr_arr['email'], "");
} else {
$mail->AddAddress($addr_arr['email'], $locale->translateCharsetMIME(trim($addr_arr['display']), 'UTF-8', $OBCharset));
}
}
$mail->AddAttachment($attachFilePath, $attachFileName, 'base64', self::getMimeType($attachFileName));
$mail->prepForOutbound();
$mail->Body = $email->decodeDuringSend($mail->Body);
$mail->AltBody = $email->decodeDuringSend($mail->AltBody);
if (!$mail->Send()) {
ob_clean();
$answer['error'] = $app_strings['LBL_EMAIL_ERROR_PREPEND'] . $mail->ErrorInfo;
$answer['status'] = false;
return $answer;
}
//.........这里部分代码省略.........
示例6: email2Send
/**
* Sends Email for Email 2.0
*/
function email2Send($request)
{
global $current_user;
global $timedate;
$saveAsDraft = !empty($request['saveDraft']);
if (!$saveAsDraft && !empty($request["MAIL_RECORD_STATUS"]) && $request["MAIL_RECORD_STATUS"] == 'archived') {
$archived = true;
$this->type = 'archived';
} else {
$archived = false;
if (!empty($request['MAIL_RECORD_STATUS']) && $request['MAIL_RECORD_STATUS'] === 'ready') {
$this->type = 'out';
}
}
/**********************************************************************
* Sugar Email PREP
*/
/* preset GUID */
$orignialId = "";
if (!empty($this->id)) {
$orignialId = $this->id;
}
// if
if (empty($this->id)) {
$this->id = create_guid();
$this->new_with_id = true;
}
/* satisfy basic HTML email requirements */
$this->name = $request['sendSubject'];
if (isset($_REQUEST['setEditor']) && $_REQUEST['setEditor'] == 1) {
$_REQUEST['description_html'] = $_REQUEST['sendDescription'];
$this->description_html = $_REQUEST['description_html'];
} else {
$this->description_html = '';
$this->description = $_REQUEST['sendDescription'];
}
if ($this->isDraftEmail($request)) {
if ($this->type != 'draft' && $this->status != 'draft') {
$this->id = create_guid();
$this->new_with_id = true;
$this->date_entered = "";
}
// if
$q1 = "update emails_email_addr_rel set deleted = 1 WHERE email_id = '{$this->id}'";
$this->db->query($q1);
}
// if
if ($saveAsDraft) {
$this->type = 'draft';
$this->status = 'draft';
} else {
if ($archived) {
$this->type = 'archived';
$this->status = 'archived';
}
/* Apply Email Templates */
// do not parse email templates if the email is being saved as draft....
$toAddresses = $this->email2ParseAddresses($_REQUEST['sendTo']);
$sea = BeanFactory::getBean('EmailAddresses');
$object_arr = array();
if (!empty($_REQUEST['parent_type']) && !empty($_REQUEST['parent_id']) && ($_REQUEST['parent_type'] == 'Accounts' || $_REQUEST['parent_type'] == 'Contacts' || $_REQUEST['parent_type'] == 'Leads' || $_REQUEST['parent_type'] == 'Users' || $_REQUEST['parent_type'] == 'Prospects')) {
$bean = BeanFactory::getBean($_REQUEST['parent_type'], $_REQUEST['parent_id']);
if (!empty($bean->id)) {
$object_arr[$bean->module_dir] = $bean->id;
}
}
foreach ($toAddresses as $addrMeta) {
$addr = $addrMeta['email'];
$beans = $sea->getBeansByEmailAddress($addr);
foreach ($beans as $bean) {
if (!isset($object_arr[$bean->module_dir])) {
$object_arr[$bean->module_dir] = $bean->id;
}
}
}
/* template parsing */
if (empty($object_arr)) {
$object_arr = array('Contacts' => '123');
}
$object_arr['Users'] = $current_user->id;
$this->description_html = EmailTemplate::parse_template($this->description_html, $object_arr);
$this->name = EmailTemplate::parse_template($this->name, $object_arr);
$this->description = EmailTemplate::parse_template($this->description, $object_arr);
$this->description = html_entity_decode($this->description, ENT_COMPAT, 'UTF-8');
if ($this->type != 'draft' && $this->status != 'draft' && $this->type != 'archived' && $this->status != 'archived') {
$this->id = create_guid();
$this->date_entered = "";
$this->new_with_id = true;
$this->type = 'out';
$this->status = 'sent';
}
}
if (isset($_REQUEST['parent_type']) && empty($_REQUEST['parent_type']) && isset($_REQUEST['parent_id']) && empty($_REQUEST['parent_id'])) {
$this->parent_id = "";
$this->parent_type = "";
}
// if
//.........这里部分代码省略.........