19 declare(strict_types=1);
50 $mail = parent::initMail();
51 $this->
logger->debug(
'Initialized mail service');
55 public function sendMail(array $a_rcp,
bool $a_parse_recipients =
true): void
57 $this->
logger->debug(sprintf(
58 '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 (count($this->provider->getAttachments()) > 0) {
75 $this->
logger->debug(
'Adding attachments ...');
76 foreach ($this->provider->getAttachments() as $attachment) {
79 $this->
appendBody(
"\n------------------------------------------------------------\n");
84 public function send(): bool
88 $lng = $DIC->language();
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');
106 case self::TYPE_THREAD_DELETED:
109 $customText = sprintf(
111 $this->provider->getDeletedBy(),
112 $this->provider->getForumTitle()
115 'frm_noti_subject_del_thread',
118 'content_deleted_thread' 123 case self::TYPE_POST_NEW:
126 $customText = sprintf(
128 $this->provider->getForumTitle()
134 case self::TYPE_POST_ACTIVATION:
142 case self::TYPE_POST_ANSWERED:
150 case self::TYPE_POST_UPDATED:
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()
168 case self::TYPE_POST_CENSORED:
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()
186 case self::TYPE_POST_UNCENSORED:
189 $customText = sprintf(
191 $this->provider->getPostUpdateUserName($this->getLanguage())
194 'frm_noti_subject_uncens_post',
198 $this->provider->getPostCensoredDate()
203 case self::TYPE_POST_DELETED:
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 = $this->provider->getRefId() .
"_" . $this->provider->getThreadId() .
"_" . $this->provider->getPostId();
257 $this->
logger->debug(sprintf(
258 'Building permanent with parameters %s',
262 $posting_link = sprintf(
267 $posting_link .= sprintf(
269 $ilClientIniFile->readVariable(
"client",
"name"),
273 $this->
logger->debug(sprintf(
278 return $posting_link;
283 $pos_message = $this->provider->getPostMessage();
284 if (strip_tags($pos_message) !== $pos_message) {
285 $pos_message = preg_replace(
"/\n/i",
"", $pos_message);
286 $pos_message = preg_replace(
"/<li([^>]*)>/i",
"\n<li$1>", $pos_message);
287 $pos_message = preg_replace(
"/<\/ul([^>]*)>(?!\s*?(<p|<ul))/i",
"</ul$1>\n", $pos_message);
288 $pos_message = preg_replace(
"/<br(\s*)(\/?)>/i",
"\n", $pos_message);
289 $pos_message = preg_replace(
"/<p([^>]*)>/i",
"\n\n", $pos_message);
290 $pos_message = preg_replace(
"/<\/p([^>]*)>/i",
'', $pos_message);
299 string $subjectLanguageId,
305 $this->
createMail($subjectLanguageId, $userId, $customText, $action, $date);
312 string $subjectLanguageId,
318 $this->
createMail($subjectLanguageId, $userId, $customText, $action, $date);
330 if (is_string($date)) {
342 if ($this->provider->providesClosestContainer()) {
344 $this->
getLanguageText(
'frm_noti_obj_' . $this->provider->closestContainer()->getType()) .
": " .
345 $this->provider->closestContainer()->getTitle()
351 $this->
appendBody($this->
getLanguageText($action) .
": \n------------------------------------------------------------\n");
355 if (is_string($date) && $date !==
'') {
366 if ($this->provider->isPostCensored()) {
367 $message = $this->provider->getCensorshipComment();
371 $this->
appendBody(
"------------------------------------------------------------\n");
378 $container_text =
'';
379 if ($this->provider->providesClosestContainer()) {
380 $container_text =
" (" .
381 $this->
getLanguageText(
'obj_' . $this->provider->closestContainer()->getType()) .
382 " \"" . $this->provider->closestContainer()->getTitle() .
"\")";
387 $this->provider->getForumTitle(),
389 $this->provider->getThreadTitle()
398 $date = $this->provider->getPostDate();
const PERMANENT_LINK_FORUM
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='')
Base class for course/group mail notifications.
ilForumNotificationMailData $provider
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.
__construct(Container $dic, ilPlugin $plugin)
setSubject(string $a_subject)
sendMail(array $a_rcp, bool $a_parse_recipients=true)
static setUseRelativeDates(bool $a_status)
set use relative dates
__construct(ilForumNotificationMailData $provider, ilLogger $logger)
const TYPE_POST_UNCENSORED
static _getInstallationSignature()
setAttachments(array $a_att)