function mobile_tools_init in Mobile Tools 7.3
Same name and namespace in other branches
- 5 mobile_tools.module \mobile_tools_init()
- 6.3 mobile_tools.module \mobile_tools_init()
- 6.2 mobile_tools.module \mobile_tools_init()
- 7.2 mobile_tools.module \mobile_tools_init()
Implements hook_init().
Performs device redirection as required
File
- ./
mobile_tools.module, line 118 - Functionality to ease the creation of mixed device environments.
Code
function mobile_tools_init() {
// If redirection is on, check if any device groups want to redirect, and if
// so, take the first one by weight.
// @todo ensure the javascript based redirection doesn't trigger
// the code below
if (!variable_get('mobile_tools_enable_redirection', FALSE) or mobile_tools_redirection_disabled()) {
return;
}
// @todo add redirection skip functionality
// Get list of device groups
$device_groups = mobile_tools_device_group_load_all();
// Get current device group for comparison
$active_device_group = mobile_tools_get_active_device_group();
// Sort into buckets by weight
foreach ($device_groups as $device_group) {
$tmp[$device_group->weight][$device_group->dgid] = $device_group;
}
sort($tmp, SORT_NUMERIC);
$device_groups = $tmp;
// Do a little cleanup
unset($tmp);
unset($device_group);
// Check each in ascending order if it wants to redirect
foreach ($device_groups as $weight => $groups) {
foreach ($groups as $device_group) {
if (!empty($device_group->detector) and !empty($device_group->detection_settings[$device_group->detector]['activation callback'])) {
if (isset($active_device_group->dgid) and $active_device_group->dgid == $device_group->dgid) {
// The active device group is the highest ordered group with redirection
// enabled. Which means we don't have to do anything.
return;
}
else {
// Check for redirection
if (call_user_func($device_group->detection_settings[$device_group->detector]['activation callback'], $device_group)) {
mobile_tools_device_redirect($device_group);
}
}
}
}
}
}