function mobile_switch_boot in Mobile Switch 7.2
Same name and namespace in other branches
- 6 mobile_switch.module \mobile_switch_boot()
- 7 mobile_switch.module \mobile_switch_boot()
Implements hook_boot().
Alter specific entries in the system variable registry:
- theme_default: If mobile mobile device, the value are changed to the configured mobile theme.
Insert virtual system variables. Virtual means, the variable is not inserted in system variables registry.
- theme_mobile: The default value is FALSE. If a mobile theme used, the value is the machine name of the used theme.
- mobile_switch_theme_default: Save the system variable theme_default for later use.
- mobile_switch_admin_theme: Save the system variable admin_theme for later use.
- mobile_switch_mobile_theme_use: Boolean. Operating mode theme switch. The result from check to use the mobile theme. If the mobile theme used the value is TRUE.
File
- ./
mobile_switch.module, line 91 - Provides various functionalities to develop mobile ready websites.
Code
function mobile_switch_boot() {
global $conf;
// We use virtual system variables.
// Virtual means, the variable is not saved in the system variables registry.
$conf['theme_mobile'] = FALSE;
$conf['mobile_switch_theme_default'] = $conf['theme_default'];
$conf['mobile_switch_admin_theme'] = $conf['admin_theme'];
$conf['mobile_switch_mobile_theme_use'] = FALSE;
// Use the mobile switch functionality on tablet devices?
$get['tablet_usage'] = (bool) variable_get('mobile_switch_tablet_usage', TRUE);
// Use the mobile switch functionality on admin pages?
$get['admin_usage'] = (bool) variable_get('mobile_switch_admin_usage', FALSE);
// Desktop browser mode enabled?
$get['deskbrowser'] = (bool) variable_get('mobile_switch_deskbrowser', FALSE);
// Developer mode enabled?
$get['developer'] = (bool) variable_get('mobile_switch_developer', FALSE);
// Get informations from Mobile Detect.
$get['browser'] = mobile_switch_mobile_detect($get['developer']);
// Get the Mobile Switch operating mode.
$get['op_mode'] = mobile_switch_get_operating_mode();
// Operating modes without theme switch function.
switch ($get['op_mode']) {
// Operating mode 'Do not use'.
case 'none':
// Only load the Mobile Detect PHP class.
_mobile_switch_mobile_detect_class_load();
return;
// Operating mode 'detect only'.
case 'detectonly':
$get['browser'] = mobile_switch_mobile_detect($get['developer']);
return;
// Operating mode 'redirect to website'.
case 'redirect':
// Get informations from Mobile Detect.
$get['browser'] = mobile_switch_mobile_detect($get['developer']);
//Identify the current website version - desktop or mobile.
$get['site_variant'] = _mobile_switch_get_site_version($get);
if ($get['site_variant'] === 'mobile') {
// Use the mobile theme on admin pages.
if (stristr($_GET['q'], 'admin') && $get['admin_usage'] === TRUE) {
$conf['admin_theme'] = $conf['theme_default'];
}
}
drupal_alter('mobile_switch_boot', $conf, $get);
return;
// Operating mode 'themeswitch'.
case 'themeswitch':
break;
}
// Operating mode theme switch.
// Check website maintenance mode and admin usage.
if (variable_get('maintenance_mode', 0) || stristr($_GET['q'], 'admin') && $get['admin_usage'] === FALSE) {
return;
}
// Tablet device usage is configured to none.
if ($get['tablet_usage'] === FALSE) {
if ((bool) $get['browser']['istablet'] === TRUE) {
return;
}
}
// An prevented device is detected.
if ((bool) variable_get('mobile_switch_prevent_devices', FALSE) === TRUE) {
if ((bool) $get['browser']['prevent_device'] === TRUE) {
return;
}
}
// Switch the theme.
if ((bool) $get['browser']['ismobiledevice'] === TRUE || (bool) $get['browser']['ismobiledevice'] === FALSE && $get['developer'] === TRUE && $get['deskbrowser'] === TRUE || $get['deskbrowser'] === TRUE) {
// The functional heart for theme switching.
$conf['theme_mobile'] = $conf['theme_default'] = $conf['mobile_switch_mobile_theme'];
$conf['mobile_switch_mobile_theme_use'] = TRUE;
// Use the mobile theme on admin pages.
if (stristr($_GET['q'], 'admin') && $get['admin_usage'] === TRUE) {
$conf['admin_theme'] = $conf['mobile_switch_mobile_theme'];
}
}
drupal_alter('mobile_switch_boot', $conf, $get);
}