Index: adsense.module
===================================================================
--- adsense.module	(revision 6966)
+++ adsense.module	(working copy)
@@ -41,7 +41,6 @@
 }
 
 define('ADSENSE_MAX_GROUPS',                  5);
-define('ADSENSE_MAX_CHANNELS',                7);
 define('ADSENSE_MAX_BLOCKS',                  8);
 define('ADSENSE_VISIBILITY',                  'adsense_visibility');
 define('ADSENSE_ACCESS_PAGES',                'adsense_access_pages');
@@ -53,7 +52,6 @@
 define('ADSENSE_COLOR_URL',                   'adsense_color_url_');
 define('ADSENSE_ALT',                         'adsense_alt_');
 define('ADSENSE_ALT_INFO',                    'adsense_alt_info_');
-define('ADSENSE_AD_CHANNEL',                  'adsense_ad_channel_');
 define('ADSENSE_REVENUE_ENABLE',              'adsense_revenue_enable');
 define('ADSENSE_PERCENTAGE_AUTHOR',           'adsense_percentage_author');
 define('ADSENSE_PERCENTAGE_REFER',            'adsense_percentage_refer');
@@ -71,6 +69,7 @@
 define('ADSENSE_SECTION_START',               '<!-- google_ad_section_start -->');
 define('ADSENSE_SECTION_IGNORE',              '<!-- google_ad_section_start(weight=ignore) -->');
 define('ADSENSE_SECTION_END',                 '<!-- google_ad_section_end -->');
+define('ADSENSE_MULTI_CHANNEL_PATTERN',       '\d[\d\+]+\d');
 
 function adsense_get_ad_code($format) {
   $all_ads = adsense_ad_formats();
@@ -296,10 +295,16 @@
     '#collapsible' => true,
     '#collapsed' => true,
     '#title' => t('Custom channels'),
-    '#description' => t('Enter up to !channels custom channels that you have configured in Google AdSense. If you are not using custom channels, or you are only using URL channels, then leave this empty.', array('!channels' => ADSENSE_MAX_CHANNELS)),
+    '#description' => t('Enter any custom channels that you have configured in Google AdSense. If you are not using custom channels, or you are only using URL channels, then leave this empty.'),
   );
 
-  for($channel=1; $channel<ADSENSE_MAX_CHANNELS+1; $channel++) {
+  $result = db_query('SELECT channel_id, channel_name'
+      . ' FROM {adsense_channels}');
+  /*
+      Custom Channel UI -- Not possible(?) at the moment without changing
+      that call to system_settings_form at the bottom of this function
+  while ($row = db_fetch_object($result)) {
+    $channel_list[$row->channel_id] = $row->channel_name;
     $form['channels'][ADSENSE_AD_CHANNEL . $channel] = array(
       '#type' => 'textfield',
       '#title' => t('Custom channel ID ') . $channel,
@@ -308,6 +313,7 @@
       '#maxlength' => 30,
     );
   }
+  */
 
   $form['revenue'] = array(
     '#type' => 'fieldset',
@@ -618,12 +624,11 @@
   return $group;
 }
 
-function _adsense_validate_channel($channel = 1) {
-  if ($channel < 1 || $channel > ADSENSE_MAX_CHANNELS) {
-    // Default to 1 if an invalid channel is supplied
-    return 1;
+function _adsense_validate_channel($channel = '') {
+  if (preg_match('/'.ADSENSE_MULTI_CHANNEL_PATTERN.'/', $channel)) {
+    return $channel;
   }
-  return $channel;
+  return '';
 }
 
 function _adsense_format($format, $group = 1, $channel = 1) {
@@ -641,7 +646,7 @@
   $alt      = variable_get(ADSENSE_ALT .          $group, 0);
   $alt_info = variable_get(ADSENSE_ALT_INFO .     $group, '');
 
-  $channel = variable_get(ADSENSE_AD_CHANNEL . _adsense_validate_channel($channel), '');
+  $channel  = _adsense_validate_channel($channel);
 
   switch (variable_get(ADSENSE_AD_TYPE . $group, '0')) {
     case 2:
@@ -786,7 +791,7 @@
   $patterns = array(
     'flexi' => '/\[adsense:flexiblock:(\d+)\]/x',
     'block' => '/\[adsense:block:(\d+)\]/x',
-    'tags'  => '/\[adsense:(\w+):(\d+):(\d+)\]/x');
+    'tags'  => '/\[adsense:(\w+):(\d+):('.ADSENSE_MULTI_CHANNEL_PATTERN.')\]/x');
 
   foreach($patterns as $mode => $pattern) {
     if (preg_match_all($pattern, $text, $matches, PREG_SET_ORDER)) {
@@ -858,8 +863,10 @@
         $group_list[$group] = 'Group ' . $group;
       }
 
-      for($channel=1; $channel<ADSENSE_MAX_CHANNELS+1; $channel++) {
-        $channel_list[$channel] = 'Channel ' . $channel;
+      $result = db_query('SELECT channel_id, channel_name'
+          . ' FROM {adsense_channels}');
+      while ($row = db_fetch_object($result)) {
+        $channel_list[$row->channel_id] = $row->channel_name;
       }
 
       $form['ad_format'] = array(
@@ -877,11 +884,16 @@
       );
 
       $form['ad_channel'] = array(
-        '#type' => 'select',
+        '#type' => 'checkboxes',
         '#title' => t('Channel'),
         '#default_value' => ($ad) ? $ad[2] : 1,
         '#options' => $channel_list,
       );
+      if (count($channel_list) == 0)
+      {
+         $form['ad_channel']['#suffix'] = '<p>'.t('Set up your channels on the <a href="@adsense-config">adsense configuration</a> page.',
+               array('@adsense-config' => url('admin/settings/adsense'))).'</p>';
+      }
 
       return $form;
 
Index: adsense.install
===================================================================
--- adsense.install	(revision 6966)
+++ adsense.install	(working copy)
@@ -13,6 +13,12 @@
         PRIMARY KEY  (aid),
         KEY (timestamp)
         ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
+      $success = $success && db_query(
+        "CREATE TABLE IF NOT EXISTS {adsense_channels} (
+        channel_id   VARCHAR(20) NOT NULL,
+        channel_name VARCHAR(255) NOT NULL,
+        PRIMARY KEY (channel_id)
+        ) /*!40100 DEFAULT CHARACTER SET utf8 */");
       break;
     case 'pgsql':
       $success = db_query("CREATE TABLE {adsense_clicks} (
@@ -38,6 +44,7 @@
  */
 function adsense_uninstall() {
   db_query('DROP TABLE {adsense_clicks}');
+  db_query('DROP TABLE {adsense_channels}');
 }
 
 function adsense_update_1() {
@@ -53,3 +60,18 @@
   }
 }
 
+function adsense_update_3() {
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      db_query("CREATE TABLE IF NOT EXISTS {adsense_channels} (
+        channel_id   VARCHAR(20) NOT NULL,
+        channel_name VARCHAR(255) NOT NULL,
+        PRIMARY KEY (channel_id)
+        ) /*!40100 DEFAULT CHARACTER SET utf8 */");
+      for($channel=1; $channel<ADSENSE_MAX_CHANNELS+1; $channel++) {
+        variable_del(ADSENSE_AD_CHANNEL . $channel);
+      }
+      break;
+  }
+}
