19declare(strict_types=1);
45 $mail = parent::initMail();
46 $this->
logger->debug(
'Initialized mail service');
51 public function sendMail(array $a_rcp,
bool $a_parse_recipients =
true): void
53 $this->
logger->debug(sprintf(
54 'Delegating notification transport to mail service for recipient "%s" ...',
55 json_encode($a_rcp, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT)
57 parent::sendMail($a_rcp, $a_parse_recipients);
58 $this->
logger->debug(
'Notification transport delegated');
63 $value = parent::setSubject($a_subject);
64 $this->
logger->debug(sprintf(
'Setting subject to: %s', $a_subject));
69 public function send(): bool
75 if (!
$ilSetting->get(
'forum_notification',
'0')) {
76 $this->
logger->debug(
'Forum notifications are globally disabled');
82 $this->
logger->debug(
'No notification recipients, nothing to do');
87 $lng->loadLanguageModule(
'forum');
98 $customText = sprintf(
100 $this->provider->getDeletedBy(),
101 $this->provider->getForumTitle()
105 'frm_noti_subject_del_thread',
108 'content_deleted_thread'
116 $customText = sprintf(
118 $this->provider->getForumTitle()
122 'frm_noti_subject_new_post',
136 'frm_noti_subject_act_post',
150 'frm_noti_subject_answ_post',
161 $customText = sprintf(
163 $this->provider->getPostUpdateUserName($this->getLanguage()),
164 $this->provider->getForumTitle()
166 $date = $this->provider->getPostUpdate();
169 'frm_noti_subject_upt_post',
172 'content_post_updated',
181 $customText = sprintf(
183 $this->provider->getPostUpdateUserName($this->getLanguage()),
184 $this->provider->getForumTitle()
186 $date = $this->provider->getPostCensoredDate();
189 'frm_noti_subject_cens_post',
192 'content_censored_post',
201 $customText = sprintf(
203 $this->provider->getPostUpdateUserName($this->getLanguage())
205 $date = $this->provider->getPostCensoredDate();
208 'frm_noti_subject_uncens_post',
220 $customText = sprintf(
222 $this->provider->getDeletedBy(),
223 $this->provider->getForumTitle()
227 'frm_noti_subject_del_post',
230 'content_deleted_post'
237 if (
null === $contextId) {
260 parent::initLanguage($a_usr_id);
261 $this->
language->loadLanguageModule(
'forum');
277 $ilClientIniFile =
$DIC[
'ilClientIniFile'];
279 if (
$type === self::PERMANENT_LINK_FORUM) {
280 $language_text = $this->
getLanguageText(
"forums_notification_show_frm");
281 $forum_parameters = $this->provider->getRefId();
283 $language_text = $this->
getLanguageText(
"forums_notification_show_post");
284 $forum_parameters = $this->provider->getRefId() .
"_" . $this->provider->getThreadId() .
"_" . $this->provider->getPostId();
287 $this->
logger->debug(sprintf(
288 'Building permanent with parameters %s',
292 $posting_link = sprintf(
296 $posting_link .= sprintf(
298 $ilClientIniFile->readVariable(
"client",
"name"),
302 $this->
logger->debug(sprintf(
307 return $posting_link;
312 $pos_message = $this->provider->getPostMessage() ??
'';
313 if (strip_tags($pos_message) !== $pos_message) {
314 $pos_message = preg_replace(
"/\n/i",
"", $pos_message);
315 $pos_message = preg_replace(
"/<li([^>]*)>/i",
"\n<li$1>", $pos_message);
316 $pos_message = preg_replace(
"/<\/ul([^>]*)>(?!\s*?(<p|<ul))/i",
"</ul$1>\n", $pos_message);
317 $pos_message = preg_replace(
"/<br(\s*)(\/?)>/i",
"\n", $pos_message);
318 $pos_message = preg_replace(
"/<p([^>]*)>/i",
"\n\n", $pos_message);
319 return preg_replace(
"/<\/p([^>]*)>/i",
'', $pos_message);
334 string $subjectLanguageId,
335 int $recipientUserId,
351 $bodyText .= $attachmentText;
354 $bodyText .= $attachmentText;
361 ilStr::strLen($subjectText) > 255 ? ilStr::substr($subjectText, 0, 255) : $subjectText,
363 $this->provider->getAttachments(),
373 string $subjectLanguageId,
374 int $recipientUserId,
379 $subjectText = $this->createSubjectText($subjectLanguageId);
381 $bodyText = $this->createMailBodyText(
394 ilStr::strLen($subjectText) > 255 ? ilStr::substr($subjectText, 0, 255) : $subjectText,
409 $date = $this->createMailDate($date);
411 $this->addMailSubject($subject);
416 $body .= $customText;
418 $body .= $this->getLanguageText(
'forum') .
": " . $this->provider->getForumTitle();
420 if ($this->provider->providesClosestContainer()) {
421 $body .= $this->getLanguageText(
'obj_' . $this->provider->closestContainer()->getType()) .
": " . $this->provider->closestContainer()->getTitle();
424 $body .= $this->getLanguageText(
'thread') .
": " . $this->provider->getThreadTitle();
426 $body .= $this->getLanguageText($action) .
": \n------------------------------------------------------------\n";
428 $body .= $this->getLanguageText(
'author') .
": " . $this->provider->getPostUserName($this->
getLanguage());
430 $body .= $this->getLanguageText(
'date') .
": " . $date;
432 $body .= $this->getLanguageText(
'subject') .
": " . $this->provider->getPostTitle();
434 $body .= $this->getLanguageText(
'frm_noti_message');
437 $message = strip_tags($this->getPostMessage());
439 if ($this->provider->isPostCensored()) {
440 $message = $this->provider->getCensorshipComment();
445 return $body .
"------------------------------------------------------------\n";
450 $attachmentText =
'';
451 if ($this->provider->getAttachments() !== []) {
452 $this->
logger->debug(
'Adding attachments ...');
453 foreach ($this->provider->getAttachments() as $attachment) {
454 $attachmentText .= $this->getLanguageText(
'attachment') .
": " . $attachment .
"\n";
456 $attachmentText .=
"\n------------------------------------------------------------\n";
459 return $attachmentText;
464 $body = $this->getPermanentLink();
473 $this->setSubject($this->createSubjectText($subject));
481 $date = $this->provider->getPostDate();
489 $container_text =
'';
490 if ($this->provider->providesClosestContainer()) {
491 $container_text =
" (" . $this->getLanguageText(
'frm_noti_obj_' . $this->provider->closestContainer()->getType()) .
492 " \"" . $this->provider->closestContainer()->getTitle() .
"\")";
496 $this->getLanguageText($subject),
497 $this->provider->getForumTitle(),
499 $this->provider->getThreadTitle()
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
createAttachmentLinkText()
const string PERMANENT_LINK_FORUM
const int TYPE_POST_CENSORED
createSubjectText(string $subject)
const int TYPE_POST_UPDATED
createMailBodyText(string $subject, int $userId, string $customText, string $action, string $date)
const string PERMANENT_LINK_POST
createMailValueObjectsWithAttachments(string $subjectLanguageId, int $recipientUserId, string $customText, string $action, string $date='')
Add body and send mail with attachments.
const int TYPE_THREAD_DELETED
createMailValueObjectWithoutAttachments(string $subjectLanguageId, int $recipientUserId, string $customText, string $action, string $date='')
Add body and send mail without attachments.
sendMail(array $a_rcp, bool $a_parse_recipients=true)
initLanguage(int $a_usr_id)
setIsCronjob(bool $is_cronjob)
__construct(protected ilForumNotificationMailData $provider, protected ilLogger $logger)
const int TYPE_POST_ANSWERED
addMailSubject(string $subject)
setSubject(string $a_subject)
getPermanentLink(string $type=self::PERMANENT_LINK_POST)
const int TYPE_POST_UNCENSORED
const int TYPE_POST_DELETED
createMailDate(string $date)
const int TYPE_POST_ACTIVATION
Component logger with individual log levels by component id.
getLanguageText(string $a_keyword)
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
static _getInstallationSignature()
static _lookupLogin(int $a_user_id)
static strLen(string $a_string)
Interface ilForumNotificationMailData.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc