|
4 | 4 |
|
5 | 5 | namespace PhpList\Core\Domain\Messaging\Service\Constructor; |
6 | 6 |
|
| 7 | +use PhpList\Core\Domain\Common\Html2Text; |
7 | 8 | use PhpList\Core\Domain\Common\RemotePageFetcher; |
| 9 | +use PhpList\Core\Domain\Common\TextParser; |
| 10 | +use PhpList\Core\Domain\Configuration\Model\ConfigOption; |
8 | 11 | use PhpList\Core\Domain\Configuration\Service\Manager\EventLogManager; |
| 12 | +use PhpList\Core\Domain\Configuration\Service\Provider\ConfigProvider; |
9 | 13 | use PhpList\Core\Domain\Configuration\Service\UserPersonalizer; |
10 | 14 | use PhpList\Core\Domain\Messaging\Exception\RemotePageFetchException; |
11 | 15 | use PhpList\Core\Domain\Messaging\Model\Dto\MessagePrecacheDto; |
|
14 | 18 | use PhpList\Core\Domain\Subscription\Repository\SubscriberRepository; |
15 | 19 | use Symfony\Component\Mime\Email; |
16 | 20 | // todo: check this class |
17 | | -class PersonalizedContentConstructor |
| 21 | +class MailConstructor |
18 | 22 | { |
19 | 23 | public function __construct( |
20 | 24 | private readonly SubscriberRepository $subscriberRepository, |
21 | 25 | private readonly RemotePageFetcher $remotePageFetcher, |
22 | 26 | private readonly EventLogManager $eventLogManager, |
| 27 | + private readonly ConfigProvider $configProvider, |
| 28 | + private readonly Html2Text $html2Text, |
| 29 | + private readonly TextParser $textParser, |
23 | 30 | private readonly UserPersonalizer $userPersonalizer, |
| 31 | + private readonly bool $forwardAlternativeContent, |
24 | 32 | ) { |
25 | 33 | } |
26 | 34 |
|
27 | 35 | public function build( |
28 | 36 | Message $message, |
29 | 37 | Subscriber $subscriber, |
30 | 38 | MessagePrecacheDto $messagePrecacheDto, |
| 39 | + ?string $hash = null |
31 | 40 | ): Email { |
32 | | - $content = $messagePrecacheDto->content; |
| 41 | + $defaultstyle = $this->configProvider->getValue(ConfigOption::HtmlEmailStyle); |
| 42 | + $adddefaultstyle = 0; |
33 | 43 |
|
| 44 | + $content = $messagePrecacheDto->content; |
| 45 | + $text = []; |
| 46 | + $html = []; |
34 | 47 | if ($messagePrecacheDto->userSpecificUrl) { |
35 | 48 | $userData = $this->subscriberRepository->getDataById($subscriber->getId()); |
36 | 49 | $this->replaceUserSpecificRemoteContent($messagePrecacheDto, $subscriber, $userData); |
37 | 50 | } |
38 | 51 |
|
| 52 | + if ($hash !== 'forwarded') { |
| 53 | + $text['footer'] = $messagePrecacheDto->textFooter; |
| 54 | + $html['footer'] = $messagePrecacheDto->htmlFooter; |
| 55 | + } else { |
| 56 | + //0013076: different content when forwarding 'to a friend' |
| 57 | + if ($this->forwardAlternativeContent) { |
| 58 | + $text['footer'] = stripslashes($messagePrecacheDto->footer); |
| 59 | + } else { |
| 60 | + $text['footer'] = $this->configProvider->getValue(ConfigOption::ForwardFooter); |
| 61 | + } |
| 62 | + $html['footer'] = $text['footer']; |
| 63 | + } |
| 64 | + |
| 65 | + $hasText = !empty($messagePrecacheDto->textContent); |
| 66 | + if ($messagePrecacheDto->htmlFormatted) { |
| 67 | + $textcontent = $hasText ? $messagePrecacheDto->textContent : ($this->html2Text)($content); |
| 68 | + $htmlcontent = $content; |
| 69 | + } else { |
| 70 | + $textcontent = $hasText ? $content : $messagePrecacheDto->textContent; |
| 71 | + $htmlcontent = ($this->textParser)($content); |
| 72 | + } |
| 73 | + |
| 74 | + if ($messagePrecacheDto->template) { |
| 75 | + // template used |
| 76 | + // use only the content of the body element if it is present |
| 77 | + if (preg_match('|<body.*?>(.+)</body>|is', $htmlcontent, $matches)) { |
| 78 | + $htmlcontent = $matches[1]; |
| 79 | + } |
| 80 | + $htmlmessage = str_replace('[CONTENT]', $htmlcontent, $messagePrecacheDto->template); |
| 81 | + } else { |
| 82 | + // no template used |
| 83 | + $htmlmessage = $htmlcontent; |
| 84 | + $adddefaultstyle = 1; |
| 85 | + } |
| 86 | + if ($messagePrecacheDto->templateText) { |
| 87 | + // text template used |
| 88 | + $textmessage = str_replace('[CONTENT]', $textcontent, $messagePrecacheDto->templateText); |
| 89 | + } else { |
| 90 | + // no text template used |
| 91 | + $textmessage = $textcontent; |
| 92 | + } |
39 | 93 |
|
40 | 94 |
|
41 | 95 | $mail = new Email(); |
|
0 commit comments