You are here

function _dfp_js_slot_definition in Doubleclick for Publishers (DFP) 7.2

Same name and namespace in other branches
  1. 7 dfp.module \_dfp_js_slot_definition()

Helper function to build the javascript needed to define an ad slot and add it to the head tag.

1 call to _dfp_js_slot_definition()
template_preprocess_dfp_tag in ./dfp.module
Preprocess function for DFP tags.

File

./dfp.module, line 771

Code

function _dfp_js_slot_definition($tag) {

  // Avoid accidentaly adding ad slot definition more than once.
  if (isset($tag->processed) && $tag->processed === TRUE) {
    watchdog('dfp', 'DFP tag %machinename is being added to the page more than once.', array(
      '%machinename' => $tag->machinename,
    ), WATCHDOG_WARNING);
    return;
  }

  // Start by defining breakpoints for this ad.
  $bp_sizes = array();
  if (!empty($tag->breakpoints)) {
    $breakpoints = $tag->breakpoints;
    foreach ($breakpoints as $breakpoint) {
      $bp_sizes[] = array(
        'browser' => dfp_format_size($breakpoint['browser_size']),
        'ad' => dfp_format_size($breakpoint['ad_sizes']),
      );
    }
  }
  $click_url = variable_get('dfp_click_url', '');
  if (!empty($click_url)) {
    $click_url = url($click_url, array(
      'absolute' => TRUE,
    ));
  }
  $adsense_colors = array();
  foreach ($tag->adsense_colors as $key => $val) {
    if (!empty($val)) {
      $key = 'adsense_' . $key . '_color';
      $val = '#' . drupal_strtoupper($val);
      $adsense_colors[] = array(
        'key' => $key,
        'value' => $val,
      );
    }
  }
  $targeting = dfp_format_targeting($tag->targeting, $tag);

  // Drupal.settings array.
  $settings = array(
    'dfpTags' => array(
      $tag->machinename => array(
        'machinename' => $tag->machinename,
        'breakpoints' => $bp_sizes,
        'size' => $tag->size,
        'adunit' => $tag->adunit,
        'placeholder_id' => $tag->placeholder_id,
        'out_of_page' => !empty($tag->settings['out_of_page']) ? TRUE : FALSE,
        'click_url' => $click_url,
        'adsense_ad_types' => $tag->adsense_ad_types,
        'adsense_channel_ids' => $tag->adsense_channel_ids,
        'adsense_colors' => $adsense_colors,
        'targeting' => $targeting,
        'banner' => !empty($tag->settings['banner']) ? TRUE : FALSE,
        'companion' => !empty($tag->settings['companion']) ? TRUE : FALSE,
        'disable_initial_load' => !empty($tag->settings['disable_initial_load']) ? TRUE : FALSE,
      ),
    ),
  );

  // Add Drupal.settings.
  drupal_add_js($settings, 'setting');
}