function language_selection_page_language in Language Selection Page 7.2
Same name and namespace in other branches
- 7 language_selection_page.module \language_selection_page_language()
Language selection callback method.
This callback is called prior calling the callback defined in hook_menu. It should normally return a language code but instead of that, we redirect the user to the language selection page.
This function is not a hook but a callback and I think it has its place in the .module file.
1 string reference to 'language_selection_page_language'
File
- ./
language_selection_page.module, line 92
Code
function language_selection_page_language($languages) {
// Bail out when running tests on commandline.
if (drupal_is_cli()) {
return FALSE;
}
// Bail out when handling AJAX requests.
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);
// Don't run this code if we are accessing anything in the files 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;
}
// Don't run this code on the language selection page itself.
require_once './includes/common.inc';
if ($path[0] === variable_get('language_selection_page_path', 'language_selection')) {
return FALSE;
}
// @TODO: document this
if (!isset($_SERVER['SERVER_ADDR'])) {
return FALSE;
}
// Don't run this code if we are accessing another php file than index.php.
if ($_SERVER['SCRIPT_NAME'] !== $GLOBALS['base_path'] . 'index.php') {
return FALSE;
}
// Check the path against a list of paths where that the module shouldn't run
// on.
// This list of path is configurable on the admin page.
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));
// In order to be able to blacklist pages like 'update.php',
// if current_path is empty, the php REQUEST_URI will be match.
if (empty($current_path)) {
$current_path = ltrim($_SERVER['REQUEST_URI'], '/');
}
if (drupal_match_path($current_path, $blacklist_pages)) {
return FALSE;
}
}
// Check if the ignore "language neutral" option is checked.
// If so, we will check if the entity language is set to LANGUAGE_NONE.
// Checking also for content type translation options since node can have the
// default language set instead of LANGUAGE_NONE.
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;
}
}
// Do not return any language if we use the Drupal's block method
// to display the redirection.
// Be aware that this will automatically assign the default language.
if (LANGUAGE_SELECTION_PAGE_BLOCK === variable_get('language_selection_page_redirect_type', LANGUAGE_SELECTION_PAGE_TEMPLATE_ONLY)) {
return FALSE;
}
// Redirect to the language selection page properly.
$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;
}