You are here

function mobile_tools_device_redirect in Mobile Tools 7.2

Same name and namespace in other branches
  1. 6.3 mobile_tools.module \mobile_tools_device_redirect()
  2. 6 mobile_tools.module \mobile_tools_device_redirect()
  3. 6.2 mobile_tools.module \mobile_tools_device_redirect()
  4. 7.3 mobile_tools.module \mobile_tools_device_redirect()

Redirect the user based on the device/site type combination

1 call to mobile_tools_device_redirect()
mobile_tools_init in ./mobile_tools.module
Implements hook_init().

File

./mobile_tools.module, line 576
Functionality to ease the creation of mixed device environments.

Code

function mobile_tools_device_redirect() {

  // @todo add redirect session detection (i.e. see if the user has already been redirected)
  // @todo add detection to get the current device
  // Get the device group
  $active_groups = mobile_tools_get_active_device_group();

  // Since we can only redirect to one site, we take the first returned device
  // group
  if (!empty($active_groups)) {
    $device_group = $active_groups[0];
  }
  else {

    // No active device group, so no redirect can be triggered
    return FALSE;
  }

  // code takes into account path exceptions in the configuration.
  $pages = variable_get('mobile_tools_redirect_exceptions', '');
  $page_match = FALSE;

  // Get the current 'q' path parameter
  // @todo replace with purl normal path function call
  $q = themekey_get_q();
  if ($q && $pages != '') {

    // Check for the excluded paths
    $path = drupal_get_path_alias($q);

    // Compare with the internal and path alias (if any).
    $page_match = drupal_match_path($path, $pages);
    if ($path != $q) {
      $page_match = $page_match || drupal_match_path($q, $pages);
    }
  }

  // Check if exceptions are pages on which to redirect, or not to redirect
  if (variable_get('mobile_tools_redirect_exceptions_type', FALSE) == 'only-redirect') {
    $page_match = !$page_match;
  }

  // Perform the redirect
  if (!$page_match) {

    // Load the switch options
    $options = mobile_tools_switch_options($device_group);

    // Send the user to that new URL.
    purl_goto($q, $options);
  }
}