--- adsense.module-old 2006-02-18 01:08:36.000000000 +0000 +++ adsense.module 2006-02-22 01:14:25.356729016 +0000 @@ -13,12 +13,12 @@ * * To ad a new code: * - Make sure the dimensions are not in use by a different format - * - Go to Google AdSense + * - Go to Google AdSense * . Get the dimensions - * . Get the code (suffix after the dimensions) + * . Get the code (suffix after the dimensions) * - Add it below in ascending order (width first, then height) * @return returns an array of supported ad formats (desc: description, code: Google Ad code suffix) - * + * */ function adsense_ad_formats() { @@ -184,21 +184,21 @@ '); } } - + function adsense_perm() { return array ('hide adsense'); } function adsense_settings() { cache_clear_all('adsense', TRUE); - + $form['required'] = array( '#type' => 'fieldset', '#collapsible' => true, '#collapsed' => true, '#title' => t('Required parameters'), ); - + $form['required']['adsense_client_id'] = array( '#type' => 'textfield', '#title' => t('Google AdSense Client ID'), @@ -207,7 +207,7 @@ '#maxlength' => 25, '#description' => t('This is the google_ad_client line in your Ad code, without the quotes. You must apply for an account with Google AdSense before you get this client ID. Please type it carefully. If you mistype it, your account will not get credited by Google for ads displayed on your site.'), ); - + $form['general'] = array( '#type' => 'fieldset', '#collapsible' => true, @@ -238,9 +238,9 @@ '#collapsed' => true, '#title' => t('Ad Type and Colors'), ); - + for($group=1; $group '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('