[Mapbender-commits] r9214 - trunk/mapbender/http/php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Jun 15 03:09:29 PDT 2015


Author: verenadiewald
Date: 2015-06-15 03:09:29 -0700 (Mon, 15 Jun 2015)
New Revision: 9214

Added:
   trunk/mapbender/http/php/wfs.php
Log:
inspire WFS proxy

Added: trunk/mapbender/http/php/wfs.php
===================================================================
--- trunk/mapbender/http/php/wfs.php	                        (rev 0)
+++ trunk/mapbender/http/php/wfs.php	2015-06-15 10:09:29 UTC (rev 9214)
@@ -0,0 +1,379 @@
+<?php
+# $Id: wfs.php 
+# http://www.mapbender.org/index.php/wfs.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//http://localhost/mapbender_trunk/php/wfs.php?featuretype_id=21018&INSPIRE=1&REQUEST=GetCapabilities&VERSION=1.0.0&SERVICE=wfs&withChilds=1
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_layer_monitor.php");
+require_once(dirname(__FILE__)."/../classes/class_administration.php");
+//
+$admin = new administration();
+//
+// make all parameters available as upper case
+//
+foreach($_GET as $key => $val) {
+	$_GET[strtoupper($key)] = $val;
+}
+
+$requestType = $_GET["REQUEST"];
+$version = $_GET["VERSION"];
+$service = strtoupper($_GET["SERVICE"]);
+$featuretypeId = $_GET["FEATURETYPE_ID"];
+$updateSequence = intval($_GET["UPDATESEQUENCE"]);
+$inspire = $_GET["INSPIRE"];
+$withChilds = false;
+
+if (isset($_REQUEST["withChilds"]) && $_REQUEST["withChilds"] === "1") {
+	$withChilds = true;
+}
+$sessionId = $_GET[strtoupper(session_name())];
+//if session id not set, set a dummy id!
+if (!isset($sessionId) || $sessionId =="") {
+	$sessionId = "00000000000000000000000000000000";
+	}
+if (isset($inspire) && $inspire === 1 ) {
+	$inspire = true;
+}
+
+$mapbenderMetadaUrl = $_SERVER['HTTP_HOST']."/mapbender/php/mod_showMetadata.php?resource=featuretype&id=";
+$inspireServiceMetadataUrl =  $_SERVER['HTTP_HOST']."/mapbender/php/mod_layerISOMetadata.php?SERVICE=WMS&outputFormat=iso19139&Id=";
+$mapbenderMetadataUrlUrl = $_SERVER['HTTP_HOST']."/mapbender/php/mod_dataISOMetadata.php?outputFormat=iso19139&id=";
+
+if (isset($_SERVER["HTTPS"])){
+	$urlPrefix = "https://";
+} else {
+	$urlPrefix = "http://";
+}
+$mapbenderMetadataUrl = $urlPrefix.$mapbenderMetadataUrl;
+$inspireServiceMetadataUrl = $urlPrefix.$inspireServiceMetadataUrl;
+$mapbenderMetadataUrlUrl = $urlPrefix.$mapbenderMetadataUrlUrl;
+
+$con = db_connect(DBSERVER,OWNER,PW);
+db_select_db(DB,$con);
+
+/**
+ * Creates an XML Exception according to WMS 1.1.1
+ * 
+ * @return an XML String
+ * @param $errorCode String
+ * @param $errorMessage String
+ */
+function createExceptionXml ($errorCode, $errorMessage) {
+	// see http://de2.php.net/manual/de/domimplementation.createdocumenttype.php
+	$imp = new DOMImplementation;
+	$dtd = $imp->createDocumentType("ServiceExceptionReport", "", "http://schemas.opengis.net/wms/1.1.1/exception_1_1_1.dtd");
+	
+	$doc = $imp->createDocument("", "", $dtd);
+	$doc->encoding = 'UTF-8';
+	$doc->standalone = false;
+	
+	$el = $doc->createElement("ServiceExceptionReport");
+	$exc = $doc->createElement("ServiceException", $errorMessage);
+	if ($errorCode) {
+		$exc->setAttribute("code", $errorCode);
+	}
+	$el->appendChild($exc);
+	$doc->appendChild($el);
+	
+	return $doc->saveXML();
+}
+
+//
+// check if service param is set
+//
+if (!isset($service) || $service === "" || $service != "WFS") {
+	header("Content-type: application/xhtml+xml; charset=UTF-8");
+	echo createExceptionXml("", "Parameter SERVICE invalid");
+	die;
+}
+
+//
+// check if request param is set
+//
+if (!isset($requestType) || $requestType === "" || ($service == "WFS" && $requestType != "GetCapabilities")) {
+	header("Content-type: application/xhtml+xml; charset=UTF-8");
+	echo createExceptionXml("", "Parameter REQUEST invalid");
+	die;
+}
+
+//
+// check if version param is set
+//
+if (!isset($version) || $version === "" || ($service == "WFS" && $version != "1.0.0")) {
+	// optional parameter, set to 1.0.0 if not set
+	$version = "1.0.0";
+}
+
+//
+// check if featuretype id is set
+//
+if (!isset($featuretypeId) || !is_numeric($featuretypeId)) {
+	// TO DO: create exception XML
+	header("Content-type: application/xhtml+xml; charset=UTF-8");
+	echo createExceptionXml("Featuretype not defined", "Unknown featuretype id " . $featuretypeId);
+	die;
+}
+
+//
+// check if featuretype is stored in database
+//
+$wfs_sql = "SELECT * FROM wfs AS w, wfs_featuretype AS f " . 
+	"where f.featuretype_id = $1 AND f.fkey_wfs_id = w.wfs_id LIMIT 1";
+$v = array($featuretypeId);
+$t = array("i");
+$res_wfs_sql = db_prep_query($wfs_sql, $v, $t);
+$wfs_row = db_fetch_array($res_wfs_sql);
+
+if (!$wfs_row["wfs_id"]) {
+	// TODO: create exception XML
+	header("Content-type: application/xhtml+xml; charset=UTF-8");
+	echo createExceptionXml("Featuretype not defined", "Unknown featuretype id " . $featuretypeId);
+	die;
+}
+
+//Get Geometry Type if featuretype info was requested
+if ($resource == 'featuretype') {
+	$getTypeSql = "SELECT element_id, element_type from wfs_element WHERE fkey_featuretype_id = $1 AND element_type LIKE '%PropertyType';";
+	$vgetType = array($resourceMetadata['contentid']);
+	$tgetType = array('i');
+	$resGetType = db_prep_query($getTypeSql,$vgetType,$tgetType);
+	$featuretypeElements = db_fetch_array($resGetType);
+	$resourceMetadata['featuretype_geomType'] = $featuretypeElements['element_type'];
+}
+
+
+//
+// check if update sequence is valid
+//
+$updateSequenceDb = intval($wfs_row["wfs_timestamp"]);
+
+if ($updateSequence) {
+	if ($updateSequence > $updateSequenceDb) {
+		// Exception: code=InvalidUpdateSequence
+		header("Content-type: application/xhtml+xml; charset=UTF-8");
+		echo createExceptionXml("InvalidUpdateSequence", "Invalid update sequence");
+		die;
+	}
+	else if ($updateSequence == $updateSequenceDb) {
+		// Exception: code=CurrentUpdateSequence
+		header("Content-type: application/xhtml+xml; charset=UTF-8");
+		echo createExceptionXml("CurrentUpdateSequence", "Current update sequence");
+		die;
+	}
+}
+
+// ---------------------------------------------------------------------------
+//
+// START TO CREATE CAPABILITIES DOC
+// (return most recent Capabilities XML)
+//
+// ---------------------------------------------------------------------------
+
+$doc = new DOMDocument('1.0');
+$doc->encoding = 'UTF-8';
+$doc->standalone = false;
+
+#Load existing XML from database
+$xml_sql = "SELECT wfs_getcapabilities_doc FROM wfs AS w, wfs_featuretype AS f " .
+		"WHERE f.featuretype_id = $1 AND f.fkey_wfs_id = w.wfs_id;";
+$v = array($featuretypeId);
+$t = array("i");
+$res_xml_sql = db_prep_query($xml_sql, $v, $t);
+$xml_row = db_fetch_array($res_xml_sql);
+
+$doc->loadXML($xml_row["wfs_getcapabilities_doc"]);
+$xpath = new DOMXPath($doc);
+
+$xpath->registerNamespace("wfs", "http://www.opengis.net/wfs");
+$xpath->registerNamespace("ows", "http://www.opengis.net/ows");
+$xpath->registerNamespace("gml", "http://www.opengis.net/gml");
+$xpath->registerNamespace("ogc", "http://www.opengis.net/ogc");
+$xpath->registerNamespace("xlink", "http://www.w3.org/1999/xlink");
+$xpath->registerNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
+$xpath->registerNamespace("default", "http://www.opengis.net/wfs");
+
+$elements = $xpath->query('/wfs:WFS_Capabilities');
+if ($elements->length >= 1) {
+	$element = $elements->item(0);
+	$element->setAttribute("updateSequence", $wfs_row["wfs_timestamp"]);
+	
+	if ($inspire){
+		$element->setAttribute("xmlns:inspire_common", "http://inspire.ec.europa.eu/schemas/common/1.0");
+		$element->setAttribute("xmlns:inspire_vs", "http://inspire.ec.europa.eu/schemas/inspire_vs/1.0");
+	}
+}
+
+# switch URLs for OWSPROXY
+//check if resource is freely available to anonymous user - which are all users who search thru metadata catalogues:
+//for the inspire use case:
+//url maybe owsproxy, if proxy is active and guest have right to use resource
+//url maybe http_auth if proxy is active and guest is not authorized
+//url maybe original if proxy is not active
+
+//$e = new mb_exception($urlPrefix.$_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"]."?".$_SERVER["QUERY_STRING"]);
+$tmpOR = $urlPrefix.$_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"]."?".$_SERVER["QUERY_STRING"];
+$tmpOR = str_replace(SERVERIP, SERVERNAME, $tmpOR);
+//$e = new mb_exception($tmpOR);
+$wfs_row['wfs_getcapabilities'] = $tmpOR;
+
+if ($inspire) {
+	$wfs_row['wfs_getcapabilities'] .= "&INSPIRE=1";
+}
+$e = new mb_notice($wfs_row['wfs_getcapabilities']);
+$publicHasPermission=$admin->getWfsConfByPermission(PUBLIC_USER);
+if ($wfs_row['wfs_owsproxy'] <> "" AND $wfs_row['wfs_owsproxy'] <> NULL) {
+	if ($inspire) {
+		if ($publicHasPermission) {
+			//use owsproxy url
+			$tmpOR = $urlPrefix.$_SERVER["HTTP_HOST"]."/owsproxy/".$sessionId."/".$wfs_row["wfs_owsproxy"]."?";
+			$tmpOR = str_replace(SERVERIP, SERVERNAME, $tmpOR);
+			$wfs_row['wfs_describefeaturetype'] = $tmpOR;
+			$wfs_row['wfs_getfeature'] = $tmpOR;
+			$wfs_row['wfs_transaction'] = $tmpOR;
+		} else {
+			//use http_auth
+			$tmpOR = $urlPrefix.$_SERVER["HTTP_HOST"]."/http_auth/".$featuretypeId."?";
+			$tmpOR = str_replace(SERVERIP, SERVERNAME, $tmpOR);
+			$wfs_row['wfs_describefeaturetype'] = $tmpOR;
+			$wfs_row['wfs_getfeature'] = $tmpOR;
+			$wfs_row['wfs_transaction'] = $tmpOR;
+		}
+	}
+	else {
+		//use owsproxy url
+		$tmpOR = $urlPrefix.$_SERVER["HTTP_HOST"]."/owsproxy/".$sessionId."/".$wfs_row["wfs_owsproxy"]."?";
+		$tmpOR = str_replace(SERVERIP, SERVERNAME, $tmpOR);
+		$wfs_row['wfs_describefeaturetype'] = $tmpOR;
+		$wfs_row['wfs_getfeature'] = $tmpOR;
+		$wfs_row['wfs_transaction'] = $tmpOR;
+	}
+}
+
+$elements = $xpath->query('//ows:OnlineResource');
+if ($elements->length >= 1) {
+	$element = $elements->item(0);
+	$element->setAttribute("xlink:href", $wfs_row['wfs_getcapabilities']);
+}
+
+$elements = $xpath->query('/wfs:WFS_Capabilities/ows:OperationsMetadata/ows:Operation[@name="GetCapabilities"]/ows:DCP/ows:HTTP/ows:Post');
+if ($elements->length >= 1) {
+	$element = $elements->item(0);
+	$element->setAttribute("xlink:href", $wfs_row['wfs_describefeaturetype']);
+}
+
+$elements = $xpath->query('/wfs:WFS_Capabilities/ows:OperationsMetadata/ows:Operation[@name="GetCapabilities"]/ows:DCP/ows:HTTP/ows:Get');
+if ($elements->length >= 1) {
+	$element = $elements->item(0);
+	$element->setAttribute("xlink:href", $wfs_row['wfs_describefeaturetype']);
+}
+
+$elements = $xpath->query('/wfs:WFS_Capabilities/ows:OperationsMetadata/ows:Operation[@name="DescribeFeatureType"]/ows:DCP/ows:HTTP/ows:Post');
+if ($elements->length >= 1) {
+	$element = $elements->item(0);
+	$element->setAttribute("xlink:href", $wfs_row['wfs_describefeaturetype']);
+}
+
+$elements = $xpath->query('/wfs:WFS_Capabilities/ows:OperationsMetadata/ows:Operation[@name="DescribeFeatureType"]/ows:DCP/ows:HTTP/ows:Get');
+if ($elements->length >= 1) {
+	$element = $elements->item(0);
+	$element->setAttribute("xlink:href", $wfs_row['wfs_describefeaturetype']);
+}
+
+$elements = $xpath->query('/wfs:WFS_Capabilities/ows:OperationsMetadata/ows:Operation[@name="GetFeature"]/ows:DCP/ows:HTTP/ows:Post');
+if ($elements->length >= 1) {
+	$element = $elements->item(0);
+	$element->setAttribute("xlink:href", $wfs_row['wfs_describefeaturetype']);
+}
+
+$elements = $xpath->query('/wfs:WFS_Capabilities/ows:OperationsMetadata/ows:Operation[@name="GetFeature"]/ows:DCP/ows:HTTP/ows:Get');
+if ($elements->length >= 1) {
+	$element = $elements->item(0);
+	$element->setAttribute("xlink:href", $wfs_row['wfs_describefeaturetype']);
+}
+
+
+################################################################
+#INSPIRE
+if ($inspire) {
+	
+	$refNodes = $xpath->query('//ows:OperationsMetadata');
+	$refNode = $refNodes->item(0);
+		
+	#generating the vendor specific node
+	$vendorSpecificCapabilities = $doc->createElement("VendorSpecificCapabilities");
+	$vendorSpecificCapabilities = $refNode->appendChild($vendorSpecificCapabilities);
+	#generate inspire_vs:ExtendedCapabilities node
+	$inspire_vs_ExtendedCapabilities = $doc->createElement("inspire_vs:ExtendedCapabilities");
+	$inspire_vs_ExtendedCapabilities->setAttribute("xmlns:inspire_vs", "http://inspire.ec.europa.eu/schemas/inspire_vs/1.0");
+	$inspire_vs_ExtendedCapabilities = $vendorSpecificCapabilities->appendChild($inspire_vs_ExtendedCapabilities);
+	#generate inspire_vs: node
+	#$inspire_vs_ExtendedCapabilities = $doc->createElement("inspire_vs:ExtendedCapabilities");
+	#$inspire_vs_ExtendedCapabilities = $vendorSpecificCapabilities->appendChild($inspire_vs_ExtendedCapabilities);
+	#MetadataUrl to inspire service metadata
+	$inspire_common_MetadataUrl = $doc->createElement("inspire_common:MetadataUrl");
+	/*<inspire_common:MetadataUrl xmlns:inspire_common="http://inspire.ec.europa.eu/schemas/common/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="inspire_common:resourceLocatorType">*/
+	$inspire_common_MetadataUrl->setAttribute("xmlns:inspire_common", "http://inspire.ec.europa.eu/schemas/common/1.0");
+	$inspire_common_MetadataUrl->setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
+	$inspire_common_MetadataUrl->setAttribute("xsi:type", "inspire_common:resourceLocatorType");
+	$inspire_common_MetadataUrl = $inspire_vs_ExtendedCapabilities->appendChild($inspire_common_MetadataUrl);
+	#URL
+	$inspire_common_URL = $doc->createElement("inspire_common:URL");
+	$inspire_common_URL->setAttribute("xmlns:inspire_common", "http://inspire.ec.europa.eu/schemas/common/1.0");
+
+	$inspire_common_URLText = $doc->createTextNode($inspireServiceMetadataUrl.$layerId);
+	$inspire_common_URL->appendChild($inspire_common_URLText);
+	$inspire_common_URL = $inspire_common_MetadataUrl->appendChild($inspire_common_URL);
+	#MediaType
+	$inspire_common_MediaType = $doc->createElement("inspire_common:MediaType");
+	$inspire_common_MediaType->setAttribute("xmlns:inspire_common", "http://inspire.ec.europa.eu/schemas/common/1.0");
+	$inspire_common_MediaTypeText = $doc->createTextNode('application/vnd.iso.19139+xml');#from http://inspire.ec.europa.eu/schemas/inspire_vs/1.0/examples/WMS_Image2000GetCapabilities_InspireSchema.xml
+	$inspire_common_MediaType->appendChild($inspire_common_MediaTypeText);
+	$inspire_common_MediaType = $inspire_common_MetadataUrl->appendChild($inspire_common_MediaType);
+	#Language Part
+	#SupportedLanguages
+	$inspire_common_SupportedLanguages = $doc->createElement("inspire_common:SupportedLanguages");
+	$inspire_common_SupportedLanguages = $inspire_vs_ExtendedCapabilities->appendChild($inspire_common_SupportedLanguages);
+	#DefaultLanguage
+	$inspire_common_DefaultLanguage = $doc->createElement("inspire_common:DefaultLanguage");
+	$inspire_common_DefaultLanguage = $inspire_common_SupportedLanguages->appendChild($inspire_common_DefaultLanguage);
+	#Language
+	$inspire_common_Language = $doc->createElement("inspire_common:Language");
+	$inspire_common_LanguageText = $doc->createTextNode('ger');
+	$inspire_common_Language->appendChild($inspire_common_LanguageText);
+	$inspire_common_Language = $inspire_common_DefaultLanguage->appendChild($inspire_common_Language);
+	#SupportedLanguage
+	$inspire_common_SupportedLanguage = $doc->createElement("inspire_common:SupportedLanguage");
+	$inspire_common_SupportedLanguage = $inspire_common_SupportedLanguages->appendChild($inspire_common_SupportedLanguage);
+	#Language
+	$inspire_common_Language = $doc->createElement("inspire_common:Language");
+	$inspire_common_LanguageText = $doc->createTextNode('ger');
+	$inspire_common_Language->appendChild($inspire_common_LanguageText);
+	$inspire_common_Language = $inspire_common_SupportedLanguage->appendChild($inspire_common_Language);
+	#ResponseLanguage
+	$inspire_common_ResponseLanguage = $doc->createElement("inspire_common:ResponseLanguage");
+	$inspire_common_ResponseLanguage = $inspire_vs_ExtendedCapabilities->appendChild($inspire_common_ResponseLanguage);
+	#Language
+	$inspire_common_Language = $doc->createElement("inspire_common:Language");
+	$inspire_common_LanguageText = $doc->createTextNode('ger');
+	$inspire_common_Language->appendChild($inspire_common_LanguageText);
+	$inspire_common_Language = $inspire_common_ResponseLanguage->appendChild($inspire_common_Language);
+}
+
+header("Content-type: application/xhtml+xml; charset=UTF-8");
+echo $doc->saveXml();
+
+?>



More information about the Mapbender_commits mailing list