You are here

adsense_oldcode.module in Google AdSense integration 8

Displays Google AdSense ads on Drupal pages using the pre-2007 code.

These ad codes were deprecated by Google in 2007, and even though they still seem to work, their use is not recommended.

File

oldcode/adsense_oldcode.module
View source
<?php

/**
 * @file
 * Displays Google AdSense ads on Drupal pages using the pre-2007 code.
 *
 * These ad codes were deprecated by Google in 2007, and even though they still
 * seem to work, their use is not recommended.
 */

// @codingStandardsIgnoreStart DrupalPractice.Constants.GlobalDefine.GlobalConstant
// Ad channel defaults.
define('ADSENSE_OLDCODE_MAX_CHANNELS', 10);
define('ADSENSE_OLDCODE_MAX_GROUPS', 5);
define('ADSENSE_OLDCODE_AD_CHANNEL_DEFAULT', '');

// Ad types, link or ad.
define('ADSENSE_OLDCODE_TYPE_LINK', 1);

// Deprecated by Google.
define('ADSENSE_OLDCODE_TYPE_AD', 2);

// @codingStandardsIgnoreEnd

/**
 * Implements hook_theme().
 */
function adsense_oldcode_theme() {
  return [
    'adsense_oldcode' => [
      'variables' => [
        'client' => '',
        'alt_url' => '',
        'alt_color' => '',
        'width' => '',
        'height' => '',
        'format' => '',
        'type' => '',
        'channel' => '',
        'border' => '',
        'bg' => '',
        'link' => '',
        'text' => '',
        'url' => '',
        'features' => '',
        'secret' => '',
      ],
    ],
    'adsense_oldsearch_form' => [
      'variables' => [
        'theme' => '',
        'country' => '',
        'bg_color' => '',
        'logo' => '',
        'logo_color' => '',
        'hidden_q' => FALSE,
        'domain' => '',
        'qsize' => '',
        'search_button' => '',
        'btn' => '',
        'box_text_color' => '',
        'domain_0' => '',
        'domain_1' => '',
        'domain_2' => '',
        'client' => '',
        'channel' => '',
        'encoding' => '',
        'safe_mode' => '',
        'url' => '',
        'border' => '',
        'visited' => '',
        'bg' => '',
        'logobg' => '',
        'title' => '',
        'text' => '',
        'light' => '',
        'language' => '',
      ],
    ],
  ];
}

/**
 * Implements hook_preprocess_block().
 */
function adsense_oldcode_preprocess_block(&$variables) {

  // Remove adsense from the block id and classes to bypass adblock rules.
  if ($variables['configuration']['provider'] == 'adsense_oldcode' && \Drupal::config('adsense.settings')
    ->get('adsense_unblock_ads')) {
    $variables['plugin_id'] = str_replace('adsense', '', $variables['plugin_id']);
    $variables['configuration']['provider'] = '';
  }
}