[Mapbender-commits] r8996 - trunk/mapbender/http/plugins
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Thu Jul 10 03:14:29 PDT 2014
Author: armin11
Date: 2014-07-10 03:14:29 -0700 (Thu, 10 Jul 2014)
New Revision: 8996
Modified:
trunk/mapbender/http/plugins/mb_downloadFeedClient.php
trunk/mapbender/http/plugins/mb_downloadFeedServer.php
Log:
Bugfix for INSPIRE ATOM Feed Client - alter xml parsing to dom, cause simple xml has problems when casting to arrays - see: https://bugs.php.net/bug.php?id=62203
Modified: trunk/mapbender/http/plugins/mb_downloadFeedClient.php
===================================================================
--- trunk/mapbender/http/plugins/mb_downloadFeedClient.php 2014-07-09 13:48:20 UTC (rev 8995)
+++ trunk/mapbender/http/plugins/mb_downloadFeedClient.php 2014-07-10 10:14:29 UTC (rev 8996)
@@ -118,7 +118,7 @@
<p>
<form id="service_feed_form">
<label for="download_feed_url"><?php echo _mb("ATOM Feed url");?></label>
- <input name="download_feed_url" id="download_feed_url" class="required" <?php if (isset($url)) {echo " value=\"".$url."\"";} else { echo " value=\"\"";}?>/><img src="../img/gnome/process-stop.png" width="20px" onclick="$('#download_feed_url').val('');"/><input type="button" title="Get Feed" id="download_feed_button" value="Get Feed Content"/>
+ <input name="download_feed_url" id="download_feed_url" class="required" <?php if (isset($url)) {echo " value=\"".htmlspecialchars($url)."\"";} else { echo " value=\"\"";}?>/><img src="../img/gnome/process-stop.png" width="20px" onclick="$('#download_feed_url').val('');"/><input type="button" title="Get Feed" id="download_feed_button" value="Get Feed Content"/>
</form>
</p>
</div>
Modified: trunk/mapbender/http/plugins/mb_downloadFeedServer.php
===================================================================
--- trunk/mapbender/http/plugins/mb_downloadFeedServer.php 2014-07-09 13:48:20 UTC (rev 8995)
+++ trunk/mapbender/http/plugins/mb_downloadFeedServer.php 2014-07-10 10:14:29 UTC (rev 8996)
@@ -59,25 +59,60 @@
}
}
+
+function DOMNodeListObjectValuesToArray($domNodeList) {
+ $iterator = 0;
+ $array = array();
+ foreach ($domNodeList as $item) {
+ $array[$iterator] = $item->nodeValue; // this is a DOMNode instance
+ // you might want to have the textContent of them like this
+ $iterator++;
+ }
+ return $array;
+}
+
+function DOMNodeListObjectValuesToHTML($domNodeList) {
+ $iterator = 0;
+ $array = array();
+ //$dom = new DOMDocument;
+ foreach ($domNodeList as $item) {
+ $array[$iterator] = $item->saveXML(); // this is a DOMNode instance
+ // you might want to have the textContent of them like this
+ $iterator++;
+ }
+ return $array;
+}
+
+function DOMNodeListObjectAttributes($domNodeList) {
+ $attributes = array();
+ foreach($domNodeList->attributes as $attribute_name => $attribute_node)
+ {
+ /** @var DOMNode $attribute_node */
+ $attributes[$attribute_name] = $attribute_node->nodeValue;
+ }
+ return $attributes;
+}
+
switch ($_REQUEST['method']) {
case "getServiceFeedObjectFromUrl" :
$serviceFeedUrl = htmlspecialchars_decode($_REQUEST['url']);//htmlspecialchars_decode is done to prohibit xss vulnerability of the client, which allows url as a get parameter
$logUrl = date("F j, Y, g:i a",time())." - ".$serviceFeedUrl;
$e = new mb_exception("inspire: ".$logUrl);
logit($logUrl);
-
- //test url
-
//get feed from remote server
$feedConnector = new connector($serviceFeedUrl);
$feedConnector->set("timeOut", "5");
$feedFile = $feedConnector->file;
- //$mbMetadata = $this->createMapbenderMetadataFromXML($xml);
//parse content
//$e = new mb_exception($feedFile);
libxml_use_internal_errors(true);
+ //DOM
+ $feedXML = new DOMDocument();
try {
- $feedXML = simplexml_load_string($feedFile);
+ //$feedXML = simplexml_load_string($feedFile);
+ //alternative dom parsing
+ $feedXML->loadXML($feedFile);
+
if ($feedXML === false) {
foreach(libxml_get_errors() as $error) {
$err = new mb_exception("downloadFeedServer.php:".$error->message);
@@ -92,72 +127,78 @@
}
//$e = new mb_exception($feedXML->file);
if ($feedXML != false) {
- $feedXML->registerXPathNamespace("georss", "http://www.georss.org/georss");
- $feedXML->registerXPathNamespace("inspire_dls", "http://inspire.ec.europa.eu/schemas/inspire_dls/1.0");
- $feedXML->registerXPathNamespace("defaultns", "http://www.w3.org/2005/Atom");
-
- $title = $feedXML->xpath('/defaultns:feed/defaultns:entry/defaultns:title');
- //$content = $feedXML->xpath('/defaultns:feed/defaultns:entry/defaultns:content');
- $rights = $feedXML->xpath('/defaultns:feed/defaultns:entry/defaultns:rights');
- $feedRights = $feedXML->xpath('/defaultns:feed/defaultns:rights');
- $summary = $feedXML->xpath('/defaultns:feed/defaultns:entry/defaultns:summary');
- $feedSummary = $feedXML->xpath('/defaultns:feed/defaultns:subtitle');
- $date = $feedXML->xpath('/defaultns:feed/defaultns:entry/defaultns:date');
- $code = $feedXML->xpath('/defaultns:feed/defaultns:entry/inspire_dls:spatial_dataset_identifier_code');
- $namespace = $feedXML->xpath('/defaultns:feed/defaultns:entry/inspire_dls:spatial_dataset_identifier_namespace');
- $polygon = $feedXML->xpath('/defaultns:feed/defaultns:entry/georss:polygon');
- $bbox = $feedXML->xpath('/defaultns:feed/defaultns:entry/georss:box');
- $metadataLink = $feedXML->xpath('/defaultns:feed/defaultns:entry/defaultns:link[contains(@rel,\'describedby\')]/@href');
+ //$xml->loadXML($feedFile);
+ $xpath = new DOMXPath($feedXML);
+ $rootNamespace = $feedXML->lookupNamespaceUri($feedXML->namespaceURI);
+ $xpath->registerNamespace('defaultns', $rootNamespace);
+ $xpath->registerNamespace('georss','http://www.georss.org/georss');
+ $xpath->registerNamespace('inspire_dls','http://inspire.ec.europa.eu/schemas/inspire_dls/1.0');
+
+ $title = $xpath->query('/defaultns:feed/defaultns:entry/defaultns:title');
+ //$content = $xpath->query('/defaultns:feed/defaultns:entry/defaultns:content');
+ $rights = $xpath->query('/defaultns:feed/defaultns:entry/defaultns:rights');
+ $feedRights = $xpath->query('/defaultns:feed/defaultns:rights');
+ $summary = $xpath->query('/defaultns:feed/defaultns:entry/defaultns:summary');
+ $feedSummary = $xpath->query('/defaultns:feed/defaultns:subtitle');
+ $date = $xpath->query('/defaultns:feed/defaultns:entry/defaultns:date');
+ $code = $xpath->query('/defaultns:feed/defaultns:entry/inspire_dls:spatial_dataset_identifier_code');
+ $namespace = $xpath->query('/defaultns:feed/defaultns:entry/inspire_dls:spatial_dataset_identifier_namespace');
+ $polygon = $xpath->query('/defaultns:feed/defaultns:entry/georss:polygon');
+ $bbox = $xpath->query('/defaultns:feed/defaultns:entry/georss:box');
+ $metadataLink = $xpath->query('/defaultns:feed/defaultns:entry/defaultns:link[contains(@rel,\'describedby\')]/@href');
//for hybrid implementation
- $capabilitiesLink = $feedXML->xpath('/defaultns:feed/defaultns:link[contains(@rel,\'related\')]/@href');
- $datasetFeedLink = $feedXML->xpath('/defaultns:feed/defaultns:entry/defaultns:link[contains(@rel,\'alternate\')]/@href');
+ $capabilitiesLink = $xpath->query('/defaultns:feed/defaultns:link[contains(@rel,\'related\')]/@href');
+ $datasetFeedLink = $xpath->query('/defaultns:feed/defaultns:entry/defaultns:link[contains(@rel,\'alternate\') and contains(@type,\'application/atom+xml\')]/@href');
//new feature collection
$featureCollection = new FeatureCollection;
- for ($i=0; $i<=(count($title)-1); $i++) {
+ //node values entry level
+ $titleArray = DOMNodeListObjectValuesToArray($title);
+ $contentArray = DOMNodeListObjectValuesToArray($content);
+ $rightsArray = DOMNodeListObjectValuesToArray($rights);
+ $summaryArray = DOMNodeListObjectValuesToArray($summary);
+ $dateArray = DOMNodeListObjectValuesToArray($date);
+ $codeArray = DOMNodeListObjectValuesToArray($code);
+ $namespaceArray = DOMNodeListObjectValuesToArray($namespace);
+ $bboxArray = DOMNodeListObjectValuesToArray($bbox);
+ $polygonArray = DOMNodeListObjectValuesToArray($polygon);
+ //node values feed level
+ $feedRightsArray = DOMNodeListObjectValuesToArray($feedRights);
+ $feedSummaryArray = DOMNodeListObjectValuesToArray($feedSummary);
+ //node attributes entry level
+ $metadataLinkArray = DOMNodeListObjectValuesToArray($metadataLink);
+ $datasetFeedLinkArray = DOMNodeListObjectValuesToArray($datasetFeedLink);
+ //node attributes feed level
+ $capLinkArray = DOMNodeListObjectValuesToArray($capabilitiesLink);
+ //for each titled entry element
+ for ($i=0; $i<=(count($titleArray)-1); $i++) {
$feature = new Feature;
$uuid = new Uuid;
- $feature->fid = $uuid;
- $titleArray = (array)$title[$i];
- $contentArray = (array)$content[$i];
- $rightsArray = (array)$rights[$i];
+ $feature->fid = $uuid;
if ($rightsArray[0] == "") {
- $rightsArray = (array)$feedRights[0];
+ $rightsArray = $feedRightsArray[0];
}
- $summaryArray = (array)$summary[$i];
if ($summaryArray[0] == "") {
- $summaryArray = (array)$feedSummary[0];
+ $summaryArray = (array)$feedSummaryArray[0];
}
- $dateArray = (array)$date[$i];
- $codeArray = (array)$code[$i];
- $namespaceArray = (array)$namespace[$i];
- $bboxArray = (array)$bbox[$i];
- $polygonArray = (array)$polygon[$i];
- $mdLinkArray = (array)$metadataLink[$i];
- $mdLinkArray = $mdLinkArray["@attributes"];
- $capLinkArray = (array)$capabilitiesLink[$i];
- $capLinkArray = $capLinkArray["@attributes"];
- $e = new mb_exception((string)count($capLinkArray));
- $dsLinkArray = (array)$datasetFeedLink[$i];
- $dsLinkArray = $dsLinkArray["@attributes"];
- $feature->properties["title"] = $titleArray[0];
+ $feature->properties["title"] = $titleArray[$i];
//$feature->properties["content"] = $contentArray[0];
- $feature->properties["summary"] = $summaryArray[0];
- $feature->properties["rights"] = $rightsArray[0];
- $feature->properties["date"] = $dateArray[0];
- $feature->properties["code"] = $codeArray[0];
- $feature->properties["namespace"] = $namespaceArray[0];
- $feature->properties["metadataLink"] = $mdLinkArray["href"];
- $feature->properties["capabilitiesLink"] = $capLinkArray["href"];
- $feature->properties["datasetFeedLink"] = $dsLinkArray["href"];
+ $feature->properties["summary"] = $summaryArray[$i];
+ $feature->properties["rights"] = $rightsArray[$i];
+ $feature->properties["date"] = $dateArray[$i];
+ $feature->properties["code"] = $codeArray[$i];
+ $feature->properties["namespace"] = $namespaceArray[$i];
+ $feature->properties["metadataLink"] = $metadataLinkArray[$i];
+ $feature->properties["capabilitiesLink"] = $capLinkArray[0];
+ $feature->properties["datasetFeedLink"] = $datasetFeedLinkArray[$i];
//check if polygon is given
- if (isset($polygonArray[0]) && $polygonArray[0] != '') {
+ if (isset($polygonArray[$i]) && $polygonArray[$i] != '') {
$feature->geometry = new geoRSSPolygon();
- $feature->geometry->parsePolygon($polygonArray[0]);
+ $feature->geometry->parsePolygon($polygonArray[$i]);
} else { //maybe bbox is given
- if (isset($bboxArray[0]) && $bboxArray[0] != '') {
+ if (isset($bboxArray[$i]) && $bboxArray[$i] != '') {
$feature->geometry = new geoRSSBox();
$feature->geometry->targetEPSG = '4326';
- $feature->geometry->parseBox($bboxArray[0]);
+ $feature->geometry->parseBox($bboxArray[$i]);
} else {
//set dummy extent - maybe the one of the first feed
$feature->geometry = null;
@@ -184,9 +225,12 @@
//$mbMetadata = $this->createMapbenderMetadataFromXML($xml);
//parse content
//$e = new mb_exception($feedFile);
+ //DOM
+ $feedXML = new DOMDocument();
libxml_use_internal_errors(true);
try {
- $feedXML = simplexml_load_string($feedFile);
+ //$feedXML = simplexml_load_string($feedFile);
+ $feedXML->loadXML($feedFile);
if ($feedXML === false) {
foreach(libxml_get_errors() as $error) {
$err = new mb_exception("downloadFeedServer.php:".$error->message);
@@ -201,56 +245,67 @@
}
//$e = new mb_exception($feedXML->file);
if ($feedXML != false) {
- $feedXML->registerXPathNamespace("georss", "http://www.georss.org/georss");
- $feedXML->registerXPathNamespace("inspire_dls", "http://inspire.ec.europa.eu/schemas/inspire_dls/1.0");
- $feedXML->registerXPathNamespace("defaultns", "http://www.w3.org/2005/Atom");
+ //$xml->loadXML($feedFile);
+ $xpath = new DOMXPath($feedXML);
+ $rootNamespace = $feedXML->lookupNamespaceUri($feedXML->namespaceURI);
+ $xpath->registerNamespace('defaultns', $rootNamespace);
+ $xpath->registerNamespace('georss','http://www.georss.org/georss');
+ $xpath->registerNamespace('inspire_dls','http://inspire.ec.europa.eu/schemas/inspire_dls/1.0');
+ $title = $xpath->query('/defaultns:feed/defaultns:entry/defaultns:title');
+ $content = $xpath->query('/defaultns:feed/defaultns:entry/defaultns:content');
+ $polygon = $xpath->query('/defaultns:feed/defaultns:entry/georss:polygon');
+ $bbox = $xpath->query('/defaultns:feed/defaultns:entry/georss:box');
- $title = $feedXML->xpath('/defaultns:feed/defaultns:entry/defaultns:title');
- $content = $feedXML->xpath('/defaultns:feed/defaultns:entry/defaultns:content');
- $polygon = $feedXML->xpath('/defaultns:feed/defaultns:entry/georss:polygon');
- $bbox = $feedXML->xpath('/defaultns:feed/defaultns:entry/georss:box');
- //$link = $feedXML->xpath('/defaultns:feed/defaultns:entry/defaultns:link[contains(@rel,\'section\')]/@bbox');
- //$datasetFeedLink = $feedXML->xpath('/defaultns:feed/defaultns:entry/defaultns:link[contains(@rel,\'alternate\')]/@href');
+ $titleArray = DOMNodeListObjectValuesToArray($title);
+ $contentArray = DOMNodeListObjectValuesToArray($content);
+ $polygonArray = DOMNodeListObjectValuesToArray($polygon);
+ $bboxArray = DOMNodeListObjectValuesToArray($bbox);
+ //node attributes entry level
+ $metadataLinkArray = DOMNodeListObjectValuesToArray($metadataLink);
+ $datasetFeedLinkArray = DOMNodeListObjectValuesToArray($datasetFeedLink);
//new feature collection
$featureCollection = new FeatureCollection;
- for ($i=0; $i<=(count($title)-1); $i++) {
+ //$e = new mb_exception("dataset feeds entries: ".count($titleArray));
+ for ($i=0; $i<=(count($titleArray)-1); $i++) {
$feature = new Feature;
$uuid = new Uuid;
$feature->fid = $uuid;
- $links = $feedXML->xpath('/defaultns:feed/defaultns:entry['.(string)($i + 1).']/defaultns:link');
+ $links = $xpath->query('/defaultns:feed/defaultns:entry['.(string)($i + 1).']/defaultns:link[contains(@rel,\'alternate\')]');
+ $linksArray = DOMNodeListObjectValuesToArray($links);
+ //example
+ /* <link rel="alternate" href="http://map1.naturschutz.rlp.de/service_lanis/mod_wfs/wfs_getmap.php?mapfile=naturschutzgebiet&SERVICE=WFS&REQUEST=GetFeature&VERSION=1.1.0&typeName=naturschutzgebiet&maxFeatures=520&srsName=EPSG:25832" type="application/gml+xml" hreflang="de" title="Naturschutzgebiete im CRS EPSG:25832 - - Teil 1 von 1" bbox="48.9451980590054 6.1773996352971 50.9453010559041 8.48990058899502"/> */
+ //read it and give it back as string (or xml)
- $titleArray = (array)$title[$i];
- $contentArray = (array)$content[$i];
- $bboxArray = (array)$bbox[$i];
- $polygonArray = (array)$polygon[$i];
- $mdLinkArray = (array)$metadataLink[$i];
- $mdLinkArray = $mdLinkArray["@attributes"];
- $dsLinkArray = (array)$datasetFeedLink[$i];
- $dsLinkArray = $dsLinkArray["@attributes"];
- $feature->properties["title"] = $titleArray[0];
- $feature->properties["content"] = $contentArray[0];
- $feature->properties["metadataLink"] = $mdLinkArray["href"];
- $feature->properties["datasetFeedLink"] = $dsLinkArray["href"];
+ //need attributes href and bbox of this element! Test old system
+ //$linksArray = DOMNodeListObjectValuesToHTML($links);
+
+ //$e = new mb_exception("Count of found links: ".count($linksArray));
+
+ //$e = new mb_exception("linksArray[0]: ".$linksArray[0]);
+ //echo var_dump($links->item(0));
+ //die();
+ $feature->properties["title"] = $titleArray[$i];
+ $feature->properties["content"] = $contentArray[$i];
+ //$feature->properties["metadataLink"] = $mdLinkArray["href"];
+ //$feature->properties["datasetFeedLink"] = $dsLinkArray["href"];
//$feature->properties["entry"] = array();
- if (isset($polygonArray[0]) && $polygonArray[0] != '') {
+ if (isset($polygonArray[$i]) && $polygonArray[$i] != '') {
$feature->geometry = new geoRSSPolygon();
- $feature->geometry->parsePolygon($polygonArray[0]);
+ $feature->geometry->parsePolygon($polygonArray[$i]);
} else { //maybe bbox is given
- if (isset($bboxArray[0]) && $bboxArray[0] != '') {
+ if (isset($bboxArray[$i]) && $bboxArray[$i] != '') {
$feature->geometry = new geoRSSBox();
$feature->geometry->targetEPSG = '4326';
- $feature->geometry->parseBox($bboxArray[0]);
+ $feature->geometry->parseBox($bboxArray[$i]);
} else {
//set dummy extent - maybe the one of the first feed
$feature->geometry = null;
-
}
-
}
//extract all links
- for ($j=0; $j<=(count($links)-1); $j++) {
- $feature->properties["link"][$j] = $links[$j];
+ for ($j=0; $j<=($links->length-1); $j++) {
+ $feature->properties["link"][$j]->{"@attributes"} = DOMNodeListObjectAttributes($links->item($j));
}
//$link = $feedXML->xpath('/defaultns:feed/defaultns:entry/defaultns:link[contains(@rel,\'section\')]/@bbox');
//check if polygon is given
More information about the Mapbender_commits
mailing list