You are here

function ad_embed_auto in Advertisement 6

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

Automatically embed advertisement into content.

1 call to ad_embed_auto()
ad_embed_nodeapi in embed/ad_embed.module
Implementation of hook_nodeapi().

File

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

Code

function ad_embed_auto($text, $ad, $count, $force = FALSE) {
  if (!$text) {
    return;
  }
  if ($count == 0) {
    $text = $ad . $text;
  }
  else {
    if ($count == -1) {
      $text = $text . $ad;
    }
  }
  $pos = $paragraph = 0;
  while ($pos !== FALSE) {
    $pos = strpos($text, "\n", $pos + 1);
    if ($pos) {
      $paragraph++;
      if ($paragraph == $count) {
        $part1 = substr($text, 0, $pos);
        $part2 = substr($text, $pos + 1, strlen($text));
        $text = $part1 . $ad . $part2;
        break;
      }
    }
  }

  // Not enough paragraphs to display ad, unless forced.
  if ($paragraph < $count && $force) {
    $text = $text . $ad;
  }
  return $text;
}