You are here

function logintoboggan_destination in LoginToboggan 6

Same name and namespace in other branches
  1. 5 logintoboggan.module \logintoboggan_destination()
1 call to logintoboggan_destination()
logintoboggan_form_alter in ./logintoboggan.module
Implementation of hook_form_alter()

File

./logintoboggan.module, line 847
Logintoboggan Module

Code

function logintoboggan_destination() {

  // Drupal has reset $_GET[q], so we need a workaround.
  if ($internal_path = substr(request_uri(), strlen(base_path()))) {

    // Clean URLs disabled, so break apart the query string and
    // pull out the path.
    if (!variable_get('clean_url', 0)) {
      $internal_path = parse_url($internal_path);
      $queryarray = explode('&', $internal_path['query']);
      $path = str_replace('q=', '', $queryarray[0]);
      unset($queryarray[0]);
      $query = !empty($queryarray) ? '?' . implode('&', $queryarray) : '';
      $internal_path = $path . $query;
    }

    // If the language path prefixing is enabled remove it from the path.
    switch (variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE)) {
      case LANGUAGE_NEGOTIATION_PATH_DEFAULT:
      case LANGUAGE_NEGOTIATION_PATH:
        $args = explode('/', $internal_path);
        $prefix = array_shift($args);

        // Search prefix within enabled languages.
        $languages = language_list('enabled');
        foreach ($languages[1] as $language) {
          if (!empty($language->prefix) && $language->prefix == $prefix) {

            // Found a match, rebuild the path without the language.
            $internal_path = implode('/', $args);
            break;
          }
        }
    }
    $_REQUEST['destination'] = $internal_path;
  }
  else {
    $_REQUEST['destination'] = variable_get('site_frontpage', 'node');
  }
}