ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 
4 include_once './Services/Mail/classes/class.ilMailNotification.php';
5 
12 {
13  const TYPE_THREAD_DELETED = 54;
14 
15  const TYPE_POST_NEW = 60;
17  const TYPE_POST_UPDATED = 62;
18  const TYPE_POST_CENSORED = 63;
19  const TYPE_POST_DELETED = 64;
20  const TYPE_POST_ANSWERED = 65;
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 
40  {
41  parent::__construct();
42  $this->provider = $provider;
43  }
44 
48  public function send()
49  {
55  global $ilSetting, $lng, $ilUser;
56 
57  if(!$ilSetting->get('forum_notification', 0))
58  {
59  return false;
60  }
61 
62  if(!$this->getRecipients())
63  {
64  return false;
65  }
66 
67  $lng->loadLanguageModule('forum');
68 
71 
72  switch($this->getType())
73  {
74  case self::TYPE_THREAD_DELETED:
75  foreach($this->getRecipients() as $rcp)
76  {
77  $this->initLanguage($rcp);
78  ilDatePresentation::setLanguage($this->language);
79 
80  $this->initMail();
81 
82  $this->setSubject(sprintf(
83  $this->getLanguageText('frm_noti_subject_del_thread'),
84  $this->provider->getForumTitle(),
85  $this->provider->getThreadTitle()
86  ));
87 
88  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
89  $this->appendBody("\n\n");
90  $this->appendBody(sprintf($this->getLanguageText('thread_deleted_by'), $ilUser->getLogin(), $this->provider->getForumTitle()));
91  $this->appendBody("\n\n");
92  $this->appendBody($this->getLanguageText('forum') . ": " . $this->provider->getForumTitle());
93  $this->appendBody("\n\n");
94  $this->appendBody($this->getLanguageText('thread') . ": " . $this->provider->getThreadTitle());
95  $this->appendBody("\n\n");
96  $this->appendBody($this->getLanguageText('content_deleted_thread') ."\n------------------------------------------------------------\n");
97 
98  $this->appendBody($this->getLanguageText('author') . ": " . $this->provider->getPostUserName($this->getLanguage()));
99  $this->appendBody("\n");
100 
101  $post_date = ilDatePresentation::formatDate(new ilDateTime($this->provider->getPostDate(), IL_CAL_DATETIME));
102  $this->appendBody($this->getLanguageText('date') . ": " . $post_date);
103  $this->appendBody("\n");
104  $this->appendBody($this->getLanguageText('subject') . ": " . $this->provider->getPostTitle());
105  $this->appendBody("\n");
106  $this->appendBody($this->getLanguageText('frm_noti_message'));
107  $this->appendBody("\n");
108 
109  if($this->provider->getPostCensored() == 1)
110  {
111  $this->appendBody($this->provider->getCensorshipComment() . "\n");
112  }
113  else
114  {
115  $pos_message = $this->getSecurePostMessage();
116  $this->appendBody(strip_tags($pos_message) . "\n");
117  }
118  $this->appendBody("------------------------------------------------------------\n");
119 
120  $this->appendBody($this->getPermanentLink(self::PERMANENT_LINK_FORUM));
122 
123  $this->sendMail(array($rcp), array('system'));
124  }
125  break;
126 
127  case self::TYPE_POST_NEW:
128  foreach($this->getRecipients() as $rcp)
129  {
130  $this->initLanguage($rcp);
131  ilDatePresentation::setLanguage($this->language);
132 
133  $this->initMail();
134 
135  $this->setSubject(sprintf(
136  $this->getLanguageText('frm_noti_subject_new_post'),
137  $this->provider->getForumTitle(),
138  $this->provider->getThreadTitle()
139  ));
140 
141  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
142  $this->appendBody("\n\n");
143  $this->appendBody(sprintf($this->getLanguageText('frm_noti_new_post'), $this->provider->getForumTitle()));
144  $this->appendBody("\n\n");
145  $this->appendBody($this->getLanguageText('forum').": ".$this->provider->getForumTitle());
146  $this->appendBody("\n\n");
147  $this->appendBody($this->getLanguageText('thread').": ".$this->provider->getThreadTitle());
148  $this->appendBody("\n\n");
149  $this->appendBody($this->getLanguageText('new_post').": \n------------------------------------------------------------\n");
150 
151  $this->appendBody($this->getLanguageText('author').": ". $this->provider->getPostUserName($this->getLanguage()));
152  $this->appendBody("\n");
153  $this->appendBody($this->getLanguageText('date').": ". ilDatePresentation::formatDate(new ilDateTime($this->provider->getPostDate(), IL_CAL_DATETIME)));
154  $this->appendBody("\n");
155  $this->appendBody($this->getLanguageText('subject').": ". $this->provider->getPostTitle());
156  $this->appendBody("\n");
157  $this->appendBody($this->getLanguageText('frm_noti_message'));
158  $this->appendBody("\n");
159 
160  if($this->provider->getPostCensored() == 1)
161  {
162  $this->appendBody($this->provider->getCensorshipComment() . "\n");
163  }
164  else
165  {
166  $pos_message = $this->getSecurePostMessage();
167  $this->appendBody(strip_tags($pos_message) . "\n");
168  }
169  $this->appendBody("------------------------------------------------------------\n");
170 
171  if(count($this->provider->getAttachments()) > 0)
172  {
173  foreach($this->provider->getAttachments() as $attachment)
174  {
175  $this->appendBody($this->getLanguageText('attachment') . ": " . $attachment . "\n");
176  }
177  $this->appendBody("\n------------------------------------------------------------\n");
178  }
179 
180  $this->appendBody($this->getPermanentLink());
182 
183  $this->sendMail(array($rcp), array('system'));
184 
185  }
186  break;
187 
188  case self::TYPE_POST_ACTIVATION:
189  foreach($this->getRecipients() as $rcp)
190  {
191  $this->initLanguage($rcp);
192  ilDatePresentation::setLanguage($this->language);
193 
194  $this->initMail();
195 
196  $this->setSubject(sprintf(
197  $this->getLanguageText('frm_noti_subject_act_post'),
198  $this->provider->getForumTitle(),
199  $this->provider->getThreadTitle()
200  ));
201 
202  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
203  $this->appendBody("\n\n");
204 
205  $this->appendBody($this->getLanguageText('forums_post_activation_mail'));
206  $this->appendBody("\n\n");
207  $this->appendBody($this->getLanguageText('forum').": ".$this->provider->getForumTitle());
208  $this->appendBody("\n\n");
209  $this->appendBody($this->getLanguageText('thread').": ".$this->provider->getThreadTitle());
210  $this->appendBody("\n\n");
211  $this->appendBody($this->getLanguageText('new_post').": \n------------------------------------------------------------\n");
212 
213  $this->appendBody($this->getLanguageText('author').": ". $this->provider->getPostUserName($this->getLanguage()));
214  $this->appendBody("\n");
215  $this->appendBody($this->getLanguageText('date').": ". ilDatePresentation::formatDate(new ilDateTime($this->provider->getPostDate(), IL_CAL_DATETIME)));
216  $this->appendBody("\n");
217  $this->appendBody($this->getLanguageText('subject').": ". $this->provider->getPostTitle());
218  $this->appendBody("\n");
219  $this->appendBody($this->getLanguageText('frm_noti_message'));
220  $this->appendBody("\n");
221 
222  if($this->provider->getPostCensored() == 1)
223  {
224  $this->appendBody($this->provider->getCensorshipComment() . "\n");
225  }
226  else
227  {
228  $pos_message = $this->getSecurePostMessage();
229  $this->appendBody(strip_tags($pos_message) . "\n");
230  }
231  $this->appendBody("------------------------------------------------------------\n");
232 
233  if(count($this->provider->getAttachments()) > 0)
234  {
235  foreach($this->provider->getAttachments() as $attachment)
236  {
237  $this->appendBody($this->getLanguageText('attachment') . ": " . $attachment . "\n");
238  }
239  $this->appendBody("\n------------------------------------------------------------\n");
240  }
241 
242  $this->appendBody($this->getPermanentLink());
244 
245  $this->sendMail(array($rcp), array('system'));
246  }
247  break;
248 
249  case self::TYPE_POST_ANSWERED;
250  foreach($this->getRecipients() as $rcp)
251  {
252  $this->initLanguage($rcp);
253  ilDatePresentation::setLanguage($this->language);
254 
255  $this->initMail();
256 
257  $this->setSubject(sprintf(
258  $this->getLanguageText('frm_noti_subject_answ_post'),
259  $this->provider->getForumTitle(),
260  $this->provider->getThreadTitle()
261  ));
262 
263  $this->setBody(ilMail::getSalutation($rcp,$this->getLanguage()));
264  $this->appendBody("\n\n");
265 
266  $this->appendBody($this->getLanguageText('forum_post_replied'));
267  $this->appendBody("\n\n");
268  $this->appendBody($this->getLanguageText('forum').": ".$this->provider->getForumTitle());
269 
270  $this->appendBody("\n\n");
271  $this->appendBody($this->getLanguageText('thread').": ".$this->provider->getThreadTitle());
272  $this->appendBody("\n\n");
273  $this->appendBody($this->getLanguageText('new_post').": \n------------------------------------------------------------\n");
274 
275  $this->appendBody($this->getLanguageText('author').": ". $this->provider->getPostUserName($this->getLanguage()));
276  $this->appendBody("\n");
277  $this->appendBody($this->getLanguageText('date').": ". ilDatePresentation::formatDate(new ilDateTime($this->provider->getPostDate(), IL_CAL_DATETIME)));
278  $this->appendBody("\n");
279  $this->appendBody($this->getLanguageText('subject').": ". $this->provider->getPostTitle());
280  $this->appendBody("\n");
281  $this->appendBody($this->getLanguageText('frm_noti_message'));
282  $this->appendBody("\n");
283 
284  if($this->provider->getPostCensored() == 1)
285  {
286  $this->appendBody($this->provider->getCensorshipComment() . "\n");
287  }
288  else
289  {
290  $pos_message = $this->getSecurePostMessage();
291  $this->appendBody(strip_tags($pos_message) . "\n");
292  }
293  $this->appendBody("------------------------------------------------------------\n");
294 
295  if(count($this->provider->getAttachments()) > 0)
296  {
297  foreach($this->provider->getAttachments() as $attachment)
298  {
299  $this->appendBody($this->getLanguageText('attachment') . ": " . $attachment . "\n");
300  }
301  $this->appendBody("\n------------------------------------------------------------\n");
302  }
303 
304  $this->appendBody($this->getPermanentLink());
306 
307  $this->sendMail(array($rcp), array('system'));
308 
309  }
310  break;
311 
312  case self::TYPE_POST_UPDATED:
313  foreach($this->getRecipients() as $rcp)
314  {
315  $this->initLanguage($rcp);
316  ilDatePresentation::setLanguage($this->language);
317 
318  $this->initMail();
319 
320  $this->setSubject(sprintf(
321  $this->getLanguageText('frm_noti_subject_upt_post'),
322  $this->provider->getForumTitle(),
323  $this->provider->getThreadTitle()
324  ));
325 
326  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
327  $this->appendBody("\n\n");
328  $this->appendBody(sprintf($this->getLanguageText('post_updated_by'), $this->provider->getPostUpdateUserName($this->getLanguage()), $this->provider->getForumTitle()));
329  $this->appendBody("\n\n");
330  $this->appendBody($this->getLanguageText('forum') . ": " . $this->provider->getForumTitle());
331  $this->appendBody("\n\n");
332  $this->appendBody($this->getLanguageText('thread') . ": " . $this->provider->getThreadTitle());
333  $this->appendBody("\n\n");
334  $this->appendBody($this->getLanguageText('content_post_updated') . "\n------------------------------------------------------------\n");
335 
336  $this->appendBody($this->getLanguageText('author') . ": " . $this->provider->getPostUserName($this->getLanguage()));
337  $this->appendBody("\n");
338  $this->appendBody($this->getLanguageText('date') . ": " . ilDatePresentation::formatDate(new ilDateTime($this->provider->getPostUpdate(), IL_CAL_DATETIME)));
339  $this->appendBody("\n");
340  $this->appendBody($this->getLanguageText('subject') . ": " . $this->provider->getPostTitle());
341  $this->appendBody("\n");
342  $this->appendBody($this->getLanguageText('frm_noti_message'));
343  $this->appendBody("\n");
344 
345  if($this->provider->getPostCensored() == 1)
346  {
347  $this->appendBody($this->provider->getCensorshipComment() . "\n");
348  }
349  else
350  {
351  $pos_message = $this->getSecurePostMessage();
352  $this->appendBody(strip_tags($pos_message) . "\n");
353  }
354  $this->appendBody("------------------------------------------------------------\n");
355 
356  if(count($this->provider->getAttachments()) > 0)
357  {
358  foreach($this->provider->getAttachments() as $attachment)
359  {
360  $this->appendBody($this->getLanguageText('attachment') . ": " . $attachment . "\n");
361  }
362  $this->appendBody("\n------------------------------------------------------------\n");
363  }
364 
365  $this->appendBody($this->getPermanentLink());
367 
368  $this->sendMail(array($rcp), array('system'));
369  }
370  break;
371 
372  case self::TYPE_POST_CENSORED:
373  foreach($this->getRecipients() as $rcp)
374  {
375  $this->initLanguage($rcp);
376  ilDatePresentation::setLanguage($this->language);
377 
378  $this->initMail();
379 
380  $this->setSubject(sprintf(
381  $this->getLanguageText('frm_noti_subject_cens_post'),
382  $this->provider->getForumTitle(),
383  $this->provider->getThreadTitle()
384  ));
385 
386  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
387  $this->appendBody("\n\n");
388  $this->appendBody(sprintf($this->getLanguageText('post_censored_by'), $this->provider->getPostUpdateUserName($this->getLanguage()) ,$this->provider->getForumTitle()));
389  $this->appendBody("\n\n");
390  $this->appendBody($this->getLanguageText('forum') . ": " . $this->provider->getForumTitle());
391  $this->appendBody("\n\n");
392  $this->appendBody($this->getLanguageText('thread') . ": " . $this->provider->getThreadTitle());
393  $this->appendBody("\n\n");
394  $this->appendBody($this->getLanguageText('content_censored_post') . "\n------------------------------------------------------------\n");
395 
396  $this->appendBody($this->getLanguageText('author') . ": " . $this->provider->getPostUserName($this->getLanguage()));
397  $this->appendBody("\n");
398  $this->appendBody($this->getLanguageText('date') . ": " . ilDatePresentation::formatDate(new ilDateTime($this->provider->getPostCensoredDate(), IL_CAL_DATETIME)));
399  $this->appendBody("\n");
400  $this->appendBody($this->getLanguageText('subject') . ": " . $this->provider->getPostTitle());
401  $this->appendBody("\n");
402  $this->appendBody($this->getLanguageText('frm_noti_message'));
403  $this->appendBody("\n");
404 
405  if($this->provider->getPostCensored() == 1)
406  {
407  $this->appendBody($this->provider->getCensorshipComment() . "\n");
408  }
409  else
410  {
411  $pos_message = $this->getSecurePostMessage();
412  $this->appendBody(strip_tags($pos_message) . "\n");
413  }
414  $this->appendBody("------------------------------------------------------------\n");
415 
416  if(count($this->provider->getAttachments()) > 0)
417  {
418  foreach($this->provider->getAttachments() as $attachment)
419  {
420  $this->appendBody($this->getLanguageText('attachment') . ": " . $attachment . "\n");
421  }
422  $this->appendBody("\n------------------------------------------------------------\n");
423  }
424 
425  $this->appendBody($this->getPermanentLink());
427 
428  $this->sendMail(array($rcp), array('system'));
429  }
430  break;
431  case self::TYPE_POST_UNCENSORED:
432  foreach($this->getRecipients() as $rcp)
433  {
434  $this->initLanguage($rcp);
435  ilDatePresentation::setLanguage($this->language);
436 
437  $this->initMail();
438 
439  $this->setSubject(sprintf(
440  $this->getLanguageText('frm_noti_subject_uncens_post'),
441  $this->provider->getForumTitle(),
442  $this->provider->getThreadTitle()
443  ));
444 
445  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
446  $this->appendBody("\n\n");
447  $this->appendBody(sprintf($this->getLanguageText('post_uncensored_by'), $this->provider->getPostUpdateUserName($this->getLanguage())));
448  $this->appendBody("\n\n");
449  $this->appendBody($this->getLanguageText('forum') . ": " . $this->provider->getForumTitle());
450  $this->appendBody("\n\n");
451  $this->appendBody($this->getLanguageText('thread') . ": " . $this->provider->getThreadTitle());
452  $this->appendBody("\n\n");
453  $this->appendBody($this->getLanguageText('forums_the_post') . "\n------------------------------------------------------------\n");
454 
455  $this->appendBody($this->getLanguageText('author') . ": " . $this->provider->getPostUserName($this->getLanguage()));
456  $this->appendBody("\n");
457  $this->appendBody($this->getLanguageText('date') . ": " . ilDatePresentation::formatDate(new ilDateTime($this->provider->getPostCensoredDate(), IL_CAL_DATETIME)));
458  $this->appendBody("\n");
459  $this->appendBody($this->getLanguageText('subject') . ": " . $this->provider->getPostTitle());
460  $this->appendBody("\n");
461  $this->appendBody($this->getLanguageText('frm_noti_message'));
462  $this->appendBody("\n");
463 
464  $pos_message = $this->getSecurePostMessage();
465  $this->appendBody(strip_tags($pos_message) . "\n");
466 
467  $this->appendBody("------------------------------------------------------------\n");
468 
469  if(count($this->provider->getAttachments()) > 0)
470  {
471  foreach($this->provider->getAttachments() as $attachment)
472  {
473  $this->appendBody($this->getLanguageText('attachment') . ": " . $attachment . "\n");
474  }
475  $this->appendBody("\n------------------------------------------------------------\n");
476  }
477 
478  $this->appendBody($this->getPermanentLink());
480 
481  $this->sendMail(array($rcp), array('system'));
482  }
483  break;
484 
485  case self::TYPE_POST_DELETED:
486  foreach($this->getRecipients() as $rcp)
487  {
488  $this->initLanguage($rcp);
489  ilDatePresentation::setLanguage($this->language);
490 
491  $this->initMail();
492 
493  $this->setSubject(sprintf(
494  $this->getLanguageText('frm_noti_subject_del_post'),
495  $this->provider->getForumTitle(),
496  $this->provider->getThreadTitle()
497  ));
498 
499  $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
500  $this->appendBody("\n\n");
501  $this->appendBody(sprintf($this->getLanguageText('post_deleted_by'), $ilUser->getLogin(), $this->provider->getForumTitle()));
502  $this->appendBody("\n\n");
503  $this->appendBody($this->getLanguageText('forum') . ": " . $this->provider->getForumTitle());
504  $this->appendBody("\n\n");
505  $this->appendBody($this->getLanguageText('thread') . ": " . $this->provider->getThreadTitle());
506  $this->appendBody("\n\n");
507  $this->appendBody($this->getLanguageText('content_deleted_post') ."\n------------------------------------------------------------\n");
508 
509  $this->appendBody($this->getLanguageText('author') . ": " . $this->provider->getPostUserName($this->getLanguage()));
510  $this->appendBody("\n");
511 
512  $post_date = ilDatePresentation::formatDate(new ilDateTime($this->provider->getPostDate(), IL_CAL_DATETIME));
513  $this->appendBody($this->getLanguageText('date') . ": " . $post_date);
514  $this->appendBody("\n");
515  $this->appendBody($this->getLanguageText('subject') . ": " . $this->provider->getPostTitle());
516  $this->appendBody("\n");
517  $this->appendBody($this->getLanguageText('frm_noti_message'));
518  $this->appendBody("\n");
519 
520  if($this->provider->getPostCensored() == 1)
521  {
522  $this->appendBody($this->provider->getCensorshipComment() . "\n");
523  }
524  else
525  {
526  $pos_message = $this->getSecurePostMessage();
527  $this->appendBody(strip_tags($pos_message) . "\n");
528  }
529  $this->appendBody("------------------------------------------------------------\n");
530 
531  $this->appendBody($this->getPermanentLink(self::PERMANENT_LINK_FORUM));
533 
534  $this->sendMail(array($rcp), array('system'));
535  }
536  break;
537  }
538 
541 
542  return true;
543  }
544 
548  protected function initLanguage($a_usr_id)
549  {
550  parent::initLanguage($a_usr_id);
551  $this->language->loadLanguageModule('forum');
552  }
553 
557  public function isCronjob()
558  {
559  return (bool)$this->is_cronjob;
560  }
561 
565  public function setIsCronjob($is_cronjob)
566  {
567  $this->is_cronjob = (bool)$is_cronjob;
568  }
569 
574  private function getPermanentLink($type = self::PERMANENT_LINK_POST)
575  {
579  global $ilClientIniFile;
580 
581  if($type == self::PERMANENT_LINK_FORUM)
582  {
583  $language_text = $this->getLanguageText("forums_notification_show_frm");
584  $forum_parameters = $this->provider->getRefId();
585  }
586  else
587  {
588  $language_text = $this->getLanguageText("forums_notification_show_post");
589  $forum_parameters = $this->provider->getRefId() . "_" . $this->provider->getThreadId() . "_" . $this->provider->getPostId();
590  }
591 
592  if($this->isCronjob())
593  {
594  $posting_link = sprintf($language_text,
595  ilUtil::_getHttpPath() . "/goto.php?target=frm_" .$forum_parameters. '&client_id=' . CLIENT_ID) . "\n\n";
596 
597  $posting_link .= sprintf($this->getLanguageText("forums_notification_intro"),
598  $ilClientIniFile->readVariable("client", "name"),
599  ilUtil::_getHttpPath() . '/?client_id=' . CLIENT_ID) . "\n\n";
600  }
601  else
602  {
603  $posting_link = sprintf($language_text,
604  ilUtil::_getHttpPath() . "/goto.php?target=frm_" .$forum_parameters. '&client_id=' . CLIENT_ID) . "\n\n";
605 
606  $posting_link .= sprintf($this->getLanguageText("forums_notification_intro"),
607  $ilClientIniFile->readVariable("client", "name"),
608  ilUtil::_getHttpPath() . '/?client_id=' . CLIENT_ID) . "\n\n";
609  }
610 
611  return $posting_link;
612  }
613 
617  private function getSecurePostMessage()
618  {
619  $pos_message = $this->provider->getPostMessage();
620  if(strip_tags($pos_message) != $pos_message)
621  {
622  $pos_message = preg_replace("/\n/i", "", $pos_message);
623  $pos_message = preg_replace("/<br(\s*)(\/?)>/i", "\n", $pos_message);
624  $pos_message = preg_replace("/<p([^>]*)>/i", "\n\n", $pos_message);
625  $pos_message = preg_replace("/<\/p([^>]*)>/i", '', $pos_message);
626  return $pos_message;
627  }
628  return strip_tags($pos_message);
629  }
630 }
getType()
Get notification type.
const IL_CAL_DATETIME
static setUseRelativeDates($a_status)
set use relative dates
static useRelativeDates()
check if relative dates are used
static setLanguage($a_lng)
set language
Base class for course/group mail notifications.
static formatDate(ilDateTime $date)
Format a date public.
Date and time handling
static getSalutation($a_usr_id, $a_language=null)
Get salutation.
Interface ilForumNotificationMailData.
sendMail(array $a_rcp, $a_type, $a_parse_recipients=true)
getRecipients()
get array of recipients
static _getHttpPath()
global $ilUser
Definition: imgupload.php:15
global $ilSetting
Definition: privfeed.php:40
global $lng
Definition: privfeed.php:40
__construct(ilForumNotificationMailData $provider)
appendBody($a_body)
Append body text.
static _getInstallationSignature()
Static getter for the installation signature.