[Mapbender-commits] r8566 - in trunk/mapbender/http: classes php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Feb 21 01:15:41 PST 2013


Author: armin11
Date: 2013-02-21 01:15:41 -0800 (Thu, 21 Feb 2013)
New Revision: 8566

Modified:
   trunk/mapbender/http/classes/class_metadata_new.php
   trunk/mapbender/http/php/mod_layerISOMetadata.php
   trunk/mapbender/http/php/wms.php
Log:
Fix some inspire related problems and give owsproxy urls to search interface.

Modified: trunk/mapbender/http/classes/class_metadata_new.php
===================================================================
--- trunk/mapbender/http/classes/class_metadata_new.php	2013-02-20 13:00:05 UTC (rev 8565)
+++ trunk/mapbender/http/classes/class_metadata_new.php	2013-02-21 09:15:41 UTC (rev 8566)
@@ -1290,13 +1290,20 @@
 	}
 
 	private function getMapUrlfromWMSId($wmsId) {
-			$sql = "SELECT wms_getmap FROM wms WHERE wms_id = $1 AND (wms_owsproxy IS NULL OR wms_owsproxy ='')";
+			$sql = "SELECT wms_getmap, wms_owsproxy FROM wms WHERE wms_id = $1";
 			$v = array($wmsId);
 			$t = array('i');
 			$res = db_prep_query($sql, $v, $t);
 			while($row = db_fetch_array($res)){
 				$getMap = $row['wms_getmap'];
+				$owsProxy = $row['wms_owsproxy'];
 			}
+			//hostname does not exist! - use hostname from parameter instead
+			if ($owsProxy != null && $owsProxy != '') {
+				//create dummy session - no one knows the user which requests this metadata!
+				$sessionId = "00000000000000000000000000000000";
+				$getMap = "http://".$this->hostName."/owsproxy/".$sessionId."/".$owsProxy."?";
+			}
 			return $getMap; 
 
 	}

Modified: trunk/mapbender/http/php/mod_layerISOMetadata.php
===================================================================
--- trunk/mapbender/http/php/mod_layerISOMetadata.php	2013-02-20 13:00:05 UTC (rev 8565)
+++ trunk/mapbender/http/php/mod_layerISOMetadata.php	2013-02-21 09:15:41 UTC (rev 8566)
@@ -714,13 +714,13 @@
 	$gmd_URL=$iso19139->createElement("gmd:URL");
 
 	//Check if anonymous user has rights to access this layer - if not ? which resource should be advertised? TODO
-	if ($hasPermission) {
+	//if ($hasPermission) {
 		$gmd_URLText=$iso19139->createTextNode("http://".$_SERVER['HTTP_HOST']."/mapbender/php/wms.php?inspire=1&layer_id=".$mapbenderMetadata['layer_id']."&REQUEST=GetCapabilities&SERVICE=WMS");
-	}
-	else {
+	//}
+	/*else {
 		$serverWithOutPort80 = str_replace(":80","",$_SERVER['HTTP_HOST']);//fix problem when metadata is generated thru curl invocations
 		$gmd_URLText=$iso19139->createTextNode("https://".$serverWithOutPort80."/http_auth/".$mapbenderMetadata['layer_id']."?REQUEST=GetCapabilities&SERVICE=WMS");
-	}
+	}*/
 	$gmd_URL->appendChild($gmd_URLText);
 	$gmd_linkage->appendChild($gmd_URL);
 	$CI_OnlineResource->appendChild($gmd_linkage);

Modified: trunk/mapbender/http/php/wms.php
===================================================================
--- trunk/mapbender/http/php/wms.php	2013-02-20 13:00:05 UTC (rev 8565)
+++ trunk/mapbender/http/php/wms.php	2013-02-21 09:15:41 UTC (rev 8566)
@@ -19,8 +19,11 @@
 
 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) {
@@ -270,27 +273,66 @@
 }
 	
 # switch URLs for OWSPROXY
