You are here

function adsense_injector_node_view in Content Injector (formerly AdSense Injector) 7.3

Same name and namespace in other branches
  1. 7 adsense_injector.module \adsense_injector_node_view()

Implements hook_node_view().

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 129
Inject adsense ads into node content automatically.

Code

function adsense_injector_node_view($node, $view_mode) {

  //return;

  // TODO Remaining code in this function needs to be moved to the appropriate new hook function.
  // We only consider content types which are enabled for inline adsense.
  if (!_ai_should_inject($node)) {
    return;
  }

  // Insert an ad into the body.
  if ($view_mode == 'full') {

    //
    // 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 ($view_mode == 'teaser' && variable_get('adsense_injector_list_view', FALSE)) {

    // Process adsense module tags in the template text, if enabled and possible.
    $template = variable_get('adsense_injector_list_view_template', '%teaser<br class="clear"/>[adsense:728x90:0123456789]');
    if (function_exists('_adsense_process_tags')) {
      $template = _adsense_process_tags($template, null);
    }
    $node->content['body'][0]['#markup'] = strtr($template, array(
      '%teaser' => $node->content['body'][0]['#markup'],
    ));
  }
}