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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Jun 8 07:56:18 EDT 2010


Author: armin11
Date: 2010-06-08 07:56:17 -0400 (Tue, 08 Jun 2010)
New Revision: 6244

Added:
   trunk/mapbender/http/php/mod_getServiceDisclaimer.php
   trunk/mapbender/http/php/tagCloud.php
Modified:
   trunk/mapbender/http/classes/class_metadata_new.php
   trunk/mapbender/http/php/mod_callMetadata.php
Log:
some files for the new mb searchInterface

Modified: trunk/mapbender/http/classes/class_metadata_new.php
===================================================================
--- trunk/mapbender/http/classes/class_metadata_new.php	2010-06-02 15:20:17 UTC (rev 6243)
+++ trunk/mapbender/http/classes/class_metadata_new.php	2010-06-08 11:56:17 UTC (rev 6244)
@@ -84,7 +84,16 @@
 		$this->searchURL = $searchURL;
 		$this->hostName = $hostName;
 		$this->orderBy = $orderBy;
-		
+		//definitions for tags
+		$this->maxObjects = 15;
+		$this->maxFontSize = 30;
+		$this->maxWeight = 0;
+		$this->scale == 'linear';
+
+
+
+
+
 		$this->tempFolder = TMPDIR; //TODO define another path - maybe the one which is given in mapbender.conf
 		if ($this->outputFormat == 'json'){
 			$this->json = new Mapbender_JSON;
@@ -136,24 +145,28 @@
 			$this->resourceCategories[1]['name2show'] = 'Such- und Downloaddienste';
 			$this->resourceCategories[2]['name2show'] = 'Kartenzusammenstellungen';
 			$this->resourceCategories[3]['name2show'] = 'Geokodierte Newsfeeds';
+			$this->keywordTitle = 'Schlagwortliste';
        			break;
         		case 'en':
                		$this->resourceCategories[0]['name2show'] = 'Viewingservices';
 			$this->resourceCategories[1]['name2show'] = 'Search- and Downloadservices';
 			$this->resourceCategories[2]['name2show'] = 'Combined Maps';
 			$this->resourceCategories[3]['name2show'] = 'Geocodet Newsfeeds';
+			$this->keywordTitle = 'Keywordlist';
         		break;
         		case 'fr':
           	     	$this->resourceCategories[0]['name2show'] = 'Viewingservices';
 			$this->resourceCategories[1]['name2show'] = 'Search- and Downloadservices';
 			$this->resourceCategories[2]['name2show'] = 'Combined Maps';
 			$this->resourceCategories[3]['name2show'] = 'Geocodet Newsfeeds';
+			$this->keywordTitle = 'Keywordlist';
        			break;
      			default:
                 	$this->resourceCategories[0]['name2show'] = 'Darstellungsdienste';
 			$this->resourceCategories[1]['name2show'] = 'Such- und Downloaddienste';
 			$this->resourceCategories[2]['name2show'] = 'Kartenzusammenstellungen';
 			$this->resourceCategories[3]['name2show'] = 'Geokodierte Newsfeeds';
+			$this->keywordTitle = 'Schlagwortliste';
 		}	
 		//not needed til now - maybe usefull for georss output
 		if ($this->outputFormat == "xml") {
@@ -177,6 +190,9 @@
 		if ($this->outputFormat === "json") {
 			$this->e = new mb_exception("orderBy old: ".$this->orderBy);
 			if (isset($this->searchResources) & strtolower($this->searchResources) === "wfs") {
+				$this->databaseIdColumnName = 'featuretype_id';
+				$this->databaseTableName = 'wfs_featuretype';
+				//$this->keywordRelation = 'wfs_featuretype_keyword';
 				$this->searchView = 'search_wfs_view';
 				switch ($this->orderBy) {
 					case "rank":
@@ -188,6 +204,9 @@
 					case "title":
 						$this->orderBy = " ORDER BY featuretype_title ";
 						break;
+					case "date":
+						$this->orderBy = " ORDER BY wfs_timestamp DESC ";
+						break;
 					default:
 						$this->orderBy = " ORDER BY wfs_id,featuretype_id,wfs_conf_id ";
 				}
@@ -196,6 +215,9 @@
 				$this->generateWFSMetadata($this->wfsDoc);
 			}
 			if (isset($this->searchResources) & strtolower($this->searchResources) === "wms") {
+				$this->databaseIdColumnName = 'layer_id';
+				$this->databaseTableName = 'layer';
+				//$this->keywordRelation = 'layer_keyword';
 				$this->searchView = 'wms_search_table_test';
 				switch ($this->orderBy) {
 					case "rank":
@@ -207,6 +229,9 @@
 					case "title":
 						$this->orderBy = " ORDER BY layer_title ";
 						break;
+					case "date":
+						$this->orderBy = " ORDER BY wms_timestamp DESC ";
+						break;
 					default:
 						$this->orderBy = " ORDER BY load_count DESC";
 				}
@@ -216,6 +241,9 @@
 			}
 			if (isset($this->searchResources) & strtolower($this->searchResources) === "wmc") {
 				$this->searchView = 'search_wmc_view';
+				$this->databaseIdColumnName = 'wmc_id';
+				$this->databaseTableName = 'mb_user_wmc';
+
 				switch ($this->orderBy) {
 					case "rank":
 						$this->orderBy = " ORDER BY wmc_id ";
@@ -226,6 +254,9 @@
 					case "title":
 						$this->orderBy = " ORDER BY wmc_title ";
 						break;
+					case "date":
+						$this->orderBy = " ORDER BY wmc_timestamp DESC ";
+						break;
 					default:
 						$this->orderBy = " ORDER BY wmc_title ";
 				}
@@ -579,9 +610,9 @@
 					 $this->wmsJSON->wms->srv[$j]->nwaccess = true;
 				}
 
-				$this->wmsJSON->wms->srv[$j]->logged = NULL; //$wmsMatrix[$i][''];
-				$this->wmsJSON->wms->srv[$j]->price = NULL; //$wmsMatrix[$i][''];
-				$this->wmsJSON->wms->srv[$j]->nwaccess = NULL; //$wmsMatrix[$i][''];
+				#$this->wmsJSON->wms->srv[$j]->logged = NULL; //$wmsMatrix[$i][''];
+				#$this->wmsJSON->wms->srv[$j]->price = NULL; //$wmsMatrix[$i][''];
+				#$this->wmsJSON->wms->srv[$j]->nwaccess = NULL; //$wmsMatrix[$i][''];
 				$this->wmsJSON->wms->srv[$j]->bbox = $subLayers[$rootIndex]['bbox']; //$wmsMatrix[$i][''];
 				//Call recursively the child elements, give and pull $layerIdArray to push the done elements in the array to avoid double results
 				#print_r($subLayers);
@@ -785,7 +816,15 @@
 				array_push($t,"s");	
 			}
 		}
