mirror of
https://github.com/e107inc/e107.git
synced 2025-01-17 12:48:24 +01:00
Closes #4919 - Enhancement: plugins may now use their own custom email templates with sendEmail();
This commit is contained in:
parent
aba1b27108
commit
93a05dc777
@ -912,13 +912,25 @@ class e107Email extends PHPMailer
|
||||
if(!empty($eml['template'])) // @see e107_core/templates/email_template.php
|
||||
{
|
||||
require_once(e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_users.php"); // do not use e107::lan etc.
|
||||
if($tmpl = e107::getCoreTemplate('email', $eml['template'], 'front', true)) //FIXME - Core template is failing with template 'notify'. Works with theme template. Issue with core template registry?
|
||||
|
||||
if(is_array($eml['template']) && !empty($eml['template']['plugin']) && !empty($eml['template']['name']) && !empty($eml['template']['key']))
|
||||
{
|
||||
$tmpl = e107::getTemplate($eml['template']['plugin'],$eml['template']['name'], $eml['template']['key']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$tmpl = e107::getCoreTemplate('email', $eml['template'], 'front', true);
|
||||
}
|
||||
|
||||
if(!empty($tmpl)) //FIXME - Core template is failing with template 'notify'. Works with theme template. Issue with core template registry?
|
||||
{
|
||||
$eml['templateHTML'] = $tmpl;
|
||||
$eml['shortcodes'] = $this->processShortcodes($eml);
|
||||
$eml['shortcodes']['_WRAPPER_'] = 'email/'.$eml['template'];
|
||||
|
||||
$emailBody = $tmpl['header']. str_replace('{BODY}', $eml['body'], $tmpl['body']) . $tmpl['footer'];
|
||||
if(is_string($eml['template']))
|
||||
{
|
||||
$eml['shortcodes']['_WRAPPER_'] = 'email/'.$eml['template'];
|
||||
}
|
||||
$emailBody = varset($tmpl['header']). str_replace('{BODY}', $eml['body'], $tmpl['body']) . varset($tmpl['footer']);
|
||||
|
||||
$eml['body'] = $tp->parseTemplate($emailBody, true, $eml['shortcodes']);
|
||||
|
||||
@ -935,7 +947,7 @@ class e107Email extends PHPMailer
|
||||
|
||||
unset($eml['add_html_header']); // disable other headers when template is used.
|
||||
|
||||
$this->Subject = $tp->parseTemplate($tmpl['subject'], true, varset($eml['shortcodes'],null));
|
||||
$this->Subject = $tp->parseTemplate(varset($tmpl['subject'],'{SUBJECT}'), true, varset($eml['shortcodes'],null));
|
||||
|
||||
if($this->debug)
|
||||
{
|
||||
@ -946,7 +958,7 @@ class e107Email extends PHPMailer
|
||||
{
|
||||
if($this->debug)
|
||||
{
|
||||
echo "<h4>Couldn't find email template: ".$eml['template']."</h4>";
|
||||
echo "<h4>Couldn't find email template: ".print_r($eml['template'],true)."</h4>";
|
||||
}
|
||||
// $emailBody = $eml['body'];
|
||||
|
||||
|
@ -9,8 +9,17 @@
|
||||
*/
|
||||
|
||||
|
||||
$_BLANK_WRAPPER['default']['BLANK_TEST'] = "[ {---} ]";
|
||||
$_BLANK_TEMPLATE['default'] = "<div>{BLANK_TEST}</div>";
|
||||
$_BLANK_WRAPPER['default']['BLANK_TEST'] = "[ {---} ]";
|
||||
$_BLANK_TEMPLATE['default'] = "<div>{BLANK_TEST}</div>";
|
||||
|
||||
|
||||
$_BLANK_TEMPLATE['other'] = "<div>{BLANK_TEST}</div>";
|
||||
$_BLANK_TEMPLATE['other'] = "<div>{BLANK_TEST}</div>";
|
||||
$_BLANK_TEMPLATE['other'] = "<div>{BLANK_TEST}</div>";
|
||||
|
||||
/**
|
||||
* Custom Plugin email template
|
||||
* @see https://github.com/e107inc/e107/issues/4919
|
||||
*/
|
||||
$_BLANK_TEMPLATE['email']['header'] = '<html lang="en"><body>';
|
||||
$_BLANK_TEMPLATE['email']['body'] = "<div><span>{NAME}</span> <small>{DATE}</small></div><div>{BODY}</div>";
|
||||
$_BLANK_TEMPLATE['email']['footer'] = '</body></html>';
|
@ -24,7 +24,7 @@
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
$this->assertTrue(false, "Couldn't load e107Email object");
|
||||
$this->fail("Couldn't load e107Email object");
|
||||
}
|
||||
|
||||
|
||||
@ -68,6 +68,64 @@
|
||||
$this->assertStringNotContainsString('{MEDIA1}', $this->eml->Body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test using an email template from e107_plugins/_blank/templates/_blank_template.php
|
||||
* @return void
|
||||
*/
|
||||
public function testArraySetPluginTemplate()
|
||||
{
|
||||
$eml = array(
|
||||
'subject' => "[PLUGIN TEMPLATE EXAMPLE]",
|
||||
'sender_email' => "noreply@test.com",
|
||||
'sender_name' => "Test Person",
|
||||
'replyto' => "",
|
||||
'html' => true,
|
||||
'priority' => 1,
|
||||
'template' => ['plugin'=>'_blank', 'name'=>'_blank', 'key'=>'email'],
|
||||
'body' => "This is the body text",
|
||||
'cc' => '',
|
||||
'shortcodes' => [
|
||||
'NAME' => "TestName",
|
||||
'DATE' => 'Jan 1st, 2020'
|
||||
],
|
||||
);
|
||||
|
||||
$this->eml->arraySet($eml);
|
||||
|
||||
$this->assertStringContainsString("noreply@test.com", $this->eml->From);
|
||||
$this->assertStringContainsString("Test Person", $this->eml->FromName);
|
||||
$this->assertStringContainsString("[PLUGIN TEMPLATE EXAMPLE]", $this->eml->Subject);
|
||||
|
||||
$this->assertStringContainsString('<html lang="en"><body>', $this->eml->Body);
|
||||
|
||||
$this->assertStringContainsString('<div><span>TestName</span> <small>Jan 1st, 2020</small></div><div>This is the body text</div>', $this->eml->Body);
|
||||
$this->assertStringNotContainsString('{MEDIA1}', $this->eml->Body);
|
||||
}
|
||||
|
||||
|
||||
public function testArraySetNotifyTemplate()
|
||||
{
|
||||
$eml = array(
|
||||
'subject' => "[URGENT EXAMPLE]",
|
||||
'sender_email' => "noreply@test.com",
|
||||
'sender_name' => "Test Person",
|
||||
'replyto' => "",
|
||||
'html' => true,
|
||||
'priority' => 1,
|
||||
'template' => 'notify',
|
||||
'body' => "This is the body text",
|
||||
'cc' => ''
|
||||
);
|
||||
|
||||
$this->eml->arraySet($eml);
|
||||
|
||||
$this->assertStringContainsString("noreply@test.com", $this->eml->From);
|
||||
$this->assertStringContainsString("Test Person", $this->eml->FromName);
|
||||
$this->assertStringContainsString("e107: [URGENT EXAMPLE] ", $this->eml->Subject);
|
||||
$this->assertStringContainsString("This is the body text", $this->eml->Body);
|
||||
$this->assertStringContainsString("<div class='unsubscribe'></div>", $this->eml->Body);
|
||||
$this->assertStringNotContainsString('{MEDIA1}', $this->eml->Body);
|
||||
}
|
||||
/*
|
||||
public function testMakePrintableAddress()
|
||||
{
|
||||
@ -89,7 +147,7 @@
|
||||
$html = "\n
|
||||
Hi <b>Joe</b><br />
|
||||
|
||||
Check out <a href='http://e107.org'>http://e107.org</a><br />
|
||||
Check out <a href='https://e107.org'>https://e107.org</a><br />
|
||||
<br />
|
||||
Thanks,<br />
|
||||
Admin<br />
|
||||
@ -106,7 +164,7 @@ Admin<br />
|
||||
$this->eml->MsgHTML($html);
|
||||
|
||||
$result = json_encode($this->eml->AltBody);
|
||||
$expected = '"Hi Joe\\nCheck out http:\\/\\/e107.org\\n\\nThanks,\\nAdmin\\n\\nWebsite:\\thttps:\\/\\/e107.org\\t\\nGithub:\\thttps:\\/\\/github.com\\/e107inc\\/"';
|
||||
$expected = '"Hi Joe\\nCheck out https:\\/\\/e107.org\\n\\nThanks,\\nAdmin\\n\\nWebsite:\\thttps:\\/\\/e107.org\\t\\nGithub:\\thttps:\\/\\/github.com\\/e107inc\\/"';
|
||||
$this->assertSame($expected, $result);
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user