[Mapbender-commits] r10035 - trunk/mapbender/http/php
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Mon Jan 21 08:15:09 PST 2019
Author: armin11
Date: 2019-01-21 08:15:09 -0800 (Mon, 21 Jan 2019)
New Revision: 10035
Added:
trunk/mapbender/http/php/mod_callCswMetadata.php
Log:
New draft for json interface to registrated csw catalogue
Added: trunk/mapbender/http/php/mod_callCswMetadata.php
===================================================================
--- trunk/mapbender/http/php/mod_callCswMetadata.php (rev 0)
+++ trunk/mapbender/http/php/mod_callCswMetadata.php 2019-01-21 16:15:09 UTC (rev 10035)
@@ -0,0 +1,696 @@
+<?php
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_connector.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+//classes for csw handling
+require_once(dirname(__FILE__)."/../classes/class_cswClient.php");
+require_once(dirname(__FILE__)."/../classes/class_csw.php");
+//************************************************************************************
+//parsing parameters
+//************************************************************************************
+//initialize request parameters:
+// $searchId = "dummysearch";
+$searchText = "*";
+// $isoCategories = NULL;
+// $inspireThemes = NULL;
+// $customCategories = NULL;
+// $timeBegin = NULL;
+// $timeEnd = NULL;
+// $regTimeBegin = NULL;
+// $regTimeEnd = NULL;
+if (defined('DEFAULT_MAX_RESULTS_PER_PAGE')){
+ $maxResults = DEFAULT_MAX_RESULTS_PER_PAGE;
+} else {
+ $maxResults = 10;
+}
+$searchBbox = NULL;
+$searchTypeBbox = "intersects"; //outside / inside
+$languageCode = "de";
+$outputFormat = 'json';
+//$searchResources = "dataset,service,application,other";
+//$searchResources = "dataset";
+$searchPages = "1";
+// $resourceIds = NULL; //resourceIds is used to get a comma separated list with ids of the resources - layer - featuretypes - wmc
+//it will be used to filter some results
+$resultTarget = "web";
+// $preDefinedMaxResults = array(5,10,15,20,25,30);
+// $searchEPSG = "EPSG:31466";
+// $resolveCoupledResources = false;
+$classJSON = new Mapbender_JSON;
+if (defined('ABSOLUTE_TMPDIR')){
+ $tempFolder = ABSOLUTE_TMPDIR;
+} else {
+ $tempFolder = TMPDIR;
+}
+// $orderBy = "rank"; //rank or title or id or date
+$hostName = $_SERVER['HTTP_HOST'];
+$headers = apache_request_headers();
+$originFromHeader = false;
+foreach ($headers as $header => $value) {
+ if ($header === "Origin") {
+ //$e = new mb_exception("Origin: ".$value);
+ $originFromHeader = $value;
+ }
+}
+//read the whole query string:
+$searchURL = $_SERVER['QUERY_STRING'];
+//$e = new mb_exception("mod_callMetadata.php: searchURL".$searchURL);
+//decode it !
+$searchURL = urldecode($searchURL);
+//control if some request variables are not set and set them explicit to NULL
+
+$checkForNullRequests = array("registratingDepartments","isoCategories","inspireThemes","customCategories","regTimeBegin","regTimeEnd","timeBegin","timeEnd","searchBbox","searchTypeBbox","searchResources","orderBy","hostName","resourceIds","restrictToOpenData");
+
+for($i=0; $i < count($checkForNullRequests); $i++){
+ if (!$_REQUEST[$checkForNullRequests[$i]] or $_REQUEST[$checkForNullRequests[$i]] == 'false' or $_REQUEST[$checkForNullRequests[$i]] == 'undefined') {
+ $_REQUEST[$checkForNullRequests[$i]] = "";
+ $searchURL = delTotalFromQuery($checkForNullRequests[$i],$searchURL);
+ }
+}
+
+//Read out request Parameter:
+if (isset($_REQUEST["searchId"]) & $_REQUEST["searchId"] != "") {
+ //generate md5 representation, cause the id is used as a filename later on! - no validation needed
+ $searchId = md5($_REQUEST["searchId"]);
+}
+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["registratingDepartments"]) & $_REQUEST["registratingDepartments"] != "") {
+ //validate to csv integer list
+ $testMatch = $_REQUEST["registratingDepartments"];
+ $pattern = '/^[\d,]*$/';
+ if (!preg_match($pattern,$testMatch)){
+ //echo 'registratingDepartments: <b>'.$testMatch.'</b> is not valid.<br/>';
+ echo 'Parameter <b>registratingDepartments</b> is not valid (integer or cs integer list).<br/>';
+ die();
+ }
+ $registratingDepartments = $testMatch;
+ $testMatch = NULL;
+}
+if (isset($_REQUEST["resourceIds"]) & $_REQUEST["resourceIds"] != "") {
+ //validate to csv integer list
+ $testMatch = $_REQUEST["resourceIds"];
+ $pattern = '/^[\d,]*$/';
+ if (!preg_match($pattern,$testMatch)){
+ //echo 'resourceIds: <b>'.$testMatch.'</b> is not valid.<br/>';
+ echo 'Parameter <b>resourceIds</b> is not valid (integer or cs integer list).<br/>';
+ die();
+ }
+ $resourceIds = $testMatch;
+ $testMatch = NULL;
+}
+if (isset($_REQUEST["isoCategories"]) & $_REQUEST["isoCategories"] != "") {
+ //validate to csv integer list
+ $testMatch = $_REQUEST["isoCategories"];
+ $pattern = '/^[\d,]*$/';
+ if (!preg_match($pattern,$testMatch)){
+ //echo 'isoCategories: <b>'.$testMatch.'</b> is not valid.<br/>';
+ echo 'Parameter <b>isoCategories</b> is not valid (integer or cs integer list).<br/>';
+ die();
+ }
+ $isoCategories = $testMatch;
+ $testMatch = NULL;
+}
+if (isset($_REQUEST["inspireThemes"]) & $_REQUEST["inspireThemes"] != "") {
+ //validate to csv integer list
+ $testMatch = $_REQUEST["inspireThemes"];
+ $pattern = '/^[\d,]*$/';
+ if (!preg_match($pattern,$testMatch)){
+ //echo 'inspireThemes: <b>'.$testMatch.'</b> is not valid.<br/>';
+ echo 'Parameter <b>inspireThemes</b> is not valid (integer or cs integer list).<br/>';
+ die();
+ }
+ $inspireThemes = $testMatch;
+ $testMatch = NULL;
+}
+
+if (isset($_REQUEST["customCategories"]) & $_REQUEST["customCategories"] != "") {
+ //validate to csv integer list
+ $testMatch = $_REQUEST["customCategories"];
+ $pattern = '/^[\d,]*$/';
+ if (!preg_match($pattern,$testMatch)){
+ //echo 'customCategories: <b>'.$testMatch.'</b> is not valid.<br/>';
+ echo 'Parameter <b>customCategories</b> is not valid (integer or cs integer list).<br/>';
+ die();
+ }
+ $customCategories = $testMatch;
+ $testMatch = NULL;
+}
+
+if (isset($_REQUEST["timeBegin"]) & $_REQUEST["timeBegin"] != "") {
+ //validate to iso date format YYYY-MM-DD
+ $testMatch = $_REQUEST["timeBegin"];
+ $pattern = '/^(19|20)[0-9]{2}[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$/';
+ if (!preg_match($pattern,$testMatch)){
+ //echo 'timeBegin: <b>'.$testMatch.'</b> is not valid.<br/>';
+ echo 'Parameter <b>timeBegin</b> is not valid.<br/>';
+ die();
+ }
+ $timeBegin = $testMatch;
+ $testMatch = NULL;
+}
+if (isset($_REQUEST["timeEnd"]) & $_REQUEST["timeEnd"] != "") {
+ $testMatch = $_REQUEST["timeEnd"];
+ $pattern = '/^(19|20)[0-9]{2}[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$/';
+ if (!preg_match($pattern,$testMatch)){
+ //echo 'timeEnd: <b>'.$testMatch.'</b> is not valid.<br/>';
+ echo 'Parameter <b>timeEnd</b> is not valid.<br/>';
+ die();
+ }
+ $timeEnd = $testMatch;
+ $testMatch = NULL;
+}
+if (isset($_REQUEST["regTimeBegin"]) & $_REQUEST["regTimeBegin"] != "") {
+ //validate to iso date format YYYY-MM-DD
+ $testMatch = $_REQUEST["regTimeBegin"];
+ $pattern = '/^(19|20)[0-9]{2}[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$/';
+ if (!preg_match($pattern,$testMatch)){
+ //echo 'regTimeBegin: <b>'.$testMatch.'</b> is not valid.<br/>';
+ echo 'Parameter <b>regTimeBegin</b> is not valid.<br/>';
+ die();
+ }
+ $regTimeBegin = $testMatch;
+ $testMatch = NULL;
+}
+if (isset($_REQUEST["regTimeEnd"]) & $_REQUEST["regTimeEnd"] != "") {
+ //validate to iso date format YYYY-MM-DD
+ $testMatch = $_REQUEST["regTimeEnd"];
+ $pattern = '/^(19|20)[0-9]{2}[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$/';
+ if (!preg_match($pattern,$testMatch)){
+ //echo 'regTimeEnd: <b>'.$testMatch.'</b> is not valid.<br/>';
+ echo 'Parameter <b>regTimeEnd</b> is not valid.<br/>';
+ die();
+ }
+ $regTimeEnd = $testMatch;
+ $testMatch = NULL;
+}*/
+
+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 = $testMatch;
+ $testMatch = NULL;
+}
+if (isset($_REQUEST["catalogueId"]) & $_REQUEST["catalogueId"] != "") {
+ //validate integer to 100 - not more
+ $testMatch = $_REQUEST["catalogueId"];
+ //
+ $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>catalogueId</b> is not valid (integer < 99).<br/>';
+ die();
+ }
+ $catalogueId = $testMatch;
+ $testMatch = NULL;
+} else {
+ echo 'Mandatory parameter <b>catalogueId</b> not set!<br/>';
+ die();
+}
+if (isset($_REQUEST["searchBbox"]) & $_REQUEST["searchBbox"] != "") {
+ //validate to float/integer
+ $testMatch = $_REQUEST["searchBbox"];
+ //$pattern = '/^[-\d,]*$/';
+ $pattern = '/^[-+]?([0-9]*\.[0-9]+|[0-9]+)*$/';
+ $testMatchArray = explode(',',$testMatch);
+ if (count($testMatchArray) != 4) {
+ echo 'Parameter <b>searchBbox</b> has a wrong amount of entries.<br/>';
+ die();
+ }
+ for($i=0; $i<count($testMatchArray);$i++){
+ if (!preg_match($pattern,$testMatchArray[$i])){
+ echo 'Parameter <b>searchBbox</b> is not a valid coordinate value.<br/>';
+ die();
+ }
+ }
+ $searchBbox = $testMatch;
+ $testMatch = NULL;
+}
+if (isset($_REQUEST["searchTypeBbox"]) & $_REQUEST["searchTypeBbox"] != "") {
+ //validate to inside / outside - TODO implement other ones than intersects which is default
+ $testMatch = $_REQUEST["searchTypeBbox"];
+ if (!($testMatch == 'inside' or $testMatch == 'outside' or $testMatch == 'intersects')){
+ //echo 'searchTypeBbox: <b>'.$testMatch.'</b> is not valid.<br/>';
+ echo 'Parameter <b>searchTypeBbox</b> is not valid (inside,outside,intersects).<br/>';
+ die();
+ }
+ $searchTypeBbox = $testMatch; //TODO activate this
+ $testMatch = NULL;
+}
+/*if (isset($_REQUEST["accessRestrictions"]) & $_REQUEST["accessRestrictions"] != "") {
+ //validate to ?
+ //TODO implement me //$accessRestrictions = $_REQUEST["accessRestrictions"];
+}*/
+if (isset($_REQUEST["languageCode"]) & $_REQUEST["languageCode"] != "") {
+ //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/>';
+ echo 'Parameter <b>languageCode</b> is not valid (de,fr,en).<br/>';
+ die();
+ }
+ $languageCode = $testMatch;
+ $testMatch = NULL;
+}
+if (isset($_REQUEST["outputFormat"]) & $_REQUEST["outputFormat"] != "") {
+ $testMatch = $_REQUEST["outputFormat"];
+ if (!($testMatch == 'json' or $testMatch == 'georss')){
+ //echo 'outputFormat: <b>'.$testMatch.'</b> is not valid.<br/>';
+ echo 'Parameter <b>outputFormat</b> is not valid (json,georss).<br/>';
+ die();
+ }
+ $outputFormat = $testMatch;
+ $testMatch = NULL;
+}
+
+//$restrictToOpenData = false;
+/*if (isset($_REQUEST["restrictToOpenData"]) & $_REQUEST["restrictToOpenData"] != "") {
+ $testMatch = $_REQUEST["restrictToOpenData"];
+ if (!($testMatch == 'true' or $testMatch == 'false')){
+ echo 'Parameter <b>restrictToOpenData</b> is not valid (true,false).<br/>';
+ die();
+ }
+ switch ($testMatch) {
+ case "true":
+ $restrictToOpenData = "true";
+ break;
+ case "false":
+ $restrictToOpenData = "false";
+ break;
+ }
+ $testMatch = NULL;
+}
+
+if (isset($_REQUEST["resolveCoupledResources"]) & $_REQUEST["resolveCoupledResources"] != "") {
+ $testMatch = $_REQUEST["resolveCoupledResources"];
+ if (!($testMatch == 'true' or $testMatch == 'false')){
+ echo 'Parameter <b>resolveCoupledResources</b> is not valid (true,false (default to false)).<br/>';
+ die();
+ }
+ switch ($testMatch) {
+ case "true":
+ $resolveCoupledResources = "true";
+ break;
+ case "false":
+ $resolveCoupledResources = "false";
+ break;
+ }
+ $testMatch = NULL;
+}*/
+
+if (isset($_REQUEST["hostName"]) & $_REQUEST["hostName"] != "") {
+ //validate to some hosts
+ $testMatch = $_REQUEST["hostName"];
+ //look for whitelist in mapbender.conf
+ $HOSTNAME_WHITELIST_array = explode(",",HOSTNAME_WHITELIST);
+ if (!in_array($testMatch,$HOSTNAME_WHITELIST_array)) {
+ //echo "Requested hostname <b>".$testMatch."</b> not whitelist! Please control your mapbender.conf.";
+ echo "Requested <b>hostName</b> not in whitelist! Please control your mapbender.conf.";
+
+ $e = new mb_notice("Whitelist: ".HOSTNAME_WHITELIST);
+ $e = new mb_notice("hostName not found in whitelist!");
+ die();
+ }
+ $hostName = $testMatch;
+ $testMatch = NULL;
+}
+/*if (isset($_REQUEST["orderBy"]) & $_REQUEST["orderBy"] != "") {
+ $testMatch = $_REQUEST["orderBy"];
+ if (!($testMatch == 'rank' or $testMatch == 'title' or $testMatch == 'id' or $testMatch == 'date')){
+ //echo 'orderBy: <b>'.$testMatch.'</b> is not valid.<br/>';
+ echo 'Parameter <b>orderBy</b> is not valid (rank,title,id,date).<br/>';
+ die();
+ }
+ $orderBy = $testMatch;
+ $testMatch = NULL;
+}// else {*/
+//$orderBy= 'rank';
+//}
+if (isset($_REQUEST["searchResources"]) & $_REQUEST["searchResources"] != "") {
+ //validate to wms,wfs,wmc,georss
+ $testMatch = $_REQUEST["searchResources"];
+ #$pattern = '/^(19|20)[0-9]{2}[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$/';
+ $countSR = count(explode(',',$testMatch));
+ if (!($countSR >= 1 && $countSR <= 4)){
+ //echo 'searchResources: <b>'.$testMatch.'</b> count of requested resources out of sync.<br/>';
+ echo 'Parameter <b>searchResources</b> count of requested resources out of sync.<br/>';
+ die();
+ } else {
+ $testArray = explode(',',$testMatch);
+ for($i=0; $i<count($testArray);$i++){
+ if (!($testArray[$i] == 'dataset' or $testArray[$i] == 'service' or $testArray[$i] == 'application' or $testArray[$i] == 'nonGeographicDataset')) {
+ //echo 'searchResources: <b>'.$testMatch.'</b>at least one of them does not exists!<br/>';
+ echo 'Parameter <b>searchResources</b> at least one of them does not exists! (dataset, service, application, nonGeographicDataset)<br/>';
+ die();
+ }
+ }
+ unset($i);
+ }
+ $searchResources = $testMatch;
+ $testMatch = NULL;
+}
+if (isset($_REQUEST["searchPages"]) & $_REQUEST["searchPages"] != "") {
+ //validate to csv integer list with dimension of searchResources list
+ $testMatch = $_REQUEST["searchPages"];
+ $pattern = '/^[-\d,]*$/';
+ if (!preg_match($pattern,$testMatch)){
+ //echo 'searchPages: <b>'.$testMatch.'</b> is not valid.<br/>';
+ echo 'Parameter <b>searchPages</b> is not valid (integer or integer csv).<br/>';
+ die();
+ }
+ if (count(explode(',',$testMatch)) != count(explode(',',$searchResources))) {
+ //echo 'searchPages: <b>'.$testMatch.'</b> has a wrong amount of entries.<br/>';
+ echo 'Parameter <b>searchPages</b> has a wrong amount of entries.<br/>';
+ die();
+ }
+ $searchPages = $testMatch;
+ $testMatch = NULL;
+#$searchPages = $_REQUEST["searchPages"];
+ #$searchPages = split(',',$searchPages);
+
+}
+if (isset($_REQUEST["resultTarget"]) & $_REQUEST["resultTarget"] != "") {
+ //validate to web,debug,file
+ $testMatch = $_REQUEST["resultTarget"];
+ if (!($testMatch == 'web' or $testMatch == 'debug' or $testMatch == 'file' or $testMatch == 'webclient' or $testMatch == 'internal' or $testMatch == "categories")){
+ //echo 'resultTarget: <b>'.$testMatch.'</b> is not valid.<br/>';
+ echo 'Parameter <b>resultTarget</b> is not valid (file,web,debug,webclient,internal,categories).<br/>';
+ die();
+ }
+ $resultTarget = $testMatch;
+ $testMatch = NULL;
+}
+//$e = new mb_exception("UserID GET: ".$_REQUEST['userId']);
+//$e = new mb_exception("UserID from session (new): ".Mapbender::session()->get("mb_user_id"));
+//$e = new mb_exception("UserID from session (old): ".$_SESSION['mb_user_id']);
+
+/*if (isset($_REQUEST["userId"]) & $_REQUEST["userId"] != "") {
+ //validate integer to 100 - not more
+ $testMatch = $_REQUEST["userId"];
+ //give max 99 entries - more will be to slow
+ $pattern = '/^[0-9]*$/';
+ if (!preg_match($pattern,$testMatch)){
+ //echo 'userId: <b>'.$testMatch.'</b> is not valid.<br/>';
+ echo 'Parameter <b>userId</b> is not valid (integer).<br/>';
+ die();
+ }
+ $userId = $testMatch;
+ $testMatch = NULL;
+#
+} else { //look for id in session
+ $userId = Mapbender::session()->get("mb_user_id");
+ if ($userId == false) {
+ $userId = PUBLIC_USER;
+ }
+}
+*/
+#$searchResources = array('wms','wfs','wmc','georss');
+#$searchPages = array(1,1,1,1);
+
+//TODO: if class is called directly
+
+if ($resultTarget == 'debug') {
+ echo "<br>DEBUG: searchURL: ".$searchURL."<br>";
+ #echo "<br>DEBUG: languageCode: ".$languageCode."<br>";
+}
+
+
+if ($resultTarget == 'file' or $resultTarget == 'webclient') {
+ if (!isset($searchResources) OR ($searchResources == "")) {
+ $searchResources = "dataset,service,application,other";
+ $resolveCoupledResources = true;
+ $searchPages = "1,1,1,1";
+ }
+
+}
+if (!isset($searchPages) OR ($searchPages == "")) {
+ for($i=0;$i<count(explode(",",$searchResources));$i++) {
+ $searchPages[$i] = 1;
+ }
+ $searchPages = implode(",",$searchPages);
+ //$e = new mb_exception("mod_callMetadata.php: set searchPages to :".$searchPages);
+}
+if ($resultTarget == 'web' or $resultTarget == 'debug') {
+ if (!isset($searchResources) OR ($searchResources == "")) {
+ $searchResources = "dataset";
+ $searchPages = "1";
+ }
+}
+
+//convert the respources and the pagenumbers into arrays
+$searchResourcesArray = explode(",",$searchResources);
+$searchPages = explode(",",$searchPages);
+//************************************************************************************
+//begin main program
+//************************************************************************************
+$queryString = $searchText;
+$queryStringParts = explode("+",$queryString);
+$queryText = $queryStringParts[0];
+
+//TODO query
+
+
+$existsSpatialFilter = false;
+$searchBboxArray = explode(",", $searchBbox);
+if ($searchBbox !== NULL) {
+ $existsSpatialFilter = true;
+ switch ($searchTypeBbox) {
+ case "intersect":
+ $spatialFilter .= "<ogc:BBOX>";
+ break;
+ case "inside":
+ $spatialFilter .= "<ogc:Within>";
+ break;
+ case "outside":
+ $spatialFilter .= "<ogc:Disjoint>";
+ break;
+ default:
+ $spatialFilter .= "<ogc:BBOX>";
+ }
+ $spatialFilter .= "<ogc:PropertyName>BoundingBox</ogc:PropertyName>";
+ $spatialFilter .= "<gml:Envelope>";
+ $spatialFilter .= "<gml:lowerCorner>".$searchBboxArray[0]." ".$searchBboxArray[1]."</gml:lowerCorner>";
+ $spatialFilter .= "<gml:upperCorner>".$searchBboxArray[2]." ".$searchBboxArray[3]."</gml:upperCorner>";
+ $spatialFilter .= "</gml:Envelope>";
+ switch ($searchTypeBbox) {
+ case "intersect":
+ $spatialFilter .= "</ogc:BBOX>";
+ break;
+ case "inside":
+ $spatialFilter .= "</ogc:Within>";
+ break;
+ case "outside":
+ $spatialFilter .= "</ogc:Disjoint>";
+ break;
+ default:
+ $spatialFilter .= "/<ogc:BBOX>";
+ }
+}
+//csw Id = catalogueId
+$csw = new csw();
+$csw->createCatObjFromDB($catalogueId);
+if ($csw == false) {
+ echo "Catalogue with id ".$catalogueId." not found in mapbender database!";
+ die();
+}
+$cswClient = new cswClient();
+$cswClient->cswId = $catalogueId;
+//$e = new mb_exception("invoke get record by id");
+//$e = new mb_exception("catalogue id = ".$cswId);
+//map paging to results
+
+if ($existsSpatialFilter == true){
+ $additionalFilter = $spatialFilter;
+} else {
+ $additionalFilter = false;
+}
+$recordType = $searchResources;
+//first count all hits for filter:
+$cswResponseObject = $cswClient->doRequest($cswClient->cswId, 'counthits', false, false, $recordType, false, false, $additionalFilter);
+
+$e = new mb_exception("Number of type ".$recordType." datasets in portal CSW: ".$cswClient->operationResult);
+
+$maxRecords = (integer)$cswClient->operationResult;
+$pages = ceil($maxRecords / $maxResults);
+//$e = new mb_exception("pages: ".$pages);
+$metadataArray = array();
+$numberOfMetadataRecords = 0;
+//$cswResponseObject = $cswClient->doRequest($cswClient->cswId, 'getrecords', $fileIdentifier, false, false, false, false, $additionalFilter);
+//parse XML
+
+//$e = new mb_exception("maxResults: ".$maxResults);
+
+
+for ($i = 0; $i < 1 ; $i++) {
+//for ($i = 0; $i <= $pages-1 ; $i++) {
+ //$cswClient = new cswClient();
+ //$cswClient->cswId = $catalogueId;
+ $result = $cswClient->doRequest($cswClient->cswId, 'getrecordspaging', false, false, $recordType, $maxResults, ($i*$recordsPerPage)+1, $additionalFilter);
+ $page = $i + 1;
+ //$e = new mb_exception("page: ".$page." (".$pages.")");
+ //$e = new mb_exception("result: ".json_encode($cswClient->operationSuccessful));
+ if ($cswClient->operationSuccessful == true) {
+ //$e = new mb_exception("operation successfull");
+ //$e = new mb_exception(gettype($cswClient->operationResult));
+ $metadataRecord = $cswClient->operationResult->xpath('/csw:GetRecordsResponse/csw:SearchResults/gmd:MD_Metadata');
+ //$e = new mb_exception("number of records: ".count($metadataRecord));
+ //what is possible: keywords, categories?, spatial, ...
+ for ($k = 1; $k <= count($metadataRecord) ; $k++) {
+ $fileIdentifier = $cswClient->operationResult->xpath('/csw:GetRecordsResponse/csw:SearchResults/gmd:MD_Metadata['.$k.']/gmd:fileIdentifier/gco:CharacterString');
+ $fileIdentifier = (string)$fileIdentifier[0];
+ echo $fileIdentifier." - ";
+ $mdDateStamp = $cswClient->operationResult->xpath('/csw:GetRecordsResponse/csw:SearchResults/gmd:MD_Metadata['.$k.']/gmd:dateStamp/gco:Date');
+ $mdDateStamp = (string)$mdDateStamp[0];
+ echo $mdDateStamp."<br>";
+ $datasetIdentifier = $cswClient->operationResult->xpath('/csw:GetRecordsResponse/csw:SearchResults/gmd:MD_Metadata['.$k.']/gmd:identificationInfo/gmd:MD_DataIdentification/@uuid');
+ $datasetidentifier = (string)$datasetidentifier[0];
+ $url = $cswClient->operationResult->xpath('/csw:GetRecordsResponse/csw:SearchResults/gmd:MD_Metadata['.$k.']/gmd:distributionInfo/gmd:MD_Distribution/gmd:transferOptions/gmd:MD_DigitalTransferOptions/gmd:onLine/gmd:CI_OnlineResource/gmd:linkage/gmd:URL');
+ $url = (string)$url[0];
+ if (isset($url) && $url !=="") {
+ //$metadataArray[$numberOfMetadataRecords]['uuid'] = $datasetIdentifier;
+ $metadataArray[$numberOfMetadataRecords]['uuid'] = $fileIdentifier;
+ $metadataArray[$numberOfMetadataRecords]['changedate'] = $mdDateStamp;
+ $numberOfMetadataRecords++;
+ }
+ }
+ }
+}
+//************************************************************************************
+//functions
+//************************************************************************************
+//function to delete one of the comma separated values from one get request
+function delFromQuery($paramName,$queryString,$string,$queryArray,$queryList) {
+ //check if if count searchArray = 1
+ if (count($queryArray) == 1){
+ //remove request parameter from url by regexpr or replace
+ $str2search = $paramName."=".$queryList;
+ if ($paramName == "searchText") {
+ $str2exchange = "searchText=*&";
+ } else {
+ $str2exchange = "";
+ }
+ if ($paramName == "searchResources") {
+ $str2exchange = "searchResources=dataset,wms,wfs,wmc&";
+ } else {
+ $str2exchange = "";
+ }
+ $queryStringNew = str_replace($str2search, $str2exchange, $queryString);
+ $queryStringNew = str_replace("&&", "&", $queryStringNew);
+ } else {
+ //there are more than one filter - reduce the filter
+ $objectList = "";
+ for($i=0; $i < count($queryArray); $i++){
+ if ($queryArray[$i] != $string){
+ $objectList .= $queryArray[$i].",";
+ }
+ }
+ //remove last comma
+ $objectList = rtrim($objectList, ",");
+ $str2search = $paramName."=".$queryList;
+ //echo "string to search: ".$str2search."<br>";
+ $str2exchange = $paramName."=".$objectList;
+ //echo "string to exchange: ".$str2exchange."<br>";
+ $queryStringNew = str_replace($str2search, $str2exchange, urldecode($queryString));
+ }
+ return $queryStringNew;
+}
+
+//function to remove one complete get param out of the query
+function delTotalFromQuery($paramName,$queryString) {
+ //echo $paramName ."<br>";
+ $queryString = "&".$queryString;
+ if ($paramName == "searchText") {
+ $str2exchange = "searchText=*&";
+ } else {
+ $str2exchange = "";
+ }
+ if ($paramName == "searchResources") {
+ $str2exchange = "searchResources=dataset,wms,wfs,wmc&";
+ }
+ $queryStringNew = preg_replace('/\b'.$paramName.'\=[^&]*&?/',$str2exchange,$queryString); //TODO find empty get params
+ $queryStringNew = ltrim($queryStringNew,'&');
+ $queryStringNew = rtrim($queryStringNew,'&');
+ return $queryStringNew;
+}
+//delete all string entries from array
+function deleteEntry($arrayname, $entry) {
+ $n = $arrayname.length;
+ for($i=0; $i<($n+1); $i++){
+ if ($arrayname[$i] == $entry) {
+ $arrayname.splice($i, 1);
+ }
+ }
+ return $arrayname;
+}
+function correctWmsUrl($wms_url) {
+ //check if last sign is ? or & or none of them
+ $lastChar = substr($wms_url,-1);
+ //check if getcapabilities is set as a parameter
+ $findme = "getcapabilities";
+ $posGetCap = strpos(strtolower($wms_url), $findme);
+ if ($posGetCap === false) {
+ $posGetAmp = strpos(strtolower($wms_url), "?");
+ if ($posGetAmp === false) {
+ $wms_url .= "?REQUEST=GetCapabilities&VERSION=1.1.1&SERVICE=WMS";
+ } else {
+ switch ($lastChar) {
+ case "?":
+ $wms_url .= "REQUEST=GetCapabilities&VERSION=1.1.1&SERVICE=WMS";
+ break;
+ case "&":
+ $wms_url .= "REQUEST=GetCapabilities&VERSION=1.1.1&SERVICE=WMS";
+ break;
+ default:
+ $wms_url .= "&REQUEST=GetCapabilities&VERSION=1.1.1&SERVICE=WMS";
+ break;
+ }
+ }
+ } else {
+ //check if version is defined
+ $findme1 = "version=";
+ $posVersion = strpos(strtolower($wms_url), $findme1);
+ if ($posVersion === false) {
+ $wms_url .= "&VERSION=1.1.1";
+ } else {
+ //mapbender only handle 1.1.1
+ $wms_url = str_replace('version=1.3.0', 'VERSION=1.1.1', $wms_url);
+ $wms_url = str_replace('VERSION=1.3.0', 'VERSION=1.1.1', $wms_url);
+ }
+
+ }
+
+ //exchange &? with & and &
+ $wms_url = str_replace('&?', '&', $wms_url);
+ $wms_url = str_replace('&?', '&', $wms_url);
+ $wms_url = str_replace('&', '&', $wms_url);
+return $wms_url;
+}
+function isValidURL($url) {
+ return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url);
+}
+
+?>
More information about the Mapbender_commits
mailing list