function adsense_block in Google AdSense integration 5.2
Same name and namespace in other branches
- 5 adsense.module \adsense_block()
Implementation of hook_block().
File
- ./
adsense.module, line 1371
Code
function adsense_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
for ($count = 0; $count < ADSENSE_MAX_BLOCKS; $count++) {
if ($ad = _adsense_get_block_config($count)) {
$title = t('AdSense: ') . $ad[0];
}
else {
$title = t('AdSense: unconfigured ') . $count;
}
$block[$count]['info'] = $title;
}
break;
case 'configure':
$ad = _adsense_get_block_config($delta);
$ad_list[] = t('None');
foreach (adsense_ad_formats() as $format => $data) {
$ad_list[$format] = $format . ' : ' . $data['desc'];
}
for ($group = 1; $group < ADSENSE_MAX_GROUPS + 1; $group++) {
$title = $group . ' ' . variable_get(ADSENSE_GROUP_TITLE . $group, '');
$group_list[$group] = t('Group ') . $title;
}
$group_list[$group] = ADSENSE_SEARCH_BOX;
for ($channel = 1; $channel < ADSENSE_MAX_CHANNELS + 1; $channel++) {
$channel_list[$channel] = 'Channel ' . $channel;
}
$form['ad_format'] = array(
'#type' => 'select',
'#title' => t('Ad format'),
'#default_value' => $ad ? $ad[0] : 1,
'#options' => $ad_list,
);
$form['ad_group'] = array(
'#type' => 'select',
'#title' => t('Group'),
'#default_value' => $ad ? $ad[1] : 1,
'#options' => $group_list,
);
$form['ad_channel'] = array(
'#type' => 'select',
'#title' => t('Channel'),
'#default_value' => $ad ? $ad[2] : 1,
'#options' => $channel_list,
);
return $form;
case 'save':
$data = implode(':', array(
$edit['ad_format'],
$edit['ad_group'],
$edit['ad_channel'],
));
variable_set(ADSENSE_AD_BLOCK . $delta, $data);
return;
case 'view':
$ad = _adsense_get_block_config($delta);
$block['subject'] = '';
$block['content'] = $ad ? adsense_display($ad[0], $ad[1], $ad[2]) : t('AdSense unconfigured block. <a href=!url>Click to configure.</a>', array(
'!url' => url('admin/build/block/configure/adsense/' . $delta),
));
break;
}
return $block;
}