-if($wms_row['wms_owsproxy'] <> "" AND $wms_row['wms_owsproxy'] <> NULL) {
-	$tmpOR = $urlPrefix.$_SERVER["HTTP_HOST"]."/owsproxy/".$sessionId."/".$wms_row["wms_owsproxy"]."?";
-	$tmpOR = str_replace(SERVERIP, SERVERNAME, $tmpOR);
-	$wms_row['wms_getcapabilities'] = $tmpOR;
-	$wms_row['wms_getmap'] = $tmpOR;
-	$wms_row['wms_getfeatureinfo'] = $tmpOR;
 
+//check if resource is freely available to anonymous user - which are all users who search thru metadata catalogues:
+//$publicHasPermission=$admin->getLayerPermission($mapbenderMetadata['wms_id'],$mapbenderMetadata['layer_name'],PUBLIC_USER);
+//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
+
+//set new capabilities url:
+
+$tmpOR = $urlPrefix.$_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"]."?".$_SERVER["QUERY_STRING"];
+$tmpOR = str_replace(SERVERIP, SERVERNAME, $tmpOR);
+$wms_row['wms_getcapabilities'] = $tmpOR;
+
+if ($inspire) {
+	$wms_row['wms_getcapabilities'] .= "&INSPIRE=1";
 }
-#Creating the "OnlineResource" node
+
+$publicHasPermission=$admin->getLayerPermission($wms_row['wms_id'],$wms_row['layer_name'],PUBLIC_USER);
+if ($wms_row['wms_owsproxy'] <> "" AND $wms_row['wms_owsproxy'] <> NULL) {
+	if ($inspire) {
+		if ($publicHasPermission) {
+			//use owsproxy url
+			$tmpOR = $urlPrefix.$_SERVER["HTTP_HOST"]."/owsproxy/".$sessionId."/".$wms_row["wms_owsproxy"]."?";
+			$tmpOR = str_replace(SERVERIP, SERVERNAME, $tmpOR);
+			$wms_row['wms_getmap'] = $tmpOR;
+			$wms_row['wms_getfeatureinfo'] = $tmpOR;
+			$wms_row['wms_getlegendgraphics'] = $tmpOR;
+		} else {
+			//use http_auth
+			$tmpOR = $urlPrefix.$_SERVER["HTTP_HOST"]."/http_auth/".$layerId."?";
+			$tmpOR = str_replace(SERVERIP, SERVERNAME, $tmpOR);
+			$wms_row['wms_getmap'] = $tmpOR;
+			$wms_row['wms_getfeatureinfo'] = $tmpOR;
+			$wms_row['wms_getlegendgraphics'] = $tmpOR;
+		}
+	}	
+	else {
+		//use owsproxy url
+		$tmpOR = $urlPrefix.$_SERVER["HTTP_HOST"]."/owsproxy/".$sessionId."/".$wms_row["wms_owsproxy"]."?";
+		$tmpOR = str_replace(SERVERIP, SERVERNAME, $tmpOR);
+		$wms_row['wms_getmap'] = $tmpOR;
+		$wms_row['wms_getfeatureinfo'] = $tmpOR;
+		$wms_row['wms_getlegendgraphics'] = $tmpOR;
+	}
+} 
+
+//Creating the "OnlineResource" node
 //if($wms_row['wms_getcapabilities'] <> "" AND $wms_row['wms_getcapabilities'] <> NULL) {
     $onlineResource = $doc->createElement("OnlineResource");
 	$onlineResource = $service->appendChild($onlineResource);
 	$onlineResource->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink" );
-//	$onlineResource->setAttribute("xlink:href", $wms_row['wms_getcapabilities']);
-	$onlRes = $_SERVER["HTTP_HOST"] . $_SERVER["SCRIPT_NAME"] . "?layer_id=" . $layerId."&".session_name()."=".$sessionId;
+	$onlineResource->setAttribute("xlink:href", $wms_row['wms_getcapabilities']);
+/*	$onlRes = $_SERVER["HTTP_HOST"] . $_SERVER["SCRIPT_NAME"] . "?layer_id=" . $layerId."&".session_name()."=".$sessionId;
 	if (isset($_SERVER["HTTPS"])) {
 		$onlRes = "https://" . $onlRes;
 	}
 	else {
 		$onlRes = "http://" . $onlRes;
-	}
+	}*/
 	$onlineResource->setAttribute("xlink:href", $onlRes);
 	$onlineResource->setAttribute("xlink:type", "simple");
 //}
@@ -505,8 +547,8 @@
 	$onlineResource = $doc->createElement("OnlineResource");
 	$onlineResource = $get->appendChild($onlineResource);
 	$onlineResource->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
-//	$onlineResource->setAttribute("xlink:href", $wms_row['wms_getcapabilities']);
-	$onlRes = $_SERVER["HTTP_HOST"] . $_SERVER["SCRIPT_NAME"] . "?layer_id=" . $layerId;
+	$onlineResource->setAttribute("xlink:href", $wms_row['wms_getcapabilities']);
+/*	$onlRes = $_SERVER["HTTP_HOST"] . $_SERVER["SCRIPT_NAME"] . "?layer_id=" . $layerId;
 
 	if ($inspire) {
 	$onlRes = $onlRes."&INSPIRE=1";
@@ -517,7 +559,7 @@
 	}
 	else {
 		$onlRes = "http://" . $onlRes;
-	}
+	}*/
 	$onlineResource->setAttribute("xlink:href", $onlRes);
 	$onlineResource->setAttribute("xlink:type", "simple");		
 //}
@@ -531,8 +573,8 @@
 	$onlineResource = $doc->createElement("OnlineResource");
 	$onlineResource = $post->appendChild($onlineResource);
 	$onlineResource->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
-//	$onlineResource->setAttribute("xlink:href", $wms_row['wms_getcapabilities']);
-	$onlRes = $_SERVER["HTTP_HOST"] . $_SERVER["SCRIPT_NAME"] . "?layer_id=" . $layerId;
+	$onlineResource->setAttribute("xlink:href", $wms_row['wms_getcapabilities']);
+/*	$onlRes = $_SERVER["HTTP_HOST"] . $_SERVER["SCRIPT_NAME"] . "?layer_id=" . $layerId;
 
 	if ($inspire) {
 	$onlRes = $onlRes."&INSPIRE=1&";
@@ -543,7 +585,7 @@
 	}
 	else {
 		$onlRes = "http://" . $onlRes;
-	}
+	}*/
 	$onlineResource->setAttribute("xlink:href", $onlRes);
 	$onlineResource->setAttribute("xlink:type", "simple");
 //}
@@ -1228,8 +1270,8 @@
 		//$e = new mb_exception("i: ".$i);
 	}
 	
