You are here

function spam_validate_comment in Spam 5

1 call to spam_validate_comment()
spam_content_filter in ./spam.module
Determine whether or not provided text is spam.

File

./spam.module, line 2938

Code

function spam_validate_comment($cid) {
  $comment = db_fetch_object(db_query('SELECT nid FROM {comments} WHERE cid = %d', $cid));

  // new comments must be attached to nodes
  if ($comment->nid == 0) {
    spam_log(SPAM_LOG, t('spam_validate_comment: comment not attached to a node.'), 'comment', $cid);
    return FALSE;
  }
  $node = db_fetch_object(db_query('SELECT nid, status FROM {node} WHERE nid = %d', $comment->nid));
  if ($node && $node->nid) {

    // new comments must be attached to published nodes
    if ($node->status != 1) {
      spam_log(SPAM_LOG, t('spam_validate_comment: new comment attached to an unpublished node.'), 'comment', $cid);
      return FALSE;
    }
  }
  else {
    spam_log(SPAM_LOG, t('spam_validate_comment: new comment attached to a non-existing node.'), 'comment', $cid);
    return FALSE;
  }
  spam_log(SPAM_DEBUG, t('spam_validate_comment: new comment attached to existing and published node.'), 'comment', $cid);
  return TRUE;
}