You are here

function _adsense_can_insert_another in Google AdSense integration 5.2

Same name and namespace in other branches
  1. 5.3 adsense.module \_adsense_can_insert_another()
  2. 5 adsense.module \_adsense_can_insert_another()
  3. 6 adsense.module \_adsense_can_insert_another()

Determine if AdSense has reached limit on this page. As per Google's policies, a page can have up to 3 ad units and 3 link units.

Return value

TRUE if we can insert another ad, FALSE if not allowed.

1 call to _adsense_can_insert_another()
adsense_display in ./adsense.module

File

./adsense.module, line 1219

Code

function _adsense_can_insert_another($format = '160x600') {
  static $num_ads = array(
    ADSENSE_TYPE_AD => 0,
    ADSENSE_TYPE_LINK => 0,
    ADSENSE_TYPE_SEARCH => 0,
  );
  $max_ads = array(
    ADSENSE_TYPE_AD => 3,
    ADSENSE_TYPE_LINK => 3,
    ADSENSE_TYPE_SEARCH => 2,
  );
  $ad_list = adsense_ad_formats();
  $type = $ad_list[$format]['type'];
  if ($num_ads[$type] < $max_ads[$type]) {
    $num_ads[$type]++;
    $ret = TRUE;
  }
  else {
    $ret = FALSE;
  }
  return $ret;
}