]> git.mxchange.org Git - friendica.git/blob - include/enotify.php
4316188506f1cebb18c1fefa435c96c04aa90db9
[friendica.git] / include / enotify.php
1 <?php
2 require_once('include/Emailer.php');
3 require_once('include/email.php');
4 require_once('include/bbcode.php');
5 require_once('include/html2bbcode.php');
6
7 function notification($params) {
8
9         #logger('notification()', LOGGER_DEBUG);
10
11         $a = get_app();
12
13         // from here on everything is in the recipients language
14
15         push_lang($params['language']);
16
17
18         $banner = t('Friendica Notification');
19         $product = FRIENDICA_PLATFORM;
20         $siteurl = $a->get_baseurl(true);
21         $thanks = t('Thank You,');
22         $sitename = $a->config['sitename'];
23         $site_admin = sprintf( t('%s Administrator'), $sitename);
24         $nickname = "";
25
26         $sender_name = $sitename;
27         $hostname = $a->get_hostname();
28         if(strpos($hostname,':'))
29                 $hostname = substr($hostname,0,strpos($hostname,':'));
30         
31         $sender_email = $a->config['sender_email'];
32         if (empty($sender_email)) {
33                 $sender_email = t('noreply') . '@' . $hostname;
34         }
35
36         $user = q("SELECT `nickname` FROM `user` WHERE `uid` = %d", intval($params['uid']));
37         if ($user)
38                 $nickname = $user[0]["nickname"];
39
40         // with $params['show_in_notification_page'] == false, the notification isn't inserted into
41         // the database, and an email is sent if applicable.
42         // default, if not specified: true
43         $show_in_notification_page = ((x($params,'show_in_notification_page'))  ?       $params['show_in_notification_page']:True);
44
45         $additional_mail_header = "";
46         $additional_mail_header .= "Precedence: list\n";
47         $additional_mail_header .= "X-Friendica-Host: ".$hostname."\n";
48         $additional_mail_header .= "X-Friendica-Account: <".$nickname."@".$hostname.">\n";
49         $additional_mail_header .= "X-Friendica-Platform: ".FRIENDICA_PLATFORM."\n";
50         $additional_mail_header .= "X-Friendica-Version: ".FRIENDICA_VERSION."\n";
51         $additional_mail_header .= "List-ID: <notification.".$hostname.">\n";
52         $additional_mail_header .= "List-Archive: <".$a->get_baseurl()."/notifications/system>\n";
53
54
55         if(array_key_exists('item',$params)) {
56                 $title = $params['item']['title'];
57                 $body = $params['item']['body'];
58         }
59         else {
60                 $title = $body = '';
61         }
62
63         // e.g. "your post", "David's photo", etc.
64         $possess_desc = t('%s <!item_type!>');
65
66         if (isset($params['parent']))
67                 $parent_id = $params['parent'];
68         else
69                 $parent_id = 0;
70
71         if($params['type'] == NOTIFY_MAIL) {
72
73                 $subject =      sprintf( t('[Friendica:Notify] New mail received at %s'),$sitename);
74
75                 $preamble = sprintf( t('%1$s sent you a new private message at %2$s.'),$params['source_name'],$sitename);
76                 $epreamble = sprintf( t('%1$s sent you %2$s.'),'[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]', '[url=$itemlink]' . t('a private message') . '[/url]');
77                 $sitelink = t('Please visit %s to view and/or reply to your private messages.');
78                 $tsitelink = sprintf( $sitelink, $siteurl . '/message/' . $params['item']['id'] );
79                 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '/message/' . $params['item']['id'] . '">' . $sitename . '</a>');
80                 $itemlink = $siteurl . '/message/' . $params['item']['id'];
81         }
82
83         if($params['type'] == NOTIFY_COMMENT) {
84 //              logger("notification: params = " . print_r($params, true), LOGGER_DEBUG);
85
86                 //$parent_id = $params['parent'];
87
88                 $p = q("SELECT `ignored` FROM `thread` WHERE `iid` = %d AND `uid` = %d LIMIT 1",
89                         intval($parent_id),
90                         intval($params['uid'])
91                 );
92                 if ($p AND count($p) AND ($p[0]["ignored"])) {
93                         logger("Thread ".$parent_id." will be ignored", LOGGER_DEBUG);
94                         return;
95                 }
96
97                 // Check to see if there was already a tag notify or comment notify for this post.
98                 // If so don't create a second notification
99
100                 $p = null;
101                 $p = q("select id from notify where (type = %d or type = %d or type = %d) and link = '%s' and uid = %d limit 1",
102                         intval(NOTIFY_TAGSELF),
103                         intval(NOTIFY_COMMENT),
104                         intval(NOTIFY_SHARE),
105                         dbesc($params['link']),
106                         intval($params['uid'])
107                 );
108                 if($p and count($p)) {
109                         pop_lang();
110                         return;
111                 }
112
113
114                 // if it's a post figure out who's post it is.
115
116                 $p = null;
117
118                 if($params['otype'] === 'item' && $parent_id) {
119                         $p = q("select * from item where id = %d and uid = %d limit 1",
120                                 intval($parent_id),
121                                 intval($params['uid'])
122                         );
123                 }
124
125                 $item_post_type = item_post_type($p[0]);
126                 //$possess_desc = str_replace('<!item_type!>',$possess_desc);
127
128                 // "a post"
129                 $dest_str = sprintf(t('%1$s commented on [url=%2$s]a %3$s[/url]'),
130                                                                 '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
131                                                                 $itemlink,
132                                                                 $item_post_type);
133
134                 // "George Bull's post"
135                 if($p)
136                         $dest_str = sprintf(t('%1$s commented on [url=%2$s]%3$s\'s %4$s[/url]'),
137                                                 '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
138                                                 $itemlink,
139                                                 $p[0]['author-name'],
140                                                 $item_post_type);
141
142                 // "your post"
143                 if($p[0]['owner-name'] == $p[0]['author-name'] && $p[0]['wall'])
144                         $dest_str = sprintf(t('%1$s commented on [url=%2$s]your %3$s[/url]'),
145                                                                 '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
146                                                                 $itemlink,
147                                                                 $item_post_type);
148
149                 // Some mail softwares relies on subject field for threading.
150                 // So, we cannot have different subjects for notifications of the same thread.
151                 // Before this we have the name of the replier on the subject rendering
152                 // differents subjects for messages on the same thread.
153
154                 $subject = sprintf( t('[Friendica:Notify] Comment to conversation #%1$d by %2$s'), $parent_id, $params['source_name']);
155                 $preamble = sprintf( t('%s commented on an item/conversation you have been following.'), $params['source_name']);
156                 $epreamble = $dest_str;
157
158                 $sitelink = t('Please visit %s to view and/or reply to the conversation.');
159                 $tsitelink = sprintf( $sitelink, $siteurl );
160                 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
161                 $itemlink =  $params['link'];
162         }
163
164         if($params['type'] == NOTIFY_WALL) {
165                 $subject = sprintf( t('[Friendica:Notify] %s posted to your profile wall') , $params['source_name']);
166
167                 $preamble = sprintf( t('%1$s posted to your profile wall at %2$s') , $params['source_name'], $sitename);
168
169                 $epreamble = sprintf( t('%1$s posted to [url=%2$s]your wall[/url]') ,
170                                                                 '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
171                                                                 $params['link']);
172
173                 $sitelink = t('Please visit %s to view and/or reply to the conversation.');
174                 $tsitelink = sprintf( $sitelink, $siteurl );
175                 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
176                 $itemlink =  $params['link'];
177         }
178
179         if($params['type'] == NOTIFY_TAGSELF) {
180                 $subject =      sprintf( t('[Friendica:Notify] %s tagged you') , $params['source_name']);
181                 $preamble = sprintf( t('%1$s tagged you at %2$s') , $params['source_name'], $sitename);
182                 $epreamble = sprintf( t('%1$s [url=%2$s]tagged you[/url].') ,
183                                                                 '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
184                                                                 $params['link']);
185
186                 $sitelink = t('Please visit %s to view and/or reply to the conversation.');
187                 $tsitelink = sprintf( $sitelink, $siteurl );
188                 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
189                 $itemlink =  $params['link'];
190         }
191
192         if($params['type'] == NOTIFY_SHARE) {
193                 $subject =      sprintf( t('[Friendica:Notify] %s shared a new post') , $params['source_name']);
194                 $preamble = sprintf( t('%1$s shared a new post at %2$s') , $params['source_name'], $sitename);
195                 $epreamble = sprintf( t('%1$s [url=%2$s]shared a post[/url].') ,
196                                                                 '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
197                                                                 $params['link']);
198
199                 $sitelink = t('Please visit %s to view and/or reply to the conversation.');
200                 $tsitelink = sprintf( $sitelink, $siteurl );
201                 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
202                 $itemlink =  $params['link'];
203         }
204
205         if($params['type'] == NOTIFY_POKE) {
206
207                 $subject =      sprintf( t('[Friendica:Notify] %1$s poked you') , $params['source_name']);
208                 $preamble = sprintf( t('%1$s poked you at %2$s') , $params['source_name'], $sitename);
209                 $epreamble = sprintf( t('%1$s [url=%2$s]poked you[/url].') ,
210                                                                 '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
211                                                                 $params['link']);
212
213                 $subject = str_replace('poked', t($params['activity']), $subject);
214                 $preamble = str_replace('poked', t($params['activity']), $preamble);
215                 $epreamble = str_replace('poked', t($params['activity']), $epreamble);
216
217                 $sitelink = t('Please visit %s to view and/or reply to the conversation.');
218                 $tsitelink = sprintf( $sitelink, $siteurl );
219                 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
220                 $itemlink =  $params['link'];
221         }
222
223         if($params['type'] == NOTIFY_TAGSHARE) {
224                 $subject =      sprintf( t('[Friendica:Notify] %s tagged your post') , $params['source_name']);
225                 $preamble = sprintf( t('%1$s tagged your post at %2$s') , $params['source_name'], $sitename);
226                 $epreamble = sprintf( t('%1$s tagged [url=%2$s]your post[/url]') ,
227                                                                 '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
228                                                                 $itemlink);
229
230                 $sitelink = t('Please visit %s to view and/or reply to the conversation.');
231                 $tsitelink = sprintf( $sitelink, $siteurl );
232                 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
233                 $itemlink =  $params['link'];
234         }
235
236         if($params['type'] == NOTIFY_INTRO) {
237                 $subject = sprintf( t('[Friendica:Notify] Introduction received'));
238                 $preamble = sprintf( t('You\'ve received an introduction from \'%1$s\' at %2$s'), $params['source_name'], $sitename);
239                 $epreamble = sprintf( t('You\'ve received [url=%1$s]an introduction[/url] from %2$s.'),
240                                                                 $itemlink,
241                                                                 '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]');
242                 $body = sprintf( t('You may visit their profile at %s'),$params['source_link']);
243
244                 $sitelink = t('Please visit %s to approve or reject the introduction.');
245                 $tsitelink = sprintf( $sitelink, $siteurl );
246                 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
247                 $itemlink =  $params['link'];
248
249                 switch ($params['verb']) {
250                         case ACTIVITY_FRIEND:
251                                 // someone started to share with user (mostly OStatus)
252                                 $subject = sprintf( t('[Friendica:Notify] A new person is sharing with you'));
253                                 $preamble = sprintf( t('%1$s is sharing with you at %2$s'), $params['source_name'], $sitename);
254                                 $epreamble = sprintf( t('%1$s is sharing with you at %2$s'),
255                                                                                 '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
256                                                                                 $sitename);
257                                 break;
258                         case ACTIVITY_FOLLOW:
259                                 // someone started to follow the user (mostly OStatus)
260                                 $subject = sprintf( t('[Friendica:Notify] You have a new follower'));
261                                 $preamble = sprintf( t('You have a new follower at %2$s : %1$s'), $params['source_name'], $sitename);
262                                 $epreamble = sprintf( t('You have a new follower at %2$s : %1$s'),
263                                                                                 '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
264                                                                                 $sitename);
265                                 break;
266                         default:
267                                 // ACTIVITY_REQ_FRIEND is default activity for notifications
268                                 break;
269                 }
270
271
272         }
273
274         if($params['type'] == NOTIFY_SUGGEST) {
275                 $subject = sprintf( t('[Friendica:Notify] Friend suggestion received'));
276                 $preamble = sprintf( t('You\'ve received a friend suggestion from \'%1$s\' at %2$s'), $params['source_name'], $sitename);
277                 $epreamble = sprintf( t('You\'ve received [url=%1$s]a friend suggestion[/url] for %2$s from %3$s.'),
278                                                                         $itemlink,
279                                                                         '[url=' . $params['item']['url'] . ']' . $params['item']['name'] . '[/url]',
280                                                                         '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]');
281
282                 $body = t('Name:') . ' ' . $params['item']['name'] . "\n";
283                 $body .= t('Photo:') . ' ' . $params['item']['photo'] . "\n";
284                 $body .= sprintf( t('You may visit their profile at %s'),$params['item']['url']);
285
286                 $sitelink = t('Please visit %s to approve or reject the suggestion.');
287                 $tsitelink = sprintf( $sitelink, $siteurl );
288                 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
289                 $itemlink =  $params['link'];
290         }
291
292         if($params['type'] == NOTIFY_CONFIRM) {
293                 if ($params['verb'] == ACTIVITY_FRIEND ){ // mutual connection
294                         $subject = sprintf( t('[Friendica:Notify] Connection accepted'));
295                         $preamble = sprintf( t('\'%1$s\' has acepted your connection request at %2$s'), $params['source_name'], $sitename);
296                         $epreamble = sprintf( t('%2$s has accepted your [url=%1$s]connection request[/url].'),
297                                                                         $itemlink,
298                                                                         '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]');
299                         $body =  t('You are now mutual friends and may exchange status updates, photos, and email
300         without restriction.');
301
302                         $sitelink = t('Please visit %s  if you wish to make any changes to this relationship.');
303                         $tsitelink = sprintf( $sitelink, $siteurl );
304                         $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
305                         $itemlink =  $params['link'];
306                 } else { // ACTIVITY_FOLLOW
307                         $subject = sprintf( t('[Friendica:Notify] Connection accepted'));
308                         $preamble = sprintf( t('\'%1$s\' has acepted your connection request at %2$s'), $params['source_name'], $sitename);
309                         $epreamble = sprintf( t('%2$s has accepted your [url=%1$s]connection request[/url].'),
310                                                                         $itemlink,
311                                                                         '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]');
312                         $body =  sprintf(t('\'%1$s\' has chosen to accept you a "fan", which restricts some forms of communication - such as private messaging and some profile interactions. If this is a celebrity or community page, these settings were applied automatically.'), $params['source_name']);
313                         $body .= "\n\n";
314                         $body .= sprintf(t('\'%1$s\' may choose to extend this into a two-way or more permissive relationship in the future. '), $params['source_name']);
315
316                         $sitelink = t('Please visit %s  if you wish to make any changes to this relationship.');
317                         $tsitelink = sprintf( $sitelink, $siteurl );
318                         $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
319                         $itemlink =  $params['link'];
320                 }
321
322         }
323
324         if($params['type'] == NOTIFY_SYSTEM) {
325                 switch($params['event']) {
326                         case "SYSTEM_REGISTER_REQUEST":
327                                 $subject = sprintf( t('[Friendica System:Notify] registration request'));
328                                 $preamble = sprintf( t('You\'ve received a registration request from \'%1$s\' at %2$s'), $params['source_name'], $sitename);
329                                 $epreamble = sprintf( t('You\'ve received a [url=%1$s]registration request[/url] from %2$s.'),
330                                                                                 $itemlink,
331                                                                                 '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]');
332                                 $body = sprintf( t('Full Name:  %1$s\nSite Location:    %2$s\nLogin Name:       %3$s (%4$s)'),
333                                                                         $params['source_name'], $siteurl, $params['source_mail'], $params['source_nick']);
334
335                                 $sitelink = t('Please visit %s to approve or reject the request.');
336                                 $tsitelink = sprintf( $sitelink, $params['link'] );
337                                 $hsitelink = sprintf( $sitelink, '<a href="' . $params['link'] . '">' . $sitename . '</a><br><br>');
338                                 $itemlink =  $params['link'];
339                                 break;
340                         case "SYSTEM_DB_UPDATE_FAIL":
341                                 break;
342                 }
343         }
344
345         if ($params['type'] == "SYSTEM_EMAIL"){
346                 // not part of the notifications.
347                 // it just send a mail to the user.
348                 // It will be used by the system to send emails to users (like
349                 // password reset, invitations and so) using one look (but without
350                 // add a notification to the user, with could be inexistent)
351                         $subject = $params['subject'];
352                         $preamble = $params['preamble'];
353                         $body =  $params['body'];
354                         $sitelink = "";
355                         $tsitelink = "";
356                         $hsitelink = "";
357                         $itemlink =  "";
358                         $show_in_notification_page = false;
359         }
360
361         $subject .= " (".$nickname."@".$hostname.")";
362
363         $h = array(
364                 'params'    => $params,
365                 'subject'   => $subject,
366                 'preamble'  => $preamble,
367                 'epreamble' => $epreamble,
368                 'body'      => $body,
369                 'sitelink'  => $sitelink,
370                 'tsitelink' => $tsitelink,
371                 'hsitelink' => $hsitelink,
372                 'itemlink'  => $itemlink
373         );
374
375         call_hooks('enotify',$h);
376
377         $subject   = $h['subject'];
378         $preamble  = $h['preamble'];
379         $epreamble = $h['epreamble'];
380         $body      = $h['body'];
381         $sitelink  = $h['sitelink'];
382         $tsitelink = $h['tsitelink'];
383         $hsitelink = $h['hsitelink'];
384         $itemlink  = $h['itemlink'];
385
386
387
388         if ($show_in_notification_page) {
389                 logger("adding notification entry", LOGGER_DEBUG);
390                 do {
391                         $dups = false;
392                         $hash = random_string();
393                         $r = q("SELECT `id` FROM `notify` WHERE `hash` = '%s' LIMIT 1",
394                                 dbesc($hash));
395                         if(count($r))
396                                 $dups = true;
397                 } while($dups == true);
398
399
400                 $datarray = array();
401                 $datarray['hash']  = $hash;
402                 $datarray['name']  = $params['source_name'];
403                 $datarray['url']   = $params['source_link'];
404                 $datarray['photo'] = $params['source_photo'];
405                 $datarray['date']  = datetime_convert();
406                 $datarray['uid']   = $params['uid'];
407                 $datarray['link']  = $itemlink;
408                 $datarray['parent'] = $parent_id;
409                 $datarray['type']  = $params['type'];
410                 $datarray['verb']  = $params['verb'];
411                 $datarray['otype'] = $params['otype'];
412                 $datarray['abort'] = false;
413
414                 call_hooks('enotify_store', $datarray);
415
416                 if($datarray['abort']) {
417                         pop_lang();
418                         return False;
419                 }
420
421                 // create notification entry in DB
422
423                 $r = q("insert into notify (hash,name,url,photo,date,uid,link,parent,type,verb,otype)
424                         values('%s','%s','%s','%s','%s',%d,'%s',%d,%d,'%s','%s')",
425                         dbesc($datarray['hash']),
426                         dbesc($datarray['name']),
427                         dbesc($datarray['url']),
428                         dbesc($datarray['photo']),
429                         dbesc($datarray['date']),
430                         intval($datarray['uid']),
431                         dbesc($datarray['link']),
432                         intval($datarray['parent']),
433                         intval($datarray['type']),
434                         dbesc($datarray['verb']),
435                         dbesc($datarray['otype'])
436                 );
437
438                 $r = q("select id from notify where hash = '%s' and uid = %d limit 1",
439                         dbesc($hash),
440                         intval($params['uid'])
441                 );
442                 if($r)
443                         $notify_id = $r[0]['id'];
444                 else {
445                         pop_lang();
446                         return False;
447                 }
448
449                 // we seem to have a lot of duplicate comment notifications due to race conditions, mostly from forums
450                 // After we've stored everything, look again to see if there are any duplicates and if so remove them
451
452                 $p = null;
453                 $p = q("select id from notify where ( type = %d or type = %d ) and link = '%s' and uid = %d order by id",
454                         intval(NOTIFY_TAGSELF),
455                         intval(NOTIFY_COMMENT),
456                         dbesc($params['link']),
457                         intval($params['uid'])
458                 );
459                 if($p && (count($p) > 1)) {
460                         for ($d = 1; $d < count($p); $d ++) {
461                                 q("delete from notify where id = %d",
462                                         intval($p[$d]['id'])
463                                 );
464                         }
465
466                         // only continue on if we stored the first one
467
468                         if($notify_id != $p[0]['id']) {
469                                 pop_lang();
470                                 return False;
471                         }
472                 }
473
474
475                 $itemlink = $a->get_baseurl() . '/notify/view/' . $notify_id;
476                 $msg = replace_macros($epreamble,array('$itemlink' => $itemlink));
477                 $r = q("update notify set msg = '%s' where id = %d and uid = %d",
478                         dbesc($msg),
479                         intval($notify_id),
480                         intval($params['uid'])
481                 );
482
483         }
484
485         // send email notification if notification preferences permit
486         if((intval($params['notify_flags']) & intval($params['type']))
487                 || $params['type'] == NOTIFY_SYSTEM
488                 || $params['type'] == "SYSTEM_EMAIL") {
489
490                 logger('sending notification email');
491
492                 if (isset($params['parent']) AND (intval($params['parent']) != 0)) {
493                         $id_for_parent = $params['parent']."@".$hostname;
494
495                         // Is this the first email notification for this parent item and user?
496
497                         $r = q("select `id` from `notify-threads` where `master-parent-item` = %d and `receiver-uid` = %d limit 1",
498                                 intval($params['parent']),
499                                 intval($params['uid']) );
500
501                         // If so, create the record of it and use a message-id smtp header.
502
503                         if(!$r) {
504                                 logger("notify_id:".intval($notify_id).", parent: ".intval($params['parent'])."uid: ".intval($params['uid']), LOGGER_DEBUG);
505                                 $r = q("insert into `notify-threads` (`notify-id`, `master-parent-item`, `receiver-uid`, `parent-item`)
506                                         values(%d,%d,%d,%d)",
507                                         intval($notify_id),
508                                         intval($params['parent']),
509                                         intval($params['uid']),
510                                         0 );
511
512                                 $additional_mail_header .= "Message-ID: <${id_for_parent}>\n";
513                                 $log_msg = "include/enotify: No previous notification found for this parent:\n" .
514                                                 "  parent: ${params['parent']}\n" . "  uid   : ${params['uid']}\n";
515                                 logger($log_msg, LOGGER_DEBUG);
516                         } else {
517                                 // If not, just "follow" the thread.
518                                 $additional_mail_header .= "References: <${id_for_parent}>\nIn-Reply-To: <${id_for_parent}>\n";
519                                 logger("There's already a notification for this parent:\n" . print_r($r, true), LOGGER_DEBUG);
520                         }
521                 }
522
523
524                 // textversion keeps linebreaks
525                 $textversion = strip_tags(str_replace("<br>","\n",html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n"), "\n",
526                         $body))),ENT_QUOTES,'UTF-8')));
527                 $htmlversion = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"),
528                         "<br />\n",$body))),ENT_QUOTES,'UTF-8');
529
530
531                 $datarray = array();
532                 $datarray['banner'] = $banner;
533                 $datarray['product'] = $product;
534                 $datarray['preamble'] = $preamble;
535                 $datarray['sitename'] = $sitename;
536                 $datarray['siteurl'] = $siteurl;
537                 $datarray['type'] = $params['type'];
538                 $datarray['parent'] = $params['parent'];
539                 $datarray['source_name'] = $params['source_name'];
540                 $datarray['source_link'] = $params['source_link'];
541                 $datarray['source_photo'] = $params['source_photo'];
542                 $datarray['uid'] = $params['uid'];
543                 $datarray['username'] = $params['to_name'];
544                 $datarray['hsitelink'] = $hsitelink;
545                 $datarray['tsitelink'] = $tsitelink;
546                 $datarray['hitemlink'] = '<a href="' . $itemlink . '">' . $itemlink . '</a>';
547                 $datarray['titemlink'] = $itemlink;
548                 $datarray['thanks'] = $thanks;
549                 $datarray['site_admin'] = $site_admin;
550                 $datarray['title'] = stripslashes($title);
551                 $datarray['htmlversion'] = $htmlversion;
552                 $datarray['textversion'] = $textversion;
553                 $datarray['subject'] = $subject;
554                 $datarray['headers'] = $additional_mail_header;
555
556                 call_hooks('enotify_mail', $datarray);
557
558                 // check whether sending post content in email notifications is allowed
559                 // always true for "SYSTEM_EMAIL"
560                 $content_allowed = ((!get_config('system','enotify_no_content')) || ($params['type'] == "SYSTEM_EMAIL"));
561
562                 // load the template for private message notifications
563                 $tpl = get_markup_template('email_notify_html.tpl');
564                 $email_html_body = replace_macros($tpl,array(
565                         '$banner'       => $datarray['banner'],
566                         '$product'      => $datarray['product'],
567                         '$preamble'     => str_replace("\n","<br>\n",$datarray['preamble']),
568                         '$sitename'     => $datarray['sitename'],
569                         '$siteurl'      => $datarray['siteurl'],
570                         '$source_name'  => $datarray['source_name'],
571                         '$source_link'  => $datarray['source_link'],
572                         '$source_photo' => $datarray['source_photo'],
573                         '$username'     => $datarray['to_name'],
574                         '$hsitelink'    => $datarray['hsitelink'],
575                         '$hitemlink'    => $datarray['hitemlink'],
576                         '$thanks'       => $datarray['thanks'],
577                         '$site_admin'   => $datarray['site_admin'],
578                         '$title'                => $datarray['title'],
579                         '$htmlversion'  => $datarray['htmlversion'],
580                         '$content_allowed'      => $content_allowed,
581                 ));
582
583                 // load the template for private message notifications
584                 $tpl = get_markup_template('email_notify_text.tpl');
585                 $email_text_body = replace_macros($tpl,array(
586                         '$banner'       => $datarray['banner'],
587                         '$product'      => $datarray['product'],
588                         '$preamble'     => $datarray['preamble'],
589                         '$sitename'     => $datarray['sitename'],
590                         '$siteurl'      => $datarray['siteurl'],
591                         '$source_name'  => $datarray['source_name'],
592                         '$source_link'  => $datarray['source_link'],
593                         '$source_photo' => $datarray['source_photo'],
594                         '$username'     => $datarray['to_name'],
595                         '$tsitelink'    => $datarray['tsitelink'],
596                         '$titemlink'    => $datarray['titemlink'],
597                         '$thanks'       => $datarray['thanks'],
598                         '$site_admin'   => $datarray['site_admin'],
599                         '$title'                => $datarray['title'],
600                         '$textversion'  => $datarray['textversion'],
601                         '$content_allowed'      => $content_allowed,
602                 ));
603
604 //              logger('text: ' . $email_text_body);
605
606                 // use the Emailer class to send the message
607
608                 return Emailer::send(array(
609                         'uid' => $params['uid'],
610                         'fromName' => $sender_name,
611                         'fromEmail' => $sender_email,
612                         'replyTo' => $sender_email,
613                         'toEmail' => $params['to_email'],
614                         'messageSubject' => $datarray['subject'],
615                         'htmlVersion' => $email_html_body,
616                         'textVersion' => $email_text_body,
617                         'additionalMailHeader' => $datarray['headers'],
618                 ));
619         }
620
621     return False;
622
623 }
624
625 ?>