function subscriptions_content_comment in Subscriptions 5.2
Same name and namespace in other branches
- 6 subscriptions_content.module \subscriptions_content_comment()
Implementation of hook_comment().
Catch comment inserts and updates and send them to the subscriptions queue.
File
- ./
subscriptions_content.module, line 241 - Subscriptions to content events
Code
function subscriptions_content_comment($comment, $op) {
global $user;
static $is_unpublished;
$comment = (array) $comment;
// $comment can be an object or an array.
if ($op == 'form') {
$is_unpublished = isset($comment['admin']) ? $comment['admin']['status']['#default_value'] : !user_access('post comments without approval');
if (user_access('administer comments')) {
$tr = 't';
$form['subscriptions_notify'] = array(
'#type' => 'checkbox',
'#title' => t('Send subscriptions notifications'),
'#default_value' => TRUE,
);
// hook_form_alter() will move the checkbox inside the Administration fieldset!
if (isset($comment['admin']) && $is_unpublished) {
// for update
$form['subscriptions_notify']['#description'] = t('Subscriptions notifications are not sent for unpublished comments (except to users who have the %administer_comments permission), but when you change !Status to %Published, Subscriptions will send out "new" notifications, unless you suppress this here.', array(
'%administer_comments' => $tr('administer comments'),
'!Status' => $tr('Status'),
'%Published' => $tr('Published'),
));
}
elseif ($is_unpublished) {
$form['subscriptions_notify']['#description'] = t('Subscriptions notifications are not sent for unpublished comments, except to users who have the %administer_comments permission, and you can even suppress the latter here.', array(
'%administer_comments' => $tr('administer comments'),
));
}
else {
$form['subscriptions_notify']['#description'] = t('You can suppress sending subscriptions notifications here; this option is not saved.');
}
}
return isset($form) ? $form : NULL;
}
if (!isset($comment['nomail']) && ($op == 'insert' || $op == 'update' || $op == 'publish')) {
if (!isset($comment['subscriptions_notify']) || $comment['subscriptions_notify']) {
$node = node_load($comment['nid']);
$event = array(
'module' => 'node',
'load_function' => 'subscriptions_content_comment_load',
'load_args' => $comment['cid'],
'uid' => $comment['uid'],
'type' => 'comment',
'action' => $op,
'is_new' => $op != 'update' || $is_unpublished && $comment['status'] == COMMENT_PUBLISHED,
'node' => $node,
'comment' => (object) $comment,
);
subscriptions_queue($event);
}
_subscriptions_content_autosubscribe($node->type, 'node', 'nid', $comment['nid'], 'on_comment');
}
}