function language_cookie_language_rewrite in Language Cookie 7
Same name and namespace in other branches
- 7.2 language_cookie.module \language_cookie_language_rewrite()
Rewrite URLs for the Cookie language provider.
1 string reference to 'language_cookie_language_rewrite'
File
- ./
language_cookie.module, line 178 - Language Cookie module.
Code
function language_cookie_language_rewrite(&$path, &$options) {
static $query_rewrite, $query_param, $query_value;
// No need to rewrite the URL if LOCALE_LANGUAGE_NEGOTIATION_URL already takes
// care of it for us.
require_once DRUPAL_ROOT . '/includes/locale.inc';
if (language_negotiation_get_any(LOCALE_LANGUAGE_NEGOTIATION_URL)) {
return;
}
// The following values are not supposed to change during a single page
// request processing.
if (!isset($query_rewrite)) {
global $user;
if (!$user->uid) {
$languages = language_list('enabled');
$languages = $languages[1];
$query_param = check_plain(variable_get('language_cookie_param', 'language'));
$query_value = isset($_GET[$query_param]) ? check_plain($_GET[$query_param]) : NULL;
$query_rewrite = isset($languages[$query_value]) && language_negotiation_get_any(LANGUAGE_COOKIE_NEGOTIATION);
}
else {
$query_rewrite = FALSE;
}
}
// If the user is anonymous, the user language provider is enabled, and the
// corresponding option has been set, we must preserve any explicit user
// language preference even with cookies disabled.
if ($query_rewrite) {
if (is_string($options['query'])) {
$options['query'] = drupal_get_query_array($options['query']);
}
if (!isset($options['query'][$query_param])) {
$options['query'][$query_param] = $query_value;
}
}
}