function _adsense_process_tags in Google AdSense integration 7
Same name and namespace in other branches
- 5.3 adsense.module \_adsense_process_tags()
- 5 adsense.module \_adsense_process_tags()
- 5.2 adsense.module \_adsense_process_tags()
- 6 adsense.module \_adsense_process_tags()
Implements callback_filter_process().
1 string reference to '_adsense_process_tags'
- adsense_filter_info in ./
adsense.module - Implements hook_filter_info().
File
- ./
adsense.module, line 241 - Displays Google AdSense ads on Drupal pages.
Code
function _adsense_process_tags($text, $filter) {
$patterns = array(
'block' => '/\\[adsense:block:([^\\]]+)\\]/x',
'oldtag' => '/\\[adsense:([^:]+):(\\d*):(\\d*):?(\\w*)\\]/x',
'tag' => '/\\[adsense:([^:]+):([^\\]]+)\\]/x',
);
foreach ($patterns as $mode => $pattern) {
if (preg_match_all($pattern, $text, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
switch ($mode) {
case 'block':
$mods = array(
'adsense_managed',
'adsense_cse',
'adsense_oldcode',
'adsense_search',
);
foreach ($mods as $module) {
$module_blocks = module_invoke($module, 'block_info');
if ($module_blocks) {
foreach ($module_blocks as $delta => $block) {
if ($block['info'] == $match[1]) {
// Found the block with the same name as the passed arg.
$block = module_invoke($module, 'block_view', $delta);
$ad = $block['content'];
}
}
}
}
break;
case 'oldtag':
// If not specified, default group and channel to 1.
if (empty($match[2])) {
$match[2] = 1;
}
if (empty($match[3])) {
$match[3] = 1;
}
$args = array(
'format' => $match[1],
'group' => $match[2],
'channel' => $match[3],
'slot' => $match[4],
);
$ad = adsense_display($args);
unset($args);
break;
case 'tag':
$args = array(
'format' => $match[1],
'slot' => $match[2],
);
$ad = adsense_display($args);
unset($args);
break;
}
// Replace the first occurrence of the tag, in case we have the same
// tag more than once.
if (!empty($ad)) {
$str = '/\\' . $match[0] . '/';
$text = preg_replace($str, $ad, $text, 1);
}
}
}
}
return $text;
}