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