### Eclipse Workspace Patch 1.0
#P adsense
Index: adsense.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/adsense/adsense.module,v
retrieving revision 1.63
diff -u -r1.63 adsense.module
--- adsense.module	28 Jan 2008 06:06:37 -0000	1.63
+++ adsense.module	29 Jan 2008 11:49:07 -0000
@@ -21,12 +21,15 @@
 function adsense_ad_formats() {
   return array (
     '120x90'           =>  array('type' => ADSENSE_TYPE_LINK,   'desc' => t('Ad links 4-links 120x90'),      'code' => '_0ads_al'),
+    '120x90-5'         =>  array('type' => ADSENSE_TYPE_LINK,   'desc' => t('Ad Links 5-links 120x90'),      'code' => '_0ads_al_s'),
     '120x240'          =>  array('type' => ADSENSE_TYPE_AD,     'desc' => t('Vertical banner'),              'code' => '_as'),
     '120x600'          =>  array('type' => ADSENSE_TYPE_AD,     'desc' => t('Skyscraper'),                   'code' => '_as'),
     '125x125'          =>  array('type' => ADSENSE_TYPE_AD,     'desc' => t('Button'),                       'code' => '_as'),
     '160x90'           =>  array('type' => ADSENSE_TYPE_LINK,   'desc' => t('Ad links 4-links 160x90'),      'code' => '_0ads_al'),
+    '160x90-5'         =>  array('type' => ADSENSE_TYPE_LINK,   'desc' => t('Ad Links 5-links 160x90'),      'code' => '_0ads_al_s'),
     '160x600'          =>  array('type' => ADSENSE_TYPE_AD,     'desc' => t('Wide skyscraper'),              'code' => '_as'),
     '180x90'           =>  array('type' => ADSENSE_TYPE_LINK,   'desc' => t('Ad links 4-links 180x90'),      'code' => '_0ads_al'),
+    '180x90-5'         =>  array('type' => ADSENSE_TYPE_LINK,   'desc' => t('Ad Links 5-links 180x90'),      'code' => '_0ads_al_s'),
     '180x150'          =>  array('type' => ADSENSE_TYPE_AD,     'desc' => t('Small rectangle'),              'code' => '_as'),
     '200x200'          =>  array('type' => ADSENSE_TYPE_AD,     'desc' => t('Small square'),                 'code' => '_as'),
     '234x60'           =>  array('type' => ADSENSE_TYPE_AD,     'desc' => t('Half banner'),                  'code' => '_as'),
@@ -34,14 +37,15 @@
     '300x250'          =>  array('type' => ADSENSE_TYPE_AD,     'desc' => t('Medium rectangle'),             'code' => '_as'),
     '336x280'          =>  array('type' => ADSENSE_TYPE_AD,     'desc' => t('Large rectangle'),              'code' => '_as'),
     '468x15'           =>  array('type' => ADSENSE_TYPE_LINK,   'desc' => t('Banner ad links 4-links'),      'code' => '_0ads_al'),
+    '468x15-5'         =>  array('type' => ADSENSE_TYPE_LINK,   'desc' => t('Banner Ad Links 5-links'),      'code' => '_0ads_al_s'),
     '468x60'           =>  array('type' => ADSENSE_TYPE_AD,     'desc' => t('Banner'),                       'code' => '_as'),
     '728x15'           =>  array('type' => ADSENSE_TYPE_LINK,   'desc' => t('Wide banner ad links 4-links'), 'code' => '_0ads_al'),
+    '728x15-5'         =>  array('type' => ADSENSE_TYPE_LINK,   'desc' => t('Wide Banner Ad Links 5-links'), 'code' => '_0ads_al_s'),
     '728x90'           =>  array('type' => ADSENSE_TYPE_AD,     'desc' => t('Leaderboard'),                  'code' => '_as'),
-    ADSENSE_SEARCH_BOX =>  array('type' => ADSENSE_TYPE_SEARCH, 'desc' => t('AdSense for Search'),                  'code' => '')
+    ADSENSE_SEARCH_BOX =>  array('type' => ADSENSE_TYPE_SEARCH, 'desc' => t('AdSense for Search'),           'code' => '')
     );
 }
 
-// Ad types, link or ad
 define('ADSENSE_TYPE_LINK',                   1);
 define('ADSENSE_TYPE_AD',                     2);
 define('ADSENSE_TYPE_SEARCH',                 3);
@@ -86,12 +90,25 @@
 define('ADSENSE_SEARCH_COLOR_URL',            'adsense_search_color_url');
 define('ADSENSE_SEARCH_COLOR_VISITED_URL',    'adsense_search_color_visited_url');
 define('ADSENSE_SEARCH_COLOR_LIGHT_URL',      'adsense_search_color_light_url');
