function language_cookie_boot in Language Cookie 7
Same name and namespace in other branches
- 7.2 language_cookie.module \language_cookie_boot()
Implements hook_boot().
File
- ./
language_cookie.module, line 220 - Language Cookie module.
Code
function language_cookie_boot() {
$method = variable_get('locale_language_negotiation_url_part');
$languages = language_list('enabled');
$languages = $languages[1];
require_once DRUPAL_ROOT . '/includes/locale.inc';
switch ($method) {
case LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX:
$path = request_path();
$args = explode('/', $path);
$prefix = array_shift($args);
// Search prefix within enabled languages.
foreach ($languages as $language) {
if (!empty($language->prefix) && $language->prefix == $prefix) {
$lang = $language;
}
}
break;
case LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN:
foreach ($languages as $language) {
$parts = parse_url($language->domain);
if (!empty($parts['host']) && $_SERVER['HTTP_HOST'] == $parts['host']) {
$lang = $language;
}
}
break;
default:
$lang = language_default();
}
if (isset($lang)) {
$lang = $lang->language;
$param = variable_get('language_cookie_param', 'language');
require_once DRUPAL_ROOT . '/includes/language.inc';
if ((!isset($_COOKIE[$param]) || isset($_COOKIE[$param]) && $_COOKIE[$param] != $lang) && language_negotiation_get_any(LANGUAGE_COOKIE_NEGOTIATION)) {
language_cookie_set($lang);
}
}
}