You are here

function og_comment in Organic groups 5

Same name and namespace in other branches
  1. 5.2 og.module \og_comment()
  2. 5.7 og.module \og_comment()

File

./og.module, line 1835

Code

function og_comment($comment, $op) {
  switch ($op) {
    case 'publish':
      $comment = (array) $comment;

    // fall through
    case 'insert':
      $skip_notification = FALSE;

      // Any module that returns true from its hook_og_notify($node) will prevent sending notifications.
      // og2list uses this to send its own notifications instead for mailing list content.
      $node = node_load($comment['nid']);
      foreach (module_implements('og_notify') as $module) {
        if (module_invoke($module, 'og_notify', $node)) {
          $skip_notification = TRUE;
          break;
        }
      }

      // remove the perm check after 5.3 is released.
      if ($comment['status'] == COMMENT_PUBLISHED && !$skip_notification && og_is_mail_type($node->type) && isset($node->og_groups) && !empty($node->og_groups)) {
        if (module_exists('job_queue')) {
          $description = t('OG: Notify group members about comment %id on !link.', array(
            '%id' => $comment['cid'],
            '!link' => l($node->title, "node/{$node->nid}", NULL, NULL, 'comment-' . $comment['cid']),
          ));
          job_queue_add('og_mail', $description, array(
            'comment',
            $comment['cid'],
          ));
        }
        else {
          og_mail('comment', (object) $comment);
        }
      }
      break;
  }
}