Index: zeitgeist.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/zeitgeist/zeitgeist.module,v
retrieving revision 1.9.4.5
diff -u -r1.9.4.5 zeitgeist.module
--- zeitgeist.module	31 Oct 2007 19:31:22 -0000	1.9.4.5
+++ zeitgeist.module	19 Nov 2007 15:41:29 -0000
@@ -31,6 +31,8 @@
 define('ZGONEDAY',         86400);                   // 24 hours * 60 minutes * 60 seconds
 define('ZGPATHSETTINGS',   'admin/settings/zeitgeist');
 define('ZGPATHPAGE',       'admin/logs/zeitgeist');
+define('ZGCIDLATEST',      'zeitgeist-latest');
+define('ZGCIDTOP',         'zeitgeist-top');
 
 /**
  * Enumerations
@@ -61,8 +63,10 @@
  */
 define('ZGVARLATESTCLEAR', 'zeitgeist_latest_clear'); // What is the data of the latest history clear ?
 define('ZGVARLATESTCOUNT', 'zeitgeist_latest_count'); // How many recent searches are displayed in their block ?
+define('ZGVARLATESTCACHE', 'zeitgeist_latest_cache'); // Block minimum caching duration in minutes
 define('ZGVARTOPCOUNT',    'zeitgeist_top_count');    // How many top queries are displayed in their block ?
 define('ZGVARTOPSPAN',     'zeitgeist_top_span');     // ZG span for the top queries block
+define('ZGVARTOPCACHE',    'zeitgeist_top_cache');    // Block minimum caching duration in minutes
 define('ZGVARHISTORY',     'zeitgeist_history');      // How long does the module keep its historical data.
 define('ZGVARNOFOLLOW',    'zeitgeist_nofollow');     // Emit a rel=nofollow attribute in feature blocks
 define('ZGVARPAGEHEIGHT',  'zeitgeist_page_height');  // Number of rows on the zeitgeist pager
@@ -86,8 +90,8 @@
 /**
  * Block deltas
  */
