class OldCodeAd in Google AdSense integration 8
Provides an AdSense old code ad unit.
Plugin annotation
@AdsenseAd(
id = "oldcode",
name = @Translation("Old code ads"),
isSearch = FALSE,
needsSlot = FALSE
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\adsense\AdsenseAdBase implements AdsenseAdInterface, ContainerFactoryPluginInterface uses StringTranslationTrait
- class \Drupal\adsense\ContentAdBase
- class \Drupal\adsense_oldcode\Plugin\AdsenseAd\OldCodeAd
- class \Drupal\adsense\ContentAdBase
- class \Drupal\adsense\AdsenseAdBase implements AdsenseAdInterface, ContainerFactoryPluginInterface uses StringTranslationTrait
Expanded class hierarchy of OldCodeAd
File
- oldcode/
src/ Plugin/ AdsenseAd/ OldCodeAd.php, line 18
Namespace
Drupal\adsense_oldcode\Plugin\AdsenseAdView source
class OldCodeAd extends ContentAdBase {
/**
* Ad style (key to configured styles).
*
* @var int
*/
private $style;
/**
* Ad Channel.
*
* @var string
*/
private $channel;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id = '', $plugin_definition = NULL, $config_factory = NULL, $module_handler = NULL, $current_user = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $config_factory, $module_handler, $current_user);
$fo = !empty($configuration['format']) ? $configuration['format'] : '';
$st = !empty($configuration['style']) ? $configuration['style'] : 1;
$ch = !empty($configuration['channel']) ? $configuration['channel'] : '';
if ($st < 1 || $st > ADSENSE_OLDCODE_MAX_GROUPS) {
// Default to 1 if an invalid style is supplied.
$st = 1;
}
if (substr($fo, 0, 10) != 'Search Box' && !empty($fo)) {
$this->format = $fo;
$this->style = $st;
$this->channel = $ch;
}
}
/**
* {@inheritdoc}
*/
public function getAdPlaceholder() {
if (!empty($this->format)) {
$client = PublisherId::get();
// Get width and height from the format.
list($width, $height) = $this
->dimensions($this->format);
$content = $this->configFactory
->get('adsense.settings')
->get('adsense_placeholder_text');
$content .= "\nclient = {$client}\nformat = {$this->format}\nwidth = {$width}\nheight = {$height}\nstyle = {$this->style}\nchannel = {$this->channel}";
return [
'#content' => [
'#markup' => nl2br($content),
],
'#format' => $this->format,
'#width' => $width,
'#height' => $height,
];
}
return [];
}
/**
* {@inheritdoc}
*/
public function getAdContent() {
if (!empty($this->format)) {
$ad = $this
->adsenseAdFormats($this->format);
if ($ad != NULL) {
$core_config = $this->configFactory
->get('adsense.settings');
$oldcode_config = $this->configFactory
->get('adsense_oldcode.settings');
$client = PublisherId::get();
$this->moduleHandler
->alter('adsense', $client);
// Get width and height from the format.
list($width, $height) = $this
->dimensions($this->format);
switch ($oldcode_config
->get('adsense_ad_type_' . $this->style)) {
case 0:
$type = 'text';
break;
case 1:
$type = 'image';
break;
default:
$type = 'text_image';
break;
}
$alt = $oldcode_config
->get('adsense_alt_' . $this->style);
$alt_info = $oldcode_config
->get('adsense_alt_info_' . $this->style);
return [
'#theme' => 'adsense_oldcode',
'#client' => $client,
'#alt_url' => $alt == 1 ? $alt_info : '',
'#alt_color' => $alt == 2 ? $alt_info : '',
'#width' => $width,
'#height' => $height,
'#format' => $ad['code'],
'#type' => $ad['type'] == ADSENSE_OLDCODE_TYPE_AD ? $type : '',
'#channel' => $oldcode_config
->get('adsense_ad_channel_' . $this->channel),
'#border' => mb_substr($oldcode_config
->get('adsense_color_border_' . $this->style), 1),
'#bg' => mb_substr($oldcode_config
->get('adsense_color_bg_' . $this->style), 1),
'#link' => mb_substr($oldcode_config
->get('adsense_color_link_' . $this->style), 1),
'#text' => mb_substr($oldcode_config
->get('adsense_color_text_' . $this->style), 1),
'#url' => mb_substr($oldcode_config
->get('adsense_color_url_' . $this->style), 1),
'#features' => $oldcode_config
->get('adsense_ui_features_' . $this->style),
'#secret' => $core_config
->get('adsense_secret_language'),
];
}
}
return [];
}
/**
* {@inheritdoc}
*/
public static function adsenseAdFormats($key = NULL) {
$ads = [
// Top performing ad sizes.
'300x250' => [
'type' => ADSENSE_OLDCODE_TYPE_AD,
'desc' => t('Medium Rectangle'),
'code' => '300x250_as',
],
'336x280' => [
'type' => ADSENSE_OLDCODE_TYPE_AD,
'desc' => t('Large Rectangle'),
'code' => '336x280_as',
],
'728x90' => [
'type' => ADSENSE_OLDCODE_TYPE_AD,
'desc' => t('Leaderboard'),
'code' => '728x90_as',
],
// Other supported ad sizes.
'468x60' => [
'type' => ADSENSE_OLDCODE_TYPE_AD,
'desc' => t('Banner'),
'code' => '468x60_as',
],
'234x60' => [
'type' => ADSENSE_OLDCODE_TYPE_AD,
'desc' => t('Half Banner'),
'code' => '234x60_as',
],
'120x600' => [
'type' => ADSENSE_OLDCODE_TYPE_AD,
'desc' => t('Skyscraper'),
'code' => '120x600_as',
],
'120x240' => [
'type' => ADSENSE_OLDCODE_TYPE_AD,
'desc' => t('Vertical Banner'),
'code' => '120x240_as',
],
'160x600' => [
'type' => ADSENSE_OLDCODE_TYPE_AD,
'desc' => t('Wide Skyscraper'),
'code' => '160x600_as',
],
'250x250' => [
'type' => ADSENSE_OLDCODE_TYPE_AD,
'desc' => t('Square'),
'code' => '250x250_as',
],
'200x200' => [
'type' => ADSENSE_OLDCODE_TYPE_AD,
'desc' => t('Small Square'),
'code' => '200x200_as',
],
'180x150' => [
'type' => ADSENSE_OLDCODE_TYPE_AD,
'desc' => t('Small Rectangle'),
'code' => '180x150_as',
],
'125x125' => [
'type' => ADSENSE_OLDCODE_TYPE_AD,
'desc' => t('Button'),
'code' => '125x125_as',
],
];
if (!empty($key)) {
return array_key_exists($key, $ads) ? $ads[$key] : NULL;
}
else {
return $ads;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AdsenseAdBase:: |
protected | property | Config factory. | |
AdsenseAdBase:: |
protected | property | Current user. | |
AdsenseAdBase:: |
protected | property | Module handler. | |
AdsenseAdBase:: |
public static | function |
List of available languages. Overrides AdsenseAdInterface:: |
|
AdsenseAdBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
AdsenseAdBase:: |
public static | function |
Creates the ad object, as specified by the definitions in the parameter. Overrides AdsenseAdInterface:: |
|
AdsenseAdBase:: |
public | function | Display ad HTML. | |
AdsenseAdBase:: |
public static | function | Check if ads display is disabled. | |
ContentAdBase:: |
protected | property | Ad Format. | |
ContentAdBase:: |
public static | function | Provides the width and height of the ad. | |
ContentAdBase:: |
public | function | Gets the ad format. | |
OldCodeAd:: |
private | property | Ad Channel. | |
OldCodeAd:: |
private | property | Ad style (key to configured styles). | |
OldCodeAd:: |
public static | function |
This is the array that holds all ad formats. Overrides AdsenseAdInterface:: |
|
OldCodeAd:: |
public | function |
Return the ad content. Overrides AdsenseAdInterface:: |
|
OldCodeAd:: |
public | function |
Return the ad placeholder. Overrides AdsenseAdInterface:: |
|
OldCodeAd:: |
public | function |
Creates a new AdsenseAdBase instance. Overrides AdsenseAdBase:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |