You are here

function mobile_switch_block_block in Mobile Switch Block 6

Implementation of hook_block().

File

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

Code

function mobile_switch_block_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'configure':
      $form['mobile_switch_block_content'] = array(
        '#type' => 'select',
        '#title' => t('Block content'),
        '#default_value' => variable_get('mobile_switch_block_content', 'link'),
        '#options' => _mobile_switch_block_content_options(),
      );
      return $form;
    case 'list':
      $blocks['switch'] = array(
        'info' => t('Mobile switch'),
      );
      return $blocks;
    case 'save':
      if ($delta === 'switch') {
        variable_set('mobile_switch_block_content', $edit['mobile_switch_block_content']);
      }
      break;
    case 'view':
      global $conf;
      if ($conf['mobile_switch_theme_mobile'] === 'none') {
        return;
      }
      $get['deskbrowser'] = (bool) variable_get('mobile_switch_deskbrowser', FALSE);
      $get['developer'] = (bool) variable_get('mobile_switch_developer', FALSE);
      $get['browser'] = mobile_switch_browscap_get_browser($get['developer']);
      $block = array();
      switch ($delta) {
        case 'switch':
          if ((bool) $get['browser']['ismobiledevice'] === TRUE && (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;
  }
}