function adsense_injector_nodeapi in Content Injector (formerly AdSense Injector) 6.3
Same name and namespace in other branches
- 5.2 adsense_injector.module \adsense_injector_nodeapi()
- 5 adsense_injector.module \adsense_injector_nodeapi()
- 6 adsense_injector.module \adsense_injector_nodeapi()
- 6.2 adsense_injector.module \adsense_injector_nodeapi()
Implementation of hook_nodeapi().
If rendering a full page, and the node type one of the configured types, inject configured adsense content using simple string concatenation.
@todo: Evaluate efficiency of string concat vs. sprintf, other methods.
File
- ./
adsense_injector.module, line 130 - Inject adsense ads into node content automatically.
Code
function adsense_injector_nodeapi(&$node, $op, $teaser, $page) {
// insert an ad into the body.
// Currently uses $op='view' rather than alter, in order to avoid conflicts
// with other modules.
// TODO: for front and back insertion, use node fields rather than body?
if ($op == 'view') {
// was 'alter'
if ($page && _ai_node_body_view_enabled()) {
// We only consider content types which are enabled for inline adsense. Bail if not.
if (!_ai_should_inject($node)) {
return;
}
//
// Any other reason not to inject?
if (_ai_noinject($node)) {
return;
}
//
// If there are any manual insertions, perform them and exit if
// desired.
if (_ai_manual_insertion($node)) {
return;
}
//
// Now do the auto insertions.
_ai_process_auto_insertions($node);
}
elseif ($teaser && variable_get('adsense_injector_list_view', FALSE)) {
// Process adsense module tags in the template text, if enabled and possible.
$template = _adsense_injector_process_tags(variable_get('adsense_injector_list_view_template', '%teaser<br class="clear"/>[adsense:728x90:0123456789]'));
$node->content['body']['#value'] = strtr($template, array(
'%teaser' => $node->teaser,
));
}
}
}