Commit 5790eb62 authored by João Ventura's avatar João Ventura
Browse files

Issue #3004896: Remove limit-checking code as Google lifted their per-page ad limits

parent 883dde74
Loading
Loading
Loading
Loading
+0 −6
Changes for adsense.module: 0 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -14,12 +14,6 @@ use Drupal\adsense\AdsenseAdBase;
use Drupal\adsense\ContentAdBase;
use Drupal\adsense\PublisherId;

// Ad types, link or ad.
define('ADSENSE_TYPE_LINK', 1);
define('ADSENSE_TYPE_AD', 2);
define('ADSENSE_TYPE_SEARCH', 3);
define('ADSENSE_TYPE_MATCHED', 4);

/**
 * Implements hook_page_attachments().
 */
+4 −0
Changes for oldcode/adsense_oldcode.module: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -13,6 +13,10 @@ 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);
define('ADSENSE_OLDCODE_TYPE_AD', 2);

/**
 * Implements hook_theme().
 */
+25 −28
Changes for oldcode/src/Plugin/AdsenseAd/OldCodeAd.php: 25 added lines, 28 removed lines.
Original line number Diff line number Diff line
@@ -51,9 +51,6 @@ class OldCodeAd extends ContentAdBase {
      $this->format = $fo;
      $this->style = $st;
      $this->channel = $ch;

      $fmt = $this->adsenseAdFormats($fo);
      $this->type = $fmt['type'];
    }
    return parent::__construct($configuration, $plugin_id, $plugin_definition);
  }
