'fieldset',
'#collapsible' => true,
@@ -294,7 +294,7 @@
'#size' => 6,
'#maxlength' => 6,
);
-
+
$form['types_colors']['groups'][$group][ADSENSE_ALT . $group] = array(
'#type' => 'select',
'#title' => t('Alternate URL/Color'),
@@ -329,7 +329,7 @@
'#maxlength' => 30,
);
}
-
+
$form['revenue'] = array(
'#type' => 'fieldset',
'#collapsible' => true,
@@ -351,14 +351,14 @@
'#default_value' => variable_get(ADSENSE_PERCENTAGE_AUTHOR, 0),
'#options' => drupal_map_assoc(array(0, 5, 10, 15, 20, 25, 30, 40, 50, 60, 70, 75, 80, 90, 100)),
);
-
+
$form['revenue'][ADSENSE_PERCENTAGE_REFER] = array(
'#type' => 'select',
'#title' => t('Percentage of node views going to user who referred the author'),
'#default_value' => variable_get(ADSENSE_PERCENTAGE_REFER, 0),
'#options' => drupal_map_assoc(array(0, 5, 10, 15, 20, 25, 30, 40, 50, 60, 70, 75, 80, 90, 100)),
);
-
+
$form['revenue']['content'] = array(
'#type' => 'fieldset',
'#collapsible' => true,
@@ -416,7 +416,7 @@
'#maxlength' => 6,
'#description' => t('Google currently limits a page to 3 ad units, in addition to one ad links unit'),
);
-
+
$form['advanced'][ADSENSE_SECTION_TARGETING] = array(
'#type' => 'checkbox',
'#title' => t('Enable Adsense Section targeting?'),
@@ -426,25 +426,24 @@
);
return $form;
-}
+}
-function adsense_display($format = '160x600', $group = 1, $channel = 1) {
+function adsense_display($format = '160x600', $group = 1, $channel = 1, $filter = FALSE) {
static $num_adsense_on_this_page;
-
if (!_adsense_validate_dimensions($format)) {
$ad = '';
}
else {
// This ad format is not cached, generate it
// Check first if disabled or if we are at adsense limit or if this page doesn't allow adsense
- if (_adsense_check_if_enabled()) {
+ if (_adsense_check_if_enabled() || $filter) {
if (_adsense_can_insert_another()) {
if (_adsense_page_match()) {
// Ad should be displayed
// Check cache first
$num_adsense_on_this_page++;
- $ad = _adsense_get_ad($format, $group, $channel);
+ $ad = theme('adsense_ad', _adsense_get_ad($format, $group, $channel), $group);
}
else {
$ad = '';
@@ -460,31 +459,40 @@
$ad = '' . _adsense_format_placeholder($format);
}
else {
- $ad = '';
+ $ad = '';
}
}
}
return $ad;
}
+
+function theme_adsense_ad($ad, $group) {
+ $output = '' . $ad . '
';
+ return $output;
+}
+
function _adsense_get_ad($format, $group, $channel) {
$sharing = variable_get(ADSENSE_REVENUE_ENABLE, 0);
if ($sharing) {
$ad = _adsense_format($format, $group, $channel);
return $ad;
}
-
+
$cache_key = "adsense-$group-$format-$channel";
$cache = cache_get($cache_key);
- if ($cache) {
+ if ($cache && !_adsense_check_placeholder()) {
// This ad format is cached, use it
$ad = '' . $cache->data;
}
else {
// Not cached. Format an ad
$ad = _adsense_format($format, $group, $channel);
- // Add it to cache
- cache_set($cache_key, $ad, CACHE_PERMANENT);
+
+ // Add it to cache if it's not a place holder
+ if(!_adsense_check_placeholder()) {
+ cache_set($cache_key, $ad, CACHE_PERMANENT);
+ }
}
return $ad;
@@ -499,7 +507,6 @@
// Google AdSense Client ID is not configured
return false;
}
-
if ($disable_ads) {
return false;
}
@@ -512,7 +519,7 @@
}
function _adsense_check_placeholder() {
- if (variable_get(ADSENSE_PLACEHOLDER, '1')) {
+ if (variable_get(ADSENSE_PLACEHOLDER, '1') && _adsense_check_if_enabled() == FALSE) {
// Ads are globally disabled and a place holder is set
return true;
}
@@ -617,7 +624,6 @@
$format = $width . 'x' . $height . adsense_get_ad_code($format);
$output .= _adsense_add_nl('');
- $output .= _adsense_add_nl('');
$output .= _adsense_add_nl('');
- $output .= _adsense_add_nl('
');
return $output;
}
@@ -673,17 +678,17 @@
*/
function _adsense_page_match() {
$page_match = FALSE;
- $visibility = (int)variable_get(ADSENSE_VISIBILITY, '0');
+ $visibility = (int)variable_get(ADSENSE_VISIBILITY, '0');
$pages = variable_get(ADSENSE_ACCESS_PAGES, '');
-
+
if ($pages) {
// Specific pages are configured
$path = drupal_get_path_alias($_GET['q']);
$regexp = '/^('. preg_replace(
- array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'),
- array('|', '.*', '\1'. variable_get('site_frontpage', 'node') .'\2'),
+ array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'),
+ array('|', '.*', '\1'. variable_get('site_frontpage', 'node') .'\2'),
preg_quote($pages, '/')) .')$/';
- $page_match = !($visibility xor preg_match($regexp, $path));
+ $page_match = !($visibility xor preg_match($regexp, $path));
}
else {
// No pages are configured
@@ -737,7 +742,7 @@
}
else {
// Tag is in [adsense:468x60:1:1] format
- $ad = adsense_display($match[1], $match[2], $match[3]);
+ $ad = adsense_display($match[1], $match[2], $match[3], TRUE);
}
$text = str_replace($match[0], $ad, $text);
}