19declare(strict_types=1);
48 $mail = parent::initMail();
49 $this->
logger->debug(
'Initialized mail service');
53 public function sendMail(array $a_rcp,
bool $a_parse_recipients =
true): void
57 'Delegating notification transport to mail service for recipients: %s',
61 parent::sendMail($a_rcp, $a_parse_recipients);
62 $this->
logger->debug(
'Notification transport delegated');
67 $value = parent::setSubject($a_subject);
68 $this->
logger->debug(sprintf(
'Setting subject to: %s', $a_subject));
74 if ($this->provider->getAttachments() !== []) {
75 $this->
logger->debug(
'Adding attachments ...');
76 foreach ($this->provider->getAttachments() as $attachment) {
79 $this->
appendBody(
"\n------------------------------------------------------------\n");
84 public function send(): bool
90 if (!
$ilSetting->get(
'forum_notification',
'0')) {
91 $this->
logger->debug(
'Forum notifications are globally disabled');
96 $this->
logger->debug(
'No notification recipients, nothing to do');
100 $lng->loadLanguageModule(
'forum');
109 $customText = sprintf(
111 $this->provider->getDeletedBy(),
112 $this->provider->getForumTitle()
115 'frm_noti_subject_del_thread',
118 'content_deleted_thread'
126 $customText = sprintf(
128 $this->provider->getForumTitle()
153 $customText = sprintf(
155 $this->provider->getPostUpdateUserName($this->getLanguage()),
156 $this->provider->getForumTitle()
159 'frm_noti_subject_upt_post',
162 'content_post_updated',
163 $this->provider->getPostUpdate()
171 $customText = sprintf(
173 $this->provider->getPostUpdateUserName($this->getLanguage()),
174 $this->provider->getForumTitle()
177 'frm_noti_subject_cens_post',
180 'content_censored_post',
181 $this->provider->getPostCensoredDate()
189 $customText = sprintf(
191 $this->provider->getPostUpdateUserName($this->getLanguage())
194 'frm_noti_subject_uncens_post',
198 $this->provider->getPostCensoredDate()
206 $customText = sprintf(
208 $this->provider->getDeletedBy(),
209 $this->provider->getForumTitle()
212 'frm_noti_subject_del_post',
215 'content_deleted_post'
229 parent::initLanguage($a_usr_id);
230 $this->
language->loadLanguageModule(
'forum');
247 $ilClientIniFile =
$DIC[
'ilClientIniFile'];
249 if (
$type === self::PERMANENT_LINK_FORUM) {
250 $language_text = $this->
getLanguageText(
'forums_notification_show_frm');
251 $forum_parameters = $this->provider->getRefId();
253 $language_text = $this->
getLanguageText(
'forums_notification_show_post');
254 $forum_parameters = implode(
'_', [
255 $this->provider->getRefId(),
256 $this->provider->getThreadId(),
257 $this->provider->getPostId()
263 'Building permanent with parameters %s',
268 $posting_link = sprintf(
273 $posting_link .= sprintf(
275 $ilClientIniFile->readVariable(
'client',
'name'),
286 return $posting_link;
291 $pos_message = $this->provider->getPostMessage() ??
'';
292 if (strip_tags($pos_message) !== $pos_message) {
293 $pos_message = preg_replace(
"/\n/i",
'', $pos_message);
294 $pos_message = preg_replace(
'/<li([^>]*)>/i',
"\n<li$1>", $pos_message);
295 $pos_message = preg_replace(
"/<\/ul([^>]*)>(?!\s*?(<p|<ul))/i",
"</ul$1>\n", $pos_message);
296 $pos_message = preg_replace(
"/<br(\s*)(\/?)>/i",
"\n", $pos_message);
297 $pos_message = preg_replace(
'/<p([^>]*)>/i',
"\n\n", $pos_message);
298 $pos_message = preg_replace(
"/<\/p([^>]*)>/i",
'', $pos_message);
307 string $subjectLanguageId,
313 $this->
createMail($subjectLanguageId, $userId, $customText, $action, $date);
320 string $subjectLanguageId,
326 $this->createMail($subjectLanguageId, $userId, $customText, $action, $date);
327 $this->addLinkToMail();
328 $this->sendMail([$userId]);
338 if (is_string($date)) {
339 $date = $this->createMailDate($date);
342 $this->addMailSubject($subject);
345 $this->appendBody(
"\n\n");
346 $this->appendBody($customText);
347 $this->appendBody(
"\n\n");
348 $this->appendBody($this->getLanguageText(
'forum') .
': ' . $this->provider->getForumTitle());
349 $this->appendBody(
"\n\n");
350 if ($this->provider->providesClosestContainer()) {
352 $this->getLanguageText(
'frm_noti_obj_' . $this->provider->closestContainer()->getType()) .
': ' .
353 $this->provider->closestContainer()->getTitle()
355 $this->appendBody(
"\n\n");
357 $this->appendBody($this->getLanguageText(
'thread') .
': ' . $this->provider->getThreadTitle());
358 $this->appendBody(
"\n\n");
360 $this->getLanguageText($action) .
": \n------------------------------------------------------------\n"
364 $this->getLanguageText(
'author') .
': ' . $this->provider->getPostUserName($this->getLanguage())
366 $this->appendBody(
"\n");
367 if (is_string($date) && $date !==
'') {
368 $this->appendBody($this->getLanguageText(
'date') .
': ' . $date);
369 $this->appendBody(
"\n");
371 $this->appendBody($this->getLanguageText(
'subject') .
': ' . $this->provider->getPostTitle());
372 $this->appendBody(
"\n");
373 $this->appendBody($this->getLanguageText(
'frm_noti_message'));
374 $this->appendBody(
"\n");
376 $message = strip_tags($this->getPostMessage());
378 if ($this->provider->isPostCensored()) {
379 $message = $this->provider->getCensorshipComment();
383 $this->appendBody(
"------------------------------------------------------------\n");
390 $container_text =
'';
391 if ($this->provider->providesClosestContainer()) {
392 $container_text =
' (' .
393 $this->getLanguageText(
'obj_' . $this->provider->closestContainer()->getType()) .
394 ' "' . $this->provider->closestContainer()->getTitle() .
'")';
399 $this->getLanguageText($subject),
400 $this->provider->getForumTitle(),
402 $this->provider->getThreadTitle()
412 $date = $this->provider->getPostDate();
420 $this->appendBody($this->getPermanentLink());
static useRelativeDates()
static setUseRelativeDates(bool $a_status)
set use relative dates
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
static setLanguage(ilLanguage $a_lng)
@classDescription Date and time handling
const TYPE_POST_UNCENSORED
const string PERMANENT_LINK_POST
setIsCronjob(bool $is_cronjob)
initLanguage(int $a_usr_id)
addMailSubject(string $subject)
sendMail(array $a_rcp, bool $a_parse_recipients=true)
sendMailWithAttachments(string $subjectLanguageId, int $userId, string $customText, string $action, string $date='')
createMail(string $subject, int $userId, string $customText, string $action, ?string $date)
setSubject(string $a_subject)
sendMailWithoutAttachments(string $subjectLanguageId, int $userId, string $customText, string $action, ?string $date=null)
const TYPE_THREAD_DELETED
const TYPE_POST_ACTIVATION
createMailDate(string $date)
const string PERMANENT_LINK_FORUM
__construct(private readonly ilForumNotificationMailData $provider, private readonly ilLogger $logger)
getPermanentLink(string $type=self::PERMANENT_LINK_POST)
Component logger with individual log levels by component id.
getLanguageText(string $a_keyword)
appendBody(string $a_body)
setAttachments(array $a_att)
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
static _getInstallationSignature()
Interface ilForumNotificationMailData.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
if(!file_exists('../ilias.ini.php'))