You are here

function language_cookie_boot in Language Cookie 7.2

Same name and namespace in other branches
  1. 7 language_cookie.module \language_cookie_boot()

Implements hook_boot().

File

./language_cookie.module, line 138
Language Cookie module.

Code

function language_cookie_boot() {
  require_once DRUPAL_ROOT . '/includes/language.inc';

  // Do not set cookie if not configured in Language Negotiation.
  if (!language_negotiation_get_any(LANGUAGE_COOKIE_NEGOTIATION)) {
    return;
  }

  // Do not set cookie on AJAX requests (ie. Admin_menu).
  if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
    return;
  }

  // Do not set cookie on blacklisted paths:
  require_once DRUPAL_ROOT . '/' . variable_get('path_inc', 'includes/path.inc');
  require_once DRUPAL_ROOT . '/includes/unicode.inc';
  $language_selection = variable_get('language_selection_page_path', 'language_selection');
  if ($blacklist_pages = variable_get('language_cookie_blacklisted_paths', $language_selection)) {
    $blacklist_pages = drupal_strtolower($blacklist_pages);
    $current_path = ltrim($_SERVER["REQUEST_URI"], '/');
    if (drupal_match_path($current_path, $blacklist_pages)) {
      return;
    }
  }

  // Get the current request path.
  $request_path = $_SERVER["REQUEST_URI"];

  // Don't run this code if we are accessing anything in the files path.
  $public_files_path = variable_get('file_public_path', conf_path() . '/files');
  if (strpos($request_path, $public_files_path) === 0) {
    return;
  }
  if (strpos($request_path, 'cdn/farfuture') === 0) {
    return;
  }
  if (strpos($request_path, 'httprl_async_function_callback') === 0) {
    return;
  }

  // Get current language
  $lang = _language_cookie_get_language();
  if (isset($lang->language)) {
    $lang = $lang->language;
    $param = variable_get('language_cookie_param', 'language');
    if (!isset($_COOKIE[$param]) || isset($_COOKIE[$param]) && $_COOKIE[$param] != $lang || variable_get('language_cookie_set_on_every_pageload', FALSE)) {
      language_cookie_set($lang);
    }
  }
}