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