View source
<?php
define('LANGUAGE_SELECTION_PAGE_LANGUAGE_COOKIE_KEY', 'language_prefix');
function language_selection_page_menu() {
$items = array();
$items['admin/settings/language/i18n/selection_page'] = array(
'title' => 'Language selection page',
'description' => 'Configure the language selection page behavior',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'language_selection_page_admin',
),
'access arguments' => array(
'administer site configuration',
),
'file' => 'language_selection_page.admin.inc',
'type' => MENU_LOCAL_TASK,
);
$items['language_selection'] = array(
'description' => 'Language selection page',
'page callback' => 'language_selection_page_selection_page',
'access arguments' => array(
'access content',
),
'file' => 'language_selection_page.pages.inc',
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function language_selection_page_init() {
global $language;
if (variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE) != 2) {
return;
}
module_load_include('inc', 'language_selection_page', 'includes/language_selection_page.helpers');
$lang_count = _language_selection_page_check_language_count();
if ($lang_count['db'] < 2) {
return;
}
$black_paths = variable_get('language_selection_page_blacklisted_paths', array());
if ((bool) drupal_match_path($_GET['q'], implode("\r\n", $black_paths))) {
return;
}
if ($_GET['q'] == 'language_selection') {
return;
}
if (!isset($_SERVER['SERVER_ADDR'])) {
return;
}
drupal_init_language();
$url_parsed = _language_selection_page_parse_url_custom();
$lang_from_url_argument = _language_selection_page_detect_lang_from_url_argument();
$lang_from_url = _language_selection_page_detect_lang_from_url();
$lang_from_cookie = _language_selection_page_detect_lang_from_cookie();
$language = _language_selection_page_resolve_lang($lang_from_url_argument, $lang_from_url, $lang_from_cookie);
if ($lang_from_url || $lang_from_url_argument) {
$cookie = variable_get('language_selection_page_use_language_cookie', 8) == 16 ? $language->language : NULL;
setcookie(LANGUAGE_SELECTION_PAGE_LANGUAGE_COOKIE_KEY, $cookie, time() + variable_get('language_selection_page_cookie_lifetime', 60 * 60 * 24 * 30), '/');
return;
}
$query = array();
$query['destination'] = $_GET['q'];
$query = array_merge((array) $query, (array) $url_parsed['query']);
unset($query['q']);
$destination = NULL;
$behavior = (int) variable_get('language_selection_page_use_language_cookie', 8) + (int) variable_get('language_selection_page_enable', 2);
switch ($behavior) {
case 9:
case 10:
case 18:
$destination = NULL;
break;
case 17:
$destination = $_GET['q'];
if ($lang_from_cookie) {
unset($query['destination']);
break;
}
case 12:
case 20:
$language = new stdClass();
$destination = 'language_selection';
break;
}
if ($destination) {
drupal_goto($destination, drupal_query_string_encode($query));
}
}
function language_selection_page_theme() {
return array(
'language_selection_page' => array(
'arguments' => array(
'data' => array(),
),
'path' => drupal_get_path('module', 'language_selection_page') . '/themes',
'template' => 'language_selection_page',
),
'language_selection_page_body' => array(
'arguments' => array(
'data' => array(),
),
'path' => drupal_get_path('module', 'language_selection_page') . '/themes',
'template' => 'language_selection_page_body',
),
);
}