You are here

function subscriptions_comment in Subscriptions 5

Implementation of hook_comment().

File

./subscriptions.module, line 764

Code

function subscriptions_comment($comment, $op) {
  global $user;
  $strsent = '!';

  // $comment can be an object or an array.
  $comment = (array) $comment;
  if ($op == 'insert' || $op == 'update' && $comment['status'] == 0) {

    // ignore deactivated comments
    // if use_cron is set, insert node actions into holding table
    if (variable_get('subscriptions_usecron', 0)) {
      subscriptions_hold($comment, 'comment', $op, $user->uid);
    }
    else {

      // if cron is not used
      $nid = $comment['nid'];
      $nobj = node_load($nid);

      // send node subscriptions
      $strsent .= subscriptions_mailvars($nid, $comment['cid'], $user->uid, 'node', $strsent);

      // get subscription->node->taxonomy
      $taxa = subscriptions_comment_taxa($comment);

      // send to taxonomy subscribers
      foreach ($taxa as $tid) {
        $strsent .= subscriptions_mailvars($tid, $nid, $user->uid, 'taxa', $strsent);
      }

      // send content type subscriptions
      $strsent .= subscriptions_mailvars($nobj->type, $nobj->nid, $user->uid, 'type', $strsent);
    }

    // end cron test
    subscriptions_autosubscribe($user->uid, $nid);
  }
}