notify.module

File

modules/notify/notify.module
View source
  1. <?php
  2. /**
  3. * $cid is the related content's cid, if applicable.
  4. *
  5. * If there is supposed to be an attachment, it's contents should be in $attachments. At the moment, this is only used by email.
  6. *
  7. */
  8. function notify_send_notification_to_user($user_id, $msg, $cid = 0, $content_type = "", $notification_type='default', $attachments = array()) {
  9. // TODO: As a safety measure, if the user is getting TOO MANY notifications, we should throttle it. Could be a hacking
  10. // attempt or something similar.
  11. $account = fp_load_user($user_id);
  12. $user_cwid = $account->cwid;
  13. // Let's find out what the user's default notification setting is. Unless it's set to NONE, we will
  14. // use their email address.
  15. $method = "";
  16. $default_notification_method = @$account->settings['default_notification_method'];
  17. if ($default_notification_method == "") {
  18. $default_notification_method = "email";
  19. }
  20. if ($default_notification_method == "NONE") {
  21. // The user does not have a default method. Therefor, we will not be notifying them about nothing.
  22. return;
  23. }
  24. $method = $default_notification_method;
  25. $user_email = $account->email;
  26. $mobile_phone = @$account->attributes['mobile_phone'];
  27. $subject = t("FlightPath - Notification");
  28. $msg .= "<br><br>\n\n " . t("To change your notification options, visit your settings page in @name.", array("@name" => variable_get("system_name", "FlightPath")));
  29. if ($method == 'email') {
  30. notify_by_mail($user_email, $subject, $msg, $attachments);
  31. notify_save_notification($user_id, $cid, $content_type, 'email', $user_email, $subject, $msg, $notification_type);
  32. }
  33. if ($method == 'txt') {
  34. notify_by_sms($mobile_phone, $subject, $msg);
  35. notify_save_notification($user_id, $cid, $content_type, 'txt', $mobile_phone, $subject, $msg, $notification_type);
  36. }
  37. if ($method == 'email_txt') {
  38. // Sending to both.
  39. notify_by_mail($user_email, $subject, $msg, $attachments);
  40. notify_save_notification($user_id, $cid, $content_type, 'email', $user_email, $subject, $msg, $notification_type);
  41. notify_by_sms($mobile_phone, $subject, $msg);
  42. notify_save_notification($user_id, $cid, $content_type, 'txt', $mobile_phone, $subject, $msg, $notification_type);
  43. }
  44. } // notify_send_notification_to_user
  45. /**
  46. * Actually writes our notification to our notification_history table.
  47. */
  48. function notify_save_notification($user_id, $cid = 0, $content_type = "", $method, $address_or_num, $subject, $msg, $type = 'default') {
  49. db_query("INSERT INTO notification_history (cid, content_type, to_user_id, notification_method, to_address, subject, msg, notification_type, submitted)
  50. VALUES (?,?,?,?,?,?,?,?,?) ", array($cid, $content_type, intval($user_id), $method, $address_or_num, $subject, $msg, $type, time()));
  51. return db_insert_id();
  52. }
  53. function notify_by_mail($email, $subject, $msg, $attachments = array()) {
  54. // We will assume the attachments is in "string" format, if present.
  55. $bool_attachment_string = FALSE;
  56. if (count($attachments) > 0) $bool_attachment_string = TRUE;
  57. fp_mail($email, $subject, $msg, TRUE, $attachments, $bool_attachment_string);
  58. }
  59. function notify_by_sms($mobile_phone, $subject, $msg) {
  60. // The msg cannot have any HTML, since it's just a text message.
  61. $msg = filter_markup($msg, 'plain');
  62. $msg = str_replace("&amp;", "&", $msg); // trouble HTML chars back into normal chars for SMS.
  63. engagements_send_sms_to_number($mobile_phone, $subject . "\n--\n" . $msg);
  64. }

Functions

Namesort descending Description
notify_by_mail
notify_by_sms
notify_save_notification Actually writes our notification to our notification_history table.
notify_send_notification_to_user $cid is the related content's cid, if applicable.