forked from bitweaver/geoserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wms_query.php
91 lines (78 loc) · 2.1 KB
/
wms_query.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
* A straight WMS proxy
*
* @package geoserver
* @version $Header$
* @author spider <nick@sluggardy.net>
*/
// TODO: Move to a library
/**
*
* Outputs an exception document
*
* @param string $exception The exception message to send
*/
function geoserver_exception($exception) {
require_once( '../kernel/setup_inc.php' );
global $gBitSmarty, $gBitSystem;
$gBitSmarty->assign('exception', $exception);
$gBitSystem->display('bitpackage:geoserver/wfs_exception.tpl', '', array( 'format' => 'xml' ));
}
/**
*
* 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;
}
$url = 'http://localhost:8080/geoserver/wms';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$args = $_POST;
} else {
$args = $_GET;
}
geoserver_fetch($url, $args);