You are here

function cleantalk_find_spam_comments in Anti Spam by CleanTalk 7.4

Same name and namespace in other branches
  1. 7.5 src/Form/CleantalkCheckCommentsForm.php \cleantalk_find_spam_comments()
1 call to cleantalk_find_spam_comments()
find_spam_comments_btn in src/Form/CleantalkCheckCommentsForm.php

File

src/Form/CleantalkCheckCommentsForm.php, line 128
CleanTalk module admin functions.

Code

function cleantalk_find_spam_comments($comments) {
  $spam_comments = array();
  if ($comments && count($comments) > 0) {
    $data = array();
    foreach ($comments as $comment) {

      // Skip adding the role to the user if they already have it.
      if ($comment !== FALSE && isset($comment->mail)) {
        array_push($data, $comment->mail);
      }
    }
    $data = implode(',', $data);
    $result = CleantalkHelper::api_method__spam_check_cms(trim(variable_get('cleantalk_authkey', '')), $data);
    if (isset($result['error_message'])) {
      drupal_set_message($result['error_message'], 'error');
    }
    else {
      foreach ($result as $key => $value) {
        if ($value['appears'] == '1') {
          foreach ($comments as $comment) {
            if ($comment->mail == $key) {
              $spam_comments[] = $comment;
            }
          }
        }
      }
    }
  }
  return $spam_comments;
}