19 declare(strict_types=1);
46 $mail = parent::initMail();
47 $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 recipients: %s',
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));
70 if ($this->provider->getAttachments() !== []) {
71 $this->
logger->debug(
'Adding attachments ...');
72 foreach ($this->provider->getAttachments() as $attachment) {
75 $this->
appendBody(
"\n------------------------------------------------------------\n");
80 public function send(): bool
84 $lng = $DIC->language();
86 if (!
$ilSetting->get(
'forum_notification',
'0')) {
87 $this->
logger->debug(
'Forum notifications are globally disabled');
92 $this->
logger->debug(
'No notification recipients, nothing to do');
96 $lng->loadLanguageModule(
'forum');
102 case self::TYPE_THREAD_DELETED:
105 $customText = sprintf(
107 $this->provider->getDeletedBy(),
108 $this->provider->getForumTitle()
111 'frm_noti_subject_del_thread',
114 'content_deleted_thread' 119 case self::TYPE_POST_NEW:
122 $customText = sprintf(
124 $this->provider->getForumTitle()
130 case self::TYPE_POST_ACTIVATION:
138 case self::TYPE_POST_ANSWERED:
146 case self::TYPE_POST_UPDATED:
149 $customText = sprintf(
151 $this->provider->getPostUpdateUserName($this->getLanguage()),
152 $this->provider->getForumTitle()
155 'frm_noti_subject_upt_post',
158 'content_post_updated',
159 $this->provider->getPostUpdate()
164 case self::TYPE_POST_CENSORED:
167 $customText = sprintf(
169 $this->provider->getPostUpdateUserName($this->getLanguage()),
170 $this->provider->getForumTitle()
173 'frm_noti_subject_cens_post',
176 'content_censored_post',
177 $this->provider->getPostCensoredDate()
182 case self::TYPE_POST_UNCENSORED:
185 $customText = sprintf(
187 $this->provider->getPostUpdateUserName($this->getLanguage())
190 'frm_noti_subject_uncens_post',
194 $this->provider->getPostCensoredDate()
199 case self::TYPE_POST_DELETED:
202 $customText = sprintf(
204 $this->provider->getDeletedBy(),
205 $this->provider->getForumTitle()
208 'frm_noti_subject_del_post',
211 'content_deleted_post' 225 parent::initLanguage($a_usr_id);
226 $this->
language->loadLanguageModule(
'forum');
243 $ilClientIniFile = $DIC[
'ilClientIniFile'];
245 if (
$type === self::PERMANENT_LINK_FORUM) {
246 $language_text = $this->
getLanguageText(
'forums_notification_show_frm');
247 $forum_parameters = $this->provider->getRefId();
249 $language_text = $this->
getLanguageText(
'forums_notification_show_post');
250 $forum_parameters = $this->provider->getRefId() .
'_' . $this->provider->getThreadId() .
'_' . $this->provider->getPostId();
253 $this->
logger->debug(sprintf(
254 'Building permanent with parameters %s',
258 $posting_link = sprintf(
263 $posting_link .= sprintf(
265 $ilClientIniFile->readVariable(
'client',
'name'),
269 $this->
logger->debug(sprintf(
274 return $posting_link;
279 $pos_message = $this->provider->getPostMessage();
280 if (strip_tags($pos_message) !== $pos_message) {
281 $pos_message = preg_replace(
"/\n/i",
'', $pos_message);
282 $pos_message = preg_replace(
'/<li([^>]*)>/i',
"\n<li$1>", $pos_message);
283 $pos_message = preg_replace(
"/<\/ul([^>]*)>(?!\s*?(<p|<ul))/i",
"</ul$1>\n", $pos_message);
284 $pos_message = preg_replace(
"/<br(\s*)(\/?)>/i",
"\n", $pos_message);
285 $pos_message = preg_replace(
'/<p([^>]*)>/i',
"\n\n", $pos_message);
286 $pos_message = preg_replace(
"/<\/p([^>]*)>/i",
'', $pos_message);
295 string $subjectLanguageId,
301 $this->
createMail($subjectLanguageId, $userId, $customText, $action, $date);
308 string $subjectLanguageId,
314 $this->
createMail($subjectLanguageId, $userId, $customText, $action, $date);
326 if (is_string($date)) {
338 if ($this->provider->providesClosestContainer()) {
340 $this->
getLanguageText(
'frm_noti_obj_' . $this->provider->closestContainer()->getType()) .
': ' .
341 $this->provider->closestContainer()->getTitle()
347 $this->
appendBody($this->
getLanguageText($action) .
": \n------------------------------------------------------------\n");
351 if (is_string($date) && $date !==
'') {
362 if ($this->provider->isPostCensored()) {
363 $message = $this->provider->getCensorshipComment();
367 $this->
appendBody(
"------------------------------------------------------------\n");
374 $container_text =
'';
375 if ($this->provider->providesClosestContainer()) {
376 $container_text =
' (' .
377 $this->
getLanguageText(
'obj_' . $this->provider->closestContainer()->getType()) .
378 ' "' . $this->provider->closestContainer()->getTitle() .
'")';
383 $this->provider->getForumTitle(),
385 $this->provider->getThreadTitle()
394 $date = $this->provider->getPostDate();
const PERMANENT_LINK_FORUM
__construct(private ilForumNotificationMailData $provider, private ilLogger $logger)
appendBody(string $a_body)
const TYPE_POST_ACTIVATION
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
getPermanentLink(string $type=self::PERMANENT_LINK_POST)
const PERMANENT_LINK_POST
createMail(string $subject, int $userId, string $customText, string $action, ?string $date)
initLanguage(int $a_usr_id)
setIsCronjob(bool $is_cronjob)
const TYPE_THREAD_DELETED
static setLanguage(ilLanguage $a_lng)
addMailSubject(string $subject)
static useRelativeDates()
sendMailWithAttachments(string $subjectLanguageId, int $userId, string $customText, string $action, string $date='')
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
createMailDate(string $date)
getLanguageText(string $a_keyword)
sendMailWithoutAttachments(string $subjectLanguageId, int $userId, string $customText, string $action, ?string $date=null)
Interface ilForumNotificationMailData.
setSubject(string $a_subject)
sendMail(array $a_rcp, bool $a_parse_recipients=true)
static setUseRelativeDates(bool $a_status)
set use relative dates
const TYPE_POST_UNCENSORED
static _getInstallationSignature()
setAttachments(array $a_att)