You are here

function mobile_switch_boot in Mobile Switch 6

Same name and namespace in other branches
  1. 7.2 mobile_switch.module \mobile_switch_boot()
  2. 7 mobile_switch.module \mobile_switch_boot()

Implementation of hook_boot().

Alter specific entries in the 'variable' table:

  • theme_default: If mobile mobile device the value are changed to the configured mobile theme.

Insert new entries in the 'variable' table:

  • mobile_switch_ismobiledevice: The default value is FALSE. If the browscap value 'ismobiledevice' are 1 the value is TRUE.
  • mobile_switch_ismobiletheme: The default value is FALSE. If used mobile theme the value is TRUE.
  • theme_mobile: The default value is FALSE. If used mobile theme the value is the machine name of the used theme.

File

./mobile_switch.module, line 22
Simple theme switch for mobile devices, detected by browscap.

Code

function mobile_switch_boot() {
  global $conf;

  // Initialize the new variables here (as fallback) if configured the
  // 'Mobile theme' setting  with the option 'Do not use'.
  $conf['mobile_switch_ismobiledevice'] = FALSE;
  $conf['mobile_switch_ismobiletheme'] = FALSE;
  $conf['theme_mobile'] = FALSE;

  // Preserve the configuration variables.
  $conf['mobile_switch_theme_default'] = variable_get('theme_default', 'garland');
  $conf['mobile_switch_theme_mobile'] = variable_get('mobile_switch_mobile_theme', 'none');

  // Use the mobile theme on admin pages.
  $get['admin_usage'] = (bool) variable_get('mobile_switch_admin_usage', FALSE);
  if (variable_get('mobile_switch_mobile_theme', 'none') === 'none') {
    return;
  }
  if (isset($conf['site_offline'])) {
    if ((bool) $conf['site_offline'] === TRUE) {
      return;
    }
  }
  if (isset($_REQUEST['q'])) {
    if (stristr($_REQUEST['q'], 'admin') && $get['admin_usage'] === FALSE) {
      return;
    }
  }
  $get['deskbrowser'] = (bool) variable_get('mobile_switch_deskbrowser', FALSE);
  $get['developer'] = (bool) variable_get('mobile_switch_developer', FALSE);
  $get['theme_default'] = variable_get('theme_default', 'garland');
  $get['browser'] = mobile_switch_browscap_get_browser($get['developer']);
  if ((bool) variable_get('mobile_switch_prevent_devices', FALSE) === TRUE) {
    if ((bool) $get['browser']['prevent_device'] === TRUE) {
      return;
    }
  }
  if ((bool) $get['browser']['ismobiledevice'] === TRUE || (bool) $get['browser']['ismobiledevice'] === FALSE && $get['developer'] === TRUE && $get['deskbrowser'] === TRUE || $get['deskbrowser'] === TRUE) {
    $conf['theme_default'] = $conf['theme_mobile'] = $conf['mobile_switch_theme_mobile'];
    $conf['mobile_switch_ismobiletheme'] = TRUE;

    // Use mobile theme on admin pages.
    if (isset($_REQUEST['q'])) {
      if (stristr($_REQUEST['q'], 'admin') && $get['admin_usage'] === TRUE) {
        $conf['admin_theme'] = $conf['mobile_switch_theme_mobile'];
      }
    }
  }
  if ((bool) $get['browser']['ismobiledevice'] === TRUE) {
    $conf['mobile_switch_ismobiledevice'] = TRUE;
  }
  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  drupal_alter('mobile_switch_boot', $conf, $get);
}