1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-29 10:38:08 +01:00

Fixes #3726 - legacy shortcode wrapper conflict with email template.

This commit is contained in:
Cameron 2020-06-01 17:37:49 -07:00
parent da7e6ee774
commit 1c8e755edf
6 changed files with 101 additions and 14 deletions

View File

@ -96,7 +96,7 @@ $EMAIL_OVERRIDES = array(
// Default - test email and when no template specified.
$EMAIL_TEMPLATE = [];
$EMAIL_TEMPLATE['default']['name'] = 'Default';
$EMAIL_TEMPLATE['default']['subject'] = '{SITENAME}: {SUBJECT} ';
$EMAIL_TEMPLATE['default']['header'] = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">
@ -255,9 +255,9 @@ $EMAIL_TEMPLATE['quickadduser']['body'] = USRLAN_185.USRLAN_186;
$EMAIL_TEMPLATE['quickadduser']['footer'] = $EMAIL_TEMPLATE['default']['footer']; // will use default footer above.
// ------- Notify (@see admin-> notify)
//$EMAIL_WRAPPER['notify']['SUBJECT'] = "*** {---} ***";
// ------- Notify (@see admin-> notify)
$EMAIL_TEMPLATE['notify']['name'] = 'Notify';
$EMAIL_TEMPLATE['notify']['subject'] = '{SITENAME}: {SUBJECT} ';
$EMAIL_TEMPLATE['notify']['header'] = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">
@ -367,4 +367,3 @@ $EMAIL_TEMPLATE['example']['priority'] = 3; // (1 = High, 3 = Normal, 5 = low)
?>

View File

@ -903,13 +903,14 @@ class e107Email extends PHPMailer
if(vartrue($eml['template'])) // @see e107_core/templates/email_template.php
if(!empty($eml['template'])) // @see e107_core/templates/email_template.php
{
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?
{
$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'];

View File

@ -744,6 +744,25 @@ class e_parse_shortcode
return in_array($name, $this->scBatchOverride);
}
/**
* Backward Compatibility for $sc_style wrapper
* @param mixed $extraCodes
*/
private function mergeLegacyWrappers($extraCodes=null)
{
global $sc_style; //legacy, will be removed soon, use the non-global $SC_STYLE instead
if(is_array($extraCodes) && isset($extraCodes['_WRAPPER_'])) // v2.x array wrapper.
{
return null;
}
if(isset($sc_style) && is_array($sc_style)/* && !isset($extraCodes['_WRAPPER_'])*/)
{
$this->sc_style = array_merge($sc_style, $this->sc_style);
}
}
/**
* Parse the shortcodes in some text
*
@ -758,8 +777,6 @@ class e_parse_shortcode
*/
function parseCodes($text, $useSCFiles = true, $extraCodes = null, $eVars = null)
{
global $sc_style; //legacy, will be removed soon, use the non-global $SC_STYLE instead
$saveParseSCFiles = $this->parseSCFiles; // In case of nested call
$this->parseSCFiles = $useSCFiles;
$saveVars = $this->eVars; // In case of nested call
@ -788,10 +805,7 @@ class e_parse_shortcode
*
*/
if(isset($sc_style) && is_array($sc_style))
{
$this->sc_style = array_merge($sc_style, $this->sc_style); // XXX Commenting this out will fix #2 above.
}
$this->mergeLegacyWrappers($extraCodes); // XXX Commenting this out will fix #2 above.
//object support

View File

@ -0,0 +1,19 @@
<?php
/**
* e107 website system
*
* Copyright (C) 2008-2020 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
*/
class plugin__blank__blank_shortcodes extends e_shortcode // plugin_{plugin folder}_{filename without '_shortcodes'}_shortcodes
{
function sc_blank_test()
{
return 'test';
}
}

View File

@ -0,0 +1,13 @@
<?php
/**
* e107 website system
*
* Copyright (C) 2008-2020 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
*/
$_BLANK_WRAPPER['default']['BLANK_TEST'] = "[ {---} ]";
$_BLANK_TEMPLATE['default'] = "<div>{BLANK_TEST}</div>";

View File

@ -63,7 +63,7 @@ class e_parse_shortcodeTest extends \Codeception\Test\Unit
}
*/
public function testParseCodes()
public function testParseCodesWithArray()
{
$text = '<ul class="dropdown-menu {LINK_SUB_OVERSIZED}" role="menu" >';
@ -83,10 +83,51 @@ class e_parse_shortcodeTest extends \Codeception\Test\Unit
'LINK_BADGE' => '',
);
$result = $this->scParser->parseCodes($text, false, $array);
// -- Legacy Wrapper --
global $sc_style;
$sc_style = array();
$sc_style['LINK_SUB_OVERSIZED']['pre'] = "** ";
$sc_style['LINK_SUB_OVERSIZED']['post'] = " **";
$actual = $this->scParser->parseCodes($text, false, $array);
$expected = '<ul class="dropdown-menu ** oversized **" role="menu" >';
$this->assertEquals($expected, $actual);
// v2.x Array Wrapper - should override any $sc_style legacy wrapper
$array['_WRAPPER_'] = "non-existent/template";
$actual = $this->scParser->parseCodes($text, false, $array);
$expected = '<ul class="dropdown-menu oversized" role="menu" >';
$this->assertEquals($expected, $actual);
// var_dump($result);
}
public function testParseCodesWithClass()
{
$sc = e107::getScBatch('_blank', true, '_blank');
$this->assertIsObject($sc);
// - v1.x Wrapper Test.
global $sc_style;
$sc_style = array();
$sc_style['BLANK_TEST']['pre'] = "** ";
$sc_style['BLANK_TEST']['post'] = " **";
$actualTemplate = e107::getTemplate('_blank', '_blank', 'default');
$expectedTemplate = "<div>{BLANK_TEST}</div>";
$this->assertEquals($expectedTemplate, $actualTemplate);
$actualLegacy = $this->scParser->parseCodes($actualTemplate, false, $sc);
$expectedLegacy = "<div>** test **</div>";
$this->assertEquals($expectedLegacy, $actualLegacy);
// - v2.x Wrapper Test.
$sc->wrapper('_blank/default'); // overrides legacy $sc_style;
$actual = $this->scParser->parseCodes($actualTemplate, false, $sc);
$expected = "<div>[ test ]</div>";
$this->assertEquals($expected, $actual);
}
/*
public function testInitShortcodeClass()
{