You are here

function boost_admin_boost_performance_page_validate in Boost 6

validate boost_admin_boost_performance_page form submissions.

1 string reference to 'boost_admin_boost_performance_page_validate'
boost_admin_boost_performance_page in ./boost.admin.inc
Form builder; Displays Boost's configuration page.

File

./boost.admin.inc, line 1127
All the code for the Boost module's administrative interface.

Code

function boost_admin_boost_performance_page_validate($form, &$form_state) {
  $boost_previously = variable_get('boost_enabled', '');
  extract($form_state['values'], EXTR_SKIP | EXTR_REFS);
  if (BOOST_MULTISITE_SINGLE_DB) {
    $boost_file_path = boost_cache_directory(NULL, FALSE, $boost_root_cache_dir, $boost_normal_dir);
  }

  // Boost enabled/disabled logic
  if ($boost_enabled != CACHE_DISABLED) {

    // The cache is enabled
    // Ensure the cache directory exists or can be created:
    _boost_mkdir_p($boost_file_path);
    file_check_directory($boost_file_path, FILE_CREATE_DIRECTORY, 'boost_file_path');
  }
  elseif ($boost_enabled == CACHE_DISABLED && $boost_previously != CACHE_DISABLED) {

    // The cache was previously enabled
    variable_set('boost_ignore_flush', 0);
    if (boost_cache_clear_all()) {
      drupal_set_message(t('Boost: Static page cache cleared.'));
    }
  }

  // Validate file extensions
  if (BOOST_CACHE_HTML && isset($boost_file_extension) && strpos($boost_file_extension, '.') !== 0) {
    form_set_error('boost_file_extension', t('Cache file extension %extension must begin with a period.', array(
      '%extension' => $boost_file_extension,
    )));
  }
  if (BOOST_CACHE_XML && isset($boost_xml_extension) && strpos($boost_xml_extension, '.') !== 0) {
    form_set_error('boost_xml_extension', t('Cache file extension %extension must begin with a period.', array(
      '%extension' => $boost_xml_extension,
    )));
  }
  if (BOOST_CACHE_JSON && isset($boost_json_extension) && strpos($boost_json_extension, '.') !== 0) {
    form_set_error('boost_json_extension', t('Cache file extension %extension must begin with a period.', array(
      '%extension' => $boost_json_extension,
    )));
  }
  if (BOOST_CACHE_CSS && isset($boost_css_extension) && strpos($boost_css_extension, '.') !== 0) {
    form_set_error('boost_css_extension', t('Cache file extension %extension must begin with a period.', array(
      '%extension' => $boost_css_extension,
    )));
  }
  if (BOOST_CACHE_JS && isset($boost_js_extension) && strpos($boost_js_extension, '.') !== 0) {
    form_set_error('boost_js_extension', t('Cache file extension %extension must begin with a period.', array(
      '%extension' => $boost_js_extension,
    )));
  }

  // Check that the preprocess function exists.
  if (!empty($boost_pre_process_function) && !is_callable($boost_pre_process_function)) {
    form_set_error('boost_pre_process_function', t('Pre-process function %function() does not exist.', array(
      '%function' => $boost_pre_process_function,
    )));
  }

  // Validate whitelist and blacklist elements.
  $use_lists = $form_state['values']['boost_domain_use_lists'];
  if ($use_lists != BOOST_DOMAIN_NO_LISTS && $use_lists != BOOST_DOMAIN_WHITELIST_ONLY && $use_lists != BOOST_DOMAIN_BLACKLIST_ONLY && $use_lists != BOOST_DOMAIN_BOTH_LISTS) {
    form_set_error('boost_domain_use_lists', t('Invalid selection'));
  }
  if ($use_lists == BOOST_DOMAIN_WHITELIST_ONLY || $use_lists == BOOST_DOMAIN_BOTH_LISTS) {
    $whitelist_values = explode("\n", $form_state['values']['boost_domain_whitelist']);
    $whitelist_values = array_map('trim', $whitelist_values);
    $whitelist = array_combine($whitelist_values, $whitelist_values);
    if (function_exists('domain_valid_domain')) {
      foreach ($whitelist as $key => $value) {
        $error_msg = domain_valid_domain($value);
        if (!empty($error_msg)) {
          $error_msg = str_replace(':', t(' in domain whitelist:'), $error_msg);
          form_set_error('boost_domain_whitelist', $error_msg);
        }
      }
    }
    $whitelist_wild_values = explode("\n", $form_state['values']['boost_domain_whitelist_wild']);
    $whitelist_wild_values = array_map('trim', $whitelist_wild_values);
    $whitelist_wild = array_combine($whitelist_wild_values, $whitelist_wild_values);
    if (function_exists('domain_valid_domain')) {
      foreach ($whitelist_wild as $key => $value) {
        $value = str_replace('*', 'qwerqwrkasdwiopekasdn', $value);
        $error_msg = domain_valid_domain($value);
        if (!empty($error_msg)) {
          $error_msg = str_replace(':', t(' in domain wildcard whitelist:'), $error_msg);
          $error_msg = str_replace('qwerqwrkasdwiopekasdn', '*', $error_msg);
          form_set_error('boost_domain_whitelist_wild', $error_msg);
        }
      }
    }
  }
  if ($use_lists == BOOST_DOMAIN_BLACKLIST_ONLY || $use_lists == BOOST_DOMAIN_BOTH_LISTS) {
    $blacklist_values = explode("\n", $form_state['values']['boost_domain_blacklist']);
    $blacklist_values = array_map('trim', $blacklist_values);
    $blacklist = array_combine($blacklist_values, $blacklist_values);
    if (function_exists('domain_valid_domain')) {
      foreach ($blacklist as $key => $value) {
        $error_msg = domain_valid_domain($value);
        if (!empty($error_msg)) {
          $error_msg = str_replace(':', t(' in domain blacklist:'), $error_msg);
          form_set_error('boost_domain_blacklist', $error_msg);
        }
      }
    }
  }
}