function adsense_managed_block in Google AdSense integration 5.3
Same name and namespace in other branches
- 6 managed/adsense_managed.module \adsense_managed_block()
Implementation of hook_block().
File
- managed/
adsense_managed.module, line 40 - Displays Google AdSense ads on Drupal pages
Code
function adsense_managed_block($op = 'list', $delta = 0, $edit = array()) {
$block = NULL;
switch ($op) {
case 'list':
$max = variable_get('adsense_managed_number_blocks', ADSENSE_MANAGED_NUMBER_BLOCKS_DEFAULT);
for ($count = 0; $count < $max; $count++) {
if ($ad = _adsense_managed_get_block_config($count)) {
$title = $ad[0];
}
else {
$title = t('AdSense: unconfigured ') . $count;
}
$block[$count]['info'] = $title;
$block[$count]['cache'] = BLOCK_NO_CACHE;
}
break;
case 'configure':
$ad = _adsense_managed_get_block_config($delta);
foreach (adsense_ad_formats() as $format => $data) {
$ad_list[$format] = $format . ' : ' . $data['desc'];
}
$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.'),
'#required' => TRUE,
);
$form['ad_slot'] = array(
'#type' => 'textfield',
'#title' => t('Ad Slot ID'),
'#default_value' => $ad ? $ad[2] : '',
'#description' => t('This is the Ad Slot ID from your Google Adsense account, such as 0123456789.'),
'#required' => TRUE,
);
$form['ad_align'] = array(
'#type' => 'select',
'#title' => t('Ad alignment'),
'#default_value' => $ad ? $ad[3] : '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_slot'],
$edit['ad_align'],
));
variable_set('adsense_managed_ad_block_' . $delta, $data);
return;
case 'view':
if (_adsense_page_match()) {
$ad = _adsense_managed_get_block_config($delta);
$block['content'] = $ad ? adsense_display(array(
'format' => $ad[1],
'slot' => $ad[2],
)) : t('AdSense unconfigured block. <a href=!url>Click to configure.</a>', array(
'!url' => url('admin/build/block/configure/adsense_managed/' . $delta),
));
if (!empty($ad[3])) {
$block['content'] = "<div style='text-align:{$ad[3]}; display: block;'>{$block['content']}</div>";
}
}
break;
}
return $block;
}