You are here

function require_login_admin_settings_validate in Require Login 7

Require login configuration form validation handler.

File

./require_login.admin.inc, line 42
require_login.admin.inc

Code

function require_login_admin_settings_validate($form, &$form_state) {
  $absolutes = array();

  // Add leading slash to paths (except for <front>). Trims extra whitespace
  // and prepares exclusions for saving.
  $exclude_paths = explode(PHP_EOL, $form_state['values']['require_login_excluded_paths']);
  foreach ($exclude_paths as $key => $exclude_path) {
    $exclude_path = trim($exclude_path);
    if (empty($exclude_path) || $exclude_path == '<front>') {
      continue;
    }
    $url = parse_url($exclude_path);

    // Detect invalid absolute domain in path.
    if (isset($url['scheme']) || isset($url['host']) || preg_match('/^www./i', $url['path'])) {
      $absolutes[] = trim($exclude_path);
    }
    elseif (substr($exclude_path, 0, 1) != '/') {
      $exclude_paths[$key] = '/' . $exclude_path;
    }
    else {
      $exclude_paths[$key] = $exclude_path;
    }
  }
  $form_state['values']['require_login_excluded_paths'] = implode(PHP_EOL, $exclude_paths);

  // Throw error if absolute paths were detected.
  if ($absolutes) {
    form_set_error('require_login_excluded_paths', t('Exclude paths cannot include protocols or domain names. Invalid paths:<br />!paths', array(
      '!paths' => implode('<br />', $absolutes),
    )));
  }

  // Add leading slash to user login path. Trims extra whitespace and prepares
  // user login path for saving.
  if (!empty($form_state['values']['require_login_auth_path'])) {
    $auth_path = trim($form_state['values']['require_login_auth_path']);
    $url = parse_url($auth_path);

    // Detect invalid absolute domain in path.
    if (isset($url['scheme']) || isset($url['host']) || preg_match('/^www./i', $url['path'])) {
      form_set_error('require_login_auth_path', t('User login path must be relative.'));
    }
    elseif (substr($auth_path, 0, 1) != '/') {
      $form_state['values']['require_login_auth_path'] = '/' . $auth_path;
    }
    else {
      $form_state['values']['require_login_auth_path'] = $auth_path;
    }
  }
}