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