Index: DrupalGoogleMini.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/google_appliance/DrupalGoogleMini.php,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 DrupalGoogleMini.php
--- DrupalGoogleMini.php	18 Aug 2008 01:31:30 -0000	1.1.2.1
+++ DrupalGoogleMini.php	23 Feb 2009 00:37:30 -0000
@@ -1,8 +1,4 @@
 <?php
-
-
-define('GOOGLE_MINI_MAX_RESULTS', variable_get('google_appliance_max_results', 1000));
-
 include_once 'GoogleMini.php';
 
 class DrupalGoogleMini extends GoogleMini {
@@ -13,15 +9,7 @@ class DrupalGoogleMini extends GoogleMin
     parent::__construct($debug,$debug_callback);
   }
   
-  function log($message = null) {
-    if ($this->debug_callback) {
-      $callback = $this->debug_callback;
-      call_user_func($callback,$message);
-    }
-    watchdog("google_appliance",$message);
-  }
-  
-  function query($iteratorClass = 'GoogleMiniResultIterator') {
+  function query($iteratorClass = 'GoogleMiniresult_iterator') {
     if (!db_table_exists('cache_google')) {
       $this->cache = false;
     }
@@ -40,19 +28,19 @@ class DrupalGoogleMini extends GoogleMin
             dpr("got cache for $cache_key");
           }
         } elseif ($google_debug == 1)  {
-          watchdog('amnestysearch',"got cache for $cache_key at" . $_GET['q']);
+          watchdog('google_search',"got cache for $cache_key at" . $_GET['q']);
         }
       } else {
         $google_results = parent::query($iteratorClass);
         //10 Min cache by default
-        cache_set($cache_key,'cache_google',$google_results->payload->asXML(),time() + variable_get('google_appliance_cache_timeout',600));
+        cache_set($cache_key,$google_results->payload->asXML(),'cache_google',time() + variable_get('google_appliance_cache_timeout',600));
         $google_debug = variable_get('google_debug',0);
         if ($google_debug >= 2 ){
           if (function_exists('dpr')) {
             dpr("setting cache for $cache_key");
           }
         } elseif ($google_debug == 1)  {
-          watchdog('amnestysearch',"setting cache for $cache_key at" . $_GET['q']);
+          watchdog('google_search',"setting cache for $cache_key at" . $_GET['q']);
         }
       }
       return $google_results;
Index: GoogleMini.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/google_appliance/GoogleMini.php,v
retrieving revision 1.1.2.3
diff -u -p -r1.1.2.3 GoogleMini.php
--- GoogleMini.php	18 Aug 2008 01:39:46 -0000	1.1.2.3
+++ GoogleMini.php	23 Feb 2009 00:37:30 -0000
@@ -1,8 +1,6 @@
 <?php
 
-if (!defined('GOOGLE_MINI_MAX_RESULTS')) {
-  define('GOOGLE_MINI_MAX_RESULTS', 1000);
-}
+define('GOOGLE_MINI_MAX_RESULTS', variable_get('google_appliance_max_results', 1000));
 
 class GoogleMini {
 
@@ -28,7 +26,7 @@ class GoogleMini {
       $callback = $this->debug_callback;
       call_user_func($callback,$message);
     }
-    error_log($message);
+    watchdog('google_search',$message);
   }
 
   /**
@@ -186,7 +184,15 @@ class GoogleMini {
    *
    * @param int $page
    */
