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 SystemMailBuilder
19 private $contentAllowed = true;
22 /** @var array Details to print a photo:
32 /** @var array HTML/Plain version of the Site Link:
40 /** @var string The item link */
41 private $itemLink = '';
43 public function __construct(L10n $l10n, BaseURL $baseUrl, IConfig $config, string $siteEmailAddress, string $siteName)
45 parent::__construct($l10n, $baseUrl, $config, $siteEmailAddress, $siteName);
47 // check whether sending post content in email notifications is allowed
48 $this->contentAllowed = $this->config->get('system', 'enotify_no_content');
52 * Adds a notification (in fact a more detailed message)
54 * @param string $subject
55 * @param string $preamble
56 * @param string $title
57 * @param string|null $body
61 public function withNotification(string $subject, string $preamble, string $title, string $body = null)
63 $this->title = stripslashes($title);
65 return $this->withMessage($subject, $preamble, $body);
69 * Adds a photo of the source of the notify
71 * @param string $image The image link to the photo
72 * @param string $link The link to the source
73 * @param string $name The name of the source
77 public function withPhoto(string $image, string $link, string $name)
80 'image' => $image ?? '',
81 'link' => $link ?? '',
82 'name' => $name ?? '',
89 * Adds a sitelink to the notification
91 * @param string $text The text version of the site link
92 * @param string $html The html version of the site link
96 public function withSiteLink(string $text, string $html = '')
107 * Adds a link to the item of the notification
109 * @param string $link The text version of the item link
113 public function withItemLink(string $link)
115 $this->itemLink = $link;
123 protected function getSubject()
125 return $this->subject;
131 * @throws InternalServerErrorException
134 protected function getHtmlMessage()
136 $htmlVersion = BBCode::convert($this->body);
138 // load the template for private message notifications
139 $tpl = Renderer::getMarkupTemplate('email/notify/html.tpl');
140 return Renderer::replaceMacros($tpl, [
141 '$preamble' => str_replace("\n", "<br>\n", $this->preamble),
142 '$source_name' => $this->photo['name'],
143 '$source_link' => $this->photo['link'],
144 '$source_photo' => $this->photo['image'],
145 '$hsitelink' => $this->siteLink['html'],
146 '$hitemlink' => sprintf('<a href="%s">%s</a>', $this->itemLink, $this->itemLink),
147 '$thanks' => $this->l10n->t('thanks'),
148 '$site_admin' => $this->siteAdmin,
149 '$title' => $this->title,
150 '$htmlversion' => $htmlVersion,
151 '$content_allowed' => $this->contentAllowed,
161 protected function getPlaintextMessage()
163 $textVersion = BBCode::toPlaintext($this->body);
165 // load the template for private message notifications
166 $tpl = Renderer::getMarkupTemplate('email/notify/text.tpl');
167 return Renderer::replaceMacros($tpl, [
168 '$preamble' => $this->preamble,
169 '$tsitelink' => $this->siteLink['text'],
170 '$titemlink' => $this->itemLink,
171 '$thanks' => $this->l10n->t('thanks'),
172 '$site_admin' => $this->siteAdmin,
173 '$title' => $this->title,
174 '$textversion' => $textVersion,
175 '$content_allowed' => $this->contentAllowed,