You are here

function _adsense_get_ad in Google AdSense integration 5

Same name and namespace in other branches
  1. 5.2 adsense.module \_adsense_get_ad()
1 call to _adsense_get_ad()
adsense_display in ./adsense.module

File

./adsense.module, line 1031

Code

function _adsense_get_ad($format, $group, $channel) {
  $sharing = variable_get(ADSENSE_REVENUE_ENABLE, 0);
  if ($sharing) {
    $ad = _adsense_format($format, $group, $channel);
    return $ad;
  }
  $cache_key = "adsense-{$group}-{$format}-{$channel}";
  $cache = cache_get($cache_key);
  if ($cache) {

    // This ad format is cached, use it
    $ad = '<!--adsense: cached-->' . $cache->data;
  }
  else {

    // Not cached. Format an ad
    $ad = _adsense_format($format, $group, $channel);

    // Add it to cache
    cache_set($cache_key, 'cache', $ad, CACHE_PERMANENT);
  }
  return $ad;
}