You are here

function adsense_search_block in Google AdSense integration 5.3

Same name and namespace in other branches
  1. 6 old/search/adsense_search.module \adsense_search_block()

Implementation of hook_block().

File

old/search/adsense_search.module, line 71
Displays Google AdSense ads on Drupal pages

Code

function adsense_search_block($op = 'list', $delta = 0, $edit = array()) {
  $block = NULL;
  switch ($op) {
    case 'list':
      $max = variable_get('adsense_search_number_blocks', ADSENSE_SEARCH_NUMBER_BLOCKS_DEFAULT);
      for ($count = 0; $count < $max; $count++) {
        if ($ad = _adsense_search_get_block_config($count)) {
          $title = $ad[0];
        }
        else {
          $title = t('AdSense Search: unconfigured ') . $count;
        }
        $block[$count]['info'] = $title;
        $block[$count]['cache'] = BLOCK_NO_CACHE;
      }
      break;
    case 'configure':
      $ad = _adsense_search_get_block_config($delta);
      $channel_list[''] = t('None');
      for ($channel = 1; $channel <= ADSENSE_MAX_CHANNELS; $channel++) {
        $channel_list[$channel] = $channel . ' : ' . variable_get('adsense_ad_channel_' . $channel, ADSENSE_AD_CHANNEL_DEFAULT);
      }
      $form['info'] = array(
        '#type' => 'textfield',
        '#title' => t('Block description'),
        '#default_value' => $ad ? $ad[0] : '',
        '#maxlength' => 64,
        '#description' => t('A brief description of your block. Used on the <a href="@overview">block overview page</a>.', array(
          '@overview' => url('admin/build/block'),
        )),
        '#required' => TRUE,
        '#weight' => -19,
      );
      $form['ad_channel'] = array(
        '#type' => 'select',
        '#title' => t('Channel'),
        '#default_value' => $ad ? $ad[1] : '',
        '#options' => $channel_list,
      );
      return $form;
    case 'save':
      $data = implode(':', array(
        urlencode($edit['info']),
        $edit['ad_channel'],
      ));
      variable_set('adsense_search_ad_block_' . $delta, $data);
      return;
    case 'view':
      if (_adsense_page_match()) {
        $ad = _adsense_search_get_block_config($delta);
        $block['content'] = $ad ? adsense_display(array(
          'format' => 'Search Box',
          'channel' => $ad[1],
        )) : t('AdSense unconfigured block. <a href=!url>Click to configure.</a>', array(
          '!url' => url('admin/build/block/configure/adsense_search/' . $delta),
        ));
      }
      break;
  }
  return $block;
}