]> git.mxchange.org Git - friendica.git/blob - include/enotify.php
Merge pull request #1144 from tobiasd/docs2014
[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><br><br>');
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                         $body =  $params['body'];
340                         $sitelink = "";
341                         $tsitelink = "";
342                         $hsitelink = "";
343                         $itemlink =  "";
344                         $show_in_notification_page = false;
345         }
346
347
348
349         $h = array(
350                 'params'    => $params,
351                 'subject'   => $subject,
352                 'preamble'  => $preamble,
353                 'epreamble' => $epreamble,
354                 'body'      => $body,
355                 'sitelink'  => $sitelink,
356                 'tsitelink' => $tsitelink,
357                 'hsitelink' => $hsitelink,
358                 'itemlink'  => $itemlink
359         );
360
361         call_hooks('enotify',$h);
362
363         $subject   = $h['subject'];
364         $preamble  = $h['preamble'];
365         $epreamble = $h['epreamble'];
366         $body      = $h['body'];
367         $sitelink  = $h['sitelink'];
368         $tsitelink = $h['tsitelink'];
369         $hsitelink = $h['hsitelink'];
370         $itemlink  = $h['itemlink'];
371
372
373
374         if ($show_in_notification_page) {
375                 logger("adding notification entry", LOGGER_DEBUG);
376                 do {
377                         $dups = false;
378                         $hash = random_string();
379                         $r = q("SELECT `id` FROM `notify` WHERE `hash` = '%s' LIMIT 1",
380                                 dbesc($hash));
381                         if(count($r))
382                                 $dups = true;
383                 } while($dups == true);
384
385
386                 $datarray = array();
387                 $datarray['hash']  = $hash;
388                 $datarray['name']  = $params['source_name'];
389                 $datarray['url']   = $params['source_link'];
390                 $datarray['photo'] = $params['source_photo'];
391                 $datarray['date']  = datetime_convert();
392                 $datarray['uid']   = $params['uid'];
393                 $datarray['link']  = $itemlink;
394                 $datarray['parent'] = $parent_id;
395                 $datarray['type']  = $params['type'];
396                 $datarray['verb']  = $params['verb'];
397                 $datarray['otype'] = $params['otype'];
398                 $datarray['abort'] = false;
399
400                 call_hooks('enotify_store', $datarray);
401
402                 if($datarray['abort']) {
403                         pop_lang();
404                         return False;
405                 }
406
407                 // create notification entry in DB
408
409                 $r = q("insert into notify (hash,name,url,photo,date,uid,link,parent,type,verb,otype)
410                         values('%s','%s','%s','%s','%s',%d,'%s',%d,%d,'%s','%s')",
411                         dbesc($datarray['hash']),
412                         dbesc($datarray['name']),
413                         dbesc($datarray['url']),
414                         dbesc($datarray['photo']),
415                         dbesc($datarray['date']),
416                         intval($datarray['uid']),
417                         dbesc($datarray['link']),
418                         intval($datarray['parent']),
419                         intval($datarray['type']),
420                         dbesc($datarray['verb']),
421                         dbesc($datarray['otype'])
422                 );
423
424                 $r = q("select id from notify where hash = '%s' and uid = %d limit 1",
425                         dbesc($hash),
426                         intval($params['uid'])
427                 );
428                 if($r)
429                         $notify_id = $r[0]['id'];
430                 else {
431                         pop_lang();
432                         return False;
433                 }
434
435                 // we seem to have a lot of duplicate comment notifications due to race conditions, mostly from forums
436                 // After we've stored everything, look again to see if there are any duplicates and if so remove them
437
438                 $p = null;
439                 $p = q("select id from notify where ( type = %d or type = %d ) and link = '%s' and uid = %d order by id",
440                         intval(NOTIFY_TAGSELF),
441                         intval(NOTIFY_COMMENT),
442                         dbesc($params['link']),
443                         intval($params['uid'])
444                 );
445                 if($p && (count($p) > 1)) {
446                         for ($d = 1; $d < count($p); $d ++) {
447                                 q("delete from notify where id = %d",
448                                         intval($p[$d]['id'])
449                                 );
450                         }
451
452                         // only continue on if we stored the first one
453
454                         if($notify_id != $p[0]['id']) {
455                                 pop_lang();
456                                 return False;
457                         }
458                 }
459
460
461                 $itemlink = $a->get_baseurl() . '/notify/view/' . $notify_id;
462                 $msg = replace_macros($epreamble,array('$itemlink' => $itemlink));
463                 $r = q("update notify set msg = '%s' where id = %d and uid = %d",
464                         dbesc($msg),
465                         intval($notify_id),
466                         intval($params['uid'])
467                 );
468
469         }
470
471         // send email notification if notification preferences permit
472         if((intval($params['notify_flags']) & intval($params['type']))
473                 || $params['type'] == NOTIFY_SYSTEM
474                 || $params['type'] == "SYSTEM_EMAIL") {
475
476                 logger('sending notification email');
477
478                 if (isset($params['parent']) AND (intval($params['parent']) != 0)) {
479                         $id_for_parent = $params['parent']."@".$hostname;
480
481                         // Is this the first email notification for this parent item and user?
482
483                         $r = q("select `id` from `notify-threads` where `master-parent-item` = %d and `receiver-uid` = %d limit 1",
484                                 intval($params['parent']),
485                                 intval($params['uid']) );
486
487                         // If so, create the record of it and use a message-id smtp header.
488
489                         if(!$r) {
490                                 logger("notify_id:".intval($notify_id).", parent: ".intval($params['parent'])."uid: ".intval($params['uid']), LOGGER_DEBUG);
491                                 $r = q("insert into `notify-threads` (`notify-id`, `master-parent-item`, `receiver-uid`, `parent-item`)
492                                         values(%d,%d,%d,%d)",
493                                         intval($notify_id),
494                                         intval($params['parent']),
495                                         intval($params['uid']),
496                                         0 );
497
498                                 $additional_mail_header .= "Message-ID: <${id_for_parent}>\n";
499                                 $log_msg = "include/enotify: No previous notification found for this parent:\n" .
500                                                 "  parent: ${params['parent']}\n" . "  uid   : ${params['uid']}\n";
501                                 logger($log_msg, LOGGER_DEBUG);
502                         } else {
503                                 // If not, just "follow" the thread.
504                                 $additional_mail_header .= "References: <${id_for_parent}>\nIn-Reply-To: <${id_for_parent}>\n";
505                                 logger("There's already a notification for this parent:\n" . print_r($r, true), LOGGER_DEBUG);
506                         }
507                 }
508
509
510                 // textversion keeps linebreaks
511                 $textversion = strip_tags(str_replace("<br>","\n",html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n"), "\n",
512                         $body))),ENT_QUOTES,'UTF-8')));
513                 $htmlversion = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"),
514                         "<br />\n",$body))),ENT_QUOTES,'UTF-8');
515
516
517                 $datarray = array();
518                 $datarray['banner'] = $banner;
519                 $datarray['product'] = $product;
520                 $datarray['preamble'] = $preamble;
521                 $datarray['sitename'] = $sitename;
522                 $datarray['siteurl'] = $siteurl;
523                 $datarray['type'] = $params['type'];
524                 $datarray['parent'] = $params['parent'];
525                 $datarray['source_name'] = $params['source_name'];
526                 $datarray['source_link'] = $params['source_link'];
527                 $datarray['source_photo'] = $params['source_photo'];
528                 $datarray['uid'] = $params['uid'];
529                 $datarray['username'] = $params['to_name'];
530                 $datarray['hsitelink'] = $hsitelink;
531                 $datarray['tsitelink'] = $tsitelink;
532                 $datarray['hitemlink'] = '<a href="' . $itemlink . '">' . $itemlink . '</a>';
533                 $datarray['titemlink'] = $itemlink;
534                 $datarray['thanks'] = $thanks;
535                 $datarray['site_admin'] = $site_admin;
536                 $datarray['title'] = stripslashes($title);
537                 $datarray['htmlversion'] = $htmlversion;
538                 $datarray['textversion'] = $textversion;
539                 $datarray['subject'] = $subject;
540                 $datarray['headers'] = $additional_mail_header;
541
542                 call_hooks('enotify_mail', $datarray);
543
544                 // check whether sending post content in email notifications is allowed
545                 // always true for "SYSTEM_EMAIL"
546                 $content_allowed = ((!get_config('system','enotify_no_content')) || ($params['type'] == "SYSTEM_EMAIL"));
547
548                 // load the template for private message notifications
549                 $tpl = get_markup_template('email_notify_html.tpl');
550                 $email_html_body = replace_macros($tpl,array(
551                         '$banner'       => $datarray['banner'],
552                         '$product'      => $datarray['product'],
553                         '$preamble'     => str_replace("\n","<br>\n",$datarray['preamble']),
554                         '$sitename'     => $datarray['sitename'],
555                         '$siteurl'      => $datarray['siteurl'],
556                         '$source_name'  => $datarray['source_name'],
557                         '$source_link'  => $datarray['source_link'],
558                         '$source_photo' => $datarray['source_photo'],
559                         '$username'     => $datarray['to_name'],
560                         '$hsitelink'    => $datarray['hsitelink'],
561                         '$hitemlink'    => $datarray['hitemlink'],
562                         '$thanks'       => $datarray['thanks'],
563                         '$site_admin'   => $datarray['site_admin'],
564                         '$title'                => $datarray['title'],
565                         '$htmlversion'  => $datarray['htmlversion'],
566                         '$content_allowed'      => $content_allowed,
567                 ));
568
569                 // load the template for private message notifications
570                 $tpl = get_markup_template('email_notify_text.tpl');
571                 $email_text_body = replace_macros($tpl,array(
572                         '$banner'       => $datarray['banner'],
573                         '$product'      => $datarray['product'],
574                         '$preamble'     => $datarray['preamble'],
575                         '$sitename'     => $datarray['sitename'],
576                         '$siteurl'      => $datarray['siteurl'],
577                         '$source_name'  => $datarray['source_name'],
578                         '$source_link'  => $datarray['source_link'],
579                         '$source_photo' => $datarray['source_photo'],
580                         '$username'     => $datarray['to_name'],
581                         '$tsitelink'    => $datarray['tsitelink'],
582                         '$titemlink'    => $datarray['titemlink'],
583                         '$thanks'       => $datarray['thanks'],
584                         '$site_admin'   => $datarray['site_admin'],
585                         '$title'                => $datarray['title'],
586                         '$textversion'  => $datarray['textversion'],
587                         '$content_allowed'      => $content_allowed,
588                 ));
589
590 //              logger('text: ' . $email_text_body);
591
592                 // use the Emailer class to send the message
593
594                 return Emailer::send(array(
595                         'fromName' => $sender_name,
596                         'fromEmail' => $sender_email,
597                         'replyTo' => $sender_email,
598                         'toEmail' => $params['to_email'],
599                         'messageSubject' => $datarray['subject'],
600                         'htmlVersion' => $email_html_body,
601                         'textVersion' => $email_text_body,
602                         'additionalMailHeader' => $datarray['headers'],
603                 ));
604         }
605
606     return False;
607
608 }
609
610 ?>