restrict_abusive_words.module in Restrict Abusive Words 8        
                          
                  
                        
  
  
  
File
  restrict_abusive_words.module
  
    View source  
  <?php
use Drupal\Core\Database\Database;
function _restrict_abusive_words_search_words($words, $string) {
  if (!empty($string) && isset($words)) {
    foreach ($words as $word) {
      if (preg_match("/\\b{$word}\\b/i", $string)) {
        return $word;
      }
    }
  }
  return FALSE;
}
function _restrict_abusive_words_exists_words($words, $string) {
  if (!empty($string) && isset($words)) {
    foreach ($words as $word) {
      if ($string == $word) {
        return $word;
      }
    }
  }
  return FALSE;
}
function _restrict_abusive_words_get_words_list($wid) {
  $output = array();
  $connection = Database::getConnection();
  $query = $connection
    ->select('restrict_abusive_words', 'raw');
  if (!empty($wid) && is_numeric($wid)) {
    $query
      ->condition('id', $wid);
  }
  $query
    ->fields('raw');
  
  $data = $query
    ->execute();
  
  $results = $data
    ->fetchAll(\PDO::FETCH_OBJ);
  if (count($results) > 0) {
    foreach ($results as $result) {
      $output[$result->id] = $result->words;
    }
    return $output;
  }
  return FALSE;
}
function _restrict_abusive_words_validation_message($field, $word) {
  $message = t("%word is not allowed word to use as it is abusive words. Please correct the word or contact to site administrator.", array(
    "%word" => $word,
  ));
  form_set_error($field, $message);
}
function _restrict_abusive_words_submit_message($entity, $title, $word) {
  $message = "{$title}( {$entity} ) is deactived, please check the word:{$word}, it is a abusive word.";
  drupal_set_message($message, 'warning');
}
function _restrict_abusive_words_abusive_word_autocomplete($string) {
  if (!empty($string)) {
    $matches = array();
    $connection = Database::getConnection();
    $sth = $connection
      ->select('restrict_abusive_words', 'raw')
      ->fields('raw')
      ->condition('words', db_like($string) . '%', 'LIKE')
      ->orderBy('words', 'ASC')
      ->range(0, 10);
    
    $data = $sth
      ->execute();
    
    $result = $data
      ->fetchAll(\PDO::FETCH_OBJ);
    
    foreach ($result as $row) {
      $matches[$row->words] = check_plain($row->words);
    }
    
    drupal_json_output($matches);
  }
}