+
+
 /* This is only for the later postgis versions. The within and disjoint is to slow, cause there is no usage of the geometrical index in the old versions!
+//check for postgis version
+//sql for get version string
+//get version number
+decide which type of search should be done
+
+
 		//spatial search filter - ist should be the first filter in the where clause, cause it is 
 		//
 		if (strtolower($this->searchResources) === "wms" & $this->searchBbox != NULL) {
@@ -971,6 +1010,18 @@
 		return array($sql, $v, $t, $n);
 	}
 
+
+
+
+
+
+
+
+
+
+/** Function to write a json file which includes the categories of the search result for each searchResource - wms/wfs/wmc/georss, new: it should also count the keyword distribution of the searchResource ans save it as a special json file!
+
+**/
 	private function writeCategories($whereStr, $v, $t) {
 		//generate count sql
 		//generate count of all entries	
@@ -986,15 +1037,88 @@
 			//check if cat file already exists:
 			//filename to search for:
 			$filename = $this->tempFolder."/".$this->searchId."_".$this->searchResources."_cat.json";
-			if (!file_exists($filename) or $this->resultTarget == 'debug') { //TODO at the moment the cat file will be overwritten - change this in production system
-				//open category file for wfs results
+			$keyFilename = $this->tempFolder."/".$this->searchId."_".$this->searchResources."_keywords.json";
+			if (!file_exists($filename)  or $this->resultTarget == 'debug') { //TODO at the moment the cat file will be overwritten - change this in production system
+				//open category file for results
 				$this->catJSON = new stdClass;
 				$this->catJSON->searchMD = (object) array(
 					'searchId' => $this->searchId,
 					'n' => $n
 					);
+				//new: also generate a json object for the keyword distribution
+				$this->keyJSON = new stdClass;
+				$this->keyJSON->tagCloud = (object) array(
+					'searchId' => $this->searchId,
+					'maxFontSize' => $this->maxFontSize,
+					'maxObjects' => $this->maxObjects,
+					'title' => $this->keywordTitle,
+					'tags' => array()
+					);
+				$this->inc = $this->maxFontSize/$this->maxObjects;//maybe 10 or 5 or ...
 				//generate the list of category counts
 				$sqlCat = array();
+				//generate the sql for the keyword count
+				$sqlKeyword = "select keyword.keyword, COUNT(*) "; 
+				$sqlKeyword .= "FROM (select ";
+				$sqlKeyword .= $this->databaseIdColumnName;
+				$sqlKeyword .= " FROM ".$this->searchView." WHERE ".$whereStr.") as a";
+				$sqlKeyword .= " INNER JOIN ".$this->databaseTableName."_keyword ON (";
+				$sqlKeyword .= $this->databaseTableName."_keyword.fkey_".$this->databaseIdColumnName." = a.";
+				$sqlKeyword .= $this->databaseIdColumnName.") ";
+				$sqlKeyword .= "INNER JOIN keyword ON (keyword.keyword_id=".$this->databaseTableName."_keyword.fkey_keyword_id) WHERE (keyword.keyword NOTNULL AND keyword.keyword <> '')";
+				$sqlKeyword .= "GROUP BY keyword.keyword  ORDER BY COUNT DESC LIMIT  ".$this->maxObjects;
+				//do sql select for keyword cloud
+				$resKeyword = db_prep_query($sqlKeyword, $v, $t);
+				$keywordCounts = db_fetch_all($resKeyword);
+				
+				if (count($keywordCounts) > 0) {
+					$this->maxWeight = $keywordCounts[0]['count'];
+					for ($j = 0; $j < count($keywordCounts); $j++) {
+						$this->keyJSON->tagCloud->tags[$j]->title = $keywordCounts[$j]['keyword'];
+						//generate the weight:
+						if ($this->scale == 'linear'){
+							//order in a linear scale desc
+							 $this->keyJSON->tagCloud->tags[$j]->weight = $this->maxFontSize-($j*$this->inc);
+						} else {
+							//set weight prop to count 
+							 $this->keyJSON->tagCloud->tags[$j]->weight = $keywordCounts[$j]['count']*$this->maxFontSize/$this->maxWeight;
+						}
+						//$this->keyJSON->tags[$j]->weight = $keywordCounts[$j]['count'];
+
+						$paramValue = $this->getValueForParam('searchText', $this->searchURL);	
+						//delete resources part from query and set some new one
+						$searchUrlKeywords = $this->delTotalFromQuery('searchResources',$this->searchURL);
+						//append the resource parameter:
+						$searchUrlKeywords .= '&searchResources='.$this->searchResources;
+						$e = new mb_exception("class_metadata_new: value ".$paramValue." for searchText param found");
+						$paramValue = urldecode($paramValue);
+						if ($paramValue == false) {
+							$this->keyJSON->tagCloud->tags[$j]->url = $searchUrlKeywords."&searchText=".$keywordCounts[$j]['keyword'];
+						} else {
+							$this->keyJSON->tagCloud->tags[$j]->url = $this->addToQuery('searchText',$searchUrlKeywords,$keywordCounts[$j]['keyword'],$paramValue);
+						}
+					}
+				}
+				//encode json!
+				$this->keyJSON = $this->json->encode($this->keyJSON);
+				//write clouds to file
+				if($keyFileHandle = fopen($keyFilename, "w")){
+					fwrite($keyFileHandle,$this->keyJSON);
+					fclose($keyFileHandle);
+					$e = new mb_notice("class_metadata: new ".$this->searchResources."_keyword_file created!");
+				} else {
+					$e = new mb_notice("class_metadata: cannot create ".$this->searchResources."_keyword_file!");
+				}
+				if ($this->resultTarget == 'debug') {
+					echo "<br>DEBUG: show keywords: <br>".$this->keyJSON."<br><br>";
+				}
+
+/** "$resourceId." from ".$wms_view." where ".$whereClause.") as a";
+				$sqlKeyword .= "(select keyword, count(*) from keyword INNER JOIN  layer_keyword  ON (layer_keyword.fkey_keyword_id = keyword.keyword_id) GROUP BY keyword.keyword) ";
+				$sqlKeyword .= " GROUP BY keyword.keyword)) as a WHERE a.keyword <> '' GROUP BY a.keyword ORDER BY sum DESC LIMIT $1";
+**/
+
+
 				//check if categories are defined for the resource
 				if ($this->resourceClasses != NULL) {
 					$this->catJSON->searchMD->category = array();
@@ -1084,6 +1208,7 @@
 					} else {
 						$e = new mb_notice("class_metadata: cannot create ".$this->searchResources."_cat_file!");
 					}
+					
 				} 
 				if ($this->resultTarget == 'debug') {
 					echo "<br>DEBUG: show categories: <br>".$this->catJSON."<br><br>";
@@ -1286,7 +1411,12 @@
 		//'wfs test array' -> ('wfs' 'test' 'array')
 		$asstr = array();
 		if ($this->searchText != "false"){
-			$asstr = split(",",$this->searchText);	
+			$asstr = split(",",$this->searchText);
+			//delete left and right whitespaces
+			for ($i=0; $i<count($asstr);$i++) {
+				$asstr[$i]=ltrim($asstr[$i]);
+				$asstr[$i]=rtrim($asstr[$i]);
+			}	
 		}
 		return $asstr;
 	}			
@@ -1524,16 +1654,32 @@
 
 	
 	private function getValueForParam($paramName,$queryString) {
-		$queryString = "&".$queryString;
-		$pattern = '/\b'.$paramName.'\=[^&]+&?/';	
+		#another approach:
+		parse_str($queryString, $allQueries);
+		if (isset($allQueries[$paramName]) & $allQueries[$paramName] != '') {
+			return $allQueries[$paramName];
+		} else {
+			return false;
+		}
+
+
+#		old version
+
+/*		#TODO: check if last and first ampersand was set before
+		$queryString = "&".$queryString."&";
+		#$pattern = '/\b'.$paramName.'=([a-z0-9-]+)\&?/';
+		$pattern = '/\b&'.$paramName.'\=[^&]+&?/';
+		#$pattern = '/^&'.$paramName.'=[a-zA-ZöäüÖÄÜß,]*&$/';
+		$e = new mb_exception("class_metadata_new.php: look for pattern: ".$pattern."  in ".$queryString);
  		if (!preg_match($pattern, $queryString, $matches)){
+			
 			return false;
 		} else {
 			//some param found
 			//delete $paramName= and the last ampersand!
 			if (count($matches) == 1) {
 				$requestString = $matches[0];
-				$requestString = ltrim($requestString,$paramName."=");
+				$requestString = ltrim($requestString,"&".$paramName."=");
 				$requestString = rtrim($requestString,'&');
 
 				return $requestString;
@@ -1542,7 +1688,7 @@
 				#echo "Parameter Ambiguities found!";
 				die();
 			}
-		}
+		}*/
 	}	
 
 	private function addToQuery($paramName,$queryString,$string,$queryList) {

Modified: trunk/mapbender/http/php/mod_callMetadata.php
===================================================================
--- trunk/mapbender/http/php/mod_callMetadata.php	2010-06-02 15:20:17 UTC (rev 6243)
+++ trunk/mapbender/http/php/mod_callMetadata.php	2010-06-08 11:56:17 UTC (rev 6244)
@@ -46,7 +46,7 @@
 $classJSON = new Mapbender_JSON;
 #$tempFolder = "/tmp";
 $tempFolder = TMPDIR;
-$orderBy = "rank"; //rank or title or id
+$orderBy = "rank"; //rank or title or id or date
 $hostName = $_SERVER['HTTP_HOST'];
 
 //read the whole query string:
@@ -77,7 +77,7 @@
 }
 if (isset($_REQUEST["searchText"]) & $_REQUEST["searchText"] != "") {
 	$test="(SELECT\s[\w\*\)\(\,\s]+\sFROM\s[\w]+)| (UPDATE\s[\w]+\sSET\s[\w\,\'\=]+)| (INSERT\sINTO\s[\d\w]+[\s\w\d\)\(\,]*\sVALUES\s\([\d\w\'\,\)]+)| (DELETE\sFROM\s[\d\w\'\=]+)";
-	//validate to csv integer list
+	//validate to csv integer list
 	$testMatch = $_REQUEST["searchText"];
 	$pattern = '/(\%27)|(\')|(\-\-)|(\")|(\%22)/';		
  	if (preg_match($pattern,$testMatch)){ 
@@ -88,7 +88,7 @@
 	$testMatch = NULL;
 }
 if (isset($_REQUEST["registratingDepartments"]) & $_REQUEST["registratingDepartments"] != "") {
-	//validate to csv integer list
+	//validate to csv integer list
 	$testMatch = $_REQUEST["registratingDepartments"];
 	$pattern = '/^[\d,]*$/';		
  	if (!preg_match($pattern,$testMatch)){ 
@@ -99,7 +99,7 @@
 	$testMatch = NULL;
 }
 if (isset($_REQUEST["isoCategories"]) & $_REQUEST["isoCategories"] != "") {
-	//validate to csv integer list
+	//validate to csv integer list
 	$testMatch = $_REQUEST["isoCategories"];
 	$pattern = '/^[\d,]*$/';		
  	if (!preg_match($pattern,$testMatch)){ 
@@ -110,7 +110,7 @@
 	$testMatch = NULL;
 }
 if (isset($_REQUEST["inspireThemes"]) & $_REQUEST["inspireThemes"] != "") {
-	//validate to csv integer list
+	//validate to csv integer list
 	$testMatch = $_REQUEST["inspireThemes"];
 	$pattern = '/^[\d,]*$/';		
  	if (!preg_match($pattern,$testMatch)){ 
@@ -122,7 +122,7 @@
 }
 
 if (isset($_REQUEST["customCategories"]) & $_REQUEST["customCategories"] != "") {
-	//validate to csv integer list
+	//validate to csv integer list
 	$testMatch = $_REQUEST["customCategories"];
 	$pattern = '/^[\d,]*$/';		
  	if (!preg_match($pattern,$testMatch)){ 
@@ -189,7 +189,7 @@
 	$testMatch = NULL;
 }
 if (isset($_REQUEST["searchBbox"]) & $_REQUEST["searchBbox"] != "") {
-	//validate to float/integer
+	//validate to float/integer
 	$testMatch = $_REQUEST["searchBbox"];
 	//$pattern = '/^[-\d,]*$/';	
 	$pattern = '/^[-+]?([0-9]*\.[0-9]+|[0-9]+)*$/';
@@ -222,7 +222,7 @@
 	#TODO implement me //$accessRestrictions = $_REQUEST["accessRestrictions"];
 }
 if (isset($_REQUEST["languageCode"]) & $_REQUEST["languageCode"] != "") {
-	//validate to de, en, fr
+	//validate to de, en, fr
 	$testMatch = $_REQUEST["languageCode"];	
  	if (!($testMatch == 'de' or $testMatch == 'en' or $testMatch == 'fr')){ 
 		echo 'languageCode: <b>'.$testMatch.'</b> is not valid.<br/>'; 
@@ -251,7 +251,7 @@
 }
 if (isset($_REQUEST["orderBy"]) & $_REQUEST["orderBy"] != "") {
 	$testMatch = $_REQUEST["orderBy"];	
- 	if (!($testMatch == 'rank' or $testMatch == 'title' or $testMatch == 'id')){ 
+ 	if (!($testMatch == 'rank' or $testMatch == 'title' or $testMatch == 'id' or $testMatch == 'date')){ 
 		echo 'orderBy: <b>'.$testMatch.'</b> is not valid.<br/>'; 
 		die(); 		
  	}
@@ -282,7 +282,7 @@
 	$testMatch = NULL;
 }
 if (isset($_REQUEST["searchPages"]) & $_REQUEST["searchPages"] != "") {
-	//validate to csv integer list with dimension of searchResources list
+	//validate to csv integer list with dimension of searchResources list
 	$testMatch = $_REQUEST["searchPages"];
 	$pattern = '/^[-\d,]*$/';		
  	if (!preg_match($pattern,$testMatch)){ 
@@ -565,6 +565,7 @@
 		$orderByTitle['id'] = 'ID';
 		$orderByTitle['title'] = 'Titel';
 		$orderByTitle['rank'] = 'Relevanz';
+		$orderByTitle['date'] = 'Letzte Änderung';
 
 	
        	break;
@@ -587,6 +588,7 @@
 		$orderByTitle['id'] = 'ID';
 		$orderByTitle['title'] = 'title';
 		$orderByTitle['rank'] = 'relevance';
+		$orderByTitle['date'] = 'last change';
 
         break;
         case 'fr':
@@ -608,6 +610,7 @@
 		$orderByTitle['id'] = 'identification';
 		$orderByTitle['title'] = 'title';
 		$orderByTitle['rank'] = 'relevance';
+		$orderByTitle['date'] = 'last change';
 
        	break;
      	default:
@@ -629,6 +632,7 @@
 		$orderByTitle['id'] = 'ID';
 		$orderByTitle['title'] = 'Titel';
 		$orderByTitle['rank'] = 'Relevanz';
+		$orderByTitle['date'] = 'Letzte Änderung';
 
 }	
 
@@ -654,6 +658,15 @@
 		//check if the filter has subfilters - if not delete the whole filter from query
 		if ($classificationElements[$i]['list'] == false) { //the object has no subsets - like bbox or time filters
 			$queryJSON->searchFilter->{$classificationElements[$i]['name']}->delLink = delTotalFromQuery($classificationElements[$i]['name'],$searchURL);
+			$queryJSON->searchFilter->{$classificationElements[$i]['name']}->item = array();
+			if ($classificationElements[$i]['name'] == 'searchBbox') {
+				$sBboxTitle = $searchTypeBbox." ".${$classificationElements[$i]['name']};
+				$queryJSON->searchFilter->{$classificationElements[$i]['name']}->item[0]->title = $sBboxTitle;
+			}
+			else {
+			$queryJSON->searchFilter->{$classificationElements[$i]['name']}->item[0]->title = ${$classificationElements[$i]['name']};
+			}
+			$queryJSON->searchFilter->{$classificationElements[$i]['name']}->item[0]->delLink = delTotalFromQuery($classificationElements[$i]['name'],$searchURL);
 		} else {
 
 
@@ -707,7 +720,10 @@
 	$queryJSON->searchFilter->orderFilter->item[0]->url = $searchURL."&orderBy=title";
 	$queryJSON->searchFilter->orderFilter->item[1]->title = $orderByTitle['id'];
 	$queryJSON->searchFilter->orderFilter->item[1]->url = $searchURL."&orderBy=id";
+	$queryJSON->searchFilter->orderFilter->item[2]->title = $orderByTitle['date'];
+	$queryJSON->searchFilter->orderFilter->item[2]->url = $searchURL."&orderBy=date";
 
+
 } else {
 //read out actual order filter
 switch ($orderBy) {
@@ -719,6 +735,11 @@
 						$queryJSON->searchFilter->orderFilter->item[1]->title = $orderByTitle['title'];
 
 						$queryJSON->searchFilter->orderFilter->item[1]->url = str_replace("orderBy=rank", "orderBy=title", $searchURL);
+$queryJSON->searchFilter->orderFilter->item[2]->title = $orderByTitle['date'];
+
+						$queryJSON->searchFilter->orderFilter->item[2]->url = str_replace("orderBy=rank", "orderBy=date", $searchURL);
+
+
 						break;
 					case "id":
 						$queryJSON->searchFilter->orderFilter->title = $orderByTitle['id'];
@@ -728,6 +749,11 @@
 						$queryJSON->searchFilter->orderFilter->item[1]->title = $orderByTitle['title'];
 
 						$queryJSON->searchFilter->orderFilter->item[1]->url = str_replace("orderBy=id", "orderBy=title", $searchURL);
+						$queryJSON->searchFilter->orderFilter->item[2]->title = $orderByTitle['date'];
+
+						$queryJSON->searchFilter->orderFilter->item[2]->url = str_replace("orderBy=id", "orderBy=date", $searchURL);
+
+
 						break;
 					case "title":
 						$queryJSON->searchFilter->orderFilter->title = $orderByTitle['title'];
@@ -737,7 +763,22 @@
 						$queryJSON->searchFilter->orderFilter->item[1]->title = $orderByTitle['id'];
 
 						$queryJSON->searchFilter->orderFilter->item[1]->url = str_replace("orderBy=title", "orderBy=id", $searchURL);
+						$queryJSON->searchFilter->orderFilter->item[2]->title = $orderByTitle['date'];
+
+						$queryJSON->searchFilter->orderFilter->item[2]->url = str_replace("orderBy=title", "orderBy=date", $searchURL);
 						break;
+					case "date":
+						$queryJSON->searchFilter->orderFilter->title = $orderByTitle['date'];
+						$queryJSON->searchFilter->orderFilter->item[0]->title = $orderByTitle['rank'];
+
+						$queryJSON->searchFilter->orderFilter->item[0]->url = str_replace("orderBy=date", "orderBy=rank", $searchURL);
+						$queryJSON->searchFilter->orderFilter->item[1]->title = $orderByTitle['id'];
+
+						$queryJSON->searchFilter->orderFilter->item[1]->url = str_replace("orderBy=date", "orderBy=id", $searchURL);
+						$queryJSON->searchFilter->orderFilter->item[2]->title = $orderByTitle['title'];
+
+						$queryJSON->searchFilter->orderFilter->item[2]->url = str_replace("orderBy=date", "orderBy=title", $searchURL);
+						break;
 					
 }
 }
@@ -823,11 +864,11 @@
 if ($resultTarget == 'file') {
 	for($i=0; $i<count($searchResources);$i++){
 		$str = "nohup php5 /data/mapbender/http/php/mod_metadataWrite.php ";
-		$str .= "'".$userId."' ";		
-		$str .= "'".$searchId."' ";		
-		$str .= "'".$searchText."' "; 		
-		$str .= "'".$registratingDepartments."' ";						
-		$str .= "'".$isoCategories."' ";							
+		$str .= "'".$userId."' ";		
+		$str .= "'".$searchId."' ";		
+		$str .= "'".$searchText."' "; 		
+		$str .= "'".$registratingDepartments."' ";						
+		$str .= "'".$isoCategories."' ";							
 		$str .= "'".$inspireThemes."' ";
 		$str .= "'".$timeBegin."' ";
 		$str .= "'".$timeEnd."' ";
@@ -890,4 +931,4 @@
 //searchid_georss_cat.json - doesn't exists till now
 //searchid_filter.json
 
-?>
+?>
\ No newline at end of file

Added: trunk/mapbender/http/php/mod_getServiceDisclaimer.php
===================================================================
--- trunk/mapbender/http/php/mod_getServiceDisclaimer.php	                        (rev 0)
+++ trunk/mapbender/http/php/mod_getServiceDisclaimer.php	2010-06-08 11:56:17 UTC (rev 6244)
@@ -0,0 +1,231 @@
+<?php
+//http://www.geoportal.rlp.de/mapbender/php/mod_getServiceDisclaimer.php?type=wms&id=1501
+//include relevant scripts
+//
+require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+require_once(dirname(__FILE__)."/../classes/class_administration.php"); //TODO: include some class which can do the db connects
+
+//function to parse urls as links
+function display_text($string) {
+    $string = eregi_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"\\0\" target=_blank>\\0</a>", $string);   
+    $string = eregi_replace("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@([0-9a-z](-?[0-9a-z])*\.)+[a-z]{2}([zmuvtg]|fo|me)?$", "<a href=\"mailto:\\0\" target=_blank>\\0</a>", $string);   
+    $string = eregi_replace("\n", "<br>", $string);
+    return $string;
+}  
+
+//initialize request parameters:
+$type = "wms";
+$id = 1;
+$languageCode = "de";
+//parse request parameters
+//
+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;	
+}
+//
+if (isset($_REQUEST["type"]) & $_REQUEST["type"] != "") {
+	//validate to wms, wfs
+	$testMatch = $_REQUEST["type"];	
+ 	if (!($testMatch == 'wms' or $testMatch == 'wfs')){ 
+		echo 'type: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	$type = $testMatch;
+	$testMatch = NULL;
+}
+//
+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;
+}
+$htmlHeader = array();
+
+switch($languageCode){
+        		case 'de':
+                	$htmlHeader['discHeader'] = 'Nutzungsbedingungen des angefragten Service';
+			$htmlHeader['discPrivacyHeader'] = 'Datenschutzhinweis';
+			$htmlHeader['accessConstraintsHeader'] = 'Beschränkungen des öffentlichen Zugangs';
+			$htmlHeader['feesHeader'] = 'Angaben zu Kosten/Gebühren/Lizenzen';
+			$htmlHeader['licences'] = '<b>"."Lizenz:"."</b><br>';
+			$htmlHeader['networkAccess'] = 'Der Dienst ist <b>nicht im Internet</b> sondern nur in ausgewählten  Netzwerken (z.B. Intranets) verfügbar. Genauere Angaben erhalten Sie ggf. im folgenden Abschnitt.<br>';
+			$htmlHeader['logInformation'] = 'Die Zugriffe auf den Dienst werden vom Anbieter <b>nutzerbezogen</b> aufgezeichnet. Dies erfolgt entweder zur Abrechnung vertraglicher Vereinbarungen ';
+			$htmlHeader['logInformation'] .= 'oder aufgrund gesetzlicher Vorgaben.<br><b>Wenn Sie hiermit nicht einverstanden sein sollten, nutzen Sie diesen Dienst nicht!</b><br>';
+			$htmlHeader['logInformation'] .= 'Falls Sie weitere Fragen haben, kontaktieren Sie bitte den Anbieter unter ';
+			$htmlHeader['priceInformation'][0] = 'Der Anbieter dieses Dienstes hat ein allgemeines Nutzungsentgelt von <b>';
+			$htmlHeader['priceInformation'][1] = ' Cent pro Megapixel</b> ';
+			$htmlHeader['priceInformation'][2] = ' für abgerufene Bildinformationen angegeben. Das Abrufen eines Kartenbildes in einer Standardauflösung von 600x400 Pixeln kostet dementsprechend <b>';
+			$htmlHeader['priceInformation'][3] = ' Euro</b>. Angaben zu eventuell möglichen Rabatten erhalten Sie über ';
+
+
+       			break;
+        		case 'en':
+			$htmlHeader['discHeader'] = 'Terms of use';
+			$htmlHeader['discPrivacyHeader'] = 'Note on protection of privacy';
+			$htmlHeader['accessConstraintsHeader'] = 'Constraints on public access';
+			$htmlHeader['feesHeader'] = 'Information about costs/fees/licences';
+			$htmlHeader['licences'] = '<b>"."Licence:"."</b><br>';
+			$htmlHeader['networkAccess'] = 'This Service is <b>not available via www</b> but only in special networks. Possibly you get further information about the network availability in the following paragraph.<br>';
+			$htmlHeader['logInformation'] = 'The access on this service is logged <b>user-related</b> by the provider. The logging is done to support automated settlement based on a contract ';
+			$htmlHeader['logInformation'] .= 'or to fulfill legal standards.<br><b>If you do not agree on this - please don\'t use this service!</b><br>';
+			$htmlHeader['logInformation'] .= 'If you have further questions, please contact the provider under ';
+			$htmlHeader['priceInformation'][0] = 'The provider have defined a charge of <b>';
+			$htmlHeader['priceInformation'][1] = ' (euro)cent per megapixel</b> ';
+			$htmlHeader['priceInformation'][2] = ' for retrieved picture data. The retrieving of a typical map with a standardized resolution of 600x400 px will cost <b>';
+			$htmlHeader['priceInformation'][3] = ' euro</b>. For information about possible discounts please contact ';
+
+           
+        		break;
+        		case 'fr':
+			$htmlHeader['discHeader'] = 'Nutzungsbedingungen des angefragten Service';
+			$htmlHeader['discPrivacyHeader'] = 'Datenschutzhinweis';
+			$htmlHeader['accessConstraintsHeader'] = 'Beschränkungen des öffentlichen Zugangs';
+			$htmlHeader['feesHeader'] = 'Angaben zu Kosten/Gebühren/Lizenzen';
+			$htmlHeader['licences'] = '<b>"."Lizenz:"."</b><br>';
+			$htmlHeader['networkAccess'] = 'Der Dienst ist <b>nicht im Internet</b> sondern nur in ausgewählten  Netzwerken (z.B. Intranets) verfügbar. Genauere Angaben erhalten Sie ggf. im folgenden Abschnitt.<br>';
+			$htmlHeader['logInformation'] = 'Die Zugriffe auf den Dienst werden vom Anbieter <b>nutzerbezogen</b> aufgezeichnet. Dies erfolgt entweder zur Abrechnung vertraglicher Vereinbarungen ';
+			$htmlHeader['logInformation'] .= 'oder aufgrund gesetzlicher Vorgaben.<br><b>Wenn Sie hiermit nicht einverstanden sein sollten, nutzen Sie diesen Dienst nicht!</b><br>';
+			$htmlHeader['logInformation'] .= 'Falls Sie weitere Fragen haben, kontaktieren Sie bitte den Anbieter unter ';
+			$htmlHeader['priceInformation'][0] = 'Der Anbieter dieses Dienstes hat ein allgemeines Nutzungsentgelt von <b>';
+			$htmlHeader['priceInformation'][1] = ' Cent pro Megapixel</b> ';
+			$htmlHeader['priceInformation'][2] = ' für abgerufene Bildinformationen angegeben. Das Abrufen eines Kartenbildes in einer Standardauflösung von 600x400 Pixeln kostet dementsprechend <b>';
+			$htmlHeader['priceInformation'][3] = ' Euro</b>. Angaben zu eventuell möglichen Rabatten erhalten Sie über ';
+
+       			break;
+     			default:
+			$htmlHeader['discHeader'] = 'Nutzungsbedingungen des angefragten Service';
+			$htmlHeader['discPrivacyHeader'] = 'Datenschutzhinweis';
+			$htmlHeader['accessConstraintsHeader'] = 'Beschränkungen des öffentlichen Zugangs';
+			$htmlHeader['feesHeader'] = 'Angaben zu Kosten/Gebühren/Lizenzen';
+			$htmlHeader['licences'] = '<b>"."Lizenz:"."</b><br>';
+			$htmlHeader['networkAccess'] = 'Der Dienst ist <b>nicht im Internet</b> sondern nur in ausgewählten  Netzwerken (z.B. Intranets) verfügbar. Genauere Angaben erhalten Sie ggf. im folgenden Abschnitt.<br>';
+			$htmlHeader['logInformation'] = 'Die Zugriffe auf den Dienst werden vom Anbieter <b>nutzerbezogen</b> aufgezeichnet. Dies erfolgt entweder zur Abrechnung vertraglicher Vereinbarungen ';
+			$htmlHeader['logInformation'] .= 'oder aufgrund gesetzlicher Vorgaben.<br><b>Wenn Sie hiermit nicht einverstanden sein sollten, nutzen Sie diesen Dienst nicht!</b><br>';
+			$htmlHeader['logInformation'] .= 'Falls Sie weitere Fragen haben, kontaktieren Sie bitte den Anbieter unter ';
+			$htmlHeader['priceInformation'][0] = 'Der Anbieter dieses Dienstes hat ein allgemeines Nutzungsentgelt von <b>';
+			$htmlHeader['priceInformation'][1] = ' Cent pro Megapixel</b> ';
+			$htmlHeader['priceInformation'][2] = ' für abgerufene Bildinformationen angegeben. Das Abrufen eines Kartenbildes in einer Standardauflösung von 600x400 Pixeln kostet dementsprechend <b>';
+			$htmlHeader['priceInformation'][3] = ' Euro</b>. Angaben zu eventuell möglichen Rabatten erhalten Sie über ';
+		}	
+
+//parameters:	type	:wms, wfs, ... string
+//		id	:1234, 234, ... integer
+//
+//
+//read information from database
+//
+//
+if ($type == "wms") {
+	$sql = "SELECT wms_id, wms.accessconstraints, wms.fees, wms.wms_network_access , wms.wms_pricevolume, wms.wms_proxylog, termsofuse.name,";
+	$sql .= " termsofuse.termsofuse_id, termsofuse.symbollink, termsofuse.description,termsofuse.descriptionlink from wms LEFT OUTER JOIN";
+	$sql .= "  wms_termsofuse ON  (wms.wms_id = wms_termsofuse.fkey_wms_id) LEFT OUTER JOIN termsofuse ON";
+	$sql .= " (wms_termsofuse.fkey_termsofuse_id=termsofuse.termsofuse_id) where wms.wms_id = $1";
+}
+if ($type == "wfs") {
+	$sql = "SELECT wms_id, accessconstraints, fees, wfs_network_access , termsofuse.name,";
+	$sql .= " termsofuse.termsofuse_id ,termsofuse.symbollink, termsofuse.description,termsofuse.descriptionlink from wfs LEFT OUTER JOIN";
+	$sql .= "  wfs_termsofuse ON  (wfs.wfs_id = wfs_termsofuse.fkey_wfs_id) LEFT OUTER JOIN termsofuse ON";
+	$sql .= " (wfs_termsofuse.fkey_termsofuse_id=termsofuse.termsofuse_id) where wfs.wfs_id = $1";	
+}
+$v = array();
+$t = array();
+array_push($t, "i");
+array_push($v, $id);
+$res = db_prep_query($sql,$v,$t);
+$row = db_fetch_array($res);
+if (!isset($row['wms_id'])) {
+echo $type."-service with this id is not known!";
+	die();
+}
+//get email adress of responsible person for service:
+if ($type == "wms") {
+	$sql = "SELECT mb_user_email FROM wms LEFT OUTER JOIN mb_user ON  (wms_owner = mb_user.mb_user_id) WHERE wms_id=$1";
+}
+if ($type == "wfs") {
+	$sql = "SELECT mb_user_email FROM wfs LEFT OUTER JOIN mb_user ON  (wfs_owner = mb_user.mb_user_id) WHERE wfs_id=$1";
+}
+$v = array();
+$t = array();
+
+array_push($t, "i");
+array_push($v, $id);
+
+$res = db_prep_query($sql,$v,$t);
+
+$rowOwner = db_fetch_array($res);
+
+
+
+
+if ((isset($row[$type.'_proxylog']) & $row[$type.'_proxylog'] != 0) or strtoupper($row['accessconstraints']) != "NONE" or strtoupper($row['fees']) != "NONE" or isset($row['termsofuse_id']) or (isset($row[$type.'_network_access']) & $row[$type.'_network_access'] != 0)) {
+
+//generate text for json object if restrictions exists
+
+echo "<h1>".$htmlHeader['discHeader']."</h1>";
+
+if (isset($row[$type.'_proxylog']) & $row[$type.'_proxylog'] != 0 )  {
+	$discPrivacy = $htmlHeader['logInformation'];
+	$discPrivacy .= "<a href=\"mailto:".$rowOwner['mb_user_email']."\">".$rowOwner['mb_user_email']."</a>";
+	echo "<h2>".$htmlHeader['discPrivacyHeader']."</h2>";
+	echo $discPrivacy."<br>";
+}
+
+
+if (strtoupper($row['accessconstraints']) != "NONE" or (isset($row[$type.'_network_access']) & $row[$type.'_network_access'] != 0) ) {
+	$accessConstraintsHeader = "Beschränkungen des öffentlichen Zugangs";
+	if (isset($row[$type.'_network_access']) & $row[$type.'_network_access'] != 0) {
+		$accessConstraints = $htmlHeader['networkAccess'];
+	}
+	else {
+		$accessConstraints = "";
+	}
+	$accessConstraints .= display_text($row['accessconstraints']);
+	echo "<h2>".$htmlHeader['accessConstraintsHeader']."</h2>";
+	echo $accessConstraints."<br>";
+}
+if (isset($row['termsofuse_id']) or strtoupper($row['fees']) != "NONE" or ($type == "wms" & isset($row['wms_pricevolume']) & $row['wms_pricevolume'] != 0) ) {
+
+echo "<h2>".$htmlHeader['feesHeader']."</h2>";
+if (isset($row['termsofuse_id'])) {
+
+	$fees = $htmlHeader['licences'];
+
+	#$fees .= $row['name']."<br>";
+	$fees .= "<a href='".$row['descriptionlink']."' target=_blank><img src='".$row['symbollink']."' ".$row['name']."></a><br>";
+	$fees .= $row['description']."<br>";
+	echo $fees."<br>";
+} else {
+	$fees = display_text($row['fees'])."<br>";
+	echo $fees."<br>";
+}
+if ($type == "wms" & isset($row['wms_pricevolume']) & $row['wms_pricevolume'] != 0) {
+	$priceExample = (integer)$row['wms_pricevolume']*400*600/100000000;
+
+	$priceInformation = $htmlHeader['priceInformation'][0].(integer)$row['wms_pricevolume'];
+
+	$priceInformation .= $htmlHeader['priceInformation'][1].$htmlHeader['priceInformation'][2].$priceExample.$htmlHeader['priceInformation'][3]." <a href=\"mailto:".$rowOwner['mb_user_email']."\">".$rowOwner['mb_user_email']."</a><br>";
+
+	echo $priceInformation."<br>";
+
+	}
+}
+} else {
+//if nothing about restrictions is defined
+echo "No information for disclaimer available!";
+}
+
+?>
\ No newline at end of file

Added: trunk/mapbender/http/php/tagCloud.php
===================================================================
--- trunk/mapbender/http/php/tagCloud.php	                        (rev 0)
+++ trunk/mapbender/http/php/tagCloud.php	2010-06-08 11:56:17 UTC (rev 6244)
@@ -0,0 +1,226 @@
+<?php
+session_start();
+include(dirname(__FILE__)."/../../conf/mapbender.conf");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+#include(dirname(__FILE__)."/../php/mb_validateSession.php");
+$con = db_connect(DBSERVER,OWNER,PW);
+db_select_db(DB,$con);
+$pathToSearchScript = '/portal/servicebereich/suche.html?cat=dienste&searchfilter=';
+$languageCode = 'de';
+$maxFontSize = 40;
+$maxObjects = 10;
+$outputFormat = 'html';
+
+//read out information from database:
+
+if (isset($_REQUEST["type"]) & $_REQUEST["type"] != "") {
+	$testMatch = $_REQUEST["type"];	
+ 	if (!($testMatch == 'keywords' or $testMatch == 'topicCategories')){ 
+		echo 'type: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	$type = $testMatch;
+	$testMatch = NULL;
+}
+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["scale"]) & $_REQUEST["scale"] != "") {
+	$testMatch = $_REQUEST["scale"];	
+ 	if (!($testMatch == 'linear')){ 
+		echo 'scale: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	$scale = $testMatch;
+	$testMatch = NULL;
+}
+if (isset($_REQUEST["maxObjects"]) & $_REQUEST["maxObjects"] != "") {
+	$testMatch = $_REQUEST["maxObjects"];	
+ 	if (!(($testMatch == '10') or ($testMatch == '15') or ($testMatch == 20) or ($testMatch == '25') or ($testMatch == '30'))){ 
+		echo 'maxObjects: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	$maxObjects = (integer)$testMatch;
+	$testMatch = NULL;
+}
+if (isset($_REQUEST["maxFontSize"]) & $_REQUEST["maxFontSize"] != "") {
+	$testMatch = $_REQUEST["maxFontSize"];	
+ 	if (!(($testMatch == '10') or ($testMatch == '20') or ($testMatch == '30') or ($testMatch == '40'))){ 
+		echo 'maxFontSize: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	$maxFontSize = (integer)$testMatch;
+	$testMatch = NULL;
+}
+//
+if (isset($_REQUEST["languageCode"]) & $_REQUEST["languageCode"] != "") {
+	//validate to wms, wfs
+	$testMatch = $_REQUEST["languageCode"];	
+ 	if (!($testMatch == 'de' or $testMatch == 'en' or  $testMatch == 'fr')){ 
+		echo 'languageCode: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	$languageCode = $testMatch;
+	$testMatch = NULL;
+}
+
+
+
+
+
+if ($outputFormat == 'json'){
+	$classJSON = new Mapbender_JSON;
+}
+
+if ($languageCode == 'en'){
+	$pathToSearchScript = '/portal/en/service/search.html?cat=dienste&searchfilter=';
+}
+
+
+
+if ($type == 'keywords'){
+	$sql = "select a.keyword, sum(a.count) from ("; 
+	$sql .= "(select keyword, count(*) from keyword INNER JOIN  layer_keyword  ON (layer_keyword.fkey_keyword_id = keyword.keyword_id) GROUP BY keyword.keyword) union ";
+	$sql .= "(select keyword, count(*) from keyword INNER JOIN  wmc_keyword  ON (wmc_keyword.fkey_keyword_id = keyword.keyword_id) GROUP BY keyword.keyword) union ";
+	$sql .= "(select keyword, count(*) from keyword INNER JOIN  wfs_featuretype_keyword  ON (wfs_featuretype_keyword.fkey_keyword_id = keyword.keyword_id)";
+	$sql .= " GROUP BY keyword.keyword)) as a WHERE a.keyword <> '' GROUP BY a.keyword ORDER BY sum DESC LIMIT $1";
+	$showName = 'keyword';
+}
+
+if ($type == 'topicCategories') {
+	$sql = "select a.md_topic_category_code_".$languageCode.", a.md_topic_category_id,sum(a.count) from ("; 
+	$sql .= "(select md_topic_category_code_".$languageCode.",md_topic_category_id, count(*) from md_topic_category INNER JOIN  layer_md_topic_category  ON (layer_md_topic_category.fkey_md_topic_category_id = md_topic_category.md_topic_category_id) GROUP BY md_topic_category.md_topic_category_code_".$languageCode.",md_topic_category.md_topic_category_id) union ";
+	$sql .= "(select md_topic_category_code_".$languageCode.",md_topic_category_id, count(*) from  md_topic_category INNER JOIN  wfs_featuretype_md_topic_category  ON (wfs_featuretype_md_topic_category.fkey_md_topic_category_id = md_topic_category.md_topic_category_id) GROUP BY md_topic_category.md_topic_category_code_".$languageCode.",md_topic_category.md_topic_category_id) union ";
+	$sql .= "(select md_topic_category_code_".$languageCode.",md_topic_category_id, count(*) from md_topic_category INNER JOIN  wmc_md_topic_category  ON (wmc_md_topic_category.fkey_md_topic_category_id = md_topic_category.md_topic_category_id)";
+	$sql .= " GROUP BY md_topic_category.md_topic_category_code_".$languageCode.",md_topic_category.md_topic_category_id)) as a WHERE a.md_topic_category_code_".$languageCode." <> '' GROUP BY a.md_topic_category_code_".$languageCode.", a.md_topic_category_id ORDER BY sum DESC LIMIT $1";
+	$showName = 'md_topic_category_code_'.$languageCode;
+}
+#sql
+#select a.md_topic_category_code_de,a.md_topic_category_id, sum(a.count) from ((select md_topic_category_code_de,md_topic_category_id, count(*) from md_topic_category INNER JOIN  layer_md_topic_category  ON (layer_md_topic_category.fkey_md_topic_category_id = md_topic_category.md_topic_category_id) GROUP BY md_topic_category.md_topic_category_code_de,md_topic_category.md_topic_category_id) union (select md_topic_category_code_de,md_topic_category_id, count(*) from  md_topic_category INNER JOIN  wfs_featuretype_md_topic_category  ON (wfs_featuretype_md_topic_category.fkey_md_topic_category_id = md_topic_category.md_topic_category_id) GROUP BY md_topic_category.md_topic_category_code_de,md_topic_category.md_topic_category_id) union (select md_topic_category_code_de,md_topic_category_id, count(*) from md_topic_category INNER JOIN  wmc_md_topic_category  ON (wmc_md_topic_category.fkey_md_topic_category_id = md_topic_category.md_topic_category_id) GROUP BY md_topic_category.md_topic_category_code_de,md_topic_category.md_topic_category_id)) as a WHERE a.md_topic_category_code_de <> '' GROUP BY a.md_topic_category_code_de, a.md_topic_category_id ORDER BY sum DESC LIMIT 20
+
+
+$v = array($maxObjects);
+$t = array('i');
+$res = db_prep_query($sql,$v,$t);
+$tags = array();
+$i = 0;
+//max pixelsize
+
+$inc = $maxFontSize/$maxObjects;//maybe 10 or 5 or ...
+$maxWeight = 0;
+
+while($row = db_fetch_array($res)){
+	if ((integer)$row['sum'] >= $maxWeight ) {
+		$maxWeight = (integer)$row['sum'];
+	} 
+	if ($type == 'topicCategories') {
+		$tags[$i] = array('weight'  =>$row['sum'], 'tagname' =>$row[$showName], 'url'=>'http://'.$_SERVER['HTTP_HOST'].$pathToSearchScript.urlencode('searchText=e&resultTarget=file&outputFormat=json&isoCategories='.$row['md_topic_category_id'].'&languageCode='.$languageCode));
+	}
+	if ($type == 'keywords') {
+		$tags[$i] = array('weight'  =>$row['sum'], 'tagname' =>$row[$showName], 'url'=>'http://'.$_SERVER['HTTP_HOST'].$pathToSearchScript.urlencode('searchText='.$row[$showName].'&resultTarget=file&outputFormat=json&languageCode='.$languageCode));
+	}
+
+	$i++;
+}
+//normalize the tag cloud with some max value for pixelsize or set them to linear scale!
+
+for($i=0; $i<count($tags); $i++){
+	if ($scale == 'linear'){
+		$tags[$i]['weight'] = $maxFontSize-($i*$inc);
+	} else {
+		$tags[$i]['weight'] = $tags[$i]['weight']*$maxFontSize/$maxWeight;
+	}
+}
+
+if ($outputFormat == 'html'){
+	echo "<html>";
+	echo "<title>Mapbender Tag Cloud</title>";
+	echo "<style type=\"text/css\">";
+	echo "#tagcloud{";
+		echo "color: #dda0dd;";
+		echo "font-family: Arial, verdana, sans-serif;";
+		echo "width:650px;";
+		echo "border: 1px solid black;";
+		echo "text-align: center;";
+	echo "}";
+
+	echo "#tagcloud a{";
+	echo "      color: #871e32;";
+	echo "      text-decoration: none;";
+	echo "      text-transform: capitalize;";
+	echo "}";
+	echo "</style>";
+	echo "<body>";
+	echo "</body>";
+	echo "</html>";
+	echo "<div id=\"tagcloud\">";
+	/*** create a new tag cloud object ***/
+	$tagCloud = new tagCloud($tags);
+	echo $tagCloud -> displayTagCloud();
+	echo "</div>";
+	echo "</body>";
+	echo "</html>";
+}
+
+if ($outputFormat == 'json'){
+	$tagCloudJSON = new stdClass;
+	$tagCloudJSON->tagCloud = (object) array(
+		'maxFontSize' => $maxFontSize, 
+		'maxObjects' => $maxObjects,
+		'tags' => array()
+	);
+	for($i=0; $i<count($tags);$i++){
+    		$tagCloudJSON->tagCloud->tags[$i]->title = $tags[$i]['tagname'];
+		$tagCloudJSON->tagCloud->tags[$i]->url = $tags[$i]['url'];
+		$tagCloudJSON->tagCloud->tags[$i]->weight = $tags[$i]['weight'];
+   	 }
+#echo "json";
+	$tagCloudJSON = $classJSON->encode($tagCloudJSON);
+	echo $tagCloudJSON;
+}
+
+class tagCloud{
+
+/*** the array of tags ***/
+private $tagsArray;
+
+
+public function __construct($tags){
+ /*** set a few properties ***/
+ $this->tagsArray = $tags;
+}
+
+/**
+ *
+ * Display tag cloud
+ *
+ * @access public
+ *
+ * @return string
+ *
+ */
+public function displayTagCloud(){
+ $ret = '';
+ shuffle($this->tagsArray);
+ foreach($this->tagsArray as $tag)
+    {
+    $ret.='<a style="font-size: '.$tag['weight'].'px;" href="'.$tag['url'].'" title="'.$tag['tagname'].'">'.$tag['tagname'].'</a>'."\n";
+    }
+ return $ret;
+}
+
+
+} /*** end of class ***/
+
+
+
+
+
+
+?>
\ No newline at end of file



More information about the Mapbender_commits mailing list