+define('ADSENSE_SEARCH_COLOR_BOX_BACKGROUND', 'adsense_search_color_box_background');
+define('ADSENSE_SEARCH_COLOR_BOX_TEXT',       'adsense_search_color_box_text');
+define('ADSENSE_SEARCH_COLOR_WHITE',          'white');
+define('ADSENSE_SEARCH_COLOR_BLACK',          '#000000');
+define('ADSENSE_SEARCH_COLOR_GRAY',           '#cccccc');
 define('ADSENSE_SEARCH_DOMAIN',               'adsense_search_domain');
 define('ADSENSE_SEARCH_LANGUAGE',             'adsense_search_language');
+define('ADSENSE_SEARCH_ENCODING',             'adsense_search_encoding');
 define('ADSENSE_SEARCH_COUNTRY',              'adsense_search_country');
 define('ADSENSE_SEARCH_TEXTBOX_LENGTH',       'adsense_search_textbox_length');
+define('ADSENSE_SEARCH_LOGO',                 'adsense_search_logo');
+define('ADSENSE_SEARCH_LOGO_GOOGLE',          'adsense_search_logo_google');
+define('ADSENSE_SEARCH_LOGO_ABOVE_TEXTBOX',   'adsense_search_logo_above_textbox');
+define('ADSENSE_SEARCH_LOGO_ON_BUTTON',       'adsense_search_logo_on_button');
+define('ADSENSE_SEARCH_BUTTON',               'adsense_search_button');
 define('ADSENSE_SEARCH_FRAME_WIDTH',          'adsense_search_frame_width');
 define('ADSENSE_SEARCH_BOX',                  'Search Box');
+define('ADSENSE_SEARCH_PATH',                 'adsense/search');
+define('ADSENSE_SITE_SEARCH',                 '<!-- SiteSearch Google -->');
 
 function adsense_get_ad_code($format) {
   $all_ads = adsense_ad_formats();
@@ -104,7 +121,7 @@
 function adsense_help($section) {
   switch ($section) {
     case 'admin/settings/adsense':
-      return t('<p>@revision @date</p>', array('@revision' => trim('$Revision: 1.63 $', ' $'), '@date' => trim('$Date: 2008/01/28 06:06:37 $', ' $')));
+      return t('<p>@revision @date</p>', array('@revision' => trim('$Revision: 1.61 $', ' $'), '@date' => trim('$Date: 2007/07/07 18:00:32 $', ' $')));
   }
 }
 
@@ -162,7 +179,7 @@
       );
    }
    $items[] = array(
-       'path'     => 'adsense/search',
+       'path'     => ADSENSE_SEARCH_PATH,
        'callback' => 'adsense_search',
        'access'   => user_access('access adsense search result page'),
        'type'     => MENU_CALLBACK,
@@ -496,6 +513,55 @@
     '#description' => t('Display the domain name instead of the IP address. This can slow down the display of the logs page and tie up a PHP process for several seconds. On some hosting providers it may not be available.'),
   );
 
+  $form['advanced'] = array(
+    '#type' => 'fieldset',
+    '#collapsible' => true,
+    '#collapsed' => true,
+    '#title' => t('Advanced options'),
+  );
+
+  $form['advanced'][ADSENSE_TEST_MODE] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Enable test mode?'),
+    '#return_value' => 1,
+    '#default_value' => variable_get(ADSENSE_TEST_MODE, 0),
+    '#description' => t('This enables you to test the AdSense module settings. This can be useful in some situations: for example, testing whether revenue sharing is working properly or not without having to display real ads on your site. It is best to test this after you log out.'),
+  );
+
+  $form['advanced'][ADSENSE_DISABLE] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Disable Google AdSense ads?'),
+    '#return_value' => 1,
+    '#default_value' => variable_get(ADSENSE_DISABLE, 0),
+    '#description' => t('This disables all display of Google AdSense ads from your web site. This is useful in certain situations, such as site upgrades, or if you make a copy of the site for development and test purposes.'),
+  );
+
+  $form['advanced'][ADSENSE_PLACEHOLDER] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Placeholder when ads are disabled?'),
+    '#return_value' => 1,
+    '#default_value' => variable_get(ADSENSE_PLACEHOLDER, 1),
+    '#description' => t('This causes an empty box to be displayed in place of the ads when they are disabled.'),
+  );
+
+  $form['advanced'][ADSENSE_PLACEHOLDER_TEXT] = array(
+    '#type' => 'textarea',
+    '#title' => t('Placeholder text to display'),
+    '#default_value' => variable_get(ADSENSE_PLACEHOLDER_TEXT, t('Google AdSense')),
+    '#cols' => 70,
+    '#rows' => 3,
+    '#description' => t('Enter any text to display as a placeholder when ads are disabled.'),
+  );
+
+  $form['advanced'][ADSENSE_SECTION_TARGETING] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Enable AdSense section targeting?'),
+    '#return_value' => 1,
+    '#default_value' => variable_get(ADSENSE_SECTION_TARGETING, 1),
+    '#description' => t('This better targets Google ads to the teaser and body of nodes.'),
+  );
+
+
   $form['search'] = array(
     '#type' => 'fieldset',
     '#collapsible' => true,
@@ -503,16 +569,171 @@
     '#title' => t('AdSense Search')
   );
 
