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