You are here

function boost_admin_htaccess_settings in Boost 7

Form builder; Configure boost settings.

See also

system_settings_form()

1 string reference to 'boost_admin_htaccess_settings'
boost_menu in ./boost.module
Implements hook_menu().

File

./boost.admin.htaccess.inc, line 30
Admin page callbacks for the boost module.

Code

function boost_admin_htaccess_settings() {
  global $base_path;

  // Apache .htaccess settings generation
  //   $htaccess = boost_admin_generate_htaccess();
  $form['htaccess'] = array(
    '#type' => 'fieldset',
    '#title' => t('Boost Apache .htaccess settings generation'),
    '#description' => t('<a href="!link">Explanation of .htaccess variables</a> <br /><br />  <em>Be sure to save the configuration and then go to the <a href="!rules">htaccess rules generation page</a> and copy the rules.</em> <br /><strong>Apache 2.4 users should uncomment the two marked sections, each line beginning with #</strong> ', array(
      '!link' => url('http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html'),
      '!rules' => url('admin/config/system/boost/htaccess/generator'),
    )),
  );
  $form['htaccess']['boost_server_name_http_host'] = array(
    '#type' => 'radios',
    '#title' => t("Server's URL or Name"),
    '#default_value' => variable_get('boost_server_name_http_host', BOOST_SERVER_NAME_HTTP_HOST),
    '#options' => array(
      '%{HTTP_HOST}' => '%{HTTP_HOST}',
      '%{SERVER_NAME}' => '%{SERVER_NAME}',
      $_SERVER['HTTP_HOST'] => $_SERVER['HTTP_HOST'],
      $_SERVER['SERVER_NAME'] => $_SERVER['SERVER_NAME'],
    ),
    '#description' => t('Best to leave these as %{}, only try the last option(s) if boost is still not working.'),
  );

  // Set DOCUMENT_ROOT.
  $drupal_subdir = rtrim($base_path, '/');

  // Fix windows dir slashes.
  $document_root = str_replace("\\", '/', getcwd());

  // Remove subdir.
  $document_root = trim(str_replace($drupal_subdir, '', $document_root));

  // Initial options.
  $options = array(
    '%{DOCUMENT_ROOT}' => '%{DOCUMENT_ROOT}',
    $document_root => $document_root,
  );

  // Values to ignore.
  $rejects = array(
    'SCRIPT_FILENAME',
    'DOCUMENT_ROOT',
  );

  // Search for values that match getcwd.
  $output = boost_admin_htaccess_array_find($document_root, $_SERVER, $rejects);
  $description_extra = '';
  if (!empty($output)) {
    foreach ($output as $key => $value) {
      $temp = '%{ENV:' . $key . '}';

      // Adding values to options.
      $options[$temp] = $temp . ' = ' . $value;
      if (strcmp($value, $document_root) == 0) {

        // Set best since it's a match.
        $best = $temp;
      }
    }
  }
  if (strcmp($_SERVER['DOCUMENT_ROOT'], $document_root) == 0) {
    $best = '%{DOCUMENT_ROOT}';
  }
  elseif (!isset($best)) {
    $best = $document_root;
    $description_extra = t('Please <a href="!link">open an boost issue on Drupal.org</a>, since apache and php might not be configured correctly.', array(
      '!link' => url('http://drupal.org/node/add/project-issue/boost'),
    ));
  }
  $percent = 0;
  $int = similar_text(substr(trim($_SERVER['DOCUMENT_ROOT']), 18, 1), substr(trim($document_root), 18, 1), $percent);
  $description = t('Value of %best is recommended for this server.', array(
    '%best' => $best,
  )) . ' ' . $description_extra;
  $form['htaccess']['boost_document_root'] = array(
    '#type' => 'radios',
    '#title' => t('Document Root'),
    '#default_value' => variable_get('boost_document_root', BOOST_DOCUMENT_ROOT),
    '#options' => $options,
    '#description' => $description,
  );
  $form['htaccess']['boost_apache_etag'] = array(
    '#type' => 'radios',
    '#title' => t('ETag Settings'),
    '#default_value' => variable_get('boost_apache_etag', BOOST_APACHE_ETAG),
    '#options' => array(
      3 => "Set FileETag 'MTime Size' - Useful in server clusters (Highly Recommended)",
      2 => "Set FileETag 'All' - Default if enabled",
      1 => "Set FileETag 'None' - Do not send an etag",
      0 => 'Do Nothing',
    ),
    '#description' => t('Uses <a href="!link">FileETag Directive</a> to set <a href="!about">ETags</a> for the files cached by Boost. <a href="!stack">More info on this subject</a>', array(
      '!link' => url('http://httpd.apache.org/docs/trunk/mod/core.html#fileetag'),
      '!about' => url('http://en.wikipedia.org/wiki/HTTP_ETag'),
      '!stack' => url('http://stackoverflow.com/questions/tagged?tagnames=etag&sort=votes&pagesize=50'),
    )),
  );
  $form['htaccess']['boost_apache_vary_cookie'] = array(
    '#type' => 'radios',
    '#title' => t('Vary Cookie'),
    '#default_value' => variable_get('boost_apache_vary_cookie', BOOST_APACHE_VARY_COOKIE),
    '#options' => array(
      1 => 'Set Vary Cookie header',
      0 => 'Do not set Vary Cookie header',
    ),
    '#description' => t('When caching pages for authenticated users, the Vary Cookie header ensures that the browser does not display an old version of a page after login/logout.'),
  );
  $form['htaccess']['boost_apache_xheader'] = array(
    '#type' => 'radios',
    '#title' => t('Boost Tags'),
    '#default_value' => variable_get('boost_apache_xheader', BOOST_APACHE_XHEADER),
    '#options' => array(
      1 => 'Set Boost header',
      0 => 'Do not set Boost header',
    ),
    '#description' => t('In order to identify that the page is being served from the cache, Boost can send out a header that will identify any files served from the boost cache.'),
  );
  $form['htaccess']['boost_ssl_bypass'] = array(
    '#type' => 'checkbox',
    '#title' => t('Bypass the boost cache for ssl requests.'),
    '#default_value' => variable_get('boost_ssl_bypass', BOOST_SSL_BYPASS),
    '#description' => t('Ticking this is recommended if you use the securepages module.'),
  );
  $form['htaccess']['boost_add_default_charset'] = array(
    '#type' => 'checkbox',
    '#title' => t('Add "AddDefaultCharset X" to the htaccess rules'),
    '#default_value' => variable_get('boost_add_default_charset', BOOST_ADD_DEFAULT_CHARSET),
    '#description' => t('Depending on your i18n settings you might want this disabled or enabled. X is set below'),
  );
  $form['htaccess']['boost_charset_type'] = array(
    '#type' => 'textfield',
    '#title' => t('Add "AddDefaultCharset utf-8" to the htaccess rules'),
    '#default_value' => variable_get('boost_charset_type', BOOST_CHARSET_TYPE),
    '#description' => t('Depending on your i18n settings you might want this disabled or enabled.'),
  );
  $form['htaccess']['boost_match_symlinks_options'] = array(
    '#type' => 'radios',
    '#title' => t('%cache_folder Options', array(
      '%cache_folder' => $document_root . '/' . variable_get('boost_root_cache_dir', BOOST_ROOT_CACHE_DIR) . '/' . variable_get('boost_normal_dir', BOOST_NORMAL_DIR) . '/' . variable_get('boost_server_name_http_host', BOOST_SERVER_NAME_HTTP_HOST) . '/.htaccess',
    )),
    '#default_value' => variable_get('boost_match_symlinks_options', BOOST_MATCH_SYMLINKS_OPTIONS),
    '#options' => array(
      1 => 'Set "Options +FollowSymLinks"',
      0 => 'Set "Options +SymLinksIfOwnerMatch"',
    ),
    '#description' => t('The .htaccess file in the cache folder requires "Options +FollowSymLinks" or "Options +SymLinksIfOwnerMatch" for mod_rewrite. Some hosting companies only permit the SymLinksIfOwnerMatch option. If you get a http 500 error code try setting SymLinksIfOwnerMatch.'),
  );

  // Reset htaccess on submit.
  $form['#submit'][] = 'boost_form_submit_handler';
  return system_settings_form($form);
}