/** * * Makes a wfs request to the specified geoserver and outputs the document returned * * @param string $url The url to send the request to * @param string $request The WFS Request to make * @param string $args Additional parameters to send along in the post (if any) * @param string $filter The filter to render and send (if any). This will load wfs_$filter.tpl * @param string $format The format desired for the result. Defaults to GML2. */ function geoserver_fetch($url, $request = "GetFeature", $args = NULL, $filter = FALSE, $format = 'GML2') { global $gBitSystem, $gBitSmarty; $post = 'SERVICE=WFS&VERSION=1.0.0&REQUEST=' . $request; $post .= '&OUTPUTFORMAT=' . $format; $query_url = $url; if (!empty($args)) { foreach ($args as $arg => $val) { if ($filter && strtolower($arg) == 'bbox') { $gBitSmarty->assign('bbox', $val); } elseif ($filter && strtolower($arg) == 'filter') { $val = html_entity_decode($val); $f = preg_replace('/<\\/?filter\\s*>/i', '', $val); $f = html_entity_decode($f); $gBitSmarty->assign('filter', $f); } elseif (strtolower($arg) == 'wfs_path') { $query_url .= $val; } elseif (strtolower($arg) == 'offset') { $gBitSmarty->assign('offset', $val); } else { $post .= '&' . $arg . '=' . html_entity_decode($val); } } } // Get the filter to post if ($filter) { $post .= "&FILTER=" . urlencode($gBitSmarty->fetch('bitpackage:geoserver/' . $filter)); } if ($_SERVER['REQUEST_METHOD'] != 'POST') { $query_url .= '?' . $post; } // create a new cURL resource $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $query_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, false); if ($_SERVER['REQUEST_METHOD'] == 'POST') { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); } $result = curl_exec($ch); if (!$result) { geoserver_exception(curl_error($ch)); } $header = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); if (!empty($header)) { header('Content-Type: ' . $header); } curl_close($ch); // Trick out any URLs in the result $result = str_replace($gBitSystem->getConfig('geoserver_url', 'http://localhost:8080/geoserver/'), GEOSERVER_PKG_URI, $result); echo $result; }
/** * * Makes a wfs request to the specified geoserver and outputs the document returned v * * @param string $url The url to send the request to * @param string $args Additional parameters to send along in the post (if any) */ function geoserver_fetch($url, $args = NULL) { $query_url = $url; $post = ''; if (!empty($args)) { foreach ($args as $arg => $val) { if (strtolower($arg) == 'wms_path') { $query_url .= $val; } else { $post .= '&' . $arg . '=' . $val; } } } if ($_SERVER['REQUEST_METHOD'] != 'POST') { $query_url .= '?' . $post; } // create a new cURL resource $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $query_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, false); if ($_SERVER['REQUEST_METHOD'] == 'POST') { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); } $result = curl_exec($ch); if (!$result) { geoserver_exception(curl_error($ch)); } $header = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); if (!empty($header)) { // Hack for geoserver stupidity. if (strstr($header, 'xml')) { header('Content-Type: application/xml'); } else { header('Content-Type: ' . $header); } } curl_close($ch); // Trick out any URLs in the result $result = str_replace('http://localhost:8080/geoserver/', '/geoserver/', $result); echo $result; }