[Mapbender-commits] r9553 - trunk/mapbender/http/geoportal

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Aug 10 03:04:14 PDT 2016


Author: armin11
Date: 2016-08-10 03:04:14 -0700 (Wed, 10 Aug 2016)
New Revision: 9553

Added:
   trunk/mapbender/http/geoportal/mod_getCatalogueKeywordSuggestion.php
Log:
Little module to give keyword sugestions for mapbender catalogue

Added: trunk/mapbender/http/geoportal/mod_getCatalogueKeywordSuggestion.php
===================================================================
--- trunk/mapbender/http/geoportal/mod_getCatalogueKeywordSuggestion.php	                        (rev 0)
+++ trunk/mapbender/http/geoportal/mod_getCatalogueKeywordSuggestion.php	2016-08-10 10:04:14 UTC (rev 9553)
@@ -0,0 +1,63 @@
+<?php
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+
+//GET parameter: searchText, maxResults
+$maxResults = 10;
+$timeBegin = microtime(1000000);
+//validate parameter
+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
+	$testMatch = $_REQUEST["searchText"];
+	$pattern = '/(\%27)|(\')|(\-\-)|(\")|(\%22)/';		
+ 	if (preg_match($pattern,$testMatch)){
+		//echo 'searchText: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		echo 'Parameter <b>searchText</b> is not valid.<br/>'; 
+		die(); 		
+ 	}
+	$searchText = $testMatch;
+        $searchText = str_replace('<','{<}',$searchText);
+ 	$searchText = str_replace('>','{>}',$searchText);
+	$testMatch = NULL;
+	if ($searchText ==='false') {
+		$searchText ='*';
+	}
+}
+if (isset($_REQUEST["maxResults"]) & $_REQUEST["maxResults"] != "") {
+	//validate integer to 100 - not more
+	$testMatch = $_REQUEST["maxResults"];
+	//give max 99 entries - more will be to slow
+	$pattern = '/^([0-9]{0,1})([0-9]{1})$/';		
+ 	if (!preg_match($pattern,$testMatch)){ 
+		//echo 'maxResults: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		echo 'Parameter <b>maxResults</b> is not valid (integer < 99).<br/>'; 
+		die(); 		
+ 	}
+	$maxResults = (integer)$testMatch;
+	$testMatch = NULL;
+	if ($maxResults > 25) {
+		echo 'Parameter <b>maxResults</b> is not valid (integer < 25).<br/>'; 
+		die();
+	}
+}
+//do the sql select
+$sql = "SELECT keyword FROM keyword_search_view WHERE keyword_ts @@ to_tsquery('german', $1) || keyword_upper LIKE $2 ORDER BY keyword LIMIT $3";
+$t = array('s', 's', 'i');
+$normSearch = str_replace("รค","AE",strtoupper($searchText));
+$v = array($searchText, "%".$normSearch."%", $maxResults);
+$resultList = array();
+$res = db_prep_query($sql,$v,$t);
+header('Content-type: application/json; charset=utf-8');
+$i = 0;
+while($row = db_fetch_array($res)){
+	$resultList[$i]['keyword'] = $row['keyword'];
+	$resultList[$i]['keywordHigh'] = str_replace($searchText, "<b>".$searchText."</b>", $row['keyword']);
+	$i++;
+}
+$result->results = $i;
+$timeEnd = microtime(1000000);
+$timeDiff = $timeEnd - $timeBegin;
+$result->time = $timeDiff;
+$result->resultList = $resultList;
+echo json_encode($result);
+?>



More information about the Mapbender_commits mailing list