Index: google_cse_adv.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/google_cse_adv/google_cse_adv.module,v
retrieving revision 1.1.2.3
diff -u -p -r1.1.2.3 google_cse_adv.module
--- google_cse_adv.module	29 Sep 2010 06:16:54 -0000	1.1.2.3
+++ google_cse_adv.module	1 Oct 2010 03:39:33 -0000
@@ -271,9 +271,21 @@ function google_cse_adv_response_results
   $results = array();
 
   if (isset($xml->RES->R)) {
+
+    // Cap the result total if necessary.
+    // Google will not return more than 1000 results, but RES->M may
+    // be higher than this, which messes up our paging. Retain a copy
+    // of the original so that themers can still display it.
+    $max_results = variable_get('google_cse_adv_maximum_results', 1000);
+    $total = (int) $xml->RES->M;
+    $xml->RES->M_ORIGINAL = $total;
+    if ($total > $max_results) {
+      $xml->RES->M = $total = $max_results;
+    }
+
     foreach($xml->RES->R as $result) {
       // Markup is escaped in title - we have to strip it (and strip_tags is not enough protection for XSS)
-	  $title = strip_tags((string)$result->T);
+      $title = strip_tags((string)$result->T);
       $title = function_exists('htmlspecialchars_decode') ? htmlspecialchars_decode($title, ENT_QUOTES) : $title;
       $snippet = check_plain(strip_tags((string)$result->S));
       $snippet = function_exists('htmlspecialchars_decode') ? htmlspecialchars_decode($snippet, ENT_QUOTES) : $snippet;
@@ -285,8 +297,10 @@ function google_cse_adv_response_results
         'keys' => check_plain($keys),
       );
     }
+
     // No pager query was executed - we have to set the pager manually
-    _google_cse_adv_pager_init((int)$xml->RES->M, count($results));
+    $limit = variable_get('google_cse_adv_results_per_page', 10);
+    _google_cse_adv_pager_init($total, $limit);
   }
   return $results;
 }