+  $form['search']['box'] = array(
+    '#type' => 'fieldset',
+    '#collapsible' => true,
+    '#collapsed' => true,
+    '#title' => t('Search Box Options')
+  );
+
+
   global $base_url;
-  $form['search'][ADSENSE_SEARCH_DOMAIN] = array(
+  $form['search']['box'][ADSENSE_SEARCH_DOMAIN . '_0'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Google WebSearch + SiteSearch (withouth the last \'/\'); Allows users to search the web or the specific site(s) of your choice'),
+    '#field_prefix' => 'http://',
+    '#default_value' => variable_get(str_replace('http://', '', ADSENSE_SEARCH_DOMAIN . '_0'), str_replace('http://', '', $base_url)),
+    '#size' => 32,
+    '#maxlength' => 255
+  );
+
+  $form['search']['box'][ADSENSE_SEARCH_DOMAIN . '_1'] = array(
+    '#type' => 'textfield',
+    '#field_prefix' => 'http://',
+    '#default_value' => variable_get(str_replace('http://', '', ADSENSE_SEARCH_DOMAIN . '_1'), ''),
+    '#size' => 32,
+    '#maxlength' => 255
+  );
+
+  $form['search']['box'][ADSENSE_SEARCH_DOMAIN . '_2'] = array(
     '#type' => 'textfield',
-    '#title' => t('URL for SiteSearch'),
-    '#default_value' => variable_get(ADSENSE_SEARCH_DOMAIN, $base_url),
-    '#size' => 255,
+    '#field_prefix' => 'http://',
+    '#default_value' => variable_get(str_replace('http://', '', ADSENSE_SEARCH_DOMAIN . '_2'), ''),
+    '#size' => 32,
     '#maxlength' => 255
   );
 
-  $form['search'][ADSENSE_SEARCH_COUNTRY] = array(
+  $form['search']['box'][ADSENSE_SEARCH_LOGO] = array(
+    '#type' => 'radios',
+    '#title' => t('Logo Type'),
+    '#default_value' => variable_get(ADSENSE_SEARCH_LOGO, ADSENSE_SEARCH_LOGO_GOOGLE),
+    '#options' => array(ADSENSE_SEARCH_LOGO_GOOGLE        => t('Google Logo'),
+                        ADSENSE_SEARCH_LOGO_ABOVE_TEXTBOX => t('Logo above text box'),
+                        ADSENSE_SEARCH_LOGO_ON_BUTTON     => t('"Google Search" on button'),
+                       )
+  );
+
+  $form['search']['box'][ADSENSE_SEARCH_BUTTON] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Search button below text box'),
+    '#return_value' => 1,
+    '#default_value' => variable_get(ADSENSE_SEARCH_BUTTON, 0)
+  );
+
+  $box_background_color = variable_get(ADSENSE_SEARCH_COLOR_BOX_BACKGROUND, ADSENSE_SEARCH_COLOR_WHITE);
+  $form['search']['box'][ADSENSE_SEARCH_COLOR_BOX_BACKGROUND] = array(
+    '#type' => 'select',
+    '#title' => t('Background Color'),
+    '#default_value' => $box_background_color,
+    '#options' => array(ADSENSE_SEARCH_COLOR_WHITE => t('White'),
+                        ADSENSE_SEARCH_COLOR_BLACK => t('Black'),
+                        ADSENSE_SEARCH_COLOR_GRAY  => t('Gray'),
+                       )
+  );
+
+  $box_text_color = variable_get(ADSENSE_SEARCH_COLOR_BOX_TEXT, ADSENSE_SEARCH_COLOR_BLACK);
+  if($box_background_color == ADSENSE_SEARCH_COLOR_BLACK) {
+    $box_text_color = ADSENSE_SEARCH_COLOR_WHITE;
+  } elseif($box_background_color == ADSENSE_SEARCH_COLOR_WHITE) {
+    $box_text_color = ADSENSE_SEARCH_COLOR_BLACK;
+  }
+
+  $form['search']['box'][ADSENSE_SEARCH_COLOR_BOX_TEXT] = array(
+    '#type' => 'select',
+    '#title' => t('Text Color'),
+    '#default_value' => $box_text_color,
+    '#options' => array(ADSENSE_SEARCH_COLOR_BLACK => t('Black'),
+                        ADSENSE_SEARCH_COLOR_WHITE => t('White')
+                       )
+  );
+
+  $textbox_length = $textbox_length > 64 ? 64 : variable_get(ADSENSE_SEARCH_TEXTBOX_LENGTH, 15);
+  $form['search']['box'][ADSENSE_SEARCH_TEXTBOX_LENGTH] = array(
+    '#type' => 'textfield',
+    '#title' => t('Length of text box (Max 64): '),
+    '#default_value' => $textbox_length,
+    '#size' => 2,
+    '#maxlength' => 2
+  );
+
+  $form['search']['box'][ADSENSE_SEARCH_LANGUAGE] = array(
+    '#type' => 'select',
+    '#title' => t('Site Language'),
+    '#default_value' => variable_get(ADSENSE_SEARCH_LANGUAGE, 'en'),
+    '#options' => array('ar'    => t('Arabic'),
+                        'bg'    => t('Bulgarian'),
+                        'zh-CN' => t('Chinese (simplified)'),
+                        'zh-TW' => t('Chinese (traditional)'),
+                        'hr'    => t('Croatian'),
+                        'cs'    => t('Czech'),
+                        'da'    => t('Danish'),
+                        'nl'    => t('Dutch'),
+                        'en'    => t('English'),
+                        'fi'    => t('Finnish'),
+                        'fr'    => t('French'),
+                        'de'    => t('German'),
+                        'el'    => t('Greek'),
+                        'iw'    => t('Hebrew'),
+                        'hu'    => t('Hungarian'),
+                        'in'    => t('Indonesian'),
+                        'it'    => t('Italian'),
+                        'ja'    => t('Japanese'),
+                        'ko'    => t('Korean'),
+                        'no'    => t('Norwegian'),
+                        'pl'    => t('Polish'),
+                        'pt'    => t('Portuguese'),
+                        'ro'    => t('Romanian'),
+                        'ru'    => t('Russian'),
+                        'sk'    => t('Slovak'),
+                        'es'    => t('Spanish'),
+                        'sv'    => t('Swedish'),
+                        'tr'    => t('Turkish')
+                       )
+  );
+
+  $form['search']['box'][ADSENSE_SEARCH_ENCODING] = array(
+    '#type' => 'select',
+    '#title' => t('Site Encoding'),
+    '#default_value' => variable_get(ADSENSE_SEARCH_ENCODING, 'UTF-8'),
+    '#options' => array('ISO-8859-1'   =>  t('West European Latin-1 (ISO-8859-1)'),
+                        'ISO-8859-15'  =>  t('West European Latin-9 (ISO-8859-15)'),
+                        'windows-1252' =>  t('Western (Windows-1252)'),
+                        'ISO-8859-10'  =>  t('Nordic Latin-6 (ISO-8859-10)'),
+                        'ISO-8859-7'   =>  t('Greek (ISO-8859-7)'),
+                        'Shift_JIS'    =>  t('Japanese (Shift_JIS)'),
+                        'EUC-JP'       =>  t('Japanese (EUC-JP)'),
+                        'ISO-2022-JP'  =>  t('Japanese (ISO-2022-JP)'),
+                        'GB2312'       =>  t('Chinese Simplified (GB2312)'),
+                        'GB18030'      =>  t('Chinese Simplified (GB18030)'),
+                        'big5'         =>  t('Chinese Traditional (Big5)'),
+                        'EUC-KR'       =>  t('Korean (EUC-KR)'),
+                        'windows-874'  =>  t('Thai (Windows-874)'),
+                        'windows-1258' =>  t('Vietnamese (Windows-1258)'),
+                        'ISO-8859-2'   =>  t('Central European Latin-2 (ISO-8859-2)'),
+                        'windows-1250' =>  t('Central European (Windows-1250)'),
+                        'cp852'        =>  t('Central European (CP852)'),
+                        'ISO-8859-9'   =>  t('Turkish Latin-5 (ISO-8859-9)'),
+                        'windows-1254' =>  t('Turkish (Windows-1254)'),
+                        'ISO-8859-3'   =>  t('South European Latin-3 (ISO-8859-3)'),
+                        'ISO-8859-8-I' =>  t('Hebrew (ISO-8859-8-I)'),
+                        'windows-1255' =>  t('Hebrew (Windows-1255)'),
+                        'windows-1256' =>  t('Arabic (Windows-1256)'),
+                        'ISO-8859-5'   =>  t('Cyrillic (ISO-8859-5)'),
+                        'KOI8-R'       =>  t('Cyrillic (KOI8-R)'),
+                        'windows-1251' =>  t('Cyrillic (Windows-1251)'),
+                        'cp-866'       =>  t('Cyrillic/Russian (CP-866)'),
+                        'UTF-8'        =>  t('Unicode (UTF-8)')
+                       )
+  );
+
+  $form['search']['result'] = array(
+    '#type' => 'fieldset',
+    '#collapsible' => true,
+    '#collapsed' => true,
+    '#title' => t('Search Results Style')
+  );
+
+  $form['search']['result'][ADSENSE_SEARCH_COUNTRY] = array(
     '#type' => 'select',
     '#title' => t('Country or territory for Google domain'),
     '#default_value' => variable_get(ADSENSE_SEARCH_COUNTRY, 'www.google.com'),
@@ -758,104 +979,13 @@
                        )
   );
 
