3 function notification($params) {
5 logger('notification: entry');
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 = t('Administrator');
16 $sender_email = t('noreply') . '@' . $a->get_hostname();
18 $title = $params['item']['title'];
19 $body = $params['item']['body'];
21 if($params['type'] == NOTIFY_MAIL) {
23 $subject = sprintf( t('New mail received at %s'),$sitename);
25 $preamble = sprintf( t('%s sent you a new private message at %s.'),$params['source_name'],$sitename);
27 $sitelink = t('Please visit %s to view and/or reply to your private messages.');
28 $tsitelink = sprintf( $sitelink, $siteurl . '/message' );
29 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '/message">' . $sitename . '</a>');
33 if($params['type'] == NOTIFY_COMMENT) {
35 $preamble = $subject = sprintf( t('%s commented on an item at %s'), $params['source_name'], $sitename);
37 $sitelink = t('Please visit %s to view and/or reply to the conversation.');
38 $tsitelink = sprintf( $sitelink, $siteurl );
39 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
40 $itemlink = $params['link'];
43 if($params['type'] == NOTIFY_WALL) {
44 $preamble = $subject = sprintf( t('%s posted to your profile wall at %s') , $params['source_name'], $sitename);
46 $sitelink = t('Please visit %s to view and/or reply to the conversation.');
47 $tsitelink = sprintf( $sitelink, $siteurl );
48 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
49 $itemlink = $params['link'];
53 // send email notification if notification preferences permit
55 require_once('bbcode.php');
56 if(intval($params['notify_flags']) & intval($params['type'])) {
58 logger('notification: sending email');
60 push_lang($params['language']);
62 $textversion = strip_tags(html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n"), "\n",
63 $body))),ENT_QUOTES,'UTF-8'));
64 $htmlversion = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"),
67 // load the template for private message notifications
68 $tpl = get_markup_template('email_notify_html.tpl');
69 $email_html_body = replace_macros($tpl,array(
71 '$product' => $product,
72 '$preamble' => $preamble,
73 '$sitename' => $sitename,
74 '$siteurl' => $siteurl,
75 '$source_name' => $parama['source_name'],
76 '$source_link' => $params['source_link'],
77 '$source_photo' => $params['source_photo'],
78 '$username' => $params['to_name'],
79 '$hsitelink' => $hsitelink,
80 '$itemlink' => $itemlink,
82 '$site_admin' => $site_admin,
83 '$title' => stripslashes($title),
84 '$htmlversion' => $htmlversion,
87 // load the template for private message notifications
88 $tpl = get_markup_template('email_notify_text.tpl');
89 $email_text_body = replace_macros($tpl,array(
91 '$product' => $product,
92 '$preamble' => $preamble,
93 '$sitename' => $sitename,
94 '$siteurl' => $siteurl,
95 '$source_name' => $parama['source_name'],
96 '$source_link' => $params['source_link'],
97 '$source_photo' => $params['source_photo'],
98 '$username' => $params['to_name'],
99 '$tsitelink' => $tsitelink,
100 '$itemlink' => $itemlink,
101 '$thanks' => $thanks,
102 '$site_admin' => $site_admin,
103 '$title' => stripslashes($title),
104 '$textversion' => $textversion,
107 logger('text: ' . $email_text_body);
109 // use the EmailNotification library to send the message
112 'fromName' => $sender_name,
113 'fromEmail' => $sender_email,
114 'replyTo' => $sender_email,
115 'toEmail' => $params['to_email'],
116 'messageSubject' => $subject,
117 'htmlVersion' => $email_html_body,
118 'textVersion' => $email_text_body
124 require_once('include/email.php');
128 * Send a multipart/alternative message with Text and HTML versions
130 * @param fromName name of the sender
131 * @param fromEmail email fo the sender
132 * @param replyTo replyTo address to direct responses
133 * @param toEmail destination email address
134 * @param messageSubject subject of the message
135 * @param htmlVersion html version of the message
136 * @param textVersion text only version of the message
138 static public function send($params) {
140 $fromName = email_header_encode($params['fromName'],'UTF-8');
141 $messageSubject = email_header_encode($params['messageSubject'],'UTF-8');
143 // generate a mime boundary
144 $mimeBoundary =rand(0,9)."-"
145 .rand(10000000000,9999999999)."-"
146 .rand(10000000000,9999999999)."=:"
149 // generate a multipart/alternative message header
151 "From: {$params['fromName']} <{$params['fromEmail']}>\n" .
152 "Reply-To: {$params['replyTo']}\n" .
153 "MIME-Version: 1.0\n" .
154 "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
156 // assemble the final multipart message body with the text and html types included
157 $textBody = chunk_split(base64_encode($params['textVersion']));
158 $htmlBody = chunk_split(base64_encode($params['htmlVersion']));
159 $multipartMessageBody =
160 "--" . $mimeBoundary . "\n" . // plain text section
161 "Content-Type: text/plain; charset=UTF-8\n" .
162 "Content-Transfer-Encoding: base64\n\n" .
164 "--" . $mimeBoundary . "\n" . // text/html section
165 "Content-Type: text/html; charset=UTF-8\n" .
166 "Content-Transfer-Encoding: base64\n\n" .
168 "--" . $mimeBoundary . "--\n"; // message ending
172 $params['toEmail'], // send to address
173 $params['messageSubject'], // subject
174 $multipartMessageBody, // message body
175 $messageHeader // message headers
177 logger("enotify::send returns " . $res, LOGGER_DEBUG);