You are here

function protected_submissions_if_char_allowed in Protected Submissions 8

Helper function to check if character belongs to allowed language scripts.

Parameters

string $random_char: A character.

array $allowed_scripts: An array of allowed scripts.

array $language_scripts: An array of language scripts.

Return value

bool Return true if char is allowed.

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

File

./protected_submissions.module, line 758
Protected Submissions module.

Code

function protected_submissions_if_char_allowed($random_char, array $allowed_scripts, array $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 $lang_script) {

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

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