You are here

function ad_embed_nodeapi in Advertisement 5

Same name and namespace in other branches
  1. 5.2 embed/ad_embed.module \ad_embed_nodeapi()
  2. 6.3 embed/ad_embed.module \ad_embed_nodeapi()
  3. 6 embed/ad_embed.module \ad_embed_nodeapi()
  4. 6.2 embed/ad_embed.module \ad_embed_nodeapi()
  5. 7 embed/ad_embed.module \ad_embed_nodeapi()

Drupal _nodeapi hook.

File

embed/ad_embed.module, line 73
Embed ads in content.

Code

function ad_embed_nodeapi(&$node, $op, $teaser, $page) {
  switch ($op) {
    case 'view':
      $node = (object) $node;

      // Only replace tags if content creator has 'embed' permission
      if (user_access('embed ads in content', user_load(array(
        'uid' => $node->uid,
      )))) {
        if (isset($node->content['teaser']['#value'])) {
          $node->content['teaser']['#value'] = ad_embed_replace($node->content['teaser']['#value']);
        }
        if (isset($node->content['body']['#value'])) {
          $node->content['body']['#value'] = ad_embed_replace($node->content['body']['#value']);
        }
      }
      if (!$teaser && variable_get("embed-ad-{$node->type}", 0)) {
        $ad = ad(variable_get("embed-ad-{$node->type}" . '-group', array()), variable_get("embed-ad-{$node->type}" . '-quantity', 1));
        $node->content['body']['#value'] = ad_embed_auto($node->content['body']['#value'], $ad, variable_get("embed-ad-{$node->type}" . '-count', 3), variable_get("embed-ad-{$node->type}" . '-force', 0));
      }
  }
}