19declare(strict_types=1);
50 $mail = parent::initMail();
51 $this->
logger->debug(
'Initialized mail service');
56 public function sendMail(array $a_rcp,
bool $a_parse_recipients =
true): void
58 $this->
logger->debug(sprintf(
59 'Delegating notification transport to mail service for recipient "%s" ...',
60 json_encode($a_rcp, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT)
62 parent::sendMail($a_rcp, $a_parse_recipients);
63 $this->
logger->debug(
'Notification transport delegated');
68 $value = parent::setSubject($a_subject);
69 $this->
logger->debug(sprintf(
'Setting subject to: %s', $a_subject));
74 public function send(): bool
80 if (!
$ilSetting->get(
'forum_notification',
'0')) {
81 $this->
logger->debug(
'Forum notifications are globally disabled');
87 $this->
logger->debug(
'No notification recipients, nothing to do');
92 $lng->loadLanguageModule(
'forum');
103 $customText = sprintf(
105 $this->provider->getDeletedBy(),
106 $this->provider->getForumTitle()
110 'frm_noti_subject_del_thread',
113 'content_deleted_thread'
121 $customText = sprintf(
123 $this->provider->getForumTitle()
127 'frm_noti_subject_new_post',
141 'frm_noti_subject_act_post',
155 'frm_noti_subject_answ_post',
166 $customText = sprintf(
168 $this->provider->getPostUpdateUserName($this->getLanguage()),
169 $this->provider->getForumTitle()
171 $date = $this->provider->getPostUpdate();
174 'frm_noti_subject_upt_post',
177 'content_post_updated',
186 $customText = sprintf(
188 $this->provider->getPostUpdateUserName($this->getLanguage()),
189 $this->provider->getForumTitle()
191 $date = $this->provider->getPostCensoredDate();
194 'frm_noti_subject_cens_post',
197 'content_censored_post',
206 $customText = sprintf(
208 $this->provider->getPostUpdateUserName($this->getLanguage())
210 $date = $this->provider->getPostCensoredDate();
213 'frm_noti_subject_uncens_post',
225 $customText = sprintf(
227 $this->provider->getDeletedBy(),
228 $this->provider->getForumTitle()
232 'frm_noti_subject_del_post',
235 'content_deleted_post'
242 if (
null === $contextId) {
265 parent::initLanguage($a_usr_id);
266 $this->
language->loadLanguageModule(
'forum');
282 $ilClientIniFile =
$DIC[
'ilClientIniFile'];
284 if (
$type === self::PERMANENT_LINK_FORUM) {
285 $language_text = $this->
getLanguageText(
"forums_notification_show_frm");
286 $forum_parameters = $this->provider->getRefId();
288 $language_text = $this->
getLanguageText(
"forums_notification_show_post");
289 $forum_parameters = $this->provider->getRefId() .
"_" . $this->provider->getThreadId() .
"_" . $this->provider->getPostId();
292 $this->
logger->debug(sprintf(
293 'Building permanent with parameters %s',
297 $posting_link = sprintf(
301 $posting_link .= sprintf(
303 $ilClientIniFile->readVariable(
"client",
"name"),
307 $this->
logger->debug(sprintf(
312 return $posting_link;
317 $pos_message = $this->provider->getPostMessage();
318 if (strip_tags($pos_message) !== $pos_message) {
319 $pos_message = preg_replace(
"/\n/i",
"", $pos_message);
320 $pos_message = preg_replace(
"/<li([^>]*)>/i",
"\n<li$1>", $pos_message);
321 $pos_message = preg_replace(
"/<\/ul([^>]*)>(?!\s*?(<p|<ul))/i",
"</ul$1>\n", $pos_message);
322 $pos_message = preg_replace(
"/<br(\s*)(\/?)>/i",
"\n", $pos_message);
323 $pos_message = preg_replace(
"/<p([^>]*)>/i",
"\n\n", $pos_message);
324 return preg_replace(
"/<\/p([^>]*)>/i",
'', $pos_message);
340 string $subjectLanguageId,
341 int $recipientUserId,
357 $bodyText .= $attachmentText;
360 $bodyText .= $attachmentText;
367 ilStr::strLen($subjectText) > 255 ? ilStr::substr($subjectText, 0, 255) : $subjectText,
369 $this->provider->getAttachments(),
385 string $subjectLanguageId,
386 int $recipientUserId,
391 $subjectText = $this->createSubjectText($subjectLanguageId);
393 $bodyText = $this->createMailBodyText(
406 ilStr::strLen($subjectText) > 255 ? ilStr::substr($subjectText, 0, 255) : $subjectText,
421 $date = $this->createMailDate($date);
423 $this->addMailSubject($subject);
428 $body .= $customText;
430 $body .= $this->getLanguageText(
'forum') .
": " . $this->provider->getForumTitle();
432 if ($this->provider->providesClosestContainer()) {
433 $body .= $this->getLanguageText(
'obj_' . $this->provider->closestContainer()->getType()) .
": " . $this->provider->closestContainer()->getTitle();
436 $body .= $this->getLanguageText(
'thread') .
": " . $this->provider->getThreadTitle();
438 $body .= $this->getLanguageText($action) .
": \n------------------------------------------------------------\n";
440 $body .= $this->getLanguageText(
'author') .
": " . $this->provider->getPostUserName($this->
getLanguage());
442 $body .= $this->getLanguageText(
'date') .
": " . $date;
444 $body .= $this->getLanguageText(
'subject') .
": " . $this->provider->getPostTitle();
446 $body .= $this->getLanguageText(
'frm_noti_message');
449 $message = strip_tags($this->getPostMessage());
451 if ($this->provider->isPostCensored()) {
452 $message = $this->provider->getCensorshipComment();
456 $body .=
"------------------------------------------------------------\n";
463 $attachmentText =
'';
464 if (count($this->provider->getAttachments()) > 0) {
465 $this->
logger->debug(
'Adding attachments ...');
466 foreach ($this->provider->getAttachments() as $attachment) {
467 $attachmentText .= $this->getLanguageText(
'attachment') .
": " . $attachment .
"\n";
469 $attachmentText .=
"\n------------------------------------------------------------\n";
472 return $attachmentText;
477 $body = $this->getPermanentLink();
487 $this->setSubject($this->createSubjectText($subject));
495 $date = $this->provider->getPostDate();
503 $container_text =
'';
504 if ($this->provider->providesClosestContainer()) {
505 $container_text =
" (" . $this->getLanguageText(
'frm_noti_obj_' . $this->provider->closestContainer()->getType()) .
506 " \"" . $this->provider->closestContainer()->getTitle() .
"\")";
510 $this->getLanguageText($subject),
511 $this->provider->getForumTitle(),
513 $this->provider->getThreadTitle()
static useRelativeDates()
static setUseRelativeDates(bool $a_status)
set use relative dates
static setLanguage(ilLanguage $a_lng)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling
createAttachmentLinkText()
const TYPE_POST_UNCENSORED
const PERMANENT_LINK_POST
createSubjectText(string $subject)
ilForumNotificationMailData $provider
createMailBodyText(string $subject, int $userId, string $customText, string $action, string $date)
createMailValueObjectsWithAttachments(string $subjectLanguageId, int $recipientUserId, string $customText, string $action, string $date='')
Add body and send mail with attachments.
__construct(ilForumNotificationMailData $provider, ilLogger $logger)
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)
const TYPE_THREAD_DELETED
addMailSubject(string $subject)
setSubject(string $a_subject)
const PERMANENT_LINK_FORUM
const TYPE_POST_ACTIVATION
getPermanentLink(string $type=self::PERMANENT_LINK_POST)
createMailDate(string $date)
Component logger with individual log levels by component id.
Base class for course/group mail notifications.
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