function amp_block_view in Accelerated Mobile Pages (AMP) 7
Implements hook_block_view().
File
- ./
amp.module, line 831
Code
function amp_block_view($delta = '') {
$block = array();
$adsense_blocks = _amp_get_adsense_block_ids();
$doubleclick_blocks = _amp_get_doubleclick_block_ids();
if (in_array($delta, $adsense_blocks)) {
// Start by getting global Adsense configuration.
$adsense_id = variable_get('amp_google_adsense_id', '');
if (!empty($adsense_id)) {
$width = variable_get($delta . '_width', '');
$height = variable_get($delta . '_height', '');
$data_ad_slot = variable_get($delta . '_data_ad_slot', '');
if (empty($width) || empty($height) || empty($data_ad_slot)) {
$block['content'] = array(
'message' => array(
'#type' => 'markup',
'#markup' => t('This Adsense block requires a width, height, and data ad slot.'),
'#suffix' => '',
),
);
}
else {
$block['content']['amp_adsense'] = array(
'#theme' => 'amp_ad',
'#adtype' => 'adsense',
'#height' => $height,
'#width' => $width,
'#slot_attributes_array' => array(
'data-ad-client' => $adsense_id,
'data-ad-slot' => $data_ad_slot,
),
);
}
}
else {
$block['content'] = array(
'message' => array(
'#type' => 'markup',
'#markup' => t('This DoubleClick block requires a Google Adsense ID.'),
'#suffix' => '',
),
);
}
}
elseif (in_array($delta, $doubleclick_blocks)) {
$doubleclick_id = variable_get('amp_google_doubleclick_id', '');
if (!empty($doubleclick_id) && $doubleclick_id != "/") {
$width = variable_get($delta . '_width', '');
$height = variable_get($delta . '_height', '');
$data_ad_slot = variable_get($delta . '_data_ad_slot', '');
if (!empty($width) && !empty($height) && !empty($data_ad_slot)) {
$block['content']['amp_doubleclick'] = array(
'#theme' => 'amp_ad',
'#adtype' => 'doubleclick',
'#height' => $height,
'#width' => $width,
'#slot_attributes_array' => array(
'data-slot' => $doubleclick_id . '/' . $data_ad_slot,
),
);
}
else {
$block['content'] = array(
'message' => array(
'#type' => 'markup',
'#markup' => t('This block requires a width, height, and data ad slot.'),
'#suffix' => '',
),
);
}
}
else {
$block['content'] = array(
'message' => array(
'#type' => 'markup',
'#markup' => t('This block requires a Google DoubleClick ID.'),
'#suffix' => '',
),
);
}
}
return $block;
}