function mobile_tools_get_device in Mobile Tools 6.2
Same name and namespace in other branches
- 5 mobile_tools.module \mobile_tools_get_device()
- 6.3 mobile_tools.module \mobile_tools_get_device()
- 6 mobile_tools.module \mobile_tools_get_device()
- 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().
- mobile_tools_init in ./
mobile_tools.module - Implementation of hook_init().
File
- ./
mobile_tools.module, line 335 - Primarily Drupal hooks.
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 = variable_get('mobile_tools_cookie_session', 3600 * 24 * 30);
// Cookie sessions set to zero are session cookies and will expire at the end
// of the session. For all other lengths, make valid by adding the current time.
if ($session_time > 0) {
$session_time = $session_time + time();
}
//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'], $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'], $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'], $session_time, '/');
return array(
'type' => 'mobile',
'group' => $_COOKIE['mt_device'],
);
}
}
}
return mobile_tools_is_mobile_device();
}