You are here

function pagestyle_admin_settings_validate in Page Style 5

Same name and namespace in other branches
  1. 6 includes/pagestyle.admin.inc \pagestyle_admin_settings_validate()
  2. 7 includes/pagestyle.admin.inc \pagestyle_admin_settings_validate()

Validate the pagestyle settings form.

See also

pagestyle_admin_settings()

File

includes/pagestyle.admin.inc, line 372
Provides the Page Style administrative interface.

Code

function pagestyle_admin_settings_validate($form_id, $form_values) {
  $bw = $form_values['pagestyle_black_white'];
  $wb = $form_values['pagestyle_white_black'];
  $yb = $form_values['pagestyle_yellow_blue'];
  $st = $form_values['pagestyle_standard'];
  $normal = $form_values['pagestyle_normal'];
  $ps_co_ex = $form_values['pagestyle_cookie_expires'];
  $ps_co_do = $form_values['pagestyle_cookie_domain'];
  $ps_fw_wb = $form_values['pagestyle_fontweight_white_black'];
  $ps_fw_yb = $form_values['pagestyle_fontweight_yellow_blue'];
  $normal_text = array(
    'black_white' => t('Black') . '/' . t('White'),
    'white_black' => t('White') . '/' . t('Black'),
    'yellow_blue' => t('Yellow') . '/' . t('Blue'),
    'standard' => t('Standard'),
  );
  if ($bw + $wb + $yb + $st < 2) {
    form_set_error('pagestyle_standard', t('Minimum 2 styles are required.'));
  }
  if ($form_values['pagestyle_' . $normal] != 1) {
    form_set_error('pagestyle_normal', t('The style %style is not available in "Style display settings".', array(
      '%style' => $normal_text[$normal],
    )));
  }

  // Page Style Cookie Expires
  if (!is_numeric($ps_co_ex) || $ps_co_ex != round($ps_co_ex) || $ps_co_ex[0] == "+") {
    form_set_error('pagestyle_cookie_expires', t('Please enter a integer in:') . ' "' . t('Cookie Expires') . '".');
  }
  if ($ps_co_ex < 1 || $ps_co_ex[0] == "-") {
    form_set_error('pagestyle_cookie_expires', t('The minimum is 1 day in:') . ' "' . t('Cookie Expires') . '".');
  }
  if ($ps_co_ex > 3650) {
    form_set_error('pagestyle_cookie_expires', t('The maximum is 3650 day in:') . ' "' . t('Cookie Expires') . '".');
  }

  // Page Style Cookie Domain
  if (empty($ps_co_do[0])) {
    form_set_error('pagestyle_cookie_domain', t('The cookie domain can not have a empty space (" ") as first in:') . ' "' . t('Cookie Domain') . '".');
  }
  if (!empty($ps_co_do[0])) {
    if ($ps_co_do[0] != "/") {
      form_set_error('pagestyle_cookie_domain', t('Please enter a slash "/" as first in:') . ' "' . t('Cookie Domain') . '".');
    }
    elseif ($ps_co_do[0] == "/") {
      if (!empty($ps_co_do[1])) {
        if ($ps_co_do[1] == "/") {
          form_set_error('pagestyle_cookie_domain', t('Please enter only one slash "/" as first in:') . ' "' . t('Cookie Domain') . '".');
        }
        elseif ($ps_co_do[1] != "/") {
          if ($ps_co_do != base_path()) {
            drupal_set_message(t('Warning') . ': ' . t('The cookie domain: "!ps_co_do" is specific!', array(
              '!ps_co_do' => $ps_co_do,
            )), "warning");
          }
          elseif ($ps_co_do != variable_get('pagestyle_cookie_domain', base_path())) {
            drupal_set_message(t('Warning') . ': ' . t('The cookie domain has been changed.') . ' ' . t('After a change, the user must store the cookie again.'), "warning");
          }
        }
      }
    }
  }

  // White/Black
  if (!is_numeric($ps_fw_wb)) {
    if ($ps_fw_wb != 'bold' && $ps_fw_wb != 'bolder') {
      drupal_set_message(t('Warning') . ': ' . t('The font weight: "!ps_fw_wb" for the style Black/White is not "Bold" or "Bolder"!', array(
        '!ps_fw_wb' => $ps_fw_wb,
      )), "warning");
    }
  }
  elseif (is_numeric($ps_fw_wb)) {
    if ($ps_fw_wb < 700) {
      drupal_set_message(t('Warning') . ': ' . t('The font weight: "!ps_fw_wb" for the style Black/White is not "Bold" or "Bolder"!', array(
        '!ps_fw_wb' => $ps_fw_wb,
      )) . ' ' . t('The values 100-900 are not for all fonts.') . ' ' . t('The value is smaller than 700.'), "warning");
    }
    elseif ($ps_fw_wb >= 700) {
      drupal_set_message(t('Warning') . ': ' . t('The font weight: "!ps_fw_wb" for the style Black/White is not "Bold" or "Bolder"!', array(
        '!ps_fw_wb' => $ps_fw_wb,
      )) . ' ' . t('The values 100-900 are not for all fonts.'), "warning");
    }
  }

  // Yellow/Blue
  if (!is_numeric($ps_fw_yb)) {
    if ($ps_fw_yb != 'bold' && $ps_fw_yb != 'bolder') {
      drupal_set_message(t('Warning') . ': ' . t('The font weight: "!ps_fw_yb" for the style Yellow/Blue is not "Bold" or "Bolder"!', array(
        '!ps_fw_yb' => $ps_fw_yb,
      )), "warning");
    }
  }
  elseif (is_numeric($ps_fw_yb)) {
    if ($ps_fw_yb < 700) {
      drupal_set_message(t('Warning') . ': ' . t('The font weight: "!ps_fw_yb" for the style Yellow/Blue is not "Bold" or "Bolder"!', array(
        '!ps_fw_yb' => $ps_fw_yb,
      )) . ' ' . t('The values 100-900 are not for all fonts.') . ' ' . t('The value is smaller than 700.'), "warning");
    }
    elseif ($ps_fw_yb >= 700) {
      drupal_set_message(t('Warning') . ': ' . t('The font weight: "!ps_fw_yb" for the style Yellow/Blue is not "Bold" or "Bolder"!', array(
        '!ps_fw_yb' => $ps_fw_yb,
      )) . ' ' . t('The values 100-900 are not for all fonts.'), "warning");
    }
  }
}