Inital commit

This commit is contained in:
2020-11-19 15:36:28 +01:00
parent 71f32f83d3
commit 66ce4ee218
18077 changed files with 2166122 additions and 35184 deletions

View File

@@ -2,13 +2,12 @@
namespace Thelia\Model;
use Thelia\Core\Template\Exception\ResourceNotFoundException;
use Thelia\Model\Base\Message as BaseMessage;
use Propel\Runtime\Connection\ConnectionInterface;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Event\Message\MessageEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Template\Exception\ResourceNotFoundException;
use Thelia\Core\Template\ParserInterface;
use Thelia\Core\Template\TemplateHelper;
use Thelia\Model\Base\Message as BaseMessage;
class Message extends BaseMessage
{
@@ -70,16 +69,21 @@ class Message extends BaseMessage
/**
* Calculate the message body, given the HTML entered in the back-office, the message layout, and the message template
* @param ParserInterface $parser
* @param $message
* @param $layout
* @param $template
* @return bool
*/
protected function getMessageBody($parser, $message, $layout, $template)
protected function getMessageBody($parser, $message, $layout, $template, $compressOutput = true)
{
$body = false;
// Try to get the body from template file, if a file is defined
if (! empty($template)) {
try {
$body = $parser->render($template);
$body = $parser->render($template, [], $compressOutput);
} catch (ResourceNotFoundException $ex) {
// Ignore this.
}
@@ -87,17 +91,16 @@ class Message extends BaseMessage
// We did not get it ? Use the message entered in the back-office
if ($body === false) {
$body = $parser->renderString($message);
$body = $parser->renderString($message, [], $compressOutput);
}
// Do we have a layout ?
if (! empty($layout)) {
// Populate the message body variable
$parser->assign('message_body', $body);
// Render the layout file
$body = $parser->render($layout);
$body = $parser->render($layout, [], $compressOutput);
}
return $body;
@@ -109,10 +112,10 @@ class Message extends BaseMessage
public function getHtmlMessageBody(ParserInterface $parser)
{
return $this->getMessageBody(
$parser,
$this->getHtmlMessage(),
$this->getHtmlLayoutFileName(),
$this->getHtmlTemplateFileName()
$parser,
$this->getHtmlMessage(),
$this->getHtmlLayoutFileName(),
$this->getHtmlTemplateFileName()
);
}
@@ -121,21 +124,37 @@ class Message extends BaseMessage
*/
public function getTextMessageBody(ParserInterface $parser)
{
return $this->getMessageBody(
$parser,
$this->getTextMessage(),
$this->getTextLayoutFileName(),
$this->getTextTemplateFileName()
$message = $this->getMessageBody(
$parser,
$this->getTextMessage(),
$this->getTextLayoutFileName(),
$this->getTextTemplateFileName(),
true // Do not compress the output, and keep empty lines.
);
// Replaced all <br> by newlines.
return preg_replace("/<br>/i", "\n", $message);
}
/**
* Add a subject and a body (TEXT, HTML or both, depending on the message
* configuration.
*
* @param ParserInterface $parser
* @param \Swift_Message $messageInstance
* @param bool $useFallbackTemplate When we send mail from a module and don't use the `default` email
* template, if the file (html/txt) is not found in the template then
* the template file located in the module under
* `templates/email/default/' directory is used if
* `$useFallbackTemplate` is set to `true`.
*/
public function buildMessage($parser, \Swift_Message $messageInstance)
public function buildMessage(ParserInterface $parser, \Swift_Message $messageInstance, $useFallbackTemplate = true)
{
$parser->setTemplateDefinition(TemplateHelper::getInstance()->getActiveMailTemplate());
$parser->setTemplateDefinition(
$parser->getTemplateHelper()->getActiveMailTemplate(),
$useFallbackTemplate
);
$subject = $parser->fetch(sprintf("string:%s", $this->getSubject()));
$htmlMessage = $this->getHtmlMessageBody($parser);
$textMessage = $this->getTextMessageBody($parser);