You are here

function mobile_switch_block_mobile_switch_boot_alter in Mobile Switch Block 7.2

Same name and namespace in other branches
  1. 6 mobile_switch_block.module \mobile_switch_block_mobile_switch_boot_alter()
  2. 7 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 a virtual system variable. Virtual means, the variable is not inserted in system variables registry.

  • 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 32
Extends the Mobile Switch module with an theme switch block.

Code

function mobile_switch_block_mobile_switch_boot_alter(&$conf, $get) {
  $get['mode'] = mobile_switch_get_operating_mode();
  if ($get['mode'] === 'none' || $get['mode'] === 'detectonly') {
    return;
  }
  $get['theme_cookie'] = FALSE;

  // Theme switch from URL.
  // Set users cookie.
  if (isset($_GET['mobile_switch'])) {
    _mobile_switch_block_set_cookie($_GET['mobile_switch']);
    $get['theme_cookie'] = check_plain($_GET['mobile_switch']);
  }

  // Provide cookie value.
  $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_mobile_theme'];

  //}

  // Theme switch from URL as visitor action.
  if (isset($_GET['mobile_switch'])) {
    switch ($_GET['mobile_switch']) {
      case 'standard':
      case 'standard-rm':
        $conf['theme_default'] = $conf['mobile_switch_theme_default'];
        $conf['theme_mobile'] = $conf['mobile_switch_theme_default'];

        // Use the mobile theme on admin pages.
        if (stristr($_GET['q'], 'admin') && $get['admin_usage'] === TRUE) {
          $conf['admin_theme'] = $conf['mobile_switch_admin_theme'];
        }
        break;
      case 'mobile':
      case 'mobile-rm':
        if ($get['mode'] === 'redirect') {
          $conf['theme_default'] = $conf['mobile_switch_theme_default'];
        }
        if ($get['mode'] === 'themeswitch') {
          $conf['theme_default'] = $conf['mobile_switch_mobile_theme'];
        }
        break;
    }
  }
  elseif ($get['theme_cookie']) {
    switch ($get['theme_cookie']) {
      case 'standard':
      case 'standard-rm':
        $conf['theme_default'] = $conf['mobile_switch_theme_default'];
        $conf['theme_mobile'] = $conf['mobile_switch_theme_default'];

        // Use the mobile theme on admin pages.
        if (stristr($_GET['q'], 'admin') && $get['admin_usage'] === TRUE) {
          $conf['admin_theme'] = $conf['mobile_switch_admin_theme'];
        }
        break;
      case 'mobile':
      case 'mobile-rm':
        if ($get['mode'] === 'redirect') {
          $conf['theme_default'] = $conf['mobile_switch_theme_default'];
        }
        if ($get['mode'] === 'themeswitch') {
          $conf['theme_default'] = $conf['mobile_switch_mobile_theme'];
        }
        break;
    }
  }
}