@@ -121,7 +118,7 @@ class OldCodeAd extends ContentAdBase {
          '#width' => $width,
          '#height' => $height,
          '#format' => $ad['code'],
          '#type' => ($ad['type'] == ADSENSE_TYPE_AD) ? $type : '',
          '#type' => ($ad['type'] == ADSENSE_OLDCODE_TYPE_AD) ? $type : '',
          '#channel' => $oldcode_config->get('adsense_ad_channel_' . $this->channel),
          '#border' => Unicode::substr($oldcode_config->get('adsense_color_border_' . $this->style), 1),
          '#bg' => Unicode::substr($oldcode_config->get('adsense_color_bg_' . $this->style), 1),
@@ -143,125 +140,125 @@ class OldCodeAd extends ContentAdBase {
    $ads = [
      // Top performing ad sizes.
      '300x250' => [
        'type' => ADSENSE_TYPE_AD,
        'type' => ADSENSE_OLDCODE_TYPE_AD,
        'desc' => t('Medium Rectangle'),
        'code' => '300x250_as',
      ],
      '336x280' => [
        'type' => ADSENSE_TYPE_AD,
        'type' => ADSENSE_OLDCODE_TYPE_AD,
        'desc' => t('Large Rectangle'),
        'code' => '336x280_as',
      ],
      '728x90' => [
        'type' => ADSENSE_TYPE_AD,
        'type' => ADSENSE_OLDCODE_TYPE_AD,
        'desc' => t('Leaderboard'),
        'code' => '728x90_as',
      ],
      // Other supported ad sizes.
      '468x60' => [
        'type' => ADSENSE_TYPE_AD,
        'type' => ADSENSE_OLDCODE_TYPE_AD,
        'desc' => t('Banner'),
        'code' => '468x60_as',
      ],
      '234x60' => [
        'type' => ADSENSE_TYPE_AD,
        'type' => ADSENSE_OLDCODE_TYPE_AD,
        'desc' => t('Half Banner'),
        'code' => '234x60_as',
      ],
      '120x600' => [
        'type' => ADSENSE_TYPE_AD,
        'type' => ADSENSE_OLDCODE_TYPE_AD,
        'desc' => t('Skyscraper'),
        'code' => '120x600_as',
      ],
      '120x240' => [
        'type' => ADSENSE_TYPE_AD,
        'type' => ADSENSE_OLDCODE_TYPE_AD,
        'desc' => t('Vertical Banner'),
        'code' => '120x240_as',
      ],
      '160x600' => [
        'type' => ADSENSE_TYPE_AD,
        'type' => ADSENSE_OLDCODE_TYPE_AD,
        'desc' => t('Wide Skyscraper'),
        'code' => '160x600_as',
      ],
      '250x250' => [
        'type' => ADSENSE_TYPE_AD,
        'type' => ADSENSE_OLDCODE_TYPE_AD,
        'desc' => t('Square'),
        'code' => '250x250_as',
      ],
      '200x200' => [
        'type' => ADSENSE_TYPE_AD,
        'type' => ADSENSE_OLDCODE_TYPE_AD,
        'desc' => t('Small Square'),
        'code' => '200x200_as',
      ],
      '180x150' => [
        'type' => ADSENSE_TYPE_AD,
        'type' => ADSENSE_OLDCODE_TYPE_AD,
        'desc' => t('Small Rectangle'),
        'code' => '180x150_as',
      ],
      '125x125' => [
        'type' => ADSENSE_TYPE_AD,
        'type' => ADSENSE_OLDCODE_TYPE_AD,
        'desc' => t('Button'),
        'code' => '125x125_as',
      ],
      // 4-links.
      '120x90' => [
        'type' => ADSENSE_TYPE_LINK,
        'type' => ADSENSE_OLDCODE_TYPE_LINK,
        'desc' => t('4-links Vertical Small'),
        'code' => '120x90_0ads_al',
      ],
      '160x90' => [
        'type' => ADSENSE_TYPE_LINK,
        'type' => ADSENSE_OLDCODE_TYPE_LINK,
        'desc' => t('4-links Vertical Medium'),
        'code' => '160x90_0ads_al',
      ],
      '180x90' => [
        'type' => ADSENSE_TYPE_LINK,
        'type' => ADSENSE_OLDCODE_TYPE_LINK,
        'desc' => t('4-links Vertical Large'),
        'code' => '180x90_0ads_al',
      ],
      '200x90' => [
        'type' => ADSENSE_TYPE_LINK,
        'type' => ADSENSE_OLDCODE_TYPE_LINK,
        'desc' => t('4-links Vertical X-Large'),
        'code' => '200x90_0ads_al',
      ],
      '468x15' => [
        'type' => ADSENSE_TYPE_LINK,
        'type' => ADSENSE_OLDCODE_TYPE_LINK,
        'desc' => t('4-links Horizontal Medium'),
        'code' => '468x15_0ads_al',
      ],
      '728x15' => [
        'type' => ADSENSE_TYPE_LINK,
        'type' => ADSENSE_OLDCODE_TYPE_LINK,
        'desc' => t('4-links Horizontal Large'),
        'code' => '728x15_0ads_al',
      ],
      // 5-links.
      '120x90_5' => [
        'type' => ADSENSE_TYPE_LINK,
        'type' => ADSENSE_OLDCODE_TYPE_LINK,
        'desc' => t('5-links Vertical Small'),
        'code' => '120x90_0ads_al_s',
      ],
      '160x90_5' => [
        'type' => ADSENSE_TYPE_LINK,
        'type' => ADSENSE_OLDCODE_TYPE_LINK,
        'desc' => t('5-links Vertical Medium'),
        'code' => '160x90_0ads_al_s',
      ],
      '180x90_5' => [
        'type' => ADSENSE_TYPE_LINK,
        'type' => ADSENSE_OLDCODE_TYPE_LINK,
        'desc' => t('5-links Vertical Large'),
        'code' => '180x90_0ads_al_s',
      ],
      '200x90_5' => [
        'type' => ADSENSE_TYPE_LINK,
        'type' => ADSENSE_OLDCODE_TYPE_LINK,
        'desc' => t('5-links Vertical X-Large'),
        'code' => '200x90_0ads_al_s',
      ],
      '468x15_5' => [
        'type' => ADSENSE_TYPE_LINK,
        'type' => ADSENSE_OLDCODE_TYPE_LINK,
        'desc' => t('5-links Horizontal Medium'),
        'code' => '468x15_0ads_al_s',
      ],
      '728x15_5' => [
        'type' => ADSENSE_TYPE_LINK,
        'type' => ADSENSE_OLDCODE_TYPE_LINK,
        'desc' => t('5-links Horizontal Large'),
        'code' => '728x15_0ads_al_s',
      ],
+0 −1
Changes for oldcode/src/Plugin/AdsenseAd/OldSearchAd.php: 0 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ class OldSearchAd extends SearchAdBase {
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id = NULL, $plugin_definition = NULL) {
    $this->type = ADSENSE_TYPE_SEARCH;
    $ch = (!empty($configuration['channel'])) ? $configuration['channel'] : '';

    $this->channel = $ch;
+7 −52
Changes for src/AdsenseAdBase.php: 7 added lines, 52 removed lines.
Original line number Diff line number Diff line
@@ -11,13 +11,6 @@ use Drupal\Core\StringTranslation\StringTranslationTrait;
abstract class AdsenseAdBase extends PluginBase implements AdsenseAdInterface {
  use StringTranslationTrait;

  /**
   * Ad type.
   *
   * @var int
   */
  protected $type;

  /**
   * {@inheritdoc}
   */
@@ -55,9 +48,13 @@ abstract class AdsenseAdBase extends PluginBase implements AdsenseAdInterface {
    $text = '';

    if ($this->isDisabled($text)) {
    }
    elseif (!$this->canInsertAnother()) {
      $text = 'ad limit reached for type.';
      return [
        '#type' => 'inline_template',
        '#template' => '<!-- adsense: {{ comment }} -->',
        '#context' => [
          'comment' => $text,
        ],
      ];
    }
    elseif ($config->get('adsense_test_mode') || $account->hasPermission('show adsense placeholders')) {
      // Show ad placeholder.
@@ -90,14 +87,6 @@ abstract class AdsenseAdBase extends PluginBase implements AdsenseAdInterface {
        '#attached' => ['library' => $libraries],
      ];
    }

    return [
      '#type' => 'inline_template',
      '#template' => '<!-- adsense: {{ comment }} -->',
      '#context' => [
        'comment' => $text,
      ],
    ];
  }

  /**
@@ -128,40 +117,6 @@ abstract class AdsenseAdBase extends PluginBase implements AdsenseAdInterface {
    return TRUE;
  }

  /**
   * Check if another ad of this type can be inserted.
   *
   * @return bool
   *   TRUE if ad can be inserted.
   */
  public function canInsertAnother() {
    // Because of #1627846, it's better to always return TRUE.
    return TRUE;

    // @codingStandardsIgnoreStart
//    static $num_ads = [
//      ADSENSE_TYPE_AD      => 0,
//      ADSENSE_TYPE_LINK    => 0,
//      ADSENSE_TYPE_SEARCH  => 0,
//      ADSENSE_TYPE_MATCHED => 0,
//    ];
//
//    $max_ads = [
//      ADSENSE_TYPE_AD      => 3,
//      ADSENSE_TYPE_LINK    => 3,
//      ADSENSE_TYPE_SEARCH  => 2,
//      ADSENSE_TYPE_MATCHED => PHP_INT_MAX,
//    ];
//
//    if ($num_ads[$this->type] < $max_ads[$this->type]) {
//      $num_ads[$this->type]++;
//      return TRUE;
//    }
//
//    return FALSE;
    // @codingStandardsIgnoreEnd
  }

  /**
   * List of available languages.
   *
Loading