-  $form['search'][ADSENSE_SEARCH_LANGUAGE] = array(
-    '#type' => 'select',
-    '#title' => t('Site Language'),
-    '#default_value' => variable_get(ADSENSE_SEARCH_LANGUAGE, 'en'),
-    '#options' => array('ar'    => t('Arabic'),
-                        'bg'    => t('Bulgarian'),
-                        'zh-CN' => t('Chinese (simplified)'),
-                        'zh-TW' => t('Chinese (traditional)'),
-                        'hr'    => t('Croatian'),
-                        'cs'    => t('Czech'),
-                        'da'    => t('Danish'),
-                        'nl'    => t('Dutch'),
-                        'en'    => t('English'),
-                        'fi'    => t('Finnish'),
-                        'fr'    => t('French'),
-                        'de'    => t('German'),
-                        'el'    => t('Greek'),
-                        'iw'    => t('Hebrew'),
-                        'hu'    => t('Hungarian'),
-                        'in'    => t('Indonesian'),
-                        'it'    => t('Italian'),
-                        'ja'    => t('Japanese'),
-                        'ko'    => t('Korean'),
-                        'no'    => t('Norwegian'),
-                        'pl'    => t('Polish'),
-                        'pt'    => t('Portuguese'),
-                        'ro'    => t('Romanian'),
-                        'ru'    => t('Russian'),
-                        'sk'    => t('Slovak'),
-                        'es'    => t('Spanish'),
-                        'sv'    => t('Swedish'),
-                        'tr'    => t('Turkish')
-                       )
-  );
-
-  $form['search'][ADSENSE_SEARCH_TEXTBOX_LENGTH] = array(
-    '#type' => 'textfield',
-    '#title' => t('Length of text box'),
-    '#default_value' => variable_get(ADSENSE_SEARCH_TEXTBOX_LENGTH, 15),
-    '#size' => 2,
-    '#maxlength' => 2
-  );
-
-  $form['search'][ADSENSE_SEARCH_FRAME_WIDTH] = array(
+  $form['search']['result'][ADSENSE_SEARCH_FRAME_WIDTH] = array(
     '#type' => 'textfield',
     '#title' => t('Width of results area'),
     '#default_value' => variable_get(ADSENSE_SEARCH_FRAME_WIDTH, 500),
     '#size' => 3,
     '#maxlength' => 3
   );
-  $form['advanced'] = array(
-    '#type' => 'fieldset',
-    '#collapsible' => true,
-    '#collapsed' => true,
-    '#title' => t('Advanced options'),
-  );
-
-  $form['advanced'][ADSENSE_TEST_MODE] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Enable test mode?'),
-    '#return_value' => 1,
-    '#default_value' => variable_get(ADSENSE_TEST_MODE, 0),
-    '#description' => t('This enables you to test the AdSense module settings. This can be useful in some situations: for example, testing whether revenue sharing is working properly or not without having to display real ads on your site. It is best to test this after you log out.'),
-  );
-
-  $form['advanced'][ADSENSE_DISABLE] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Disable Google AdSense ads?'),
-    '#return_value' => 1,
-    '#default_value' => variable_get(ADSENSE_DISABLE, 0),
-    '#description' => t('This disables all display of Google AdSense ads from your web site. This is useful in certain situations, such as site upgrades, or if you make a copy of the site for development and test purposes.'),
-  );
-
-  $form['advanced'][ADSENSE_PLACEHOLDER] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Placeholder when ads are disabled?'),
-    '#return_value' => 1,
-    '#default_value' => variable_get(ADSENSE_PLACEHOLDER, 1),
-    '#description' => t('This causes an empty box to be displayed in place of the ads when they are disabled.'),
-  );
-
-  $form['advanced'][ADSENSE_PLACEHOLDER_TEXT] = array(
-    '#type' => 'textarea',
-    '#title' => t('Placeholder text to display'),
-    '#default_value' => variable_get(ADSENSE_PLACEHOLDER_TEXT, t('Google AdSense')),
-    '#cols' => 70,
-    '#rows' => 3,
-    '#description' => t('Enter any text to display as a placeholder when ads are disabled.'),
-  );
-
-  $form['advanced'][ADSENSE_SECTION_TARGETING] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Enable AdSense section targeting?'),
-    '#return_value' => 1,
-    '#default_value' => variable_get(ADSENSE_SECTION_TARGETING, 1),
-    '#description' => t('This better targets Google ads to the teaser and body of nodes.'),
-  );
-
 
   return system_settings_form($form);
 }
@@ -973,6 +1103,7 @@
 
 function _adsense_get_dimensions($format) {
   list($width, $height) = explode('x', $format);
+  $height = (int)$height;
   return array('width' => $width, 'height' => $height);
 }
 
@@ -1111,13 +1242,15 @@
     ADSENSE_TYPE_SEARCH => 0,
     );
 
+  $max_ads = array(
+    ADSENSE_TYPE_AD     => 3,
+    ADSENSE_TYPE_LINK   => 3,
+    ADSENSE_TYPE_SEARCH => 2,
+    );
+
   $ad_list = adsense_ad_formats();
   $type = $ad_list[$format]['type'];
-  if ($num_ads[ADSENSE_TYPE_SEARCH] < 1) {
-    $num_ads[$type]++;
-    $ret = TRUE;
-  }
-  elseif ($num_ads[$type] < 3) {
+  if ($num_ads[$type] < $max_ads[$type]) {
     $num_ads[$type]++;
     $ret = TRUE;
   }
@@ -1628,60 +1761,157 @@
   $visited  = variable_get(ADSENSE_SEARCH_COLOR_VISITED_URL, '663399');
   $light    = variable_get(ADSENSE_SEARCH_COLOR_LIGHT_URL,   '0000FF');
 
+  $box_text_color       = variable_get(ADSENSE_SEARCH_COLOR_BOX_TEXT      , ADSENSE_SEARCH_COLOR_BLACK);
+  $box_background_color = variable_get(ADSENSE_SEARCH_COLOR_BOX_BACKGROUND, ADSENSE_SEARCH_COLOR_WHITE);
+  $encoding = variable_get(ADSENSE_SEARCH_ENCODING, 'UTF-8');
+
   $channel  = variable_get(ADSENSE_AD_CHANNEL . _adsense_validate_channel($channel), '');
 
   global $base_url;
-  $domain         = variable_get(ADSENSE_SEARCH_DOMAIN,         $base_url);
+  $domain_0 = variable_get(ADSENSE_SEARCH_DOMAIN . '_0', $base_url);
+  $domain_1 = variable_get(ADSENSE_SEARCH_DOMAIN . '_1', '');
+  $domain_2 = variable_get(ADSENSE_SEARCH_DOMAIN . '_2', '');
+  $domain   = $domain_1 ? "$domain_0;$domain_1" : $domain_0;
+  $domain   = $domain_2 ? "$domain_0;$domain_2" : $domain_0;
+
   $language       = variable_get(ADSENSE_SEARCH_LANGUAGE,       'en');
   $textbox_length = variable_get(ADSENSE_SEARCH_TEXTBOX_LENGTH, 15);
 
-  $output .= _adsense_add_nl('<form method="get" action="/adsense/search" target="_top" style="text-align:left;">');
-  $output .= _adsense_add_nl('<input type="hidden" name="domains" value="'    . $domain  . '"></input>');
-  $output .= _adsense_add_nl('<input type="text" name="as_q" size="'          . $textbox_length . '" maxlength="255" value="' . $_GET['as_q'] . '" class="form-text"></input>');
-  $output .= _adsense_add_nl('<input type="hidden" name="sitesearch" value="' . $domain  . '"></input>');
-  $output .= _adsense_add_nl('<input type="hidden" name="client" value="'     . $client  . '"></input>');
-  $output .= _adsense_add_nl('<input type="hidden" name="channel" value="'    . $channel . '"></input>');
-  $output .= _adsense_add_nl('<input type="hidden" name="forid" value="1"></input>' );
-  $output .= _adsense_add_nl('<input type="hidden" name="ie" value="UTF-8"></input>');
-  $output .= _adsense_add_nl('<input type="hidden" name="oe" value="UTF-8"></input>');
-  $output .= _adsense_add_nl('<input type="hidden" name="cof" value="GALT:'          . $url
-                                                                 . ';GL:1;DIV:'      . $border
-                                                                 . ';VLC:'           . $visited
-                                                                 . ';AH:center;BGC:' . $bg
-                                                                 . ';ALC:'           . $title
-                                                                 . ';LC:'            . $title
-                                                                 . ';T:'             . $text
-                                                                 . ';GFNT:'          . $light
-                                                                 . ';GIMP:'          . $light
+  $logo           = variable_get(ADSENSE_SEARCH_LOGO, ADSENSE_SEARCH_LOGO_GOOGLE);
+  $search_button  = variable_get(ADSENSE_SEARCH_BUTTON, 0);
+
+  $output .= _adsense_add_nl('<div class="adsense adsense_search">');
+  $output .= _adsense_add_nl(ADSENSE_SITE_SEARCH);
+  $output .= _adsense_add_nl('<form method="get" action="' . "http://$domain/". ADSENSE_SEARCH_PATH . '" target="_top">');
+  $output .= _adsense_add_nl('<table border="0" bgcolor="'. $box_background_color . '">');
+  $output .= _adsense_add_nl('<tr><td nowrap="nowrap" valign="top" align="left" height="32">');
+  if($logo != ADSENSE_SEARCH_LOGO_ON_BUTTON) {
+    $output .= _adsense_add_nl('<a href="http://www.google.com/">');
+    if($box_background_color == ADSENSE_SEARCH_COLOR_WHITE) {
+      $logo_color = 'wht';
+    } elseif($box_background_color == ADSENSE_SEARCH_COLOR_BLACK) {
+      $logo_color = 'blk';
+    } elseif($box_background_color == ADSENSE_SEARCH_COLOR_GRAY) {
+      $logo_color = 'gry';
+    }
+    $output .= _adsense_add_nl('<img src="http://www.google.com/logos/Logo_25' . $logo_color . '.gif" border="0" alt="Google" align="middle"></img></a>');
+  }
+
+  if($logo == ADSENSE_SEARCH_LOGO_GOOGLE) {
+    $output .= _adsense_add_nl('</td>');
+    $output .= _adsense_add_nl('<td nowrap="nowrap">');
+  } elseif($logo == ADSENSE_SEARCH_LOGO_ABOVE_TEXTBOX) {
+    $output .= _adsense_add_nl('<br/>');
+  }
+
+  $output .= _adsense_add_nl('<input type="hidden" name="domains" value="' . $domain . '"></input>');
+  $output .= _adsense_add_nl('<label for="sbi" style="display: none">' . t('Enter your search terms') . '</label>');
+  $output .= _adsense_add_nl('<input type="text" name="as_q" size="' . $textbox_length . '" maxlength="255" value="" id="sbi"></input>');
+
+  if(!$search_button) {
+    $output .= _adsense_add_nl('<label for="sbb" style="display: none">' . t('Submit search form') . '</label>');
+    if($logo != ADSENSE_SEARCH_LOGO_ON_BUTTON) {
+      $output .= _adsense_add_nl('<input type="submit" name="sa" value="' . t('Search')        . '" id="sbb"></input>');
+    } else {
+      $output .= _adsense_add_nl('<input type="submit" name="sa" value="' . t('Google Search') . '" id="sbb"></input>');
+    }
+  }
+
+  $output .= _adsense_add_nl('</td></tr>');
+  $output .= _adsense_add_nl('<tr>');
+
+  if($logo == ADSENSE_SEARCH_LOGO_GOOGLE) {
+    $output .= _adsense_add_nl('<td>&nbsp;</td>');
+  }
+
+  $output .= _adsense_add_nl('<td nowrap="nowrap">');
+  $output .= _adsense_add_nl('<table>');
+  $output .= _adsense_add_nl('<tr>');
+  $output .= _adsense_add_nl('<td>');
+  $output .= _adsense_add_nl('<input type="radio" name="sitesearch" value="" id="ss0"></input>');
+  $output .= _adsense_add_nl('<label for="ss0" title="' . t('Search the Web') . '"><font size="-1" color="'. $box_text_color . '">Web</font></label></td>');
+  $output .= _adsense_add_nl('<td>');
+  $output .= _adsense_add_nl('<input type="radio" name="sitesearch" value="' . $domain_0 . '" checked id="ss1"></input>');
+  $output .= _adsense_add_nl('<label for="ss1" title="' . t('Search') . ' ' . $domain_0 . '"><font size="-1" color="' . $box_text_color .  '">' . $domain_0 . '</font></label></td>');
+  $output .= _adsense_add_nl('</tr>');
+  if($domain_1) {
+    $output .= _adsense_add_nl('<tr>');
+    $output .= _adsense_add_nl('<td>');
+    $output .= _adsense_add_nl('<input type="radio" name="sitesearch" value="' . $domain_1 . '" id="ss2"></input>');
+    $output .= _adsense_add_nl('<label for="ss2" title="Search ' . $domain_1 . '"><font size="-1" color="' . $box_text_color . '">' . $domain_1 . '</font></label></td>');
+    if($domain_2) {
+      $output .= _adsense_add_nl('<td>');
+      $output .= _adsense_add_nl('<input type="radio" name="sitesearch" value="' . $domain_2 .'" id="ss3"></input>');
+      $output .= _adsense_add_nl('<label for="ss3" title="Search ' . $domain_2 . '"><font size="-1" color="' . $box_text_color . '">' . $domain_2 . '</font></label></td>');
+    } else {
+      $output .= _adsense_add_nl('<td></td>');
+    }
+    $output .= _adsense_add_nl('</tr>');
+  }
+  $output .= _adsense_add_nl('</table>');
+
+  if($search_button) {
+    $output .= _adsense_add_nl('<label for="sbb" style="display: none">' . t('Submit search form') . '</label>');
+    if($logo != ADSENSE_SEARCH_LOGO_ON_BUTTON) {
+      $output .= _adsense_add_nl('<input type="submit" name="sa" value="' . t('Search')        . '" id="sbb"></input>');
+    } else {
+      $output .= _adsense_add_nl('<input type="submit" name="sa" value="' . t('Google Search') . '" id="sbb"></input>');
+    }
+  }
+
+  $output .= _adsense_add_nl('<input type="hidden" name="client" value="' . $client . '"></input>');
+  $output .= _adsense_add_nl('<input type="hidden" name="forid" value="1"></input>');
+  $output .= _adsense_add_nl('<input type="hidden" name="channel" value="' . $channel . '"></input>');
+  $output .= _adsense_add_nl('<input type="hidden" name="ie" value="' . $encoding . '"></input>');
+  $output .= _adsense_add_nl('<input type="hidden" name="oe" value="' . $encoding . '"></input>');
+  $output .= _adsense_add_nl('<input type="hidden" name="cof" value="GALT:#'          . $url
+                                                                 . ';GL:1;DIV:#'      . $border
+                                                                 . ';VLC:#'           . $visited
+                                                                 . ';AH:center;BGC:#' . $bg
+                                                                 . ';LBGC:#'          . $bg
+                                                                 . ';ALC:#'           . $title
+                                                                 . ';LC:#'            . $title
+                                                                 . ';T:#'             . $text
+                                                                 . ';GFNT:#'          . $light
+                                                                 . ';GIMP:#'          . $light
                                                                  . ';FORID:11"></input>');
-  $output .= _adsense_add_nl('<input type="hidden" name="hl" value="' . $language   . '"></input>');
-  $output .= _adsense_add_nl('<input type="submit" name="sa" value="' . t('Search') . '" class="form-submit"></input>');
+  $output .= _adsense_add_nl('<input type="hidden" name="hl" value="' . $language . '"></input>');
+  $output .= _adsense_add_nl('</td></tr></table>');
   $output .= _adsense_add_nl('</form>');
+  $output .= _adsense_add_nl(ADSENSE_SITE_SEARCH);
+  $output .= _adsense_add_nl('</div>');
 
   return $output;
 }
 
-function adsense_search() {
+function adsense_search($op = 'search', $keys = NULL) {
 
-  global $base_url;
-  $width   = variable_get(ADSENSE_SEARCH_FRAME_WIDTH, '500');
-  $domain  = variable_get(ADSENSE_SEARCH_DOMAIN     , $base_url);
-  $country = variable_get(ADSENSE_SEARCH_COUNTRY    , 'www.google.com');
+  if(!user_access('access adsense search result page')) return;
 
+  switch ($op) {
 
-  $output .= _adsense_add_nl(ADSENSE_SEARCH_RESULT_START);
-  $output .= _adsense_add_nl('<div id="googleSearchUnitIframe"></div>');
-
-  $output .= _adsense_add_nl('<script type="text/javascript">');
-  $output .= _adsense_add_nl('   var googleSearchIframeName = \'googleSearchUnitIframe\';');
-  $output .= _adsense_add_nl('   var googleSearchFrameWidth = ' . $width   . ';');
-  $output .= _adsense_add_nl('   var googleSearchFrameborder = 0 ;');
-  $output .= _adsense_add_nl('   var googleSearchDomain = \''   . $country . '\';');
-  $output .= _adsense_add_nl('</script>');
-  $output .= _adsense_add_nl('<script type="text/javascript"');
-  $output .= _adsense_add_nl('         src="http://www.google.com/afsonline/show_afs_search.js">');
-  $output .= _adsense_add_nl('</script>');
-  $output .= _adsense_add_nl(ADSENSE_SEARCH_RESULT_END);
+    case 'name':
+      return t('Google AdSense for Search');
 
-  return $output;
-}
+    case 'search':
+      global $base_url;
+      $width   = variable_get(ADSENSE_SEARCH_FRAME_WIDTH, '500');
+      $domain  = variable_get(ADSENSE_SEARCH_DOMAIN . '_0'     , $base_url);
+      $country = variable_get(ADSENSE_SEARCH_COUNTRY    , 'www.google.com');
+    
+      $output .= _adsense_add_nl(ADSENSE_SEARCH_RESULT_START);
+      $output .= _adsense_add_nl('<div id="googleSearchUnitIframe"></div>');
+    
+      $output .= _adsense_add_nl('<script type="text/javascript">');
+      $output .= _adsense_add_nl('   var googleSearchIframeName = \'googleSearchUnitIframe\';');
+      $output .= _adsense_add_nl('   var googleSearchFrameWidth = ' . $width   . ';');
+      $output .= _adsense_add_nl('   var googleSearchFrameborder = 0 ;');
+      $output .= _adsense_add_nl('   var googleSearchDomain = \''   . $country . '\';');
+      $output .= _adsense_add_nl('</script>');
+      $output .= _adsense_add_nl('<script type="text/javascript"');
+      $output .= _adsense_add_nl('         src="http://www.google.com/afsonline/show_afs_search.js">');
+      $output .= _adsense_add_nl('</script>');
+      $output .= _adsense_add_nl(ADSENSE_SEARCH_RESULT_END);
+      return $output;
+  }
+}
\ No newline at end of file
