You are here

function adsense_injector_process_body in Content Injector (formerly AdSense Injector) 7.3

Same name and namespace in other branches
  1. 6.3 adsense_injector.module \adsense_injector_process_body()

Process the body, handle adsense injector tags. Look for an insertion point based on paragraphs.

Parameters

$node_body The node body HTML to process.:

$node The node object (for field insertion):

$skipList An array of insertions to skip.:

Return value

The processed HTML.

2 calls to adsense_injector_process_body()
_ai_manual_insertion in ./adsense_injector.module
Perform manual insertions, if any.
_ai_process_auto_insertions in ./adsense_injector.module
Process automatic insertions.

File

./adsense_injector.module, line 26
Inject adsense ads into node content automatically.

Code

function adsense_injector_process_body($node_body, &$node, $skipList = null) {

  // Process adsense module tags in the template text, if enabled and possible.
  // Determine the target paragraph # from tags.
  // TODO: Remove dependency on adsense module.  Only call _adsense_process_tags()
  // if module is present.
  $vars = _ai_get_body_insertions_vars();
  $special = array();
  foreach ($vars as $key => $insertion) {

    //
    // Skip any keys in skipList
    if ($skipList && in_array($key, $skipList)) {
      continue;
    }

    //
    // Find and hold all non-xpath insertions for last.
    // Non-xpath insertions start with !! (!!TOP, !!BOTTOM)
    if (strpos($insertion['xpath'], '!!') === 0) {

      // Add it to the list and continue.
      $special[] = $insertion;
      continue;
    }
    else {

      // Process current insertion text.
      $template = _adsense_injector_process_tags($insertion['text']);

      //
      // TODO: allow views, blocks render tags: [ci:block:xxx] and [ci:view:xyz]
      // Given: body, list of xpath expressions and associated html snippet
      // Produce: new body
      $xpath_expr = $insertion['xpath'];

      // TODO: Ignore empty paragraphs if possible.
      // TODO: Smart location: Count words in each 'paragraph' element?
      // TODO: This doesn't take into account the <br> stuff inserted by auto-line breaks
      $node_body = _ai_injectXPath($node_body, $template, $xpath_expr);
    }
  }
  foreach ($special as $specialInsertion) {

    // Process current insertion text.
    $template = _adsense_injector_process_tags($specialInsertion['text']);
    switch ($specialInsertion['xpath']) {
      case ADSENSE_INJECTOR_DEFAULT_XPATH_FRONT:
        $node->content['adsense_injector_front'] = array(
          '#markup' => $template,
          '#weight' => variable_get('adsense_injector_front_weight', -6),
        );
        break;
      case ADSENSE_INJECTOR_DEFAULT_XPATH_BACK:
        $node->content['adsense_injector_back'] = array(
          '#markup' => $template,
          '#weight' => variable_get('adsense_injector_back_weight', 10),
        );
        break;
      default:
        watchdog('adsense_injector', t('Unknown special insertion type in adsense_injector_process_body'), WATCHDOG_ERROR);
    }
  }
  return $node_body;
}