You are here

function adsense_ad_formats in Google AdSense integration 7

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

This is the array that holds all ad formats.

All it has is a multi-dimensional array indexed by a key, containing the ad type, the description, Google's javascript ad code and the dimensions.

To add a new code:

  • Make sure the key is not in use by a different format
  • Go to Google AdSense . Get the dimensions . Get the code
  • Add it below

Parameters

string $key: Ad key for which the format is needed (optional).

bool $newcode: Pass TRUE to get list of new code ads (optional).

Return value

array if no key is provided: array of supported ad formats as an array (type, desc(ription), code, width and height) if a key is provided, the array containing the ad format for that key, or NULL if there is no ad with that key

5 calls to adsense_ad_formats()
adsense_display in ./adsense.module
Generates the Google AdSense Ad.
adsense_help_text in help/adsense.help.inc
Creates the help text for the settings tab.
adsense_managed_block_configure in managed/adsense_managed.module
Implements hook_block_configure().
adsense_oldcode_block_configure in old/oldcode/adsense_oldcode.module
Implements hook_block_configure().
_adsense_oldcode_get_ad in old/oldcode/adsense_oldcode.module
Generates the AdSense ad.

File

./adsense.module, line 56
Displays Google AdSense ads on Drupal pages.

Code

function adsense_ad_formats($key = NULL, $newcode = TRUE) {

  // Don't forget to add responsive formats in _adsense_is_responsive().
  $ads = array(
    // @codingStandardsIgnoreStart Drupal.Arrays.Array.LongLineDeclaration
    'responsive' => array(
      'type' => ADSENSE_TYPE_AD,
      'desc' => t('Responsive ad unit'),
      'code' => 'responsive',
      'width' => '',
      'height' => '',
    ),
    'custom' => array(
      'type' => ADSENSE_TYPE_AD,
      'desc' => t('Custom size ad unit'),
      'code' => 'custom',
      'width' => '',
      'height' => '',
    ),
    'autorelaxed' => array(
      'type' => ADSENSE_TYPE_OTHER,
      'desc' => t('Matched content'),
      'code' => 'autorelaxed',
      'width' => '',
      'height' => '',
    ),
    'in-article' => array(
      'type' => ADSENSE_TYPE_OTHER,
      'desc' => t('In-article ad'),
      'code' => 'in-article',
      'width' => '',
      'height' => '',
    ),
    'in-feed' => array(
      'type' => ADSENSE_TYPE_OTHER,
      'desc' => t('In-feed ad'),
      'code' => 'in-feed',
      'width' => '',
      'height' => '',
    ),
    '120x240' => array(
      'type' => ADSENSE_TYPE_AD,
      'desc' => t('Vertical Banner'),
      'code' => '120x240_as',
      'width' => 120,
      'height' => 240,
    ),
    '120x600' => array(
      'type' => ADSENSE_TYPE_AD,
      'desc' => t('Skyscraper'),
      'code' => '120x600_as',
      'width' => 120,
      'height' => 600,
    ),
    '125x125' => array(
      'type' => ADSENSE_TYPE_AD,
      'desc' => t('Button'),
      'code' => '125x125_as',
      'width' => 125,
      'height' => 125,
    ),
    '160x600' => array(
      'type' => ADSENSE_TYPE_AD,
      'desc' => t('Wide Skyscraper'),
      'code' => '160x600_as',
      'width' => 160,
      'height' => 600,
    ),
    '180x150' => array(
      'type' => ADSENSE_TYPE_AD,
      'desc' => t('Small Rectangle'),
      'code' => '180x150_as',
      'width' => 180,
      'height' => 150,
    ),
    '200x200' => array(
      'type' => ADSENSE_TYPE_AD,
      'desc' => t('Small Square'),
      'code' => '200x200_as',
      'width' => 200,
      'height' => 200,
    ),
    '234x60' => array(
      'type' => ADSENSE_TYPE_AD,
      'desc' => t('Half Banner'),
      'code' => '234x60_as',
      'width' => 234,
      'height' => 60,
    ),
    '250x250' => array(
      'type' => ADSENSE_TYPE_AD,
      'desc' => t('Square'),
      'code' => '250x250_as',
      'width' => 250,
      'height' => 250,
    ),
    '300x1050' => array(
      'type' => ADSENSE_TYPE_AD,
      'desc' => t('Portrait'),
      'code' => '300x1050_as',
      'width' => 300,
      'height' => 1050,
    ),
    '300x250' => array(
      'type' => ADSENSE_TYPE_AD,
      'desc' => t('Medium Rectangle'),
      'code' => '300x250_as',
      'width' => 300,
      'height' => 250,
    ),
    '300x600' => array(
      'type' => ADSENSE_TYPE_AD,
      'desc' => t('Large Skyscraper'),
      'code' => '300x600_as',
      'width' => 300,
      'height' => 600,
    ),
    '320x50' => array(
      'type' => ADSENSE_TYPE_AD,
      'desc' => t('Mobile Banner'),
      'code' => '320x50_as',
      'width' => 320,
      'height' => 50,
    ),
    '320x100' => array(
      'type' => ADSENSE_TYPE_AD,
      'desc' => t('Large Mobile Banner'),
      'code' => '320x100_as',
      'width' => 320,
      'height' => 100,
    ),
    '336x280' => array(
      'type' => ADSENSE_TYPE_AD,
      'desc' => t('Large Rectangle'),
      'code' => '336x280_as',
      'width' => 336,
      'height' => 280,
    ),
    '468x60' => array(
      'type' => ADSENSE_TYPE_AD,
      'desc' => t('Banner'),
      'code' => '468x60_as',
      'width' => 468,
      'height' => 60,
    ),
    '728x90' => array(
      'type' => ADSENSE_TYPE_AD,
      'desc' => t('Leaderboard'),
      'code' => '728x90_as',
      'width' => 728,
      'height' => 90,
    ),
    '970x250' => array(
      'type' => ADSENSE_TYPE_AD,
      'desc' => t('Billboard'),
      'code' => '970x250_as',
      'width' => 970,
      'height' => 250,
    ),
    '970x90' => array(
      'type' => ADSENSE_TYPE_AD,
      'desc' => t('Large Leaderboard'),
      'code' => '970x90_as',
      'width' => 970,
      'height' => 90,
    ),
    'link' => array(
      'type' => ADSENSE_TYPE_LINK,
      'desc' => t('Responsive links'),
      'code' => 'link',
      'width' => '',
      'height' => '',
    ),
    '120x90' => array(
      'type' => ADSENSE_TYPE_LINK,
      'desc' => t('4-links Vertical Small'),
      'code' => '120x90_0ads_al',
      'width' => 120,
      'height' => 90,
    ),
    '160x90' => array(
      'type' => ADSENSE_TYPE_LINK,
      'desc' => t('4-links Vertical Medium'),
      'code' => '160x90_0ads_al',
      'width' => 160,
      'height' => 90,
    ),
    '180x90' => array(
      'type' => ADSENSE_TYPE_LINK,
      'desc' => t('4-links Vertical Large'),
      'code' => '180x90_0ads_al',
      'width' => 180,
      'height' => 90,
    ),
    '200x90' => array(
      'type' => ADSENSE_TYPE_LINK,
      'desc' => t('4-links Vertical X-Large'),
      'code' => '200x90_0ads_al',
      'width' => 200,
      'height' => 90,
    ),
    '468x15' => array(
      'type' => ADSENSE_TYPE_LINK,
      'desc' => t('4-links Horizontal Medium'),
      'code' => '468x15_0ads_al',
      'width' => 468,
      'height' => 15,
    ),
    '728x15' => array(
      'type' => ADSENSE_TYPE_LINK,
      'desc' => t('4-links Horizontal Large'),
      'code' => '728x15_0ads_al',
      'width' => 728,
      'height' => 15,
    ),
    '120x90_5' => array(
      'type' => ADSENSE_TYPE_LINK,
      'desc' => t('5-links Vertical Small'),
      'code' => '120x90_0ads_al_s',
      'width' => 120,
      'height' => 90,
    ),
    '160x90_5' => array(
      'type' => ADSENSE_TYPE_LINK,
      'desc' => t('5-links Vertical Medium'),
      'code' => '160x90_0ads_al_s',
      'width' => 160,
      'height' => 90,
    ),
    '180x90_5' => array(
      'type' => ADSENSE_TYPE_LINK,
      'desc' => t('5-links Vertical Large'),
      'code' => '180x90_0ads_al_s',
      'width' => 180,
      'height' => 90,
    ),
    '200x90_5' => array(
      'type' => ADSENSE_TYPE_LINK,
      'desc' => t('5-links Vertical X-Large'),
      'code' => '200x90_0ads_al_s',
      'width' => 200,
      'height' => 90,
    ),
    '468x15_5' => array(
      'type' => ADSENSE_TYPE_LINK,
      'desc' => t('5-links Horizontal Medium'),
      'code' => '468x15_0ads_al_s',
      'width' => 468,
      'height' => 15,
    ),
    '728x15_5' => array(
      'type' => ADSENSE_TYPE_LINK,
      'desc' => t('5-links Horizontal Large'),
      'code' => '728x15_0ads_al_s',
      'width' => 728,
      'height' => 15,
    ),
  );
  if (!$newcode) {
    unset($ads['responsive']);
    unset($ads['custom']);
    unset($ads['autorelaxed']);
    unset($ads['link']);
  }
  if (!empty($key)) {
    if (array_key_exists($key, $ads)) {
      return $ads[$key];
    }
    elseif (substr($key, 0, 10) == 'Search Box') {
      return array(
        'type' => ADSENSE_TYPE_SEARCH,
        'desc' => t('AdSense for Search'),
      );
    }
    elseif ($newcode) {
      $ad = _adsense_dimensions($key);
      if (!empty($ad)) {
        return array(
          'type' => ADSENSE_TYPE_AD,
          'desc' => t('Custom'),
          'width' => $ad['width'],
          'height' => $ad['height'],
        );
      }
    }
    return NULL;
  }
  return $ads;
}