View source
<?php
define('DFP_GOOGLE_TAG_SERVICES_URL', 'www.googletagservices.com/tag/js/gpt.js');
define('DFP_GOOGLE_SHORT_TAG_SERVICES_URL', 'pubads.g.doubleclick.net/gampad');
define('DFP_TOKEN_CACHE', 'dfp:tag_token_results');
function dfp_help($path, $arg) {
switch ($path) {
case 'admin/help#dfp':
$output = '<p>' . t('The Doubleclick For Publishers (DFP) module allows you to integrate Google Publisher Tags onto your site.') . '</p>';
$output .= '<p>' . t('This module provides you with a general settings form as well as the ability to create a tag (with all its associated data) in the database. You can display your ads as blocks, or add a simple bit of php to your tpl.php file(s) within your theme to indicate where specific tags should be displayed.') . '</p>';
return $output;
}
}
function dfp_permission() {
return array(
'administer DFP' => array(
'title' => t('Administer Doubleclick for Publisher ads'),
'description' => t('Users can create, edit, and delete Doubleclick for Publishers (dfp) ad tags and configure how and when they should be displayed.'),
'restrict access' => TRUE,
),
);
}
function dfp_theme($existing, $type, $theme, $path) {
$theme_hooks = array(
'dfp_tag' => array(
'variables' => array(
'tag' => NULL,
'slug' => NULL,
),
'template' => 'theme/dfp_tag',
),
'dfp_short_tag' => array(
'variables' => array(
'tag' => NULL,
),
'template' => 'theme/dfp_short_tag',
),
'dfp_target_settings' => array(
'render element' => 'form',
'file' => 'dfp.admin.inc',
),
'dfp_breakpoint_settings' => array(
'render element' => 'form',
'file' => 'dfp.admin.inc',
),
'dfp_adsense_color_settings' => array(
'render element' => 'form',
'file' => 'dfp.admin.inc',
),
'dfp_size_settings' => array(
'render element' => 'form',
'file' => 'dfp.admin.inc',
),
);
return $theme_hooks;
}
function dfp_menu() {
$items = array();
$items['admin/structure/dfp_ads/settings'] = array(
'title' => 'Global DFP Settings',
'type' => MENU_LOCAL_TASK,
'description' => "Configure your site-wide DFP settings.",
'page callback' => 'drupal_get_form',
'page arguments' => array(
'dfp_admin_settings',
),
'access arguments' => array(
'administer DFP',
),
'file' => 'dfp.admin.inc',
'weight' => 5,
);
$items['admin/structure/dfp_ads/test_page'] = array(
'title' => 'DFP Test Page',
'type' => MENU_LOCAL_TASK,
'description' => "View all your DFP tags on a single page",
'page callback' => 'dfp_adtest_page',
'access arguments' => array(
'administer DFP',
),
'file' => 'dfp.adtest.inc',
'weight' => 10,
);
return $items;
}
function dfp_menu_alter(&$items) {
$items['admin/structure/dfp_ads/list/%ctools_export_ui/edit']['context'] = MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE;
$items['admin/structure/dfp_ads/list/%ctools_export_ui/edit']['title'] = t('Edit DFP ad tag');
}
function dfp_block_info() {
$tags = dfp_tag_load_all();
$blocks = array();
$hashes = array();
foreach ($tags as $tag) {
if ($tag->block) {
if (drupal_strlen($tag->machinename) >= 32) {
$delta = md5($tag->machinename);
$hashes[$delta] = $tag->machinename;
}
else {
$delta = $tag->machinename;
}
$blocks[$delta]['info'] = t('DFP tag: @slotname', array(
'@slotname' => $tag->slot,
));
$blocks[$delta]['cache'] = DRUPAL_CACHE_PER_PAGE;
}
}
$old_hashes = variable_get('dfp_block_hashes', array());
if ($hashes != $old_hashes) {
variable_set('dfp_block_hashes', $hashes);
}
return $blocks;
}
function dfp_block_view($delta) {
$block = array();
if (drupal_strlen($delta) == 32) {
$hashes = variable_get('dfp_block_hashes', array());
if (!empty($hashes[$delta])) {
$delta = $hashes[$delta];
}
}
$tag = dfp_tag_load($delta);
if (empty($tag->disabled)) {
$block['title'] = NULL;
$block['content'] = dfp_tag($delta);
$block['content']['#contextual_links'] = array(
'dfp' => array(
'admin/structure/dfp_ads/list',
array(
$delta,
'edit',
),
),
);
}
return $block;
}
function dfp_entity_view($entity, $type, $view_mode, $langcode) {
$dfp_targeting_terms =& drupal_static('dfp_entity_targeting_terms', array());
if (variable_get('dfp_enable_ad_categories', 0) && $view_mode == 'full') {
if ($type == 'taxonomy_term') {
$dfp_targeting_terms[] = _dfp_get_ad_category($entity, TRUE);
}
foreach (element_children($entity->content) as $key) {
if (isset($entity->content[$key]['#field_type']) && $entity->content[$key]['#field_type'] == 'taxonomy_term_reference') {
$terms = field_view_field($type, $entity, $key);
if (isset($terms['#items']) && is_array($terms['#items'])) {
foreach ($terms['#items'] as $item) {
if (array_key_exists('taxonomy_term', $item)) {
$dfp_targeting_terms[] = _dfp_get_ad_category($item['taxonomy_term'], TRUE);
}
}
}
}
}
$dfp_targeting_terms = array_unique($dfp_targeting_terms);
}
}
function dfp_ctools_plugin_directory($module, $type) {
if ($type == 'export_ui' || $type == 'content_types') {
return 'plugins/' . $type;
}
}
function dfp_context_registry() {
return array(
'reactions' => array(
'dfp_tags' => array(
'title' => t('DFP Tags'),
'plugin' => 'dfp_context_reaction_tags',
),
'dfp_outofpage' => array(
'title' => t('DFP Out of page'),
'plugin' => 'dfp_context_reaction_outofpage',
),
'dfp_settings' => array(
'title' => t('DFP Variables'),
'plugin' => 'dfp_context_reaction_settings',
),
'dfp_adunit' => array(
'title' => t('DFP AdUnit'),
'plugin' => 'dfp_context_reaction_adunit',
),
'dfp_adsize' => array(
'title' => t('DFP Sizes'),
'plugin' => 'dfp_context_reaction_sizes',
),
),
);
}
function dfp_context_plugins() {
$plugins = array();
$plugins['dfp_context_reaction_tags'] = array(
'handler' => array(
'path' => drupal_get_path('module', 'dfp') . '/plugins/contexts',
'file' => 'dfp_context_reaction_tags.inc',
'class' => 'dfp_context_reaction_tags',
'parent' => 'context_reaction',
),
);
$plugins['dfp_context_reaction_outofpage'] = array(
'handler' => array(
'path' => drupal_get_path('module', 'dfp') . '/plugins/contexts',
'file' => 'dfp_context_reaction_outofpage.inc',
'class' => 'dfp_context_reaction_outofpage',
'parent' => 'context_reaction',
),
);
$plugins['dfp_context_reaction_settings'] = array(
'handler' => array(
'path' => drupal_get_path('module', 'dfp') . '/plugins/contexts',
'file' => 'dfp_context_reaction_settings.inc',
'class' => 'dfp_context_reaction_settings',
'parent' => 'context_reaction',
),
);
$plugins['dfp_context_reaction_adunit'] = array(
'handler' => array(
'path' => drupal_get_path('module', 'dfp') . '/plugins/contexts',
'file' => 'dfp_context_reaction_adunit.inc',
'class' => 'dfp_context_reaction_adunit',
'parent' => 'context_reaction',
),
);
$plugins['dfp_context_reaction_sizes'] = array(
'handler' => array(
'path' => drupal_get_path('module', 'dfp') . '/plugins/contexts',
'file' => 'dfp_context_reaction_sizes.inc',
'class' => 'dfp_context_reaction_sizes',
'parent' => 'context_reaction',
),
);
return $plugins;
}
function dfp_token_info() {
$type = array(
'name' => t('DFP Ad Tags'),
'description' => t('Tokens related to a given DFP ad tag.'),
'needs-data' => 'tag',
);
$tag['slot'] = array(
'name' => t('Slot Name'),
'description' => t("The name of the ad slot defined by this tag."),
);
$tag['network_id'] = array(
'name' => t("Network ID"),
'description' => t("The unique ID provided by Google."),
);
$tag['ad_categories'] = array(
'name' => t("DFP Ad Categories"),
'description' => t("The DFP Ad Categories or uncategorized taxonomy terms attached to the entities currently being displayed to the user."),
);
$tag['url_parts'] = array(
'name' => t("URL Parts (n)"),
'description' => t('**Deprecated. See <a href="http://drupal.org/node/1812372" target="_blank">this issue<a> for alternitives.'),
);
return array(
'types' => array(
'dfp_tag' => $type,
),
'tokens' => array(
'dfp_tag' => $tag,
),
);
}
function dfp_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();
if ($type == 'dfp_tag') {
foreach ($tokens as $name => $original) {
switch ($name) {
case 'slot':
if (!empty($data['tag'])) {
$replacements[$original] = check_plain($data['tag']->slot);
}
break;
case 'network_id':
$replacements[$original] = check_plain(variable_get('dfp_network_id', ''));
break;
case 'ad_categories':
$term_names =& drupal_static('dfp_entity_targeting_terms', array());
$replacements[$original] = implode(',', $term_names);
break;
}
}
if ($created_tokens = token_find_with_prefix($tokens, 'url_parts')) {
foreach ($created_tokens as $name => $original) {
$url_parts = explode('/', $_GET['q']);
$replacements[$original] = implode('/', array_slice($url_parts, 0, $name));
}
}
}
return $replacements;
}
function dfp_preprocess_html($variables) {
_dfp_js_global_settings();
}
function dfp_tag($machinename) {
$tag = dfp_tag_load($machinename);
$render_array = array();
if (!$tag) {
watchdog('dfp', 'Unknown ad tag %machinename passed to dfp_tag().', array(
'%machinename' => $machinename,
), WATCHDOG_WARNING);
}
else {
$tag->slug = dfp_format_slug($tag->slug);
$slug_placement = variable_get('dfp_slug_placement', 0);
if (!empty($tag)) {
$render_array = array(
'dfp_wrapper' => array(
'#type' => 'container',
'#attributes' => array(
'id' => $tag->wrapper_id,
'class' => array(
'dfp-tag-wrapper',
),
),
'tag' => array(
'#theme' => $tag->short_tag ? 'dfp_short_tag' : 'dfp_tag',
'#tag' => $tag,
),
),
);
if (!empty($tag->slug) && $slug_placement == 0) {
$render_array['dfp_wrapper']['slug_wrapper'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'slug',
),
),
'slug' => array(
'#markup' => check_plain($tag->slug),
),
'#weight' => -1,
);
}
}
}
return $render_array;
}
function dfp_tag_load($machinename) {
ctools_include('export');
$tags =& drupal_static(__FUNCTION__, array());
if (!isset($tags[$machinename])) {
$result = ctools_export_load_object('dfp_tags', 'names', array(
$machinename,
));
if (isset($result[$machinename])) {
$tag = $result[$machinename];
}
else {
return NULL;
}
$tag->raw = clone $tag;
drupal_alter('dfp_tag_load', $tag);
foreach ($tag->settings as $key => $val) {
$tag->{$key} = $val;
}
$tag->wrapper_id = 'dfp-ad-' . $tag->machinename . '-wrapper';
$tag->placeholder_id = 'dfp-ad-' . $tag->machinename;
drupal_alter('dfp_tag', $tag);
$tags[$machinename] = $tag;
}
else {
$tag = $tags[$machinename];
}
return $tag;
}
function dfp_tag_load_all($include_disabled = FALSE) {
ctools_include('export');
$tags = ctools_export_crud_load_all('dfp_tags');
foreach ($tags as $key => $tag) {
if (!$include_disabled && isset($tag->disabled) && $tag->disabled) {
unset($tags[$key]);
}
}
return $tags;
}
function dfp_tag_save(&$tag) {
$update = isset($tag->adid) && is_numeric($tag->adid) ? array(
'adid',
) : array();
return drupal_write_record('dfp_tags', $tag, $update);
}
function dfp_dfp_tag_load_alter(&$tag) {
if (module_exists('context')) {
$contexts = dfp_context_registry();
foreach ($contexts['reactions'] as $key => $val) {
if ($plugin = context_get_plugin('reaction', $key)) {
$plugin
->execute($tag);
}
}
}
module_load_include('inc', 'dfp', 'dfp.adtest');
dfp_adtest_alter_tag($tag);
}
function dfp_exportable_scheduler_form_group_alter(&$group) {
$group = 'settings';
}
function dfp_form_ctools_export_ui_edit_item_form_alter(&$form, &$form_state) {
if (arg(2) == 'context') {
form_load_include($form_state, 'inc', 'dfp', 'dfp.admin');
}
}
function dfp_format_targeting($targeting, $tag = '') {
foreach ($targeting as $key => &$target) {
$target['target'] = '"' . check_plain($target['target']) . '"';
$target['value'] = dfp_token_replace(check_plain($target['value']), $tag, array(
'sanitize' => TRUE,
'clear' => TRUE,
));
drupal_alter('dfp_target', $target);
if (empty($target['value'])) {
unset($targeting[$key]);
continue;
}
$values = explode(',', $target['value']);
$values = array_map('trim', $values);
if (count($values) == 1) {
$target['value'] = '"' . $values[0] . '"';
}
elseif (count($values) > 1) {
$target['value'] = '["' . implode('","', $values) . '"]';
}
}
return $targeting;
}
function dfp_format_size($size) {
$formatted_sizes = array();
$sizes = explode(',', check_plain($size));
foreach ($sizes as $size) {
$formatted_size = explode('x', trim($size));
$formatted_sizes[] = '[' . implode(', ', $formatted_size) . ']';
}
return count($formatted_sizes) == 1 ? $formatted_sizes[0] : '[' . implode(', ', $formatted_sizes) . ']';
}
function dfp_format_slug($slug) {
$formatted_slug = variable_get('dfp_default_slug', '');
if ($slug == '<none>') {
$formatted_slug = "";
}
elseif (!empty($slug)) {
$formatted_slug = $slug;
}
return $formatted_slug;
}
function _dfp_get_ad_category($term, $clean_string = FALSE) {
if (!empty($term->field_dfp_ad_categories)) {
$term = taxonomy_term_load($term->field_dfp_ad_categories[LANGUAGE_NONE][0]['tid']);
}
$term_name = $term->name;
if ($clean_string) {
ctools_include('cleanstring');
$term_name = ctools_cleanstring($term_name, array(
'lower_case' => TRUE,
));
}
return $term->name;
}
function _dfp_js_global_settings() {
$js = 'var googletag = googletag || {};' . "\n";
$js .= 'googletag.cmd = googletag.cmd || [];';
$js .= variable_get('dfp_injected_js', '') . "\n";
$js .= 'googletag.slots = googletag.slots || {};';
$options = array(
'type' => 'inline',
'group' => JS_LIBRARY,
'every_page' => TRUE,
'weight' => -10,
'force header' => TRUE,
'scope_lock' => TRUE,
);
drupal_add_js($js, $options);
$options['type'] = 'external';
$options['weight']++;
drupal_add_js("//" . DFP_GOOGLE_TAG_SERVICES_URL, $options);
$js = 'googletag.cmd.push(function() {' . "\n";
if (variable_get('dfp_async_rendering', 1)) {
$js .= ' googletag.pubads().enableAsyncRendering();' . "\n";
}
else {
$js .= ' googletag.pubads().enableSyncRendering();' . "\n";
}
if (variable_get('dfp_single_request', 1)) {
$js .= ' googletag.pubads().enableSingleRequest();' . "\n";
}
switch (variable_get('dfp_collapse_empty_divs', 1)) {
case 1:
$js .= ' googletag.pubads().collapseEmptyDivs();' . "\n";
break;
case 2:
$js .= ' googletag.pubads().collapseEmptyDivs(true);' . "\n";
break;
}
if (variable_get('dfp_disable_init_load', 0)) {
$js .= ' googletag.pubads().disableInitialLoad();' . "\n";
}
if (variable_get('dfp_set_centering', 0)) {
$js .= ' googletag.pubads().setCentering(true);' . "\n";
}
$targeting = variable_get('dfp_targeting', array());
drupal_alter('dfp_global_targeting', $targeting);
$targeting = dfp_format_targeting($targeting);
foreach ($targeting as $key => $target) {
if (!empty($target['target']) && !empty($target['value'])) {
$js .= ' googletag.pubads().setTargeting(' . $target['target'] . ', ' . $target['value'] . ');' . "\n";
}
}
$js .= '});' . "\n";
$js .= variable_get('dfp_injected_js2', '') . "\n";
$js .= 'googletag.enableServices();';
$options = array(
'type' => 'inline',
'group' => JS_DEFAULT,
'every_page' => TRUE,
'weight' => 10,
'force header' => TRUE,
'scope_lock' => TRUE,
);
drupal_add_js($js, $options);
}
function _dfp_js_slot_definition($tag) {
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;
}
$js = '';
if (!empty($tag->breakpoints)) {
$breakpoints = $tag->breakpoints;
$js .= 'var mapping = googletag.sizeMapping()' . "\n";
foreach ($breakpoints as $breakpoint) {
$ad_sizes = strpos($breakpoint['ad_sizes'], '<none>') !== FALSE ? '' : $breakpoint['ad_sizes'];
$js .= ' .addSize(' . dfp_format_size($breakpoint['browser_size']) . ', ' . dfp_format_size($ad_sizes) . ')' . "\n";
}
$js .= ' .build();' . "\n";
}
if (!empty($tag->settings['out_of_page'])) {
$js .= 'googletag.slots["' . $tag->machinename . '"] = googletag.defineOutOfPageSlot("' . $tag->adunit . '", "' . $tag->placeholder_id . '")' . "\n";
}
else {
$js .= 'googletag.slots["' . $tag->machinename . '"] = googletag.defineSlot("' . $tag->adunit . '", ' . $tag->size . ', "' . $tag->placeholder_id . '")' . "\n";
}
$click_url = variable_get('dfp_click_url', '');
if (!empty($click_url)) {
$js .= ' .setClickUrl("' . url($click_url, array(
'absolute' => TRUE,
)) . '")' . "\n";
}
$js .= ' .addService(googletag.pubads())' . "\n";
if (!empty($tag->adsense_ad_types)) {
$js .= ' .set("adsense_ad_types", "' . $tag->adsense_ad_types . '")' . "\n";
}
if (!empty($tag->adsense_channel_ids)) {
$js .= ' .set("adsense_channel_ids", "' . $tag->adsense_channel_ids . '")' . "\n";
}
foreach ($tag->adsense_colors as $key => $val) {
if (!empty($val)) {
$key = 'adsense_' . $key . '_color';
$val = '#' . drupal_strtoupper($val);
$js .= ' .set("' . $key . '", "' . $val . '")' . "\n";
}
}
$targeting = dfp_format_targeting($tag->targeting, $tag);
foreach ($targeting as $target) {
$js .= ' .setTargeting(' . $target['target'] . ', ' . $target['value'] . ')' . "\n";
}
if (!empty($tag->breakpoints)) {
$js .= ' .defineSizeMapping(mapping)' . "\n";
}
$js = rtrim($js, "\n") . ';';
$options = array(
'type' => 'inline',
'group' => JS_LIBRARY,
'weight' => 0,
'force header' => TRUE,
'scope_lock' => TRUE,
);
drupal_add_js($js, $options);
}
function _dfp_prepare_tokens($tag = NULL) {
global $user;
$data = array();
$data['user'] = $user;
$data['node'] = menu_get_object();
$data['term'] = arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2)) ? taxonomy_term_load(arg(2)) : NULL;
if (!empty($tag)) {
$data['tag'] = $tag;
}
return $data;
}
function _dfp_prepare_adunit($tag) {
$global_adunit = variable_get('dfp_default_adunit', '');
if (empty($tag->adunit) && !empty($global_adunit)) {
$tag->adunit = $global_adunit;
}
return $tag;
}
function dfp_token_replace($text, $tag = NULL, array $options = array()) {
$text_tokens = token_scan($text);
if (empty($text_tokens)) {
return $text;
}
$data = _dfp_prepare_tokens($tag);
$dfp_token_cache_enabled = variable_get('dfp_token_cache_enabled', TRUE);
if ($dfp_token_cache_enabled && function_exists('entity_modified_last')) {
$replacement = _dfp_token_replace_cache($text, $data, $options);
}
else {
$replacement = token_replace($text, $data, $options);
}
return $replacement;
}
function _dfp_token_replace_cache($text, $data, array $options = array()) {
$processed_strings =& drupal_static(__FUNCTION__, NULL);
$key = _dfp_token_replace_make_key($text, $data);
$cache_item = DFP_TOKEN_CACHE . ':' . implode(':', drupal_render_cid_parts(DRUPAL_CACHE_PER_PAGE));
if (is_null($processed_strings)) {
$cache = cache_get($cache_item, 'cache');
$processed_strings = $cache ? $cache->data : array();
}
if (!isset($processed_strings[$key]) || is_null($processed_strings[$key])) {
$processed_strings[$key] = token_replace($text, $data, $options);
$lifetime = variable_get('dfp_token_cache_lifetime', 0);
$expire_at = $lifetime == 0 ? CACHE_TEMPORARY : REQUEST_TIME + $lifetime;
cache_set($cache_item, $processed_strings, 'cache', $expire_at);
}
return $processed_strings[$key];
}
function _dfp_token_replace_make_key($text, array $data) {
$keys[] = sha1($text);
$keys[] = isset($data['node']->nid) ? $data['node']->nid . '-' . entity_modified_last('node', $data['node']) : NULL;
$keys[] = isset($data['user']->uid) ? $data['user']->uid . '-' . entity_modified_last('user', $data['user']) : NULL;
$keys[] = isset($data['term']->tid) ? $data['term']->tid . '-' . entity_modified_last('taxonomy_term', $data['term']) : NULL;
$keys[] = isset($data['tag']->machinename) ? $data['tag']->machinename . '-' . entity_modified_last('tag', $data['tag']) : NULL;
return implode('|', array_filter($keys));
}
function template_preprocess_dfp_tag(&$variables) {
$tag = $variables['tag'];
$tag = _dfp_prepare_adunit($tag);
$slug_placement = variable_get('dfp_slug_placement', 0);
$tag->adunit = dfp_token_replace('[dfp_tag:network_id]/' . $tag->adunit, $tag, array(
'sanitize' => TRUE,
'clear' => TRUE,
));
$tag->size = dfp_format_size($tag->size);
$tag->slug = dfp_format_slug($tag->slug);
$variables['placeholder_attributes'] = array(
'id' => $tag->placeholder_id,
'class' => array(
'dfp-tag-wrapper',
),
);
if (!empty($tag->slug) && $slug_placement == 1) {
$variables['slug'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'slug',
),
),
'slug' => array(
'#markup' => check_plain($tag->slug),
),
'#weight' => -1,
);
}
_dfp_js_slot_definition($tag);
$variables['tag']->processed = TRUE;
}
function template_preprocess_dfp_short_tag(&$variables) {
static $tile = 0;
$tag = $variables['tag'];
$tag = _dfp_prepare_adunit($tag);
$keyvals = array();
$keyvals['iu'] = dfp_token_replace('/[dfp_tag:network_id]/' . $tag->adunit, $tag, array(
'sanitize' => TRUE,
'clear' => TRUE,
));
$keyvals['sz'] = str_replace(',', '|', check_plain($tag->raw->size));
$keyvals['c'] = rand(10000, 99999);
$targets = array();
foreach ($tag->targeting as $data) {
$targets[] = check_plain($data['target']) . '=' . check_plain($data['value']);
}
if (!empty($targets)) {
$keyvals['t'] = implode('&', $targets);
}
drupal_alter('dfp_short_tag_keyvals', $keyvals);
$variables['url_jump'] = 'http://' . DFP_GOOGLE_SHORT_TAG_SERVICES_URL . '/jump?' . drupal_http_build_query($keyvals);
$variables['url_ad'] = 'http://' . DFP_GOOGLE_SHORT_TAG_SERVICES_URL . '/ad?' . drupal_http_build_query($keyvals);
}
function dfp_page_build(&$page) {
$html = '';
$tags = dfp_tag_load_all();
foreach ($tags as $tag) {
if (isset($tag->settings['out_of_page']) && $tag->settings['out_of_page'] == TRUE) {
drupal_alter('dfp_tag_load', $tag);
}
}
if (module_exists('context')) {
if ($plugin = context_get_plugin('reaction', 'dfp_outofpage')) {
if (isset($plugin->out_of_page_tags)) {
foreach ($plugin->out_of_page_tags as $key => $machinename) {
$tag = dfp_tag_load($machinename);
if (empty($tag->disabled)) {
$dfp_tag = dfp_tag($machinename);
$dfp_tag['dfp_wrapper']['#attributes']['class'][] = 'element-hidden';
$html .= render($dfp_tag);
}
}
}
}
}
$page['page_top']['dfp_out_of_page'] = array(
'#weight' => -1000,
'#markup' => $html,
);
}