cvs -z9 diff -u -wb -F^function -- textlinkads.module (in directory C:\devtools\IRails\www\sites\default\modules\textlinkads\)
Index: textlinkads.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/textlinkads/textlinkads.module,v
retrieving revision 1.1.4.10
diff -u -w -b -F^function -r1.1.4.10 textlinkads.module
--- textlinkads.module	8 Feb 2007 19:26:29 -0000	1.1.4.10
+++ textlinkads.module	26 Apr 2007 05:59:04 -0000
@@ -1,5 +1,16 @@
 <?php
 
+  /**
+   
+  *  Support multiple inventory keys per site
+  *  1.  Multiple blocks? (with a key per block) - let drupal block visibility system manage visibility?
+  *      
+  *  2. Database changes - store inventory key?
+  *  3. Cron changes
+  *  4. Settings changes
+  *     Inventory key(s), path mach pattern? 
+  *     Module will provide block per key
+   */
 define('TEXTLINKADS_VERSION', '$Id: textlinkads.module,v 1.1.4.10 2007/02/08 19:26:29 kbahey Exp $');
 define('TEXTLINKADS_MODULE_PATH', drupal_get_path('module', 'textlinkads'));
 
@@ -67,24 +78,29 @@ function textlinkads_menu($may_cache) {
   return $items;
 }
 
+function textlinkads_get_keys() {
+  $keys = explode(',', variable_get('textlinkads_website_xml_key', ''));
+  return $keys;
+}
+
 function textlinkads_block($op = 'list', $delta = 0, $edit = array()) {
+  $keys = textlinkads_get_keys();
+  $nblocks = count($keys);
   switch ($op) {
     case 'list':
-      $blocks[0]['info'] = t('text link ads advertisments');
+      for ($i = 0; $i < $nblocks; $i++) {
+        $blocks[$i]['info'] = t('TLA Block for key= !key', array('!key'=>$keys[$i]));
+      }
       return $blocks;
     case 'view':
-      switch ($delta) {
-        case 0:
-          $block['subject'] = t(variable_get('textlinkads_ad_block_title', 'Advertisments'));
-          $block['content'] = textlinkads_content();
-          break;
-      }
+      $block['subject'] = t(variable_get('textlinkads_ad_block_title', t('Advertisements')));
+      $block['content'] = textlinkads_content($keys[$delta]);
       return $block;
   }
 }
 
