$value) { if ($header === "Origin") { //$e = new mb_exception("Origin: ".$value); $originFromHeader = $value; } } 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 ".$testMatch." not whitelist! Please control your mapbender.conf."; echo "Requested hostName 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($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { $scheme = "https"; } else { $scheme = "http"; } //get language parameter out of mapbender session if it is set else set default language to de_DE $sessionLang = Mapbender::session()->get("mb_lang"); if (isset($sessionLang) && ($sessionLang!='')) { $e = new mb_notice("mod_showMetadata.php: language found in session: ".$sessionLang); $language = $sessionLang; $langCode = explode("_", $language); $langCode = $langCode[0]; # Hopefully de or s.th. else $languageCode = $langCode; #overwrite the GET Parameter with the SESSION information } if (isset($_REQUEST["languageCode"]) & $_REQUEST["languageCode"] != "") { //validate to csv integer list $testMatch = $_REQUEST["languageCode"]; if (!($testMatch == 'de' or $testMatch == 'fr' or $testMatch == 'en')){ //echo 'languageCode: '.$testMatch.' is not valid.
'; echo 'Parameter languageCode is not valid (de,fr,en).
'; die(); } $languageCode = $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: '.$testMatch.' is not valid.
'; echo 'Parameter catalogueId is not valid (integer < 99).
'; die(); } $catalogueId = $testMatch; $testMatch = NULL; } else { echo 'Mandatory parameter catalogueId not set!
'; die(); }*/ /*if (isset($_REQUEST["datasetId"]) & $_REQUEST["datasetId"] != "") { //validate integer to 100 - not more $testMatch = $_REQUEST["datasetId"]; // $pattern = '/^([0-9]{0,1})([0-9]{1})$/'; if (!preg_match($pattern,$testMatch)){ //echo 'maxResults: '.$testMatch.' is not valid.
'; echo 'Parameter datasetId is not valid (integer < 99).
'; die(); } $datasetId = $testMatch; $testMatch = NULL; } else { echo 'Mandatory parameter datasetId not set!
'; die(); }*/ //write languageCode into session! $localeObj->setCurrentLocale($languageCode); if (isset($_REQUEST["outputFormat"]) & $_REQUEST["outputFormat"] != "") { //validate to de, en, fr $testMatch = $_REQUEST["outputFormat"]; if (!($testMatch == 'html' or $testMatch == 'json')){ //echo 'languageCode: '.$testMatch.' is not valid.
'; echo 'Parameter outputFormat is not valid (json,html).
'; die(); } $outputFormat = $testMatch; $testMatch = NULL; } //instantiate $mbMetadata = new Iso19139(); //initialize if resource is based on a request to csw interface $cswBasedResource = false; //test if getrecordbyid request was used - then the service data may also be in the same catalogue if (strpos(strtoupper($url), "GETRECORDBYID") !== false && strpos(strtoupper($url), "SERVICE=CSW") !== false && strpos(strtoupper($url), "VERSION=2.0.2") !== false) { $cswBasedResource = true; } else { $resultObj['message'] ='Url dont validate against a getrecordbyid url!'; $resultObj['result'] = null; echo json_encode($resultObj); die(); } //build search request for services //TODO: test if this ok - maybe not everything is parsed by class? instead we could use $mbMetadata->readFromUrl($url); //$e = new mb_exception("php/mod_getCoupledResourcesForDataset.php: url for getrecordbyid: ".$url); //$mbMetadata->createFromUrl($url); if ($mbMetadata->createFromUrl($url) == false) { $resultObj['message'] ='Could not get metadata by getrecordbyid request!'; $resultObj['result'] = null; echo json_encode($resultObj); die(); } //$e = new mb_exception("php/mod_getCoupledResourcesForDataset.php: datasetid from getrecordbyid: ".$mbMetadata->datasetIdCodeSpace.$mbMetadata->datasetId); $serviceMetadata = new stdClass(); $serviceMetadataIndex = 0; if ($mbMetadata->hierarchyLevel == 'dataset' || $mbMetadata->hierarchyLevel == 'series') { //get datasetidentifier to resolve coupled resources //$e = new mb_exception("datasetId: ".$mbMetadata->datasetId); //$e = new mb_exception("datasetIdCodeSpace: ".$mbMetadata->datasetIdCodeSpace); if ($cswBasedResource == true) { //$e = new mb_exception("try to resolve coupled resources"); //createCatObjFromXML($url); $csw = new csw(); //$e = new mb_exception("parse csw capabilities!"); //parse url $urlArray = parse_url($url); $urlWithoutRequest = $urlArray['scheme']."://".$urlArray['host'].$urlArray['path']; $cswCapUrl = $urlWithoutRequest."?SERVICE=CSW&VERSION=2.0.2&REQUEST=GetCapabilities"; $csw->createCatObjFromXML($cswCapUrl); $cswClient = new cswClient(); //$e = new mb_exception("php/mod_getCoupledResourcesForDataset.php: datasetid from getrecordbyid: ".$mbMetadata->datasetId); $operation = "getrecordsresolvecoupling"; $getrecordId = $mbMetadata->fileIdentifier; if ($mbMetadata->datasetIdCodeSpace != '') { $datasetId = str_replace('&','&',rtrim($mbMetadata->datasetIdCodeSpace, '/').'/'.$mbMetadata->datasetId); } else { $datasetId = (string)$mbMetadata->datasetId; } $recordType = 'service'; $cswResponseObject = $cswClient->doRequest(false, $operation, $getrecordId, false, $recordType, false, false, false, $datasetId, $csw); $serviceMetadataUrls = array(); 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, ... if (count($metadataRecord) < 1) { $resultObj['message'] ='No coupled services found in csw catalogue!'; $resultObj['result'] = null; echo json_encode($resultObj); die(); } for ($k = 1; $k <= count($metadataRecord) ; $k++) { //TODO: check if class metadata can be used instead - read xml write xml - parse metadata from xml? Look for namespaces! $fileIdentifier = $cswClient->operationResult->xpath('/csw:GetRecordsResponse/csw:SearchResults/gmd:MD_Metadata['.$k.']/gmd:fileIdentifier/gco:CharacterString'); $fileIdentifier = (string)$fileIdentifier[0]; //$e = new mb_exception("service fileidentifier: ".$fileIdentifier); //service date $mdDateStamp = $cswClient->operationResult->xpath('/csw:GetRecordsResponse/csw:SearchResults/gmd:MD_Metadata['.$k.']/gmd:identificationInfo/srv:SV_ServiceIdentification/gmd:date/gmd:CI_Date/gmd:date/gco:Date'); $mdDateStamp = (string)$mdDateStamp[0]; //service title $mdTitle = $cswClient->operationResult->xpath('/csw:GetRecordsResponse/csw:SearchResults/gmd:MD_Metadata['.$k.']/gmd:identificationInfo/srv:SV_ServiceIdentification/gmd:citation/gmd:CI_Citation/gmd:title/gco:CharacterString'); $mdTitle = (string)$mdTitle[0]; //service type $mdServiceType = $cswClient->operationResult->xpath('/csw:GetRecordsResponse/csw:SearchResults/gmd:MD_Metadata['.$k.']/gmd:identificationInfo/srv:SV_ServiceIdentification/srv:serviceType/gco:LocalName'); $mdServiceType = (string)$mdServiceType[0]; //service type version $mdServiceTypeVersion = $cswClient->operationResult->xpath('/csw:GetRecordsResponse/csw:SearchResults/gmd:MD_Metadata['.$k.']/gmd:identificationInfo/srv:SV_ServiceIdentification/srv:serviceTypeVersion/gco:CharacterString'); $mdServiceTypeVersion = (string)$mdServiceTypeVersion[0]; //accessUrl /*$mdAccessUrl = $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'); $mdAccessUrl = (string)$mdAccessUrl[0];*/ //first read the inspire kind of implementation of the access to capabilities documents $accessUrl = $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'); if ($accessUrl[0] == '') { //search for another accessUrl - as defined in csw ap iso $accessUrl = $cswClient->operationResult->xpath('/csw:GetRecordsResponse/csw:SearchResults/gmd:MD_Metadata['.$k.']/gmd:identificationInfo/srv:SV_ServiceIdentification/srv:containsOperations/srv:SV_OperationMetadata/srv:connectPoint/gmd:CI_OnlineResource/gmd:linkage/gmd:URL'); } $mdAccessUrl = $accessUrl[0]; //get service type - view / download //get service title /*$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++; }*/ //$e = new mb_exception("found service with fileIdentifier: ".$fileIdentifier." - date - ".$mdDateStamp); $serviceMetadata->service[$k]->datasetId = $datasetId; $serviceMetadata->service[$k]->serviceType = $mdServiceType; $serviceMetadata->service[$k]->serviceTitle = $mdTitle; $serviceMetadata->service[$k]->serviceDate = $mdDateStamp; $serviceMetadata->service[$k]->mdLink = $urlWithoutRequest."?SERVICE=CSW&VERSION=2.0.2&REQUEST=GetRecordById&ElementSetName=full&outputSchema=".urlencode('http://www.isotc211.org/2005/gmd')."&id=".$fileIdentifier; $serviceMetadata->service[$k]->htmlLink = $scheme.'://'.$hostName.str_replace(basename($_SERVER['SCRIPT_NAME']), "mod_exportIso19139.php", $_SERVER['PHP_SELF'])."?url=".urlencode($urlWithoutRequest."?SERVICE=CSW&VERSION=2.0.2&REQUEST=GetRecordById&ElementSetName=full&outputSchema=".urlencode('http://www.isotc211.org/2005/gmd')."&id=".$fileIdentifier); if (is_array($mdAccessUrl)) { $mdAccessUrl = $mdAccessUrl[0]; } //$serviceMetadata->service[$k]->accessUrl = $mdAccessUrl; if (in_array(strtoupper($mdServiceType), array('VIEW','OGC:WMS','WMS','PREDEFINED ATOM','DOWNLOAD','WFS','ATOM'))) { if (in_array(strtoupper($mdServiceType), array('PREDEFINED ATOM','DOWNLOAD','WFS','ATOM')) || in_array(strtoupper($mdServiceTypeVersion), array('PREDEFINED ATOM','DOWNLOAD','WFS','ATOM'))) { if (in_array(strtoupper($mdServiceType), array('PREDEFINED ATOM','ATOM')) || in_array(strtoupper($mdServiceTypeVersion), array('PREDEFINED ATOM','ATOM'))) { $serviceMetadata->service[$k]->accessClient = $scheme.'://'.$hostName.str_replace("php/".basename($_SERVER['SCRIPT_NAME']), "plugins/mb_downloadFeedClient.php", $_SERVER['PHP_SELF'])."?url=".urlencode($mdAccessUrl); $serviceMetadata->service[$k]->serviceSubType = 'ATOM'; $serviceMetadata->service[$k]->serviceType = "download"; $serviceMetadata->service[$k]->accessUrl = (string)$mdAccessUrl; } else { $serviceMetadata->service[$k]->serviceSubType = 'WFS'; $serviceMetadata->service[$k]->serviceType = "download"; $serviceMetadata->service[$k]->accessUrl = (string)$mdAccessUrl; } } else { $serviceMetadata->service[$k]->serviceType = 'view'; $serviceMetadata->service[$k]->accessUrl = correctWmsUrl($mdAccessUrl); } } else { $serviceMetadata->service[$k]->serviceType = 'other'; if ($mdAccessUrl == "" || isempty($mdAccessUrl)) { $serviceMetadata->service[$k]->accessUrl = null; } } } } $serviceMetadata->service = array_values($serviceMetadata->service); $serviceMetadata->fileIdentifier = (string)$mbMetadata->fileIdentifier; $serviceMetadata->resourceResponsibleParty = (string)$mbMetadata->resourceResponsibleParty; $serviceMetadata->resourceContactEmail = (string)$mbMetadata->resourceContactEmail; $resultObj['message'] = "Coupling resolved successfully!"; $resultObj['success'] = true; $serviceMetadata->genTime = microtime_float() - $starttime; $resultObj['result'] = $serviceMetadata; echo json_encode($resultObj, TRUE); die(); } else { $resultObj['message'] ='No csw based resource!!'; $resultObj['result'] = null; echo json_encode($resultObj); die(); } } else { $resultObj['message'] ='Hierarchy level of ISO metadata is '.$mbMetadata->hierarchyLevel.' - not dataset or series!'; $resultObj['result'] = null; echo json_encode($resultObj); die(); } ?>