function mobile_tools_get_device in Mobile Tools 6
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.2 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_block_message in ./
mobile_tools.module - Helper function returning the configurable message for the notification
- mobile_tools_boot in ./
mobile_tools.module - Implementation of hook_boot(). Hook boot is called for both anonymous users and logged in users
File
- ./
mobile_tools.module, line 241 - 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;
// 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), '/');
return array(
'type' => $_GET['device'],
'group' => '',
);
break;
case 'auto':
setCookie('mt_device', '', time() - 3600);
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), '/');
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'],
);
}
}
}
// backwards compatibility with the nomobile parameter
if (isset($_GET['nomobile'])) {
if (strtolower($_GET['nomobile']) == 'true') {
setCookie('mobile_tools_switch', 0, variable_get('mobile_tools_cookie_lifetime', $session_time), '/');
return array(
'type' => 'desktop',
'group' => '',
);
}
elseif (strtolower($_GET['nomobile']) == 'false') {
setCookie('mobile_tools_switch', 1, variable_get('mobile_tools_cookie_lifetime', $session_time), '/');
return array(
'type' => 'mobile',
'group' => '',
);
}
}
if (isset($_COOKIE['mobile_tools_switch'])) {
switch ($_COOKIE['mobile_tools_switch']) {
case '0':
return array(
'type' => 'desktop',
'group' => '',
);
case '1':
return array(
'type' => 'mobile',
'group' => '',
);
}
}
// we default to the real detection
return mobile_tools_is_mobile_device();
}