function adsense_cse_block in Google AdSense integration 6
Same name and namespace in other branches
- 5.3 cse/adsense_cse.module \adsense_cse_block()
Implementation of hook_block().
File
- cse/
adsense_cse.module, line 55 - Displays Google AdSense ads on Drupal pages.
Code
function adsense_cse_block($op = 'list', $delta = 0, $edit = array()) {
$block = NULL;
switch ($op) {
case 'list':
$max = variable_get('adsense_cse_number_blocks', ADSENSE_CSE_NUMBER_BLOCKS_DEFAULT);
for ($count = 0; $count < $max; $count++) {
if ($ad = _adsense_cse_get_block_config($count)) {
$title = $ad[0];
}
else {
$title = t('AdSense CSE: unconfigured !d', array(
'!d' => $count + 1,
));
}
$block[$count]['info'] = $title;
$block[$count]['cache'] = BLOCK_NO_CACHE;
}
break;
case 'configure':
$ad = _adsense_cse_get_block_config($delta);
$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_slot'] = array(
'#type' => 'textfield',
'#title' => t('Ad Slot ID'),
'#default_value' => $ad ? $ad[1] : '',
'#description' => t('This is the provided by the AdSense site in the Search Box Code "cx" field. This is usually provided in the form partner-<em>Publisher ID</em>:<em>Slot Id</em>. If the code provided is, for example, partner-pub-0123456789:<strong>abcdefghij</strong>, then insert only <strong>abcdefghij</strong> here.'),
'#required' => TRUE,
);
return $form;
case 'save':
$data = implode(':', array(
urlencode($edit['info']),
$edit['ad_slot'],
));
variable_set('adsense_cse_ad_block_' . $delta, $data);
return;
case 'view':
if (_adsense_page_match()) {
$ad = _adsense_cse_get_block_config($delta);
$block['content'] = $ad ? adsense_display(array(
'title' => $ad[0],
'format' => 'Search Box',
'slot' => $ad[1],
)) : t('AdSense unconfigured block. <a href=!url>Click to configure.</a>', array(
'!url' => url('admin/build/block/configure/adsense_cse/' . $delta),
));
}
break;
}
return $block;
}