-  public function setPageAndResultsPerPage($page = 0, $results = 10) {
+  public function setPageAndResultsPerPage($page = NULL, $results = 10) {
+  if (!$page) {
+    if($_GET['page']) {
+      $page = $_GET['page'];
+    }
+    else {
+      $page = 0;
+    }
+  }
     $end = $page * $results + $results;
     if ($end > GOOGLE_MINI_MAX_RESULTS) {
       throw new GoogleMiniCriteriaException("You cannot get more than ".GOOGLE_MINI_MAX_RESULTS." results per page, requested $end",2);
@@ -240,22 +246,11 @@ class GoogleMini {
             }
             // The 'OROR' case is used on the Related Information pages, where you want
             // to search documents with one of multiple terms in multiple vocabularies.
-            // You have to join the different types with a | otherwise the date sorting gets messed up.
-            
-            
-            /***
-             * IMPORTANT!  The new Version of the Mini uses parenthesis.
-             * This will not work for older versions pre August 2008 (I believe).
-             *
-             * If you are using one of these versions see the patch at:
-             * which will use the old
-             *
-             */
-            
+            // You have to join the different types with a | otherwise the date sorting gets messed up.            
             if ($mdf->type == 'OROR') {
-              $metafilter .= '(' . join("|", $vals) . ")|";
+              $metafilter .= join("|", $vals) . "|";
             } else {
-              $metafilter .= '(' . join("|", $vals) . ").";
+              $metafilter .= join("|", $vals) . ".";
             }
           } else {
             foreach ($mdf->values as $value) {
@@ -286,14 +281,13 @@ class GoogleMini {
     if ($this->debug) {
       $this->log($query);
     }
-
     return $query;
 
   }
 
 
 
-  public function query($iteratorClass = 'GoogleMiniResultIterator') {
+  public function query($iteratorClass = 'GoogleMiniresult_iterator') {
 
     $query = $this->buildQuery();
     // get search results in XML using cURL
@@ -307,17 +301,16 @@ class GoogleMini {
     	$this->log('Made CURL request to ' . $query);
 	}
 
+ //   print_r($resultXML);
     return self::resultFactory($resultXML,$iteratorClass);
   }
 
-  function resultFactory($resultXML,$className = 'GoogleMiniResultIterator') {
+  function resultFactory($resultXML,$className = 'GoogleMiniresult_iterator') {
     $results = array();
 
-
     $payload = simplexml_load_string($resultXML);
-
-    $totalResults = $payload->RES->M;    
-    
+ 
+    $totalResults = $payload->RES->M;   
     if ($totalResults == 0) {
       if (!$payload->GM) {
         throw new GoogleMiniResultException("No Results found", '1');
@@ -327,6 +320,7 @@ class GoogleMini {
         $results[] = $res;
       }
     }
+    $results['totalResults'] = $totalResults;
     $iterator = new $className($results);
     $iterator->payload = $payload;
     $iterator->time = $payload->TM;
@@ -339,7 +333,7 @@ class GoogleResult extends SimpleXMLIter
 
 }
 
-class GoogleMiniResultIterator extends ArrayIterator   {
+class GoogleMiniresult_iterator extends ArrayIterator   {
 
   public $time;
   public $payload;
@@ -366,7 +360,6 @@ class GoogleMiniResultIterator extends A
         $output[(string)$match->GL] = (string)$match->GD;
       }
     }
-
     return $output;
   }
 
@@ -377,7 +370,6 @@ class GoogleMiniResult {
   function __construct($result) {
     $this->result = $result;
   }
-
   function __get($key) {
     return $this->result->$key;
   }
Index: google_appliance.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/google_appliance/google_appliance.info,v
retrieving revision 1.1
diff -u -p -r1.1 google_appliance.info
--- google_appliance.info	8 Apr 2008 17:50:32 -0000	1.1
+++ google_appliance.info	23 Feb 2009 00:37:30 -0000
@@ -1,4 +1,5 @@
-; $Id: 
+; $Id$
 name = "Google Search Appliance Integration"
 description = "Provides a search interace to the googleMini or GSA, meta-data generators which will allow for advanced search and a class for talking to a GoogleMini or GSA."
 package = "Other"
+core = 6.x
Index: google_appliance.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/google_appliance/google_appliance.install,v
retrieving revision 1.1
diff -u -p -r1.1 google_appliance.install
--- google_appliance.install	8 Apr 2008 17:50:32 -0000	1.1
+++ google_appliance.install	23 Feb 2009 00:37:30 -0000
@@ -1,35 +1,95 @@
 <?php
+// $Id$
+
+/**
+ * @file
+ * Installation file for building tables for Google Integration
+ */
 function google_appliance_install() {
-  $q = "
-CREATE TABLE IF NOT EXISTS `{cache_google}` (
-  `cid` varchar(255) NOT NULL default '',
-  `data` longblob,
-  `expire` int(11) NOT NULL default '0',
-  `created` int(11) NOT NULL default '0',
-  `headers` text,
-  PRIMARY KEY  (`cid`),
-  KEY `expire` (`expire`)
-) ENGINE=innoDB DEFAULT CHARSET=utf8
-";
+  $install = drupal_install_schema('google_appliance');
   
-  $ret[] = db_query($q);
-  return $ret;
+  if ($install['0']['success'] == 1) {
+    drupal_set_message(t('Google Appliance module installed successfully'));
+  } 
+  else {
+    drupal_set_message(t('Google Appliance module failed to install'), 'error');
+  }
+}
+
+/**
+ * Hook to drop the google_appliance table.
+ *
+ */
+function google_appliance_uninstall() {
+  // Remove tables.
+  $uninstall = drupal_uninstall_schema('google_appliance');
+
+  if ($uninstall['0']['success'] == 1) {
+    drupal_set_message(t('Google Appliance module uninstalled successfully'));
+  } 
+  else {
+    drupal_set_message(t('Google Appliance module failed to uninstall'), 'error');
+  }
+}
+
+function google_appliance_schema() {
+
+  $schema['google_appliance'] = array(
+    'fields' => array(
+      'cid'    => array(
+        'type' => 'varchar', 
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => ''
+      ),
+      'data'    => array(
+      'type' => 'blob',
+      'size' => 'big'
+      ),
+      'expire' => array(
+      'type' => 'int',
+       'not null' => TRUE,
+       'default' => 0
+      ),
+      'created' => array(
+        'type' => 'int',
+        'not null' => TRUE, 
+        'default' => 0
+        ),
+      'headers' => array(
+        'type' => 'text'
+        )
+    ),
+    'indexes' => array(
+      'cid'    => array('cid')
+    ),
+    'primary key' => array('cid'),
+    'key' => array('expire')
+    
+  );
+
+  return $schema;
 }
 
 function google_appliance_update_1() {
-  $q = "
-CREATE TABLE IF NOT EXISTS `{cache_google}` (
-  `cid` varchar(255) NOT NULL default '',
-  `data` longblob,
-  `expire` int(11) NOT NULL default '0',
-  `created` int(11) NOT NULL default '0',
-  `headers` text,
-  PRIMARY KEY  (`cid`),
-  KEY `expire` (`expire`)
-) ENGINE=innoDB DEFAULT CHARSET=utf8
+  switch ($GLOBALS['db_type']) {
+    case 'mysqli':
+    case 'mysql':
+      $sql = "
+         CREATE TABLE IF NOT EXISTS `{cache_google}` (
+        `cid` varchar(255) NOT NULL default '',
+        `data` longblob,
+        `expire` int(11) NOT NULL default '0',
+        `created` int(11) NOT NULL default '0',
+        `headers` text,
+        `serialized` smallint(6) NOT NULL default '0',
+        PRIMARY KEY  (`cid`),
+        KEY `expire` (`expire`)
+      ) ENGINE=innoDB DEFAULT CHARSET=utf8
 ";
-  
-  $ret[] = update_sql($q);  
-  return $ret;
-}
-?>
\ No newline at end of file
+      $ret[] = update_sql($sql);
+      //$sql2 = "ALTER TABLE (google_appliance} ADD COLUMN serialized smallint(6) AFTER headers";
+      //$ret[] = update_sql($sql2);
+      return $ret;
+  }
+}
\ No newline at end of file
Index: google_appliance.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/google_appliance/google_appliance.module,v
retrieving revision 1.1.2.3
diff -u -p -r1.1.2.3 google_appliance.module
--- google_appliance.module	18 Aug 2008 01:31:52 -0000	1.1.2.3
+++ google_appliance.module	23 Feb 2009 00:37:30 -0000
@@ -1,34 +1,43 @@
 <?php
+// $Id$
 /**
  * @file GSA integration
  */
 
 /**
+ * Implementation of hook_perm().
+ */
+function google_appliance_perm() {
+  return array('administer google appliance search');
+}
+
+/**
  * Implementation of hook_menu()
  *
  */
-function google_appliance_menu($may_cache = false) {
+function google_appliance_menu() {
   $items = array();
-  if ($may_cache) {
-    $items[] = array (
-    'path' => 'google_appliance',
-    'callback' => 'google_appliance_search',
+    $items['google-appliance'] = array(
+    'page callback' => 'google_appliance_search',
+    'access arguments' => array('access content'),
     'type' => MENU_CALLBACK,
-    'access' => true,
     );
 
-    $items[] = array(
-      'path' => 'admin/settings/google_appliance',
+    $items['google-appliance-feeder'] = array(
+      'page callback' => 'google_apppliance_feeder',
+      'access arguments' => array('access content'),
+      'type' => MENU_CALLBACK,
+    );
+
+    $items['admin/settings/google-appliance'] = array(
       'title' => t('Google Appliance Settings'),
       'description' => t('Configuration for the Google Appliance search'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('google_appliance_admin_settings'),
-      'access' => user_access('administer search'),
+      'page callback' => 'drupal_get_form',
+      'page arguments' => array('google_appliance_admin_settings'),
+      'access arguments' => array('administer google appliance search'),
       'type' => MENU_NORMAL_ITEM,
     );
-  } else {
-    _google_appliance_add_meta_tags();
-  }
+    
   return $items;
 }
 
@@ -39,7 +48,12 @@ function google_appliance_menu($may_cach
 function google_appliance_block($op = 'list', $delta = 0, $edit = array()) {
   switch ($op) {
 
-    case 'list':      
+    case 'list':
+    
+    
+      $blocks['google_search']['info'] = t('Google Search');
+      $blocks['google_search']['title'] = t('Search'); 
+          
       $blocks['recommended_links']['info'] = t("Recommended Links");
       $blocks['recommended_links']['title'] = t('Recommended Links');      
       $blocks['recommended_links']['pages'] = '*search/google_appliance*';
@@ -61,16 +75,24 @@ function google_appliance_block($op = 'l
           
             $links = array();          
             foreach ($matches as $link => $title) {
-              $links[] = l($title,$link);
+              $links[] = l($title, $link);
             }
           
             if (count($links)) {
-              $block['content'] = theme('item_list',$links);
-            } else {
+              $block['content'] = theme('item_list', $links);
+            } 
+            else {
               return false;
             }
           }
           break;
+        case 'google_search':
+        
+          $block['content'] = drupal_get_form('google_appliance_search_block_form');
+          $block['subject'] = t('Search');
+          return $block;
+          
+        break;  
           
       }
 
@@ -141,14 +163,6 @@ function google_appliance_admin_settings
     "#default_value" => variable_get('google_debug', ''),    
   );
   
-  $form["config_init"]["google_appliance_limit_per_page"] = array(
-    "#type" => "textfield",
-    "#size" => 5,
-    "#title" => t("Number of results per page"),
-    "#description" => t('If you enter 0, it will return the max allowed by the appliance (100)'),
-    "#default_value" => variable_get('google_appliance_limit_per_page', 10),    
-  );
-  
 
   // error message config
   $form["config_messages"] = array(
@@ -194,7 +208,7 @@ function google_appliance_admin_settings
     "#maxlength" => 255,
     "#required" => true,
     "#description" => t('If the search cannot connect to the Google Appliance server.'),
-    "#default_value" => variable_get('google_appliance_errorcode_neg_100','We apologize, but the connection to our search engine appears to be down at the moment, please try again later.'),
+    "#default_value" => variable_get('google_appliance_errorcode_neg_100', 'We apologize, but the connection to our search engine appears to be down at the moment, please try again later.'),
   );
 
   // optional metadata configuration
@@ -212,27 +226,28 @@ function google_appliance_admin_settings
     "#value" => t("Save Settings"),
   );
 
-  return $form;
+  return system_settings_form($form);
 }
 
 /**
  * Validation function, though it's actually getting overridden by the #required fields...
  *
  */
-function google_appliance_admin_settings_validate($form_id, $form) {
-  if (empty($form['google_appliance_host_name'])) {
+function google_appliance_admin_settings_validate(&$form, $form_state) {
+
+  if (empty($form['#post']['google_appliance_host_name'])) {
     form_set_error('google_appliance_host_name', t('Please enter your host name or IP address.'));
   }
 
-  if (empty($form['google_appliance_collection'])) {
+  if (empty($form['#post']['google_appliance_collection'])) {
     form_set_error('google_appliance_collection', t('Please enter the name of the collection you want to search.'));
   }
 
-  if (empty($form['google_appliance_client'])) {
+  if (empty($form['#post']['google_appliance_client'])) {
     form_set_error('google_appliance_client', t('Please enter name of the client frontend you are searching.'));
   }
 
-  if (empty($form['google_appliance_name'])) {
+  if (empty($form['#post']['google_appliance_name'])) {
     form_set_error('google_appliance_name', t('Please enter the name of this search, to appear as sub-navigation on the search page.'));
   }
 }
@@ -240,14 +255,13 @@ function google_appliance_admin_settings
 /**
  * Submits the admin settings form and saves all the variables.
  */
-function google_appliance_admin_settings_submit($form_id, $form) {
+function google_appliance_admin_settings_submit($form, &$form_state) {
   variable_set('google_appliance_host_name', check_plain($form['google_appliance_host_name']));
   variable_set('google_appliance_collection', check_plain($form['google_appliance_collection']));
   variable_set('google_appliance_client', check_plain($form['google_appliance_client']));
   variable_set('google_appliance_name', check_plain($form['google_appliance_name']));
   variable_set('google_appliance_cache_timeout', check_plain($form['google_appliance_cache_timeout']));
   variable_set('google_debug', check_plain($form['google_debug']));
-  variable_set('google_appliance_limit_per_page', check_plain($form['google_appliance_limit_per_page']));
 
   // don't run check_plain on these because they can have HTML
   variable_set('google_appliance_errorcode_1', $form['google_appliance_errorcode_1']);
@@ -270,6 +284,21 @@ function _google_appliance_add_meta_tags
   }
 }
 
+function google_appliance_feeder() {
+  //not sure if this is appropriate as everything should be findable via the main site, but this basically just creates a listing of all nodes.
+  $result = db_query('SELECT * from {node} WHERE status = 1');
+  print '<html>';
+  print '<body>';
+
+  while ($row = db_fetch_object($result)) {
+    print l($row->title, 'node/'. $row->nid);
+  }
+
+  print '</body>';
+  print '</html>';
+  die();
+}
+
 /**
  * Implementation of hook_search()
  *
@@ -287,34 +316,22 @@ function google_appliance_search($op = '
       break;
 
     case 'search':
-      global $pager_page_array, $pager_total, $pager_total_items;
-      $page = isset($_GET['page']) ? $_GET['page'] : '';
-      // Convert comma-separated $page to an array, used by other functions.
-      $pager_page_array = explode(',', $page);
-      // $element indicates which of the pagers active this pager is working from.  $limit indicates how many per page.
-      $element = 0;
-      $limit = variable_get('google_appliance_limit_per_page',10);
-      
       $dir = drupal_get_path('module', 'google_appliance');
-      include_once $dir . '/DrupalGoogleMini.php';
+      include_once $dir .'/DrupalGoogleMini.php';
       
-      $google_debug = variable_get('google_debug',0);
-      if ($google_debug >= 2 ){
-          $gm = new DrupalGoogleMini(true,'dpr');
-        } elseif ($google_debug == 1)  {
+      $google_debug = variable_get('google_debug', 0);
+      if ($google_debug >= 2 ) {
+          $gm = new DrupalGoogleMini(true, 'dpr');
+        } 
+        elseif ($google_debug == 1) {
           $gm = new DrupalGoogleMini(true);
-        } else {
+        } 
+        else {
           $gm = new DrupalGoogleMini(false);
         }
       
-      /**
-       * If you have many searches for the same content
-       * You can use this setting to keep the GSA from getting hit too often
-       *
-       */
-      
-      if ($cache = variable_get('google_appliance_cache_timeout',0) ) {
-        cache_clear_all(null,'cache_google');
+      if ($cache = variable_get('google_appliance_cache_timeout', 0)) {
+        cache_clear_all(null, 'cache_google');
         $gm->cache = true;
       }
 
@@ -330,11 +347,11 @@ function google_appliance_search($op = '
           drupal_set_message(t('No host name has been configured for the search appliance. Please enter it on the <a href="@admin-url">Google Appliance settings page</a>', array("@admin-url" => url("admin/settings/search/google_appliance"))), 'error');
           return false;
         }
-        $gm->baseUrl = $_tmp_host . "/search";
+        $gm->baseUrl = $_tmp_host ."/search";
         $gm->collection = variable_get('google_appliance_collection', '');
-        $gm->setQueryPart('client',variable_get('google_appliance_client', ''));
-        $gm->setPageAndResultsPerPage($page,$limit);
-        
+        $gm->setQueryPart('client', variable_get('google_appliance_client', ''));
+        $gm->setPageAndResultsPerPage();
+        $gm->setQueryPart('filter', 0);
         // set search parameters
         $gm->setKeywords($keys);
         
@@ -346,17 +363,19 @@ function google_appliance_search($op = '
       }
       catch (GoogleMiniCriteriaException $e) {
         $code = $e->getCode();
-        if ($message = variable_get('google_appliance_errorcode_' . $code,'')) {
+        if ($message = variable_get('google_appliance_errorcode_'. $code, '')) {
           $user_message = $message;
-        } else {
+        } 
+        else {
           $user_message = GoogleMiniException::getUserMessage($code);  
         }
         
         $error_message = $e->getMessage();
         if ($code > 0) {
-            $output .= "<h2>" . $user_message . "</h2>";
+            $output .= "<h2>". $user_message ."</h2>";
             return $output;
-        } else {
+        } 
+        else {
           watchdog('google_appliance', $error_message);
           drupal_set_message($error_message, 'error');
         }
@@ -365,25 +384,29 @@ function google_appliance_search($op = '
       // perform the search
       $results = array();
       try {
-        $resultIterator = $gm->query();
-        google_appliance_static_response_cache($resultIterator);
-        // Google never returns more than 1000 results, so we ignore any values larger than that.
-        $pager_total_items[$element] = ($resultIterator->totalResults < 1000) ? $resultIterator->totalResults : 1000;
-        $pager_total[$element] = ceil($pager_total_items[$element] / $limit);
-        $pager_page_array[$element] = max(0, min((int)$pager_page_array[$element], ((int)$pager_total[$element]) - 1));
-        
-        foreach ($resultIterator as $key => $result) {
-          $results[] = theme('google_appliance_search_result_array', $result);
+        $result_iterator = $gm->query();
+       $totalresults = $result_iterator['totalResults'];
+
+        google_appliance_static_response_cache($result_iterator);
+        $themedresults = '<dl class="search-results">';
+        foreach ($result_iterator as $key => $result) {
+          $googleresult = $result->result;
+          if ($googleresult->attributes()->N) {
+            $last_result = $googleresult->attributes()->N;         
+          }
+          $themedresults .= theme('google_appliance_search_result_array', $googleresult);
         }
       }
-      catch(Exception $e) {
+      catch (Exception $e) {
         if ($e->getCode() > 0) {
-          google_appliance_static_response_cache($resultIterator);
+          google_appliance_static_response_cache($result_iterator);
         }
         drupal_set_message($e->getMessage());
         return false;
       }
-      return $results;
+      $themedresults .= '</dl>';
+      $pager = google_appliance_pager($last_result, $totalresults);
+      return $pager . $themedresults;
       break;
 
     case 'reset':
@@ -393,6 +416,56 @@ function google_appliance_search($op = '
   }
 }
 
+function google_appliance_pager($last_result = NULL, $total_results = NULL, $results_per_page = 10) {
+   if (!$total_results) {
+     return;
+   }
+   $first = $last_result - $results_per_page +1;
+   
+   $output .= "<div id='Search_details'>";
+   $output .= '   '. $first .' - '. $last_result .' of '. $total_results;
+   $output .= "</div>";
+   $output .= "<div id='Search_pager'>";
+   if ($last_result > $results_per_page) {
+     if (isset($_GET['page'])) {
+       $page1 = $_GET['page'];
+       $page1==1 ? $page1=0 : $page1 = $page1-1;
+       $url1 = '/google-appliance/search/'. arg(2) .'?page='. $page1;
+     }
+   else{
+     $url1 = '/google-appliance/search/'. arg(2) .'?page=0';
+   }
+     $output .= "<a href='". $url1 ."'>Previous</a> ";
+   }
+   if ($last_result <= $total_results-1) {
+     if (isset($_GET['page'])) {
+       $page = $_GET['page'];
+       $page==0 ? $page=1 : $page = $page+1;
+       $url2 = '/google-appliance/search/'. arg(2) .'?page='. $page;
+   }
+   else {
+     $url2 = '/google-appliance/search/'. arg(2) .'?page=1';
+   }
+     $output .= " <a href='". $url2 ."'>Next</a> ";
+   }
+   $output .= "</div>";
+   return $output;
+}
+
+function google_appliance_theme() {
+  return array(
+    'add_google_appliance_meta_tags' => array(
+      'arguments' => array(
+        'results' => array()
+      )
+    ),
+    'google_appliance_search_result_array' => array(
+      'arguments' => array(
+        'node' => array()
+      )
+    ),
+  );
+}
 
 function theme_add_google_appliance_meta_tags($node) {
   // create list of tags to add
@@ -403,11 +476,11 @@ function theme_add_google_appliance_meta
    */
   $vocabs = taxonomy_get_vocabularies();
   if (module_exists('nat') && $node->nat) {
-    $node->taxonomy = array_merge($node->nat,$node->taxonomy);
+    $node->taxonomy = array_merge($node->nat, $node->taxonomy);
     //$node->taoxnomy[] = $
   }
   foreach ($node->taxonomy as $term ) {
-    $tagname = 'category-' . strtolower($vocabs[$term->vid]->name);
+    $tagname = 'category-'. strtolower($vocabs[$term->vid]->name);
     $results[] = array($tagname, $term->name);
   }
 
@@ -455,26 +528,26 @@ function theme_add_google_appliance_meta
   }
 }
 
-function theme_google_appliance_search_result_array($result) {  
-  return array(  
-    'link' => $result->U,
-    'user' => $result->getMetaData('user'),
-    'type' => $result->getMetaData('type'),
-    'title' => strip_tags($result->T),
-    'date' => strtotime($result->getMetaData('date')),
-    'snippet' => decode_entities((string)$result->S),
-  );
+function theme_google_appliance_search_result_array($result) {
+
+  $output .= '<dt class="title">';
+  $output .= '<a href = "'. $result->U .'">';
+  $output .= strip_tags($result->T);
+  $output .= '</a></dt>';
+  $output .= '<dd>'. decode_entities((string)$result->S) .'</dd></dt>';
+
+  return $output;
 }
 
-function google_appliance_form_alter($form_id,&$form) {
-   if ($form_id == 'block_admin_configure'){
+function google_appliance_form_alter($form_id, &$form) {
+   if ($form_id == 'block_admin_configure') {
     $module = $form['module']['#value'];
     $delta = $form['delta']['#value'];
-    $var_name = $module . '-' .$delta;
+    $var_name = $module .'-'. $delta;
 
     $ga_blocksettings = google_appliance_blocksettings_get();
 
-    $form['block_settings']['google_appliance'] = array (
+    $form['block_settings']['google_appliance'] = array(
     '#type' => 'fieldset',
     '#title' => t("Google Appliance Settings"),
     '#description' => t(''),
@@ -484,7 +557,7 @@ function google_appliance_form_alter($fo
     '#weight' => -1,
     );
 
-    $form['block_settings']['google_appliance']['hide'] = array (
+    $form['block_settings']['google_appliance']['hide'] = array(
     '#type' => 'radios',
     '#title' => t("Do you want to hide this block from the GSA crawler?"),
     '#description' => t('Select No if you want this block content to be crawled with the page content.'),
@@ -501,12 +574,13 @@ function google_appliance_form_alter($fo
    }
 }
 
-function google_appliance_block_save($form_id,$form_values) {
-  $var_name = $form_values['module'] . '-' . $form_values['delta'];
+function google_appliance_block_save($form_id, $form_values) {
+  $var_name = $form_values['module'] .'-'. $form_values['delta'];
   $block_settings = google_appliance_blocksettings_get();
   if (!isset($form_values['google_appliance']['hide'])) {
     unset($block_settings[$var_name]);
-  } else {
+  } 
+  else {
     $block_settings[$var_name] = $form_values['google_appliance']['hide'];
   }
 
@@ -515,21 +589,21 @@ function google_appliance_block_save($fo
 
 
 function google_appliance_blocksettings_set($new_val) {
-  variable_set('google_appliance_block_settings',$new_val);
+  variable_set('google_appliance_block_settings', $new_val);
 }
 
 
 function google_appliance_blocksettings_get() {
   static $google_appliance;
   if (empty($google_appliance)) {
-    $google_appliance = variable_get('google_appliance_block_settings',array());
+    $google_appliance = variable_get('google_appliance_block_settings', array());
   }
   return $google_appliance;
 }
 
 function google_appliance_block_nogoogle($block) {
   $gsa_block_settings = google_appliance_blocksettings_get();
-  $var_name = $block->module . '-' . $block->delta;
+  $var_name = $block->module .'-'. $block->delta;
   if (!isset($gsa_block_settings[$var_name]) || $gsa_block_settings[$var_name]) {
     return true;
   }
@@ -555,9 +629,25 @@ function &google_appliance_static_respon
 
 
 function google_appliance_simpletest() {
-  $dir = drupal_get_path('module', 'google_appliance'). '/tests';
+  $dir = drupal_get_path('module', 'google_appliance') .'/tests';
   $tests = file_scan_directory($dir, '\.test$');
   return array_keys($tests);
 }
 
-?>
\ No newline at end of file
+function google_appliance_search_block_form() {
+  $form['keys'] = array(
+    '#type' => 'textfield',
+    '#title' => '',
+    '#default_value' => '',
+    '#size' => 20,
+    '#maxlength' => 255,
+  );
+  $form['submit'] = array('#type' => 'submit', '#value' => t('Search'));
+
+  return $form;
+}
+
+function google_appliance_search_block_form_submit($form, &$form_state) {
+
+  $form_state['redirect'] = 'google-appliance/search/'. $form_state['values']['keys'];
+}
\ No newline at end of file
