]> git.mxchange.org Git - friendica.git/blob - include/enotify.php
send ostatus follow/share notifications via notification()
[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                                 break;
254                 }
255
256
257         }
258
259         if($params['type'] == NOTIFY_SUGGEST) {
260                 $subject = sprintf( t('[Friendica:Notify] Friend suggestion received'));
261                 $preamble = sprintf( t('You\'ve received a friend suggestion from \'%1$s\' at %2$s'), $params['source_name'], $sitename);
262                 $epreamble = sprintf( t('You\'ve received [url=%1$s]a friend suggestion[/url] for %2$s from %3$s.'),
263                                                                         $itemlink,
264                                                                         '[url=' . $params['item']['url'] . ']' . $params['item']['name'] . '[/url]',
265                                                                         '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]');
266
267                 $body = t('Name:') . ' ' . $params['item']['name'] . "\n";
268                 $body .= t('Photo:') . ' ' . $params['item']['photo'] . "\n";
269                 $body .= sprintf( t('You may visit their profile at %s'),$params['item']['url']);
270
271                 $sitelink = t('Please visit %s to approve or reject the suggestion.');
272                 $tsitelink = sprintf( $sitelink, $siteurl );
273                 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
274                 $itemlink =  $params['link'];
275         }
276
277         if($params['type'] == NOTIFY_CONFIRM) {
278                 if ($params['verb'] == ACTIVITY_FRIEND ){ // mutual connection
279                         $subject = sprintf( t('[Friendica:Notify] Connection accepted'));
280                         $preamble = sprintf( t('\'%1$s\' has acepted your connection request at %2$s'), $params['source_name'], $sitename);
281                         $epreamble = sprintf( t('%2$s has accepted your [url=%1$s]connection request[/url].'),
282                                                                         $itemlink,
283                                                                         '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]');
284                         $body =  t('You are now mutual friends and may exchange status updates, photos, and email
285         without restriction.');
286
287                         $sitelink = t('Please visit %s  if you wish to make any changes to this relationship.');
288                         $tsitelink = sprintf( $sitelink, $siteurl );
289                         $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
290                         $itemlink =  $params['link'];
291                 } else { // ACTIVITY_FOLLOW
292                         $subject = sprintf( t('[Friendica:Notify] Connection accepted'));
293                         $preamble = sprintf( t('\'%1$s\' has acepted your connection request at %2$s'), $params['source_name'], $sitename);
294                         $epreamble = sprintf( t('%2$s has accepted your [url=%1$s]connection request[/url].'),
295                                                                         $itemlink,
296                                                                         '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]');
297                         $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']);
298                         $body .= "\n\n";
299                         $body .= sprintf(t('\'%1$s\' may choose to extend this into a two-way or more permissive relationship in the future. '), $params['source_name']);
300
301                         $sitelink = t('Please visit %s  if you wish to make any changes to this relationship.');
302                         $tsitelink = sprintf( $sitelink, $siteurl );
303                         $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
304                         $itemlink =  $params['link'];
305                 }
306
307         }
308
309         if($params['type'] == NOTIFY_SYSTEM) {
310                         $subject = $params['subject'];
311                         $preamble = $params['preamble'];
312                         $epreamble = $params['epreamble'];
313                         $body =  $params['body'];
314                         $sitelink = "";
315                         $tsitelink = "";
316                         $hsitelink = "";
317                         $itemlink =  "";
318         }
319
320
321
322         $h = array(
323                 'params'    => $params,
324                 'subject'   => $subject,
325                 'preamble'  => $preamble,
326                 'epreamble' => $epreamble,
327                 'body'      => $body,
328                 'sitelink'  => $sitelink,
329                 'tsitelink' => $tsitelink,
330                 'hsitelink' => $hsitelink,
331                 'itemlink'  => $itemlink
332         );
333
334         call_hooks('enotify',$h);
335
336         $subject   = $h['subject'];
337         $preamble  = $h['preamble'];
338         $epreamble = $h['epreamble'];
339         $body      = $h['body'];
340         $sitelink  = $h['sitelink'];
341         $tsitelink = $h['tsitelink'];
342         $hsitelink = $h['hsitelink'];
343         $itemlink  = $h['itemlink'];
344
345
346         if ($show_in_notification_page) {
347
348                 do {
349                         $dups = false;
350                         $hash = random_string();
351                         $r = q("SELECT `id` FROM `notify` WHERE `hash` = '%s' LIMIT 1",
352                                 dbesc($hash));
353                         if(count($r))
354                                 $dups = true;
355                 } while($dups == true);
356
357
358                 $datarray = array();
359                 $datarray['hash']  = $hash;
360                 $datarray['name']  = $params['source_name'];
361                 $datarray['url']   = $params['source_link'];
362                 $datarray['photo'] = $params['source_photo'];
363                 $datarray['date']  = datetime_convert();
364                 $datarray['uid']   = $params['uid'];
365                 $datarray['link']  = $itemlink;
366                 $datarray['parent'] = $parent_id;
367                 $datarray['type']  = $params['type'];
368                 $datarray['verb']  = $params['verb'];
369                 $datarray['otype'] = $params['otype'];
370                 $datarray['abort'] = false;
371
372                 call_hooks('enotify_store', $datarray);
373
374                 if($datarray['abort']) {
375                         pop_lang();
376                         return False;
377                 }
378
379                 // create notification entry in DB
380
381                 $r = q("insert into notify (hash,name,url,photo,date,uid,link,parent,type,verb,otype)
382                         values('%s','%s','%s','%s','%s',%d,'%s',%d,%d,'%s','%s')",
383                         dbesc($datarray['hash']),
384                         dbesc($datarray['name']),
385                         dbesc($datarray['url']),
386                         dbesc($datarray['photo']),
387                         dbesc($datarray['date']),
388                         intval($datarray['uid']),
389                         dbesc($datarray['link']),
390                         intval($datarray['parent']),
391                         intval($datarray['type']),
392                         dbesc($datarray['verb']),
393                         dbesc($datarray['otype'])
394                 );
395
396                 $r = q("select id from notify where hash = '%s' and uid = %d limit 1",
397                         dbesc($hash),
398                         intval($params['uid'])
399                 );
400                 if($r)
401                         $notify_id = $r[0]['id'];
402                 else {
403                         pop_lang();
404                         return False;
405                 }
406
407                 // we seem to have a lot of duplicate comment notifications due to race conditions, mostly from forums
408                 // After we've stored everything, look again to see if there are any duplicates and if so remove them
409
410                 $p = null;
411                 $p = q("select id from notify where ( type = %d or type = %d ) and link = '%s' and uid = %d order by id",
412                         intval(NOTIFY_TAGSELF),
413                         intval(NOTIFY_COMMENT),
414                         dbesc($params['link']),
415                         intval($params['uid'])
416                 );
417                 if($p && (count($p) > 1)) {
418                         for ($d = 1; $d < count($p); $d ++) {
419                                 q("delete from notify where id = %d",
420                                         intval($p[$d]['id'])
421                                 );
422                         }
423
424                         // only continue on if we stored the first one
425
426                         if($notify_id != $p[0]['id']) {
427                                 pop_lang();
428                                 return False;
429                         }
430                 }
431
432
433                 $itemlink = $a->get_baseurl() . '/notify/view/' . $notify_id;
434                 $msg = replace_macros($epreamble,array('$itemlink' => $itemlink));
435                 $r = q("update notify set msg = '%s' where id = %d and uid = %d",
436                         dbesc($msg),
437                         intval($notify_id),
438                         intval($params['uid'])
439                 );
440
441         }
442
443         // send email notification if notification preferences permit
444         if((intval($params['notify_flags']) & intval($params['type'])) || $params['type'] == NOTIFY_SYSTEM) {
445
446                 logger('notification: sending notification email');
447
448                 if (isset($params['parent']) AND (intval($params['parent']) != 0)) {
449                         $id_for_parent = $params['parent']."@".$hostname;
450
451                         // Is this the first email notification for this parent item and user?
452
453                         $r = q("select `id` from `notify-threads` where `master-parent-item` = %d and `receiver-uid` = %d limit 1",
454                                 intval($params['parent']),
455                                 intval($params['uid']) );
456
457                         // If so, create the record of it and use a message-id smtp header.
458
459                         if(!$r) {
460                                 logger("notify_id:".intval($notify_id).", parent: ".intval($params['parent'])."uid: ".intval($params['uid']), LOGGER_DEBUG);
461                                 $r = q("insert into `notify-threads` (`notify-id`, `master-parent-item`, `receiver-uid`, `parent-item`)
462                                         values(%d,%d,%d,%d)",
463                                         intval($notify_id),
464                                         intval($params['parent']),
465                                         intval($params['uid']),
466                                         0 );
467
468                                 $additional_mail_header .= "Message-ID: <${id_for_parent}>\n";
469                                 $log_msg = "include/enotify: No previous notification found for this parent:\n" .
470                                                 "  parent: ${params['parent']}\n" . "  uid   : ${params['uid']}\n";
471                                 logger($log_msg, LOGGER_DEBUG);
472                         } else {
473                                 // If not, just "follow" the thread.
474                                 $additional_mail_header .= "References: <${id_for_parent}>\nIn-Reply-To: <${id_for_parent}>\n";
475                                 logger("There's already a notification for this parent:\n" . print_r($r, true), LOGGER_DEBUG);
476                         }
477                 }
478
479
480                 $textversion = strip_tags(html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n"), "\n",
481                         $body))),ENT_QUOTES,'UTF-8'));
482                 $htmlversion = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"),
483                         "<br />\n",$body))),ENT_QUOTES,'UTF-8');
484
485                 $datarray = array();
486                 $datarray['banner'] = $banner;
487                 $datarray['product'] = $product;
488                 $datarray['preamble'] = $preamble;
489                 $datarray['sitename'] = $sitename;
490                 $datarray['siteurl'] = $siteurl;
491                 $datarray['type'] = $params['type'];
492                 $datarray['parent'] = $params['parent'];
493                 $datarray['source_name'] = $params['source_name'];
494                 $datarray['source_link'] = $params['source_link'];
495                 $datarray['source_photo'] = $params['source_photo'];
496                 $datarray['uid'] = $params['uid'];
497                 $datarray['username'] = $params['to_name'];
498                 $datarray['hsitelink'] = $hsitelink;
499                 $datarray['tsitelink'] = $tsitelink;
500                 $datarray['hitemlink'] = '<a href="' . $itemlink . '">' . $itemlink . '</a>';
501                 $datarray['titemlink'] = $itemlink;
502                 $datarray['thanks'] = $thanks;
503                 $datarray['site_admin'] = $site_admin;
504                 $datarray['title'] = stripslashes($title);
505                 $datarray['htmlversion'] = $htmlversion;
506                 $datarray['textversion'] = $textversion;
507                 $datarray['subject'] = $subject;
508                 $datarray['headers'] = $additional_mail_header;
509
510                 call_hooks('enotify_mail', $datarray);
511
512                 // check whether sending post content in email notifications is allowed
513                 $content_allowed = !get_config('system','enotify_no_content');
514
515                 // load the template for private message notifications
516                 $tpl = get_markup_template('email_notify_html.tpl');
517                 $email_html_body = replace_macros($tpl,array(
518                         '$banner'       => $datarray['banner'],
519                         '$product'      => $datarray['product'],
520                         '$preamble'     => $datarray['preamble'],
521                         '$sitename'     => $datarray['sitename'],
522                         '$siteurl'      => $datarray['siteurl'],
523                         '$source_name'  => $datarray['source_name'],
524                         '$source_link'  => $datarray['source_link'],
525                         '$source_photo' => $datarray['source_photo'],
526                         '$username'     => $datarray['to_name'],
527                         '$hsitelink'    => $datarray['hsitelink'],
528                         '$hitemlink'    => $datarray['hitemlink'],
529                         '$thanks'       => $datarray['thanks'],
530                         '$site_admin'   => $datarray['site_admin'],
531                         '$title'                => $datarray['title'],
532                         '$htmlversion'  => $datarray['htmlversion'],
533                         '$content_allowed'      => $content_allowed,
534                 ));
535
536                 // load the template for private message notifications
537                 $tpl = get_markup_template('email_notify_text.tpl');
538                 $email_text_body = replace_macros($tpl,array(
539                         '$banner'       => $datarray['banner'],
540                         '$product'      => $datarray['product'],
541                         '$preamble'     => $datarray['preamble'],
542                         '$sitename'     => $datarray['sitename'],
543                         '$siteurl'      => $datarray['siteurl'],
544                         '$source_name'  => $datarray['source_name'],
545                         '$source_link'  => $datarray['source_link'],
546                         '$source_photo' => $datarray['source_photo'],
547                         '$username'     => $datarray['to_name'],
548                         '$tsitelink'    => $datarray['tsitelink'],
549                         '$titemlink'    => $datarray['titemlink'],
550                         '$thanks'       => $datarray['thanks'],
551                         '$site_admin'   => $datarray['site_admin'],
552                         '$title'                => $datarray['title'],
553                         '$textversion'  => $datarray['textversion'],
554                         '$content_allowed'      => $content_allowed,
555                 ));
556
557 //              logger('text: ' . $email_text_body);
558
559                 // use the Emailer class to send the message
560
561                 Emailer::send(array(
562                         'fromName' => $sender_name,
563                         'fromEmail' => $sender_email,
564                         'replyTo' => $sender_email,
565                         'toEmail' => $params['to_email'],
566                         'messageSubject' => $datarray['subject'],
567                         'htmlVersion' => $email_html_body,
568                         'textVersion' => $email_text_body,
569                         'additionalMailHeader' => $datarray['headers'],
570                 ));
571         return True;
572         }
573
574     return False;
575
576 }
577
578 ?>