function adsense_oldcode_block in Google AdSense integration 6
Same name and namespace in other branches
- 5.3 old/oldcode/adsense_oldcode.module \adsense_oldcode_block()
Implementation of hook_block().
File
- old/
oldcode/ adsense_oldcode.module, line 48 - Displays Google AdSense ads on Drupal pages.
Code
function adsense_oldcode_block($op = 'list', $delta = 0, $edit = array()) {
$block = NULL;
switch ($op) {
case 'list':
$max = variable_get('adsense_oldcode_number_blocks', ADSENSE_OLDCODE_NUMBER_BLOCKS_DEFAULT);
for ($count = 0; $count < $max; $count++) {
if ($ad = _adsense_oldcode_get_block_config($count)) {
$title = $ad[0];
}
else {
$title = t('AdSense old code: unconfigured !d', array(
'!d' => $count + 1,
));
}
$block[$count]['info'] = $title;
$block[$count]['cache'] = BLOCK_NO_CACHE;
}
break;
case 'configure':
$ad = _adsense_oldcode_get_block_config($delta);
foreach (adsense_ad_formats() as $format => $data) {
$ad_list[$format] = $format . ' : ' . $data['desc'];
}
for ($group = 1; $group <= ADSENSE_MAX_GROUPS; $group++) {
$group_list[$group] = $group . ' : ' . variable_get('adsense_group_title_' . $group, ADSENSE_GROUP_TITLE_DEFAULT);
}
$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_format'] = array(
'#type' => 'select',
'#title' => t('Ad format'),
'#default_value' => $ad ? $ad[1] : '250x250',
'#options' => $ad_list,
'#description' => t('Select the ad dimensions you want for this block.'),
);
$form['ad_group'] = array(
'#type' => 'select',
'#title' => t('Group'),
'#default_value' => $ad ? $ad[2] : 1,
'#options' => $group_list,
);
$form['ad_channel'] = array(
'#type' => 'select',
'#title' => t('Channel'),
'#default_value' => $ad ? $ad[3] : 1,
'#options' => $channel_list,
);
$form['ad_align'] = array(
'#type' => 'select',
'#title' => t('Ad alignment'),
'#default_value' => $ad ? $ad[4] : 'center',
'#options' => array(
'' => t('None'),
'left' => t('Left'),
'center' => t('Centered'),
'right' => t('Right'),
),
'#description' => t('Select the horizontal alignment of the ad within the block.'),
);
return $form;
case 'save':
$data = implode(':', array(
urlencode($edit['info']),
$edit['ad_format'],
$edit['ad_group'],
$edit['ad_channel'],
$edit['ad_align'],
));
variable_set('adsense_oldcode_ad_block_' . $delta, $data);
return;
case 'view':
if (_adsense_page_match()) {
$ad = _adsense_oldcode_get_block_config($delta);
$block['content'] = $ad ? adsense_display(array(
'title' => $ad[0],
'format' => $ad[1],
'group' => $ad[2],
'channel' => $ad[3],
)) : t('AdSense unconfigured block. <a href=!url>Click to configure.</a>', array(
'!url' => url('admin/build/block/configure/adsense_oldcode/' . $delta),
));
if (!empty($ad[4])) {
$block['content'] = "<div style='text-align:{$ad[4]}'>{$block['content']}</div>";
}
}
break;
}
return $block;
}