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 Friendica\Util\Emailer;
15 * Builder for system-wide emails without any dependency to concrete entities (like items, activities, ..)
17 class SystemMailBuilder extends MailBuilder
29 public function __construct(L10n $l10n, BaseURL $baseUrl, IConfig $config)
31 parent::__construct($l10n, $baseUrl, $config);
33 $siteName = $this->config->get('config', 'sitename');
35 if ($this->config->get('config', 'admin_name')) {
36 $this->siteAdmin = $l10n->t('%1$s, %2$s Administrator', $this->config->get('config', 'admin_name'), $siteName);
38 $this->siteAdmin = $l10n->t('%s Administrator', $siteName);
45 * @param string $subject The subject of the email
46 * @param string $preamble The preamble of the email
47 * @param string|null $body The body of the email (if not set, the preamble will get used as body)
51 public function withMessage(string $subject, string $preamble, string $body = null)
57 $this->subject = $subject;
58 $this->preamble = $preamble;
67 protected function getSubject()
69 return $this->subject;
75 * @throws InternalServerErrorException
78 protected function getHtmlMessage()
80 $htmlVersion = BBCode::convert($this->body);
82 // load the template for private message notifications
83 $tpl = Renderer::getMarkupTemplate('email/system/html.tpl');
84 return Renderer::replaceMacros($tpl, [
85 '$preamble' => str_replace("\n", "<br>\n", $this->preamble),
86 '$thanks' => $this->l10n->t('thanks'),
87 '$site_admin' => $this->siteAdmin,
88 '$htmlversion' => $htmlVersion,
97 protected function getPlaintextMessage()
99 $textVersion = BBCode::toPlaintext($this->body);
101 // load the template for private message notifications
102 $tpl = Renderer::getMarkupTemplate('email/system/text.tpl');
103 return Renderer::replaceMacros($tpl, [
104 '$preamble' => $this->preamble,
105 '$thanks' => $this->l10n->t('thanks'),
106 '$site_admin' => $this->siteAdmin,
107 '$textversion' => $textVersion,