Index: trip_search.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/trip_search/trip_search.module,v
retrieving revision 1.15
diff -u -r1.15 trip_search.module
--- trip_search.module	25 Oct 2004 19:39:12 -0000	1.15
+++ trip_search.module	30 Oct 2004 11:41:05 -0000
@@ -32,17 +32,54 @@
  */
 function trip_search_block($op = 'list', $delta = 0) {
   if ($op == 'list') {
-    $blocks[]['info'] = t('Search');
+    $blocks[0]['info'] = t('Search');
+    $blocks[1]['info'] = t('Recent Search Queries');
     return $blocks;
   }
   else {
-    if (user_access('search content')) {
-      $form = trip_search_form ($edit);
-      $block['subject'] = t('Search');
-      $block['content'] = $form;
-      return $block;
+    switch($delta) {
+      case 0:
+        if (user_access('search content')) {
+          $form = trip_search_form($edit);
+          $block['subject'] = t('Search');
+          $block['content'] = $form;
+        }
+        break;
+      case 1:
+        if (user_access('access recent search queries block')) {
+          $block['subject'] = t('Recent Search Queries');
+          $block['content'] = '';
+
+          // TODO: Don't hardcode the number of queries shown.
+          $result = db_query_range('SELECT * FROM {watchdog} WHERE type=\'message\' ORDER BY timestamp DESC', 0, 10);
+
+          if ($result) {
+            $block['content'] .= '<div class="item-list"><ul>';
+
+            while ($term = db_fetch_object($result)) {
+              // TODO: Queries may contain quotes. Handle that properly.
+
+              // Get the keyword(s).
+              preg_match('/"(.*)"/', $term->message, $matches);
+              $matches ? $keyword = $matches[1] : $keyword = '?';
+
+              // Get the number of results.
+              preg_match('/^(\d+)/', $term->message, $matches);
+              $matches ? $count = $matches[1] : $count = '?';
+
+              $block['content'] .= "<li>$keyword (<a href=\"trip_search/$keyword\">$count results</a>)</li>";
+            }
+
+            $block['content'] .= '</ul></div>';
+          }
+          else {
+            $block['content'] .= 'No search queries found.';
+          }
+        }
+        break;
     }
   }
+  return $block;
 }
 
 /**
@@ -67,7 +104,7 @@
  * Implementation of hook_perm().
  */
 function trip_search_perm() {
-  return array('search content');
+  return array('search content', 'access recent search queries block');
 }
 
 /**
