You are here

function mobile_switch_block_block_view in Mobile Switch Block 7.2

Same name and namespace in other branches
  1. 7 mobile_switch_block.module \mobile_switch_block_block_view()

Implements hook_block_view()

File

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

Code

function mobile_switch_block_block_view($delta) {
  $block = array();
  $mode = mobile_switch_get_operating_mode();

  // Not supported operating modes.
  if ($mode === 'none' || $mode === 'detectonly') {
    return $block;
  }

  // Setting from basic settings.
  $get['tablet_usage'] = (bool) variable_get('mobile_switch_tablet_usage', TRUE);

  // Setting from block settings
  $get['no_tablet_usage'] = (bool) variable_get('mobile_switch_block_no_tablet_usage', 0);
  $get['deskbrowser'] = (bool) variable_get('mobile_switch_deskbrowser', FALSE);
  $get['developer'] = (bool) variable_get('mobile_switch_developer', FALSE);
  $get['browser'] = mobile_switch_mobile_detect($get['developer']);

  // Not supported usage by configuration.
  switch ($get['browser']['istablet']) {

    // Tablet usage.
    case TRUE:
      if ($get['tablet_usage'] === FALSE) {
        return $block;
      }
      break;

    // Non-tablet usage - configuration option.
    // Use the block on mobile devices when a non-tablet device is detected.
    case FALSE:
      if ($get['no_tablet_usage'] === FALSE && (bool) $get['browser']['ismobiledevice'] === TRUE) {
        return $block;
      }
      break;
  }
  switch ($delta) {
    case 'switch':
      if ((bool) $get['browser']['prevent_device'] === FALSE || $get['deskbrowser'] === TRUE && (bool) $get['browser']['ismobiledevice'] === FALSE) {
        $block['subject'] = t('Theme switch');
        $block['content'] = theme('mobile_switch_block_switch_content');
      }
      break;
  }
  return $block;
}