function mobile_switch_init in Mobile Switch 7.2
Implements hook_init().
Handle the redirect operating mode.
File
- ./mobile_switch.module, line 193 
- Provides various functionalities to develop mobile ready websites.
Code
function mobile_switch_init() {
  $get['op_mode'] = mobile_switch_get_operating_mode();
  // Do nothing if the redirect mode is not active.
  if ($get['op_mode'] != 'redirect') {
    return;
  }
  $theme_cookie = _mobile_switch_check_theme_cookie_use();
  // Do nothing if the redirect mode is active and the theme switch are
  // manulay initiated by visitor (Theme switch block link).
  $rm = stristr($theme_cookie, '-rm');
  if ($rm === '-rm') {
    return;
  }
  $get['redirect_url_to_mobile'] = variable_get('mobile_switch_redirect_url_to_mobile', '');
  $get['redirect_url_to_desktop'] = variable_get('mobile_switch_redirect_url_to_desktop', '');
  // Get the detection informations.
  $get['browser'] = mobile_switch_mobile_detect();
  // Use the mobile switch functionality on admin pages?
  $get['admin_usage'] = (bool) variable_get('mobile_switch_admin_usage', FALSE);
  // Use the mobile theme on tablet devices?
  $get['tablet_usage'] = (bool) variable_get('mobile_switch_tablet_usage', TRUE);
  // Use device preventation?
  $get['prevented_device'] = (bool) variable_get('mobile_switch_prevent_devices', FALSE);
  // Multisite with shared content?
  $get['shared_content'] = (bool) variable_get('mobile_switch_redirect_shared_content', 0);
  // Identify the current website version - desktop or mobile.
  $get['site_variant'] = _mobile_switch_get_site_version($get);
  // Tablet device usage is configured to none.
  $get['tablet'] = TRUE;
  if ($get['tablet_usage'] === FALSE) {
    if ((bool) $get['browser']['istablet'] === TRUE) {
      $get['tablet'] = FALSE;
    }
  }
  // An prevented device is detected.
  $get['prevent'] = FALSE;
  if ((bool) variable_get('mobile_switch_prevent_devices', FALSE) === TRUE) {
    if ((bool) $get['browser']['prevent_device'] === TRUE) {
      $get['prevent'] = TRUE;
    }
  }
  // Prepare the request URI.
  $get['request_uri'] = '';
  if ($get['shared_content'] == TRUE) {
    $get['request_uri'] = request_uri();
  }
  // Handling the redirection.
  switch ($get['site_variant']) {
    case 'desktop':
      if ((bool) $get['browser']['ismobiledevice'] === TRUE && $get['prevent'] === FALSE && $get['tablet'] === TRUE) {
        //if ((bool) $get['browser']['ismobiledevice'] === TRUE) {
        //if (!$theme_cookie || (isset($theme_cookie) && $theme_cookie == 'mobile')) {;
        drupal_goto($get['redirect_url_to_mobile'] . $get['request_uri']);
        //}
      }
      break;
    case 'mobile':
      if ((bool) $get['browser']['ismobiledevice'] === FALSE || $get['prevent'] === TRUE || $get['tablet'] === FALSE) {
        //if ((bool) $get['browser']['ismobiledevice'] === FALSE) {
        //if (!$theme_cookie || (isset($theme_cookie) && $theme_cookie == 'mobile')) {
        drupal_goto($get['redirect_url_to_desktop'] . $get['request_uri']);
        //}
      }
      break;
  }
}