You are here

function mobile_tools_get_device in Mobile Tools 6.3

Same name and namespace in other branches
  1. 5 mobile_tools.module \mobile_tools_get_device()
  2. 6 mobile_tools.module \mobile_tools_get_device()
  3. 6.2 mobile_tools.module \mobile_tools_get_device()
  4. 7.2 mobile_tools.module \mobile_tools_get_device()

Get $device object. Check if the 'device' argument is present or a cookie is set to overwrite the device:

  • device=mobile => mobile view
  • device=desktop => desktop view
  • device=[group] => specific group view
  • device=auto => reset overwrite

Return value

$device The $device object

2 calls to mobile_tools_get_device()
mobile_tools_boot in ./mobile_tools.module
Implementation of hook_boot(). Redirecting if needed
mobile_tools_init in ./mobile_tools.module
Theme switching:

File

./mobile_tools.module, line 353
Mobile Tools provides a range of functionality assisting in creating a mobile Drupal site . this functionality contains:

Code

function mobile_tools_get_device() {
  global $cookie_domain, $mobile_tools_device;

  // currently the boot method saves the result in a global variable.
  if (isset($mobile_tools_device)) {
    return $mobile_tools_device;
  }

  // Checking the possible arguments
  $session_time = time() + variable_get('mobile_tools_cookie_session', 3600 * 24 * 30);

  //first check if the device type is forced in the device argument
  if (isset($_GET['device'])) {
    switch ($_GET['device']) {
      case 'desktop':
      case 'mobile':
        setCookie('mt_device', $_GET['device'], variable_get('mobile_tools_cookie_lifetime', $session_time), '/', $cookie_domain);
        return array(
          'type' => $_GET['device'],
          'group' => '',
        );
        break;
      case 'auto':
        setCookie('mt_device', '', time() - 3600, '/', $cookie_domain);
        break;
      default:
        $device_groups = mobile_tools_device_groups();
        if (isset($device_groups[$_GET['device']])) {
          setCookie('mt_device', $_GET['device'], variable_get('mobile_tools_cookie_lifetime', $session_time), '/', $cookie_domain);
          return array(
            'type' => 'mobile',
            'group' => $_GET['device'],
          );
        }
    }
  }
  elseif (isset($_COOKIE['mt_device'])) {
    switch ($_COOKIE['mt_device']) {
      case 'desktop':
      case 'mobile':
        return array(
          'type' => $_COOKIE['mt_device'],
          'group' => '',
        );
        break;
      case 'auto':
        setCookie('mt_device', '', time() - 3600, '/');
        break;
      default:
        $device_groups = mobile_tools_device_groups();
        if (isset($device_groups[$_COOKIE['mt_device']])) {
          setCookie('mt_device', $_COOKIE['mt_device'], variable_get('mobile_tools_cookie_lifetime', $session_time), '/');
          return array(
            'type' => 'mobile',
            'group' => $_COOKIE['mt_device'],
          );
        }
    }
  }

  // we default to the real detection
  return mobile_tools_is_mobile_device();
}