function _adsense_managed_get_ad in Google AdSense integration 7
Same name and namespace in other branches
- 5.3 managed/adsense_managed.module \_adsense_managed_get_ad()
- 6 managed/adsense_managed.module \_adsense_managed_get_ad()
Generates the AdSense ad.
Parameters
string $format: Format of the ad.
string $client: Publisher ID.
string $slot: Slot Id for the AdSense ad.
string $shape: Responsive ad shape.
string $layout_key: In-feed layout key.
Return value
string JavaScript that embeds the Google AdSense ad
1 call to _adsense_managed_get_ad()
- adsense_display in ./
adsense.module - Generates the Google AdSense Ad.
File
- managed/
adsense_managed.module, line 313 - Displays Google AdSense ads on Drupal pages.
Code
function _adsense_managed_get_ad($format, $client, $slot, $shape = 'auto', $layout_key = '') {
$ad = _adsense_dimensions($format);
if (empty($slot) || !_adsense_is_responsive($format) && !_adsense_is_fluid($format) && $ad === NULL) {
$output = "";
}
elseif (variable_get('adsense_test_mode', ADSENSE_TEST_MODE_DEFAULT)) {
$output = theme('adsense_placeholder', array(
'text' => "client = {$client}<br />slot = {$slot}<br />width = {$ad['width']}<br />height = {$ad['height']}<br />shape = {$shape}",
'width' => $ad['width'],
'height' => $ad['height'],
));
}
else {
if (_adsense_is_responsive($format)) {
$shape = $format == 'responsive' ? $shape : $format;
// Responsive smart sizing code.
$output = <<<MANAGED_RESP_TXT
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- {<span class="php-variable">$format</span>} -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-{<span class="php-variable">$client</span>}"
data-ad-slot="{<span class="php-variable">$slot</span>}"
data-ad-format="{<span class="php-variable">$shape</span>}"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
MANAGED_RESP_TXT;
}
elseif (_adsense_is_fluid($format)) {
$style = 'display:block';
$layout = '';
if (empty($layout_key)) {
// In-article.
$layout = 'data-ad-layout="' . $format . '"';
$style .= '; text-align:center;';
}
else {
// In-feed.
$layout_key = 'data-ad-layout-key="' . $layout_key . '"';
}
// Responsive smart sizing code.
$output = <<<MANAGED_FLUID_TXT
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- {<span class="php-variable">$format</span>} -->
<ins class="adsbygoogle"
style="{<span class="php-variable">$style</span>}"
{<span class="php-variable">$layout</span>}
data-ad-format="fluid"
{<span class="php-variable">$layout_key</span>}
data-ad-client="ca-{<span class="php-variable">$client</span>}"
data-ad-slot="{<span class="php-variable">$slot</span>}"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
MANAGED_FLUID_TXT;
}
elseif (variable_get('adsense_managed_async', ADSENSE_MANAGED_ASYNC_DEFAULT)) {
// Asynchronous code.
$output = <<<MANAGED_ASYNC_TXT
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- {<span class="php-variable">$format</span>} -->
<ins class="adsbygoogle"
style="display:inline-block;width:{<span class="php-variable">$ad</span>[<span class="php-string">'width'</span>]}px;height:{<span class="php-variable">$ad</span>[<span class="php-string">'height'</span>]}px"
data-ad-client="ca-{<span class="php-variable">$client</span>}"
data-ad-slot="{<span class="php-variable">$slot</span>}"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
MANAGED_ASYNC_TXT;
}
else {
// Synchronous code.
$secret = '';
if ($lang = variable_get('adsense_secret_language', ADSENSE_SECRET_LANGUAGE_DEFAULT)) {
$secret = "google_language = '{$lang}';\n";
}
$output = <<<MANAGED_SYNC_TXT
<script type="text/javascript"><!--
google_ad_client = "ca-{<span class="php-variable">$client</span>}";
/* {<span class="php-variable">$format</span>} */
google_ad_slot = "{<span class="php-variable">$slot</span>}";
google_ad_width = {<span class="php-variable">$ad</span>[<span class="php-string">'width'</span>]};
google_ad_height = {<span class="php-variable">$ad</span>[<span class="php-string">'height'</span>]};
{<span class="php-variable">$secret</span>}//-->
</script>
<script type="text/javascript"
src="//pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
MANAGED_SYNC_TXT;
}
}
return $output;
}