You are here

function geshifilter_per_language_settings_validate in GeSHi Filter for syntax highlighting 5.2

Same name and namespace in other branches
  1. 6 geshifilter.admin.inc \geshifilter_per_language_settings_validate()
  2. 7 geshifilter.admin.inc \geshifilter_per_language_settings_validate()

Validate function for per language settings

Check that language tags differ between languages and fro the generic tags.

File

./geshifilter.admin.inc, line 263

Code

function geshifilter_per_language_settings_validate($form_id, $form_values) {

  // if we're coming from the _geshifilter_filter_settings (sub)form, we should
  // take the input format into account
  $format = isset($form_values['format']) ? $form_values['format'] : NULL;
  $f = $format === NULL ? '' : "_{$format}";

  // language tags should differ from each other
  $languages = _geshifilter_get_available_languages();
  foreach ($languages as $language1 => $language_data1) {

    // iterate over the enabled languages: skip disabled ones
    $field = "geshifilter_language_enabled_{$language1}";
    if (!(isset($form_values[$field]) ? $form_values[$field] : variable_get($field, FALSE))) {
      continue;
    }

    // get the associated tags as $tags1
    $field = "geshifilter_language_tags_{$language1}{$f}";
    if (isset($form_values[$field])) {
      $tags1 = _geshifilter_tag_split($form_values[$field]);
    }
    else {
      $tags1 = _geshifilter_tag_split(geshifilter_language_tags($language1, $format));
    }

    // also include the generic tags
    $field = "geshifilter_tags{$f}";
    $generic_tags = isset($form_values[$field]) ? $form_values[$field] : geshifilter_tags($format);
    $tags1 = array_merge($tags1, _geshifilter_tag_split($generic_tags));

    // check that other languages do not use these tags
    foreach ($languages as $language2 => $language_data2) {

      // check these tags against the tags of other enabled languages
      $field = "geshifilter_language_enabled_{$language2}";
      if ($language1 == $language2 || !(isset($form_values[$field]) ? $form_values[$field] : variable_get($field, FALSE))) {
        continue;
      }

      // get tags for $language2, or skip when not in $form_values
      $field = "geshifilter_language_tags_{$language2}{$f}";
      if (isset($form_values[$field])) {
        $tags2 = _geshifilter_tag_split($form_values[$field]);
      }
      else {
        continue;
      }

      // and now we can check tags1 against tags2
      foreach ($tags1 as $tag1) {
        foreach ($tags2 as $tag2) {
          if ($tag1 == $tag2) {
            form_set_error("geshifilter_language_tags_{$language2}{$f}", t('The language tags should differ between languages and from the generic tags.'));
          }
        }
      }
    }
  }
}