]> git.mxchange.org Git - friendica.git/blob - include/enotify.php
Merge branch 'master' into notify
[friendica.git] / include / enotify.php
1 <?php
2
3
4                 // send email notification if requested.
5 /*
6                 $notif_params = array(
7                         'type' => NOTIFY_MAIL,
8                         'notify_flags' => $importer['notify_flags'],
9                         'language' => $importer['language'],
10                         'to_name' => $importer['username'],
11                         'to_email' => $importer['email'],
12                         'item' => $msg,
13                         'source_name' => $msg['from-name'],
14                         'source_link' => $importer['url'],
15                         'source_photo' => $importer['thumb'],
16                 );
17 */                      
18                 //notification($notif_params);
19
20
21 function notification($params) {
22
23         $a = get_app();
24         $banner = t('Friendica Notification');
25         $product = FRIENDICA_PLATFORM;
26         $siteurl = z_path();
27         $thanks = t('Thank You,');
28         $sitename = get_config('config','sitename');
29         $site_admin = sprintf( t('%s Administrator'), $sitename);
30
31         $sender_name = t('Administrator');
32         $sender_email = t('noreply') . '@' . $a->get_hostname();
33
34         $title = $params['item']['title'];
35         $body = $params['item']['body'];
36
37         if($params['type'] == NOTIFY_MAIL) {
38
39                 $subject =      sprintf( t('New mail received at %s'),$sitename);
40
41                 $preamble = sprintf( t('%s sent you a new private message at %s.'),$params['source_name'],$sitename);
42                 $sitelink = t('Please visit %s to view and/or reply to your private messages.');
43                 $tsitelink = sprintf( $email_visit, $siteurl . '/message' );
44                 $hsitelink = sprintf( $email_visit, '<a href="' . $siteurl . '/message">' . $sitename . '</a>');
45
46         }
47
48
49         // send email notification if notification preferences permit
50
51         require_once('bbcode.php');
52         if(intval($params['notify-flags']) & intval($params['type'])) {
53
54                 push_lang($params['language']);
55
56                 $msg = array();
57                 $msg['fromname']        = $sender_name;
58                 $msg['fromemail']       = $sender_email;
59
60                 $msg['textversion'] = strip_tags(html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n"), "\n",
61                                         $body))),ENT_QUOTES,'UTF-8'));
62                 $msg['htmlversion']     = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"), 
63                                                 "<br />\n",$body))));
64
65                 // load the template for private message notifications
66                 $tpl = get_view_template('email_notify_html.tpl');
67                 $email_html_body_tpl = replace_macros($tpl,array(
68                         '$banner' => $banner,
69                         '$product' => $product,
70                         '$preamble' => $preamble,
71                         '$source_name' => $parama['source_name'],
72                         '$source_link' => $params['source_link'],
73                         '$source_photo' => $params['source_photo'],
74                         '$username'     => $params['to_name'],
75                         '$hsitelink'    => $hsitelink,
76                         '$thanks'       => $thanks,
77                         '$site_admin'   => $site_admin,
78                         '$title'                => stripslashes($msg['title']),                 // subject of the message
79                         '$htmlversion'  => $msg['htmlversion'],                                 // html version of the message
80
81                 ));
82                 
83                 // load the template for private message notifications
84                 $tpl = get_intltext_template('mail_received_text_body_eml.tpl');
85                 $email_text_body_tpl = replace_macros($tpl,array(
86                         '$username'     => $importer['username'],
87                         '$siteName'             => $a->config['sitename'],                      // name of this site
88                         '$siteurl'              => $a->get_baseurl(),                           // descriptive url of this site
89                         '$thumb'                => $importer['thumb'],                          // thumbnail url for sender icon
90                         '$email'                => $importer['email'],                          // email address to send to
91                         '$url'                  => $importer['url'],                            // full url for the site
92                         '$from'                 => $msg['from-name'],                           // name of the person sending the message
93                         '$title'                => stripslashes($msg['title']),                 // subject of the message
94                         '$textversion'  => $msg['textversion'],                                 // text version of the message
95                         '$mimeboundary' => $msg['mimeboundary'],                                // mime message divider
96                         '$hostname'             => $a->get_hostname()                           // name of this host
97                 ));
98
99                 // use the EmailNotification library to send the message
100                 require_once("include/EmailNotification.php");
101                 EmailNotification::sendTextHtmlEmail(
102                         $msg['notificationfromname'],
103                         $msg['notificationfromemail'],
104                         $msg['notificationfromemail'],
105                         $importer['email'],
106                         $subject,
107                         $email_html_body_tpl,
108                         $email_text_body_tpl
109                 );
110                         pop_lang();
111         }
112 }
113
114 require_once('include/email.php');
115
116 class enotify {
117         /**
118          * Send a multipart/alternative message with Text and HTML versions
119          *
120          * @param fromName                      name of the sender
121          * @param fromEmail                     email fo the sender
122          * @param replyTo                       replyTo address to direct responses
123          * @param toEmail                       destination email address
124          * @param messageSubject        subject of the message
125          * @param htmlVersion           html version of the message
126          * @param textVersion           text only version of the message
127          */
128         static public function send($params) {
129                 $fromName = email_header_encode($params['fromName'],'UTF-8'); 
130                 $messageSubject = email_header_encode($params['messageSubject'],'UTF-8');
131                 
132                 
133                 // generate a mime boundary
134                 $mimeBoundary   =rand(0,9)."-"
135                                 .rand(10000000000,9999999999)."-"
136                                 .rand(10000000000,9999999999)."=:"
137                                 .rand(10000,99999);
138
139                 // generate a multipart/alternative message header
140                 $messageHeader =
141                         "From: {$params['fromName']} <{$params['fromEmail']}>\n" . 
142                         "Reply-To: {$params['replyTo']}\n" .
143                         "MIME-Version: 1.0\n" .
144                         "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
145
146                 // assemble the final multipart message body with the text and html types included
147                 $textBody       =       chunk_split(base64_encode($params['textVersion']));
148                 $htmlBody       =       chunk_split(base64_encode($params['htmlVersion']));
149                 $multipartMessageBody =
150                         "--" . $mimeBoundary . "\n" .                                   // plain text section
151                         "Content-Type: text/plain; charset=UTF-8\n" .
152                         "Content-Transfer-Encoding: base64\n\n" .
153                         $textBody . "\n" .
154                         "--" . $mimeBoundary . "\n" .                                   // text/html section
155                         "Content-Type: text/html; charset=UTF-8\n" .
156                         "Content-Transfer-Encoding: base64\n\n" .
157                         $htmlBody . "\n" .
158                         "--" . $mimeBoundary . "--\n";                                  // message ending
159
160                 // send the message
161                 $res = mail(
162                         $toEmail,                                                                               // send to address
163                         $messageSubject,                                                                // subject
164                         $multipartMessageBody,                                                  // message body
165                         $messageHeader                                                                  // message headers
166                 );
167                 logger("sendTextHtmlEmail: returns " . $res, LOGGER_DEBUG);
168         }
169 }
170 ?>