mirror of https://github.com/BOINC/boinc.git
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.
This commit is contained in:
parent
df9d234fc8
commit
4c22f0a2a9
|
@ -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',
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* Implementation of hook_install()
|
||||
*/
|
||||
function flag_comment_notify_install() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_uninstall().
|
||||
*/
|
||||
function flag_comment_notify_uninstall() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_schema().
|
||||
*/
|
||||
function flag_comment_notify_schema() {
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides notifications when comments are posted to flagged content
|
||||
*
|
||||
* The flag module does not provide a mechanism for notifying users when nodes
|
||||
* that they have flagged have new comments. Drupal does provide a hook for
|
||||
* comments, so this module provides the missing functionality.
|
||||
*/
|
||||
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Includes that provide supporting functions
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
// ...
|
||||
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Hooks into core modules
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/**
|
||||
* Implementation of hook_comment();
|
||||
*/
|
||||
function flag_comment_notify_comment(&$a1, $op) {
|
||||
switch ($op) {
|
||||
case 'insert':
|
||||
case 'update':
|
||||
module_load_include('inc', 'drupal_queue', 'drupal_queue');
|
||||
$queue = DrupalQueue::get('flag_comment_notify');
|
||||
$subscribed_users = array_keys(flag_get_content_flags('node', $a1['nid'], 'subscriptions'));
|
||||
foreach ($subscribed_users as $uid) {
|
||||
$queue->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:
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue