Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

179 lines
5.7 KiB

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