View source
<?php
define('LANGUAGE_NEGOTIATION_SELECTION_PAGE', 'language-selection-page');
define('LANGUAGE_SELECTION_PAGE_TEMPLATE_IN_THEME', 32);
define('LANGUAGE_SELECTION_PAGE_TEMPLATE_ONLY', 64);
define('LANGUAGE_SELECTION_PAGE_BLOCK', 128);
function language_selection_page_menu() {
$items = array();
$items['admin/config/regional/language/configure/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 languages',
),
'file' => 'language_selection_page.admin.inc',
'type' => MENU_VISIBLE_IN_BREADCRUMB,
);
$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_boot() {
$path = request_path();
if ($path == 'language_selection') {
$_POST['globalredirect'] = 'Disabled on language selection page.';
}
}
function language_selection_page_language_negotiation_info() {
$language_providers[LANGUAGE_NEGOTIATION_SELECTION_PAGE] = array(
'types' => array(
LANGUAGE_TYPE_CONTENT,
LANGUAGE_TYPE_INTERFACE,
LANGUAGE_TYPE_URL,
),
'callbacks' => array(
'language' => 'language_selection_page_language',
'switcher' => 'locale_language_switcher_url',
'url_rewrite' => 'locale_language_url_rewrite_url',
),
'file' => drupal_get_path('module', 'language_selection_page') . '/language_selection_page.module',
'weight' => 50,
'name' => t('Selection Page'),
'description' => t('Show a language selection page to the visitor for making a language choice.'),
'config' => 'admin/config/regional/language/configure/selection_page',
);
return $language_providers;
}
function language_selection_page_language($languages) {
require_once './includes/locale.inc';
require_once './includes/path.inc';
require_once './includes/common.inc';
require_once './includes/unicode.inc';
if (drupal_is_cli()) {
return FALSE;
}
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
return FALSE;
}
$lang = locale_language_from_url($languages);
if ($lang) {
return $lang;
}
if (request_path() == 'language_selection') {
return FALSE;
}
if ($blacklist_pages = variable_get('language_selection_page_blacklisted_paths')) {
$blacklist_pages = drupal_strtolower($blacklist_pages);
$current_path = drupal_strtolower(drupal_get_path_alias(request_path()));
if (empty($current_path)) {
$current_path = ltrim($_SERVER["REQUEST_URI"], '/');
}
if (drupal_match_path($current_path, $blacklist_pages)) {
return FALSE;
}
}
$styles_path = variable_get('file_public_path', conf_path() . '/files') . '/styles/';
if (strpos(request_path(), $styles_path) === 0) {
return FALSE;
}
if (!isset($_SERVER['SERVER_ADDR'])) {
return FALSE;
}
if ($_SERVER['SCRIPT_NAME'] != $GLOBALS['base_path'] . 'index.php') {
return FALSE;
}
$query = drupal_get_query_parameters();
$query['destination'] = request_path() ? request_path() : '<front>';
$language = $GLOBALS['language'];
if (LANGUAGE_SELECTION_PAGE_BLOCK == variable_get('language_selection_page_redirect_type', LANGUAGE_SELECTION_PAGE_TEMPLATE_ONLY)) {
return FALSE;
}
if (empty($language->provider)) {
drupal_goto('language_selection', array(
'query' => $query,
'absolute' => FALSE,
'language' => LANGUAGE_NONE,
));
}
}
function language_selection_page_theme() {
return array(
'language_selection_page_body' => array(
'variables' => array(
'language_selection_page' => array(),
),
'path' => drupal_get_path('module', 'language_selection_page') . '/themes',
'template' => 'language-selection-page-body',
),
);
}
function language_selection_page_preprocess_page(&$vars) {
$vars['theme_hook_suggestions'][] = 'page__language_selection';
}
function language_selection_page_block_info() {
return array(
'block' => array(
'info' => t('Language Selection Block'),
'cache' => DRUPAL_NO_CACHE,
),
);
}
function language_selection_page_block_view($delta = '') {
if (LANGUAGE_SELECTION_PAGE_BLOCK != variable_get('language_selection_page_redirect_type', LANGUAGE_SELECTION_PAGE_TEMPLATE_ONLY)) {
return array();
}
module_load_include('inc', 'language_selection_page', 'language_selection_page.pages');
if (!($data = language_selection_page_selection_page_data())) {
return array();
}
$block = array();
switch ($delta) {
case 'block':
$block['subject'] = '';
$block['content'] = array(
'#theme' => 'language_selection_page_body',
'#language_selection_page' => $data,
'blop' => 'blap',
);
break;
}
return $block;
}
function language_selection_page_preprocess_block(&$vars) {
$block = $vars['block'];
if ($block->module == 'language_selection_page' && $block->delta == 'block') {
$vars['language_selection_page'] = language_selection_page_selection_page_data();
}
}