-
-	# Creating DataURL Node
+	#Creating DataURL Node - use it from database if it will exist!
+		
 	$dataUrl = $doc->createElement("DataURL");
 	$dataUrl = $sub_layer->appendChild($dataUrl);
 	$format = $doc->createElement("Format");
@@ -1237,89 +1279,91 @@
     	$formatText = $doc->createTextNode('text/html');
    	$formatText = $format->appendChild($formatText); 
 
-	/*if($wms_row['wms_owsproxy'] <> "" AND $wms_row['wms_owsproxy'] <> NULL)
+	if ($sub_layer_row['layer_dataurl'] <> "" AND $sub_layer_row['layer_dataurl'] <> NULL) {
+	    	$onlineResource = $doc->createElement("OnlineResource");
+	    	$onlineResource = $dataUrl->appendChild($onlineResource);
+		$onlineResource->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink" );
+		$onlineResource->setAttribute("xlink:href", $sub_layer_row['layer_dataurl']);
+		$onlineResource->setAttribute("xlink:type", "simple");
+    	}
+	else
 	{
-		$onlineResource = $doc->createElement("OnlineResource");
-	   	$onlineResource = $dataUrl->appendChild($onlineResource);
-	   	$onlineResource->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink" );
-		$onlineResource->setAttribute("xlink:href", OWSPROXY."/".$sessionId."/".$wms_row["wms_owsproxy"]."?");
+ 		$onlineResource = $doc->createElement("OnlineResource");
+             	$onlineResource = $dataUrl->appendChild($onlineResource);
+                $onlineResource->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink" );
+                $onlineResource->setAttribute("xlink:href", $mapbenderMetadataUrl.$sub_layer_row['layer_id']);
 		$onlineResource->setAttribute("xlink:type", "simple");
-	}
-	else
-	{*/
-		if($sub_layer_row['layer_dataurl'] <> "" AND $sub_layer_row['layer_dataurl'] <> NULL) {
-	    		$onlineResource = $doc->createElement("OnlineResource");
-	    		$onlineResource = $dataUrl->appendChild($onlineResource);
-			$onlineResource->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink" );
-			$onlineResource->setAttribute("xlink:href", $sub_layer_row['layer_dataurl']);
-			$onlineResource->setAttribute("xlink:type", "simple");
-	    	}
-		else
-		{
- 			$onlineResource = $doc->createElement("OnlineResource");
-                	$onlineResource = $dataUrl->appendChild($onlineResource);
-                        $onlineResource->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink" );
-                        $onlineResource->setAttribute("xlink:href", $mapbenderMetadataUrl.$sub_layer_row['layer_id']);
-                        $onlineResource->setAttribute("xlink:type", "simple");
-}
-	//}	
+	}	
 	
