You are here

function pagestyle_admin_settings_validate in Page Style 7

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

Validate the pagestyle settings form.

See also

pagestyle_admin_settings()

File

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

Code

function pagestyle_admin_settings_validate($form, &$form_state) {
  $abbr_url = '<abbr title="' . t('Uniform Resource Locator') . '">URL</abbr>s';
  $abbr_ajax = '<abbr title="' . t('Asynchronous JavaScript and XML') . '">AJAX</abbr>';
  $link_cleanurls = l(t('Clean URLs'), 'admin/config/search/clean-urls', array(
    'attributes' => array(
      'title' => t('Internal link to:') . ' ' . t('Clean URLs'),
    ),
  ));
  $pagestyle_cookie_expires = pagestyle_cookie_expires($mode = 'php');
  $pagestyle_cookie_domain = variable_get('pagestyle_cookie_domain', base_path());
  $bw = $form_state['values']['pagestyle_black_white'];
  $wb = $form_state['values']['pagestyle_white_black'];
  $yb = $form_state['values']['pagestyle_yellow_blue'];
  $st = $form_state['values']['pagestyle_standard'];
  $ps_no = $form_state['values']['pagestyle_normal'];
  $ps_js = $form_state['values']['pagestyle_javascript'];
  $ps_co_ex = $form_state['values']['pagestyle_cookie_expires'];
  $ps_co_do = $form_state['values']['pagestyle_cookie_domain'];
  $ps_fw_wb = $form_state['values']['pagestyle_fontweight_white_black'];
  $ps_fw_yb = $form_state['values']['pagestyle_fontweight_yellow_blue'];
  $ps_no_error = FALSE;
  $pagestyle_allowed_values = array(
    'black_white',
    'white_black',
    'yellow_blue',
    'standard',
  );
  $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.'));
  }

  // Page Style Normal
  if ($form_state['values']['pagestyle_' . $ps_no] != 1) {
    $ps_no_error = TRUE;
    form_set_error('pagestyle_normal', t('The style %style is not available in "Style display settings".', array(
      '%style' => $normal_text[$ps_no],
    )));
  }
  if (in_array($_COOKIE['pagestyle'], $pagestyle_allowed_values) && $_COOKIE['pagestyle'] != $ps_no && $ps_no_error == FALSE) {
    if ($ps_js == 0 || $ps_js == 1) {
      $_SESSION['pagestyle'] = $ps_no;
    }
    setcookie("pagestyle", $ps_no, time() + $pagestyle_cookie_expires, $pagestyle_cookie_domain, "");
    drupal_set_message(t('The page style have been saved as %ps_name.', array(
      '%ps_name' => $normal_text[$ps_no],
    )));
  }
  if ($ps_js == 1 || $ps_js == 2) {
    drupal_set_message(t('Enable Clean !abbr_url for !abbr_ajax compatibility.', array(
      '!abbr_url' => $abbr_url,
      '!abbr_ajax' => $abbr_ajax,
    )) . ' ' . $link_cleanurls, "warning");
  }

  // 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 suitable 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 suitable 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 suitable 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 suitable for all fonts.'), "warning");
    }
  }
}