-function textlinkads_content() {
-  $output = theme('textlinkads_ads', textlinkads_get_links('text'));
+function textlinkads_content($key) {
+  $output = theme('textlinkads_ads', textlinkads_get_links('text', $key), $key);
   return $output;
 }
 
@@ -96,9 +112,9 @@ function textlinkads_settings() {
 
   $form['textlinkads_website_xml_key'] = array(
     '#type' => 'textfield',
-    '#title' => t('Website XML Key'),
+    '#title' => t('Website XML Keys'),
     '#default_value' => variable_get('textlinkads_website_xml_key', ''),
-    '#description' => t('You get your XML Site Key from the <a href="http://www.text-link-ads.com/my_account.php?view=my_sites">Get Ad Code page</a> on Text-Link-Ads.com. Each of your sites has its own code that looks something like this: <code>A4WWSAAOULU1XGHWU78G</code>.'),
+    '#description' => t('A comma-separated list of keys.  You get your XML Site Key from the <a href="http://www.text-link-ads.com/my_account.php?view=my_sites">Get Ad Code page</a> on Text-Link-Ads.com. Each of your sites has its own code that looks something like this: <code>A4WWSAAOULU1XGHWU78G</code>.'),
   );
   $form['textlinkads_ad_block_title'] = array(
     '#type' => 'textfield',
@@ -108,8 +124,8 @@ function textlinkads_settings() {
   );
 
   drupal_set_html_head(textlinkads_get_js());
-  $total_options = drupal_map_assoc(array(4, 6, 8, 10));
-  $row_options = drupal_map_assoc(array(1, 2, 3, 4, 8, 10));
+  $total_options = drupal_map_assoc(array(4, 6, 8, 12));
+  $row_options = drupal_map_assoc(array(1, 2, 3, 4, 8, 12));
   $font_options = drupal_map_assoc(array(6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18));
 
   $form['textlinkads_themer'] = array('#type' => 'fieldset', '#title' => t('Textlinkads Appearance Settings'));
@@ -189,7 +205,11 @@ function textlinkads_nodeapi(&$node, $op
 }
 
 function textlinkads_stats_page() {
-  if (!$key = variable_get('textlinkads_website_xml_key', '')) {
+  // @todo: fix this to work with multi-keys
+  $keys = textlinkads_get_keys();
+  $key = $keys[0]; // first key is RSS key - sucks, needs to be smarter
+
+  if (!$key) {
     drupal_set_message(t('You need to enter your Customer ID on the <a href="%admin">administration page</a> before you can view your statistics here.', array('%admin' => url('admin/settings/textlinkads'))), 'error');
     print theme('page', '');
     return;
@@ -236,7 +256,7 @@ function theme_textlinkads_rss_ad($link)
 }
 
 
-function theme_textlinkads_ads($links) {
+function theme_textlinkads_ads($links, $key) {
   $output = '';
 
   $font_size = variable_get('textlinkads_font', 12);
@@ -316,18 +336,31 @@ function theme_textlinkads_themer_colors
  */
 function textlinkads_check_update() {
   $CONNECTION_TIMEOUT = 10;
-  $url = 'http://www.text-link-ads.com/xml.php?inventory_key=' . check_plain(variable_get(textlinkads_website_xml_key, ''))
+  // enumerate inventory keylist - pass key to textlinkads_update_links function
+  $keys = textlinkads_get_keys();
+  $nkeys = count($keys);
+
+  $prevcount = db_result(db_query("SELECT COUNT(*) FROM {textlinkads}"));
+  db_query("DELETE FROM {textlinkads}");
+  $count = 0;
+  for ($i=0; $i<$nkeys; $i++) {
+    $key = $keys[$i];
+    $url = 'http://www.text-link-ads.com/xml.php?inventory_key=' . check_plain($key)
     . '&referer=' . urlencode($_SERVER['REQUEST_URI'])
     . '&user_agent=' . urlencode($_SERVER['HTTP_USER_AGENT'])
     . '&drupal_module_version=' . urlencode(TEXTLINKADS_VERSION);
-  textlinkads_update_links($url, $CONNECTION_TIMEOUT);
+    $count += textlinkads_update_links($url, $CONNECTION_TIMEOUT, $key);
+  }
+  // report changes as appropriate
+  if ($count != $prevcount) {
+    watchdog('TextLinkAds', "update_links: Inventory change (was: $prevcount now: $count)" );
+  }
+  variable_set('textlinkads_last_update', time());
 }
 
-function textlinkads_update_links($url, $time_out) {
+function textlinkads_update_links($url, $time_out, $inventory_key) {
   $xml = textlinkads_file_get_contents($url, $time_out);
   $xml = substr($xml, strpos($xml, '<?'));
-
-  db_query("DELETE FROM {textlinkads}");
   $parser = new xml2array();
   if ($data = $parser->parseXMLintoarray($xml)) {
     // there are no links or just one link
@@ -348,12 +381,10 @@ function textlinkads_update_links($url, 
       }
     }
     foreach ($links as $key => $values) {
-      db_query("INSERT INTO {textlinkads} (url, text, beforetext, aftertext, rsstext, rssbeforetext, rssaftertext) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s')", $values['URL'], $values['TEXT'], $values['BEFORETEXT'], $values['AFTERTEXT'], $values['RSSTEXT'], $values['RSSBEFORETEXT'], $values['RSSAFTERTEXT']);
+      db_query("INSERT INTO {textlinkads} (url, text, beforetext, aftertext, rsstext, rssbeforetext, rssaftertext, inventory_key) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $values['URL'], $values['TEXT'], $values['BEFORETEXT'], $values['AFTERTEXT'], $values['RSSTEXT'], $values['RSSBEFORETEXT'], $values['RSSAFTERTEXT'], $inventory_key);
     }
   }
-  $count=count($links);
-  watchdog('TextLinkAds', "update_links: $count ads found" );
-  variable_set('textlinkads_last_update', time());
+  return count($links);
 }
 
 /**
@@ -364,7 +395,9 @@ function textlinkads_next_rss_ad() {
   static $links = NULL;
 
   if (!is_array($links)) {
-    $links = textlinkads_get_links('rss');
+    $keys = textlinkads_get_keys();
+    $key = $keys[0]; // rss is first key
+    $links = textlinkads_get_links('rss', $key);
     shuffle($links);
   }
 
@@ -376,12 +409,16 @@ function textlinkads_next_rss_ad() {
  *
  * @param string $type
  *   'text' or 'rss'
+ * @param $key The inventory key if not null
  * @return Array
  */
-function textlinkads_get_links($type = 'text') {
+function textlinkads_get_links($type = 'text', $key=NULL) {
   $links = array();
   $limit = ($type == 'text') ? variable_get('textlinkads_total', 4) : variable_get('feed_default_items', 10);
   $where = ($type == 'text') ? 'text IS NOT NULL && beforetext IS NOT NULL && aftertext IS NOT NULL' : 'rsstext IS NOT NULL';
+  if ($key) {
+    $where .= " AND inventory_key='$key'";
+  }
   $result = db_query("SELECT * FROM {textlinkads}  WHERE $where LIMIT %d", $limit);
   while ($row = db_fetch_array($result)) {
     $links[] = $row;

***** CVS exited normally with code 1 *****