From 4c22f0a2a96329c2894f61dc0a30cee136561f9e Mon Sep 17 00:00:00 2001 From: Tristan Olive Date: Tue, 20 Aug 2013 01:37:16 -0400 Subject: [PATCH] Email notifications The flag module does not include a feature to notify users when a subscribed topic has received a comment. The flag_comment_notify module fills this need by creating a mail queue for such notifications, which are processed by cron based on the Elysia configuration of the queue cron. --- ...oinc_standard.features.user_permission.inc | 8 ++ .../boinc_standard/boinc_standard.info | 4 + .../flag_comment_notify.info | 9 ++ .../flag_comment_notify.install | 20 ++++ .../flag_comment_notify.module | 98 +++++++++++++++++++ 5 files changed, 139 insertions(+) create mode 100644 drupal/sites/default/boinc/modules/flag_comment_notify/flag_comment_notify.info create mode 100644 drupal/sites/default/boinc/modules/flag_comment_notify/flag_comment_notify.install create mode 100644 drupal/sites/default/boinc/modules/flag_comment_notify/flag_comment_notify.module diff --git a/drupal/sites/all/features/boinc_standard/boinc_standard.features.user_permission.inc b/drupal/sites/all/features/boinc_standard/boinc_standard.features.user_permission.inc index 4802debbe9..43c582ac37 100644 --- a/drupal/sites/all/features/boinc_standard/boinc_standard.features.user_permission.inc +++ b/drupal/sites/all/features/boinc_standard/boinc_standard.features.user_permission.inc @@ -80,6 +80,14 @@ function boinc_standard_user_default_permissions() { ), ); + // Exported permission: administer elysia_cron + $permissions['administer elysia_cron'] = array( + 'name' => 'administer elysia_cron', + 'roles' => array( + '0' => 'administrator', + ), + ); + // Exported permission: administer features $permissions['administer features'] = array( 'name' => 'administer features', diff --git a/drupal/sites/all/features/boinc_standard/boinc_standard.info b/drupal/sites/all/features/boinc_standard/boinc_standard.info index 982e8d5c5d..57018bd405 100644 --- a/drupal/sites/all/features/boinc_standard/boinc_standard.info +++ b/drupal/sites/all/features/boinc_standard/boinc_standard.info @@ -9,10 +9,13 @@ dependencies[] = "boincuser" dependencies[] = "boincwork" dependencies[] = "content" dependencies[] = "ctools" +dependencies[] = "drupal_queue" +dependencies[] = "elysia_cron" dependencies[] = "exportables" dependencies[] = "features" dependencies[] = "flag" dependencies[] = "flag_abuse" +dependencies[] = "flag_comment_notify" dependencies[] = "ignore_user" dependencies[] = "imce" dependencies[] = "imce_wysiwyg" @@ -74,6 +77,7 @@ features[user_permission][] = "administer actions" features[user_permission][] = "administer advanced pane settings" features[user_permission][] = "administer blocks" features[user_permission][] = "administer content types" +features[user_permission][] = "administer elysia_cron" features[user_permission][] = "administer features" features[user_permission][] = "administer files" features[user_permission][] = "administer filters" diff --git a/drupal/sites/default/boinc/modules/flag_comment_notify/flag_comment_notify.info b/drupal/sites/default/boinc/modules/flag_comment_notify/flag_comment_notify.info new file mode 100644 index 0000000000..5e4c41530d --- /dev/null +++ b/drupal/sites/default/boinc/modules/flag_comment_notify/flag_comment_notify.info @@ -0,0 +1,9 @@ +; $Id$ +name = Flag Comment Notify +description = Notify users of comments on flagged content +core = 6.x +package = Flags +dependencies[] = user +dependencies[] = node +dependencies[] = flag +dependencies[] = drupal_queue diff --git a/drupal/sites/default/boinc/modules/flag_comment_notify/flag_comment_notify.install b/drupal/sites/default/boinc/modules/flag_comment_notify/flag_comment_notify.install new file mode 100644 index 0000000000..5e55d4187a --- /dev/null +++ b/drupal/sites/default/boinc/modules/flag_comment_notify/flag_comment_notify.install @@ -0,0 +1,20 @@ +createItem(array('uid' => $uid, 'cid' => (int) $a1['cid'])); + } + break; + default: + } +} + +/** + * Implementation of hook_cron_queue_info() + */ +function flag_comment_notify_cron_queue_info() { + $queues = array(); + $queues['flag_comment_notify'] = array( + 'worker callback' => 'flag_comment_notify_send_notification', + 'time' => 60, + ); + return $queues; +} + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Supporting functions + * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +function flag_comment_notify_send_notification($data) { + $account = user_load($data['uid']); + $comment = _comment_load($data['cid']); + $node = node_load($comment->nid); + $author = user_load($comment->uid); + if ($account->mail AND $node->nid) { + $params['account'] = $account; + $params['comment'] = $comment; + $params['node'] = $node; + $params['author'] = $author; + drupal_mail('flag_comment_notify', 'comment_posted', $account->mail, + user_preferred_language($account), $params); + } +} + + +function flag_comment_notify_mail($key, &$message, $params) { + $language = $message['language']; + $variables = user_mail_tokens($params['account'], $language); + $variables['!comment_url'] = url( + drupal_get_path_alias("node/{$params['node']->nid}"), + array( + 'absolute' => TRUE, + 'fragment' => "comment-{$params['comment']->cid}" + ) + ); + $variables['!topic_name'] = $params['node']->title; + $variables['!author'] = $params['author']->name; + switch($key) { + case 'comment_posted': + $message['subject'] = t('Comment posted to "!topic_name"', $variables, + $language->language); + $message['body'][] = t("A reply has been posted to \"!topic_name\" by + !author. To view this comment at !site, click here: \n!comment_url", $variables, + $language->language); + break; + default: + } +}