You are here

function mobile_switch_block_mobile_switch_boot_alter in Mobile Switch Block 7

Same name and namespace in other branches
  1. 6 mobile_switch_block.module \mobile_switch_block_mobile_switch_boot_alter()
  2. 7.2 mobile_switch_block.module \mobile_switch_block_mobile_switch_boot_alter()

Implements hook_mobile_switch_mobile_boot_alter().

Parameters

$conf: The associative array contains values to alter.

$get: The associative array contains various parameters to help to alter.

Insert new entries in the 'variable' table:

  • theme_cookie: The default value is FALSE. If the theme switch cookie exists the value can be 'standard' or 'mobile'.

File

./mobile_switch_block.module, line 31
Extends the Mobile Switch module with an theme switch block.

Code

function mobile_switch_block_mobile_switch_boot_alter(&$conf, $get) {
  $conf['theme_cookie'] = FALSE;
  $get['theme_cookie'] = FALSE;

  // Use variable_get() works not proper here.
  // We use the presaved variables:
  // - $conf['mobile_switch_theme_default']
  // - $conf['mobile_switch_theme_mobile']
  // Theme switch from URL.
  // Set users cookie.
  if (isset($_GET['mobile_switch'])) {
    _mobile_switch_block_set_cookie($_GET['mobile_switch']);
    $get['theme_cookie'] = $_GET['mobile_switch'];
  }

  // Provide cookie value.
  $conf['theme_cookie'] = $get['theme_cookie'] = _mobile_switch_block_get_cookie();

  // No theme cookie exist.
  if ((bool) $get['theme_cookie'] === FALSE && (bool) $get['browser']['ismobiledevice'] == TRUE) {
    $conf['theme_default'] = $conf['mobile_switch_theme_mobile'];
    $conf['mobile_switch_ismobiledevice'] = TRUE;
    $conf['mobile_switch_ismobiletheme'] = TRUE;
  }

  // Theme switch from URL as user action.
  if (isset($_GET['mobile_switch'])) {
    switch ($_GET['mobile_switch']) {
      case 'standard':
        $conf['theme_default'] = $conf['mobile_switch_theme_default'];
        $conf['theme_mobile'] = $conf['mobile_switch_theme_default'];
        $conf['mobile_switch_ismobiledevice'] = FALSE;
        $conf['mobile_switch_ismobiletheme'] = FALSE;
        break;
      case 'mobile':
        $conf['theme_default'] = $conf['mobile_switch_theme_mobile'];
        $conf['mobile_switch_ismobiledevice'] = TRUE;
        $conf['mobile_switch_ismobiletheme'] = TRUE;
        break;
    }
  }
  elseif ($get['theme_cookie']) {
    switch ($get['theme_cookie']) {
      case 'standard':
        $conf['theme_default'] = $conf['mobile_switch_theme_default'];
        $conf['theme_mobile'] = $conf['mobile_switch_theme_default'];
        $conf['mobile_switch_ismobiledevice'] = FALSE;
        $conf['mobile_switch_ismobiletheme'] = FALSE;
        break;
      case 'mobile':
        $conf['theme_default'] = $conf['mobile_switch_theme_mobile'];
        $conf['mobile_switch_ismobiledevice'] = TRUE;
        $conf['mobile_switch_ismobiletheme'] = TRUE;
        break;
    }
  }
}