3 namespace Friendica\Util\EMailer;
6 use Friendica\App\BaseURL;
7 use Friendica\Content\Text\BBCode;
8 use Friendica\Core\Config\IConfig;
9 use Friendica\Core\L10n;
10 use Friendica\Core\Renderer;
11 use Friendica\Network\HTTPException\InternalServerErrorException;
12 use Psr\Log\LoggerInterface;
15 * Builder for notification emails (notification, source, links, ...)
17 class NotifyMailBuilder extends MailBuilder
30 private $contentAllowed = false;
33 /** @var array Details to print a photo:
43 /** @var array HTML/Plain version of the Site Link:
51 /** @var string The item link */
52 private $itemLink = '';
54 public function __construct(L10n $l10n, BaseURL $baseUrl, IConfig $config, LoggerInterface $logger, string $siteEmailAddress, string $siteName)
56 parent::__construct($l10n, $baseUrl, $config, $logger);
58 if ($this->config->get('config', 'admin_name')) {
59 $this->siteAdmin = $l10n->t('%1$s, %2$s Administrator', $this->config->get('config', 'admin_name'), $siteName);
61 $this->siteAdmin = $l10n->t('%s Administrator', $siteName);
64 // Set the system wide site address/name as sender (default for system mails)
65 $this->withSender($siteName, $siteEmailAddress, $siteEmailAddress);
67 // check whether sending post content in email notifications is allowed
68 $this->contentAllowed = !$this->config->get('system', 'enotify_no_content', false);
72 * Adds a notification (in fact a more detailed message)
74 * @param string $subject
75 * @param string $preamble
76 * @param string $title
77 * @param string|null $body
81 public function withNotification(string $subject, string $preamble, string $title, string $body = null)
87 $this->title = stripslashes($title);
88 $this->subject = $subject;
89 $this->preamble = $preamble;
96 * Adds a photo of the source of the notify
98 * @param string $image The image link to the photo
99 * @param string $link The link to the source
100 * @param string $name The name of the source
104 public function withPhoto(string $image, string $link, string $name)
107 'image' => $image ?? '',
108 'link' => $link ?? '',
109 'name' => $name ?? '',
116 * Adds a sitelink to the notification
118 * @param string $text The text version of the site link
119 * @param string $html The html version of the site link
123 public function withSiteLink(string $text, string $html = '')
134 * Adds a link to the item of the notification
136 * @param string $link The text version of the item link
140 public function withItemLink(string $link)
142 $this->itemLink = $link;
150 protected function getSubject()
152 return $this->subject;
158 * @throws InternalServerErrorException
161 protected function getHtmlMessage()
163 $htmlVersion = BBCode::convert($this->body);
165 // load the template for private message notifications
166 $tpl = Renderer::getMarkupTemplate('email/notify/html.tpl');
167 return Renderer::replaceMacros($tpl, [
168 '$preamble' => str_replace("\n", "<br>\n", $this->preamble),
169 '$source_name' => $this->photo['name'],
170 '$source_link' => $this->photo['link'],
171 '$source_photo' => $this->photo['image'],
172 '$hsitelink' => $this->siteLink['html'],
173 '$hitemlink' => sprintf('<a href="%s">%s</a>', $this->itemLink, $this->itemLink),
174 '$thanks' => $this->l10n->t('thanks'),
175 '$site_admin' => $this->siteAdmin,
176 '$title' => $this->title,
177 '$htmlversion' => $htmlVersion,
178 '$content_allowed' => $this->contentAllowed,
188 protected function getPlaintextMessage()
190 $textVersion = BBCode::toPlaintext($this->body);
192 // load the template for private message notifications
193 $tpl = Renderer::getMarkupTemplate('email/notify/text.tpl');
194 return Renderer::replaceMacros($tpl, [
195 '$preamble' => $this->preamble,
196 '$tsitelink' => $this->siteLink['text'],
197 '$titemlink' => $this->itemLink,
198 '$thanks' => $this->l10n->t('thanks'),
199 '$site_admin' => $this->siteAdmin,
200 '$title' => $this->title,
201 '$textversion' => $textVersion,
202 '$content_allowed' => $this->contentAllowed,