ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilForumMailNotification.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once './Services/Mail/classes/class.ilMailNotification.php';
5
12{
14
15 const TYPE_POST_NEW = 60;
22
23 const PERMANENT_LINK_POST = 'PL_Post';
24 const PERMANENT_LINK_FORUM = 'PL_Forum';
25
29 protected $is_cronjob = false;
30
34 protected $provider;
35
39 protected $logger;
40
47 {
48 parent::__construct(false);
49 $this->provider = $provider;
50 $this->logger = $logger;
51 }
52
56 protected function initMail()
57 {
58 $mail = parent::initMail();
59 $this->logger->debug('Initialized mail service');
60 return $mail;
61 }
62
66 public function sendMail(array $a_rcp, $a_type, $a_parse_recipients = true)
67 {
68 $this->logger->debug('Delegating notification transport to mail service ...');
69 parent::sendMail($a_rcp, $a_type, $a_parse_recipients);
70 $this->logger->debug('Notification transport delegated');
71 }
72
76 protected function setSubject($a_subject)
77 {
78 $value = parent::setSubject($a_subject);
79 $this->logger->debug(sprintf('Setting subject to: %s', $a_subject));
80 return $value;
81 }
82
86 protected function appendAttachments()
87 {
88 if (count($this->provider->getAttachments()) > 0) {
89 $this->logger->debug('Adding attachments ...');
90 foreach ($this->provider->getAttachments() as $attachment) {
91 $this->appendBody($this->getLanguageText('attachment') . ": " . $attachment . "\n");
92 }
93 $this->appendBody("\n------------------------------------------------------------\n");
94 $this->setAttachments($this->provider->getAttachments());
95 }
96 }
97
101 public function send()
102 {
103 global $DIC;
104 $ilSetting = $DIC->settings();
105 $lng = $DIC->language();
106
107 if (!$ilSetting->get('forum_notification', 0)) {
108 $this->logger->debug('Forum notifications are globally disabled');
109 return false;
110 }
111
112 if (!$this->getRecipients()) {
113 $this->logger->debug('No notification recipients, nothing to do');
114 return false;
115 }
116
117 $lng->loadLanguageModule('forum');
118
121
122 switch ($this->getType()) {
124 foreach ($this->getRecipients() as $rcp) {
125 $this->initLanguage($rcp);
126 ilDatePresentation::setLanguage($this->language);
127
128 $this->initMail();
129
130 $this->setSubject(sprintf(
131 $this->getLanguageText('frm_noti_subject_del_thread'),
132 $this->provider->getForumTitle(),
133 $this->provider->getThreadTitle()
134 ));
135
136 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
137 $this->appendBody("\n\n");
138 $this->appendBody(sprintf($this->getLanguageText('thread_deleted_by'), $this->provider->getDeletedBy(), $this->provider->getForumTitle()));
139 $this->appendBody("\n\n");
140 $this->appendBody($this->getLanguageText('forum') . ": " . $this->provider->getForumTitle());
141 $this->appendBody("\n\n");
142 $this->appendBody($this->getLanguageText('thread') . ": " . $this->provider->getThreadTitle());
143 $this->appendBody("\n\n");
144 $this->appendBody($this->getLanguageText('content_deleted_thread') . "\n------------------------------------------------------------\n");
145
146 $this->appendBody($this->getLanguageText('author') . ": " . $this->provider->getPostUserName($this->getLanguage()));
147 $this->appendBody("\n");
148
149 $post_date = ilDatePresentation::formatDate(new ilDateTime($this->provider->getPostDate(), IL_CAL_DATETIME));
150 $this->appendBody($this->getLanguageText('date') . ": " . $post_date);
151 $this->appendBody("\n");
152 $this->appendBody($this->getLanguageText('subject') . ": " . $this->provider->getPostTitle());
153 $this->appendBody("\n");
154 $this->appendBody($this->getLanguageText('frm_noti_message'));
155 $this->appendBody("\n");
156
157 if ($this->provider->getPostCensored() == 1) {
158 $this->appendBody($this->provider->getCensorshipComment() . "\n");
159 } else {
160 $pos_message = $this->getSecurePostMessage();
161 $this->appendBody(strip_tags($pos_message) . "\n");
162 }
163 $this->appendBody("------------------------------------------------------------\n");
164
165 $this->appendBody($this->getPermanentLink(self::PERMANENT_LINK_FORUM));
167
168 $this->sendMail(array($rcp), array('system'));
169 }
170 break;
171
173 foreach ($this->getRecipients() as $rcp) {
174 $this->initLanguage($rcp);
175 ilDatePresentation::setLanguage($this->language);
176
177 $this->initMail();
178
179 $this->setSubject(sprintf(
180 $this->getLanguageText('frm_noti_subject_new_post'),
181 $this->provider->getForumTitle(),
182 $this->provider->getThreadTitle()
183 ));
184
185 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
186 $this->appendBody("\n\n");
187 $this->appendBody(sprintf($this->getLanguageText('frm_noti_new_post'), $this->provider->getForumTitle()));
188 $this->appendBody("\n\n");
189 $this->appendBody($this->getLanguageText('forum') . ": " . $this->provider->getForumTitle());
190 $this->appendBody("\n\n");
191 $this->appendBody($this->getLanguageText('thread') . ": " . $this->provider->getThreadTitle());
192 $this->appendBody("\n\n");
193 $this->appendBody($this->getLanguageText('new_post') . ": \n------------------------------------------------------------\n");
194
195 $this->appendBody($this->getLanguageText('author') . ": " . $this->provider->getPostUserName($this->getLanguage()));
196 $this->appendBody("\n");
197 $this->appendBody($this->getLanguageText('date') . ": " . ilDatePresentation::formatDate(new ilDateTime($this->provider->getPostDate(), IL_CAL_DATETIME)));
198 $this->appendBody("\n");
199 $this->appendBody($this->getLanguageText('subject') . ": " . $this->provider->getPostTitle());
200 $this->appendBody("\n");
201 $this->appendBody($this->getLanguageText('frm_noti_message'));
202 $this->appendBody("\n");
203
204 if ($this->provider->getPostCensored() == 1) {
205 $this->appendBody($this->provider->getCensorshipComment() . "\n");
206 } else {
207 $pos_message = $this->getSecurePostMessage();
208 $this->appendBody(strip_tags($pos_message) . "\n");
209 }
210 $this->appendBody("------------------------------------------------------------\n");
211
212 $this->appendAttachments();
213
214 $this->appendBody($this->getPermanentLink());
216
217 $this->sendMail(array($rcp), array('system'));
218 }
219 break;
220
222 foreach ($this->getRecipients() as $rcp) {
223 $this->initLanguage($rcp);
224 ilDatePresentation::setLanguage($this->language);
225
226 $this->initMail();
227
228 $this->setSubject(sprintf(
229 $this->getLanguageText('frm_noti_subject_act_post'),
230 $this->provider->getForumTitle(),
231 $this->provider->getThreadTitle()
232 ));
233
234 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
235 $this->appendBody("\n\n");
236
237 $this->appendBody($this->getLanguageText('forums_post_activation_mail'));
238 $this->appendBody("\n\n");
239 $this->appendBody($this->getLanguageText('forum') . ": " . $this->provider->getForumTitle());
240 $this->appendBody("\n\n");
241 $this->appendBody($this->getLanguageText('thread') . ": " . $this->provider->getThreadTitle());
242 $this->appendBody("\n\n");
243 $this->appendBody($this->getLanguageText('new_post') . ": \n------------------------------------------------------------\n");
244
245 $this->appendBody($this->getLanguageText('author') . ": " . $this->provider->getPostUserName($this->getLanguage()));
246 $this->appendBody("\n");
247 $this->appendBody($this->getLanguageText('date') . ": " . ilDatePresentation::formatDate(new ilDateTime($this->provider->getPostDate(), IL_CAL_DATETIME)));
248 $this->appendBody("\n");
249 $this->appendBody($this->getLanguageText('subject') . ": " . $this->provider->getPostTitle());
250 $this->appendBody("\n");
251 $this->appendBody($this->getLanguageText('frm_noti_message'));
252 $this->appendBody("\n");
253
254 if ($this->provider->getPostCensored() == 1) {
255 $this->appendBody($this->provider->getCensorshipComment() . "\n");
256 } else {
257 $pos_message = $this->getSecurePostMessage();
258 $this->appendBody(strip_tags($pos_message) . "\n");
259 }
260 $this->appendBody("------------------------------------------------------------\n");
261
262 $this->appendAttachments();
263
264 $this->appendBody($this->getPermanentLink());
266
267 $this->sendMail(array($rcp), array('system'));
268 }
269 break;
270
272 foreach ($this->getRecipients() as $rcp) {
273 $this->initLanguage($rcp);
274 ilDatePresentation::setLanguage($this->language);
275
276 $this->initMail();
277
278 $this->setSubject(sprintf(
279 $this->getLanguageText('frm_noti_subject_answ_post'),
280 $this->provider->getForumTitle(),
281 $this->provider->getThreadTitle()
282 ));
283
284 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
285 $this->appendBody("\n\n");
286
287 $this->appendBody($this->getLanguageText('forum_post_replied'));
288 $this->appendBody("\n\n");
289 $this->appendBody($this->getLanguageText('forum') . ": " . $this->provider->getForumTitle());
290
291 $this->appendBody("\n\n");
292 $this->appendBody($this->getLanguageText('thread') . ": " . $this->provider->getThreadTitle());
293 $this->appendBody("\n\n");
294 $this->appendBody($this->getLanguageText('new_post') . ": \n------------------------------------------------------------\n");
295
296 $this->appendBody($this->getLanguageText('author') . ": " . $this->provider->getPostUserName($this->getLanguage()));
297 $this->appendBody("\n");
298 $this->appendBody($this->getLanguageText('date') . ": " . ilDatePresentation::formatDate(new ilDateTime($this->provider->getPostDate(), IL_CAL_DATETIME)));
299 $this->appendBody("\n");
300 $this->appendBody($this->getLanguageText('subject') . ": " . $this->provider->getPostTitle());
301 $this->appendBody("\n");
302 $this->appendBody($this->getLanguageText('frm_noti_message'));
303 $this->appendBody("\n");
304
305 if ($this->provider->getPostCensored() == 1) {
306 $this->appendBody($this->provider->getCensorshipComment() . "\n");
307 } else {
308 $pos_message = $this->getSecurePostMessage();
309 $this->appendBody(strip_tags($pos_message) . "\n");
310 }
311 $this->appendBody("------------------------------------------------------------\n");
312
313 $this->appendAttachments();
314
315 $this->appendBody($this->getPermanentLink());
317
318 $this->sendMail(array($rcp), array('system'));
319 }
320 break;
321
323 foreach ($this->getRecipients() as $rcp) {
324 $this->initLanguage($rcp);
325 ilDatePresentation::setLanguage($this->language);
326
327 $this->initMail();
328
329 $this->setSubject(sprintf(
330 $this->getLanguageText('frm_noti_subject_upt_post'),
331 $this->provider->getForumTitle(),
332 $this->provider->getThreadTitle()
333 ));
334
335 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
336 $this->appendBody("\n\n");
337 $this->appendBody(sprintf($this->getLanguageText('post_updated_by'), $this->provider->getPostUpdateUserName($this->getLanguage()), $this->provider->getForumTitle()));
338 $this->appendBody("\n\n");
339 $this->appendBody($this->getLanguageText('forum') . ": " . $this->provider->getForumTitle());
340 $this->appendBody("\n\n");
341 $this->appendBody($this->getLanguageText('thread') . ": " . $this->provider->getThreadTitle());
342 $this->appendBody("\n\n");
343 $this->appendBody($this->getLanguageText('content_post_updated') . "\n------------------------------------------------------------\n");
344
345 $this->appendBody($this->getLanguageText('author') . ": " . $this->provider->getPostUserName($this->getLanguage()));
346 $this->appendBody("\n");
347 $this->appendBody($this->getLanguageText('date') . ": " . ilDatePresentation::formatDate(new ilDateTime($this->provider->getPostUpdate(), IL_CAL_DATETIME)));
348 $this->appendBody("\n");
349 $this->appendBody($this->getLanguageText('subject') . ": " . $this->provider->getPostTitle());
350 $this->appendBody("\n");
351 $this->appendBody($this->getLanguageText('frm_noti_message'));
352 $this->appendBody("\n");
353
354 if ($this->provider->getPostCensored() == 1) {
355 $this->appendBody($this->provider->getCensorshipComment() . "\n");
356 } else {
357 $pos_message = $this->getSecurePostMessage();
358 $this->appendBody(strip_tags($pos_message) . "\n");
359 }
360 $this->appendBody("------------------------------------------------------------\n");
361
362 $this->appendAttachments();
363
364 $this->appendBody($this->getPermanentLink());
366
367 $this->sendMail(array($rcp), array('system'));
368 }
369 break;
370
372 foreach ($this->getRecipients() as $rcp) {
373 $this->initLanguage($rcp);
374 ilDatePresentation::setLanguage($this->language);
375
376 $this->initMail();
377
378 $this->setSubject(sprintf(
379 $this->getLanguageText('frm_noti_subject_cens_post'),
380 $this->provider->getForumTitle(),
381 $this->provider->getThreadTitle()
382 ));
383
384 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
385 $this->appendBody("\n\n");
386 $this->appendBody(sprintf($this->getLanguageText('post_censored_by'), $this->provider->getPostUpdateUserName($this->getLanguage()), $this->provider->getForumTitle()));
387 $this->appendBody("\n\n");
388 $this->appendBody($this->getLanguageText('forum') . ": " . $this->provider->getForumTitle());
389 $this->appendBody("\n\n");
390 $this->appendBody($this->getLanguageText('thread') . ": " . $this->provider->getThreadTitle());
391 $this->appendBody("\n\n");
392 $this->appendBody($this->getLanguageText('content_censored_post') . "\n------------------------------------------------------------\n");
393
394 $this->appendBody($this->getLanguageText('author') . ": " . $this->provider->getPostUserName($this->getLanguage()));
395 $this->appendBody("\n");
396 $this->appendBody($this->getLanguageText('date') . ": " . ilDatePresentation::formatDate(new ilDateTime($this->provider->getPostCensoredDate(), IL_CAL_DATETIME)));
397 $this->appendBody("\n");
398 $this->appendBody($this->getLanguageText('subject') . ": " . $this->provider->getPostTitle());
399 $this->appendBody("\n");
400 $this->appendBody($this->getLanguageText('frm_noti_message'));
401 $this->appendBody("\n");
402
403 if ($this->provider->getPostCensored() == 1) {
404 $this->appendBody($this->provider->getCensorshipComment() . "\n");
405 } else {
406 $pos_message = $this->getSecurePostMessage();
407 $this->appendBody(strip_tags($pos_message) . "\n");
408 }
409 $this->appendBody("------------------------------------------------------------\n");
410
411 $this->appendAttachments();
412
413 $this->appendBody($this->getPermanentLink());
415
416 $this->sendMail(array($rcp), array('system'));
417 }
418 break;
420 foreach ($this->getRecipients() as $rcp) {
421 $this->initLanguage($rcp);
422 ilDatePresentation::setLanguage($this->language);
423
424 $this->initMail();
425
426 $this->setSubject(sprintf(
427 $this->getLanguageText('frm_noti_subject_uncens_post'),
428 $this->provider->getForumTitle(),
429 $this->provider->getThreadTitle()
430 ));
431
432 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
433 $this->appendBody("\n\n");
434 $this->appendBody(sprintf($this->getLanguageText('post_uncensored_by'), $this->provider->getPostUpdateUserName($this->getLanguage())));
435 $this->appendBody("\n\n");
436 $this->appendBody($this->getLanguageText('forum') . ": " . $this->provider->getForumTitle());
437 $this->appendBody("\n\n");
438 $this->appendBody($this->getLanguageText('thread') . ": " . $this->provider->getThreadTitle());
439 $this->appendBody("\n\n");
440 $this->appendBody($this->getLanguageText('forums_the_post') . "\n------------------------------------------------------------\n");
441
442 $this->appendBody($this->getLanguageText('author') . ": " . $this->provider->getPostUserName($this->getLanguage()));
443 $this->appendBody("\n");
444 $this->appendBody($this->getLanguageText('date') . ": " . ilDatePresentation::formatDate(new ilDateTime($this->provider->getPostCensoredDate(), IL_CAL_DATETIME)));
445 $this->appendBody("\n");
446 $this->appendBody($this->getLanguageText('subject') . ": " . $this->provider->getPostTitle());
447 $this->appendBody("\n");
448 $this->appendBody($this->getLanguageText('frm_noti_message'));
449 $this->appendBody("\n");
450
451 $pos_message = $this->getSecurePostMessage();
452 $this->appendBody(strip_tags($pos_message) . "\n");
453
454 $this->appendBody("------------------------------------------------------------\n");
455
456 $this->appendAttachments();
457
458 $this->appendBody($this->getPermanentLink());
460
461 $this->sendMail(array($rcp), array('system'));
462 }
463 break;
464
466 foreach ($this->getRecipients() as $rcp) {
467 $this->initLanguage($rcp);
468 ilDatePresentation::setLanguage($this->language);
469
470 $this->initMail();
471
472 $this->setSubject(sprintf(
473 $this->getLanguageText('frm_noti_subject_del_post'),
474 $this->provider->getForumTitle(),
475 $this->provider->getThreadTitle()
476 ));
477
478 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
479 $this->appendBody("\n\n");
480 $this->appendBody(sprintf($this->getLanguageText('post_deleted_by'), $this->provider->getDeletedBy(), $this->provider->getForumTitle()));
481 $this->appendBody("\n\n");
482 $this->appendBody($this->getLanguageText('forum') . ": " . $this->provider->getForumTitle());
483 $this->appendBody("\n\n");
484 $this->appendBody($this->getLanguageText('thread') . ": " . $this->provider->getThreadTitle());
485 $this->appendBody("\n\n");
486 $this->appendBody($this->getLanguageText('content_deleted_post') . "\n------------------------------------------------------------\n");
487
488 $this->appendBody($this->getLanguageText('author') . ": " . $this->provider->getPostUserName($this->getLanguage()));
489 $this->appendBody("\n");
490
491 $post_date = ilDatePresentation::formatDate(new ilDateTime($this->provider->getPostDate(), IL_CAL_DATETIME));
492 $this->appendBody($this->getLanguageText('date') . ": " . $post_date);
493 $this->appendBody("\n");
494 $this->appendBody($this->getLanguageText('subject') . ": " . $this->provider->getPostTitle());
495 $this->appendBody("\n");
496 $this->appendBody($this->getLanguageText('frm_noti_message'));
497 $this->appendBody("\n");
498
499 if ($this->provider->getPostCensored() == 1) {
500 $this->appendBody($this->provider->getCensorshipComment() . "\n");
501 } else {
502 $pos_message = $this->getSecurePostMessage();
503 $this->appendBody(strip_tags($pos_message) . "\n");
504 }
505 $this->appendBody("------------------------------------------------------------\n");
506
507 $this->appendBody($this->getPermanentLink(self::PERMANENT_LINK_FORUM));
509
510 $this->sendMail(array($rcp), array('system'));
511 }
512 break;
513 }
514
517
518 return true;
519 }
520
524 protected function initLanguage($a_usr_id)
525 {
526 parent::initLanguage($a_usr_id);
527 $this->language->loadLanguageModule('forum');
528 }
529
533 public function isCronjob()
534 {
535 return (bool) $this->is_cronjob;
536 }
537
541 public function setIsCronjob($is_cronjob)
542 {
543 $this->is_cronjob = (bool) $is_cronjob;
544 }
545
550 private function getPermanentLink($type = self::PERMANENT_LINK_POST)
551 {
552 global $DIC;
553 $ilClientIniFile = $DIC['ilClientIniFile'];
554
555 if ($type == self::PERMANENT_LINK_FORUM) {
556 $language_text = $this->getLanguageText("forums_notification_show_frm");
557 $forum_parameters = $this->provider->getRefId();
558 } else {
559 $language_text = $this->getLanguageText("forums_notification_show_post");
560 $forum_parameters = $this->provider->getRefId() . "_" . $this->provider->getThreadId() . "_" . $this->provider->getPostId();
561 }
562
563 $this->logger->debug(sprintf(
564 'Building permanent with parameters %s',
565 $forum_parameters
566 ));
567
568 if ($this->isCronjob()) {
569 $posting_link = sprintf(
570 $language_text,
571 ilUtil::_getHttpPath() . "/goto.php?target=frm_" . $forum_parameters . '&client_id=' . CLIENT_ID
572 ) . "\n\n";
573
574 $posting_link .= sprintf(
575 $this->getLanguageText("forums_notification_intro"),
576 $ilClientIniFile->readVariable("client", "name"),
577 ilUtil::_getHttpPath() . '/?client_id=' . CLIENT_ID
578 ) . "\n\n";
579 } else {
580 $posting_link = sprintf(
581 $language_text,
582 ilUtil::_getHttpPath() . "/goto.php?target=frm_" . $forum_parameters . '&client_id=' . CLIENT_ID
583 ) . "\n\n";
584
585 $posting_link .= sprintf(
586 $this->getLanguageText("forums_notification_intro"),
587 $ilClientIniFile->readVariable("client", "name"),
588 ilUtil::_getHttpPath() . '/?client_id=' . CLIENT_ID
589 ) . "\n\n";
590 }
591
592 $this->logger->debug(sprintf(
593 'Link built: %s',
594 $posting_link
595 ));
596
597 return $posting_link;
598 }
599
603 private function getSecurePostMessage()
604 {
605 $pos_message = $this->provider->getPostMessage();
606 if (strip_tags($pos_message) != $pos_message) {
607 $pos_message = preg_replace("/\n/i", "", $pos_message);
608 $pos_message = preg_replace("/<br(\s*)(\/?)>/i", "\n", $pos_message);
609 $pos_message = preg_replace("/<p([^>]*)>/i", "\n\n", $pos_message);
610 $pos_message = preg_replace("/<\/p([^>]*)>/i", '', $pos_message);
611 return $pos_message;
612 }
613 return strip_tags($pos_message);
614 }
615}
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATETIME
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date @access public.
static setLanguage($a_lng)
set language
static setUseRelativeDates($a_status)
set use relative dates
static useRelativeDates()
check if relative dates are used
@classDescription Date and time handling
getPermanentLink($type=self::PERMANENT_LINK_POST)
__construct(ilForumNotificationMailData $provider, \ilLogger $logger)
ilForumMailNotification constructor.
sendMail(array $a_rcp, $a_type, $a_parse_recipients=true)
Component logger with individual log levels by component id.
Base class for course/group mail notifications.
appendBody($a_body)
Append body text.
getType()
Get notification type.
getRecipients()
get array of recipients
setAttachments($a_att)
Set attachments.
static _getInstallationSignature()
static getSalutation($a_usr_id, ilLanguage $a_language=null)
static _getHttpPath()
Interface ilForumNotificationMailData.
global $lng
Definition: privfeed.php:17
global $ilSetting
Definition: privfeed.php:17
global $DIC
Definition: saml.php:7
$a_type
Definition: workflow.php:92