3 function notification($params) {
5 logger('notification: entry', LOGGER_DEBUG);
8 $banner = t('Friendica Notification');
9 $product = FRIENDICA_PLATFORM;
11 $thanks = t('Thank You,');
12 $sitename = get_config('config','sitename');
13 $site_admin = sprintf( t('%s Administrator'), $sitename);
15 $sender_name = $product;
16 $sender_email = t('noreply') . '@' . $a->get_hostname();
18 if(array_key_exists('item',$params)) {
19 $title = $params['item']['title'];
20 $body = $params['item']['body'];
26 if($params['type'] == NOTIFY_MAIL) {
28 $subject = sprintf( t('New mail received at %s'),$sitename);
30 $preamble = sprintf( t('%s sent you a new private message at %s.'),$params['source_name'],$sitename);
32 $sitelink = t('Please visit %s to view and/or reply to your private messages.');
33 $tsitelink = sprintf( $sitelink, $siteurl . '/message' );
34 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '/message">' . $sitename . '</a>');
38 if($params['type'] == NOTIFY_COMMENT) {
40 $subject = sprintf( t('%s commented on an item at %s'), $params['source_name'], $sitename);
41 $preamble = sprintf( t('%s commented on an item/conversation you have been following.'), $params['source_name']);
42 $sitelink = t('Please visit %s to view and/or reply to the conversation.');
43 $tsitelink = sprintf( $sitelink, $siteurl );
44 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
45 $itemlink = $params['link'];
48 if($params['type'] == NOTIFY_WALL) {
49 $preamble = $subject = sprintf( t('%s posted to your profile wall at %s') , $params['source_name'], $sitename);
51 $sitelink = t('Please visit %s to view and/or reply to the conversation.');
52 $tsitelink = sprintf( $sitelink, $siteurl );
53 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
54 $itemlink = $params['link'];
57 if($params['type'] == NOTIFY_INTRO) {
58 $subject = sprintf( t('Introduction received at %s'), $sitename);
59 $preamble = sprintf( t('You\'ve received an introduction from \'%s\' at %s'), $params['source_name'], $sitename);
60 $body = sprintf( t('You may visit their profile at %s'),$params['source_link']);
62 $sitelink = t('Please visit %s to approve or reject the introduction.');
63 $tsitelink = sprintf( $sitelink, $siteurl );
64 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
65 $itemlink = $params['link'];
68 if($params['type'] == NOTIFY_SUGGEST) {
69 $subject = sprintf( t('Friend suggestion received at %s'), $sitename);
70 $preamble = sprintf( t('You\'ve received a friend suggestion from \'%s\' at %s'), $params['source_name'], $sitename);
71 $body = t('Name:') . ' ' . $params['item']['name'] . "\n";
72 $body .= t('Photo:') . ' ' . $params['item']['photo'] . "\n";
73 $body .= sprintf( t('You may visit their profile at %s'),$params['item']['url']);
75 $sitelink = t('Please visit %s to approve or reject the suggestion.');
76 $tsitelink = sprintf( $sitelink, $siteurl );
77 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
78 $itemlink = $params['link'];
81 if($params['type'] == NOTIFY_CONFIRM) {
85 // TODO - create notification entry in DB
89 // send email notification if notification preferences permit
91 require_once('bbcode.php');
92 if(intval($params['notify_flags']) & intval($params['type'])) {
94 logger('notification: sending notification email');
96 push_lang($params['language']);
98 $textversion = strip_tags(html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n"), "\n",
99 $body))),ENT_QUOTES,'UTF-8'));
100 $htmlversion = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"),
101 "<br />\n",$body))));
103 // load the template for private message notifications
104 $tpl = get_markup_template('email_notify_html.tpl');
105 $email_html_body = replace_macros($tpl,array(
106 '$banner' => $banner,
107 '$product' => $product,
108 '$preamble' => $preamble,
109 '$sitename' => $sitename,
110 '$siteurl' => $siteurl,
111 '$source_name' => $parama['source_name'],
112 '$source_link' => $params['source_link'],
113 '$source_photo' => $params['source_photo'],
114 '$username' => $params['to_name'],
115 '$hsitelink' => $hsitelink,
116 '$itemlink' => '<a href="' . $itemlink . '">' . $itemlink . '</a>',
117 '$thanks' => $thanks,
118 '$site_admin' => $site_admin,
119 '$title' => stripslashes($title),
120 '$htmlversion' => $htmlversion,
123 // load the template for private message notifications
124 $tpl = get_markup_template('email_notify_text.tpl');
125 $email_text_body = replace_macros($tpl,array(
126 '$banner' => $banner,
127 '$product' => $product,
128 '$preamble' => $preamble,
129 '$sitename' => $sitename,
130 '$siteurl' => $siteurl,
131 '$source_name' => $parama['source_name'],
132 '$source_link' => $params['source_link'],
133 '$source_photo' => $params['source_photo'],
134 '$username' => $params['to_name'],
135 '$tsitelink' => $tsitelink,
136 '$itemlink' => $itemlink,
137 '$thanks' => $thanks,
138 '$site_admin' => $site_admin,
139 '$title' => stripslashes($title),
140 '$textversion' => $textversion,
143 // logger('text: ' . $email_text_body);
145 // use the EmailNotification library to send the message
148 'fromName' => $sender_name,
149 'fromEmail' => $sender_email,
150 'replyTo' => $sender_email,
151 'toEmail' => $params['to_email'],
152 'messageSubject' => $subject,
153 'htmlVersion' => $email_html_body,
154 'textVersion' => $email_text_body
160 require_once('include/email.php');
164 * Send a multipart/alternative message with Text and HTML versions
166 * @param fromName name of the sender
167 * @param fromEmail email fo the sender
168 * @param replyTo replyTo address to direct responses
169 * @param toEmail destination email address
170 * @param messageSubject subject of the message
171 * @param htmlVersion html version of the message
172 * @param textVersion text only version of the message
174 static public function send($params) {
176 $fromName = email_header_encode($params['fromName'],'UTF-8');
177 $messageSubject = email_header_encode($params['messageSubject'],'UTF-8');
179 // generate a mime boundary
180 $mimeBoundary =rand(0,9)."-"
181 .rand(10000000000,9999999999)."-"
182 .rand(10000000000,9999999999)."=:"
185 // generate a multipart/alternative message header
187 "From: {$params['fromName']} <{$params['fromEmail']}>\n" .
188 "Reply-To: {$params['fromName']} <{$params['replyTo']}>\n" .
189 "MIME-Version: 1.0\n" .
190 "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
192 // assemble the final multipart message body with the text and html types included
193 $textBody = chunk_split(base64_encode($params['textVersion']));
194 $htmlBody = chunk_split(base64_encode($params['htmlVersion']));
195 $multipartMessageBody =
196 "--" . $mimeBoundary . "\n" . // plain text section
197 "Content-Type: text/plain; charset=UTF-8\n" .
198 "Content-Transfer-Encoding: base64\n\n" .
200 "--" . $mimeBoundary . "\n" . // text/html section
201 "Content-Type: text/html; charset=UTF-8\n" .
202 "Content-Transfer-Encoding: base64\n\n" .
204 "--" . $mimeBoundary . "--\n"; // message ending
208 $params['toEmail'], // send to address
209 $params['messageSubject'], // subject
210 $multipartMessageBody, // message body
211 $messageHeader // message headers
213 logger("notification: enotify::send returns " . $res, LOGGER_DEBUG);