You are here

function _if_char_allowed in Protected Submissions 7

1 call to _if_char_allowed()
_protected_submissions_validate in ./protected_submissions.module
Validate the submitted text fields.

File

./protected_submissions.module, line 878
Blocks submissions from anonymous users that contain pre-defined strings.

Code

function _if_char_allowed($random_char, $allowed_scripts, $language_scripts) {
  $char = mb_convert_encoding($random_char, 'UCS-2LE', 'UTF-8');
  $char = ord(substr($char, 1, 1)) * 256 + ord(substr($char, 0, 1));
  foreach ($allowed_scripts as $key => $lang_script) {

    // Iterate through only allowed scripts.
    if ($lang_script != FALSE) {
      foreach ($language_scripts[$lang_script] as $key => $range) {
        $range = explode(' - ', $range);

        // Turn first and last Unicode hex to decimals and compare with the character.
        if (hexdec($range[0]) < $char && $char < hexdec($range[1])) {
          $found = TRUE;
        }
      }
    }
  }
  if (isset($found) && $found == TRUE) {
    return TRUE;
  }
  else {
    return FALSE;
  }
}