]> git.mxchange.org Git - friendica.git/blob - include/enotify.php
more work on enotify
[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                 $new_email = sprintf( t('%s sent you a new private message at %s.'),$params['source_name'],$sitename);
42                 $email_visit = t('Please visit %s to view and/or reply to your private messages.');
43                 $email_tlink = sprintf( $email_visit, $siteurl . '/message' );
44                 $email_hlink = 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['notificationfromname']    = $sender_name;
57                 $msg['notificationfromemail']   = $sender_email;
58
59                 $msg['textversion']
60                                 = strip_tags(html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n"), "\n",
61                                         $body))),ENT_QUOTES,'UTF-8'));
62                 $msg['htmlversion']     
63                                 = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"), 
64                                                 "<br />\n",$body))));
65
66                 // load the template for private message notifications
67                 $tpl = get_intltext_template('mail_received_html_body_eml.tpl');
68                 $email_html_body_tpl = replace_macros($tpl,array(
69                         '$username'     => $importer['username'],
70                         '$siteName'             => $a->config['sitename'],                      // name of this site
71                         '$siteurl'              => $a->get_baseurl(),                           // descriptive url of this site
72                         '$thumb'                => $importer['thumb'],                          // thumbnail url for sender icon
73                         '$email'                => $importer['email'],                          // email address to send to
74                         '$url'                  => $importer['url'],                            // full url for the site
75                         '$from'                 => $msg['from-name'],                           // name of the person sending the message
76                         '$title'                => stripslashes($msg['title']),                 // subject of the message
77                         '$htmlversion'  => $msg['htmlversion'],                                 // html version of the message
78                         '$mimeboundary' => $msg['mimeboundary'],                                // mime message divider
79                         '$hostname'             => $a->get_hostname()                           // name of this host
80                 ));
81                 
82                 // load the template for private message notifications
83                 $tpl = get_intltext_template('mail_received_text_body_eml.tpl');
84                 $email_text_body_tpl = replace_macros($tpl,array(
85                         '$username'     => $importer['username'],
86                         '$siteName'             => $a->config['sitename'],                      // name of this site
87                         '$siteurl'              => $a->get_baseurl(),                           // descriptive url of this site
88                         '$thumb'                => $importer['thumb'],                          // thumbnail url for sender icon
89                         '$email'                => $importer['email'],                          // email address to send to
90                         '$url'                  => $importer['url'],                            // full url for the site
91                         '$from'                 => $msg['from-name'],                           // name of the person sending the message
92                         '$title'                => stripslashes($msg['title']),                 // subject of the message
93                         '$textversion'  => $msg['textversion'],                                 // text version of the message
94                         '$mimeboundary' => $msg['mimeboundary'],                                // mime message divider
95                         '$hostname'             => $a->get_hostname()                           // name of this host
96                 ));
97
98                 // use the EmailNotification library to send the message
99                 require_once("include/EmailNotification.php");
100                 EmailNotification::sendTextHtmlEmail(
101                         $msg['notificationfromname'],
102                         $msg['notificationfromemail'],
103                         $msg['notificationfromemail'],
104                         $importer['email'],
105                         $subject,
106                         $email_html_body_tpl,
107                         $email_text_body_tpl
108                 );
109                         pop_lang();
110         }
111 }
112
113 require_once('include/email.php');
114
115 class enotify {
116         /**
117          * Send a multipart/alternative message with Text and HTML versions
118          *
119          * @param fromName                      name of the sender
120          * @param fromEmail                     email fo the sender
121          * @param replyTo                       replyTo address to direct responses
122          * @param toEmail                       destination email address
123          * @param messageSubject        subject of the message
124          * @param htmlVersion           html version of the message
125          * @param textVersion           text only version of the message
126          */
127         static public function send($params) {
128                 $fromName = email_header_encode($params['fromName'],'UTF-8'); 
129                 $messageSubject = email_header_encode($params['messageSubject'],'UTF-8');
130                 
131                 
132                 // generate a mime boundary
133                 $mimeBoundary   =rand(0,9)."-"
134                                 .rand(10000000000,9999999999)."-"
135                                 .rand(10000000000,9999999999)."=:"
136                                 .rand(10000,99999);
137
138                 // generate a multipart/alternative message header
139                 $messageHeader =
140                         "From: {$params['fromName']} <{$params['fromEmail']}>\n" . 
141                         "Reply-To: {$params['replyTo']}\n" .
142                         "MIME-Version: 1.0\n" .
143                         "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
144
145                 // assemble the final multipart message body with the text and html types included
146                 $textBody       =       chunk_split(base64_encode($params['textVersion']));
147                 $htmlBody       =       chunk_split(base64_encode($params['htmlVersion']));
148                 $multipartMessageBody =
149                         "--" . $mimeBoundary . "\n" .                                   // plain text section
150                         "Content-Type: text/plain; charset=UTF-8\n" .
151                         "Content-Transfer-Encoding: base64\n\n" .
152                         $textBody . "\n" .
153                         "--" . $mimeBoundary . "\n" .                                   // text/html section
154                         "Content-Type: text/html; charset=UTF-8\n" .
155                         "Content-Transfer-Encoding: base64\n\n" .
156                         $htmlBody . "\n" .
157                         "--" . $mimeBoundary . "--\n";                                  // message ending
158
159                 // send the message
160                 $res = mail(
161                         $toEmail,                                                                               // send to address
162                         $messageSubject,                                                                // subject
163                         $multipartMessageBody,                                                  // message body
164                         $messageHeader                                                                  // message headers
165                 );
166                 logger("sendTextHtmlEmail: returns " . $res, LOGGER_DEBUG);
167         }
168 }
169 ?>