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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Oct 26 14:36:03 EDT 2010


Author: armin11
Date: 2010-10-26 11:36:03 -0700 (Tue, 26 Oct 2010)
New Revision: 7066

Added:
   trunk/mapbender/http/classes/class_tou.php
   trunk/mapbender/http/geoportal/mod_initialStartWmc.php
   trunk/mapbender/http/php/mod_getWmcDisclaimer.php
Log:
Some enhancement - major for wmc handling. Json server component to serve the most popular wmc docs. It can be used to show combined maps as start option for geoportals (see http://www.gdi-rp-dienste3.rlp.de)

Added: trunk/mapbender/http/classes/class_tou.php
===================================================================
--- trunk/mapbender/http/classes/class_tou.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_tou.php	2010-10-26 18:36:03 UTC (rev 7066)
@@ -0,0 +1,100 @@
+<?php
+require_once(dirname(__FILE__) . "/../../core/globalSettings.php");
+require_once(dirname(__FILE__) . "/../classes/class_json.php");
+
+class tou{
+ 	private $id;
+	private $json;
+	private $acceptedTou;
+	//obj structure for acceptedTou:
+	//acceptedTou {
+	//		wms [100,101,112],
+	//		wfs [12,34]
+	//		}
+
+ 	
+ 	/**
+	 * @constructor
+	 */
+ 	function __construct() {
+ 		$id = false;
+		$this->json = new Mapbender_JSON();
+
+		$resultObject = array();
+ 		new mb_notice("mapbender tou instantiated ... ");
+ 	}
+
+	function set($serviceType, $serviceId) {
+		if (!Mapbender::session()->exists("acceptedTou")) {
+			//create one initially
+			$acceptedTou = new stdClass;
+			$acceptedTou = (object) array(
+				'wms' => array(),
+				'wfs' => array()
+				);
+			
+			$acceptedTou->{$serviceType}[0] = $serviceId;
+			$acceptedTouJson = $this->json->encode($acceptedTou);
+			Mapbender::session()->set("acceptedTou",$acceptedTouJson);
+			$resultObj = array(
+				"setTou" => 1,
+				"message" => "New session var acceptedTou generated"
+			);
+			return $resultObj;
+		} else {
+			//tou has been set before - add an element to the corresponding list
+			$acceptedTou = Mapbender::session()->get("acceptedTou");
+			$acceptedTou = json_decode($acceptedTou);
+			#print_r($acceptedTou);
+			$serviceIdArray = $acceptedTou->{$serviceType};
+			//check if id is defined in array already if not append it
+			if (!in_array($serviceId,$serviceIdArray)) {
+				array_push($acceptedTou->{$serviceType},$serviceId);
+				$acceptedTouJson = $this->json->encode($acceptedTou);
+				Mapbender::session()->set("acceptedTou",$acceptedTouJson);
+				$resultObj = array(
+					"setTou" => 1,
+					"message" => "Id appended to existing session var acceptedTou"
+				);
+			} else {
+				$resultObj = array(
+					"setTou" => 0,
+					"message" => "Id was set before, don't append to session var acceptedTou"
+				);
+			}
+			return $resultObj;
+		}
+	}
+
+	function check($serviceType, $serviceId) {
+		if (!Mapbender::session()->exists("acceptedTou")) {
+			$resultObj = array(
+				"accepted" => 0,
+				"message" => "No session var acceptedTou exists til now"
+			);	
+			return $resultObj;
+		} else {		
+			$acceptedTou = Mapbender::session()->get("acceptedTou");
+			$acceptedTou = json_decode($acceptedTou);
+			//read out service part
+			$serviceIdArray = $acceptedTou->{$serviceType};
+			#print_r($serviceIdArray);
+			if (in_array($serviceId,$serviceIdArray)) {
+				$resultObj = array(
+					"accepted" => 1,
+					"message" => "Session var acceptedTou found - id was set before - don't show tou anymore"
+				);
+				return $resultObj;
+			} else {
+				$resultObj = array(
+					"accepted" => 0,
+					"message" => "Session var acceptedTou found - id was not set before - show tou before load resource"
+				);	
+				return $resultObj;
+			}
+		}
+	}
+
+}
+
+?>

Added: trunk/mapbender/http/geoportal/mod_initialStartWmc.php
===================================================================
--- trunk/mapbender/http/geoportal/mod_initialStartWmc.php	                        (rev 0)
+++ trunk/mapbender/http/geoportal/mod_initialStartWmc.php	2010-10-26 18:36:03 UTC (rev 7066)
@@ -0,0 +1,122 @@
+<?php
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+$con = db_connect(DBSERVER,OWNER,PW);
+db_select_db(DB,$con);
+$languageCode = 'de';
+$maxObjects = 10;
+$outputFormat = 'json';
+$hostName = $_SERVER['HTTP_HOST'];
+$pathToLoadScript = '/portal/karten.html?WMC=';
+$pathToMetadata = '/mapbender/php/mod_showMetadata.php?';
+$pathToPreview = '/mapbender/geoportal/mod_showPreview.php?';
+if (isset($_REQUEST["outputFormat"]) & $_REQUEST["outputFormat"] != "") {
+	$testMatch = $_REQUEST["outputFormat"];	
+ 	if (!($testMatch == 'html' or $testMatch == 'json')){ 
+		echo 'outputFormat: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	$outputFormat = $testMatch;
+	$testMatch = NULL;
+}
+if (isset($_REQUEST["maxObjects"]) & $_REQUEST["maxObjects"] != "") {
+	$testMatch = $_REQUEST["maxObjects"];	
+ 	$pattern = '/^[0-9]*$/';  
+        if (!preg_match($pattern,$testMatch)){
+                echo 'maxObjects: <b>'.$testMatch.'</b> is not valid.<br/>';
+                die();
+        }	
+	$maxObjects = (integer)$testMatch;
+	if ($maxObjects > 15){
+                echo '<b>'.$maxObjects.'</b> objects are too much, at maximum 15 ojects are allowed.<br/>';
+                die();
+        }	
+	$testMatch = NULL;
+}
+if (isset($_REQUEST["languageCode"]) & $_REQUEST["languageCode"] != "") {
+	//validate to wms, wfs
+	$testMatch = $_REQUEST["languageCode"];	
+ 	if (!($testMatch == 'de' or $testMatch == 'en')){ 
+		echo 'languageCode: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	$languageCode = $testMatch;
+	$testMatch = NULL;
+}
+if (isset($_REQUEST["hostName"]) & $_REQUEST["hostName"] != "") {
+	//validate to some hosts
+	$testMatch = $_REQUEST["hostName"];	
+ 	if (!($testMatch == 'www.geoportal.rlp' or $testMatch == 'www.geoportal.rlp.de' or  $testMatch == 'www.gdi-rp-dienste3.rlp.de' or  $testMatch == '10.7.101.151')){ 
+		echo 'hostName: <b>'.$testMatch.'</b> is not a valid server of gdi-rp.<br/>'; 
+		die(); 		
+ 	}
+	$hostName = $testMatch;
+	$testMatch = NULL;
+}
+if ($outputFormat == 'json'){
+	$classJSON = new Mapbender_JSON;
+}
+if ($languageCode == 'en'){
+	$pathToLoadScript = '/portal/maps.html?WMC=';
+}
+//define sql for selecting informations from database:
+$sql = "";
+$sql .= "SELECT search_wmc_view.wmc_serial_id,search_wmc_view.wmc_title,search_wmc_view.wmc_abstract, custom_category.custom_category_code_".$languageCode. " ";
+$sql .= "FROM search_wmc_view INNER JOIN wmc_custom_category ON "; 
+$sql .= "(wmc_custom_category.fkey_wmc_serial_id=search_wmc_view.wmc_serial_id) INNER JOIN custom_category ON ";
+$sql .= "(custom_category.custom_category_id=wmc_custom_category.fkey_custom_category_id) WHERE ";
+$sql .= "custom_category.custom_category_key = 'mbc1' LIMIT $1";
+
+$v = array($maxObjects);
+$t = array('i');
+$res = db_prep_query($sql,$v,$t);
+
+$initialWmc = array();
+$i = 0;
+while($row = db_fetch_array($res)){
+	$initialWmc[$i] = array('id'  =>$row['wmc_serial_id'], 'title' =>$row['wmc_title'], 'abstract' =>$row['wmc_abstract'],'loadUrl'=>'http://'.$hostName.$pathToLoadScript.$row['wmc_serial_id'],'metadataUrl'=>'http://'.$hostName.$pathToMetadata."languageCode=".$languageCode."&resource=wmc&id=".$row['wmc_serial_id'], 'previewUrl'=>'http://'.$hostName.$pathToPreview."resource=wmc&id=".$row['wmc_serial_id']);
+	$i++;
+}
+
+if ($outputFormat == 'html'){
+	
+	echo "<html>";
+	echo "<title>Mapbender Initial WMC</title>";
+	echo "<body>";
+		for($i=0; $i<count($initialWmc);$i++){
+			echo "<b>ID: </b>".$initialWmc[$i]['id']."<br>";
+				echo "<b>Titel: </b>".$initialWmc[$i]['title']."<br>";
+				echo "<b>Zusammenfassung: </b>".$initialWmc[$i]['abstract']."<br>";
+				echo "<b>Metadaten: </b><a href='".$initialWmc[$i]['metadataUrl']."'>".$initialWmc[$i]['metadataUrl']."</a>"."<br>";
+				echo "<b>Öffnen: </b><a href='".$initialWmc[$i]['loadUrl']."'>".$initialWmc[$i]['loadUrl']."</a>"."<br>";
+				echo "<b>Preview Link: </b><a href='".$initialWmc[$i]['previewUrl']."'>".$initialWmc[$i]['previewUrl']."</a>"."<br>";
+				echo "<b>Preview: </b><img src='".$initialWmc[$i]['previewUrl']."'/>"."<br>";
+				echo "<hr>";
+			}
+	echo "</body>";
+	echo "</html>";
+}
+
+if ($outputFormat == 'json'){
+	$wmcJSON = new stdClass;
+	$wmcJSON->initialWmcDocs = array();
+	for($i=0; $i<count($initialWmc);$i++){
+    		$wmcJSON->initialWmcDocs[$i]->id = $initialWmc[$i]['id'];
+		$wmcJSON->initialWmcDocs[$i]->title = $initialWmc[$i]['title'];
+		$wmcJSON->initialWmcDocs[$i]->abstract = $initialWmc[$i]['abstract'];
+		$wmcJSON->initialWmcDocs[$i]->metadataUrl = $initialWmc[$i]['metadataUrl'];
+		$wmcJSON->initialWmcDocs[$i]->loadUrl = $initialWmc[$i]['loadUrl'];
+		$wmcJSON->initialWmcDocs[$i]->previewUrl = $initialWmc[$i]['previewUrl'];
+		$wmcJSON->initialWmcDocs[$i]->loadCount = 10;
+   	 }
+	$wmcJSON = $classJSON->encode($wmcJSON);
+	echo $wmcJSON;
+}
+
+
+
+
+
+
+
+?>

Added: trunk/mapbender/http/php/mod_getWmcDisclaimer.php
===================================================================
--- trunk/mapbender/http/php/mod_getWmcDisclaimer.php	                        (rev 0)
+++ trunk/mapbender/http/php/mod_getWmcDisclaimer.php	2010-10-26 18:36:03 UTC (rev 7066)
@@ -0,0 +1,112 @@
+<?php require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+require_once dirname(__FILE__) . "/../classes/class_wmc_factory.php";
+require_once(dirname(__FILE__) . "/../classes/class_user.php");
+
+//following is needed cause sometimes the service is invoked as a localhost service and then no userId is known but the userId in the session is needed for class_wmc to read from database!!! TODO: check if needed in this class.
+$userId = Mapbender::session()->get("mb_user_id");
+if (!isset($userId) or $userId =='') {
+	$userId = ANONYMOUS_USER; //or public
+	Mapbender::session()->set("mb_user_id",$userId);
+}
+$languageCode = 'de';
+//parameters: 
+//id - wmc id
+//languageCode - language parameter 'de', 'en', 'fr' 
+//$wmsServiceDisclaimerUrl = "";
+
+//initialize variables
+$hostName = $_SERVER['HTTP_HOST'];
+$userId = ANONYMOUS_USER;
+$id = 4373; //dummy id
+//TODO give requesting hostname to this script
+if (isset($_REQUEST["id"]) & $_REQUEST["id"] != "") {
+	//validate to integer 
+	$testMatch = $_REQUEST["id"];
+	$pattern = '/^[\d]*$/';		
+ 	if (!preg_match($pattern,$testMatch)){ 
+		echo 'id: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	$id = (integer)$testMatch;
+	$testMatch = NULL;	
+}
+//TODO give requesting hostname to this script
+if (isset($_REQUEST["hostName"]) & $_REQUEST["hostName"] != "") {
+	$testMatch = $_REQUEST["hostName"];	
+ 	if (!($testMatch == 'www.geoportal.rlp' or $testMatch == 'www.geoportal.rlp.de' or $testMatch == 'geoportal.rlp' or $testMatch == '10.7.101.165' or $testMatch == '10.7.101.151' or $testMatch == 'localhost' or $testMatch == 'www.gdi-rp-dienste3.rlp.de' )){ 
+		echo 'hostName: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	$hostName = $testMatch;
+	$testMatch = NULL;
+}
+$e = new mb_exception("mod_getWmcDisclaimer.php: requested wmc id: ".$_REQUEST["id"]);
+//
+//
+if (isset($_REQUEST["languageCode"]) & $_REQUEST["languageCode"] != "") {
+	//validate to wms, wfs
+	$testMatch = $_REQUEST["languageCode"];	
+ 	if (!($testMatch == 'de' or $testMatch == 'en' or  $testMatch == 'fr')){ 
+		echo 'type: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	$languageCode = $testMatch;
+	$testMatch = NULL;
+}
+
+//Array with translations:
+switch ($languageCode) {
+	case "de":
+		$translation['wmcDisclaimerHeader'] = 'Das vorliegende Dokument enthält Datenquellen von unterschiedlichen Stellen. Diese unterliegen den im folgenden aufgeführten Nutzungsbedingungen:';
+		$translation['wms'] = "Kartendienst";
+		$translation['wfs'] = "Datendienst";
+		break;
+	case "en":
+		$translation['wmcDisclaimerHeader'] = 'The document includes data resources from different organizations. The following parapgraph shows the different terms of use for the includes resources:';
+		$translation['wms'] = "Web Map Service";
+		$translation['wfs'] = "Web Feature Service";
+		break;
+	default: #to english
+		$translation['wmcDisclaimerHeader'] = 'The document includes data resources from different organizations. The following parapgraph shows the different terms of use for the includes resources:';
+		$translation['wms'] = "Web Map Service";
+		$translation['wfs'] = "Web Feature Service";
+}
+
+
+
+
+
+
+
+
+
+//javascript:openwindow("../php/mod_showMetadata.php?resource=layer&layout=tabs&redirectToMetadataUrl=1&id=20655");
+//Generate wmc document by id
+$wmcFactory = new WmcFactory;
+$e = new mb_exception("mod_getWmcDisclaimer.php: wmcid: ".$id);
+$wmcObj = $wmcFactory->createFromDb($id);
+//generate header for disclaimer:
+echo "<b>".$translation['wmcDisclaimerHeader']."</b><br><br>";#
+
+//Part for wms
+$resourceSymbol = "<img src='../img/osgeo_graphics/geosilk/server_map.png' alt='".$translation['wms']." - picture' title='".$translation['wms']."'>";
+//read out all wms id's
+$validWMS = $wmcObj->getValidWms();
+foreach($validWMS as $WMS) {
+	echo $resourceSymbol." <a href='http://".$hostName."/mapbender/php/mod_showMetadata.php?resource=wms&layout=tabs&id=".$WMS['id']."&languageCode=".$languageCode."'>".$WMS['title']."</a><br>";
+	$wmstou = file_get_contents("http://localhost/mapbender/php/mod_getServiceDisclaimer.php?resource=wms&id=".$WMS['id']."&languageCode=".$languageCode."&asTable=true");
+	echo $wmstou."<br>";
+}
+//var_dump($validWMS);
+//module to read out all service ids which are stored in mapbender wmc documents and generate a Big Disclaimer for those Docs.
+//It integrates all known disclaimers for the used webservices who are stored in the mapbender registry
+
+//read out all wms id's
+//read out all wfs id's
+//generate the disclaimer part for wms 
+//generate the disclaimer part for wfs
+//push disclaimer to json or html
+
+
+?>



More information about the Mapbender_commits mailing list