-	#Creating Style Node TODO: pull style and format from database!
-	$style = $doc->createElement("Style");
-	$style = $sub_layer->appendChild($style);
-	
-	$name = $doc->createElement("Name");
-    	$name = $style->appendChild($name);
-    	$nameText = $doc->createTextNode('default');
-    	$nameText = $name->appendChild($nameText);
+	//Creating Style Node by pulling style and format from database!
+	//for each possible style
+	//check for number of styles, check for name 'default'
+	//$subLayerId 
+$sql = <<<SQL
 
-	$title = $doc->createElement("Title");
-    	$title = $style->appendChild($title);
-    	$titleText = $doc->createTextNode('default');
-    	$titleText = $title->appendChild($titleText);
-	
+SELECT * FROM layer_style WHERE fkey_layer_id = $subLayerId 
 
+SQL;
 
-    if($wms_row['wms_getlegendurl'] <> "" AND $wms_row['wms_getlegendurl'] <> NULL){	
-	$legendUrl = $doc->createElement("LegendURL");
-	$legendUrl = $style->appendChild($legendUrl);
-	$legendUrl->setAttribute("width", "10" );
-	$legendUrl->setAttribute("height", "8" );
+	$res_style = db_query($sql);
 
-	$format = $doc->createElement("Format");
-    	$format = $legendUrl->appendChild($format);
-    	$formatText = $doc->createTextNode('image/png');
-    	$formatText = $format->appendChild($formatText); 
-
-	if($wms_row['wms_owsproxy'] <> "" AND $wms_row['wms_owsproxy'] <> NULL)
-	{
-		$onlineResource = $doc->createElement("OnlineResource");
-	   	$onlineResource = $legendUrl->appendChild($onlineResource);
-	   	$onlineResource->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink" );
-		$onlineResource->setAttribute("xlink:href", str_replace(":80","",OWSPROXY)."/".$sessionId."/".$wms_row["wms_owsproxy"]."?version=1.1.1&service=WMS&request=GetLegendGraphic&layer=".$sub_layer_row['layer_name']."&format=image/png&style=default");
-		$onlineResource->setAttribute("xlink:type", "simple");
-	}
-	else
-	{
-		if($wms_row['wms_getlegendurl'] <> "" AND $wms_row['wms_getlegendurl'] <> NULL)
-	    {
-	    	$onlineResource = $doc->createElement("OnlineResource");
-	    	$onlineResource = $legendUrl->appendChild($onlineResource);
+	while ($row_style = db_fetch_array($res_style)) {
+		$style = $doc->createElement("Style");
+		$style = $sub_layer->appendChild($style);
+		$name = $doc->createElement("Name");
+    		$name = $style->appendChild($name);
+		if ($row_style['name'] != '') {
+    			$nameText = $doc->createTextNode($row_style['name']);
+		} else {
+			$nameText = $doc->createTextNode('default');
+		}
+    		$nameText = $name->appendChild($nameText);
+		$title = $doc->createElement("Title");
+    		$title = $style->appendChild($title);
+		if ($row_style['title'] != '') {
+    			$titleText = $doc->createTextNode($row_style['title']);
+		} else {
+			$titleText = $doc->createTextNode('default');
+		}
+    		$titleText = $title->appendChild($titleText);
+		//if server supports get legend graphic	
+		if(($wms_row['wms_getlegendurl'] <> "" AND $wms_row['wms_getlegendurl'] <> NULL) || ($row_style['legendurl'] <> "" AND $row_style['legendurl'] <> NULL)){	
+			$legendUrl = $doc->createElement("LegendURL");
+			$legendUrl = $style->appendChild($legendUrl);
+			$legendUrl->setAttribute("width", "10" );
+			$legendUrl->setAttribute("height", "8" );
+			$format = $doc->createElement("Format");
+    			$format = $legendUrl->appendChild($format);
+			if ($row_style['format'] != '') {
+    				$formatText = $doc->createTextNode($row_style['format']);
+			} else {
+				$formatText = $doc->createTextNode('image/png');
+			}
+    			$formatText = $format->appendChild($formatText); 
+			$onlineResource = $doc->createElement("OnlineResource");
+			$onlineResource = $legendUrl->appendChild($onlineResource);
 			$onlineResource->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink" );
-			$onlineResource->setAttribute("xlink:href", $wms_row['wms_getlegendurl']."version=1.1.1&service=WMS&request=GetLegendGraphic&layer=".$sub_layer_row['layer_name']."&format=image/png");
+			if ($wms_row['wms_getlegendurl'] <> "" AND $wms_row['wms_getlegendurl'] <> NULL) {
+				$onlineResource->setAttribute("xlink:href", $wms_row['wms_getlegendurl']."version=1.1.1&service=WMS&request=GetLegendGraphic&layer=".$sub_layer_row['layer_name']."&format=image/png");
+			} else {
+				//other stupid check - TODO: make it better
+				if (strpos($row_style['legendurl'], "http:") === false) {
+					$onlineResource->setAttribute("xlink:href", $wms_row['wms_getlegendurl'].$row_style['legendurl']);
+				} else {
+					$onlineResource->setAttribute("xlink:href", $row_style['legendurl']);
+				}
+			}
 			$onlineResource->setAttribute("xlink:type", "simple");
-	    }
+		}
 	}
-}
-	#Creating "ScaleHint" node
-    if ($sub_layer_row['layer_minscale'] <> "" AND $sub_layer_row['layer_minscale'] <> NULL) {
+	//Creating "ScaleHint" node
+	if ($sub_layer_row['layer_minscale'] <> "" AND $sub_layer_row['layer_minscale'] <> NULL) {
 		$scaleHint = $doc->createElement("ScaleHint");
 		$scaleHint = $sub_layer->appendChild($scaleHint);
 		$scaleHint->setAttribute('min', (floatval($sub_layer_row['layer_minscale'])/2004.3976484406788493955738891127));
 		$scaleHint->setAttribute('max', (floatval($sub_layer_row['layer_maxscale'])/2004.3976484406788493955738891127));
-    }
-}	
-
+	}	
+}
 header("Content-type: application/xhtml+xml; charset=UTF-8");
 echo $doc->saveXml();
 ?>



More information about the Mapbender_commits mailing list