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;
14 * Builder for notification emails (notification, source, links, ...)
16 class NotifyMailBuilder extends MailBuilder
29 private $contentAllowed = true;
32 /** @var array Details to print a photo:
42 /** @var array HTML/Plain version of the Site Link:
50 /** @var string The item link */
51 private $itemLink = '';
53 public function __construct(L10n $l10n, BaseURL $baseUrl, IConfig $config, string $siteEmailAddress, string $siteName)
55 parent::__construct($l10n, $baseUrl, $config);
57 if ($this->config->get('config', 'admin_name')) {
58 $this->siteAdmin = $l10n->t('%1$s, %2$s Administrator', $this->config->get('config', 'admin_name'), $siteName);
60 $this->siteAdmin = $l10n->t('%s Administrator', $siteName);
63 // Set the system wide site address/name as sender (default for system mails)
64 $this->withSender($siteName, $siteEmailAddress, $siteEmailAddress);
66 // check whether sending post content in email notifications is allowed
67 $this->contentAllowed = $this->config->get('system', 'enotify_no_content');
71 * Adds a notification (in fact a more detailed message)
73 * @param string $subject
74 * @param string $preamble
75 * @param string $title
76 * @param string|null $body
80 public function withNotification(string $subject, string $preamble, string $title, string $body = null)
86 $this->title = stripslashes($title);
87 $this->subject = $subject;
88 $this->preamble = $preamble;
95 * Adds a photo of the source of the notify
97 * @param string $image The image link to the photo
98 * @param string $link The link to the source
99 * @param string $name The name of the source
103 public function withPhoto(string $image, string $link, string $name)
106 'image' => $image ?? '',
107 'link' => $link ?? '',
108 'name' => $name ?? '',
115 * Adds a sitelink to the notification
117 * @param string $text The text version of the site link
118 * @param string $html The html version of the site link
122 public function withSiteLink(string $text, string $html = '')
133 * Adds a link to the item of the notification
135 * @param string $link The text version of the item link
139 public function withItemLink(string $link)
141 $this->itemLink = $link;
149 protected function getSubject()
151 return $this->subject;
157 * @throws InternalServerErrorException
160 protected function getHtmlMessage()
162 $htmlVersion = BBCode::convert($this->body);
164 // load the template for private message notifications
165 $tpl = Renderer::getMarkupTemplate('email/notify/html.tpl');
166 return Renderer::replaceMacros($tpl, [
167 '$preamble' => str_replace("\n", "<br>\n", $this->preamble),
168 '$source_name' => $this->photo['name'],
169 '$source_link' => $this->photo['link'],
170 '$source_photo' => $this->photo['image'],
171 '$hsitelink' => $this->siteLink['html'],
172 '$hitemlink' => sprintf('<a href="%s">%s</a>', $this->itemLink, $this->itemLink),
173 '$thanks' => $this->l10n->t('thanks'),
174 '$site_admin' => $this->siteAdmin,
175 '$title' => $this->title,
176 '$htmlversion' => $htmlVersion,
177 '$content_allowed' => $this->contentAllowed,
187 protected function getPlaintextMessage()
189 $textVersion = BBCode::toPlaintext($this->body);
191 // load the template for private message notifications
192 $tpl = Renderer::getMarkupTemplate('email/notify/text.tpl');
193 return Renderer::replaceMacros($tpl, [
194 '$preamble' => $this->preamble,
195 '$tsitelink' => $this->siteLink['text'],
196 '$titemlink' => $this->itemLink,
197 '$thanks' => $this->l10n->t('thanks'),
198 '$site_admin' => $this->siteAdmin,
199 '$title' => $this->title,
200 '$textversion' => $textVersion,
201 '$content_allowed' => $this->contentAllowed,