You are here

function language_selection_page_language in Language Selection Page 7

Same name and namespace in other branches
  1. 7.2 language_selection_page.module \language_selection_page_language()

Language selection callback method.

1 string reference to 'language_selection_page_language'
language_selection_page_language_negotiation_info in ./language_selection_page.module
Implements hook_language_negotiation_info().

File

./language_selection_page.module, line 78

Code

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';

  // 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;
  }

  // See if we can remove this check and use $language->provider
  $lang = locale_language_from_url($languages);
  if ($lang) {
    return $lang;
  }

  // Don't run this code on the language selection page itself.
  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()));

    // 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;
    }
  }

  // Don't run this code if we are accessing an image.
  $styles_path = variable_get('file_public_path', conf_path() . '/files') . '/styles/';
  if (strpos(request_path(), $styles_path) === 0) {
    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;
  }

  // Redirect to the language selection page,
  // with the currently requested page as destination.
  $query = drupal_get_query_parameters();
  $query['destination'] = request_path() ? request_path() : '<front>';
  $language = $GLOBALS['language'];

  // Return FALSE if we use the block method
  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,
    ));
  }
}