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>');
35 $itemlink = $siteurl . '/message';
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_TAGSELF) {
58 $preamble = $subject = sprintf( t('%s tagged you at %s') , $params['source_name'], $sitename);
60 $sitelink = t('Please visit %s to view and/or reply to the conversation.');
61 $tsitelink = sprintf( $sitelink, $siteurl );
62 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
63 $itemlink = $params['link'];
66 if($params['type'] == NOTIFY_TAGSHARE) {
67 $preamble = $subject = sprintf( t('%s tagged your post at %s') , $params['source_name'], $sitename);
69 $sitelink = t('Please visit %s to view and/or reply to the conversation.');
70 $tsitelink = sprintf( $sitelink, $siteurl );
71 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
72 $itemlink = $params['link'];
75 if($params['type'] == NOTIFY_INTRO) {
76 $subject = sprintf( t('Introduction received at %s'), $sitename);
77 $preamble = sprintf( t('You\'ve received an introduction from \'%s\' at %s'), $params['source_name'], $sitename);
78 $body = sprintf( t('You may visit their profile at %s'),$params['source_link']);
80 $sitelink = t('Please visit %s to approve or reject the introduction.');
81 $tsitelink = sprintf( $sitelink, $siteurl );
82 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
83 $itemlink = $params['link'];
86 if($params['type'] == NOTIFY_SUGGEST) {
87 $subject = sprintf( t('Friend suggestion received at %s'), $sitename);
88 $preamble = sprintf( t('You\'ve received a friend suggestion from \'%s\' at %s'), $params['source_name'], $sitename);
89 $body = t('Name:') . ' ' . $params['item']['name'] . "\n";
90 $body .= t('Photo:') . ' ' . $params['item']['photo'] . "\n";
91 $body .= sprintf( t('You may visit their profile at %s'),$params['item']['url']);
93 $sitelink = t('Please visit %s to approve or reject the suggestion.');
94 $tsitelink = sprintf( $sitelink, $siteurl );
95 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
96 $itemlink = $params['link'];
99 if($params['type'] == NOTIFY_CONFIRM) {
103 // from here on everything is in the recipients language
105 push_lang($params['language']);
107 require_once('include/html2bbcode.php');
109 // create notification entry in DB
111 $r = q("insert into notify (name,url,photo,date,msg,uid,link,type,verb,otype)
112 values('%s','%s','%s','%s','%s',%d,'%s',%d,'%s','%s')",
113 dbesc($params['source_name']),
114 dbesc($params['source_link']),
115 dbesc($params['source_photo']),
116 dbesc(datetime_convert()),
118 intval($params['uid']),
120 intval($params['type']),
121 dbesc($params['verb']),
122 dbesc($params['otype'])
125 // send email notification if notification preferences permit
127 require_once('bbcode.php');
128 if(intval($params['notify_flags']) & intval($params['type'])) {
130 logger('notification: sending notification email');
133 $textversion = strip_tags(html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n"), "\n",
134 $body))),ENT_QUOTES,'UTF-8'));
135 $htmlversion = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"),
136 "<br />\n",$body))));
138 // load the template for private message notifications
139 $tpl = get_markup_template('email_notify_html.tpl');
140 $email_html_body = replace_macros($tpl,array(
141 '$banner' => $banner,
142 '$product' => $product,
143 '$preamble' => $preamble,
144 '$sitename' => $sitename,
145 '$siteurl' => $siteurl,
146 '$source_name' => $params['source_name'],
147 '$source_link' => $params['source_link'],
148 '$source_photo' => $params['source_photo'],
149 '$username' => $params['to_name'],
150 '$hsitelink' => $hsitelink,
151 '$itemlink' => '<a href="' . $itemlink . '">' . $itemlink . '</a>',
152 '$thanks' => $thanks,
153 '$site_admin' => $site_admin,
154 '$title' => stripslashes($title),
155 '$htmlversion' => $htmlversion,
158 // load the template for private message notifications
159 $tpl = get_markup_template('email_notify_text.tpl');
160 $email_text_body = replace_macros($tpl,array(
161 '$banner' => $banner,
162 '$product' => $product,
163 '$preamble' => $preamble,
164 '$sitename' => $sitename,
165 '$siteurl' => $siteurl,
166 '$source_name' => $params['source_name'],
167 '$source_link' => $params['source_link'],
168 '$source_photo' => $params['source_photo'],
169 '$username' => $params['to_name'],
170 '$tsitelink' => $tsitelink,
171 '$itemlink' => $itemlink,
172 '$thanks' => $thanks,
173 '$site_admin' => $site_admin,
174 '$title' => stripslashes($title),
175 '$textversion' => $textversion,
178 // logger('text: ' . $email_text_body);
180 // use the EmailNotification library to send the message
183 'fromName' => $sender_name,
184 'fromEmail' => $sender_email,
185 'replyTo' => $sender_email,
186 'toEmail' => $params['to_email'],
187 'messageSubject' => $subject,
188 'htmlVersion' => $email_html_body,
189 'textVersion' => $email_text_body
197 require_once('include/email.php');
201 * Send a multipart/alternative message with Text and HTML versions
203 * @param fromName name of the sender
204 * @param fromEmail email fo the sender
205 * @param replyTo replyTo address to direct responses
206 * @param toEmail destination email address
207 * @param messageSubject subject of the message
208 * @param htmlVersion html version of the message
209 * @param textVersion text only version of the message
211 static public function send($params) {
213 $fromName = email_header_encode($params['fromName'],'UTF-8');
214 $messageSubject = email_header_encode($params['messageSubject'],'UTF-8');
216 // generate a mime boundary
217 $mimeBoundary =rand(0,9)."-"
218 .rand(10000000000,9999999999)."-"
219 .rand(10000000000,9999999999)."=:"
222 // generate a multipart/alternative message header
224 "From: {$params['fromName']} <{$params['fromEmail']}>\n" .
225 "Reply-To: {$params['fromName']} <{$params['replyTo']}>\n" .
226 "MIME-Version: 1.0\n" .
227 "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
229 // assemble the final multipart message body with the text and html types included
230 $textBody = chunk_split(base64_encode($params['textVersion']));
231 $htmlBody = chunk_split(base64_encode($params['htmlVersion']));
232 $multipartMessageBody =
233 "--" . $mimeBoundary . "\n" . // plain text section
234 "Content-Type: text/plain; charset=UTF-8\n" .
235 "Content-Transfer-Encoding: base64\n\n" .
237 "--" . $mimeBoundary . "\n" . // text/html section
238 "Content-Type: text/html; charset=UTF-8\n" .
239 "Content-Transfer-Encoding: base64\n\n" .
241 "--" . $mimeBoundary . "--\n"; // message ending
245 $params['toEmail'], // send to address
246 $params['messageSubject'], // subject
247 $multipartMessageBody, // message body
248 $messageHeader // message headers
250 logger("notification: enotify::send returns " . $res, LOGGER_DEBUG);