You are here

function notifications_content_comment in Notifications 6.3

Same name and namespace in other branches
  1. 5 notifications_content/notifications_content.module \notifications_content_comment()
  2. 6.4 notifications_content/notifications_content.module \notifications_content_comment()
  3. 6 notifications_content/notifications_content.module \notifications_content_comment()
  4. 6.2 notifications_content/notifications_content.module \notifications_content_comment()

Implementation of hook_comment().

This is a bit tricky because we just want to send notifications when they are published. Quick reminder:

  • Normal 'insert' operations are followed by a 'publish' one so we don't process that ones.
  • Normal 'update' operations are followed by a 'publish' whatever the previous status was
  • For 'publish' operations we notify if the comment was not published before.

Note that we don't take the comment by ref so we don't change it when it's an array

File

notifications_content/notifications_content.module, line 738
Subscriptions to content events

Code

function notifications_content_comment($comment, $op) {

  // $comment can be an object or an array.
  $comment = (object) $comment;
  if ($op == 'publish' && empty($comment->notifications_content_disable) && (!isset($comment->notifications_comment_status) || !empty($comment->notifications_comment_status))) {

    // Check that the node is published and comment notifications are enabled for this node type
    $node = node_load($comment->nid);
    if ($node->status && notifications_content_type_enabled($node->type)) {
      $event = array(
        'uid' => $comment->uid,
        // For this special case the event actor is the user who posts the comment
        'module' => 'node',
        'type' => 'node',
        'subtype' => $node->type,
        'action' => 'comment',
        'node' => $node,
        'comment' => $comment,
        'params' => array(
          'nid' => $comment->nid,
          'cid' => $comment->cid,
        ),
      );
      notifications_event($event);
    }
  }
}