You are here

function _adsense_get_ad in Google AdSense integration 5.2

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

File

./adsense.module, line 1010

Code

function _adsense_get_ad($format, $group, $channel) {
  $module = variable_get(ADSENSE_ID_MODULE, 'adsense_basic');
  if ($module != 'adsense_basic') {

    // Do not serve the ads from the adsense cache
    $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;
}