-define('ZGBLOCKLATEST',    0);
-define('ZGBLOCKTOP',       1);
+define('ZGBLOCKLATEST',    'latest');
+define('ZGBLOCKTOP',       'top');
 
 /**
  * implement hook_help
@@ -158,17 +162,31 @@
  */
 function zeitgeist_admin_settings()
   {
-  $form[ZGVARLATESTCOUNT] = array
+  $form[ZGVARHISTORY]     = array
     (
     '#type'               => 'textfield',
-    '#title'              => t('Recent searches displayed'),
-    '#description'        => t('This is the number of recent searches displayed in the "Recent Searches" block provided by the zeitgeist module. Default: %def.',
-                               array('%def' => ZGDEFLATESTCOUNT)),
-    '#default_value'      => variable_get(ZGVARLATESTCOUNT, ZGDEFLATESTCOUNT),
-    '#maxlength'          => 2,
-    '#size'               => 2,
+    '#title'              => t('Number of days of history'),
+    '#description'        => t('Historical data are kept for that number of days. 0 means forever. Pruning is performed by cron on a daily basis'),
+    '#default_value'      => variable_get(ZGVARHISTORY, ZGDEFHISTORY),
+    '#size'               => 4, // this is good until 2037, should be enough for all 5.x needs.
+    '#maxlength'          => 4,
+    );
+    
+  $form['zeitgeist-display'] = array
+    (
+    '#type'               => 'fieldset',
+    '#title'              => t('Display settings'),
+    '#collapsible'        => TRUE,
+    );
+    
+  $form['zeitgeist-display']['zeitgeist-top'] = array
+    (
+    '#type'               => 'fieldset',
+    '#title'              => t('"Top searches" block'),
+    '#collapsible'        => TRUE,
+    '#collapsed'          => TRUE,
     );
-  $form[ZGVARTOPCOUNT] = array
+  $form['zeitgeist-display']['zeitgeist-top'][ZGVARTOPCOUNT] = array
     (
     '#type'               => 'textfield',
     '#title'              => t('Top searches displayed'),
@@ -178,27 +196,37 @@
     '#maxlength'          => 2,
     '#size'               => 2,
     );
-  $form[ZGVARHISTORY]     = array
+  $form['zeitgeist-display']['zeitgeist-top'][ZGVARTOPCACHE] = array
     (
     '#type'               => 'textfield',
-    '#title'              => t('Number of days of history'),
-    '#description'        => t('Historical data are kept for that number of days. 0 means forever. Pruning is performed by cron on a daily basis'),
-    '#default_value'      => variable_get(ZGVARHISTORY, ZGDEFHISTORY),
-    '#size'               => 4, // this is good until 2037, should be enough for all 5.x needs.
-    '#max_length'         => 4,
+    '#title'              => t('Cache expiration'),
+    '#description'        => t('Block minimum caching duration in minutes (1 day = 1440 minutes). Note that blocks are cached as themed.'),
+    '#default_value'      => variable_get(ZGVARTOPCACHE, 0),
+    '#size'               => 5,
+    '#maxlength'          => 5,
+    );
+    
+  $form['zeitgeist-display']['zeitgeist-latest'] = array
+    (
+    '#type'               => 'fieldset',
+    '#title'              => t('"Latest searches" block'),
+    '#collapsible'        => TRUE,
+    '#collapsed'          => TRUE,
     );
-  $form[ZGVARPAGEHEIGHT]  = array
+  $form['zeitgeist-display']['zeitgeist-latest'][ZGVARLATESTCOUNT] = array
     (
     '#type'               => 'textfield',
-    '#title'              => t('Height of the zeitgeist pager'),
-    '#default_value'      => variable_get(ZGVARPAGEHEIGHT, ZGDEFPAGEHEIGHT),
-    '#size'               => 3,
-    '#max_length'         => 3,
+    '#title'              => t('Latest searches displayed'),
+    '#description'        => t('This is the number of recent searches displayed in the "Latest Searches" block provided by the zeitgeist module. Default: %def.',
+                               array('%def' => ZGDEFLATESTCOUNT)),
+    '#default_value'      => variable_get(ZGVARLATESTCOUNT, ZGDEFLATESTCOUNT),
+    '#maxlength'          => 2,
+    '#size'               => 2,
     );
-  $form[ZGVARTYPE]        = array
+  $form['zeitgeist-display']['zeitgeist-latest'][ZGVARTYPE]        = array
     (
     '#type'               => 'radios',
-    '#title'              => t('When should the search type be displayed in the "recent searches" blocks ?'),
+    '#title'              => t('When should the search type be displayed in the "Latest searches" block ?'),
     '#default_value'      => variable_get(ZGVARTYPE, ZGDEFTYPE),
     '#options'            => array
       (
@@ -209,10 +237,43 @@
       ),
     '#description'        => t('<p>Recommended value is "Admin only"; "Always" is typically disturbing for visitors not already well-versed in Drupal.</p>'),
     );
-  $form[ZGVARVALIDATION]    = array
+  $form['zeitgeist-display']['zeitgeist-latest'][ZGVARLATESTCACHE] = array
+    (
+    '#type'               => 'textfield',
+    '#title'              => t('Cache expiration'),
+    '#description'        => t('Block minimum caching duration in minutes (1 day = 1440 minutes). Note that blocks are cached as themed.'),
+    '#default_value'      => variable_get(ZGVARLATESTCACHE, 0),
+    '#size'               => 5,
+    '#maxlength'          => 5,
+    );
+    
+  $form['zeitgeist-display']['zeitgeist-page'] = array
+    (
+    '#type'               => 'fieldset',
+    '#title'              => t('Default zeitgeist page'),
+    '#collapsible'        => TRUE,
+    '#collapsed'          => TRUE,
+    );
+  $form['zeitgeist-display']['zeitgeist-page'][ZGVARPAGEHEIGHT]  = array
+    (
+    '#type'               => 'textfield',
+    '#title'              => t('Height of the zeitgeist pager'),
+    '#default_value'      => variable_get(ZGVARPAGEHEIGHT, ZGDEFPAGEHEIGHT),
+    '#size'               => 3,
+    '#maxlength'          => 3,
+    );
+   
+  $form['zeigeist-filtering'] = array
+    (
+    '#type'               => 'fieldset',
+    '#title'              => t('Search filtering'),
+    '#collapsible'        => TRUE,
+    '#collapsed'          => TRUE,
+    );
+  $form['zeigeist-filtering'][ZGVARVALIDATION]    = array
     (
     '#type'               => 'radios',
-    '#title'              => t('How should search strings be validated to prevent spamming "recent searches" blocks ?'),
+    '#title'              => t('How should search strings be validated to prevent spamming ZG blocks ?'),
     '#default_value'      => variable_get(ZGVARVALIDATION, ZGDEFVALIDATION),
     '#options'            => array
       (
@@ -222,7 +283,7 @@
       ),
     '#description'        => t('<p>Recommended value is "Do not record HTML": spammers may abuse ZG by submitting links via scripts.</p>'),
     );
-  $form[ZGVARRECORDEMPTY] = array
+  $form['zeigeist-filtering'][ZGVARRECORDEMPTY] = array
     (
     '#type'               => 'checkbox',
     '#title'              => t('Should Zeitgeist record empty searches ?'),
@@ -323,11 +384,11 @@
   switch ($op)
     {
     case 'list':
-      $blocks[ZGBLOCKLATEST]['info'] = t(variable_get('zeitgeist_latest_info', t('ZG Latest %count')),
-        array('%count' => variable_get(ZGVARLATESTCOUNT, ZGDEFLATESTCOUNT))
+      $blocks[ZGBLOCKLATEST]['info'] = t(variable_get('zeitgeist_latest_info', t('ZG Latest !count')),
+        array('!count' => variable_get(ZGVARLATESTCOUNT, ZGDEFLATESTCOUNT))
         );
-      $blocks[ZGBLOCKTOP]['info'] = t(variable_get('zeitgeist_top_info', t('ZG Top %count')),
-        array('%count' => variable_get(ZGVARTOPCOUNT, ZGDEFTOPCOUNT))
+      $blocks[ZGBLOCKTOP]['info'] = t(variable_get('zeitgeist_top_info', t('ZG Top !count')),
+        array('!count' => variable_get(ZGVARTOPCOUNT, ZGDEFTOPCOUNT))
         );
       return $blocks;
       break;
@@ -338,21 +399,22 @@
         case ZGBLOCKLATEST:
           $form = array();
           _zeitgeist_block_settings_show($form,
-            t('Name of the block in the block list'), 'latest', t('ZG Latest %count'),
-            t('Title of the block when displayed'),   'latest', t('Latest %count searches')
+            t('Name of the block in the block list'), 'latest', t('ZG Latest !count'),
+            t('Title of the block when displayed'),   'latest', t('Latest searches')
             );
           break;
         case ZGBLOCKTOP:
           $form = array();
           _zeitgeist_block_settings_show($form,
-            t('Name of the block in the block list'), 'top', t('ZG Top %count'),
-            t('Title of the block when displayed'),   'top', t('Top %count searches')
+            t('Name of the block in the block list'), 'top', t('ZG Top !count'),
+            t('Title of the block when displayed'),   'top', t('Top searches')
             );
           break;
         default:
           $form = array();
           break;
         }
+      zeitgeist_admin_settings_submit(NULL, NULL); // clear cache
       return $form;
       break;
 
@@ -360,10 +422,10 @@
       switch ($delta)
         {
         case ZGBLOCKLATEST:
-          _zeitgeist_block_settings_save($edit, 'latest');
+          _zeitgeist_block_settings_save($edit, ZGBLOCKLATEST);
           break;
         case ZGBLOCKTOP:
-          _zeitgeist_block_settings_save($edit, 'top');
+          _zeitgeist_block_settings_save($edit, ZGBLOCKTOP);
           break;
         }
       break;
@@ -371,19 +433,35 @@
       switch ($delta)
         {
         case ZGBLOCKLATEST:
-          $count = variable_get(ZGVARLATESTCOUNT, ZGDEFLATESTCOUNT);
-          $subject = variable_get('zeitgeist_latest_title', t('Latest %count searches'));
-          $subject = t($subject, array('%count' => $count));
-          $block['subject'] = $subject;
-          $block['content'] = theme('zeitgeist_block_latest', $count);
+          $now = time();
+          $cache = cache_get(ZGCIDLATEST, 'cache');
+          if (empty($cache) || ($now >= $cache->expire))
+            {
+            $block = array
+              (
+              'subject' => 'foo latest',
+              'content' => theme('zeitgeist_block_latest'),
+              );
+            cache_set(ZGCIDLATEST, 'cache', serialize($block), $expires = $now + 60 * variable_get(ZGVARLATESTCACHE, 0));
+            }
+          else
+            {
+            $block = unserialize($cache->data);
+            }
           break;
         case ZGBLOCKTOP:
-          $count = variable_get(ZGVARTOPCOUNT, ZGDEFTOPCOUNT);
-          $subject = variable_get('zeitgeist_top_title', t('Top %count searches'));
-          $subject = t($subject, array('%count' => $count));
-          $block['subject'] = $subject;
-          $block['content'] = theme('zeitgeist_block_top', $count);
-        break;
+          $now = time();
+          $cache = cache_get(ZGCIDTOP, 'cache');
+          if (empty($cache) || ($now >= $cache->expire))
+            {
+            $block = array('content' => theme('zeitgeist_block_top', $count));
+            cache_set(ZGCIDTOP, 'cache', serialize($block), $expires = $now + 60 * variable_get(ZGVARTOPCACHE, 0));
+            }
+          else
+            {
+            $block = unserialize($cache->data);
+            }
+          break;
         }
       return $block;
       break;
@@ -405,8 +483,9 @@
   }
 
 /**
- * Provides the block-specific contents common to each ZG block: ability to rename the block and change its title
- *
+ * Provides the block-specific contents common to each ZG block: 
+ * ability to rename the block. 
+ * 
  * @param array $form The current form for which this is built
  * @param string $infotitle Block information: the title
  * @param string $infovar Block information: the config variable name
@@ -431,15 +510,15 @@
     (
     '#type'          => 'textfield',
     '#title'         => $titletitle,
-    '#default_value' => variable_get('zeitgeist_' . $titlevar . '_title', $titledefault),
-    '#weight'        => -1,
+    '#default_value' => variable_get('zeitgeist_' . $titlevar . '_info', $titledefault),
+    '#weight'        => -2,
     );
   }
 
 function _zeitgeist_block_settings_save($edit, $blockname)
   {
   variable_set('zeitgeist_' . $blockname . '_info',  $edit['info' ]);
-  variable_set('zeitgeist_' . $blockname . '_title', $edit['title']);
+  variable_set('zeitgeist_' . $blockname . '_title',  $edit['title' ]);
   }
 
 /**
@@ -640,8 +719,11 @@
  *
  * @param int $count
  */
-function theme_zeitgeist_block_top($count = null)
+function theme_zeitgeist_block_top()
   {
+  $block = array();
+  $count = variable_get(ZGVARTOPCOUNT, ZGDEFTOPCOUNT);
+     
   $ts = null;
 
   /**
@@ -668,7 +750,7 @@
 
   $ret = theme('item_list', $arScores);
   unset($arScores);
-
+  
   return $ret;
   }
 
@@ -879,4 +961,17 @@
   $ret .= t('<p>Searches below the pager !limit are not included in this list.</p>',
     array('!limit' => l(t('limit'), ZGPATHSETTINGS)));
   return $ret;
+  }
+
+/**
+ * When changing ZG settings, clear the ZG block cache, since its content
+ * will often be affected by the changes.
+ *
+ * @param string $form_id
+ * @param array $form_values
+ */
+function zeitgeist_admin_settings_validate($form_id, $form_values)
+  {
+  cache_clear_all(ZGCIDLATEST, 'cache');
+  cache_clear_all(ZGCIDTOP, 'cache');
   }
\ No newline at end of file
Index: zeitgeist.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/zeitgeist/Attic/zeitgeist.install,v
retrieving revision 1.1.4.4
diff -u -r1.1.4.4 zeitgeist.install
--- zeitgeist.install	27 Oct 2007 13:16:50 -0000	1.1.4.4
+++ zeitgeist.install	19 Nov 2007 15:42:40 -0000
@@ -22,6 +22,31 @@
   }
 
 /**
+ * The index on ts should not normally be there but dropping it anyway make the
+ * update idempotent, and helps cover the case where users already applied such
+ * an index, making the update safer.
+ *
+ * @return array
+ */
+function zeitgeist_update_2()
+  {
+  $items = array();
+  $sq = "SHOW INDEX FROM {zeitgeist}";
+  $q = db_query($sq);
+  while ($o = db_fetch_object($q))
+    {
+    if ($o->Key_name == 'ts')
+      {
+      $items[] = update_sql("ALTER TABLE {zeitgeist} DROP INDEX `ts` ");
+      break;
+      }
+    }
+  $items[] = update_sql("ALTER TABLE {zeitgeist} ADD INDEX ( `ts` )");
+      
+  return $items;
+  }
+
+/**
  * implementation of hook_install from #72166 and #72662 combined
  *
  * @return void
