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_CONFIRM) {
72 // TODO - create notification entry in DB
76 // send email notification if notification preferences permit
78 require_once('bbcode.php');
79 if(intval($params['notify_flags']) & intval($params['type'])) {
81 logger('notification: sending notification email');
83 push_lang($params['language']);
85 $textversion = strip_tags(html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n"), "\n",
86 $body))),ENT_QUOTES,'UTF-8'));
87 $htmlversion = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"),
90 // load the template for private message notifications
91 $tpl = get_markup_template('email_notify_html.tpl');
92 $email_html_body = replace_macros($tpl,array(
94 '$product' => $product,
95 '$preamble' => $preamble,
96 '$sitename' => $sitename,
97 '$siteurl' => $siteurl,
98 '$source_name' => $parama['source_name'],
99 '$source_link' => $params['source_link'],
100 '$source_photo' => $params['source_photo'],
101 '$username' => $params['to_name'],
102 '$hsitelink' => $hsitelink,
103 '$itemlink' => '<a href="' . $itemlink . '">' . $itemlink . '</a>',
104 '$thanks' => $thanks,
105 '$site_admin' => $site_admin,
106 '$title' => stripslashes($title),
107 '$htmlversion' => $htmlversion,
110 // load the template for private message notifications
111 $tpl = get_markup_template('email_notify_text.tpl');
112 $email_text_body = replace_macros($tpl,array(
113 '$banner' => $banner,
114 '$product' => $product,
115 '$preamble' => $preamble,
116 '$sitename' => $sitename,
117 '$siteurl' => $siteurl,
118 '$source_name' => $parama['source_name'],
119 '$source_link' => $params['source_link'],
120 '$source_photo' => $params['source_photo'],
121 '$username' => $params['to_name'],
122 '$tsitelink' => $tsitelink,
123 '$itemlink' => $itemlink,
124 '$thanks' => $thanks,
125 '$site_admin' => $site_admin,
126 '$title' => stripslashes($title),
127 '$textversion' => $textversion,
130 // logger('text: ' . $email_text_body);
132 // use the EmailNotification library to send the message
135 'fromName' => $sender_name,
136 'fromEmail' => $sender_email,
137 'replyTo' => $sender_email,
138 'toEmail' => $params['to_email'],
139 'messageSubject' => $subject,
140 'htmlVersion' => $email_html_body,
141 'textVersion' => $email_text_body
147 require_once('include/email.php');
151 * Send a multipart/alternative message with Text and HTML versions
153 * @param fromName name of the sender
154 * @param fromEmail email fo the sender
155 * @param replyTo replyTo address to direct responses
156 * @param toEmail destination email address
157 * @param messageSubject subject of the message
158 * @param htmlVersion html version of the message
159 * @param textVersion text only version of the message
161 static public function send($params) {
163 $fromName = email_header_encode($params['fromName'],'UTF-8');
164 $messageSubject = email_header_encode($params['messageSubject'],'UTF-8');
166 // generate a mime boundary
167 $mimeBoundary =rand(0,9)."-"
168 .rand(10000000000,9999999999)."-"
169 .rand(10000000000,9999999999)."=:"
172 // generate a multipart/alternative message header
174 "From: {$params['fromName']} <{$params['fromEmail']}>\n" .
175 "Reply-To: {$params['fromName']} <{$params['replyTo']}>\n" .
176 "MIME-Version: 1.0\n" .
177 "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
179 // assemble the final multipart message body with the text and html types included
180 $textBody = chunk_split(base64_encode($params['textVersion']));
181 $htmlBody = chunk_split(base64_encode($params['htmlVersion']));
182 $multipartMessageBody =
183 "--" . $mimeBoundary . "\n" . // plain text section
184 "Content-Type: text/plain; charset=UTF-8\n" .
185 "Content-Transfer-Encoding: base64\n\n" .
187 "--" . $mimeBoundary . "\n" . // text/html section
188 "Content-Type: text/html; charset=UTF-8\n" .
189 "Content-Transfer-Encoding: base64\n\n" .
191 "--" . $mimeBoundary . "--\n"; // message ending
195 $params['toEmail'], // send to address
196 $params['messageSubject'], // subject
197 $multipartMessageBody, // message body
198 $messageHeader // message headers
200 logger("notification: enotify::send returns " . $res, LOGGER_DEBUG);