function mobile_switch_browscap_get_browser in Mobile Switch 6
Same name and namespace in other branches
- 7.2 mobile_switch.module \mobile_switch_browscap_get_browser()
- 7 mobile_switch.module \mobile_switch_browscap_get_browser()
Wrapper for browscap_get_browser().
Extend the browscap device detection with additional device types.
Parameters
bool $emulator_check: Boolean value to use mobile browser emulators.
See also
1 call to mobile_switch_browscap_get_browser()
- mobile_switch_boot in ./
mobile_switch.module - Implementation of hook_boot().
File
- ./
mobile_switch.module, line 230 - Simple theme switch for mobile devices, detected by browscap.
Code
function mobile_switch_browscap_get_browser($emulator_check = FALSE) {
static $browser;
if (!isset($browser)) {
// Fix a peculiarity of Broscap module branch 2+.
// Browscap module is not loaded during bootstrap.
if (!function_exists('browscap_get_browser')) {
drupal_load('module', 'browscap');
}
$browser = browscap_get_browser(NULL, TRUE);
// Mobile device emulators.
if ($emulator_check === TRUE) {
$emulator_strings = variable_get('mobile_switch_emulator_strings', "Fennec\nAndroid\nTablet\nMobi");
$emulator_strings = str_replace(array(
"\r\n",
"\n",
"\r",
), '|', $emulator_strings);
if (preg_match("/{$emulator_strings}/i", $browser['useragent'])) {
$browser['ismobiledevice'] = TRUE;
}
}
// Mobile device prevention.
$browser['prevent_device'] = FALSE;
$prevent_devices = (bool) variable_get('mobile_switch_prevent_devices', FALSE);
$prevent_devices_strings = variable_get('mobile_switch_prevent_devices_strings', '');
if ($prevent_devices === TRUE && !empty($prevent_devices_strings)) {
$prevent_devices_strings = str_replace(array(
"\r\n",
"\n",
"\r",
), '|', $prevent_devices_strings);
$strings_arr = explode("|", $prevent_devices_strings);
foreach ($strings_arr as $val) {
$found = stristr($browser['useragent'], $val);
if (!empty($found)) {
$browser['prevent_device'] = TRUE;
}
}
}
// Fix a peculiarity of Broscap module branch 2+.
if ($browser['ismobiledevice'] === 'false') {
$browser['ismobiledevice'] = FALSE;
}
if ($browser['ismobiledevice'] === 'true') {
$browser['ismobiledevice'] = TRUE;
}
}
return $browser;
}