Index: views/wfs_plugin_display_wfs.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wfs/views/Attic/wfs_plugin_display_wfs.inc,v
retrieving revision 1.1.2.13
diff -u -p -r1.1.2.13 wfs_plugin_display_wfs.inc
--- views/wfs_plugin_display_wfs.inc	19 Jul 2010 19:09:05 -0000	1.1.2.13
+++ views/wfs_plugin_display_wfs.inc	13 Nov 2010 16:33:34 -0000
@@ -68,7 +68,7 @@ class wfs_plugin_display_wfs extends vie
    * try to process filter; this is RISKY
    */
   private function process_filter(&$view, &$display) {
-    // $post_text = trim(file_get_contents('php://input'));
+    $post_text = trim(file_get_contents('php://input'));
 
     // print_r($_GET);
     // GeoServer-style
@@ -92,16 +92,25 @@ class wfs_plugin_display_wfs extends vie
       }
     } 
     // OpenLayers-style
-    /*
     elseif (!empty($post_text)) {
-      $xml = new SimpleXMLElement(urldecode($post_text));
-
-      // Variation for OpenLayers-XML
-      $envelope = $xml->children('http://www.opengis.net/ogc')->
-        BBOX->children('http://www.opengis.net/gml')->Envelope;
+      try {
+        libxml_use_internal_errors(true);
+        $xml = new SimpleXMLElement(urldecode($post_text));
+        libxml_use_internal_errors(false);
+
+        if ($xml) {
+          // Variation for OpenLayers-XML
+          $children = $xml->children('http://www.opengis.net/wfs');
+          if (isset($children->Query)) {
+            $children = $children->Query->children('http://www.opengis.net/ogc');
+            if (isset($children->Filter->BBOX)) {
+              $envelope = $children->Filter->BBOX->children('http://www.opengis.net/gml')->Envelope;
+            }
+          }
+        }
+      } catch(Exception $e) { }
     }
-     */
-    
+
     // Proceed if either style succeeded
     if (!empty($envelope)) {
 
@@ -109,58 +118,46 @@ class wfs_plugin_display_wfs extends vie
         explode(' ', (string) $envelope->lowerCorner),
         explode(' ', (string) $envelope->upperCorner));
 
-      $lon_field = $display->display_options['style_options']['fields']['longitude'];
-      $lon_table = $view->display['default']->display_options['fields'][$lon_field]['table'];
+      foreach (array('longitude','latitude') as $idx => $coord) {
+        $field = $display->display_options['style_options']['fields'][$coord];
+        $table = $view->display['default']->display_options['fields'][$field]['table'];
+
+        $filter = array(
+          'operator' => 'between',
+          'id' => $field,
+          'table' => $table,
+          'group' => 0,
+          'field' => $view->display['default']->display_options['fields'][$field]['field'],
+          'exposed' => NULL,
+          'expose' => array(
+              'operator' => NULL,
+              'label' => NULL
+          ),
+        
+          'relationship' => 'district_id_1',
+          'value' => array(
+            'value' => '', 
+            'min' => $bounding_box[0+$idx],
+            'max' => $bounding_box[2+$idx],
+            'units' => '',      // Prevent Geo module from converting the values to meters
+          )
+        );
+
+        if (isset($view->display['default']->display_options['fields'][$field]['function'])) {
+          $filter['function'] =
+                $view->display['default']->display_options['fields'][$field]['function'];
+        }
 
-      $lat_field = $display->display_options['style_options']['fields']['latitude'];
-      $lat_table = $view->display['default']->display_options['fields'][$lat_field]['table'];
+        $view->display['default']->handler->options['filters'][$field] = $filter;
+      }
 
-      $view->display['default']->handler->options['filters'][$lat_field] = array(
-        'operator' => 'between',
-        'id' => $lat_field,
-        'table' => $lat_table,
-        'group' => 0,
-        'field' => $lat_field,
-        'exposed' => NULL,
-        'expose' => array(
-            'operator' => NULL,
-            'label' => NULL
-        ),
-        
-        'relationship' => 'district_id_1',
-        'value' => array(
-          'value' => '', 
-          'min' => $bounding_box[0],
-          'max' => $bounding_box[2],
-        )
-      );
-
-      $view->display['default']->handler->options['filters'][$lon_field] = array(
-        'operator' => 'between',
-        'id' => $lon_field,
-        'table' => $lon_table,
-        'group' => 0,
-        'field' => $lon_field,
-        'exposed' => NULL,
-        'expose' => array(
-            'operator' => NULL,
-            'label' => NULL
-        ),
-        
-        'relationship' => 'district_id_1',
-        'value' => array(
-          'value' => '', 
-          'min' => $bounding_box[1],
-          'max' => $bounding_box[3],
-        )
-      );
       // exit(print_r($view,1));
     }
   }
 
   function init(&$view, &$display, $options = NULL) {
     $_GET = array_change_key_case($_GET, CASE_LOWER);
-    // $this->process_filter(&$view, &$display);
+    $this->process_filter(&$view, &$display);
     parent::init($view, $display, $options);
   }
 
