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);
require_once DRUPAL_ROOT . '/includes/locale.inc';
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,
);
if (LANGUAGE_SELECTION_PAGE_BLOCK != variable_get('language_selection_page_redirect_type', LANGUAGE_SELECTION_PAGE_TEMPLATE_ONLY)) {
$language_selection_page_url = variable_get('language_selection_page_path', 'language_selection');
$items[$language_selection_page_url] = 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 = array_slice(explode('/', trim($_SERVER['REQUEST_URI'], '/')), 0);
if (LANGUAGE_SELECTION_PAGE_BLOCK == variable_get('language_selection_page_redirect_type', LANGUAGE_SELECTION_PAGE_TEMPLATE_ONLY) || $path[0] == variable_get('language_selection_page_path', 'language_selection')) {
$_POST['globalredirect'] = 'Disabled on language selection page.';
}
}
function language_selection_page_language_negotiation_info() {
return array(
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',
),
);
}
function language_selection_page_language($languages) {
if (drupal_is_cli()) {
return FALSE;
}
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
return FALSE;
}
$path = array_slice(explode('/', trim($_SERVER['REQUEST_URI'], '/')), 0);
$request_path = implode('/', $path);
$public_files_path = variable_get('file_public_path', conf_path() . '/files');
if (strpos($request_path, $public_files_path) === 0) {
return FALSE;
}
if (strpos($request_path, 'cdn/farfuture') === 0) {
return FALSE;
}
if (strpos($request_path, 'httprl_async_function_callback') === 0) {
return FALSE;
}
require_once './includes/common.inc';
if ($path[0] === variable_get('language_selection_page_path', 'language_selection')) {
return FALSE;
}
if (!isset($_SERVER['SERVER_ADDR'])) {
return FALSE;
}
if ($_SERVER['SCRIPT_NAME'] !== $GLOBALS['base_path'] . 'index.php') {
return FALSE;
}
require_once './includes/path.inc';
require_once './includes/unicode.inc';
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;
}
}
if (variable_get('language_selection_page_ignore_language_neutral', FALSE)) {
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$entity = menu_get_object();
if (isset($entity) && (isset($entity->language) && $entity->language == LANGUAGE_NONE || variable_get('language_content_type_' . $entity->type, '') === '0')) {
return FALSE;
}
}
if (LANGUAGE_SELECTION_PAGE_BLOCK === variable_get('language_selection_page_redirect_type', LANGUAGE_SELECTION_PAGE_TEMPLATE_ONLY)) {
return FALSE;
}
$language_selection_page_url_elements[] = variable_get('language_selection_page_path', 'language_selection');
$language_selection_page_url_elements[] = $request_path ? $request_path : NULL;
$language_selection_page_url = trim(implode('/', $language_selection_page_url_elements), '/');
if (empty($GLOBALS['language']->provider)) {
drupal_goto($language_selection_page_url, array(
'absolute' => TRUE,
'language' => LANGUAGE_NONE,
));
}
return FALSE;
}
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_block_info() {
$blocks = array();
if (LANGUAGE_SELECTION_PAGE_BLOCK === variable_get('language_selection_page_redirect_type', LANGUAGE_SELECTION_PAGE_TEMPLATE_ONLY)) {
$blocks['block'] = array(
'info' => t('Language Selection Block'),
'cache' => DRUPAL_NO_CACHE,
);
}
return $blocks;
}
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', 'includes/language_selection_page.helpers');
if (language_selection_page_is_negotiation_detected()) {
return array();
}
$block = array();
switch ($delta) {
case 'block':
$block['subject'] = '';
$block['content'] = array(
'#theme' => 'language_selection_page_body',
'#language_selection_page' => language_selection_page_selection_page_data(),
);
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();
}
}