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.2
diff -u -p -r1.1.2.2 google_cse_adv.module
--- google_cse_adv.module	15 Sep 2010 17:18:12 -0000	1.1.2.2
+++ google_cse_adv.module	27 Sep 2010 23:39:20 -0000
@@ -204,29 +204,56 @@ function google_cse_adv_search($op = 'se
  * @param string $keys
  * @param int $page
  * @param bool $reset
+ * @param array $options
  * @return string
  */
-function google_cse_adv_execute($keys, $page, $reset = FALSE) {
+function google_cse_adv_execute($keys, $page, $reset = FALSE, $options = array()) {
   static $response = array(); // Cache
   $rows = 10; // Default for Google CSE
 
   if (isset($response[$keys]) && FALSE === $reset) {
     return $response[$keys];
   }
-  // Language interface.
-  $hl = google_cse_adv_param_hl();
-  // Language filtering.
-  $lr = google_cse_adv_param_lr();
-  $url = 'http://www.google.com/cse'
-		   . '?cx=' . urlencode(variable_get('google_cse_adv_cx', ''))
-		   . '&client=google-csbe'
-		   . '&output=xml_no_dtd'
-       . ($hl ? '&hl=' . urlencode($hl) : '')
-       . ($lr ? '&lr=' . urlencode($lr) : '')
-       . '&q=' . urlencode($keys)
-       .   (isset($_GET['more']) ? '+more:' . urlencode($_GET['more']) : '')
-       . '&start=' . urlencode($page * $rows);
 
+  // Default query options
+  $defaults = array(
+    'cx' => variable_get('google_cse_adv_cx', ''),
+    'client' => 'google-csbe',
+    'output' => 'xml_no_dtd',
+    'hl' => google_cse_adv_param_hl(), // Language interface
+    'lr' => google_cse_adv_param_lr(), // Language filtering
+    'q' => $keys,
+    'more' => isset($_GET['more']) ? $_GET['more'] : '', // Labels
+    'num' => $rows,
+    'start' => $page * $rows,
+  );
+  // Use defaults for any values unspecified by the $options argument
+  // Defaults which are false are omitted (e.g. hl, lr, more, start).
+  $options += array_filter($defaults);
+
+  // Allow other modules to make changes.
+  drupal_alter('google_cse_adv_options', $options);
+
+  // URL-encode the query parameters
+  $options = array_map('urlencode', $options);
+
+  // Build the search URL
+  if (array_key_exists('more', $options)) {
+    if (!empty($options['q'])) {
+      $options['q'] .= '+more:' . $options['more'];
+    }
+    else {
+      $options['q'] = 'more:' . $options['more'];
+    }
+    unset($options['more']);
+  }
+  $query_parts = array();
+  foreach ($options as $option => $value) {
+    $query_parts[] = $option . '=' . $value;
+  }
+  $url = 'http://www.google.com/cse?' . join('&', $query_parts);
+
+  // Issue the search request
   $request = new stdClass();
   $request->url = $url;
 
