You are here

function _adsense_oldcode_get_ad in Google AdSense integration 5.3

Same name and namespace in other branches
  1. 6 old/oldcode/adsense_oldcode.module \_adsense_oldcode_get_ad()
  2. 7 old/oldcode/adsense_oldcode.module \_adsense_oldcode_get_ad()

Generates the AdSense ad

Parameters

$format: format of the ad

$group: (optional) Group ID of the configured color attributes group

$channel: (optional) Channel ID of the configured Ad Channel

Return value

JavaScript that embeds the Google AdSense ad

1 call to _adsense_oldcode_get_ad()
adsense_display in ./adsense.module
Generates the Google AdSense Ad

File

old/oldcode/adsense_oldcode.module, line 181
Displays Google AdSense ads on Drupal pages

Code

function _adsense_oldcode_get_ad($format, $client, $group = 1, $channel = 1) {
  $ad = adsense_ad_formats($format);
  if ($ad === NULL) {
    $output = "";
  }
  elseif (variable_get('adsense_test_mode', ADSENSE_TEST_MODE_DEFAULT)) {
    $output = _adsense_format_box("client = {$client}<br />format = {$format}<br />width = {$ad['width']}<br />height = {$ad['height']}", $ad['width'], $ad['height']);
  }
  else {
    if ($group < 1 || $group > ADSENSE_MAX_GROUPS) {

      // Default to 1 if an invalid group is supplied
      $group = 1;
    }
    switch (variable_get('adsense_ad_type_' . $group, ADSENSE_AD_TYPE_DEFAULT)) {
      case 2:
        $type = 'text_image';
        break;
      case 1:
        $type = 'image';
        break;
      default:
        $type = 'text';
        break;
    }
    $channel = variable_get('adsense_ad_channel_' . $channel, ADSENSE_AD_CHANNEL_DEFAULT);
    $border = substr(variable_get('adsense_color_border_' . $group, ADSENSE_COLOR_BORDER_DEFAULT), 1);
    $bg = substr(variable_get('adsense_color_bg_' . $group, ADSENSE_COLOR_BG_DEFAULT), 1);
    $link = substr(variable_get('adsense_color_link_' . $group, ADSENSE_COLOR_LINK_DEFAULT), 1);
    $url = substr(variable_get('adsense_color_url_' . $group, ADSENSE_COLOR_URL_DEFAULT), 1);
    $text = substr(variable_get('adsense_color_text_' . $group, ADSENSE_COLOR_TEXT_DEFAULT), 1);
    $corner = variable_get('adsense_ui_features_' . $group, ADSENSE_UI_FEATURES_DEFAULT);
    $alt = variable_get('adsense_alt_' . $group, ADSENSE_ALT_DEFAULT);
    $alt_info = variable_get('adsense_alt_info_' . $group, ADSENSE_ALT_INFO_DEFAULT);
    switch ($alt) {
      case 1:
        $part1 = "google_alternate_ad_url = \"{$alt_info}\";";
        break;
      case 2:
        $part1 = "google_alternate_color = \"{$alt_info}\";";
        break;
      case 0:

      // disabled
      default:
        $part1 = "";
    }
    $part2 = "";
    if ($ad['type'] == ADSENSE_TYPE_AD) {
      $part2 .= "google_ad_type = \"{$type}\";\n";
    }
    if (!empty($channel)) {
      $part2 .= "google_ad_channel = \"{$channel}\";";
    }
    $secret = '';
    if (variable_get('adsense_secret_adtest', ADSENSE_SECRET_ADTEST_DEFAULT)) {
      $secret .= "google_adtest = 'on';\n";
    }
    if ($lang = variable_get('adsense_secret_language', ADSENSE_SECRET_LANGUAGE_DEFAULT)) {
      $secret .= "google_language = '{$lang}';";
    }
    $output = <<<OLDCODE_TXT
<script type="text/javascript"><!--
google_ad_client = "{<span class="php-variable">$client</span>}";
{<span class="php-variable">$part1</span>}
google_ad_width = {<span class="php-variable">$ad</span>[<span class="php-string">'width'</span>]};
google_ad_height = {<span class="php-variable">$ad</span>[<span class="php-string">'height'</span>]};
google_ad_format = "{<span class="php-variable">$ad</span>[<span class="php-string">'code'</span>]}";
{<span class="php-variable">$part2</span>}
google_color_border = "{<span class="php-variable">$border</span>}";
google_color_bg = "{<span class="php-variable">$bg</span>}";
google_color_link = "{<span class="php-variable">$link</span>}";
google_color_text = "{<span class="php-variable">$text</span>}";
google_color_url = "{<span class="php-variable">$url</span>}";
google_ui_features = "{<span class="php-variable">$corner</span>}";
{<span class="php-variable">$secret</span>}
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
OLDCODE_TXT;
  }
  return $output;
}