Index: top_searches.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/top_searches/top_searches.info,v
retrieving revision 1.1
diff -u -r1.1 top_searches.info
--- top_searches.info	10 Jun 2008 20:37:57 -0000	1.1
+++ top_searches.info	20 Dec 2008 20:28:04 -0000
@@ -1,3 +1,4 @@
 ; $Id: top_searches.info,v 1.1 2008/06/10 20:37:57 zstolar Exp $
 name = Top Searches
 description = Provides a list of top search phrase
+core = 6.x
\ No newline at end of file
Index: top_searches.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/top_searches/top_searches.install,v
retrieving revision 1.1
diff -u -r1.1 top_searches.install
--- top_searches.install	10 Jun 2008 20:37:57 -0000	1.1
+++ top_searches.install	20 Dec 2008 21:34:08 -0000
@@ -1,39 +1,52 @@
 <?php
+// $Id$
 
 function top_searches_install() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      $query1 = db_query("
-       CREATE TABLE {top_searches} (
-      `qid` INT( 11 ) NOT NULL AUTO_INCREMENT ,
-      `q` VARCHAR( 255 ) NOT NULL ,
-      `counter` INT( 11 ) NULL DEFAULT '0',
-      PRIMARY KEY ( `qid` ),
-      UNIQUE KEY `q` (`q`)
-      )");
-
-      if ($query1) {
-        $created = TRUE;
-      }
-      break;
-  }
-  if ($created) {
-    drupal_set_message(t('Top searches module installed successfully.'));
-  }
-  else {
-    drupal_set_message(t('Table installation for the Top Searches module was unsuccessful. The tables may need to be installed by hand.'), 'error');
-  }
+  // Create tables.
+  drupal_install_schema('top_searches');
+  drupal_set_message(t('Top searches module installed successfully.'));
 }
 
 function top_searches_uninstall() {
+  // Remove tables.
+  drupal_uninstall_schema('top_searches');
+
   switch ($GLOBALS['db_type']) {
     case 'mysql':
     case 'mysqli':
-      db_query("DROP TABLE {top_searches}");
       db_query("DELETE FROM {variable} WHERE name LIKE 'top_searches%'");
       cache_clear_all('variables', 'cache');
       break;
   }
 }
 
+function top_searches_schema() {
+  $schema['top_searches'] = array(
+    'fields' => array(
+      'qid' => array(
+        'type' => 'serial',
+        'length' => 11,
+        'not_null' => TRUE,
+        'unsigned' => TRUE,
+      ),
+      'q' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not_null' => TRUE,
+        'default' => ''
+      ),
+      'counter' => array(
+        'type' => 'int',
+        'length' => 11,
+        'not_null' => FALSE,
+        'default' => 0,
+        'unsigned' => TRUE
+      )
+    ),
+    'unique keys' => array(
+      'q' => array('q')
+    ),
+    'primary key' => array('qid')
+  );
+  return $schema;
+}
\ No newline at end of file
Index: top_searches.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/top_searches/top_searches.module,v
retrieving revision 1.1
diff -u -r1.1 top_searches.module
--- top_searches.module	10 Jun 2008 20:37:57 -0000	1.1
+++ top_searches.module	20 Dec 2008 22:02:50 -0000
@@ -1,28 +1,38 @@
 <?php
+// $Id: top_searches.module,v 1.2 2008/08/07 08:00:35 zstolar Exp $
+
+/* TODO Implement the hook_theme registry. Combine all theme registry entries
+   into one hook_theme function in each corresponding module file.
+function top_searches_theme() {
+  return array(
+    'top_searches_block' => array(
+      'file' => 'top_searches.module',
+      'arguments' => array(
+        'top_searches' => NULL,
+      ),
+    ),
+  );
+}; */
 
 /**
  * Implementation of hook_menu().
  */
-function top_searches_menu($may_cache) {
+function top_searches_menu() {
   $items = array();
-  if ($may_cache) {
-    $items[] = array(
-      'path' => 'admin/settings/top_searches',
-      'access' => user_access('administer blocks'),
-      'title' => t('Top Searches'),
-      'callback' => drupal_get_form,
-      'callback arguments' => array('top_searches_admin_form'),
-      'description' => t('General settings for the Top Searches module.'),
-    );
-    $items[] = array(
-      'path' => 'admin/settings/top_searches/clear',
-      'access' => user_access('administer blocks'),
-      'title' => t('Top Searches'),
-      'type' => MENU_CALLBACK,
-      'callback' => 'top_searches_form_clear',
-      'description' => t('General settings for the Top Searches module.'),
-    );
-  }
+  $items['admin/settings/top_searches'] = array(
+    'access arguments' => array('administer blocks'),
+    'title' => 'Top Searches',
+    'page callback' => drupal_get_form,
+    'page arguments' => array('top_searches_admin_form'),
+    'description' => 'General settings for the Top Searches module.',
+  );
+  $items['admin/settings/top_searches/clear'] = array(
+    'access arguments' => array('administer blocks'),
+    'title' => 'Top Searches',
+    'type' => MENU_CALLBACK,
+    'page callback' => 'top_searches_form_clear',
+    'description' => 'General settings for the Top Searches module.',
+  );
   return $items;
 }
 
@@ -49,7 +59,7 @@
   $form['clear_searches'] = array(
     '#type' => 'button',
     '#value' => t('Reset search counters'),
-    '#description' => top_searches_count_rows() . ' values'
+    '#description' => top_searches_count_rows() .' values'
   );
 
   return system_settings_form($form);
@@ -79,7 +89,7 @@
           $top_searches = top_searches_collect_results();
           if (count($top_searches)) {
             $block['subject'] = t("Top Searches");
-            $block['content'] = theme('top_searches_block', $top_searches);
+            $block['content'] = theme_top_searches_block($top_searches);
           }
           break;
       }
@@ -87,19 +97,26 @@
   }
 }
 
-function top_searches_form_alter($form_id, &$form) {
+function top_searches_form_alter(&$form, &$form_state, $form_id) {
+  // Don't count admin searches (like admin/user/search)
+  if (arg(0) == 'admin') return;
+
+  // Only count node searches
+  // TODO: allow different blocks for different types of seraches
+  if ($form['module']['#value'] != 'node') return;
+
   if ($form_id == 'search_form' || $form_id == 'search_block_form') {
-    $form['#submit'] = array_merge($form['#submit'], array('top_searches_catch_search_keys' => array()));
+    $form['#submit'] = array_merge($form['#submit'], array('top_searches_catch_search_keys'));
   }
 }
 
-function top_searches_catch_search_keys($form_id, $form_values) {
-  switch ($form_id) {
+function top_searches_catch_search_keys($form, $form_state) {
+  switch ($form['form_id']['#value']) {
     case "search_block_form":
-      $keys = $form_values['search_block_form_keys'];
+      $keys = $form_state['values']['search_block_form_keys'];
       break;
     case "search_form":
-      $keys = $form_values['keys'];
+      $keys = $form_state['values']['keys'];
       break;
   }
 
@@ -120,10 +137,8 @@
   $result = db_query("SELECT q, counter FROM {top_searches} ORDER by counter DESC LIMIT %d", variable_get('top_searches_block_items', 50));
   $top_searches = array();
 
-  if (db_num_rows($result)) {
-    while ($row = db_fetch_object($result)) {
+  while ($row = db_fetch_object($result)) {
       $top_searches[] = $row;
-    }
   }
   return $top_searches;
 }

